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