forked from ileitch/delcom_904008_driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelcom_904008.rb
More file actions
69 lines (58 loc) · 1.5 KB
/
delcom_904008.rb
File metadata and controls
69 lines (58 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env ruby
#
# Author: Ian Leitch <ian@envato.com>
# Copyright 2010 Envato
require 'usb'
module Delcom
class SignalIndicator
VENDOR_ID = 0x0fc5
PRODUCT_ID = 0xb080
INTERFACE_ID = 0
OFF = "\x00"
GREEN = "\x01"
RED = "\x02"
YELLOW = "\x04"
def initialize
@device = USB.devices.find {|device| device.idVendor == VENDOR_ID && device.idProduct == PRODUCT_ID}
raise "Unable to find device" unless @device
end
def green
msg(GREEN)
end
def yellow
msg(YELLOW)
end
def red
msg(RED)
end
def off
msg(OFF)
end
def close
handle.release_interface(INTERFACE_ID)
handle.usb_close
@handle = nil
end
private
def msg(data)
handle.usb_control_msg(0x21, 0x09, 0x0635, 0x000, "\x65\x0C#{data}\xFF\x00\x00\x00\x00", 0)
end
def handle
return @handle if @handle
@handle = @device.usb_open
begin
# ruby-usb bug: the arity of rusb_detach_kernel_driver_np isn't defined correctly, it should only accept a single argument.
if USB::DevHandle.instance_method(:usb_detach_kernel_driver_np).arity == 2
@handle.usb_detach_kernel_driver_np(INTERFACE_ID, INTERFACE_ID)
else
@handle.usb_detach_kernel_driver_np(INTERFACE_ID)
end
rescue Errno::ENODATA => e
# Already detached
end
@handle.set_configuration(@device.configurations.first)
@handle.claim_interface(INTERFACE_ID)
@handle
end
end
end