working step0
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
#ifndef STEP_0_HPP
|
||||
#define STEP_0_HPP
|
||||
|
||||
#include "../drivers/bottom_half.hpp"
|
||||
#include "../drivers/char_lcd.hpp"
|
||||
#include "i2c_lcd_pcf8574.h"
|
||||
|
||||
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 (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 {
|
||||
lcd_set_cursor(&lcd, 1, 2);
|
||||
lcd_print(&lcd, "Invalid Star Code");
|
||||
}
|
||||
|
||||
// clear
|
||||
for (int i = 0; i < STRING_MAX_LEN; i++) {
|
||||
current[i] = 0;
|
||||
}
|
||||
current_idx = 0;
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
} 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);
|
||||
}
|
||||
while (get_released_keypad(&key)) {
|
||||
char c = char_of_keypad_key(key);
|
||||
// ESP_LOGI(STEP0_TAG, "Released: %c", c);
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* STEP_0_HPP */
|
||||
Reference in New Issue
Block a user