| 110 | #endif |
| 111 | |
| 112 | void IRrecv::ReceiveInterruptHandler() { |
| 113 | #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN) |
| 114 | digitalWriteFast(_IR_TIMING_TEST_PIN, HIGH); // 2 clock cycles |
| 115 | #endif |
| 116 | // 7 - 8.5 us for ISR body (without pushes and pops) for ATmega328 @16MHz |
| 117 | |
| 118 | #if defined(TIMER_REQUIRES_RESET_INTR_PENDING) |
| 119 | timerResetInterruptPending(); // reset TickCounterForISR interrupt flag if required (currently only for Teensy and ATmega4809) |
| 120 | #endif |
| 121 | |
| 122 | // Read if IR Receiver -> SPACE [xmt LED off] or a MARK [xmt LED on] |
| 123 | #if defined(__AVR__) |
| 124 | uint8_t tIRInputLevel = *irparams.IRReceivePinPortInputRegister & irparams.IRReceivePinMask; |
| 125 | #else |
| 126 | uint_fast8_t tIRInputLevel = (uint_fast8_t) digitalReadFast(irparams.IRReceivePin); |
| 127 | #endif |
| 128 | |
| 129 | uint_fast16_t tTickCounterForISR = irparams.TickCounterForISR; |
| 130 | /* |
| 131 | * Increase TickCounter and clip it at maximum 0xFFFF / 3.2 seconds at 50 us ticks |
| 132 | */ |
| 133 | if (irparams.TickCounterForISR < UINT16_MAX) { |
| 134 | tTickCounterForISR++; // One more 50uS tick |
| 135 | irparams.TickCounterForISR = tTickCounterForISR; |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * Due to a ESP32 compiler bug https://github.com/espressif/esp-idf/issues/1552 no switch statements are possible for ESP32 |
| 140 | * So we change the code to if / else if |
| 141 | */ |
| 142 | // switch (irparams.StateForISR) { |
| 143 | // |
| 144 | uint_fast8_t tStateForISR = irparams.StateForISR; |
| 145 | if (tStateForISR == IR_REC_STATE_IDLE) { |
| 146 | /* |
| 147 | * Here we are just resumed and wait for start bit. But in real time we may be in the middle of an ongoing transmission! |
| 148 | */ |
| 149 | if (tIRInputLevel == INPUT_MARK) { |
| 150 | // Check if we are not in the middle of an ongoing transmission by checking the minimum length of leading space |
| 151 | if (tTickCounterForISR > RECORD_GAP_TICKS) { |
| 152 | #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN) |
| 153 | // digitalWriteFast(_IR_TIMING_TEST_PIN, HIGH); // 2 clock cycles |
| 154 | #endif |
| 155 | /* |
| 156 | * Big gap between two transmissions just ended; Record gap duration + start recording transmission |
| 157 | * Initialize all state machine variables |
| 158 | */ |
| 159 | irparams.OverflowFlag = false; |
| 160 | // irparams.rawbuf[0] = irparams.TickCounterForISR; |
| 161 | // Usage of initialGapTicks enables usage of 8 bit buffer instead of 16 bit since 4.4, |
| 162 | // because the big gap value is not stored in this buffer any more |
| 163 | irparams.initialGapTicks = tTickCounterForISR; |
| 164 | irparams.rawlen = 1; |
| 165 | irparams.StateForISR = IR_REC_STATE_MARK; |
| 166 | } // otherwise stay in idle state |
| 167 | irparams.TickCounterForISR = 0; // reset counter in both cases |
| 168 | } |
| 169 |
no test coverage detected