Class: URIx::URIx
- Inherits:
-
Object
- Object
- URIx::URIx
- Defined in:
- lib/urix/urix.rb
Instance Attribute Summary collapse
-
#claimed ⇒ Object
readonly
Returns the value of attribute claimed.
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#pin_modes ⇒ Object
readonly
Returns the value of attribute pin_modes.
-
#pin_states ⇒ Object
readonly
Returns the value of attribute pin_states.
-
#usb ⇒ Object
readonly
Returns the value of attribute usb.
Instance Method Summary collapse
- #claim_interface ⇒ Object
- #close_interface ⇒ Object
-
#initialize ⇒ URIx
constructor
A new instance of URIx.
- #set_output(pin, state) ⇒ Object
- #set_pin_mode(pin, mode) ⇒ Object
- #set_ptt(state) ⇒ Object
Constructor Details
Instance Attribute Details
#claimed ⇒ Object (readonly)
Returns the value of attribute claimed.
10 11 12 |
# File 'lib/urix/urix.rb', line 10 def claimed @claimed end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
9 10 11 |
# File 'lib/urix/urix.rb', line 9 def device @device end |
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
9 10 11 |
# File 'lib/urix/urix.rb', line 9 def handle @handle end |
#pin_modes ⇒ Object (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_states ⇒ Object (readonly)
Returns the value of attribute pin_states.
10 11 12 |
# File 'lib/urix/urix.rb', line 10 def pin_states @pin_states end |
#usb ⇒ Object (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_interface ⇒ Object
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_interface ⇒ Object
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 |