diff --git a/keywords.txt b/keywords.txt index ea6e019..f2b9a49 100644 --- a/keywords.txt +++ b/keywords.txt @@ -14,6 +14,7 @@ IRsend KEYWORD1 # Methods and Functions (KEYWORD2) ####################################### +blink13 KEYWORD2 decode KEYWORD2 enableIRIn KEYWORD2 resume KEYWORD2 diff --git a/src/IRremote.cpp b/src/IRremote.cpp index c8730d7..f41f818 100644 --- a/src/IRremote.cpp +++ b/src/IRremote.cpp @@ -127,6 +127,7 @@ ISR (TIMER_INTR_NAME) { TIMER_RESET; + // 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); @@ -184,4 +185,14 @@ ISR (TIMER_INTR_NAME) break; } +#ifdef BLINKLED + // If requested, flash LED while receiving IR data + if (irparams.blinkflag) { + if (irdata == MARK) + if (irparams.blinkpin) digitalWrite(irparams.blinkpin, HIGH); // Turn user defined pin LED on + else BLINKLED_ON() ; // if no user defined LED pin, turn default LED pin for the hardware on + else if (irparams.blinkpin) digitalWrite(irparams.blinkpin, LOW); // Turn user defined pin LED on + else BLINKLED_OFF() ; // if no user defined LED pin, turn default LED pin for the hardware on + } +#endif // BLINKLED } diff --git a/src/IRremote.h b/src/IRremote.h index 40f28dc..9282843 100644 --- a/src/IRremote.h +++ b/src/IRremote.h @@ -172,8 +172,9 @@ class IRrecv { public: IRrecv (int recvpin) ; - IRrecv (int recvpin); + IRrecv (int recvpin, int blinkpin); + void blink13 (int blinkflag) ; int decode (decode_results *results) ; void enableIRIn ( ) ; bool isIdle ( ) ; diff --git a/src/IRremoteInt.h b/src/IRremoteInt.h index 08f162e..1baa05d 100644 --- a/src/IRremoteInt.h +++ b/src/IRremoteInt.h @@ -41,6 +41,8 @@ typedef // The fields are ordered to reduce memory over caused by struct-padding uint8_t rcvstate; // State Machine state uint8_t recvpin; // Pin connected to IR data from detector + uint8_t blinkpin; + uint8_t blinkflag; // true -> enable blinking of pin on IR processing uint8_t rawlen; // counter of entries in rawbuf unsigned int timer; // State timer, counts 50uS ticks. unsigned int rawbuf[RAWBUF]; // raw data diff --git a/src/boarddefs.h b/src/boarddefs.h index 5751ba7..5c49465 100644 --- a/src/boarddefs.h +++ b/src/boarddefs.h @@ -47,10 +47,29 @@ // is not configurable on the current board. //------------------------------------------------------------------------------ -// Soft Carrier fallback for SAM and SAMD architectures +// Defines for blinking the LED // +#if defined(CORE_LED0_PIN) +# define BLINKLED CORE_LED0_PIN +# define BLINKLED_ON() (digitalWrite(CORE_LED0_PIN, HIGH)) +# define BLINKLED_OFF() (digitalWrite(CORE_LED0_PIN, LOW)) + +#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +# define BLINKLED 13 +# define BLINKLED_ON() (PORTB |= B10000000) +# define BLINKLED_OFF() (PORTB &= B01111111) + +#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) +# define BLINKLED 0 +# define BLINKLED_ON() (PORTD |= B00000001) +# define BLINKLED_OFF() (PORTD &= B11111110) + #elif defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD) +# define BLINKLED LED_BUILTIN +# define BLINKLED_ON() (digitalWrite(LED_BUILTIN, HIGH)) +# define BLINKLED_OFF() (digitalWrite(LED_BUILTIN, LOW)) + # define USE_SOFT_CARRIER // Define to use spin wait instead of delayMicros() //# define USE_SPIN_WAIT @@ -60,6 +79,8 @@ # define SEND_PIN 9 #elif defined(ESP32) + // No system LED on ESP32, disable blinking by NOT defining BLINKLED + // avr/interrupt.h is not present # undef HAS_AVR_INTERRUPT_H @@ -69,6 +90,10 @@ // Supply own enbleIRIn # undef USE_DEFAULT_ENABLE_IR_IN +#else +# define BLINKLED 13 +# define BLINKLED_ON() (PORTB |= B00100000) +# define BLINKLED_OFF() (PORTB &= B11011111) #endif //------------------------------------------------------------------------------ diff --git a/src/irRecv.cpp b/src/irRecv.cpp index 8498e16..b549dac 100644 --- a/src/irRecv.cpp +++ b/src/irRecv.cpp @@ -99,11 +99,15 @@ int IRrecv::decode (decode_results *results) IRrecv::IRrecv (int recvpin) { irparams.recvpin = recvpin; + irparams.blinkflag = 0; } -IRrecv::IRrecv (int recvpin) +IRrecv::IRrecv (int recvpin, int blinkpin) { irparams.recvpin = recvpin; + irparams.blinkpin = blinkpin; + pinMode(blinkpin, OUTPUT); + irparams.blinkflag = 0; } @@ -138,6 +142,17 @@ void IRrecv::enableIRIn ( ) } #endif // USE_DEFAULT_ENABLE_IR_IN +//+============================================================================= +// Enable/disable blinking of pin 13 on IR processing +// +void IRrecv::blink13 (int blinkflag) +{ +#ifdef BLINKLED + irparams.blinkflag = blinkflag; + if (blinkflag) pinMode(BLINKLED, OUTPUT) ; +#endif +} + //+============================================================================= // Return if receiving new IR signals //