Class: URIx::URIx

Inherits:
Object
  • Object
show all
Defined in:
lib/urix/urix.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeURIx

Returns a new instance of URIx.



12
13
14
15
16
17
18
19
# File 'lib/urix/urix.rb', line 12

def initialize
	@usb = LIBUSB::Context.new
	@pin_states = 0x0
	@pin_modes = 0x0
	@claimed = false
	
	set_pin_mode( PTT_PIN, :output )
end

Instance Attribute Details

#claimedObject (readonly)

Returns the value of attribute claimed.



10
11
12
# File 'lib/urix/urix.rb', line 10

def claimed
  @claimed
end

#deviceObject (readonly)

Returns the value of attribute device.



9
10
11
# File 'lib/urix/urix.rb', line 9

def device
  @device
end

#handleObject (readonly)

Returns the value of attribute handle.



9
10
11
# File 'lib/urix/urix.rb', line 9

def handle
  @handle
end

#pin_modesObject (readonly)

Returns the value of attribute pin_modes.



10
11
12
# File 'lib/urix/urix.rb', line 10

def pin_modes
  @pin_modes
end

#pin_statesObject (readonly)

Returns the value of attribute pin_states.



10
11
12
# File 'lib/urix/urix.rb', line 10

def pin_states
  @pin_states
end

#usbObject (readonly)

Returns the value of attribute usb.



9
10
11
# File 'lib/urix/urix.rb', line 9

def usb
  @usb
end

Instance Method Details

#claim_interfaceObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/urix/urix.rb', line 21

def claim_interface
	devices = usb.devices(:idVendor => VENDOR_ID, :idProduct => PRODUCT_ID)

	unless devices.first then
		return
	end

	@device = devices.first
	@handle = @device.open
	
	@handle.detach_kernel_driver(HID_INTERFACE)
	@handle.claim_interface( HID_INTERFACE )
end

#close_interfaceObject



35
36
37
38
39
# File 'lib/urix/urix.rb', line 35

def close_interface
	@handle.release_interface( HID_INTERFACE )
	@handle.attach_kernel_driver(HID_INTERFACE)
	@handle.close
end

#set_output(pin, state) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/urix/urix.rb', line 41

def set_output pin, state
	state = false if state == :low
	state = true  if state == :high

	if ( @pin_states >> ( pin - 1 )).odd? && ( state == false ) or
	   ( @pin_states >> ( pin - 1 )).even? && ( state == true ) then

		mask = 0 + ( 1 << ( pin - 1 ))
		@pin_states ^= mask
	end
	
	write_output
end

#set_pin_mode(pin, mode) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/urix/urix.rb', line 55

def set_pin_mode pin, mode
	if ( @pin_modes >> ( pin - 1 )).odd?  && ( mode == :input  ) or
	   ( @pin_modes >> ( pin - 1 )).even? && ( mode == :output ) then

		mask = 0 + ( 1 << ( pin - 1 ))
		@pin_modes ^= mask
	end
end

#set_ptt(state) ⇒ Object



64
65
66
# File 'lib/urix/urix.rb', line 64

def set_ptt state
	set_output PTT_PIN, state
end