Class: FB::Arduino
- Inherits:
-
Object
- Object
- FB::Arduino
- Defined in:
- lib/arduino.rb
Defined Under Namespace
Classes: EmergencyStop, Position
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#inbound_queue ⇒ Object
Returns the value of attribute inbound_queue.
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#outbound_queue ⇒ Object
Returns the value of attribute outbound_queue.
-
#serial_port ⇒ Object
Returns the value of attribute serial_port.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #current_position ⇒ Object
-
#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(gcode) ⇒ 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
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/arduino.rb', line 19 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 start_event_listeners end |
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
13 14 15 |
# File 'lib/arduino.rb', line 13 def commands @commands end |
#inbound_queue ⇒ Object
Returns the value of attribute inbound_queue.
13 14 15 |
# File 'lib/arduino.rb', line 13 def inbound_queue @inbound_queue end |
#inputs ⇒ Object
Returns the value of attribute inputs.
13 14 15 |
# File 'lib/arduino.rb', line 13 def inputs @inputs end |
#logger ⇒ Object
Returns the value of attribute logger.
13 14 15 |
# File 'lib/arduino.rb', line 13 def logger @logger end |
#outbound_queue ⇒ Object
Returns the value of attribute outbound_queue.
13 14 15 |
# File 'lib/arduino.rb', line 13 def outbound_queue @outbound_queue end |
#serial_port ⇒ Object
Returns the value of attribute serial_port.
13 14 15 |
# File 'lib/arduino.rb', line 13 def serial_port @serial_port end |
#status ⇒ Object
Returns the value of attribute status.
13 14 15 |
# File 'lib/arduino.rb', line 13 def status @status end |
Instance Method Details
#current_position ⇒ Object
62 63 64 |
# File 'lib/arduino.rb', line 62 def current_position Position.new(status[:X], status[:Y], status[:Z]) end |
#disconnect ⇒ Object
Handle loss of serial connection
57 58 59 60 |
# File 'lib/arduino.rb', line 57 def disconnect log "Connection to device lost" @onclose.call if @onclose end |
#log(message) ⇒ Object
Log to screen/file/IO stream
33 34 35 |
# File 'lib/arduino.rb', line 33 def log() logger.puts() end |
#onchange(&blk) ⇒ Object
43 44 45 |
# File 'lib/arduino.rb', line 43 def onchange(&blk) @onchange = blk end |
#onclose(&blk) ⇒ Object
52 53 54 |
# File 'lib/arduino.rb', line 52 def onclose(&blk) @onclose = blk end |
#onmessage(&blk) ⇒ Object
Handle incoming text from arduino into pi
48 49 50 |
# File 'lib/arduino.rb', line 48 def (&blk) = blk end |
#write(gcode) ⇒ Object
Send outgoing test to arduino from pi
38 39 40 41 |
# File 'lib/arduino.rb', line 38 def write(gcode) @outbound_queue.unshift gcode execute_command_next_tick end |