Skip to content
This repository was archived by the owner on Dec 2, 2023. It is now read-only.

Commit dcea4b3

Browse files
committed
Merge back irISR.cpp into irRemote.cpp to avoid an issue due to the absence of exported symbols from irISR.cpp
see https://github.com/z3t0/Arduino-IRremote/issues/214 sudar/Arduino-Makefile#376 In some circumstances the linker skips irISR.cpp irRemote.cpp is always included (by the linker). Andrea
1 parent 4819726 commit dcea4b3

File tree

2 files changed

+86
-88
lines changed

2 files changed

+86
-88
lines changed

IRremote.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
// Whynter A/C ARC-110WD added by Francesco Meschia
1919
//******************************************************************************
2020

21+
#include <avr/interrupt.h>
22+
2123
// Defining IR_GLOBAL here allows us to declare the instantiation of global variables
2224
#define IR_GLOBAL
2325
# include "IRremote.h"
@@ -88,3 +90,87 @@ int MATCH_SPACE (int measured_ticks, int desired_us)
8890
return ((measured_ticks >= TICKS_LOW (desired_us - MARK_EXCESS))
8991
&& (measured_ticks <= TICKS_HIGH(desired_us - MARK_EXCESS)));
9092
}
93+
94+
//+=============================================================================
95+
// Interrupt Service Routine - Fires every 50uS
96+
// TIMER2 interrupt code to collect raw data.
97+
// Widths of alternating SPACE, MARK are recorded in rawbuf.
98+
// Recorded in ticks of 50uS [microseconds, 0.000050 seconds]
99+
// 'rawlen' counts the number of entries recorded so far.
100+
// First entry is the SPACE between transmissions.
101+
// As soon as a the first [SPACE] entry gets long:
102+
// Ready is set; State switches to IDLE; Timing of SPACE continues.
103+
// As soon as first MARK arrives:
104+
// Gap width is recorded; Ready is cleared; New logging starts
105+
//
106+
ISR (TIMER_INTR_NAME)
107+
{
108+
TIMER_RESET;
109+
110+
// Read if IR Receiver -> SPACE [xmt LED off] or a MARK [xmt LED on]
111+
// digitalRead() is very slow. Optimisation is possible, but makes the code unportable
112+
uint8_t irdata = (uint8_t)digitalRead(irparams.recvpin);
113+
114+
irparams.timer++; // One more 50uS tick
115+
if (irparams.rawlen >= RAWBUF) irparams.rcvstate = STATE_OVERFLOW ; // Buffer overflow
116+
117+
switch(irparams.rcvstate) {
118+
//......................................................................
119+
case STATE_IDLE: // In the middle of a gap
120+
if (irdata == MARK) {
121+
if (irparams.timer < GAP_TICKS) { // Not big enough to be a gap.
122+
irparams.timer = 0;
123+
124+
} else {
125+
// Gap just ended; Record duration; Start recording transmission
126+
irparams.overflow = false;
127+
irparams.rawlen = 0;
128+
irparams.rawbuf[irparams.rawlen++] = irparams.timer;
129+
irparams.timer = 0;
130+
irparams.rcvstate = STATE_MARK;
131+
}
132+
}
133+
break;
134+
//......................................................................
135+
case STATE_MARK: // Timing Mark
136+
if (irdata == SPACE) { // Mark ended; Record time
137+
irparams.rawbuf[irparams.rawlen++] = irparams.timer;
138+
irparams.timer = 0;
139+
irparams.rcvstate = STATE_SPACE;
140+
}
141+
break;
142+
//......................................................................
143+
case STATE_SPACE: // Timing Space
144+
if (irdata == MARK) { // Space just ended; Record time
145+
irparams.rawbuf[irparams.rawlen++] = irparams.timer;
146+
irparams.timer = 0;
147+
irparams.rcvstate = STATE_MARK;
148+
149+
} else if (irparams.timer > GAP_TICKS) { // Space
150+
// A long Space, indicates gap between codes
151+
// Flag the current code as ready for processing
152+
// Switch to STOP
153+
// Don't reset timer; keep counting Space width
154+
irparams.rcvstate = STATE_STOP;
155+
}
156+
break;
157+
//......................................................................
158+
case STATE_STOP: // Waiting; Measuring Gap
159+
if (irdata == MARK) irparams.timer = 0 ; // Reset gap timer
160+
break;
161+
//......................................................................
162+
case STATE_OVERFLOW: // Flag up a read overflow; Stop the State Machine
163+
irparams.overflow = true;
164+
irparams.rcvstate = STATE_STOP;
165+
break;
166+
}
167+
168+
// If requested, flash LED while receiving IR data
169+
if (irparams.blinkflag) {
170+
if (irdata == MARK)
171+
if (irparams.blinkpin) digitalWrite(irparams.blinkpin, HIGH); // Turn user defined pin LED on
172+
else BLINKLED_ON() ; // if no user defined LED pin, turn default LED pin for the hardware on
173+
else if (irparams.blinkpin) digitalWrite(irparams.blinkpin, LOW); // Turn user defined pin LED on
174+
else BLINKLED_OFF() ; // if no user defined LED pin, turn default LED pin for the hardware on
175+
}
176+
}

irISR.cpp

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)