Class: RoadToRubykaigi::SerialReader
- Inherits:
-
Object
- Object
- RoadToRubykaigi::SerialReader
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/road_to_rubykaigi/serial_reader.rb
Constant Summary collapse
- BAUD =
115200
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
16 17 18 |
# File 'lib/road_to_rubykaigi/serial_reader.rb', line 16 def queue @queue end |
Instance Method Details
#drain ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/road_to_rubykaigi/serial_reader.rb', line 18 def drain until @queue.empty? yield @queue.pop(true) end rescue ThreadError # pop(true) raises if the queue empties mid-drain end |
#start ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/road_to_rubykaigi/serial_reader.rb', line 26 def start @queue.clear Config.detect_serial_port! @port = Config.serial_port return if @thread @thread = Thread.new { read_loop } at_exit { @thread&.kill } end |