Skip to content

Commit b4b9760

Browse files
committed
Only reset on input toggles, not state changes
1 parent 5d5fcb0 commit b4b9760

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/shelly_sw_service.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,6 @@ static void shelly_sw_set_state_ctx(struct shelly_sw_service_ctx *ctx,
108108
}
109109
}
110110

111-
double now = mgos_uptime();
112-
if (now < 60) {
113-
if (now - ctx->last_change_ts > 10) {
114-
ctx->change_cnt = 0;
115-
}
116-
ctx->change_cnt++;
117-
ctx->last_change_ts = now;
118-
if (ctx->change_cnt >= 10) {
119-
LOG(LL_INFO, ("Reset sequence detected"));
120-
ctx->change_cnt = 0;
121-
mgos_gpio_blink(cfg->out_gpio, 100, 100);
122-
mgos_set_timer(600, 0, do_reset, ctx);
123-
}
124-
}
125-
126111
handle_auto_off(ctx, source, new_state);
127112
}
128113

@@ -260,6 +245,24 @@ static const HAPCharacteristic *shelly_sw_on_char(uint16_t iid) {
260245
static void shelly_sw_in_cb(int pin, void *arg) {
261246
struct shelly_sw_service_ctx *ctx = arg;
262247
bool in_state = mgos_gpio_read(pin);
248+
249+
250+
double now = mgos_uptime();
251+
if (now < 60) {
252+
if (now - ctx->last_change_ts > 10) {
253+
ctx->change_cnt = 0;
254+
}
255+
ctx->change_cnt++;
256+
ctx->last_change_ts = now;
257+
if (ctx->change_cnt >= 10) {
258+
LOG(LL_INFO, ("Reset sequence detected"));
259+
ctx->change_cnt = 0;
260+
mgos_gpio_blink(ctx->cfg->out_gpio, 100, 100);
261+
mgos_set_timer(600, 0, do_reset, ctx);
262+
return;
263+
}
264+
}
265+
263266
switch ((enum shelly_sw_in_mode) ctx->cfg->in_mode) {
264267
case SHELLY_SW_IN_MODE_MOMENTARY:
265268
if (in_state) { // Only on 0 -> 1 transitions.

0 commit comments

Comments
 (0)