Class: Commands::SoundSensor
- Inherits:
-
Object
- Object
- Commands::SoundSensor
- Includes:
- Mixins::Sensor
- Defined in:
- lib/commands/sound_sensor.rb
Overview
Implements the “Sound Sensor” block in NXT-G
Instance Attribute Summary collapse
-
#comparison ⇒ Object
Returns the value of attribute comparison.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#trigger_point ⇒ Object
Returns the value of attribute trigger_point.
Instance Method Summary collapse
-
#initialize(nxt) ⇒ SoundSensor
constructor
A new instance of SoundSensor.
-
#method_missing(cmd) ⇒ Object
attempt to return the input_value requested.
-
#raw_value ⇒ Object
returns the raw value of the sensor.
-
#set_mode ⇒ Object
sets up the sensor port.
-
#sound_level ⇒ Object
scaled value read from sensor.
Methods included from Mixins::Sensor
Constructor Details
#initialize(nxt) ⇒ SoundSensor
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/commands/sound_sensor.rb', line 28 def initialize(nxt) @nxt = nxt # defaults the same as NXT-G @port = 2 @trigger_point = 50 @comparison = ">" @mode = "dba" set_mode end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(cmd) ⇒ Object
attempt to return the input_value requested
64 65 66 |
# File 'lib/commands/sound_sensor.rb', line 64 def method_missing(cmd) @nxt.get_input_values(NXTComm.const_get("SENSOR_#{@port}"))[cmd] end |
Instance Attribute Details
#comparison ⇒ Object
Returns the value of attribute comparison.
26 27 28 |
# File 'lib/commands/sound_sensor.rb', line 26 def comparison @comparison end |
#mode ⇒ Object
Returns the value of attribute mode.
25 26 27 |
# File 'lib/commands/sound_sensor.rb', line 25 def mode @mode end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
25 26 27 |
# File 'lib/commands/sound_sensor.rb', line 25 def port @port end |
#trigger_point ⇒ Object
Returns the value of attribute trigger_point.
26 27 28 |
# File 'lib/commands/sound_sensor.rb', line 26 def trigger_point @trigger_point end |
Instance Method Details
#raw_value ⇒ Object
returns the raw value of the sensor
50 51 52 |
# File 'lib/commands/sound_sensor.rb', line 50 def raw_value value_raw end |
#set_mode ⇒ Object
sets up the sensor port
55 56 57 58 59 60 61 |
# File 'lib/commands/sound_sensor.rb', line 55 def set_mode @nxt.set_input_mode( NXTComm.const_get("SENSOR_#{@port}"), NXTComm.const_get("SOUND_#{@mode.upcase}"), NXTComm::PCTFULLSCALEMODE ) end |
#sound_level ⇒ Object
scaled value read from sensor
45 46 47 |
# File 'lib/commands/sound_sensor.rb', line 45 def sound_level value_scaled end |