rename functions
This commit is contained in:
parent
3806fd7ee8
commit
ab7148be42
@ -173,10 +173,10 @@ static bool _take_key(KeypadKey* kp, uint16_t* keypad_bitfield) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get_pressed_keypad(KeypadKey* kp) {
|
||||
bool get_keypad_pressed(KeypadKey* kp) {
|
||||
return _take_key(kp, &keypad_pressed);
|
||||
}
|
||||
bool get_released_keypad(KeypadKey* kp) {
|
||||
bool get_keypad_released(KeypadKey* kp) {
|
||||
return _take_key(kp, &keypad_released);
|
||||
}
|
||||
|
||||
@ -254,23 +254,23 @@ static bool _take_switch(SwitchKey* switch_, uint8_t* switch_bitfield) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get_pressed_button(ButtonKey* button) {
|
||||
bool get_button_pressed(ButtonKey* button) {
|
||||
return _take_button(button, &button_pressed);
|
||||
}
|
||||
bool get_released_button(ButtonKey* button) {
|
||||
bool get_button_released(ButtonKey* button) {
|
||||
return _take_button(button, &button_released);
|
||||
}
|
||||
uint8_t get_button_state() {
|
||||
return button_state;
|
||||
}
|
||||
|
||||
bool get_flipped_up_switch(SwitchKey* switch_) {
|
||||
bool get_switch_flipped_up(SwitchKey* switch_) {
|
||||
return _take_switch(switch_, &switch_flipped_up);
|
||||
}
|
||||
bool get_flipped_down_switch(SwitchKey* switch_) {
|
||||
bool get_switch_flipped_down(SwitchKey* switch_) {
|
||||
return _take_switch(switch_, &switch_flipped_down);
|
||||
}
|
||||
bool get_flipped_switch(SwitchKey* switch_) {
|
||||
bool get_switch_flipped(SwitchKey* switch_) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int bit_selector = (1 << i);
|
||||
if (
|
||||
|
||||
@ -62,11 +62,11 @@ void clear_all_pressed_released();
|
||||
/// @brief Gets the key that was just pressed (if any)
|
||||
/// @param kp an OUT variable for the key that was pressed (if any)
|
||||
/// @return true if there was a key that was just pressed
|
||||
bool get_pressed_keypad(KeypadKey* kp);
|
||||
bool get_keypad_pressed(KeypadKey* kp);
|
||||
/// @brief Gets the key that was just released (if any)
|
||||
/// @param kp an OUT variable for the key that was released (if any)
|
||||
/// @return true if there was a key that was just released
|
||||
bool get_released_keypad(KeypadKey* kp);
|
||||
bool get_keypad_released(KeypadKey* kp);
|
||||
/// @brief Converts a `KeypadKey` to a char
|
||||
/// @param kp The value to convert
|
||||
/// @return The char representing the key
|
||||
@ -74,15 +74,14 @@ char char_of_keypad_key(KeypadKey kp);
|
||||
// TODO: add a get_keypad state?
|
||||
|
||||
|
||||
// TODO: rename these to get_button_pressed.
|
||||
/// @brief Gets the button that was just pressed (if any)
|
||||
/// @param button an OUT variable for the button that was pressed (if any)
|
||||
/// @return true if there was a button that was just pressed
|
||||
bool get_pressed_button(ButtonKey* button);
|
||||
bool get_button_pressed(ButtonKey* button);
|
||||
/// @brief Gets the button that was just released (if any)
|
||||
/// @param button an OUT variable for the button that was released (if any)
|
||||
/// @return true if there was a button that was just released
|
||||
bool get_released_button(ButtonKey* button);
|
||||
bool get_button_released(ButtonKey* button);
|
||||
/// @brief Gets the raw state of the buttons b1-b4 as bitflags.
|
||||
/// B1 is MSB and B4 is LSB.
|
||||
/// @return Bitflags for b1-b4.
|
||||
@ -91,15 +90,15 @@ uint8_t get_button_state();
|
||||
/// @brief Gets the switch that was just flipped up (if any)
|
||||
/// @param switch_ an OUT variable for the switch that was flipped up (if any)
|
||||
/// @return true if there was a switch that was just flipped up
|
||||
bool get_flipped_up_switch(SwitchKey* switch_);
|
||||
bool get_switch_flipped_up(SwitchKey* switch_);
|
||||
/// @brief Gets the switch that was just flipped down (if any)
|
||||
/// @param switch_ an OUT variable for the switch that was flipped down (if any)
|
||||
/// @return true if there was a switch that was just flipped down
|
||||
bool get_flipped_down_switch(SwitchKey* switch_);
|
||||
bool get_switch_flipped_down(SwitchKey* switch_);
|
||||
/// @brief Gets the switch that was just flipped (if any)
|
||||
/// @param switch_ an OUT variable for the switch that was flipped (if any)
|
||||
/// @return true if there was a switch that was just flipped
|
||||
bool get_flipped_switch(SwitchKey* switch_);
|
||||
bool get_switch_flipped(SwitchKey* switch_);
|
||||
/// @brief Gets the raw state of the switches s1-s4 as bitflags.
|
||||
/// S1 is MSB and S4 is LSB.
|
||||
/// @return Bitflags for s1-s4.
|
||||
|
||||
@ -47,13 +47,14 @@ bool init_sd() {
|
||||
ESP_LOGI(TAG, "Filesystem mounted");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to mount sd card: %s.", esp_err_to_name(ret));
|
||||
|
||||
|
||||
lcd_print(0, 0, "SD Mount Failed!");
|
||||
lcd_print(0, 1, esp_err_to_name(ret));
|
||||
lcd_print(0, 2, "Press Green to retry");
|
||||
lcd_print(0, 3, "Press Red to format");
|
||||
|
||||
// TODO: impl buttons
|
||||
ButtonKey button;
|
||||
while (!( ))
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ void do_star_codes(StarCodeHandler* star_codes, int star_codes_len) {
|
||||
char current[STRING_MAX_LEN+1] = {0};
|
||||
|
||||
while (1) {
|
||||
while (get_pressed_keypad(&key)) {
|
||||
while (get_keypad_pressed(&key)) {
|
||||
if (key == KeypadKey::star) {
|
||||
current[0] = '*';
|
||||
for (int i = 1; i < STRING_MAX_LEN; i++) {
|
||||
|
||||
@ -26,7 +26,7 @@ static void battery_stats(void) {
|
||||
xReturned = xTaskCreate(bat_monitor_task, "bat_monitor", 4096, NULL, 5, &xHandle);
|
||||
|
||||
KeypadKey k;
|
||||
while (!get_pressed_keypad(&k) || k != KeypadKey::pound) vTaskDelay(pdMS_TO_TICKS(10));
|
||||
while (!get_keypad_pressed(&k) || k != KeypadKey::pound) vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
if (xReturned == pdPASS) {
|
||||
vTaskDelete(xHandle);
|
||||
@ -176,7 +176,7 @@ static void set_game_time(void) {
|
||||
KeypadKey key;
|
||||
ButtonKey button;
|
||||
while (1) {
|
||||
while (get_pressed_keypad(&key)) {
|
||||
while (get_keypad_pressed(&key)) {
|
||||
if (key == KeypadKey::star) {
|
||||
digits[0] = 0;
|
||||
digits[1] = 0;
|
||||
@ -244,7 +244,7 @@ static void set_game_time(void) {
|
||||
_update_display(digits, cursor_pos);
|
||||
}
|
||||
|
||||
while (get_pressed_button(&button)) {
|
||||
while (get_button_pressed(&button)) {
|
||||
if (button == ButtonKey::b1) {
|
||||
cursor_pos = MAX(0, cursor_pos-1);
|
||||
} else if (button == ButtonKey::b2) {
|
||||
@ -279,22 +279,22 @@ static void debug_switches(void) {
|
||||
ButtonKey button;
|
||||
SwitchKey switch_;
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
if (get_button_pressed(&button)) {
|
||||
sprintf(buf, "Button Pressed: %d ", button);
|
||||
lcd_print(0, 3, buf);
|
||||
ESP_LOGI(TAG, "%s", buf);
|
||||
}
|
||||
if (get_released_button(&button)) {
|
||||
if (get_button_released(&button)) {
|
||||
sprintf(buf, "Button Released: %d", button);
|
||||
lcd_print(0, 3, buf);
|
||||
ESP_LOGI(TAG, "%s", buf);
|
||||
}
|
||||
if (get_flipped_down_switch(&switch_)) {
|
||||
if (get_switch_flipped_down(&switch_)) {
|
||||
sprintf(buf, "Switch Down: %d ", switch_);
|
||||
lcd_print(0, 3, buf);
|
||||
ESP_LOGI(TAG, "%s", buf);
|
||||
}
|
||||
if (get_flipped_up_switch(&switch_)) {
|
||||
if (get_switch_flipped_up(&switch_)) {
|
||||
sprintf(buf, "Switch Up: %d ", switch_);
|
||||
lcd_print(0, 3, buf);
|
||||
ESP_LOGI(TAG, "%s", buf);
|
||||
@ -338,7 +338,7 @@ static void debug_switches(void) {
|
||||
}
|
||||
|
||||
|
||||
if (get_pressed_keypad(&key) && key == KeypadKey::pound) {
|
||||
if (get_keypad_pressed(&key) && key == KeypadKey::pound) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -229,7 +229,7 @@ static bool play_part(uint32_t time) {
|
||||
SwitchKey switch_;
|
||||
|
||||
while (times < 15) {
|
||||
while (get_pressed_button(&button)) {
|
||||
while (get_button_pressed(&button)) {
|
||||
start_module_timer();
|
||||
if ((int)(button) == correct) {
|
||||
times++;
|
||||
@ -240,7 +240,7 @@ static bool play_part(uint32_t time) {
|
||||
strike("Incorrect action");
|
||||
}
|
||||
}
|
||||
while (get_flipped_switch(&switch_)) {
|
||||
while (get_switch_flipped(&switch_)) {
|
||||
start_module_timer();
|
||||
if (switch_leds[(int)(switch_)] + 4 == correct) {
|
||||
times++;
|
||||
@ -269,7 +269,7 @@ static bool play_part(uint32_t time) {
|
||||
}
|
||||
|
||||
void step1(void) {
|
||||
while (get_flipped_switch(nullptr));
|
||||
while (get_switch_flipped(nullptr));
|
||||
|
||||
init_step();
|
||||
while (!play_part(40*1000));
|
||||
|
||||
@ -95,7 +95,7 @@ void step2(void) {
|
||||
while(solved_times < NUM_SOLVES) {
|
||||
// for every bit in the answer-
|
||||
set_module_sseg_raw(display_map);
|
||||
if (get_pressed_keypad(&key)) {
|
||||
if (get_keypad_pressed(&key)) {
|
||||
lcd_clear();
|
||||
char c = char_of_keypad_key(key);
|
||||
// ESP_LOGI(TAG, "Pressed: %c", c);
|
||||
|
||||
@ -78,7 +78,7 @@ void step3(void) {
|
||||
while (times < TIMES_TO_COMPLETE) {
|
||||
tone = tone_dist(gen);
|
||||
// tone = 2;
|
||||
while (get_pressed_button(nullptr)) vTaskDelay(pdMS_TO_TICKS(10));
|
||||
while (get_button_pressed(nullptr)) vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
play_raw(MOUNT_POINT "/que.pcm");
|
||||
play_raw(TONE_FILES[tone]);
|
||||
@ -193,7 +193,7 @@ static void debug_actual_values(uint8_t buttons, uint8_t switch_) {
|
||||
static void wait_for_timer(void) {
|
||||
KeypadKey key;
|
||||
while (get_module_time() > 0) {
|
||||
if (get_pressed_keypad(&key) && key == KeypadKey::kd) {
|
||||
if (get_keypad_pressed(&key) && key == KeypadKey::kd) {
|
||||
set_module_time(0);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ bool play_game(int time, int required_score) {
|
||||
show_board();
|
||||
|
||||
ButtonKey button;
|
||||
while (get_pressed_button(&button));
|
||||
while (get_button_pressed(&button));
|
||||
// SwitchKey switch_;
|
||||
|
||||
const TickType_t first_repeat_time = pdMS_TO_TICKS(700);
|
||||
@ -215,7 +215,7 @@ bool play_game(int time, int required_score) {
|
||||
TickType_t last_repeat = 0;
|
||||
|
||||
while(game) {
|
||||
while (get_pressed_button(&button)) {
|
||||
while (get_button_pressed(&button)) {
|
||||
switch (button) {
|
||||
case ButtonKey::b1:
|
||||
move_left();
|
||||
@ -240,7 +240,7 @@ bool play_game(int time, int required_score) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
while (get_released_button(&button)) {
|
||||
while (get_button_released(&button)) {
|
||||
if (button == ButtonKey::b3) {
|
||||
down_held = 0;
|
||||
}
|
||||
@ -269,7 +269,7 @@ bool play_game(int time, int required_score) {
|
||||
strike("Out of time");
|
||||
return false;
|
||||
}
|
||||
// if (get_flipped_switch(&switch_)) {
|
||||
// if (get_switch_flipped(&switch_)) {
|
||||
// printf("%d\n", piece);
|
||||
// for (int i = 0; i < sizeof(piece_nodes)/sizeof(piece_nodes[0]); i++) {
|
||||
// int* p = piece_nodes[i];
|
||||
@ -295,9 +295,9 @@ static void complete(void) {
|
||||
xSemaphoreGive(xGuiSemaphore);
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
while (get_pressed_button(nullptr));
|
||||
while (get_button_pressed(nullptr));
|
||||
while (1) {
|
||||
if (get_pressed_button(nullptr)) break;
|
||||
if (get_button_pressed(nullptr)) break;
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
if (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
@ -313,9 +313,9 @@ static void fail(void) {
|
||||
xSemaphoreGive(xGuiSemaphore);
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
while (get_pressed_button(nullptr));
|
||||
while (get_button_pressed(nullptr));
|
||||
while (1) {
|
||||
if (get_pressed_button(nullptr)) break;
|
||||
if (get_button_pressed(nullptr)) break;
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
if (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
|
||||
@ -248,7 +248,7 @@ void step5(void) {
|
||||
// wait for submit
|
||||
KeypadKey key;
|
||||
while (1) {
|
||||
if (get_module_time() <= 0 || (get_pressed_keypad(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
if (get_module_time() <= 0 || (get_keypad_pressed(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
solved_correctly = submit_0(green_indicators);
|
||||
break;
|
||||
}
|
||||
@ -278,7 +278,7 @@ void step5(void) {
|
||||
|
||||
KeypadKey key;
|
||||
while (1) {
|
||||
if (get_pressed_keypad(&key)) {
|
||||
if (get_keypad_pressed(&key)) {
|
||||
char keypad_char = char_of_keypad_key(key);
|
||||
if (keypad_char == '#') {
|
||||
solved_correctly = submit_1(indicators_num, pressed_keys, starting_switch_state);
|
||||
@ -329,7 +329,7 @@ void step5(void) {
|
||||
ButtonKey button;
|
||||
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
if (get_button_pressed(&button)) {
|
||||
uint8_t button_state = get_button_state();
|
||||
|
||||
if ((button_state & 0b1) == 0b1) {
|
||||
@ -355,7 +355,7 @@ void step5(void) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (get_pressed_keypad(&key)) {
|
||||
if (get_keypad_pressed(&key)) {
|
||||
char keypad_char = char_of_keypad_key(key);
|
||||
if (keypad_char == '#') {
|
||||
solved_correctly = submit_2(lit_leds, green_button_pressed, blue_button_pressed, fingerprint_sensor_pressed, keypad_string);
|
||||
@ -398,7 +398,7 @@ void step5(void) {
|
||||
|
||||
ButtonKey button;
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
if (get_button_pressed(&button)) {
|
||||
buttons_pressed++;
|
||||
uint8_t button_state = get_button_state();
|
||||
|
||||
@ -466,7 +466,7 @@ void step5(void) {
|
||||
uint8_t starting_switch_state = get_switch_state();
|
||||
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
if (get_button_pressed(&button)) {
|
||||
uint8_t button_state = get_button_state();
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
@ -481,7 +481,7 @@ void step5(void) {
|
||||
}
|
||||
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||
}
|
||||
if (get_module_time() <= 0 || (get_pressed_keypad(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
if (get_module_time() <= 0 || (get_keypad_pressed(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
solved_correctly = submit_4(button_colors, switch_colors, starting_switch_state);
|
||||
break;
|
||||
}
|
||||
@ -514,7 +514,7 @@ void step5(void) {
|
||||
KeypadKey key;
|
||||
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
if (get_button_pressed(&button)) {
|
||||
uint8_t button_state = get_button_state();
|
||||
bool failed = false;
|
||||
|
||||
@ -532,7 +532,7 @@ void step5(void) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (get_module_time() <= 0 || (get_pressed_keypad(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
if (get_module_time() <= 0 || (get_keypad_pressed(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
ESP_LOGI(TAG, "Keypad Char: %c, time: %lu", char_of_keypad_key(key), get_module_time());
|
||||
solved_correctly = submit_5(indicator_numbers, buttons_pressed);
|
||||
break;
|
||||
@ -580,7 +580,7 @@ void step5(void) {
|
||||
|
||||
std::uniform_int_distribution<> led_turn_on_dist(0, 3);
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
if (get_button_pressed(&button)) {
|
||||
uint8_t button_state = get_button_state();
|
||||
bool failed = false;
|
||||
|
||||
@ -623,7 +623,7 @@ void step5(void) {
|
||||
|
||||
lastCycleTime = xTaskGetTickCount();
|
||||
}
|
||||
if (get_module_time() <= 0 || (get_pressed_keypad(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
if (get_module_time() <= 0 || (get_keypad_pressed(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
solved_correctly = submit_6(buttons_cycling, button_turned_on, led_off);
|
||||
break;
|
||||
}
|
||||
@ -747,7 +747,7 @@ void step5(void) {
|
||||
KeypadKey key;
|
||||
|
||||
while (1) {
|
||||
if (get_pressed_keypad(&key)) {
|
||||
if (get_keypad_pressed(&key)) {
|
||||
if (key == KeypadKey::star) {
|
||||
// clear
|
||||
entered_string = "";
|
||||
@ -828,7 +828,7 @@ void step5(void) {
|
||||
|
||||
KeypadKey key;
|
||||
while (1) {
|
||||
if (get_pressed_keypad(&key)) {
|
||||
if (get_keypad_pressed(&key)) {
|
||||
bool failed = false;
|
||||
|
||||
if (key == KeypadKey::star) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user