|
17 | 17 | #include "../Helpers/Misc.h" |
18 | 18 | #include "../Helpers/Scheduler.h" |
19 | 19 |
|
20 | | -const __FlashStringHelper * command_setRulesTimer(int msecFromNow, int timerIndex, int recurringCount) { |
| 20 | +const __FlashStringHelper * command_setRulesTimer(int msecFromNow, int timerIndex, int recurringCount, bool startImmediately = false) { |
21 | 21 | if (msecFromNow < 0) |
22 | 22 | { |
23 | 23 | addLog(LOG_LEVEL_ERROR, F("TIMER: time must be positive")); |
24 | 24 | } else { |
25 | 25 | // start new timer when msecFromNow > 0 |
26 | 26 | // Clear timer when msecFromNow == 0 |
27 | | - if (Scheduler.setRulesTimer(msecFromNow, timerIndex, recurringCount)) |
| 27 | + if (Scheduler.setRulesTimer(msecFromNow, timerIndex, recurringCount, startImmediately)) |
28 | 28 | { |
29 | 29 | return return_command_success_flashstr(); |
30 | 30 | } |
@@ -78,6 +78,34 @@ const __FlashStringHelper * Command_Loop_Timer_Set_ms (struct EventStruct *event |
78 | 78 | ); |
79 | 79 | } |
80 | 80 |
|
| 81 | +const __FlashStringHelper * Command_Loop_Timer_SetAndRun (struct EventStruct *event, const char* Line) |
| 82 | +{ |
| 83 | + int recurringCount = event->Par3; |
| 84 | + if (recurringCount == 0) { |
| 85 | + // if the optional 3rd parameter is not given, set it to "run always" |
| 86 | + recurringCount = -1; |
| 87 | + } |
| 88 | + return command_setRulesTimer( |
| 89 | + event->Par2 * 1000, // msec from now |
| 90 | + event->Par1, // timer index |
| 91 | + recurringCount, |
| 92 | + true); |
| 93 | +} |
| 94 | + |
| 95 | +const __FlashStringHelper * Command_Loop_Timer_SetAndRun_ms (struct EventStruct *event, const char* Line) |
| 96 | +{ |
| 97 | + int recurringCount = event->Par3; |
| 98 | + if (recurringCount == 0) { |
| 99 | + // if the optional 3rd parameter is not given, set it to "run always" |
| 100 | + recurringCount = -1; |
| 101 | + } |
| 102 | + return command_setRulesTimer( |
| 103 | + event->Par2, // interval |
| 104 | + event->Par1, // timer index |
| 105 | + recurringCount, |
| 106 | + true); |
| 107 | +} |
| 108 | + |
81 | 109 | const __FlashStringHelper * Command_Timer_Pause(struct EventStruct *event, const char *Line) |
82 | 110 | { |
83 | 111 | if (Scheduler.pause_rules_timer(event->Par1)) { |
|
0 commit comments