93 lines
2.9 KiB
C++
93 lines
2.9 KiB
C++
#ifndef SETUP_WIRES_HPP
|
|
#define SETUP_WIRES_HPP
|
|
|
|
#include "../drivers/bottom_half.h"
|
|
#include "../drivers/char_lcd.hpp"
|
|
#include "wires_puzzle.h"
|
|
#include <esp_log.h>
|
|
|
|
void setup_wires(void) {
|
|
clear_all_pressed_released();
|
|
lcd_clear(&lcd);
|
|
|
|
WiresColor wires[NUM_WIRES];
|
|
load_wires_from_sd_card(wires);
|
|
|
|
bool cut[NUM_WIRES];
|
|
solve_wires(wires, cut);
|
|
|
|
lcd_set_cursor(&lcd, 1, 1);
|
|
char wires_string[NUM_WIRES+1] = {0};
|
|
wires_to_string(wires, wires_string);
|
|
lcd_print(&lcd, wires_string);
|
|
|
|
lcd_set_cursor(&lcd, 1, 2);
|
|
cut_to_string(cut, wires_string);
|
|
lcd_print(&lcd, wires_string);
|
|
lcd_set_cursor(&lcd, 1, 1);
|
|
|
|
int editing_idx = 0;
|
|
|
|
KeypadKey key;
|
|
ButtonKey button;
|
|
|
|
while (1) {
|
|
while (get_pressed_keypad(&key)) {
|
|
if (key == KeypadKey::k1) {
|
|
generate_new_wires(wires);
|
|
save_wires_to_sd_card(wires);
|
|
bool cut[NUM_WIRES];
|
|
solve_wires(wires, cut);
|
|
|
|
lcd_set_cursor(&lcd, 1, 1);
|
|
char wires_string[NUM_WIRES+1] = {0};
|
|
wires_to_string(wires, wires_string);
|
|
lcd_print(&lcd, wires_string);
|
|
|
|
lcd_set_cursor(&lcd, 1, 2);
|
|
cut_to_string(cut, wires_string);
|
|
lcd_print(&lcd, wires_string);
|
|
lcd_set_cursor(&lcd, editing_idx+1, 1);
|
|
} else if (key == KeypadKey::pound) {
|
|
lcd_no_cursor(&lcd);
|
|
return;
|
|
}
|
|
}
|
|
|
|
while (get_pressed_button(&button)) {
|
|
ESP_LOGI("setup_wires", "Button press: %d", (int)button);
|
|
if (button == ButtonKey::b1) {
|
|
// left
|
|
editing_idx = editing_idx - 1;
|
|
if (editing_idx < 0) editing_idx = 0;
|
|
} else if (button == ButtonKey::b4) {
|
|
// right
|
|
editing_idx = editing_idx + 1;
|
|
if (editing_idx >= NUM_WIRES) editing_idx = NUM_WIRES-1;
|
|
} else if (button == ButtonKey::b2) {
|
|
// down
|
|
wires[editing_idx] = (WiresColor)(((int)(wires[editing_idx]) + (NUM_COLORS-1)) % NUM_COLORS);
|
|
} else if (button == ButtonKey::b3) {
|
|
// up
|
|
wires[editing_idx] = (WiresColor)(((int)(wires[editing_idx]) + 1) % NUM_COLORS);
|
|
}
|
|
save_wires_to_sd_card(wires);
|
|
lcd_set_cursor(&lcd, 1, 1);
|
|
char wires_string[NUM_WIRES+1] = {0};
|
|
wires_to_string(wires, wires_string);
|
|
lcd_print(&lcd, wires_string);
|
|
|
|
bool cut[NUM_WIRES];
|
|
solve_wires(wires, cut);
|
|
lcd_set_cursor(&lcd, 1, 2);
|
|
cut_to_string(cut, wires_string);
|
|
lcd_print(&lcd, wires_string);
|
|
|
|
lcd_set_cursor(&lcd, editing_idx+1, 1);
|
|
}
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(10));
|
|
}
|
|
}
|
|
|
|
#endif /* SETUP_WIRES_HPP */ |