Class: Denko::Sensor::JSNSR04T
- Inherits:
-
Object
- Object
- Denko::Sensor::JSNSR04T
- Defined in:
- lib/denko/sensor/jsnsr04t.rb
Overview
For JSN-SR04T sensor in mode 2 ONLY.
Constant Summary collapse
- UART_CLASSES =
[Denko::UART::Hardware, Denko::UART::BitBang]
- TIMEOUT =
0.500
Constants included from Behaviors::Reader
Behaviors::Reader::READ_WAIT_TIME
Constants included from Behaviors::Lifecycle
Behaviors::Lifecycle::CALLBACK_METHODS
Instance Attribute Summary collapse
-
#uart ⇒ Object
readonly
Returns the value of attribute uart.
Attributes included from Behaviors::Threaded
Attributes included from Behaviors::State
Attributes included from Behaviors::Component
Instance Method Summary collapse
Methods included from Behaviors::Poller
Methods included from Behaviors::Threaded
#enable_interrupts, included, #mruby_thread_check, #stop, #stop_thread, #threaded, #threaded_loop
Methods included from Behaviors::Reader
#read, #read_busy?, #read_nb, #read_raw, #read_using, #update
Methods included from Behaviors::Callbacks
#add_callback, #callbacks, #pre_callback_filter, #remove_callback, #update
Methods included from Behaviors::State
Methods included from Behaviors::Lifecycle
Methods included from Behaviors::Component
Instance Attribute Details
#uart ⇒ Object (readonly)
Returns the value of attribute uart.
14 15 16 |
# File 'lib/denko/sensor/jsnsr04t.rb', line 14 def uart @uart end |
Instance Method Details
#_read ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/denko/sensor/jsnsr04t.rb', line 26 def _read # Trigger read uart.write("U") # Get line from UART start = Time.now line = nil until line || (Time.now - start > TIMEOUT) line = uart.gets sleep 0.010 end # Extract mm as integer if line && line.strip.end_with?("mm") value = line.gsub("mm").strip.to_i self.update(value) return value end return nil end |