Module: Prremote::Commands::SerialHelpers
Instance Method Summary collapse
Instance Method Details
#normalize(str) ⇒ Object
16 17 18 |
# File 'lib/prremote/commands/serial_helpers.rb', line 16 def normalize(str) str.gsub("\r\n", "\n").gsub("\r", '') end |
#wait_for_ready(serial) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/prremote/commands/serial_helpers.rb', line 4 def wait_for_ready(serial) buf = +'' deadline = Time.now + 10 loop do buf << normalize(serial.read(256) || '') return if buf.include?('READY ') raise 'Timeout waiting for device. Run `prremote reset` if a script is running.' if Time.now > deadline sleep 0.05 end end |