Class: FB::OutgoingHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/arduino/outgoing_handler.rb

Overview

Responsible for writing to the serial line. Sends Gcode from the pi to the arduino. (Pi -> Arduino)

Defined Under Namespace

Classes: UnhandledGcode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bot) ⇒ OutgoingHandler



9
10
11
# File 'lib/arduino/outgoing_handler.rb', line 9

def initialize(bot)
  @bot = bot
end

Instance Attribute Details

#botObject (readonly)

Returns the value of attribute bot.



5
6
7
# File 'lib/arduino/outgoing_handler.rb', line 5

def bot
  @bot
end

Instance Method Details

#emergency_stopObject



13
14
15
16
17
# File 'lib/arduino/outgoing_handler.rb', line 13

def emergency_stop(*)
  bot.outbound_queue = []  # Dump pending commands.
  bot.serial_port.puts "E" # Don't queue this one- write to serial line.
  bot.status[:last] = :emergency_stop
end

#home_allObject



43
44
45
# File 'lib/arduino/outgoing_handler.rb', line 43

def home_all
  write "G28"
end

#home_xObject



31
32
33
# File 'lib/arduino/outgoing_handler.rb', line 31

def home_x
  write "F11"
end

#home_yObject



35
36
37
# File 'lib/arduino/outgoing_handler.rb', line 35

def home_y
  write "F12"
end

#home_zObject



39
40
41
# File 'lib/arduino/outgoing_handler.rb', line 39

def home_z
  write "F13"
end

#move_absolute(x: 0, y: 0, z: 0, s: 100) ⇒ Object



27
28
29
# File 'lib/arduino/outgoing_handler.rb', line 27

def move_absolute(x: 0, y: 0, z: 0, s: 100)
  write "G00 X#{x} Y#{y} Z#{z}"
end

#move_relative(x: 0, y: 0, z: 0, s: 100) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/arduino/outgoing_handler.rb', line 19

def move_relative(x: 0, y: 0, z: 0, s: 100)
  x += (bot.current_position.x || 0)
  y += (bot.current_position.y || 0)
  z += (bot.current_position.z || 0)

  write { FB::Gcode.new { "G00 X#{x} Y#{y} Z#{z}" } }
end

#pin_write(pin:, value:, mode:) ⇒ Object



59
60
61
# File 'lib/arduino/outgoing_handler.rb', line 59

def pin_write(pin:, value:, mode:)
  write "F41 P#{pin} V#{value} M#{mode}"
end

#read_parameter(num) ⇒ Object



47
48
49
# File 'lib/arduino/outgoing_handler.rb', line 47

def read_parameter(num)
  write "F21 P#{num}"
end

#read_status(pin) ⇒ Object



55
56
57
# File 'lib/arduino/outgoing_handler.rb', line 55

def read_status(pin)
  write "F31 P#{pin}"
end

#write_parameter(num, val) ⇒ Object



51
52
53
# File 'lib/arduino/outgoing_handler.rb', line 51

def write_parameter(num, val)
  write "F22 P#{num} V#{val}"
end