Class: FB::Arduino
- Inherits:
-
Object
- Object
- FB::Arduino
- Defined in:
- lib/arduino.rb
Defined Under Namespace
Classes: EmergencyStop
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#inbound_queue ⇒ Object
readonly
Returns the value of attribute inbound_queue.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#outbound_queue ⇒ Object
readonly
Returns the value of attribute outbound_queue.
-
#serial_port ⇒ Object
readonly
Returns the value of attribute serial_port.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#disconnect ⇒ Object
Handle loss of serial connection.
-
#initialize(serial_port: DefaultSerialPort.new, logger: STDOUT) ⇒ Arduino
constructor
Initialize and provide a serial object, as well as an IO object to send log messages to.
-
#log(message) ⇒ Object
Log to screen/file/IO stream.
- #onchange(&blk) ⇒ Object
- #onclose(&blk) ⇒ Object
-
#onmessage(&blk) ⇒ Object
Handle incoming text from arduino into pi.
-
#write(string) ⇒ Object
Send outgoing test to arduino from pi.
Constructor Details
#initialize(serial_port: DefaultSerialPort.new, logger: STDOUT) ⇒ Arduino
Initialize and provide a serial object, as well as an IO object to send log messages to. Default SerialPort is DefaultSerialPort. Default logger is STDOUT
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/arduino.rb', line 18 def initialize(serial_port: DefaultSerialPort.new, logger: STDOUT) @outbound_queue = [] # Pi -> Arduino Gcode @inbound_queue = EM::Channel.new # Pi <- Arduino @serial_port = serial_port @logger = logger @commands = FB::OutgoingHandler.new(self) @inputs = FB::IncomingHandler.new(self) @status = FB::Status.new(self) start_event_listeners end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
12 13 14 |
# File 'lib/arduino.rb', line 12 def commands @commands end |
#inbound_queue ⇒ Object (readonly)
Returns the value of attribute inbound_queue.
12 13 14 |
# File 'lib/arduino.rb', line 12 def inbound_queue @inbound_queue end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
12 13 14 |
# File 'lib/arduino.rb', line 12 def inputs @inputs end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/arduino.rb', line 12 def logger @logger end |
#outbound_queue ⇒ Object (readonly)
Returns the value of attribute outbound_queue.
12 13 14 |
# File 'lib/arduino.rb', line 12 def outbound_queue @outbound_queue end |
#serial_port ⇒ Object (readonly)
Returns the value of attribute serial_port.
12 13 14 |
# File 'lib/arduino.rb', line 12 def serial_port @serial_port end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/arduino.rb', line 12 def status @status end |
Instance Method Details
#disconnect ⇒ Object
Handle loss of serial connection
56 57 58 59 |
# File 'lib/arduino.rb', line 56 def disconnect log "Connection to device lost" @onclose.call if @onclose end |
#log(message) ⇒ Object
Log to screen/file/IO stream
32 33 34 |
# File 'lib/arduino.rb', line 32 def log() logger.puts() end |
#onchange(&blk) ⇒ Object
42 43 44 |
# File 'lib/arduino.rb', line 42 def onchange(&blk) @onchange = blk end |
#onclose(&blk) ⇒ Object
51 52 53 |
# File 'lib/arduino.rb', line 51 def onclose(&blk) @onclose = blk end |
#onmessage(&blk) ⇒ Object
Handle incoming text from arduino into pi
47 48 49 |
# File 'lib/arduino.rb', line 47 def (&blk) @onmessage = blk end |
#write(string) ⇒ Object
Send outgoing test to arduino from pi
37 38 39 40 |
# File 'lib/arduino.rb', line 37 def write(string) @outbound_queue.unshift string execute_command_next_tick end |