Class: Enginevib::Sensor
- Inherits:
-
Object
- Object
- Enginevib::Sensor
- Defined in:
- lib/enginevib/sensor.rb
Overview
Defines a sensor class which can read data from virtual ports, non-blocking.
Instance Attribute Summary collapse
-
#buffered_data ⇒ Object
Returns the value of attribute buffered_data.
-
#fd ⇒ Object
Returns the value of attribute fd.
-
#io ⇒ Object
Returns the value of attribute io.
-
#simulation_mode ⇒ Object
Returns the value of attribute simulation_mode.
Instance Method Summary collapse
-
#initialize(serial_port, simulation_mode) ⇒ Sensor
constructor
A new instance of Sensor.
- #read ⇒ Object
Constructor Details
#initialize(serial_port, simulation_mode) ⇒ Sensor
Returns a new instance of Sensor.
6 7 8 9 |
# File 'lib/enginevib/sensor.rb', line 6 def initialize(serial_port, simulation_mode) @simulation_mode = simulation_mode init_io(serial_port) end |
Instance Attribute Details
#buffered_data ⇒ Object
Returns the value of attribute buffered_data.
4 5 6 |
# File 'lib/enginevib/sensor.rb', line 4 def buffered_data @buffered_data end |
#fd ⇒ Object
Returns the value of attribute fd.
4 5 6 |
# File 'lib/enginevib/sensor.rb', line 4 def fd @fd end |
#io ⇒ Object
Returns the value of attribute io.
4 5 6 |
# File 'lib/enginevib/sensor.rb', line 4 def io @io end |
#simulation_mode ⇒ Object
Returns the value of attribute simulation_mode.
4 5 6 |
# File 'lib/enginevib/sensor.rb', line 4 def simulation_mode @simulation_mode end |
Instance Method Details
#read ⇒ Object
11 12 13 14 15 16 |
# File 'lib/enginevib/sensor.rb', line 11 def read @buffered_data = @simulation_mode ? rand(0.10..1.00) : @io.readline_nonblock.to_f rescue @buffered_data end |