#ifndef STEP_0_HPP #define STEP_0_HPP #include "../drivers/bottom_half.h" #include "../drivers/char_lcd.h" #include "../drivers/wires.h" #include "setup_wires.hpp" static const char *STEP0_TAG = "step0"; #define STRING_MAX_LEN 8 /// Wait for "*9819" void step0(void) { KeypadKey key; int current_idx = 0; char current[STRING_MAX_LEN+1] = {0}; while (1) { while (get_pressed_keypad(&key)) { if (key == KeypadKey::star) { current[0] = '*'; for (int i = 1; i < STRING_MAX_LEN; i++) { current[i] = 0; } current_idx = 1; } else if (key == KeypadKey::pound) { // submit if (current[0] == '\0') { // do nothing } else if (strcmp(current, "*9819") == 0) { lcd_set_cursor(&lcd, 1, 2); lcd_print(&lcd, "Diffusal Initated"); vTaskDelay(pdMS_TO_TICKS(2000)); lcd_clear(&lcd); return; } else if (strcmp(current, "*59861") == 0) { lcd_set_cursor(&lcd, 1, 2); lcd_print(&lcd, "Set Up Wires"); vTaskDelay(pdMS_TO_TICKS(2000)); setup_wires(); } else { lcd_set_cursor(&lcd, 1, 2); lcd_print(&lcd, "Invalid Star Code"); strike("Invalid Star Code"); vTaskDelay(pdMS_TO_TICKS(2000)); } // clear for (int i = 0; i < STRING_MAX_LEN; i++) { current[i] = 0; } current_idx = 0; } else { // out of room. skip if (current_idx >= STRING_MAX_LEN) break; // no code started. if (current[0] != '*') continue; char c = char_of_keypad_key(key); current[current_idx++] = c; } // ESP_LOGI(STEP0_TAG, "Pressed: %c", c); lcd_clear(&lcd); lcd_set_cursor(&lcd, 1, 1); lcd_print(&lcd, current); } vTaskDelay(pdMS_TO_TICKS(10)); } } #endif /* STEP_0_HPP */