bug fixing

This commit is contained in:
Shannon Sterz 2016-01-18 23:17:34 +01:00
parent c97fa08e06
commit d69b6bc4aa

View file

@ -16,8 +16,9 @@ void setup()
void loop() void loop()
{ {
while(Serial.available()) { while(Serial.available()) {
if(index > 0 || (Serial.peek() >= 80 && Serial.peek() <= 95)) { uint8_t x = Serial.read();
message[index++] = Serial.read(); if(index > 0 || (x >= 80 && x <= 95)) {
message[index++] = x;
if(index > 7){ if(index > 7){
decodeMessage(); decodeMessage();
index = 0; index = 0;
@ -29,14 +30,10 @@ void loop()
void decodeMessage() { void decodeMessage() {
if(com) { if(com) {
int cmd = message[0]; int cmd = message[0];
Serial.println(cmd);
int pin = message[1] - 97; int pin = message[1] - 97;
Serial.println(pin); uint8_t val[6];
int val[6];
memcpy(val, message + 2, 6); memcpy(val, message + 2, 6);
for(int i =0;i<6;i++) {Serial.println(val[i]);}
switch (cmd) { switch (cmd) {
//case 80: break; //case 80: break;
//case 81: break; //case 81: break;
@ -63,7 +60,7 @@ void decodeMessage() {
} }
} }
void switchLight(int val[]) { void switchLight(uint8_t val[]) {
String triStateCode = ""; String triStateCode = "";
@ -73,18 +70,12 @@ void switchLight(int val[]) {
triStatePart = (triStatePart.length() < 2) ? String("0" + triStatePart) : triStatePart; triStatePart = (triStatePart.length() < 2) ? String("0" + triStatePart) : triStatePart;
triStateCode.concat(triStatePart); triStateCode.concat(triStatePart);
} }
char triState[triStateCode.length()]; char triState[triStateCode.length() + 1];
triStateCode.toCharArray(triState, triStateCode.length()); triStateCode.toUpperCase();
triStateCode.toCharArray(triState, triStateCode.length() + 1);
if(on) {
controlRCOutlets(triState); controlRCOutlets(triState);
Serial.println("Light is off."); Serial.println("RC-Tristate send!");
on = false;
} else {
controlRCOutlets(triState);
Serial.println("Light is on.");
on = true;
}
} }
void controlRCOutlets(const char* sCodeWord) { void controlRCOutlets(const char* sCodeWord) {