summaryrefslogtreecommitdiffstats
path: root/onkyo_ri.pde
diff options
context:
space:
mode:
Diffstat (limited to 'onkyo_ri.pde')
-rw-r--r--onkyo_ri.pde36
1 files changed, 15 insertions, 21 deletions
diff --git a/onkyo_ri.pde b/onkyo_ri.pde
index 89adcfc..2a6aa7b 100644
--- a/onkyo_ri.pde
+++ b/onkyo_ri.pde
@@ -24,14 +24,9 @@ MD = 71808
#define RESOLUTION 20
#define FUZZINESS 20
-int header[] = {300, 100};
-int values[2][2] = { {100, 100}, {100, 200} };
-int trail[] = { 100 };
-uint8_t bits = 12;
-
uint8_t raw[2];
-uint64_t listenForIR(void);
+uint64_t listenForIR(ir_t *proto);
int getPulseLength();
int getPulseLengthInRange(int expected);
@@ -42,7 +37,7 @@ void setup(void) {
}
void loop(void) {
- uint64_t code = listenForIR();
+ uint64_t code = listenForIR(&onkyo);
Serial.println(code, HEX);
}
@@ -82,36 +77,35 @@ int getPulseLengthInRange(int expected) {
return length;
}
-uint64_t listenForIR(void) {
+uint64_t listenForIR(ir_t *proto) {
int length;
uint64_t code;
- uint8_t i;
+ uint8_t i, j, k;
+ bool found;
start:
code = 0;
- for (i = 0; i < ARRAY_LEN(header); i++) {
- length = getPulseLengthInRange(header[i]);
+ for (i = 0; i < ARRAY_LEN(proto->header); i++) {
+ length = getPulseLengthInRange(proto->header[i]);
- if ((length == 0) || (length < 0))
+ if (length <= 0)
goto start;
}
- for (uint8_t j = 0; j < bits; j++) {
+ for (j = 0; j < proto->bits; j++) {
for (i = 0; i < ARRAY_LEN(raw); i++) {
raw[i] = getPulseLength();
- if ((raw[i] == 0) || (raw[i] < 0))
+ if (raw[i] <= 0)
goto start;
}
- bool found;
-
- for (uint8_t k = 0; k < ARRAY_LEN(values); k++) {
+ for (k = 0; k < ARRAY_LEN(proto->values); k++) {
found = true;
for (i = 0; i < ARRAY_LEN(raw); i++) {
- if (!inRange(raw[i], values[k][i])) {
+ if (!inRange(raw[i], proto->values[k][i])) {
found = false;
break;
}
@@ -132,10 +126,10 @@ start:
}
}
- for (i = 0; i < ARRAY_LEN(trail); i++) {
- length = getPulseLengthInRange(trail[i]);
+ for (i = 0; i < ARRAY_LEN(proto->trail); i++) {
+ length = getPulseLengthInRange(proto->trail[i]);
- if ((length == 0) || (length < 0))
+ if (length <= 0)
goto start;
}