Change command ``TimedPower``

Change command ``TimedPower`` from erasing all timers to showing remaining timers
This commit is contained in:
Theo Arends 2024-01-17 15:55:25 +01:00
parent 12ef60a3df
commit 2832ed914b
3 changed files with 28 additions and 2 deletions

View File

@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file.
### Changed
- ESP32 platform update from 2024.01.00 to 2024.01.01 (#20508)
- IP stack compatible with new Core3 IPv6 implementation (#20509)
- Command ``TimedPower`` from erasing all timers to showing remaining timers
### Fixed
- Scripter memory leak in `>w x` (#20473)
@ -27,6 +28,7 @@ All notable changes to this project will be documented in this file.
- GPIO Viewer single instance
- Zigbee ramdom crash in main page (#20481)
- Web file upload response on upload error (#20340)
- ESP32 shutter exception 6 (divide by zero) on ``ShutterMode 4`` (#20524)
### Removed

View File

@ -173,6 +173,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
- Scripter memory leak in `>w x` (#20473)[#20473](https://github.com/arendst/Tasmota/issues/20473)
- Zigbee ramdom crash in main page (#20481)[#20473](https://github.com/arendst/Tasmota/issues/20481)
- ESP32 piezo ceramic buzzer doesn't buzz [#20118](https://github.com/arendst/Tasmota/issues/20118)
- ESP32 shutter exception 6 (divide by zero) on ``ShutterMode 4`` [#20524](https://github.com/arendst/Tasmota/issues/20524)
- ESP32 Zigbee Aqara attributes [#20452](https://github.com/arendst/Tasmota/issues/20452)
- LVGL fix type for lv_imgbtn [#20354](https://github.com/arendst/Tasmota/issues/20354)
- Berry claiming UART0 if needed [#20324](https://github.com/arendst/Tasmota/issues/20324)

View File

@ -535,6 +535,27 @@ void ResetTimedCmnd(const char *command) {
}
}
void ShowTimedCmnd(const char *command) {
bool found = false;
uint32_t now = millis();
Response_P(PSTR("{\"%s\":"), XdrvMailbox.command);
for (uint32_t i = 0; i < MAX_TIMED_CMND; i++) {
if (TasmotaGlobal.timed_cmnd[i].time != 0) {
if (!strncmp(command, TasmotaGlobal.timed_cmnd[i].command.c_str(), strlen(command))) {
// Stored command starts with command
ResponseAppend_P(PSTR("%s"), (found) ? "," : "[");
found = true;
ResponseAppend_P(PSTR("{\"" D_JSON_REMAINING "\":%d,\"" D_JSON_COMMAND "\":\"%s\"}"), TasmotaGlobal.timed_cmnd[i].time - now, TasmotaGlobal.timed_cmnd[i].command.c_str());
}
}
}
if (found) {
ResponseAppend_P(PSTR("]}"));
} else {
ResponseAppend_P(PSTR("\"" D_JSON_EMPTY "\"}"));
}
}
void LoopTimedCmnd(void) {
uint32_t now = millis();
for (uint32_t i = 0; i < MAX_TIMED_CMND; i++) {
@ -755,7 +776,7 @@ void CmndTimedPower(void) {
/*
Allow timed power changes on a 50ms granularity
TimedPower<index> <milliseconds>[,0|1|2|3]
TimedPower - Clear active power timers
TimedPower - Show remaining timers
TimedPower 2000 - Turn power1 on and then off after 2 seconds
TimedPower1 - Clear active Power1 timers
TimedPower1 0 - Stop timer and perform timed action
@ -788,7 +809,9 @@ void CmndTimedPower(void) {
}
} else {
if (!XdrvMailbox.usridx) {
ResetTimedCmnd(D_CMND_POWER); // Remove all POWER timed command
// ResetTimedCmnd(D_CMND_POWER); // Remove all POWER timed command
ShowTimedCmnd(D_CMND_POWER); // Show remaining timers
return;
} else {
char cmnd[CMDSZ];
snprintf_P(cmnd, sizeof(cmnd), PSTR(D_CMND_POWER "%d"), XdrvMailbox.index);