Class: Dino::TxRx::USBSerial

Inherits:
Object
  • Object
show all
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

#readObject



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, message = *line.chomp.split(/::/)
        pin && message && changed && notify_observers(pin, message)
      end
      sleep 0.004
    end
  end
end