mirror of
https://github.com/Theaninova/Arduino-IRremote.git
synced 2026-01-05 13:02:49 +00:00
Introduced overflow detection code to the ISR State Machine
This commit is contained in:
25
irISR.cpp
25
irISR.cpp
@@ -4,22 +4,27 @@
|
|||||||
#include "IRremoteInt.h"
|
#include "IRremoteInt.h"
|
||||||
|
|
||||||
//+=============================================================================
|
//+=============================================================================
|
||||||
|
// Interrupt Service Routine - Fires every 50uS
|
||||||
// TIMER2 interrupt code to collect raw data.
|
// TIMER2 interrupt code to collect raw data.
|
||||||
// Widths of alternating SPACE, MARK are recorded in rawbuf.
|
// Widths of alternating SPACE, MARK are recorded in rawbuf.
|
||||||
// Recorded in ticks of 50 microseconds.
|
// Recorded in ticks of 50uS [microseconds, 0.000050 seconds]
|
||||||
// rawlen counts the number of entries recorded so far.
|
// 'rawlen' counts the number of entries recorded so far.
|
||||||
// First entry is the SPACE between transmissions.
|
// First entry is the SPACE between transmissions.
|
||||||
// As soon as a SPACE gets long, ready is set, state switches to IDLE, timing of SPACE continues.
|
// As soon as a the first [SPACE] entry gets long:
|
||||||
// As soon as first MARK arrives, gap width is recorded, ready is cleared, and new logging starts
|
// Ready is set; State switches to IDLE; Timing of SPACE continues.
|
||||||
|
// As soon as first MARK arrives:
|
||||||
|
// Gap width is recorded; Ready is cleared; New logging starts
|
||||||
//
|
//
|
||||||
ISR (TIMER_INTR_NAME)
|
ISR (TIMER_INTR_NAME)
|
||||||
{
|
{
|
||||||
TIMER_RESET;
|
TIMER_RESET;
|
||||||
|
|
||||||
uint8_t irdata = (uint8_t)digitalRead(irparams.recvpin);
|
// Read if IR Receiver -> SPACE [xmt LED off] or a MARK [xmt LED on]
|
||||||
|
// digitalRead() is very slow. Optimisation is possible, but makes the code unportable
|
||||||
|
uint8_t irdata = (uint8_t)digitalRead(irparams.recvpin);
|
||||||
|
|
||||||
irparams.timer++; // One more 50us tick
|
irparams.timer++; // One more 50uS tick
|
||||||
if (irparams.rawlen >= RAWBUF) irparams.rcvstate = STATE_STOP ; // Buffer overflow
|
if (irparams.rawlen >= RAWBUF) irparams.rcvstate = STATE_OVERFLOW ; // Buffer overflow
|
||||||
|
|
||||||
switch(irparams.rcvstate) {
|
switch(irparams.rcvstate) {
|
||||||
case STATE_IDLE: // In the middle of a gap
|
case STATE_IDLE: // In the middle of a gap
|
||||||
@@ -30,6 +35,7 @@ ISR (TIMER_INTR_NAME)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// gap just ended, record duration and start recording transmission
|
// gap just ended, record duration and start recording transmission
|
||||||
|
irparams.overflow = false;
|
||||||
irparams.rawlen = 0;
|
irparams.rawlen = 0;
|
||||||
irparams.rawbuf[irparams.rawlen++] = irparams.timer;
|
irparams.rawbuf[irparams.rawlen++] = irparams.timer;
|
||||||
irparams.timer = 0;
|
irparams.timer = 0;
|
||||||
@@ -64,6 +70,11 @@ ISR (TIMER_INTR_NAME)
|
|||||||
case STATE_STOP: // waiting, measuring gap
|
case STATE_STOP: // waiting, measuring gap
|
||||||
if (irdata == MARK) irparams.timer = 0 ; // reset gap timer
|
if (irdata == MARK) irparams.timer = 0 ; // reset gap timer
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case STATE_OVERFLOW: // Flag up a read overflow
|
||||||
|
irparams.overflow = true;
|
||||||
|
irparams.rcvstate = STATE_STOP;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (irparams.blinkflag) {
|
if (irparams.blinkflag) {
|
||||||
|
|||||||
@@ -57,8 +57,10 @@ void IRrecv::resume ( )
|
|||||||
// Results of decoding are stored in results
|
// Results of decoding are stored in results
|
||||||
int IRrecv::decode (decode_results *results)
|
int IRrecv::decode (decode_results *results)
|
||||||
{
|
{
|
||||||
results->rawbuf = irparams.rawbuf;
|
results->rawbuf = irparams.rawbuf;
|
||||||
results->rawlen = irparams.rawlen;
|
results->rawlen = irparams.rawlen;
|
||||||
|
|
||||||
|
results->overflow = irparams.overflow;
|
||||||
|
|
||||||
if (irparams.rcvstate != STATE_STOP) return false ;
|
if (irparams.rcvstate != STATE_STOP) return false ;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user