Class: Dino::TxRx::USBSerial
- Inherits:
-
Object
- Object
- Dino::TxRx::USBSerial
- Defined in:
- lib/smalruby/hardware/dino/fix_gets.rb
Instance Method Summary collapse
Instance Method Details
#gets(timeout = 0.005) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/smalruby/hardware/dino/fix_gets.rb', line 64 def gets(timeout = 0.005) return nil unless IO.select([io], nil, nil, timeout) io.read_timeout = (timeout * 1000).to_i bytes = [] until (x = io.getbyte).nil? bytes.push(x) end return nil if bytes.empty? bytes.pack("C*") end |
#read ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/smalruby/hardware/dino/fix_gets.rb', line 51 def read @thread ||= Thread.new do loop do line = gets if line pin, = *line.chomp.split(/::/) pin && && changed && notify_observers(pin, ) end sleep 0.004 end end end |