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,6 +19,14 @@ void setup()
void loop()
{
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)) {
@ -21,6 +37,9 @@ void loop()
}
}
}
}
}
void decodeMessage() {
@ -42,7 +61,9 @@ void decodeMessage() {
//case 86: break;
case 87: sendRCTristate(val, pin); break;
//case 88: break;
//case 89: break;
case 89: irrecv.enableIRIn();
irReceive = millis() + 10000;
break;
default: break;
}
@ -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));
}
@ -116,3 +136,28 @@ 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));
}
}