Module: Prremote::Commands::SerialHelpers
Instance Method Summary collapse
Instance Method Details
#normalize(str) ⇒ Object
22 23 24 |
# File 'lib/prremote/commands/serial_helpers.rb', line 22 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 15 16 17 18 19 20 |
# File 'lib/prremote/commands/serial_helpers.rb', line 4 def wait_for_ready(serial) # On macOS, USB CDC TX buffers can be dropped when the host reopens the port, # leaving the device stuck in getchar() without re-sending READY. # Sending Ctrl+C forces the device to restart its READY loop. sleep 0.1 serial.write("\x03") rescue nil 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 |