diff --git a/emori.ino b/emori.ino index 62e36ff..44a6d1f 100644 --- a/emori.ino +++ b/emori.ino @@ -16,10 +16,24 @@ void setup() { } void process_command(String command, String param) { + // LED Stripes if (command == "fade" || command == "f") fade_to(param.toInt()); 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"); } @@ -33,12 +47,15 @@ void switch_230(String state, String number) { if (number == "d") device = "00010"; if (number == "e") device = "00001"; - if (state == "on") rc_switch.switchOn(code, device); - if (state == "off") rc_switch.switchOff(code, device); + if (state == "on" || state == "1") { + rc_switch.switchOn(code, device); + } else { + rc_switch.switchOff(code, device); + } } void toggle_stripes(String on_or_off) { - if (on_or_off == "on") { + if (on_or_off == "on" || on_or_off == "1") { fade_to(255); digitalWrite(led_stripe, HIGH); } else { diff --git a/emori.rb b/emori.rb index 9271e9d..918018b 100755 --- a/emori.rb +++ b/emori.rb @@ -10,15 +10,5 @@ abort unless File.exists?('/dev/ttyUSB0') # Create the serial connection and send the given command. SerialPort.open('/dev/ttyUSB0', 9600, 8, 1, SerialPort::NONE) do |s| - command = 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 + s.puts(ARGV.join(' ')) end