Module: NXT::Command::Input
- Extended by:
- Utils::Accessors
- Includes:
- Base
- Included in:
- NXT::Connector::Input::Ultrasonic
- Defined in:
- lib/nxt/commands/input.rb
Overview
An implementation of all the input related NXT commands:
-
SETINPUTMODE
-
GETINPUTVALUES
-
RESETINPUTSCALEDVALUE
This class can also be used to talk to other third-party accessories connected in the input ports on the NXT brick.
Constant Summary collapse
- COMMAND_IDENTIFIER =
{ set_input_mode: 0x05, get_input_values: 0x07, reset_input_scaled_value: 0x08, ls_get_status: 0x0E, ls_write: 0x0F, ls_read: 0x10 }.freeze
- SENSOR_TYPE =
The sensor type enum. This is a list of possible values when setting the sensor type byte.
Reference: Appendix 2, Page 7
{ no_sensor: 0x00, switch: 0x01, temperature: 0x02, reflection: 0x03, angle: 0x04, light_active: 0x05, light_inactive: 0x06, sound_db: 0x07, sound_dba: 0x08, custom: 0x09, lowspeed: 0x0A, lowspeed_9v: 0x0B, no_of_sensor_types: 0x0C }.freeze
- SENSOR_MODE =
The sensor mode enum. This is a list of possible values when setting the sensor mode byte.
Reference: Appendix 2, Page 7
{ raw: 0x00, boolean: 0x20, transition_cnt: 0x40, period_counter: 0x60, pct_full_scale: 0x80, celsius: 0xA0, fahrenheit: 0xC0, angle_steps: 0xE0, slope: 0x1F, mode_mask: 0x00 }.freeze
Instance Method Summary collapse
- #command_type ⇒ Object
- #input_values ⇒ Object
- #ls_get_status(response_required: false) ⇒ Object
- #ls_read(response_required: false) ⇒ Object
- #ls_write(bytes, response_required: false) ⇒ Object
- #reset_input_scaled_value ⇒ Object
- #update_input_mode(response_required: false) ⇒ Object
Methods included from Utils::Accessors
Methods included from Utils::Assertions
#assert_in, #assert_responds_to, #assert_type
Instance Method Details
#command_type ⇒ Object
69 70 71 |
# File 'lib/nxt/commands/input.rb', line 69 def command_type COMMAND_TYPES[:direct] end |
#input_values ⇒ Object
84 85 86 87 |
# File 'lib/nxt/commands/input.rb', line 84 def input_values # TODO: Parse this response and return hash or something similar. send_and_receive(COMMAND_IDENTIFIER[:get_input_values], [], response_required) end |
#ls_get_status(response_required: false) ⇒ Object
94 95 96 |
# File 'lib/nxt/commands/input.rb', line 94 def ls_get_status(response_required: false) send_and_receive(COMMAND_IDENTIFIER[:ls_get_status], [], response_required) end |
#ls_read(response_required: false) ⇒ Object
102 103 104 |
# File 'lib/nxt/commands/input.rb', line 102 def ls_read(response_required: false) send_and_receive(COMMAND_IDENTIFIER[:ls_read], [], response_required) end |
#ls_write(bytes, response_required: false) ⇒ Object
98 99 100 |
# File 'lib/nxt/commands/input.rb', line 98 def ls_write(bytes, response_required: false) send_and_receive(COMMAND_IDENTIFIER[:ls_write], bytes, response_required) end |
#reset_input_scaled_value ⇒ Object
89 90 91 92 |
# File 'lib/nxt/commands/input.rb', line 89 def reset_input_scaled_value # TODO: Parse this response and return hash or something similar. send_and_receive(COMMAND_IDENTIFIER[:reset_input_scaled_value], [], response_required) end |
#update_input_mode(response_required: false) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/nxt/commands/input.rb', line 73 def update_input_mode(response_required: false) send_and_receive( COMMAND_IDENTIFIER[:set_input_mode], [ SENSOR_TYPE[sensor_type], SENSOR_MODE[sensor_mode] ], response_required ) end |