Add pin values to read_status response object
This commit is contained in:
parent
ad56526187
commit
ee17c817e0
|
@ -2,8 +2,28 @@ require_relative 'abstract_controller'
|
|||
|
||||
class ReadStatusController < AbstractController
|
||||
def call
|
||||
reply "read_status", x: bot.status[:x], y: bot.status[:y],
|
||||
z: bot.status[:z], busy: bot.status[:busy],
|
||||
current_command: bot.status[:last]
|
||||
reply "read_status", info
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def info
|
||||
info = {busy: bot.status[:busy], current_command: bot.status[:last]}
|
||||
info.merge(pin_info).merge(axis_info)
|
||||
end
|
||||
|
||||
def pin_info
|
||||
# Performs lazy evaluation of pin status. If the pin status is 'unknown',
|
||||
# performs a lookup for next status poll. Otherwise, uses cached value.
|
||||
[*0..13].inject({}) do |hsh, pin|
|
||||
status = bot.status.pin(pin)
|
||||
hsh["pin#{pin}".to_sym] = status
|
||||
bot.commands.read_parameter(pin) if status == :unknown
|
||||
hsh
|
||||
end
|
||||
end
|
||||
|
||||
def axis_info
|
||||
{x: bot.status[:x], y: bot.status[:y], z: bot.status[:z]}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,9 +16,8 @@ class SingleCommandController < AbstractController
|
|||
def call
|
||||
@cmd = message.payload["command"]
|
||||
action = AVAILABLE_ACTIONS[cmd["action"].to_s.downcase] || :unknown
|
||||
puts "Calling #{action}"
|
||||
send(action)
|
||||
reply "read_status", confirmation: true, command: cmd
|
||||
reply 'single_command', confirmation: true, command: cmd
|
||||
end
|
||||
|
||||
def move_relative
|
||||
|
@ -46,6 +45,7 @@ class SingleCommandController < AbstractController
|
|||
end
|
||||
|
||||
def pin_write
|
||||
bot.status.set_pin(cmd['pin'], cmd['value1']) # Belongs in FB-Serial
|
||||
bot.commands.pin_write pin: cmd['pin'],
|
||||
value: cmd['value1'],
|
||||
mode: cmd['mode'] || 0
|
||||
|
|
Loading…
Reference in a new issue