Go to the documentation of this file.
42 #ifndef _IR_COMMAND_DISPATCHER_HPP
43 #define _IR_COMMAND_DISPATCHER_HPP
54 #if !defined(USE_TINY_IR_RECEIVER) && !defined(USE_IRREMOTE_LIBRARY) && !defined(USE_IRMP_LIBRARY)
55 #define USE_TINY_IR_RECEIVER // Set TiniIR as default library
60 #if defined(USE_TINY_IR_RECEIVER)
64 #if defined(USE_ONKYO_PROTOCOL) && ! defined(DISPATCHER_IR_COMMAND_HAS_MORE_THAN_8_BIT)
65 #warning ONKYO protocol has 16 bit commands so activating of DISPATCHER_IR_COMMAND_HAS_MORE_THAN_8_BIT is recommended
67 #define USE_CALLBACK_FOR_TINY_RECEIVER // Call the function "handleReceivedTinyIRData()" below each time a frame or repeat is received.
86 # if defined(ESP8266) || defined(ESP32)
95 # if defined(LOCAL_INFO)
99 # if defined(IR_ADDRESS)
119 #elif defined(USE_IRREMOTE_LIBRARY)
123 #define DECODE_NEC // Includes Apple and Onkyo
132 void ReceiveCompleteCallbackHandler();
152 #if defined(ESP32) || defined(ESP8266)
155 void ReceiveCompleteCallbackHandler() {
167 #if !defined(SUPPORT_MULTIPLE_RECEIVER_INSTANCES) && !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) // no Serial etc. possible in callback for RTOS based cores like ESP, even when interrupts are enabled
171 # if defined(LOCAL_INFO)
180 # if defined(IR_ADDRESS)
200 #elif defined(USE_IRMP_LIBRARY)
204 #define IRMP_USE_COMPLETE_CALLBACK 1 // Enable callback functionality. It is required if IRMP library is used.
205 #define IRMP_PROTOCOL_NAMES 1 // Enable protocol number mapping to protocol strings for printIRInfo()
211 void handleReceivedIRData();
216 irmp_register_complete_callback_function(&handleReceivedIRData);
226 #if defined(ESP8266) || defined(ESP32)
229 void handleReceivedIRData()
231 irmp_get_data(&irmp_data);
238 #if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) // no Serial etc. possible in callback for RTOS based cores like ESP, even when interrupts are enabled
242 # if defined(LOCAL_INFO)
243 irmp_result_print(&Serial, &irmp_data);
246 # if defined(IR_ADDRESS)
266 #endif // elif defined(USE_IRMP_LIBRARY)
274 #if defined(USE_IRMP_LIBRARY)
275 # if defined(IR_REMOTE_NAME)
276 aSerial->println(F(
"Listening to IR remote of type " STR(IR_REMOTE_NAME)
" at pin " STR(IRMP_INPUT_PIN)));
278 aSerial->println(F(
"Listening to IR remote at pin " STR(IRMP_INPUT_PIN)));
280 aSerial->print(F(
"Accepted protocols are: "));
281 irmp_print_active_protocols(&Serial);
284 # if defined(IR_REMOTE_NAME)
285 aSerial->println(F(
"Listening to IR remote of type " STR(IR_REMOTE_NAME)
" at pin " STR(
IR_RECEIVE_PIN)));
314 #if defined(LOCAL_INFO)
315 # if defined(__AVR__)
316 # if defined(USE_DISPATCHER_COMMAND_STRINGS)
317 const __FlashStringHelper *tCommandName =
reinterpret_cast<const __FlashStringHelper*
>(IRMapping[i].CommandString);
319 char tCommandName[7];
320 snprintf_P(tCommandName,
sizeof(tCommandName), PSTR(
"0x%x"), IRMapping[i].IRCode);
323 # if defined(USE_DISPATCHER_COMMAND_STRINGS)
324 const char *tCommandName = IRMapping[i].CommandString;
326 char tCommandName[7];
327 snprintf(tCommandName,
sizeof(tCommandName),
"0x%x", IRMapping[i].IRCode);
359 if (tIsNonBlockingCommand) {
363 #if defined(DISPATCHER_BUZZER_FEEDBACK_PIN) && defined(USE_TINY_IR_RECEIVER)
368 tone(DISPATCHER_BUZZER_FEEDBACK_PIN, 2200, 50);
371 IRMapping[i].CommandToCall();
391 #if defined(DISPATCHER_BUZZER_FEEDBACK_PIN) && defined(USE_TINY_IR_RECEIVER)
396 tone(DISPATCHER_BUZZER_FEEDBACK_PIN, 2200, 50);
400 IRMapping[i].CommandToCall();
412 INFO_PRINT(F(
"Requested stop and stored blocking command "));
450 #if defined(LOCAL_INFO)
451 Serial.print(F(
"Set next command to run to 0x"));
452 Serial.print(aBlockingCommandToRunNext, HEX);
453 # if defined(USE_DISPATCHER_COMMAND_STRINGS)
470 uint32_t tStartMillis = millis();
475 }
while (millis() - tStartMillis < aDelayMillis);
481 # if defined(USE_DISPATCHER_COMMAND_STRINGS)
482 aSerial->println(
reinterpret_cast<const __FlashStringHelper*
>(IRMapping[aMappingArrayIndex].CommandString));
484 aSerial->print(F(
"0x"));
485 aSerial->println(IRMapping[aMappingArrayIndex].IRCode, HEX);
488 # if defined(USE_DISPATCHER_COMMAND_STRINGS)
489 aSerial->println(IRMapping[aMappingArrayIndex].CommandString);
491 aSerial->print(
"0x");
492 aSerial->println(IRMapping[aMappingArrayIndex].IRCode, HEX);
499 if (aCommand == IRMapping[i].IRCode) {
504 aSerial->println(F(
"unknown"));
513 #endif // _IR_COMMAND_DISPATCHER_HPP
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
volatile bool requestToStopReceived
IRCommandType currentBlockingCommandCalled
void printIRInfo(Print *aSerial)
volatile bool isAvailable
#define TRACE_PRINTLN(...)
void registerReceiveCompleteCallback(void(*aReceiveCompleteCallbackFunction)(void))
Sets the function to call if a complete protocol frame has arrived.
IRCommandType BlockingCommandToRunNext
#define IRDATA_FLAGS_IS_REPEAT
The gap between the preceding frame is as smaller than the maximum gap expected for a repeat....
#define IR_COMMAND_FLAG_REPEATABLE
void setNextBlockingCommand(IRCommandType aBlockingCommandToRunNext)
volatile uint32_t MillisOfLastCode
void printIRCommandStringForArrayIndex(Print *aSerial, uint_fast8_t aMappingArrayIndex)
volatile TinyIRReceiverCallbackDataStruct TinyIRReceiverData
void begin(uint_fast8_t aReceivePin, bool aEnableLEDFeedback=false, uint_fast8_t aFeedbackLEDPin=USE_DEFAULT_FEEDBACK_LED_PIN)
Initializes the receive and feedback pin.
IRCommandType lastBlockingCommandCalled
void handleReceivedTinyIRData()
Declaration of the callback function provided by the user application.
void printIRCommandString(Print *aSerial, IRCommandType aCommand)
uint8_t flags
IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions above.
#define INFO_PRINTLN(...)
void printIRResultMinimal(Print *aSerial)
Function to print protocol number, address, command, raw data and repeat flag of IrReceiver....
bool delayAndCheckForStop(uint16_t aDelayMillis)
uint_fast8_t IRCommandType
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
Public API to the library.
#define ENABLE_LED_FEEDBACK
void setRequestToStopReceived(bool aRequestToStopReceived=true)
void printTinyReceiverResultMinimal(Print *aSerial)
IRCommandDispatcher IRDispatcher
#define DEBUG_PRINTLN(...)
struct IRDataForCommandDispatcherStruct IRReceivedData
#define IR_COMMAND_FLAG_BEEP
void checkAndCallCommand(bool aCallBlockingCommandImmediately)
bool decode()
The main decode function, attempts to decode the recently receive IR signal.
bool initPCIInterruptForTinyReceiver()
Sets IR_RECEIVE_PIN mode to INPUT, and if IR_FEEDBACK_LED_PIN is defined, sets feedback LED output mo...
bool justCalledBlockingCommand
void resume()
Restart the ISR (Interrupt Service Routine) state machine, to enable receiving of the next IR frame.
bool checkAndRunSuspendedBlockingCommands()
IRrecv IrReceiver
The receiver instance.
#define IR_COMMAND_FLAG_NON_BLOCKING