Make the commands more convenient and add an all on/off command.

This commit is contained in:
Aaron Mueller 2014-06-29 15:36:47 +02:00
parent 2c056367e2
commit c4a8f23e58
2 changed files with 23 additions and 16 deletions

View file

@ -16,10 +16,24 @@ void setup() {
} }
void process_command(String command, String param) { void process_command(String command, String param) {
// LED Stripes
if (command == "fade" || command == "f") fade_to(param.toInt()); if (command == "fade" || command == "f") fade_to(param.toInt());
if (command == "led" || command == "l") toggle_stripes(param); if (command == "led" || command == "l") toggle_stripes(param);
if (command == "on" || command == "1") switch_230("on", param);
if (command == "off" || command == "0") switch_230("off", param); // Radio switches
if (command == "a" ||
command == "b" ||
command == "c" ||
command == "d") switch_230(param, command);
// Turn all on or off
if (command == "off" || command == "on") {
switch_230(command, "a");
switch_230(command, "b");
switch_230(command, "c");
switch_230(command, "d");
toggle_stripes(command);
}
Serial.println("Ok"); Serial.println("Ok");
} }
@ -33,12 +47,15 @@ void switch_230(String state, String number) {
if (number == "d") device = "00010"; if (number == "d") device = "00010";
if (number == "e") device = "00001"; if (number == "e") device = "00001";
if (state == "on") rc_switch.switchOn(code, device); if (state == "on" || state == "1") {
if (state == "off") rc_switch.switchOff(code, device); rc_switch.switchOn(code, device);
} else {
rc_switch.switchOff(code, device);
}
} }
void toggle_stripes(String on_or_off) { void toggle_stripes(String on_or_off) {
if (on_or_off == "on") { if (on_or_off == "on" || on_or_off == "1") {
fade_to(255); fade_to(255);
digitalWrite(led_stripe, HIGH); digitalWrite(led_stripe, HIGH);
} else { } else {

View file

@ -10,15 +10,5 @@ abort unless File.exists?('/dev/ttyUSB0')
# Create the serial connection and send the given command. # Create the serial connection and send the given command.
SerialPort.open('/dev/ttyUSB0', 9600, 8, 1, SerialPort::NONE) do |s| SerialPort.open('/dev/ttyUSB0', 9600, 8, 1, SerialPort::NONE) do |s|
command = ARGV.join(' ') s.puts(ARGV.join(' '))
if command == 'on' or command == 'off'
puts 'all ' + command + '...'
['a', 'b', 'c', 'd'].each do |port|
s.puts(command + ' ' + port)
end
s.puts('led ' + command)
else
s.puts(ARGV.join(' '))
end
end end