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()
{
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;
}
Serial.println("RC-Tristate send!");
}
void controlRCOutlets(const char* sCodeWord) {