Skip to content

Commit

Permalink
Merge pull request #83 from RickCarlino/master
Browse files Browse the repository at this point in the history
Add pin values to read_status response object
  • Loading branch information
RickCarlino committed Apr 15, 2015
2 parents 4c9eca7 + ee17c81 commit 8886a67
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
26 changes: 23 additions & 3 deletions lib/controllers/read_status_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@

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
4 changes: 2 additions & 2 deletions lib/controllers/single_command_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,6 +45,7 @@ def home_all
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
Expand Down

0 comments on commit 8886a67

Please sign in to comment.