LOCAL void plug_server_blink_cycle() { LOCAL uint8 state = 0; LOCAL uint32 timer = 0; if (!plug_server_blink) { state = 0; return; } if (plug_wifi_blink) { state = 0; } else { // change led state only if wifi not blinking state++; if (state > 7) { state = 0; } uint8 led_state = (state & 0x01) && (state < 5); plug_led(PLUG_LED1, led_state); plug_led(PLUG_LED2, !led_state && user_relay_get()); } clearTimeout(timer); timer = setTimeout(plug_server_blink_cycle, NULL, 250); }
LOCAL void ICACHE_FLASH_ATTR emtr_start_read() { LOCAL uint32 emtr_read_timer = 0; if (device_get_uart() != UART_EMTR) { #if EMTR_DEBUG debug("EMTR: %s\n", DEVICE_NOT_FOUND); #endif return; } clearTimeout(emtr_read_timer); emtr_read_timer = setTimeout(emtr_get_output, emtr_read_done, emtr_read_interval); }
LOCAL void ICACHE_FLASH_ATTR finger_start_read() { LOCAL uint32 finger_read_timer = 0; if (device_get_uart() != UART_FINGER) { #if FINGER_DEBUG debug("FINGER: %s\n", DEVICE_NOT_FOUND); #endif return; } finger_current_buff = 0; clearTimeout(finger_read_timer); finger_read_timer = setTimeout(finger_gen_img, finger_read, FINGER_TIMEOUT); }
LOCAL void plug_wifi_blink_cycle() { LOCAL bool state = false; LOCAL uint32 timer = 0; if (!plug_wifi_blink) { state = false; return; } state = !state; plug_led(PLUG_LED1, state); plug_led(PLUG_LED2, !state && user_relay_get()); clearTimeout(timer); timer = setTimeout(plug_wifi_blink_cycle, NULL, 500); }
LOCAL void ICACHE_FLASH_ATTR switch2_toggle(void *arg) { LOCAL event_timer = 0; switch2_config *config = arg; bool event = false; if (1 == GPIO_INPUT_GET(GPIO_ID_PIN(config->gpio.gpio_id))) { if (config->state_buf < SWITCH_STATE_FILTER) { config->state_buf++; event = (config->state_buf == SWITCH_STATE_FILTER); } } else { if (config->state_buf > 0) { config->state_buf--; event = (config->state_buf == 0); } } if (event) { uint8 state = (config->state_buf == SWITCH_STATE_FILTER); if (config->state != state) { config->state = state; if (config->preference == 0) { return; } int relay_state = 0; if (config->preference < 0 || config->preference >= 2) { // Relay Off-On || On-Off || Toggle relay_state = config->preference; } else if (config->preference == 1) { // Relay Set relay_state = state; } user_switch2_set(config->id - 2, relay_state); clearTimeout(event_timer); event_timer = setTimeout(user_switch2_event, NULL, 50); } } }
LOCAL void ICACHE_FLASH_ATTR wifi_write_char(char c) { LOCAL char *buff = NULL; LOCAL timer *t = NULL; LOCAL uint8 i = 0; clearTimeout(t); if (buff == NULL) { buff = (char *)os_zalloc(WIFI_DEBUG_BUFFER_LEN); } buff[i++] = c; if (c == '\0' || i == WIFI_DEBUG_BUFFER_LEN-1) { i = 0; websocket_debug_message(buff); } else { t = setTimeout(wifi_debug_flush, NULL, 200); } }