add irSend capability
This commit is contained in:
parent
1afb6e6588
commit
b1552598ea
1 changed files with 43 additions and 12 deletions
|
@ -58,9 +58,9 @@ void decodeMessage() {
|
|||
case 83: digitalR(pin); break;
|
||||
case 84: analogW(pin, val) break;
|
||||
case 85: analogR(pin) break;
|
||||
//case 86: break;
|
||||
case 86: handleRCDecimal(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();
|
||||
irReceive = millis() + 10000;
|
||||
break;
|
||||
|
@ -119,7 +119,7 @@ void analogW(uint8_t val[], int pin) {
|
|||
|
||||
if(p == -1) { if(debug) Serial.println("badpin"); return; }
|
||||
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) {
|
||||
|
||||
if (p == -1) { Serial.println("badpin"); return; }
|
||||
unsigned int length =(val[0]*256)+val[1];
|
||||
unsigned long value =(val[2]*16777216)+(val[3]*65536)+(val[4]*256)+val[5];
|
||||
unsigned int length = firsTwoToInt(val);
|
||||
unsigned long value = lastFourToLong(val);
|
||||
RCSwitch rc = RCSwitch();
|
||||
rc.enableTransmit(p);
|
||||
rc.send(value, length);
|
||||
|
@ -167,6 +167,27 @@ void sendRCTristate (uint8_t val[], int pin) {
|
|||
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) {
|
||||
|
||||
int codeType = results->decode_type;
|
||||
|
@ -190,3 +211,13 @@ void irRead(decode_results *results) {
|
|||
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];
|
||||
}
|
||||
|
|
Reference in a new issue