add irRead functionality

This commit is contained in:
Shannon Sterz 2016-01-21 17:43:29 +01:00
parent 569c6d96ac
commit 9cbf8c2419

View file

@ -1,8 +1,16 @@
#include <RCSwitch.h>
#include <IRremote.h>
// Necessary IR Globals
int RECV_PIN = 10;
IRrecv irrecv(RECV_PIN);
IRsend irsend;
decode_results results;
uint8_t message[8];
int index = 0;
boolean com = false;
int irReceive = 0;
void setup()
{
@ -11,16 +19,27 @@ void setup()
void loop()
{
while(Serial.available()) {
uint8_t x = Serial.read();
if(index > 0 || (x >= 80 && x <= 95)) {
message[index++] = x;
if(index > 7){
decodeMessage();
index = 0;
if (irReceive < millis() && irrecv.decode(&results)) {
irRead(&results);
irrecv.resume();
} else {
while(Serial.available()) {
uint8_t x = Serial.read();
if(index > 0 || (x >= 80 && x <= 95)) {
message[index++] = x;
if(index > 7){
decodeMessage();
index = 0;
}
}
}
}
}
void decodeMessage() {
@ -40,10 +59,12 @@ void decodeMessage() {
//case 84: break;
//case 85: break;
//case 86: break;
case 87: sendRCTristate(val, pin); break;
case 87: sendRCTristate(val, pin); break;
//case 88: break;
//case 89: break;
default: break;
case 89: irrecv.enableIRIn();
irReceive = millis() + 10000;
break;
default: break;
}
} else if(cmd == 90) {
@ -90,8 +111,7 @@ void digitalR(int pin) {
if(pin == -1) { Serial.println("badpin"); return; }
pinMode(pin, INPUT);
int digraw = digitalRead(pin);
String m = String(pin + '::' + digraw);
Serial.println(m);
Serial.println(String(pin + '::' + digraw));
}
@ -115,4 +135,29 @@ void sendRCTristate (uint8_t val[], int pin) {
rc.sendTriState(triState);
Serial.println("RC-Tristate send!");
}
void irRead(decode_results *results) {
unsigned long codeValue;
int codeLen;
int codeType = results->decode_type;
if (codeType == UNKNOWN) {
Serial.println("Unknown IR Protocol!");
} else {
if (codeType == NEC) {
if (results->value == REPEAT) {
return;
}
}
codeValue = results->value;
codeLen = results->bits;
String m = String(codeType + "::" + codeValue);
Serial.println(String(m + "::" + codeLen));
}
}