MCPcopy Create free account
hub / github.com/Arduino-IRremote/Arduino-IRremote / checkAndCallCommand

Method checkAndCallCommand

src/IRCommandDispatcher.hpp:301–421  ·  view source on GitHub ↗

* The main dispatcher function called by IR-ISR, main loop and checkAndRunSuspendedBlockingCommands() * Non blocking commands are executed immediately, blocking commands are executed if no other command is just running. * If another blocking command is currently running, the request to stop is set * and the command is stored for main loop to be later execute by checkAndRunSuspendedBlockingComma

Source from the content-addressed store, hash-verified

299 * Should be false if called by ISR in order not to block ISR. Is true when called from checkAndRunSuspendedBlockingCommands().
300 */
301void IRCommandDispatcher::checkAndCallCommand(bool aCallBlockingCommandImmediately) {
302 if (IRReceivedData.command == COMMAND_EMPTY) {
303 return;
304 }
305
306 /*
307 * Search for command in Array of IRToCommandMappingStruct
308 */
309 for (uint_fast8_t i = 0; i < sizeof(IRMapping) / sizeof(struct IRToCommandMappingStruct); ++i) {
310 if (IRReceivedData.command == IRMapping[i].IRCode) {
311 /*
312 * Command found
313 */
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);
318# else
319 char tCommandName[7];
320 snprintf_P(tCommandName, sizeof(tCommandName), PSTR("0x%x"), IRMapping[i].IRCode);
321# endif
322# else
323# if defined(USE_DISPATCHER_COMMAND_STRINGS)
324 const char *tCommandName = IRMapping[i].CommandString;
325# else
326 char tCommandName[7];
327 snprintf(tCommandName, sizeof(tCommandName), "0x%x", IRMapping[i].IRCode);
328# endif
329# endif
330#endif
331 /*
332 * Check for repeat and if repeat is allowed for the current command
333 */
334 if (IRReceivedData.isRepeat && !(IRMapping[i].Flags & IR_COMMAND_FLAG_REPEATABLE)) {
335
336 DEBUG_PRINT(F("Repeats of command \""));
337 DEBUG_PRINT(tCommandName);
338 DEBUG_PRINTLN("\" not accepted");
339
340 return;
341 }
342
343 /*
344 * Do not accept recursive call of the same command
345 */
346 if (currentBlockingCommandCalled == IRReceivedData.command) {
347
348 DEBUG_PRINT(F("Recursive command \""));
349 DEBUG_PRINT(tCommandName);
350 DEBUG_PRINTLN("\" not accepted");
351
352 return;
353 }
354
355 /*
356 * Execute commands
357 */
358 bool tIsNonBlockingCommand = (IRMapping[i].Flags & IR_COMMAND_FLAG_NON_BLOCKING);

Callers 3

handleReceivedTinyIRDataFunction · 0.80
handleReceivedIRDataFunction · 0.80

Calls 1

toneFunction · 0.50

Tested by

no test coverage detected