Simplify the commands and fix a small bug

This commit is contained in:
Aaron Mueller 2014-06-23 23:28:29 +02:00
parent ed8bee4df2
commit e07d8124e1
2 changed files with 10 additions and 7 deletions

View file

@ -1,4 +1,3 @@
// https://code.google.com/p/rc-switch/ // https://code.google.com/p/rc-switch/
#include <RCSwitch.h> #include <RCSwitch.h>
@ -9,7 +8,6 @@ boolean command_complete = false;
RCSwitch rc_switch = RCSwitch(); RCSwitch rc_switch = RCSwitch();
void setup() { void setup() {
pinMode(led_stripe, OUTPUT); pinMode(led_stripe, OUTPUT);
Serial.begin(9600); Serial.begin(9600);
@ -18,10 +16,10 @@ void setup() {
} }
void process_command(String command, String param) { void process_command(String command, String param) {
if (command == "fade") fade_to(param.toInt()); if (command == "fade" || command == "f") fade_to(param.toInt());
if (command == "led") toggle_stripes(param); if (command == "led" || command == "l") toggle_stripes(param);
if (command == "on") switch_230("on", param); if (command == "on" || command == "1") switch_230("on", param);
if (command == "off") switch_230("off", param); if (command == "off" || command == "0") switch_230("off", param);
Serial.println("Ok"); Serial.println("Ok");
} }
@ -85,4 +83,3 @@ void serialEvent() {
} }
} }
} }

View file

@ -3,6 +3,12 @@
require 'rubygems' require 'rubygems'
require 'serialport' 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| SerialPort.open('/dev/ttyUSB0', 9600, 8, 1, SerialPort::NONE) do |s|
s.puts(ARGV.join(' ')) s.puts(ARGV.join(' '))
end end