@@ -108,21 +108,6 @@ static void shelly_sw_set_state_ctx(struct shelly_sw_service_ctx *ctx,
108
108
}
109
109
}
110
110
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
-
126
111
handle_auto_off (ctx , source , new_state );
127
112
}
128
113
@@ -260,6 +245,24 @@ static const HAPCharacteristic *shelly_sw_on_char(uint16_t iid) {
260
245
static void shelly_sw_in_cb (int pin , void * arg ) {
261
246
struct shelly_sw_service_ctx * ctx = arg ;
262
247
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
+
263
266
switch ((enum shelly_sw_in_mode ) ctx -> cfg -> in_mode ) {
264
267
case SHELLY_SW_IN_MODE_MOMENTARY :
265
268
if (in_state ) { // Only on 0 -> 1 transitions.
0 commit comments