Outputs: positions (a key steps off → a → b → off, a knob up and down, the last off before the next on), strobe (a period) and dimmer (a knob's level by a step; a dimmable module gets a byte per channel, a relay just switches); in /keypad.html and /sim.html, a key's LED on while a position is chosen or a strobe runs
This commit is contained in:
1 parent
e82b2236b5
commit
82a728e024
7 files changed
+239
-55
No files matched your search
@@ -531,7 +531,7 @@ module Maptool
|
||||
[]
|
||||
end
|
||||
|
||||
BINDING_KEYS = %w[input action menu output mode pulse_s led led_on].freeze
|
||||
BINDING_KEYS = %w[input action menu output outputs mode pulse_s period_s step led led_on].freeze
|
||||
# A saved list's check: each an input, an action / menu or an output, known modes and colours.
|
||||
def self.check_bindings(list)
|
||||
raise ArgumentError, "bindings: a list" unless list.is_a?(Array)
|
||||
@@ -543,7 +543,14 @@ module Maptool
|
||||
raise ArgumentError, "a binding without an input" unless b["input"].is_a?(String) && b["input"].include?(".")
|
||||
raise ArgumentError, "#{b['input']}: unknown mode #{b['mode']}" if b["mode"] && !Outputs::MODES.include?(b["mode"])
|
||||
%w[led led_on].each { |k| raise ArgumentError, "#{b['input']}: unknown colour #{b[k]}" if b[k] && !Keypad::COLORS.key?(b[k]) }
|
||||
b["pulse_s"] = Float(b["pulse_s"]) if b["pulse_s"]
|
||||
if b["mode"] == "positions"
|
||||
raise ArgumentError, "#{b['input']}: positions need outputs" unless b["outputs"].is_a?(Array) && b["outputs"].any? && b["outputs"].all?(String)
|
||||
|
||||
b.delete("output")
|
||||
else
|
||||
b.delete("outputs")
|
||||
end
|
||||
%w[pulse_s period_s step].each { |k| b[k] = Float(b[k]) if b[k] }
|
||||
b
|
||||
end
|
||||
end
|
||||
@@ -561,9 +568,9 @@ module Maptool
|
||||
on = (KEYPAD_SCREEN_LEDS.dig(device.name, "on") || {}).dup
|
||||
if OUTPUTS
|
||||
bindings.each do |b|
|
||||
next unless b["output"] && b["input"].to_s.start_with?("#{device.name}.")
|
||||
next unless Outputs.outputs_of(b).any? && b["input"].to_s.start_with?("#{device.name}.")
|
||||
|
||||
on[b["input"].delete_prefix("#{device.name}.")] = OUTPUTS.on?(b["output"]) ? b.fetch("led", "red") : nil
|
||||
on[b["input"].delete_prefix("#{device.name}.")] = OUTPUTS.active?(b) ? b.fetch("led", "red") : nil
|
||||
end
|
||||
end
|
||||
KEYPAD.led_frames(device.name, on, KEYPAD_SCREEN_LEDS.dig(device.name, "blink"))
|
||||
@@ -1722,7 +1729,7 @@ module Maptool
|
||||
keys = d.protocol == "pkp" ? (1..d.keys).map { |k| "K#{k}" } : []
|
||||
{ name: d.name, protocol: d.protocol, node: d.node, channels: (keys + d.inputs.keys).uniq }
|
||||
end
|
||||
outputs = (OUTPUTS&.snapshot || []).flat_map { |m| m[:channels].map { |c| { output: "#{m[:name]}.#{c[:n]}", label: c[:label] } } }
|
||||
outputs = (OUTPUTS&.snapshot || []).flat_map { |m| m[:channels].map { |c| { output: "#{m[:name]}.#{c[:n]}", label: c[:label], dimmable: m[:dimmable] } } }
|
||||
json bindings: App.bindings, saved: File.exist?(BINDINGS_PATH), keypads: keypads, outputs: outputs,
|
||||
modes: Outputs::MODES, colors: Keypad::COLORS.keys - ["off"]
|
||||
end
|
||||
@@ -1751,7 +1758,7 @@ module Maptool
|
||||
get "/api/outputs" do
|
||||
require_login!
|
||||
halt 404, json(error: "no outputs in data/can.json") unless OUTPUTS
|
||||
bound = App.bindings.select { |b| b["output"] }
|
||||
bound = App.bindings.select { |b| Outputs.outputs_of(b).any? }
|
||||
json modules: OUTPUTS.snapshot, bindings: bound
|
||||
end
|
||||
|
||||
@@ -1764,7 +1771,7 @@ module Maptool
|
||||
halt 404, json(error: "no output #{output}") unless OUTPUTS.find(output)
|
||||
body = request.body.read
|
||||
on = body.empty? ? nil : JSON.parse(body)["on"]
|
||||
OUTPUTS.set(output, on.nil? ? !OUTPUTS.on?(output) : !!on)
|
||||
OUTPUTS.manual(output, on.nil? ? !OUTPUTS.on?(output) : !!on)
|
||||
json on: OUTPUTS.on?(output)
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user