From 114fe2ccd64e8c2af5fc50a24c8400602682e15e Mon Sep 17 00:00:00 2001 From: madmalkav Date: Fri, 31 Jul 2015 20:58:04 +0200 Subject: [PATCH] Added suport for user defined IR reception feedback LED --- IRremote.h | 3 ++- IRremoteInt.h | 4 +++- irISR.cpp | 9 ++++++--- irRecv.cpp | 10 ++++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/IRremote.h b/IRremote.h index da93648..097a217 100644 --- a/IRremote.h +++ b/IRremote.h @@ -168,11 +168,12 @@ class IRrecv { public: IRrecv (int recvpin) ; + IRrecv (int recvpin, int blinkpin); void blink13 (int blinkflag) ; int decode (decode_results *results) ; void enableIRIn ( ) ; - bool isIdle ( ) ; + bool isIdle ( ) ; void resume ( ) ; private: diff --git a/IRremoteInt.h b/IRremoteInt.h index 38a4a2c..32515c3 100644 --- a/IRremoteInt.h +++ b/IRremoteInt.h @@ -47,7 +47,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 blinkflag; // true -> enable blinking of pin 13 on IR processing + 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 @@ -70,6 +71,7 @@ EXTERN volatile irparams_t irparams; //------------------------------------------------------------------------------ // Defines for blinking the LED // + #if defined(CORE_LED0_PIN) # define BLINKLED CORE_LED0_PIN # define BLINKLED_ON() (digitalWrite(CORE_LED0_PIN, HIGH)) diff --git a/irISR.cpp b/irISR.cpp index acafafb..b124e9c 100644 --- a/irISR.cpp +++ b/irISR.cpp @@ -77,9 +77,12 @@ ISR (TIMER_INTR_NAME) break; } - // If requested, flash LED L (D13) while receiving IR data + // If requested, flash LED while receiving IR data if (irparams.blinkflag) { - if (irdata == MARK) BLINKLED_ON() ; // turn pin 13 LED on - else BLINKLED_OFF() ; // turn pin 13 LED off + 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 } } diff --git a/irRecv.cpp b/irRecv.cpp index 6cafb58..40bd782 100644 --- a/irRecv.cpp +++ b/irRecv.cpp @@ -97,6 +97,16 @@ IRrecv::IRrecv (int recvpin) irparams.blinkflag = 0; } +IRrecv::IRrecv (int recvpin, int blinkpin) +{ + irparams.recvpin = recvpin; + irparams.blinkpin = blinkpin; + pinMode(blinkpin, OUTPUT); + irparams.blinkflag = 0; +} + + + //+============================================================================= // initialization //