|
@ -16,11 +16,20 @@ Adapted by Xose Pérez <xose dot perez at gmail dot com> |
|
|
#include "ntp.h"
|
|
|
#include "ntp.h"
|
|
|
#include "relay.h"
|
|
|
#include "relay.h"
|
|
|
#include "ws.h"
|
|
|
#include "ws.h"
|
|
|
|
|
|
#include "curtain_kingart.h"
|
|
|
|
|
|
|
|
|
constexpr const int SchedulerDummySwitchId = 0xff; |
|
|
constexpr const int SchedulerDummySwitchId = 0xff; |
|
|
|
|
|
|
|
|
int _sch_restore = 0; |
|
|
int _sch_restore = 0; |
|
|
|
|
|
|
|
|
|
|
|
unsigned char schedulableCount() { |
|
|
|
|
|
return relayCount() |
|
|
|
|
|
#ifdef CURTAIN_SUPPORT
|
|
|
|
|
|
+ curtainCount() |
|
|
|
|
|
#endif
|
|
|
|
|
|
; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
#if WEB_SUPPORT
|
|
|
#if WEB_SUPPORT
|
|
@ -30,13 +39,13 @@ bool _schWebSocketOnKeyCheck(const char * key, JsonVariant& value) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void _schWebSocketOnVisible(JsonObject& root) { |
|
|
void _schWebSocketOnVisible(JsonObject& root) { |
|
|
if (!relayCount()) return; |
|
|
|
|
|
|
|
|
if (!schedulableCount()) return; |
|
|
root["schVisible"] = 1; |
|
|
root["schVisible"] = 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void _schWebSocketOnConnected(JsonObject &root){ |
|
|
void _schWebSocketOnConnected(JsonObject &root){ |
|
|
|
|
|
|
|
|
if (!relayCount()) return; |
|
|
|
|
|
|
|
|
if (!schedulableCount()) return; |
|
|
|
|
|
|
|
|
JsonObject &schedules = root.createNestedObject("schedules"); |
|
|
JsonObject &schedules = root.createNestedObject("schedules"); |
|
|
schedules["max"] = SCHEDULER_MAX_SCHEDULES; |
|
|
schedules["max"] = SCHEDULER_MAX_SCHEDULES; |
|
@ -62,7 +71,7 @@ void _schWebSocketOnConnected(JsonObject &root){ |
|
|
switch_.add(getSetting({"schSwitch", i}, 0)); |
|
|
switch_.add(getSetting({"schSwitch", i}, 0)); |
|
|
action.add(getSetting({"schAction", i}, 0)); |
|
|
action.add(getSetting({"schAction", i}, 0)); |
|
|
type.add(getSetting({"schType", i}, SCHEDULER_TYPE_SWITCH)); |
|
|
type.add(getSetting({"schType", i}, SCHEDULER_TYPE_SWITCH)); |
|
|
hour.add(getSetting({"schHour", i}, 0)); |
|
|
|
|
|
|
|
|
hour.add(getSetting({"schHour", i}, 12)); |
|
|
minute.add(getSetting({"schMinute", i}, 0)); |
|
|
minute.add(getSetting({"schMinute", i}, 0)); |
|
|
weekdays.add(getSetting({"schWDs", i}, SCHEDULER_WEEKDAYS)); |
|
|
weekdays.add(getSetting({"schWDs", i}, SCHEDULER_WEEKDAYS)); |
|
|
} |
|
|
} |
|
@ -102,7 +111,7 @@ void _schConfigure() { |
|
|
|
|
|
|
|
|
bool sch_enabled = getSetting({"schEnabled", i}, false); |
|
|
bool sch_enabled = getSetting({"schEnabled", i}, false); |
|
|
int sch_action = getSetting({"schAction", i}, 0); |
|
|
int sch_action = getSetting({"schAction", i}, 0); |
|
|
int sch_hour = getSetting({"schHour", i}, 0); |
|
|
|
|
|
|
|
|
int sch_hour = getSetting({"schHour", i}, 12); |
|
|
int sch_minute = getSetting({"schMinute", i}, 0); |
|
|
int sch_minute = getSetting({"schMinute", i}, 0); |
|
|
bool sch_utc = getSetting({"schUTC", i}, false); |
|
|
bool sch_utc = getSetting({"schUTC", i}, false); |
|
|
String sch_weekdays = getSetting({"schWDs", i}, SCHEDULER_WEEKDAYS); |
|
|
String sch_weekdays = getSetting({"schWDs", i}, SCHEDULER_WEEKDAYS); |
|
@ -110,7 +119,7 @@ void _schConfigure() { |
|
|
|
|
|
|
|
|
DEBUG_MSG_P( |
|
|
DEBUG_MSG_P( |
|
|
PSTR("[SCH] Schedule #%d: %s #%d to %d at %02d:%02d %s on %s%s\n"), |
|
|
PSTR("[SCH] Schedule #%d: %s #%d to %d at %02d:%02d %s on %s%s\n"), |
|
|
i, SCHEDULER_TYPE_SWITCH == sch_type ? "switch" : "channel", sch_switch, |
|
|
|
|
|
|
|
|
i, SCHEDULER_TYPE_SWITCH == sch_type ? "switch" : (SCHEDULER_TYPE_CURTAIN == sch_type ? "curtain" : "channel"), sch_switch, |
|
|
sch_action, sch_hour, sch_minute, sch_utc ? "UTC" : "local time", |
|
|
sch_action, sch_hour, sch_minute, sch_utc ? "UTC" : "local time", |
|
|
(char *) sch_weekdays.c_str(), |
|
|
(char *) sch_weekdays.c_str(), |
|
|
sch_enabled ? "" : " (disabled)" |
|
|
sch_enabled ? "" : " (disabled)" |
|
@ -163,6 +172,13 @@ void _schAction(unsigned char sch_id, int sch_action, int sch_switch) { |
|
|
lightUpdate(true, true); |
|
|
lightUpdate(true, true); |
|
|
} |
|
|
} |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if CURTAIN_SUPPORT == 1
|
|
|
|
|
|
if (SCHEDULER_TYPE_CURTAIN == sch_type) { |
|
|
|
|
|
DEBUG_MSG_P(PSTR("[SCH] Set curtain %d value to %d\n"), sch_switch, sch_action); |
|
|
|
|
|
curtainSetPosition(sch_switch, sch_action); |
|
|
|
|
|
} |
|
|
|
|
|
#endif
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#if NTP_LEGACY_SUPPORT
|
|
|
#if NTP_LEGACY_SUPPORT
|
|
@ -230,7 +246,7 @@ void _schCheck(int relay, int daybefore) { |
|
|
String sch_weekdays = getSetting({"schWDs", i}, SCHEDULER_WEEKDAYS); |
|
|
String sch_weekdays = getSetting({"schWDs", i}, SCHEDULER_WEEKDAYS); |
|
|
if (_schIsThisWeekday(sch_utc ? calendar_weekday.utc_wday : calendar_weekday.local_wday, sch_weekdays)) { |
|
|
if (_schIsThisWeekday(sch_utc ? calendar_weekday.utc_wday : calendar_weekday.local_wday, sch_weekdays)) { |
|
|
|
|
|
|
|
|
int sch_hour = getSetting({"schHour", i}, 0); |
|
|
|
|
|
|
|
|
int sch_hour = getSetting({"schHour", i}, 12); |
|
|
int sch_minute = getSetting({"schMinute", i}, 0); |
|
|
int sch_minute = getSetting({"schMinute", i}, 0); |
|
|
int sch_action = getSetting({"schAction", i}, 0); |
|
|
int sch_action = getSetting({"schAction", i}, 0); |
|
|
int sch_type = getSetting({"schType", i}, SCHEDULER_TYPE_SWITCH); |
|
|
int sch_type = getSetting({"schType", i}, SCHEDULER_TYPE_SWITCH); |
|
@ -255,6 +271,16 @@ void _schCheck(int relay, int daybefore) { |
|
|
} |
|
|
} |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if CURTAIN_SUPPORT == 1
|
|
|
|
|
|
if (SCHEDULER_TYPE_CURTAIN == sch_type && sch_switch == relay && minutes_to_trigger < 0 && minutes_to_trigger > minimum_restore_time) { |
|
|
|
|
|
minimum_restore_time = minutes_to_trigger; |
|
|
|
|
|
saved_action = sch_action; |
|
|
|
|
|
saved_sch = i; |
|
|
|
|
|
} |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (minutes_to_trigger == 0 && relay == -1) { |
|
|
if (minutes_to_trigger == 0 && relay == -1) { |
|
|
|
|
|
|
|
|
_schAction(i, sch_action, sch_switch); |
|
|
_schAction(i, sch_action, sch_switch); |
|
@ -311,7 +337,7 @@ void schSetup() { |
|
|
|
|
|
|
|
|
static bool restore_once = true; |
|
|
static bool restore_once = true; |
|
|
if (restore_once) { |
|
|
if (restore_once) { |
|
|
for (unsigned char i = 0; i < relayCount(); i++) { |
|
|
|
|
|
|
|
|
for (unsigned char i = 0; i < schedulableCount(); i++) { |
|
|
if (getSetting({"relayLastSch", i}, 1 == SCHEDULER_RESTORE_LAST_SCHEDULE)) { |
|
|
if (getSetting({"relayLastSch", i}, 1 == SCHEDULER_RESTORE_LAST_SCHEDULE)) { |
|
|
_schCheck(i, 0); |
|
|
_schCheck(i, 0); |
|
|
} |
|
|
} |
|
|