Class: TuxDroid::Tux
Overview
Tux Interface Class
Constant Summary
Constants included from USBCodes
USBCodes::FIRMWARE_REV, USBCodes::INTERFACE, USBCodes::PRODUCT_ID, USBCodes::READ_ENDPOINT, USBCodes::READ_TIMEOUT, USBCodes::RECV_LENGTH, USBCodes::SEND_LENGTH, USBCodes::VENDOR_ID, USBCodes::WRITE_ENDPOINT, USBCodes::WRITE_TIMEOUT
Instance Attribute Summary collapse
-
#usb_status ⇒ Object
readonly
Returns the value of attribute usb_status.
Instance Method Summary collapse
-
#eyes(cmd, options = {}) ⇒ Object
Accepts: * :open => opens eyes * :closes => closes eyes * :blink => toggles eyes (specify option “:times => n” for n amount of toggles) * :stop => stops current eye motions.
-
#initialize ⇒ Tux
constructor
Creates a new interface between ruby and the TuxDroid.
-
#leds(cmd, options = {}) ⇒ Object
Accepts: * :on => light up both eyes * :off => turn off both eyes * :left_on => light up left eye * :left_off => turn off left eye * :right_on => light up right eye * :right_off => turn off right eye * :blink => blink both eyes, options are :times => n (n amount of blinks), :delay => n (n x 4ms delay between blinks).
-
#mouth(cmd, options = {}) ⇒ Object
Accepts: * :open => opens mouth * :closes => closes mouth * :move => toggles mouth (specify option “:times => n” for n amount of toggles).
-
#spin(cmd, options = {}) ⇒ Object
Accepts: * :left => spins left roughly 90 degrees, options are :times => n (n amount of times), :speed => (1..5) * :right => spins right roughly 90 degrees, options are :times => n (n amount of times), :speed => (1..5) * :stop => stops current spinning motion.
-
#wings(cmd, options = {}) ⇒ Object
Accepts: * :toggle => toggles wings, options are :speed => (1..5) * :reset => runs wing reset routine (flaps twice) * :flap => toggles wings, options are :times => n (n amount of times), :speed => (1..5).
Constructor Details
#initialize ⇒ Tux
Creates a new interface between ruby and the TuxDroid
22 23 24 25 26 |
# File 'lib/tuxdroid.rb', line 22 def initialize @tux_device = self.class.get_usb_device() @tux_handle = self.class.get_usb_interface(@tux_device) @usb_status = :connected end |
Instance Attribute Details
#usb_status ⇒ Object (readonly)
Returns the value of attribute usb_status.
19 20 21 |
# File 'lib/tuxdroid.rb', line 19 def usb_status @usb_status end |
Instance Method Details
#eyes(cmd, options = {}) ⇒ Object
Accepts:
-
:open => opens eyes
-
:closes => closes eyes
-
:blink => toggles eyes (specify option “:times => n” for n amount of toggles)
-
:stop => stops current eye motions
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/tuxdroid.rb', line 55 def eyes(cmd, = {}) validate_within(, :times => 0..255) case cmd when :open send_command(Actions::OPEN_EYES) when :close send_command(Actions::BLINK_EYES, 1) when :blink send_command(Actions::BLINK_EYES, [:times] || 1) when :stop send_command(Actions::STOP_EYES) else raise UnknownTuxDroidActionError.new("Command: #{cmd.inspect} Options: #{options.inspect}") end end |
#leds(cmd, options = {}) ⇒ Object
Accepts:
-
:on => light up both eyes
-
:off => turn off both eyes
-
:left_on => light up left eye
-
:left_off => turn off left eye
-
:right_on => light up right eye
-
:right_off => turn off right eye
-
:blink => blink both eyes, options are :times => n (n amount of blinks), :delay => n (n x 4ms delay between blinks)
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/tuxdroid.rb', line 115 def leds(cmd, = {}) validate_within(, :times => 0..255, :delay => 0..255) case cmd when :on send_command(Actions::LED_ON) when :off send_command(Actions::LED_OFF) when :left_on send_command(Actions::LED_LEFT_ON) when :left_off send_command(Actions::LED_LEFT_OFF) when :right_on send_command(Actions::LED_RIGHT_ON) when :right_off send_command(Actions::LED_RIGHT_OFF) when :blink send_command(Actions::LED_BLINK, [:times] || 1, [:delay] || 20) else raise UnknownTuxDroidActionError.new("Command: #{cmd.inspect} Options: #{options.inspect}") end end |
#mouth(cmd, options = {}) ⇒ Object
Accepts:
-
:open => opens mouth
-
:closes => closes mouth
-
:move => toggles mouth (specify option “:times => n” for n amount of toggles)
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tuxdroid.rb', line 36 def mouth(cmd, = {}) validate_within(, :times => 0..255) case cmd when :open send_command(Actions::OPEN_MOUTH) when :close send_command(Actions::CLOSE_MOUTH) when :move send_command(Actions::MOVE_MOUTH, [:times] || 1) else raise UnknownTuxDroidActionError.new("Command: #{cmd.inspect} Options: #{options.inspect}") end end |
#spin(cmd, options = {}) ⇒ Object
Accepts:
-
:left => spins left roughly 90 degrees, options are :times => n (n amount of times), :speed => (1..5)
-
:right => spins right roughly 90 degrees, options are :times => n (n amount of times), :speed => (1..5)
-
:stop => stops current spinning motion
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/tuxdroid.rb', line 93 def spin(cmd, = {}) validate_within(, :times => 0..255, :speed => 1..5) case cmd when :left send_command(Actions::SPIN_LEFT, [:times] || 1, [:speed] || 3) when :right send_command(Actions::SPIN_RIGHT, [:times] || 1, [:speed] || 3) when :stop send_command(Actions::STOP_SPIN) else raise UnknownTuxDroidActionError.new("Command: #{cmd.inspect} Options: #{options.inspect}") end end |
#wings(cmd, options = {}) ⇒ Object
Accepts:
-
:toggle => toggles wings, options are :speed => (1..5)
-
:reset => runs wing reset routine (flaps twice)
-
:flap => toggles wings, options are :times => n (n amount of times), :speed => (1..5)
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/tuxdroid.rb', line 75 def wings(cmd, = {}) validate_within(, :times => 0..255, :speed => 1..5) case cmd when :toggle send_command(Actions::WAVE_WINGS, 1, [:speed] || 3) when :reset send_command(Actions::RESET_WINGS) when :flap send_command(Actions::WAVE_WINGS, [:times] || 1, [:speed] || 3) else raise UnknownTuxDroidActionError.new("Command: #{cmd.inspect} Options: #{options.inspect}") end end |