diff --git a/emori.ino b/emori.ino index b31bbf5..62e36ff 100644 --- a/emori.ino +++ b/emori.ino @@ -1,4 +1,3 @@ - // https://code.google.com/p/rc-switch/ #include @@ -9,7 +8,6 @@ boolean command_complete = false; RCSwitch rc_switch = RCSwitch(); - void setup() { pinMode(led_stripe, OUTPUT); Serial.begin(9600); @@ -18,10 +16,10 @@ void setup() { } void process_command(String command, String param) { - if (command == "fade") fade_to(param.toInt()); - if (command == "led") toggle_stripes(param); - if (command == "on") switch_230("on", param); - if (command == "off") switch_230("off", param); + 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); Serial.println("Ok"); } @@ -85,4 +83,3 @@ void serialEvent() { } } } - diff --git a/emori.rb b/emori.rb index 6bc7dad..918018b 100755 --- a/emori.rb +++ b/emori.rb @@ -3,6 +3,12 @@ require 'rubygems' require 'serialport' +# If the main monitor is off, the Arduino is also off because it is connected to +# the USB hub inside the monitor. So, if the main monitor is off, the user can't +# control the lights any more and the LED stripes are off too. +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| s.puts(ARGV.join(' ')) end