add mqtt_publish_stat() for override and timespec changes; add channel_override_clear(); call c_o_c() when Timespec.Clear removes the timespec, as there is no concept of overrides when there is no timespec set
This commit is contained in:
@ -35,5 +35,6 @@ struct mgos_timespec *channel_get_timespec(int idx);
|
||||
int channel_get_total();
|
||||
void channel_handler(int gpio, void *arg);
|
||||
void channel_override_set(int idx);
|
||||
void channel_override_clear(int idx);
|
||||
|
||||
#endif // __MAIN_H
|
||||
|
@ -259,6 +259,7 @@ static void channel_timespec(int idx) {
|
||||
if (idx < 0 || idx >= channel_get_total()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (timespec_empty(s_channels[idx].timespec)) {
|
||||
return;
|
||||
}
|
||||
@ -270,12 +271,14 @@ static void channel_timespec(int idx) {
|
||||
return;
|
||||
}
|
||||
LOG(LL_INFO, ("Timespec drives channel %d to relay_state %d", idx, match));
|
||||
mqtt_publish_stat("timespec", "{idx: %d, relay_state: %d, override: %B}", idx, match, s_channels[idx].channel_override);
|
||||
channel_set(idx, match);
|
||||
} else {
|
||||
// Follow override until it matches timespec
|
||||
if (match == s_channels[idx].relay_state) {
|
||||
LOG(LL_INFO, ("User state agrees with timespec, clearing override"));
|
||||
s_channels[idx].channel_override = false;
|
||||
mqtt_publish_stat("override", "{idx: %d, relay_state: %d, override: %B}", idx, match, s_channels[idx].channel_override);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -316,19 +319,37 @@ void channel_override_set(int idx) {
|
||||
if (idx < 0 || idx >= channel_get_total()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (timespec_empty(s_channels[idx].timespec)) {
|
||||
return;
|
||||
}
|
||||
|
||||
match = timespec_match_now(s_channels[idx].timespec);
|
||||
if (match != s_channels[idx].relay_state) {
|
||||
LOG(LL_INFO, ("User state disagrees with timespec, setting override"));
|
||||
s_channels[idx].channel_override = true;
|
||||
mqtt_publish_stat("override", "{idx: %d, relay_state: %d, override: %B}", idx, s_channels[idx].relay_state, s_channels[idx].channel_override);
|
||||
return;
|
||||
}
|
||||
if (s_channels[idx].channel_override && (match == s_channels[idx].relay_state)) {
|
||||
LOG(LL_INFO, ("User state agrees with timespec, clearing override"));
|
||||
mqtt_publish_stat("override", "{idx: %d, relay_state: %d, override: %B}", idx, s_channels[idx].relay_state, s_channels[idx].channel_override);
|
||||
s_channels[idx].channel_override = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the override flag on a channel.
|
||||
void channel_override_clear(int idx) {
|
||||
if (idx < 0 || idx >= channel_get_total()) {
|
||||
return;
|
||||
}
|
||||
|
||||
s_channels[idx].channel_override = false;
|
||||
mqtt_publish_stat("override", "{idx: %d, relay_state: %d, override: %B}", idx, s_channels[idx].relay_state, s_channels[idx].channel_override);
|
||||
return;
|
||||
}
|
||||
|
||||
// Channel handler arg is non-NULL if it was a pushbutton, and NULL if it was an RPC.
|
||||
void channel_handler(int gpio, void *arg) {
|
||||
uint8_t idx;
|
||||
|
Reference in New Issue
Block a user