From d69b6bc4aaf3b70cba9888ec5f7f35f5942d7978 Mon Sep 17 00:00:00 2001 From: Stefan Sterz Date: Mon, 18 Jan 2016 23:17:34 +0100 Subject: [PATCH] bug fixing --- arduino/src/sketch.ino | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/arduino/src/sketch.ino b/arduino/src/sketch.ino index 3122c5b..7290087 100644 --- a/arduino/src/sketch.ino +++ b/arduino/src/sketch.ino @@ -16,8 +16,9 @@ void setup() void loop() { while(Serial.available()) { - if(index > 0 || (Serial.peek() >= 80 && Serial.peek() <= 95)) { - message[index++] = Serial.read(); + uint8_t x = Serial.read(); + if(index > 0 || (x >= 80 && x <= 95)) { + message[index++] = x; if(index > 7){ decodeMessage(); index = 0; @@ -29,14 +30,10 @@ void loop() void decodeMessage() { if(com) { int cmd = message[0]; - Serial.println(cmd); int pin = message[1] - 97; - Serial.println(pin); - int val[6]; + uint8_t val[6]; memcpy(val, message + 2, 6); - for(int i =0;i<6;i++) {Serial.println(val[i]);} - switch (cmd) { //case 80: break; //case 81: break; @@ -63,7 +60,7 @@ void decodeMessage() { } } -void switchLight(int val[]) { +void switchLight(uint8_t val[]) { String triStateCode = ""; @@ -73,18 +70,12 @@ void switchLight(int val[]) { triStatePart = (triStatePart.length() < 2) ? String("0" + triStatePart) : triStatePart; triStateCode.concat(triStatePart); } - char triState[triStateCode.length()]; - triStateCode.toCharArray(triState, triStateCode.length()); + char triState[triStateCode.length() + 1]; + triStateCode.toUpperCase(); + triStateCode.toCharArray(triState, triStateCode.length() + 1); - if(on) { - controlRCOutlets(triState); - Serial.println("Light is off."); - on = false; - } else { - controlRCOutlets(triState); - Serial.println("Light is on."); - on = true; - } + controlRCOutlets(triState); + Serial.println("RC-Tristate send!"); } void controlRCOutlets(const char* sCodeWord) {