Merge pull request #83 from RickCarlino/master

Add pin values to read_status response object
pull/88/head 4-15
Rick Carlino 2015-04-15 08:28:26 -05:00
commit 8886a6729f
2 changed files with 25 additions and 5 deletions

View File

@ -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

View File

@ -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