Commit 4bfaa9ae authored by Max Becker's avatar Max Becker
Browse files

Loosen tolerances

Remove IDLE gap counter (causing trouble due to overflows)
Use gcc built in parity bit calculation
parent 9150de60
......@@ -12,15 +12,15 @@
//Precalculating these reduces run time (but might increase program size slightly.
//In addition the precalculation done by the compiler produces some strange results. Or maybe I am just too stupid
#define START_MARK_LOW_T 90
#define START_MARK_HIGH_T 200
#define START_MARK_HIGH_T 220
#define START_SPACE_LOW_T 50
#define START_SPACE_HIGH_T 100
#define START_SPACE_HIGH_T 120
#define ONE_SPACE_LOW_T 20
#define ONE_SPACE_HIGH_T 43
#define ONE_SPACE_HIGH_T 40
#define ZERO_SPACE_LOW_T 7
#define ZERO_SPACE_HIGH_T 15
#define ZERO_SPACE_HIGH_T 19
#define BIT_MARK_LOW_T 7
#define BIT_MARK_HIGH_T 17
#define BIT_MARK_HIGH_T 20
#endif //IR_PROTOCOL_H
......@@ -36,6 +36,9 @@ ISR(IR_IN_TIMER_INTR_NAME) {
//If any receiver should be low (MARK), the corresponding receiver bit should be 1. We consider this as a MARK
bool irdata = irdata1 || irdata2;
if (irdata) {
// PORTA |= (1 << PA6); //Set output off
}
//Remember any receiver bit active during any mark. These two bytes are only reset after a complete transmission, so at the end we should have a one for every receiver which was active for at least one tick during the transmission
if (irdata1) {
active_pins_one |= irdata1;
......@@ -53,17 +56,14 @@ ISR(IR_IN_TIMER_INTR_NAME) {
//......................................................................
case STATE_IDLE: // In the middle of a gap
if (irdata) {
if (irparams.timer < GAP_TICKS) { // Not big enough to be a gap.
irparams.timer = 0;
} else {
// Gap just ended; Record duration; Start recording transmission
irparams.overflow = false;
irparams.rawlen = 0;
irparams.rawbuf[irparams.rawlen++] = irparams.timer;
irparams.timer = 0;
irparams.rcvstate = STATE_MARK;
}
}
break;
//......................................................................
......@@ -113,13 +113,18 @@ int MATCH(uint8_t measured_ticks, uint8_t min, uint8_t max) {
//200 byte
bool decodeData(decode_results *results) {
DISABLE_IR_IN_INTR;
if (irparams.rawlen < 2 * 11 +
3) //We expect 11 bits + start mark and space + end bit mark. Since the pre signal gap is counted too, we probably want one more
return false;
uint16_t data = 0; //Store binary result
uint16_t data = 0; //Store binary result. 16 bit variable (uint16_t) is bad for performance but makes stuff simpler
int offset = 1; //Buffer index. Skip 0 as it contains the gap
if (!MATCH(irparams.rawbuf[offset++], START_MARK_LOW_T, START_MARK_HIGH_T)) return false;
#ifdef DEBUG_BLINK
......@@ -129,8 +134,10 @@ bool decodeData(decode_results *results) {
delay(100);
#endif
if (!MATCH(irparams.rawbuf[offset++], START_SPACE_LOW_T, START_SPACE_HIGH_T)) return false;
#ifdef DEBUG_BLINK
PORTA |= (1 << PA1); //Set output off
delay(1000);
......@@ -140,8 +147,11 @@ bool decodeData(decode_results *results) {
//Decode bits.
for (int i = 0; i < 11; i++) {
if (!MATCH(irparams.rawbuf[offset++], BIT_MARK_LOW_T, BIT_MARK_HIGH_T)) return false;
#ifdef DEBUG_BLINK
PORTA |= (1 << PA2); //Set output off
delay(500);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment