Class: NXT
- Inherits:
-
Object
- Object
- NXT
- Defined in:
- lib/nxt.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#communication ⇒ Object
readonly
Returns the value of attribute communication.
-
#device_path ⇒ Object
readonly
Returns the value of attribute device_path.
-
#wait_for_reply ⇒ Object
readonly
Returns the value of attribute wait_for_reply.
Instance Method Summary collapse
- #async ⇒ Object
- #connect ⇒ Object
- #disconnect ⇒ Object
- #get_battery_level ⇒ Object
- #get_current_program_name ⇒ Object
-
#get_device_info ⇒ Object
System commands.
-
#initialize(device_path, communication = nil) ⇒ NXT
constructor
A new instance of NXT.
- #play_sound_file(sound_filename, loop_sound = false) ⇒ Object
- #play_tone(frequency_hz, duration_ms) ⇒ Object
- #reset_motor_position ⇒ Object
-
#send_message(command, reply_type = nil) ⇒ Object
Lowest-level API.
- #set_input_mode(input_port, sensor_type, sensor_mode) ⇒ Object
- #set_output_state(output_state) ⇒ Object
- #start_program(program_name) ⇒ Object
-
#stop_program ⇒ Object
Direct commands.
- #stop_sound_playback ⇒ Object
Constructor Details
#initialize(device_path, communication = nil) ⇒ NXT
Returns a new instance of NXT.
17 18 19 20 21 22 23 24 |
# File 'lib/nxt.rb', line 17 def initialize(device_path, communication=nil) raise ArgumentError, "device_path must be non-nil" if device_path.nil? @wait_for_reply = true @device_path = device_path @communication = communication || BluetoothCommunication.new(device_path) @async = nil end |
Instance Attribute Details
#communication ⇒ Object (readonly)
Returns the value of attribute communication.
15 16 17 |
# File 'lib/nxt.rb', line 15 def communication @communication end |
#device_path ⇒ Object (readonly)
Returns the value of attribute device_path.
15 16 17 |
# File 'lib/nxt.rb', line 15 def device_path @device_path end |
#wait_for_reply ⇒ Object (readonly)
Returns the value of attribute wait_for_reply.
15 16 17 |
# File 'lib/nxt.rb', line 15 def wait_for_reply @wait_for_reply end |
Instance Method Details
#async ⇒ Object
36 37 38 39 |
# File 'lib/nxt.rb', line 36 def async @async = NXTAsync.new(@device_path, @communication) if @async.nil? @async end |
#connect ⇒ Object
26 27 28 29 |
# File 'lib/nxt.rb', line 26 def connect @communication.connect self end |
#disconnect ⇒ Object
31 32 33 34 |
# File 'lib/nxt.rb', line 31 def disconnect @communication.disconnect self end |
#get_battery_level ⇒ Object
75 76 77 |
# File 'lib/nxt.rb', line 75 def get_battery_level (GetBatteryLevel.new, GetBatteryLevelReply) end |
#get_current_program_name ⇒ Object
50 51 52 53 |
# File 'lib/nxt.rb', line 50 def get_current_program_name # always requires a reply, so no constructor argument to allow an override (GetCurrentProgramName.new, GetCurrentProgramNameReply) end |
#get_device_info ⇒ Object
System commands
97 98 99 100 |
# File 'lib/nxt.rb', line 97 def get_device_info # always requires a reply, so no constructor argument to allow an override (GetDeviceInfo.new, GetDeviceInfoReply) end |
#play_sound_file(sound_filename, loop_sound = false) ⇒ Object
59 60 61 |
# File 'lib/nxt.rb', line 59 def play_sound_file(sound_filename, loop_sound=false) (PlaySoundFile.new(sound_filename, loop_sound, wait_for_reply), PlaySoundFileReply) end |
#play_tone(frequency_hz, duration_ms) ⇒ Object
63 64 65 |
# File 'lib/nxt.rb', line 63 def play_tone(frequency_hz, duration_ms) (PlayTone.new(frequency_hz, duration_ms, wait_for_reply), PlayToneReply) end |
#reset_motor_position ⇒ Object
79 80 81 |
# File 'lib/nxt.rb', line 79 def reset_motor_position (ResetMotorPosition.new(wait_for_reply), ResetMotorPositionReply) end |
#send_message(command, reply_type = nil) ⇒ Object
Lowest-level API
103 104 105 |
# File 'lib/nxt.rb', line 103 def (command, reply_type=nil) @communication.(command, reply_type) end |
#set_input_mode(input_port, sensor_type, sensor_mode) ⇒ Object
67 68 69 |
# File 'lib/nxt.rb', line 67 def set_input_mode(input_port, sensor_type, sensor_mode) (SetInputMode.new(input_port, sensor_type, sensor_mode, wait_for_reply), SetInputModeReply) end |
#set_output_state(output_state) ⇒ Object
71 72 73 |
# File 'lib/nxt.rb', line 71 def set_output_state(output_state) (SetOutputState.new(output_state, wait_for_reply),SetOutputStateReply) end |
#start_program(program_name) ⇒ Object
46 47 48 |
# File 'lib/nxt.rb', line 46 def start_program(program_name) (StartProgram.new(program_name, wait_for_reply), StartProgramReply) end |
#stop_program ⇒ Object
Direct commands
42 43 44 |
# File 'lib/nxt.rb', line 42 def stop_program (StopProgram.new(wait_for_reply), StopProgramReply) end |
#stop_sound_playback ⇒ Object
55 56 57 |
# File 'lib/nxt.rb', line 55 def stop_sound_playback (StopSoundPlayback.new(wait_for_reply), StopSoundPlaybackReply) end |