Class: Ban::Board
Constant Summary collapse
- SEND_RC_ON =
0x20
- SEND_RC_OFF =
0x21
- STRING_DATA =
0x71
- EVENTS =
{ DoorEvent::CMD => DoorEvent, IrEvent::CMD => IrEvent, RcEvent::CMD => RcEvent }
Instance Method Summary collapse
- #close ⇒ Object
- #received_sysex(event_code, data) ⇒ Object
- #send_command(command, data) ⇒ Object
- #start(path) ⇒ Object
- #turn_off(address) ⇒ Object
- #turn_on(address) ⇒ Object
Instance Method Details
#close ⇒ Object
25 26 27 |
# File 'lib/ban/board.rb', line 25 def close @firmata.close end |
#received_sysex(event_code, data) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/ban/board.rb', line 29 def received_sysex(event_code, data) if klass = EVENTS[event_code] emit :event, klass.parse(data) else emit :error, msg: 'Unknown event!', event_code: event_code, data: data end end |
#send_command(command, data) ⇒ Object
45 46 47 |
# File 'lib/ban/board.rb', line 45 def send_command(command, data) @firmata.sysex(STRING_DATA, Ban.encode7bit(command.chr + data)) end |
#start(path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ban/board.rb', line 13 def start(path) @path = path @firmata = ArduinoFirmata.connect @path, nonblock_io: true, eventmachine: true Logger.debug "Firmata Version: #{@firmata.version}" arduino = self @firmata.on :sysex do |cmd, data| arduino.received_sysex(cmd, data) end end |
#turn_off(address) ⇒ Object
41 42 43 |
# File 'lib/ban/board.rb', line 41 def turn_off(address) send_command(SEND_RC_OFF, address) end |
#turn_on(address) ⇒ Object
37 38 39 |
# File 'lib/ban/board.rb', line 37 def turn_on(address) send_command(SEND_RC_ON, address) end |