add irSend capability

This commit is contained in:
Shannon Sterz 2016-01-25 23:29:21 +01:00
parent 1afb6e6588
commit b1552598ea

View file

@ -58,9 +58,9 @@ void decodeMessage() {
case 83: digitalR(pin); break; case 83: digitalR(pin); break;
case 84: analogW(pin, val) break; case 84: analogW(pin, val) break;
case 85: analogR(pin) break; case 85: analogR(pin) break;
//case 86: break; case 86: handleRCDecimal(val, pin) break;
case 87: sendRCTristate(val, pin); break; case 87: sendRCTristate(val, pin); break;
//case 88: break; case 88: irSend(val[0], val[1], lastFourToLong(val)) break;
case 89: irrecv.enableIRIn(); case 89: irrecv.enableIRIn();
irReceive = millis() + 10000; irReceive = millis() + 10000;
break; break;
@ -119,7 +119,7 @@ void analogW(uint8_t val[], int pin) {
if(p == -1) { if(debug) Serial.println("badpin"); return; } if(p == -1) { if(debug) Serial.println("badpin"); return; }
pinMode(p, OUTPUT); pinMode(p, OUTPUT);
analogWrite(p,(256*val[0])+val[1]); analogWrite(p,firsTwoToInt(val));
} }
@ -135,8 +135,8 @@ void analogR(int pin) {
void handleRCDecimal(uint8_t val[], int pin) { void handleRCDecimal(uint8_t val[], int pin) {
if (p == -1) { Serial.println("badpin"); return; } if (p == -1) { Serial.println("badpin"); return; }
unsigned int length =(val[0]*256)+val[1]; unsigned int length = firsTwoToInt(val);
unsigned long value =(val[2]*16777216)+(val[3]*65536)+(val[4]*256)+val[5]; unsigned long value = lastFourToLong(val);
RCSwitch rc = RCSwitch(); RCSwitch rc = RCSwitch();
rc.enableTransmit(p); rc.enableTransmit(p);
rc.send(value, length); rc.send(value, length);
@ -167,6 +167,27 @@ void sendRCTristate (uint8_t val[], int pin) {
Serial.println(triState); Serial.println(triState);
} }
void irSend(int type, int length, unsigned long val) {
for(int i = 0; i < 3; i++) {
switch (type) {
case RC5: irsend.sendRC5(val, length); break;
case RC6: irsend.sendRC6(val, length); break;
case NEC: if (i) { irsend.sendNEC(REPEAT, length);
} else { irsend.sendNEC(val, length);} break;
case SONY: irsend.sendSony(val, length); break;
case PANASONIC: irsend.sendPanasonic(length, val); break;
case JVC: irsend.sendJVC(val, length, i); break;
case SAMSUNG: irsend.sendSAMSUNG(val, length); break;
case WHYNTER: irsend.sendWhynter(val, length); break;
case LG: irsend.sendLG(val, length); break;
case DISH: irsend.sendDISH(val, length); break;
case DENON: irsend.sendDenon(val, length); break;
}
delay(10);
}
}
void irRead(decode_results *results) { void irRead(decode_results *results) {
int codeType = results->decode_type; int codeType = results->decode_type;
@ -190,3 +211,13 @@ void irRead(decode_results *results) {
Serial.println(m); Serial.println(m);
} }
} }
// Helpers
unsigned int firsTwoToInt(uint8_t val[]) {
return val[0] * 256 + val[1];
}
unsigned long lastFourToLong(uint8_t val[]) {
return val[2]*16777216 + val[3]*65536 + val[4]*256 + val[5];
}