add arduino debug mode

This commit is contained in:
Shannon Sterz 2016-01-30 18:10:23 +01:00
parent 74758e7d00
commit 5a4a362b11

View file

@ -10,6 +10,7 @@ decode_results results;
uint8_t message[8];
int index = 0;
boolean com = false;
boolean debug = false;
int irReceive = 0;
void setup()
@ -52,7 +53,7 @@ void decodeMessage() {
memcpy(val, message + 2, 6);
switch (cmd) {
//case 80: break;
case 80: debug = debug ? false : true; break;
case 81: setMode(val[0], pin); break;
case 82: digitalW(val[0], pin); break;
case 83: digitalR(pin); break;
@ -83,19 +84,21 @@ void decodeMessage() {
void setMode(uint8_t val, int pin) {
if(pin == -1) { Serial.println("badpin"); return; }
if(pin == -1) { if(debug) Serial.println("badpin"); return; }
if (val == 0) {
pinMode(pin, OUTPUT);
if(debug) {Serial.print('Set OUTPUT on pin:');Serial.println(pin);}
} else {
pinMode(pin, INPUT);
if(debug) {Serial.print('Set INPUT on pin:');Serial.println(pin);}
}
}
void digitalW(uint8_t val, int pin) {
if(pin == -1) { Serial.println("badpin"); return; }
if(pin == -1) { if(debug) Serial.println("badpin"); return; }
pinMode(pin, OUTPUT);
if(val == 0) {
@ -103,15 +106,16 @@ void digitalW(uint8_t val, int pin) {
} else {
digitalWrite(pin, HIGH);
}
Serial.print(pin);
Serial.print(' wrote ');
Serial.println(val);
if(debug) {
Serial.print(pin);
Serial.print(' wrote ');
Serial.println(val);
}
}
void digitalR(int pin) {
if(pin == -1) { Serial.println("badpin"); return; }
if(pin == -1) { if(debug) Serial.println("badpin"); return; }
pinMode(pin, INPUT);
int digraw = digitalRead(pin);
Serial.print(pin);
@ -122,18 +126,20 @@ void digitalR(int pin) {
void analogW(uint8_t val[], int pin) {
if(pin == -1) { Serial.println("badpin"); return; }
if(pin == -1) { if(debug) Serial.println("badpin"); return; }
pinMode(pin, OUTPUT);
analogWrite(pin,firsTwoToInt(val));
Serial.print(pin);
Serial.print(' wrote ');
Serial.println((int)val);
if(debug) {
Serial.print(pin);
Serial.print(' wrote ');
Serial.println((int)val);
}
}
void analogR(int pin) {
if(pin == -1) { Serial.println("badpin"); return; }
if(pin == -1) { if(debug) Serial.println("badpin"); return; }
pinMode(pin, INPUT);
int rval = analogRead(pin);
Serial.print(pin);
@ -144,19 +150,21 @@ void analogR(int pin) {
void handleRCDecimal(uint8_t val[], int pin) {
if (pin == -1) { Serial.println("badpin"); return; }
if (pin == -1) { if(debug) Serial.println("badpin"); return; }
unsigned int length = firsTwoToInt(val);
unsigned long value = lastFourToLong(val);
RCSwitch rc = RCSwitch();
rc.enableTransmit(pin);
rc.send(value, length);
Serial.print('RC Decimal: ');
Serial.println(value);
if(debug) {
Serial.print('RC Decimal: ');
Serial.println(value);
}
}
void sendRCTristate (uint8_t val[], int pin) {
if(pin == -1) { Serial.println("badpin"); return; }
if(pin == -1) { if(debug) Serial.println("badpin"); return; }
String triStateCode = "";
RCSwitch rc = RCSwitch();
@ -174,8 +182,10 @@ void sendRCTristate (uint8_t val[], int pin) {
rc.sendTriState(triState);
delay(500);
Serial.print("RC-Tristate send: ");
Serial.println(triState);
if(debug) {
Serial.print("RC-Tristate send: ");
Serial.println(triState);
}
}
void irSend(int type, int length, unsigned long val) {
@ -197,6 +207,7 @@ void irSend(int type, int length, unsigned long val) {
}
delay(10);
}
if(debug) {Serial.println('IR send!');}
}
void irRead(decode_results *results) {
@ -205,7 +216,7 @@ void irRead(decode_results *results) {
if (codeType == UNKNOWN) {
Serial.println("Unknown IR Protocol!");
if(debug) {Serial.println("Unknown IR Protocol!"); }
} else {