Compare commits
11
Commits
a9e44145f0
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcd4f5bb62 | ||
|
|
da781c23f1 | ||
|
|
0caf28c86a | ||
|
|
a8d3a61cf6 | ||
|
|
ee80bdb3eb | ||
|
|
aadd924bd0 | ||
|
|
53f58a3133 | ||
|
|
92d448020c | ||
|
|
202b926eb7 | ||
|
|
8bddceca66 | ||
|
|
cfc307ee72 |
@@ -8,14 +8,17 @@ set(SOURCES
|
|||||||
"char_lcd.cpp"
|
"char_lcd.cpp"
|
||||||
"game_info.cpp"
|
"game_info.cpp"
|
||||||
"game_timer.cpp"
|
"game_timer.cpp"
|
||||||
|
"hwdata.cpp"
|
||||||
"i2c_lcd_pcf8574.c"
|
"i2c_lcd_pcf8574.c"
|
||||||
"i2c.cpp"
|
"i2c.cpp"
|
||||||
"leds.cpp"
|
"leds.cpp"
|
||||||
|
"nvs.cpp"
|
||||||
|
"perh.cpp"
|
||||||
"power.cpp"
|
"power.cpp"
|
||||||
"sd.cpp"
|
"sd.cpp"
|
||||||
"speaker.cpp"
|
"speaker.cpp"
|
||||||
"sseg.cpp"
|
"sseg.cpp"
|
||||||
"star_code.cpp"
|
"starcode.cpp"
|
||||||
"state_tracking.cpp"
|
"state_tracking.cpp"
|
||||||
"tft.cpp"
|
"tft.cpp"
|
||||||
"wires.cpp"
|
"wires.cpp"
|
||||||
|
|||||||
@@ -711,9 +711,9 @@ bool BQ27441::writeExtendedData(uint8_t classID, uint8_t offset, uint8_t * data,
|
|||||||
int16_t BQ27441::i2cReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count)
|
int16_t BQ27441::i2cReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count)
|
||||||
{
|
{
|
||||||
int16_t timeout = BQ72441_I2C_TIMEOUT;
|
int16_t timeout = BQ72441_I2C_TIMEOUT;
|
||||||
xSemaphoreTake(i2c0_mutex, portMAX_DELAY);
|
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
||||||
i2c_master_write_read_device(BQ72441_I2C_NUM, _deviceAddress, &subAddress, 1, dest, count, timeout);
|
i2c_master_write_read_device(BQ72441_I2C_NUM, _deviceAddress, &subAddress, 1, dest, count, timeout);
|
||||||
xSemaphoreGive(i2c0_mutex);
|
xSemaphoreGive(main_i2c_mutex);
|
||||||
return timeout;
|
return timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -729,7 +729,9 @@ uint16_t BQ27441::i2cWriteBytes(uint8_t subAddress, uint8_t * src, uint8_t count
|
|||||||
w_buff[i+1] = src[i];
|
w_buff[i+1] = src[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
||||||
esp_err_t ret = i2c_master_write_to_device(BQ72441_I2C_NUM, _deviceAddress, src, count+1, timeout);
|
esp_err_t ret = i2c_master_write_to_device(BQ72441_I2C_NUM, _deviceAddress, src, count+1, timeout);
|
||||||
|
xSemaphoreGive(main_i2c_mutex);
|
||||||
|
|
||||||
return ret == ESP_OK;
|
return ret == ESP_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ void init_drivers() {
|
|||||||
init_i2c();
|
init_i2c();
|
||||||
// init char_lcd so we can use it to report other initialization errors.
|
// init char_lcd so we can use it to report other initialization errors.
|
||||||
init_lcd();
|
init_lcd();
|
||||||
|
init_nvs();
|
||||||
init_star_code_system();
|
init_star_code_system();
|
||||||
// init the bottom half so that we can get user input.
|
// init the bottom half so that we can get user input.
|
||||||
init_bottom_half();
|
init_bottom_half();
|
||||||
|
|||||||
+2
-1
@@ -6,11 +6,12 @@
|
|||||||
#include "game_timer.h"
|
#include "game_timer.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "leds.h"
|
#include "leds.h"
|
||||||
|
#include "nvs.h"
|
||||||
#include "power.h"
|
#include "power.h"
|
||||||
#include "sd.h"
|
#include "sd.h"
|
||||||
#include "speaker.h"
|
#include "speaker.h"
|
||||||
#include "sseg.h"
|
#include "sseg.h"
|
||||||
#include "star_code.h"
|
#include "starcode.h"
|
||||||
#include "state_tracking.h"
|
#include "state_tracking.h"
|
||||||
#include "tft.h"
|
#include "tft.h"
|
||||||
#include "wires.h"
|
#include "wires.h"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "bottom_half.h"
|
#include "bottom_half.h"
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include "state_tracking.h"
|
#include "state_tracking.h"
|
||||||
#include "star_code.h"
|
#include "starcode.h"
|
||||||
|
|
||||||
static const char *TAG = "bottom_half";
|
static const char *TAG = "bottom_half";
|
||||||
|
|
||||||
@@ -46,8 +46,14 @@ static bool replay_handler(const char* event, char* arg) {
|
|||||||
void init_bottom_half() {
|
void init_bottom_half() {
|
||||||
ESP_LOGI(TAG, "Initializing bottom half...");
|
ESP_LOGI(TAG, "Initializing bottom half...");
|
||||||
|
|
||||||
ESP_ERROR_CHECK(gpio_set_direction(BOTTOM_PIN_INTERUPT, GPIO_MODE_INPUT));
|
gpio_config_t int_conf = {
|
||||||
ESP_ERROR_CHECK(gpio_set_pull_mode(BOTTOM_PIN_INTERUPT, GPIO_PULLUP_ONLY));
|
.pin_bit_mask = 1ULL << BOTTOM_PIN_INTERUPT,
|
||||||
|
.mode = GPIO_MODE_INPUT,
|
||||||
|
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||||
|
.intr_type = GPIO_INTR_DISABLE,
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(gpio_config(&int_conf));
|
||||||
|
|
||||||
// TODO: do interupt stuff.
|
// TODO: do interupt stuff.
|
||||||
// ESP_ERROR_CHECK(gpio_intr_enable(BOTTOM_PIN_INTERUPT));
|
// ESP_ERROR_CHECK(gpio_intr_enable(BOTTOM_PIN_INTERUPT));
|
||||||
@@ -70,6 +76,7 @@ void init_bottom_half() {
|
|||||||
|
|
||||||
static uint8_t receive_delta(void) {
|
static uint8_t receive_delta(void) {
|
||||||
uint8_t reg = 1;
|
uint8_t reg = 1;
|
||||||
|
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
||||||
esp_err_t result = i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, ®, 1, buf, 1, (100 / portTICK_PERIOD_MS));
|
esp_err_t result = i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, ®, 1, buf, 1, (100 / portTICK_PERIOD_MS));
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(result);
|
ESP_ERROR_CHECK_WITHOUT_ABORT(result);
|
||||||
if (result != ESP_OK) {
|
if (result != ESP_OK) {
|
||||||
@@ -79,10 +86,11 @@ static uint8_t receive_delta(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void receive_keypad(void) {
|
static void receive_keypad(void) {
|
||||||
// TODO: use mutex
|
|
||||||
// TODO: change the bottom half polling scheme from a state-based protocol to an event based protocol
|
// TODO: change the bottom half polling scheme from a state-based protocol to an event based protocol
|
||||||
uint8_t reg = 2;
|
uint8_t reg = 2;
|
||||||
|
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
||||||
esp_err_t result = i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, ®, 1, buf, 2, (100 / portTICK_PERIOD_MS));
|
esp_err_t result = i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, ®, 1, buf, 2, (100 / portTICK_PERIOD_MS));
|
||||||
|
xSemaphoreGive(main_i2c_mutex);
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(result);
|
ESP_ERROR_CHECK_WITHOUT_ABORT(result);
|
||||||
if (result != ESP_OK) {
|
if (result != ESP_OK) {
|
||||||
return;
|
return;
|
||||||
@@ -111,7 +119,9 @@ static void receive_keypad(void) {
|
|||||||
|
|
||||||
static void receive_button_switch(void) {
|
static void receive_button_switch(void) {
|
||||||
uint8_t reg = 3;
|
uint8_t reg = 3;
|
||||||
|
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
||||||
esp_err_t result = i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, ®, 1, buf, 2, (100 / portTICK_PERIOD_MS));
|
esp_err_t result = i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, ®, 1, buf, 2, (100 / portTICK_PERIOD_MS));
|
||||||
|
xSemaphoreGive(main_i2c_mutex);
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(result);
|
ESP_ERROR_CHECK_WITHOUT_ABORT(result);
|
||||||
if (result != ESP_OK) {
|
if (result != ESP_OK) {
|
||||||
return;
|
return;
|
||||||
@@ -182,7 +192,9 @@ static void receive_button_switch(void) {
|
|||||||
static void receive_touch(void) {
|
static void receive_touch(void) {
|
||||||
uint8_t reg = 4;
|
uint8_t reg = 4;
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
|
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, ®, 1, buf, 1, (100 / portTICK_PERIOD_MS)));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, ®, 1, buf, 1, (100 / portTICK_PERIOD_MS)));
|
||||||
|
xSemaphoreGive(main_i2c_mutex);
|
||||||
bool new_touch_state = buf[0] != 0;
|
bool new_touch_state = buf[0] != 0;
|
||||||
|
|
||||||
bool just_pressed = new_touch_state & !touch_state;
|
bool just_pressed = new_touch_state & !touch_state;
|
||||||
|
|||||||
+13
-13
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#define BOTTOM_I2C_NUM I2C_NUM_0
|
#define BOTTOM_I2C_NUM I2C_NUM_0
|
||||||
#define BOTTOM_I2C_ADDR 126
|
#define BOTTOM_I2C_ADDR 126
|
||||||
#define BOTTOM_PIN_INTERUPT GPIO_NUM_0
|
#define BOTTOM_PIN_INTERUPT GPIO_NUM_13
|
||||||
|
|
||||||
#define DELTA_BIT_KP 0
|
#define DELTA_BIT_KP 0
|
||||||
#define DELTA_BIT_BUTTON_SWITCH 1
|
#define DELTA_BIT_BUTTON_SWITCH 1
|
||||||
@@ -14,22 +14,22 @@
|
|||||||
|
|
||||||
/// @brief An enum for the possible keypad buttons.
|
/// @brief An enum for the possible keypad buttons.
|
||||||
typedef enum {
|
typedef enum {
|
||||||
k1 = 0,
|
kd = 0,
|
||||||
k4 = 1,
|
pound = 1,
|
||||||
k7 = 2,
|
k0 = 2,
|
||||||
star = 3,
|
star = 3,
|
||||||
k2 = 4,
|
kc = 4,
|
||||||
k5 = 5,
|
k9 = 5,
|
||||||
k8 = 6,
|
k8 = 6,
|
||||||
k0 = 7,
|
k7 = 7,
|
||||||
k3 = 8,
|
kb = 8,
|
||||||
k6 = 9,
|
k6 = 9,
|
||||||
k9 = 10,
|
k5 = 10,
|
||||||
pound = 11,
|
k4 = 11,
|
||||||
ka = 12,
|
ka = 12,
|
||||||
kb = 13,
|
k3 = 13,
|
||||||
kc = 14,
|
k2 = 14,
|
||||||
kd = 15,
|
k1 = 15,
|
||||||
} KeypadKey;
|
} KeypadKey;
|
||||||
|
|
||||||
/// @brief An enum for the possible buttons.
|
/// @brief An enum for the possible buttons.
|
||||||
|
|||||||
+122
-78
@@ -5,8 +5,15 @@
|
|||||||
#include "state_tracking.h"
|
#include "state_tracking.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "power.h"
|
#include "power.h"
|
||||||
|
#include "starcode.h"
|
||||||
|
#include "game_info.h"
|
||||||
|
|
||||||
i2c_lcd_pcf8574_handle_t lcd;
|
i2c_lcd_pcf8574_handle_t lcd;
|
||||||
|
SemaphoreHandle_t lcd_mutex;
|
||||||
|
|
||||||
|
static volatile bool cursor_visible = false;
|
||||||
|
static volatile uint8_t cursor_resting_row = 0;
|
||||||
|
static volatile uint8_t cursor_resting_col = 0;
|
||||||
|
|
||||||
static volatile bool header_enabled = false;
|
static volatile bool header_enabled = false;
|
||||||
|
|
||||||
@@ -15,6 +22,7 @@ static const char* EMPTY_ROW = " ";
|
|||||||
|
|
||||||
static char buf[65];
|
static char buf[65];
|
||||||
|
|
||||||
|
// TODO: move this to power.cpp
|
||||||
static void monitor_battery_task(void* _arg) {
|
static void monitor_battery_task(void* _arg) {
|
||||||
(void) _arg;
|
(void) _arg;
|
||||||
|
|
||||||
@@ -27,53 +35,35 @@ static void monitor_battery_task(void* _arg) {
|
|||||||
static bool replay_handler(const char* event, char* arg) {
|
static bool replay_handler(const char* event, char* arg) {
|
||||||
if (strcmp(event, "LCD_CLEAR") == 0) {
|
if (strcmp(event, "LCD_CLEAR") == 0) {
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_CURSOR") == 0) {
|
else if (strcmp(event, "LCD_SET_DISPLAY") == 0) {
|
||||||
char* col_str = strtok(arg, ",");
|
|
||||||
char* row_str = strtok(NULL, ",");
|
|
||||||
uint32_t col = atoi(col_str);
|
|
||||||
uint32_t row = atoi(row_str);
|
|
||||||
lcd_set_cursor_pos(col, row);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (strcmp(event, "LCD_SET_DISPLAY") == 0) {
|
|
||||||
lcd_set_display(strcmp(arg, "true") == 0);
|
lcd_set_display(strcmp(arg, "true") == 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_CURSOR_VIS") == 0) {
|
else if (strcmp(event, "LCD_CURSOR_VIS") == 0) {
|
||||||
lcd_set_cursor_vis(strcmp(arg, "true") == 0);
|
lcd_set_cursor_vis(strcmp(arg, "true") == 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_CURSOR_BLINK") == 0) {
|
else if (strcmp(event, "LCD_CURSOR_BLINK") == 0) {
|
||||||
lcd_set_cursor_blink(strcmp(arg, "true") == 0);
|
lcd_set_cursor_blink(strcmp(arg, "true") == 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_SCROLL_DISPLAY_LEFT") == 0) {
|
else if (strcmp(event, "LCD_SCROLL_DISPLAY_LEFT") == 0) {
|
||||||
lcd_scroll_display_left();
|
lcd_scroll_display_left();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_SCROLL_DISPLAY_RIGHT") == 0) {
|
else if (strcmp(event, "LCD_SCROLL_DISPLAY_RIGHT") == 0) {
|
||||||
lcd_scroll_display_right();
|
lcd_scroll_display_right();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_LEFT_TO_RIGHT") == 0) {
|
else if (strcmp(event, "LCD_LEFT_TO_RIGHT") == 0) {
|
||||||
lcd_left_to_right();
|
lcd_left_to_right();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_RIGHT_TO_LEFT") == 0) {
|
else if (strcmp(event, "LCD_RIGHT_TO_LEFT") == 0) {
|
||||||
lcd_right_to_left();
|
lcd_right_to_left();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_AUTOSCROLL") == 0) {
|
else if (strcmp(event, "LCD_AUTOSCROLL") == 0) {
|
||||||
lcd_set_autoscroll(strcmp(arg, "true") == 0);
|
lcd_set_autoscroll(strcmp(arg, "true") == 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_BACKLIGHT") == 0) {
|
else if (strcmp(event, "LCD_BACKLIGHT") == 0) {
|
||||||
lcd_set_backlight(strcmp(arg, "true") == 0);
|
lcd_set_backlight(strcmp(arg, "true") == 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_CREATE_CHAR") == 0) {
|
else if (strcmp(event, "LCD_CREATE_CHAR") == 0) {
|
||||||
char* location_str = strtok(arg, ",");
|
char* location_str = strtok(arg, ",");
|
||||||
uint8_t location = atoi(location_str);
|
uint8_t location = atoi(location_str);
|
||||||
|
|
||||||
@@ -84,24 +74,34 @@ static bool replay_handler(const char* event, char* arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lcd_create_char(location, charmap);
|
lcd_create_char(location, charmap);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (strcmp(event, "LCD_PRINT") == 0) {
|
else if (strcmp(event, "LCD_PRINT") == 0) {
|
||||||
|
char* str = strtok(arg, ",");
|
||||||
|
uint8_t row = atoi(str);
|
||||||
|
str = strtok(NULL, ",");
|
||||||
|
uint8_t col = atoi(str);
|
||||||
|
// get remaining part of string.
|
||||||
|
str = strtok(NULL, "");
|
||||||
|
|
||||||
// TODO: handle \r and \n
|
// TODO: handle \r and \n
|
||||||
lcd_print(&lcd, arg);
|
lcd_print(row, col, str);
|
||||||
return true;
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_lcd() {
|
void init_lcd() {
|
||||||
ESP_LOGI(TAG, "Initializing LCD...");
|
ESP_LOGI(TAG, "Initializing LCD...");
|
||||||
|
|
||||||
|
lcd_mutex = xSemaphoreCreateMutex();
|
||||||
|
assert(lcd_mutex != NULL);
|
||||||
|
|
||||||
lcd_init(&lcd, LCD_ADDR, CHAR_LCD_I2C_NUM);
|
lcd_init(&lcd, LCD_ADDR, CHAR_LCD_I2C_NUM);
|
||||||
lcd_begin(&lcd, LCD_COLS, LCD_ROWS);
|
lcd_begin(&lcd, LCD_COLS, LCD_ROWS);
|
||||||
|
|
||||||
lcd_set_backlight(&lcd, 255);
|
lcd_set_backlight_to(&lcd, 1);
|
||||||
|
|
||||||
register_replay_fn(replay_handler);
|
register_replay_fn(replay_handler);
|
||||||
|
|
||||||
@@ -110,115 +110,124 @@ void init_lcd() {
|
|||||||
ESP_LOGI(TAG, "LCD initialized!");
|
ESP_LOGI(TAG, "LCD initialized!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_clear() {
|
void lcd_clear(bool no_lock) {
|
||||||
if (!header_enabled) {
|
if (!header_enabled) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_clear(&lcd);
|
lcd_clear(&lcd);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_CLEAR", NULL);
|
event_occured("LCD_CLEAR", NULL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lcd_print(0, 1, EMPTY_ROW);
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_print(0, 2, EMPTY_ROW);
|
lcd_print(1, 0, EMPTY_ROW, true);
|
||||||
lcd_print(0, 3, EMPTY_ROW);
|
lcd_print(2, 0, EMPTY_ROW, true);
|
||||||
|
lcd_print(3, 0, EMPTY_ROW, true);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rm
|
void lcd_set_display(bool display, bool no_lock) {
|
||||||
void lcd_cursor_home() {
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_set_cursor_pos(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: with print requiring you to set a pos every time, this function is not helpful
|
|
||||||
void lcd_set_cursor_pos(uint8_t col, uint8_t row) {
|
|
||||||
lcd_set_cursor(&lcd, col, row);
|
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
|
||||||
sprintf(buf, "%d,%d", col, row);
|
|
||||||
event_occured("LCD_CURSOR", buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void lcd_set_display(bool display) {
|
|
||||||
if (display) {
|
if (display) {
|
||||||
lcd_display(&lcd);
|
lcd_display(&lcd);
|
||||||
} else {
|
} else {
|
||||||
lcd_no_display(&lcd);
|
lcd_no_display(&lcd);
|
||||||
}
|
}
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_SET_DISPLAY", display ? "true" : "false");
|
event_occured("LCD_SET_DISPLAY", display ? "true" : "false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_set_cursor_vis(bool cursor) {
|
void lcd_set_cursor_vis(bool cursor, bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
lcd_cursor(&lcd);
|
lcd_cursor(&lcd);
|
||||||
} else {
|
} else {
|
||||||
lcd_no_cursor(&lcd);
|
lcd_no_cursor(&lcd);
|
||||||
}
|
}
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
|
cursor_visible = cursor;
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_CURSOR_VIS", cursor ? "true" : "false");
|
event_occured("LCD_CURSOR_VIS", cursor ? "true" : "false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_set_cursor_blink(bool blink) {
|
void lcd_set_cursor_blink(bool blink, bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
if (blink) {
|
if (blink) {
|
||||||
lcd_blink(&lcd);
|
lcd_blink(&lcd);
|
||||||
} else {
|
} else {
|
||||||
lcd_no_blink(&lcd);
|
lcd_no_blink(&lcd);
|
||||||
}
|
}
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_CURSOR_BLINK", blink ? "true" : "false");
|
event_occured("LCD_CURSOR_BLINK", blink ? "true" : "false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_scroll_display_left() {
|
void lcd_scroll_display_left(bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_scroll_display_left(&lcd);
|
lcd_scroll_display_left(&lcd);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_SCROLL_DISPLAY_LEFT", NULL);
|
event_occured("LCD_SCROLL_DISPLAY_LEFT", NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void lcd_scroll_display_right() {
|
void lcd_scroll_display_right(bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_scroll_display_right(&lcd);
|
lcd_scroll_display_right(&lcd);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_SCROLL_DISPLAY_RIGHT", NULL);
|
event_occured("LCD_SCROLL_DISPLAY_RIGHT", NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_left_to_right() {
|
void lcd_left_to_right(bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_left_to_right(&lcd);
|
lcd_left_to_right(&lcd);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_LEFT_TO_RIGHT", NULL);
|
event_occured("LCD_LEFT_TO_RIGHT", NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void lcd_right_to_left() {
|
void lcd_right_to_left(bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_right_to_left(&lcd);
|
lcd_right_to_left(&lcd);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_RIGHT_TO_LEFT", NULL);
|
event_occured("LCD_RIGHT_TO_LEFT", NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_set_autoscroll(bool autoscroll) {
|
void lcd_set_autoscroll(bool autoscroll, bool no_lock) {
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
if (autoscroll) {
|
if (autoscroll) {
|
||||||
lcd_autoscroll(&lcd);
|
lcd_autoscroll(&lcd);
|
||||||
} else {
|
} else {
|
||||||
lcd_no_autoscroll(&lcd);
|
lcd_no_autoscroll(&lcd);
|
||||||
}
|
}
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
event_occured("LCD_AUTOSCROLL", autoscroll ? "true" : "false");
|
event_occured("LCD_AUTOSCROLL", autoscroll ? "true" : "false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_set_backlight(bool backlight) {
|
void lcd_set_backlight(bool backlight, bool no_lock) {
|
||||||
lcd_set_backlight(&lcd, backlight);
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
|
lcd_set_backlight_to(&lcd, backlight);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
sprintf(buf, "%d", backlight);
|
sprintf(buf, "%d", backlight);
|
||||||
@@ -226,11 +235,15 @@ void lcd_set_backlight(bool backlight) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_create_char(uint8_t location, const uint8_t charmap[]) {
|
void lcd_create_char(uint8_t location, const uint8_t charmap[], bool no_lock) {
|
||||||
|
if (location == 8) location = 0;
|
||||||
|
|
||||||
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_create_char(&lcd, location, charmap);
|
lcd_create_char(&lcd, location, charmap);
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
snprintf(buf, 65,
|
snprintf(buf, sizeof(buf),
|
||||||
"%d,%d,%d,%d,%d,%d,%d,%d,%d", location,
|
"%d,%d,%d,%d,%d,%d,%d,%d,%d", location,
|
||||||
charmap[0], charmap[1], charmap[2], charmap[3], charmap[4], charmap[5], charmap[6], charmap[7]
|
charmap[0], charmap[1], charmap[2], charmap[3], charmap[4], charmap[5], charmap[6], charmap[7]
|
||||||
);
|
);
|
||||||
@@ -238,14 +251,21 @@ void lcd_create_char(uint8_t location, const uint8_t charmap[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: switch to row, col
|
void lcd_print(uint8_t row, uint8_t col, const char* str, bool no_lock) {
|
||||||
void lcd_print(uint8_t col, uint8_t row, const char* str) {
|
if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_set_cursor_pos(col, row);
|
lcd_set_cursor(&lcd, col, row);
|
||||||
lcd_print(&lcd, str);
|
lcd_print(&lcd, str);
|
||||||
|
|
||||||
|
if (cursor_visible) {
|
||||||
|
lcd_set_cursor(&lcd, cursor_resting_col, cursor_resting_row);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!no_lock) xSemaphoreGive(lcd_mutex);
|
||||||
|
|
||||||
if (is_state_tracking()) {
|
if (is_state_tracking()) {
|
||||||
// TODO: handle \r and \n
|
// TODO: handle \r and \n and others
|
||||||
event_occured("LCD_PRINT", str);
|
snprintf(buf, sizeof(buf), "%d,%d,%s", row, col, str);
|
||||||
|
event_occured("LCD_PRINT", buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,13 +302,37 @@ void lcd_do_splash() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// TODO: make the lcd_lib somehow support the custom character 0 which would otherwise be a null terminator
|
// TODO: make the lcd_lib somehow support the custom character 0 which would otherwise be a null terminator
|
||||||
lcd_create_char(1, custom_char[0]);
|
xSemaphoreTake(lcd_mutex, portMAX_DELAY);
|
||||||
lcd_create_char(2, custom_char[1]);
|
lcd_create_char(1, custom_char[0], true);
|
||||||
lcd_create_char(3, custom_char[2]);
|
lcd_create_char(2, custom_char[1], true);
|
||||||
lcd_create_char(4, custom_char[3]);
|
lcd_create_char(3, custom_char[2], true);
|
||||||
lcd_create_char(5, custom_char[4]);
|
lcd_create_char(4, custom_char[3], true);
|
||||||
lcd_create_char(6, custom_char[5]);
|
lcd_create_char(5, custom_char[4], true);
|
||||||
|
lcd_create_char(6, custom_char[5], true);
|
||||||
|
|
||||||
lcd_print(6, 1, "\x01\x02Marino");
|
lcd_print(1, 6, "\x01\x02Marino", true);
|
||||||
lcd_print(5, 2, "\x03\x04\x05\x06""DEV");
|
lcd_print(2, 5, "\x03\x04\x05\x06""DEV", true);
|
||||||
|
xSemaphoreGive(lcd_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lcd_lock(uint32_t ticks_to_wait) {
|
||||||
|
return xSemaphoreTake(lcd_mutex, ticks_to_wait);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcd_unlock() {
|
||||||
|
xSemaphoreGive(lcd_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcd_set_cursor_resting_position(uint8_t row, uint8_t col) {
|
||||||
|
cursor_resting_row = row;
|
||||||
|
cursor_resting_col = col;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcd_get_cursor_resting_position(uint8_t* row, uint8_t* col) {
|
||||||
|
if (row) *row = cursor_resting_row;
|
||||||
|
if (col) *col = cursor_resting_col;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lcd_is_cursor_visible() {
|
||||||
|
return cursor_visible;
|
||||||
}
|
}
|
||||||
+55
-40
@@ -6,54 +6,53 @@
|
|||||||
#define CHAR_LCD_I2C_NUM I2C_NUM_0
|
#define CHAR_LCD_I2C_NUM I2C_NUM_0
|
||||||
|
|
||||||
#define LCD_ADDR 0x27
|
#define LCD_ADDR 0x27
|
||||||
#define LCD_COLS 20
|
|
||||||
#define LCD_ROWS 4
|
#define LCD_ROWS 4
|
||||||
|
#define LCD_COLS 20
|
||||||
|
|
||||||
/// Initializes the 2004 Character LCD
|
/// @brief Initializes the 2004 Character LCD
|
||||||
void init_lcd();
|
void init_lcd();
|
||||||
|
|
||||||
/// Clear the LCD
|
/// @brief Clear the LCD
|
||||||
void lcd_clear();
|
void lcd_clear(bool no_lock = false);
|
||||||
|
|
||||||
/// Move cursor to home position
|
/// @brief Move cursor to home position
|
||||||
void lcd_cursor_home();
|
void lcd_cursor_home(bool no_lock = false);
|
||||||
|
|
||||||
/// Set cursor position
|
/// @brief Turn the display on/off
|
||||||
void lcd_set_cursor_pos(uint8_t col, uint8_t row);
|
void lcd_set_display(bool display, bool no_lock = false);
|
||||||
|
|
||||||
/// Turn the display on/off
|
/// @brief Turn the cursor's visibility on/off
|
||||||
void lcd_set_display(bool display);
|
void lcd_set_cursor_vis(bool cursor, bool no_lock = false);
|
||||||
|
|
||||||
/// Turn the cursor's visibility on/off
|
/// @brief Turn blinking cursor on/off
|
||||||
void lcd_set_cursor_vis(bool cursor);
|
void lcd_set_cursor_blink(bool blink, bool no_lock = false);
|
||||||
|
|
||||||
/// Turn blinking cursor on/off
|
/// @brief Scroll the display left
|
||||||
void lcd_set_cursor_blink(bool blink);
|
void lcd_scroll_display_left(bool no_lock = false);
|
||||||
|
/// @brief Scroll the display right
|
||||||
|
void lcd_scroll_display_right(bool no_lock = false);
|
||||||
|
|
||||||
/// Scroll the display left
|
/// @brief Set the text to flows automatically left to right
|
||||||
void lcd_scroll_display_left();
|
void lcd_left_to_right(bool no_lock = false);
|
||||||
/// Scroll the display right
|
/// @brief Set the text to flows automatically right to left
|
||||||
void lcd_scroll_display_right();
|
void lcd_right_to_left(bool no_lock = false);
|
||||||
|
|
||||||
/// Set the text to flows automatically left to right
|
/// @brief Turn on/off autoscroll
|
||||||
void lcd_left_to_right();
|
void lcd_set_autoscroll(bool autoscroll, bool no_lock = false);
|
||||||
/// Set the text to flows automatically right to left
|
|
||||||
void lcd_right_to_left();
|
|
||||||
|
|
||||||
// Turn on/off autoscroll
|
/// @brief Set backlight brightness
|
||||||
void lcd_set_autoscroll(bool autoscroll);
|
void lcd_set_backlight(bool backlight, bool no_lock = false);
|
||||||
|
|
||||||
// Set backlight brightness
|
/// @brief Create a custom character. You get 8 custom characters.
|
||||||
void lcd_set_backlight(bool backlight);
|
/// You can print custom characters by using escape characters in strings:
|
||||||
|
/// use '\x01' - '\x07' for custom characters 1-7. Use '\x08' for custom char 0.
|
||||||
// Create a custom character
|
void lcd_create_char(uint8_t location, const uint8_t charmap[], bool no_lock = false);
|
||||||
void lcd_create_char(uint8_t location, const uint8_t charmap[]);
|
|
||||||
|
|
||||||
/// @brief Print a string to the LCD at a given pos.
|
/// @brief Print a string to the LCD at a given pos.
|
||||||
/// @param col the column to print the string at.
|
|
||||||
/// @param row the row the print the string at.
|
/// @param row the row the print the string at.
|
||||||
|
/// @param col the column to print the string at.
|
||||||
/// @param str the string to print.
|
/// @param str the string to print.
|
||||||
void lcd_print(uint8_t col, uint8_t row, const char* str);
|
void lcd_print(uint8_t row, uint8_t col, const char* str, bool no_lock = false);
|
||||||
|
|
||||||
/// @brief Enables or disables the header on the LCD.
|
/// @brief Enables or disables the header on the LCD.
|
||||||
/// @param enable `true` to enable the header, `false` to disable.
|
/// @param enable `true` to enable the header, `false` to disable.
|
||||||
@@ -66,16 +65,32 @@ bool lcd_header_enabled();
|
|||||||
/// @brief Prints the header in the LCD.
|
/// @brief Prints the header in the LCD.
|
||||||
void lcd_print_header();
|
void lcd_print_header();
|
||||||
|
|
||||||
/// @brief Prints the star code section of the LCD header.
|
|
||||||
void lcd_print_header_star_code();
|
|
||||||
|
|
||||||
/// @brief Prints the step section of the LCD header.
|
|
||||||
void lcd_print_header_step();
|
|
||||||
|
|
||||||
/// @brief Prints the battery section of the LCD header.
|
|
||||||
void lcd_print_header_bat();
|
|
||||||
|
|
||||||
/// @brief Prints the splash screen for the BLK_BOX.
|
/// @brief Prints the splash screen for the BLK_BOX.
|
||||||
void lcd_do_splash();
|
void lcd_do_splash();
|
||||||
|
|
||||||
|
/// @brief Locks the LCD to allow chaining multiple commands without interuptions.
|
||||||
|
///
|
||||||
|
/// Commands you call while you lock the LCD, you must call with the `no_lock` flag set to true.
|
||||||
|
///
|
||||||
|
/// Do not hold this lock for an extended period of time.
|
||||||
|
/// @return `true` iff the lock was aquired.
|
||||||
|
bool lcd_lock(uint32_t ticks_to_wait);
|
||||||
|
|
||||||
|
/// @brief Unlocks the LCD to give away the mutex access to it.
|
||||||
|
void lcd_unlock();
|
||||||
|
|
||||||
|
/// @brief Set the resting position for the cursor
|
||||||
|
/// @param row the row where the cursor should rest
|
||||||
|
/// @param col the column where the cursor should rest
|
||||||
|
void lcd_set_cursor_resting_position(uint8_t row, uint8_t col);
|
||||||
|
|
||||||
|
/// @brief Get the current resting position of the cursor
|
||||||
|
/// @param row pointer to store the resting row
|
||||||
|
/// @param col pointer to store the resting column
|
||||||
|
void lcd_get_cursor_resting_position(uint8_t* row, uint8_t* col);
|
||||||
|
|
||||||
|
/// @brief Check if the cursor is currently visible
|
||||||
|
/// @return true if cursor is visible, false otherwise
|
||||||
|
bool lcd_is_cursor_visible();
|
||||||
|
|
||||||
#endif /* CHAR_LCD_H */
|
#endif /* CHAR_LCD_H */
|
||||||
@@ -1,23 +1,21 @@
|
|||||||
#include "game_info.h"
|
#include "game_info.h"
|
||||||
|
#include "starcode.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "char_lcd.h"
|
#include "char_lcd.h"
|
||||||
|
|
||||||
// static char game_state[GAME_STATE_MAX_LEN+1] = " ";
|
static char game_state[GAME_STATE_MAX_LEN+2] = " MENU ";
|
||||||
static char game_state[GAME_STATE_MAX_LEN+1] = "MENU ";
|
|
||||||
|
|
||||||
void set_game_state(char* new_state) {
|
void set_game_state(const char* new_state) {
|
||||||
snprintf(game_state, sizeof(game_state), " %-5s", new_state);
|
snprintf(game_state, sizeof(game_state), " %-5s", new_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_game_state() {
|
void reset_game_state() {
|
||||||
for (int i = 0; i < GAME_STATE_MAX_LEN; i++) {
|
set_game_state("");
|
||||||
game_state[i] = '\0';
|
|
||||||
}
|
|
||||||
game_state[GAME_STATE_MAX_LEN] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_print_header_step() {
|
void lcd_print_header_step() {
|
||||||
if (!lcd_header_enabled()) return;
|
if (!lcd_header_enabled()) return;
|
||||||
|
if (lcd_starcode_displaying_result()) return;
|
||||||
|
|
||||||
lcd_print(10, 0, game_state);
|
lcd_print(0, 10, game_state);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,12 @@
|
|||||||
/// @brief Sets the game state, used for the header.
|
/// @brief Sets the game state, used for the header.
|
||||||
///
|
///
|
||||||
/// Must be <= 5 characters
|
/// Must be <= 5 characters
|
||||||
void set_game_state(char* new_state);
|
void set_game_state(const char* new_state);
|
||||||
|
|
||||||
/// @brief Resets the game state to be blank.
|
/// @brief Resets the game state to be blank.
|
||||||
void reset_game_state();
|
void reset_game_state();
|
||||||
|
|
||||||
/// @brief Prints the game state section of the header to the char_lcd. (row 0, columns 10-14)
|
/// @brief Prints the game state section of the header to the char_lcd. (row 0, columns 11-15)
|
||||||
void lcd_print_header_step();
|
void lcd_print_header_step();
|
||||||
|
|
||||||
#endif /* GAME_INFO_H */
|
#endif /* GAME_INFO_H */
|
||||||
@@ -0,0 +1,494 @@
|
|||||||
|
#include "hwdata.h"
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "bottom_half.h"
|
||||||
|
#include "char_lcd.h"
|
||||||
|
#include "../helper.h"
|
||||||
|
#include "nvs.h"
|
||||||
|
|
||||||
|
static const char* TAG = "hwdata";
|
||||||
|
|
||||||
|
HWData::HWData()
|
||||||
|
: compat_mode(true)
|
||||||
|
{}
|
||||||
|
|
||||||
|
HWData::HWData(HWData1 data, bool compat_mode)
|
||||||
|
: compat_mode(compat_mode),
|
||||||
|
inner(data)
|
||||||
|
{}
|
||||||
|
|
||||||
|
esp_err_t HWData::save(nvs_handle_t handle, bool force) {
|
||||||
|
if (compat_mode && !force) {
|
||||||
|
ESP_LOGW(TAG, "Not saving due to being in compatability mode.");
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
return inner.save(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
HWData HWData::load(nvs_handle_t handle) {
|
||||||
|
esp_err_t err;
|
||||||
|
|
||||||
|
uint16_t stored_version = 0;
|
||||||
|
err = nvs_get_u16(handle, "version", &stored_version);
|
||||||
|
if (err == ESP_ERR_NVS_NOT_FOUND) {
|
||||||
|
ESP_LOGE(TAG, "No NVS data found! using defaults");
|
||||||
|
return HWData();
|
||||||
|
} else if (err != ESP_OK) {
|
||||||
|
ESP_ERROR_CHECK_WITHOUT_ABORT(err);
|
||||||
|
ESP_LOGE(TAG, "Other esp error! using defaults");
|
||||||
|
return HWData();
|
||||||
|
}
|
||||||
|
|
||||||
|
HWData1 data;
|
||||||
|
switch (stored_version) {
|
||||||
|
case 0:
|
||||||
|
ESP_LOGE(TAG, "HWData version was 0! using defaults");
|
||||||
|
return HWData();
|
||||||
|
case 1:
|
||||||
|
data.load(handle);
|
||||||
|
return HWData(data, false);
|
||||||
|
default:
|
||||||
|
ESP_LOGW(TAG, "Max currently supported version is %d, but saved version is %d. Loading version %d anyway!", CURRENT_HWDATA_VERSION, stored_version, CURRENT_HWDATA_VERSION);
|
||||||
|
data.load(handle);
|
||||||
|
return HWData(data, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HWData1::HWData1() {}
|
||||||
|
|
||||||
|
esp_err_t HWData1::save(nvs_handle_t handle) const {
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u16(handle, "version", 1));
|
||||||
|
|
||||||
|
// Serial number
|
||||||
|
ESP_ERROR_CHECK(nvs_set_str(handle, "serial_num", serial_num.c_str()));
|
||||||
|
|
||||||
|
// Revisions
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "rev_ctrl_maj", rev_ctrl_maj));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "rev_ctrl_min", rev_ctrl_min));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "rev_exp_maj", rev_exp_maj));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "rev_exp_min", rev_exp_min));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "rev_ft_maj", rev_ft_maj));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "rev_ft_min", rev_ft_min));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "rev_fb_maj", rev_fb_maj));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "rev_fb_min", rev_fb_min));
|
||||||
|
|
||||||
|
// Enums
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "sseg_color_t", static_cast<uint8_t>(sseg_color_t)));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "sseg_color_b", static_cast<uint8_t>(sseg_color_b)));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "lcd_color", static_cast<uint8_t>(lcd_color)));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "button_type", static_cast<uint8_t>(button_type)));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "tft_type", static_cast<uint8_t>(tft_type)));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "bat_type", static_cast<uint8_t>(bat_type)));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "shape1", static_cast<uint8_t>(shape1)));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "shape2", static_cast<uint8_t>(shape2)));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "shape3", static_cast<uint8_t>(shape3)));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "shape4", static_cast<uint8_t>(shape4)));
|
||||||
|
|
||||||
|
// Other fields
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "switch_pos", switch_pos));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "has_speaker", has_speaker));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "has_mic", has_mic));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "has_ir", has_ir));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "has_rfid", has_rfid));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "has_fp", has_fp));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "has_fp_hall", has_fp_hall));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u8(handle, "has_close_hall", has_close_hall));
|
||||||
|
|
||||||
|
// Battery capacity
|
||||||
|
ESP_ERROR_CHECK(nvs_set_u16(handle, "bat_cap", bat_cap));
|
||||||
|
|
||||||
|
return nvs_commit(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HWData1::load(nvs_handle_t handle) {
|
||||||
|
char buf[128];
|
||||||
|
size_t required_size = sizeof(buf);
|
||||||
|
esp_err_t err = nvs_get_str(handle, "serial_num", buf, &required_size);
|
||||||
|
serial_num = (err == ESP_OK) ? std::string(buf) : "";
|
||||||
|
|
||||||
|
nvs_get_u8(handle, "rev_ctrl_maj", &rev_ctrl_maj);
|
||||||
|
nvs_get_u8(handle, "rev_ctrl_min", &rev_ctrl_min);
|
||||||
|
nvs_get_u8(handle, "rev_exp_maj", &rev_exp_maj);
|
||||||
|
nvs_get_u8(handle, "rev_exp_min", &rev_exp_min);
|
||||||
|
nvs_get_u8(handle, "rev_ft_maj", &rev_ft_maj);
|
||||||
|
nvs_get_u8(handle, "rev_ft_min", &rev_ft_min);
|
||||||
|
nvs_get_u8(handle, "rev_fb_maj", &rev_fb_maj);
|
||||||
|
nvs_get_u8(handle, "rev_fb_min", &rev_fb_min);
|
||||||
|
|
||||||
|
uint8_t tmp;
|
||||||
|
if (nvs_get_u8(handle, "sseg_color_t", &tmp) == ESP_OK) sseg_color_t = static_cast<SSegColor>(tmp);
|
||||||
|
if (nvs_get_u8(handle, "sseg_color_b", &tmp) == ESP_OK) sseg_color_b = static_cast<SSegColor>(tmp);
|
||||||
|
if (nvs_get_u8(handle, "lcd_color", &tmp) == ESP_OK) lcd_color = static_cast<LCDColor>(tmp);
|
||||||
|
if (nvs_get_u8(handle, "button_type", &tmp) == ESP_OK) button_type = static_cast<ButtonType>(tmp);
|
||||||
|
if (nvs_get_u8(handle, "tft_type", &tmp) == ESP_OK) tft_type = static_cast<TFTType>(tmp);
|
||||||
|
if (nvs_get_u8(handle, "bat_type", &tmp) == ESP_OK) bat_type = static_cast<BatType>(tmp);
|
||||||
|
nvs_get_u16(handle, "bat_cap", &bat_cap);
|
||||||
|
|
||||||
|
if (nvs_get_u8(handle, "shape1", &tmp) == ESP_OK) shape1 = static_cast<ShapeType>(tmp);
|
||||||
|
if (nvs_get_u8(handle, "shape2", &tmp) == ESP_OK) shape2 = static_cast<ShapeType>(tmp);
|
||||||
|
if (nvs_get_u8(handle, "shape3", &tmp) == ESP_OK) shape3 = static_cast<ShapeType>(tmp);
|
||||||
|
if (nvs_get_u8(handle, "shape4", &tmp) == ESP_OK) shape4 = static_cast<ShapeType>(tmp);
|
||||||
|
|
||||||
|
nvs_get_u8(handle, "switch_pos", &switch_pos);
|
||||||
|
nvs_get_u8(handle, "has_speaker", &tmp); has_speaker = tmp;
|
||||||
|
nvs_get_u8(handle, "has_mic", &tmp); has_mic = tmp;
|
||||||
|
nvs_get_u8(handle, "has_ir", &tmp); has_ir = tmp;
|
||||||
|
nvs_get_u8(handle, "has_rfid", &tmp); has_rfid = tmp;
|
||||||
|
nvs_get_u8(handle, "has_fp", &tmp); has_fp = tmp;
|
||||||
|
nvs_get_u8(handle, "has_fp_hall", &tmp); has_fp_hall = tmp;
|
||||||
|
nvs_get_u8(handle, "has_close_hall", &tmp); has_close_hall = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_uint8(KeypadKey key, uint8_t& val) {
|
||||||
|
char key_c = char_of_keypad_key(key);
|
||||||
|
bool is_digit = std::isdigit(static_cast<unsigned char>(key_c));
|
||||||
|
uint8_t digit = is_digit ? static_cast<uint8_t>(key_c - '0') : 0;
|
||||||
|
|
||||||
|
if (key == KeypadKey::star) {
|
||||||
|
val = 0;
|
||||||
|
} else if (is_digit) {
|
||||||
|
uint16_t new_digit = ((uint16_t) val) * 10 + (uint16_t) digit;
|
||||||
|
if (new_digit < 255) val = new_digit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void handle_uint16(KeypadKey key, uint16_t& val) {
|
||||||
|
char key_c = char_of_keypad_key(key);
|
||||||
|
bool is_digit = std::isdigit(static_cast<unsigned char>(key_c));
|
||||||
|
uint8_t digit = is_digit ? static_cast<uint8_t>(key_c - '0') : 0;
|
||||||
|
|
||||||
|
if (key == KeypadKey::star) {
|
||||||
|
val = 0;
|
||||||
|
} else if (is_digit) {
|
||||||
|
uint32_t new_digit = ((uint32_t) val) * 10 + (uint32_t) digit;
|
||||||
|
if (new_digit < 65535) val = new_digit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_enum(ButtonKey key, uint8_t& val, uint8_t n_items) {
|
||||||
|
if (key == ButtonKey::b1) {
|
||||||
|
// dec
|
||||||
|
val = (val + n_items - 1) % n_items;
|
||||||
|
} else if (key == ButtonKey::b2) {
|
||||||
|
// inc
|
||||||
|
val = (val + 1) % n_items;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void hardware_config() {
|
||||||
|
clean_bomb();
|
||||||
|
uint8_t current_item = 0;
|
||||||
|
const uint8_t n_items = 28;
|
||||||
|
|
||||||
|
HWData1& hwdata = get_hw_data().inner;
|
||||||
|
|
||||||
|
ButtonKey btn;
|
||||||
|
KeypadKey key;
|
||||||
|
bool dirty = true;
|
||||||
|
while (true) {
|
||||||
|
if (dirty) {
|
||||||
|
// display
|
||||||
|
char name[21];
|
||||||
|
char value[21];
|
||||||
|
|
||||||
|
switch (current_item) {
|
||||||
|
case 0: // serial_num
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "serial_num");
|
||||||
|
snprintf(value, sizeof(value), "%s", hwdata.serial_num.c_str());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1: // rev_ctrl_maj
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "rev_ctrl_maj");
|
||||||
|
snprintf(value, sizeof(value), "%d", hwdata.rev_ctrl_maj);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: // rev_ctrl_min
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "rev_ctrl_min");
|
||||||
|
snprintf(value, sizeof(value), "%d", hwdata.rev_ctrl_min);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3: // rev_exp_maj
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "rev_exp_maj");
|
||||||
|
snprintf(value, sizeof(value), "%d", hwdata.rev_exp_maj);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4: // rev_exp_min
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "rev_exp_min");
|
||||||
|
snprintf(value, sizeof(value), "%d", hwdata.rev_exp_min);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5: // rev_ft_maj
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "rev_ft_maj");
|
||||||
|
snprintf(value, sizeof(value), "%d", hwdata.rev_ft_maj);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6: // rev_ft_min
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "rev_ft_min");
|
||||||
|
snprintf(value, sizeof(value), "%d", hwdata.rev_ft_min);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 7: // rev_fb_maj
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "rev_fb_maj");
|
||||||
|
snprintf(value, sizeof(value), "%d", hwdata.rev_fb_maj);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 8: // rev_fb_min
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "rev_fb_min");
|
||||||
|
snprintf(value, sizeof(value), "%d", hwdata.rev_fb_min);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 9: // sseg_color_t
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "sseg_color_t");
|
||||||
|
snprintf(value, sizeof(value), "%s", SSEG_COLOR_NAMES[static_cast<uint8_t>(hwdata.sseg_color_t)]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 10: // sseg_color_b
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "sseg_color_b");
|
||||||
|
snprintf(value, sizeof(value), "%s", SSEG_COLOR_NAMES[static_cast<uint8_t>(hwdata.sseg_color_b)]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 11: // lcd_color
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "lcd_color");
|
||||||
|
snprintf(value, sizeof(value), "%s", LCD_COLOR_NAMES[static_cast<uint8_t>(hwdata.lcd_color)]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 12: // switch_pos
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "switch_pos");
|
||||||
|
snprintf(value, sizeof(value), "%d", hwdata.switch_pos);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 13: // button_type
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "button_type");
|
||||||
|
snprintf(value, sizeof(value), "%s", BUTTON_TYPE_NAMES[static_cast<uint8_t>(hwdata.button_type)]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 14: // tft_type
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "tft_type");
|
||||||
|
snprintf(value, sizeof(value), "%s", TFT_TYPE_NAMES[static_cast<uint8_t>(hwdata.tft_type)]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 15: // bat_type
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "bat_type");
|
||||||
|
snprintf(value, sizeof(value), "%s", BAT_TYPE_NAMES[static_cast<uint8_t>(hwdata.bat_type)]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 16: // bat_cap
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "bat_cap");
|
||||||
|
snprintf(value, sizeof(value), "%d", hwdata.bat_cap);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 17: // shape1
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "shape1");
|
||||||
|
snprintf(value, sizeof(value), "%s", SHAPE_TYPE_NAMES[static_cast<uint8_t>(hwdata.shape1)]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 18: // shape2
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "shape2");
|
||||||
|
snprintf(value, sizeof(value), "%s", SHAPE_TYPE_NAMES[static_cast<uint8_t>(hwdata.shape2)]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 19: // shape3
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "shape3");
|
||||||
|
snprintf(value, sizeof(value), "%s", SHAPE_TYPE_NAMES[static_cast<uint8_t>(hwdata.shape3)]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 20: // shape4
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "shape4");
|
||||||
|
snprintf(value, sizeof(value), "%s", SHAPE_TYPE_NAMES[static_cast<uint8_t>(hwdata.shape4)]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 21: // has_speaker
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "has_speaker");
|
||||||
|
snprintf(value, sizeof(value), "%s", hwdata.has_speaker ? "true" : "false");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 22: // has_mic
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "has_mic");
|
||||||
|
snprintf(value, sizeof(value), "%s", hwdata.has_mic ? "true" : "false");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 23: // has_ir
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "has_ir");
|
||||||
|
snprintf(value, sizeof(value), "%s", hwdata.has_ir ? "true" : "false");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 24: // has_rfid
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "has_rfid");
|
||||||
|
snprintf(value, sizeof(value), "%s", hwdata.has_rfid ? "true" : "false");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 25: // has_fp
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "has_fp");
|
||||||
|
snprintf(value, sizeof(value), "%s", hwdata.has_fp ? "true" : "false");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 26: // has_fp_hall
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "has_fp_hall");
|
||||||
|
snprintf(value, sizeof(value), "%s", hwdata.has_fp_hall ? "true" : "false");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 27: // has_close_hall
|
||||||
|
snprintf(name, sizeof(name), "%-20s", "has_close_hall");
|
||||||
|
snprintf(value, sizeof(value), "%s", hwdata.has_close_hall ? "true" : "false");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
lcd_print(1, 0, name);
|
||||||
|
lcd_print(2, 0, value);
|
||||||
|
|
||||||
|
dirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get_button_pressed(&btn)) {
|
||||||
|
dirty = true;
|
||||||
|
switch (btn) {
|
||||||
|
case ButtonKey::b3: // dec
|
||||||
|
current_item = (current_item + n_items - 1) % n_items;
|
||||||
|
break;
|
||||||
|
case ButtonKey::b4: // inc
|
||||||
|
current_item = (current_item + 1) % n_items;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
switch (current_item) {
|
||||||
|
case 9: // sseg_color_t
|
||||||
|
handle_enum(btn, reinterpret_cast<uint8_t&>(hwdata.sseg_color_t), SSEG_COLOR_COUNT);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 10: // sseg_color_b
|
||||||
|
handle_enum(btn, reinterpret_cast<uint8_t&>(hwdata.sseg_color_b), SSEG_COLOR_COUNT);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 11: // lcd_color
|
||||||
|
handle_enum(btn, reinterpret_cast<uint8_t&>(hwdata.lcd_color), LCD_COLOR_COUNT);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 13: // button_type
|
||||||
|
handle_enum(btn, reinterpret_cast<uint8_t&>(hwdata.button_type), BUTTON_TYPE_COUNT);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 14: // tft_type
|
||||||
|
handle_enum(btn, reinterpret_cast<uint8_t&>(hwdata.tft_type), TFT_TYPE_COUNT);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 15: // bat_type
|
||||||
|
handle_enum(btn, reinterpret_cast<uint8_t&>(hwdata.bat_type), BAT_TYPE_COUNT);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 17: // shape1
|
||||||
|
handle_enum(btn, reinterpret_cast<uint8_t&>(hwdata.shape1), SHAPE_TYPE_COUNT);
|
||||||
|
break;
|
||||||
|
case 18: // shape2
|
||||||
|
handle_enum(btn, reinterpret_cast<uint8_t&>(hwdata.shape2), SHAPE_TYPE_COUNT);
|
||||||
|
break;
|
||||||
|
case 19: // shape3
|
||||||
|
handle_enum(btn, reinterpret_cast<uint8_t&>(hwdata.shape3), SHAPE_TYPE_COUNT);
|
||||||
|
break;
|
||||||
|
case 20: // shape4
|
||||||
|
handle_enum(btn, reinterpret_cast<uint8_t&>(hwdata.shape4), SHAPE_TYPE_COUNT);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 21: // has_speaker
|
||||||
|
hwdata.has_speaker = btn == ButtonKey::button_green;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 22: // has_mic
|
||||||
|
hwdata.has_mic = btn == ButtonKey::button_green;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 23: // has_ir
|
||||||
|
hwdata.has_ir = btn == ButtonKey::button_green;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 24: // has_rfid
|
||||||
|
hwdata.has_rfid = btn == ButtonKey::button_green;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 25: // has_fp
|
||||||
|
hwdata.has_fp = btn == ButtonKey::button_green;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 26: // has_fp_hall
|
||||||
|
hwdata.has_fp_hall = btn == ButtonKey::button_green;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 27: // has_close_hall
|
||||||
|
hwdata.has_close_hall = btn == ButtonKey::button_green;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (get_keypad_pressed(&key)) {
|
||||||
|
dirty = true;
|
||||||
|
if (key == KeypadKey::pound) {
|
||||||
|
// TODO: ask the user to save
|
||||||
|
return; // done
|
||||||
|
}
|
||||||
|
|
||||||
|
char key_c = char_of_keypad_key(key);
|
||||||
|
bool is_digit = std::isdigit(static_cast<unsigned char>(key_c));
|
||||||
|
uint8_t digit = is_digit ? static_cast<uint8_t>(key_c - '0') : 0;
|
||||||
|
|
||||||
|
// update the current value
|
||||||
|
switch (current_item) {
|
||||||
|
case 0: // serial_num
|
||||||
|
if (key == KeypadKey::star) {
|
||||||
|
hwdata.serial_num.clear();
|
||||||
|
} else {
|
||||||
|
hwdata.serial_num.push_back(char_of_keypad_key(key));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1: // rev_ctrl_maj
|
||||||
|
handle_uint8(key, hwdata.rev_ctrl_maj);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: // rev_ctrl_min
|
||||||
|
handle_uint8(key, hwdata.rev_ctrl_min);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3: // rev_exp_maj
|
||||||
|
handle_uint8(key, hwdata.rev_exp_maj);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4: // rev_exp_min
|
||||||
|
handle_uint8(key, hwdata.rev_exp_min);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5: // rev_ft_maj
|
||||||
|
handle_uint8(key, hwdata.rev_ft_maj);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6: // rev_ft_min
|
||||||
|
handle_uint8(key, hwdata.rev_ft_min);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 7: // rev_fb_maj
|
||||||
|
handle_uint8(key, hwdata.rev_fb_maj);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 8: // rev_fb_min
|
||||||
|
handle_uint8(key, hwdata.rev_fb_min);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 12: // switch_pos
|
||||||
|
if (digit == 2 || digit == 3) hwdata.switch_pos = digit;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 16: // bat_cap
|
||||||
|
handle_uint16(key, hwdata.bat_cap);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
#ifndef HWDATA_H
|
||||||
|
#define HWDATA_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
|
||||||
|
#define CURRENT_HWDATA_VERSION 1
|
||||||
|
#define CURRENT_HWDATA_STRUCT HWData1
|
||||||
|
|
||||||
|
#define SSEG_COLOR_COUNT 10
|
||||||
|
static constexpr const char* SSEG_COLOR_NAMES[SSEG_COLOR_COUNT] = {
|
||||||
|
"UNKNOWN",
|
||||||
|
"NONE",
|
||||||
|
"OTHER",
|
||||||
|
"RED",
|
||||||
|
"ORANGE",
|
||||||
|
"YELLOW",
|
||||||
|
"GREEN",
|
||||||
|
"BLUE",
|
||||||
|
"PURPLE",
|
||||||
|
"WHITE"
|
||||||
|
};
|
||||||
|
enum class SSegColor : uint8_t {
|
||||||
|
UNKNOWN = 0,
|
||||||
|
NONE = 1,
|
||||||
|
OTHER = 2,
|
||||||
|
RED = 3,
|
||||||
|
ORANGE = 4,
|
||||||
|
YELLOW = 5,
|
||||||
|
GREEN = 6,
|
||||||
|
BLUE = 7,
|
||||||
|
PURPLE = 8,
|
||||||
|
WHITE = 9,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define LCD_COLOR_COUNT 8
|
||||||
|
static constexpr const char* LCD_COLOR_NAMES[LCD_COLOR_COUNT] = {
|
||||||
|
"UNKNOWN",
|
||||||
|
"NONE",
|
||||||
|
"OTHER",
|
||||||
|
"BLACK_GREEN",
|
||||||
|
"WHITE_BLUE",
|
||||||
|
"BLACK_SKY",
|
||||||
|
"BLACK_WHITE",
|
||||||
|
"WHITE_BLACK"
|
||||||
|
};
|
||||||
|
enum class LCDColor : uint8_t {
|
||||||
|
UNKNOWN = 0,
|
||||||
|
NONE = 1,
|
||||||
|
OTHER = 2,
|
||||||
|
BLACK_GREEN = 3,
|
||||||
|
WHITE_BLUE = 4,
|
||||||
|
BLACK_SKY = 5,
|
||||||
|
BLACK_WHITE = 6,
|
||||||
|
WHITE_BLACK = 7,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define BUTTON_TYPE_COUNT 6
|
||||||
|
static constexpr const char* BUTTON_TYPE_NAMES[BUTTON_TYPE_COUNT] = {
|
||||||
|
"UNKNOWN",
|
||||||
|
"NONE",
|
||||||
|
"OTHER",
|
||||||
|
"WHITE",
|
||||||
|
"BROWN",
|
||||||
|
"RED"
|
||||||
|
};
|
||||||
|
enum class ButtonType : uint8_t {
|
||||||
|
UNKNOWN = 0,
|
||||||
|
NONE = 1,
|
||||||
|
OTHER = 2,
|
||||||
|
WHITE = 3,
|
||||||
|
BROWN = 4,
|
||||||
|
RED = 5,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define TFT_TYPE_COUNT 5
|
||||||
|
static constexpr const char* TFT_TYPE_NAMES[TFT_TYPE_COUNT] = {
|
||||||
|
"UNKNOWN",
|
||||||
|
"NONE",
|
||||||
|
"OTHER",
|
||||||
|
"EAST_RISING",
|
||||||
|
"SHENZHEN"
|
||||||
|
};
|
||||||
|
enum class TFTType : uint8_t {
|
||||||
|
UNKNOWN = 0,
|
||||||
|
NONE = 1,
|
||||||
|
OTHER = 2,
|
||||||
|
EAST_RISING = 3,
|
||||||
|
SHENZHEN = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define BAT_TYPE_COUNT 5
|
||||||
|
static constexpr const char* BAT_TYPE_NAMES[BAT_TYPE_COUNT] = {
|
||||||
|
"UNKNOWN",
|
||||||
|
"NONE",
|
||||||
|
"OTHER",
|
||||||
|
"BAT_18650",
|
||||||
|
"LIPO"
|
||||||
|
};
|
||||||
|
enum class BatType : uint8_t {
|
||||||
|
UNKNOWN = 0,
|
||||||
|
NONE = 1,
|
||||||
|
OTHER = 2,
|
||||||
|
BAT_18650 = 3,
|
||||||
|
LIPO = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SHAPE_TYPE_COUNT 11
|
||||||
|
static constexpr const char* SHAPE_TYPE_NAMES[SHAPE_TYPE_COUNT] = {
|
||||||
|
"UNKNOWN",
|
||||||
|
"OTHER",
|
||||||
|
"CIRCLE",
|
||||||
|
"SQUARE",
|
||||||
|
"TRIANGLE",
|
||||||
|
"X",
|
||||||
|
"STAR",
|
||||||
|
"SPADE",
|
||||||
|
"DIAMOND",
|
||||||
|
"CLUB",
|
||||||
|
"HEART"
|
||||||
|
};
|
||||||
|
enum class ShapeType : uint8_t {
|
||||||
|
UNKNOWN = 0,
|
||||||
|
OTHER = 1,
|
||||||
|
CIRCLE = 2,
|
||||||
|
SQUARE = 3,
|
||||||
|
TRIANGLE = 4,
|
||||||
|
X = 5,
|
||||||
|
STAR = 6,
|
||||||
|
SPADE = 7,
|
||||||
|
DIAMOND = 8,
|
||||||
|
CLUB = 9,
|
||||||
|
HEART = 10,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// @brief Version 1 of HWData, kept constant for migrations
|
||||||
|
struct HWData1 {
|
||||||
|
std::string serial_num;
|
||||||
|
uint8_t rev_ctrl_maj;
|
||||||
|
uint8_t rev_ctrl_min;
|
||||||
|
uint8_t rev_exp_maj;
|
||||||
|
uint8_t rev_exp_min;
|
||||||
|
uint8_t rev_ft_maj;
|
||||||
|
uint8_t rev_ft_min;
|
||||||
|
uint8_t rev_fb_maj;
|
||||||
|
uint8_t rev_fb_min;
|
||||||
|
|
||||||
|
SSegColor sseg_color_t;
|
||||||
|
SSegColor sseg_color_b;
|
||||||
|
LCDColor lcd_color;
|
||||||
|
uint8_t switch_pos;
|
||||||
|
ButtonType button_type;
|
||||||
|
TFTType tft_type;
|
||||||
|
BatType bat_type;
|
||||||
|
uint16_t bat_cap;
|
||||||
|
|
||||||
|
ShapeType shape1;
|
||||||
|
ShapeType shape2;
|
||||||
|
ShapeType shape3;
|
||||||
|
ShapeType shape4;
|
||||||
|
|
||||||
|
bool has_speaker;
|
||||||
|
bool has_mic;
|
||||||
|
bool has_ir;
|
||||||
|
bool has_rfid;
|
||||||
|
bool has_fp;
|
||||||
|
bool has_fp_hall;
|
||||||
|
bool has_close_hall;
|
||||||
|
|
||||||
|
HWData1();
|
||||||
|
|
||||||
|
esp_err_t save(nvs_handle_t handle) const;
|
||||||
|
void load(nvs_handle_t handle);
|
||||||
|
|
||||||
|
// Add migration method as necessary
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief The current version of HWData, to be stored
|
||||||
|
struct HWData {
|
||||||
|
/// @brief `true` if there is some issue in loading, and we are doing a "best effort" to be compatible
|
||||||
|
/// We should make no writes to NVS if this is `true`.
|
||||||
|
volatile bool compat_mode;
|
||||||
|
HWData1 inner;
|
||||||
|
|
||||||
|
HWData();
|
||||||
|
HWData(HWData1 data, bool compat_mode);
|
||||||
|
|
||||||
|
esp_err_t save(nvs_handle_t handle, bool force = false);
|
||||||
|
static HWData load(nvs_handle_t handle);
|
||||||
|
};
|
||||||
|
|
||||||
|
void hardware_config();
|
||||||
|
|
||||||
|
#endif /* HWDATA_H */
|
||||||
@@ -5,30 +5,31 @@
|
|||||||
|
|
||||||
static const char *TAG = "i2c";
|
static const char *TAG = "i2c";
|
||||||
|
|
||||||
SemaphoreHandle_t i2c0_mutex;
|
SemaphoreHandle_t main_i2c_mutex;
|
||||||
|
|
||||||
void init_i2c() {
|
void init_i2c() {
|
||||||
ESP_LOGI(TAG, "Initializing i2c...");
|
ESP_LOGI(TAG, "Initializing i2c...");
|
||||||
|
|
||||||
i2c_config_t conf = {
|
i2c_config_t conf = {
|
||||||
.mode = I2C_MODE_MASTER,
|
.mode = I2C_MODE_MASTER,
|
||||||
.sda_io_num = GPIO_NUM_5,
|
.sda_io_num = PIN_I2C_SDA,
|
||||||
.scl_io_num = GPIO_NUM_6,
|
.scl_io_num = PIN_I2C_SCL,
|
||||||
.sda_pullup_en = GPIO_PULLUP_DISABLE,
|
.sda_pullup_en = GPIO_PULLUP_DISABLE,
|
||||||
.scl_pullup_en = GPIO_PULLUP_DISABLE,
|
.scl_pullup_en = GPIO_PULLUP_DISABLE,
|
||||||
// .sda_pullup_en = GPIO_PULLUP_ENABLE,
|
// .sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
// .scl_pullup_en = GPIO_PULLUP_ENABLE,
|
// .scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
.master = {
|
.master = {
|
||||||
|
// TODO: 400k?
|
||||||
.clk_speed = 100*1000,
|
.clk_speed = 100*1000,
|
||||||
},
|
},
|
||||||
.clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL
|
.clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL
|
||||||
};
|
};
|
||||||
|
|
||||||
ESP_ERROR_CHECK(i2c_param_config(I2C_NUM_0, &conf));
|
ESP_ERROR_CHECK(i2c_param_config(MAIN_I2C_BUS_NUM, &conf));
|
||||||
ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM_0, conf.mode, 0, 0, 0));
|
ESP_ERROR_CHECK(i2c_driver_install(MAIN_I2C_BUS_NUM, conf.mode, 0, 0, 0));
|
||||||
|
|
||||||
i2c0_mutex = xSemaphoreCreateMutex();
|
main_i2c_mutex = xSemaphoreCreateMutex();
|
||||||
assert(i2c0_mutex != NULL);
|
assert(main_i2c_mutex != NULL);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "i2c initialized!");
|
ESP_LOGI(TAG, "i2c initialized!");
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -4,8 +4,13 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/semphr.h"
|
#include "freertos/semphr.h"
|
||||||
|
|
||||||
|
#define MAIN_I2C_BUS_NUM I2C_NUM_0
|
||||||
|
|
||||||
|
#define PIN_I2C_SDA GPIO_NUM_7
|
||||||
|
#define PIN_I2C_SCL GPIO_NUM_15
|
||||||
|
|
||||||
/// The mutex for accessing `I2C_NUM_0`.
|
/// The mutex for accessing `I2C_NUM_0`.
|
||||||
extern SemaphoreHandle_t i2c0_mutex;
|
extern SemaphoreHandle_t main_i2c_mutex;
|
||||||
|
|
||||||
/// @brief Initializes `I2C_NUM_0`.
|
/// @brief Initializes `I2C_NUM_0`.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ void lcd_begin(i2c_lcd_pcf8574_handle_t* lcd, uint8_t cols, uint8_t rows) {
|
|||||||
lcd->entrymode = 0x02;
|
lcd->entrymode = 0x02;
|
||||||
|
|
||||||
// The following are the reset sequence: Please see "Initialization instruction in the PCF8574 datasheet."
|
// The following are the reset sequence: Please see "Initialization instruction in the PCF8574 datasheet."
|
||||||
xSemaphoreTake(i2c0_mutex, portMAX_DELAY);
|
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
||||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
i2c_master_start(cmd);
|
i2c_master_start(cmd);
|
||||||
// We left-shift the device addres and add the read/write command
|
// We left-shift the device addres and add the read/write command
|
||||||
@@ -97,7 +97,7 @@ void lcd_begin(i2c_lcd_pcf8574_handle_t* lcd, uint8_t cols, uint8_t rows) {
|
|||||||
i2c_master_stop(cmd);
|
i2c_master_stop(cmd);
|
||||||
i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
|
i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
|
||||||
i2c_cmd_link_delete(cmd);
|
i2c_cmd_link_delete(cmd);
|
||||||
xSemaphoreGive(i2c0_mutex);
|
xSemaphoreGive(main_i2c_mutex);
|
||||||
|
|
||||||
// Instruction: function set = 0x20
|
// Instruction: function set = 0x20
|
||||||
lcd_send(lcd, 0x20 | (rows > 1 ? 0x08 : 0x00), false);
|
lcd_send(lcd, 0x20 | (rows > 1 ? 0x08 : 0x00), false);
|
||||||
@@ -233,7 +233,7 @@ void lcd_no_autoscroll(i2c_lcd_pcf8574_handle_t* lcd) {
|
|||||||
|
|
||||||
// Setting the backlight: It can only be turn on or off.
|
// Setting the backlight: It can only be turn on or off.
|
||||||
// Current backlight value is saved in the i2c_lcd_pcf8574_handle_t struct for further data transfers
|
// Current backlight value is saved in the i2c_lcd_pcf8574_handle_t struct for further data transfers
|
||||||
void lcd_set_backlight(i2c_lcd_pcf8574_handle_t* lcd, uint8_t brightness) {
|
void lcd_set_backlight_to(i2c_lcd_pcf8574_handle_t* lcd, uint8_t brightness) {
|
||||||
// Place the backlight value in the lcd struct
|
// Place the backlight value in the lcd struct
|
||||||
lcd->backlight = brightness;
|
lcd->backlight = brightness;
|
||||||
// Send no data
|
// Send no data
|
||||||
@@ -258,8 +258,13 @@ void lcd_write(i2c_lcd_pcf8574_handle_t* lcd, uint8_t value) {
|
|||||||
// Print characters to the LCD: cursor set or clear instruction must preceded this instruction, or it will write on the current text.
|
// Print characters to the LCD: cursor set or clear instruction must preceded this instruction, or it will write on the current text.
|
||||||
void lcd_print(i2c_lcd_pcf8574_handle_t* lcd, const char* str) {
|
void lcd_print(i2c_lcd_pcf8574_handle_t* lcd, const char* str) {
|
||||||
while (*str) {
|
while (*str) {
|
||||||
|
if (*str == '\x08') {
|
||||||
|
lcd_write(lcd, '\x00');
|
||||||
|
str++;
|
||||||
|
} else {
|
||||||
lcd_write(lcd, *str++);
|
lcd_write(lcd, *str++);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} // lcd_print()
|
} // lcd_print()
|
||||||
|
|
||||||
// Additional function to print numbers as formatted string
|
// Additional function to print numbers as formatted string
|
||||||
@@ -296,18 +301,17 @@ void lcd_print_number(i2c_lcd_pcf8574_handle_t* lcd, uint8_t col, uint8_t row, u
|
|||||||
|
|
||||||
// Private functions: derived from the esp32 i2c_master driver
|
// Private functions: derived from the esp32 i2c_master driver
|
||||||
|
|
||||||
|
|
||||||
static void lcd_send(i2c_lcd_pcf8574_handle_t* lcd, uint8_t value, bool is_data) {
|
static void lcd_send(i2c_lcd_pcf8574_handle_t* lcd, uint8_t value, bool is_data) {
|
||||||
xSemaphoreTake(i2c0_mutex, portMAX_DELAY);
|
|
||||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
i2c_master_start(cmd);
|
i2c_master_start(cmd);
|
||||||
i2c_master_write_byte(cmd, (lcd->i2c_addr << 1) | I2C_MASTER_WRITE, true);
|
i2c_master_write_byte(cmd, (lcd->i2c_addr << 1) | I2C_MASTER_WRITE, true);
|
||||||
|
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
||||||
lcd_write_nibble(lcd, (value >> 4 & 0x0F), is_data, cmd);
|
lcd_write_nibble(lcd, (value >> 4 & 0x0F), is_data, cmd);
|
||||||
lcd_write_nibble(lcd, (value & 0x0F), is_data, cmd);
|
lcd_write_nibble(lcd, (value & 0x0F), is_data, cmd);
|
||||||
i2c_master_stop(cmd);
|
i2c_master_stop(cmd);
|
||||||
esp_err_t ret = i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
|
esp_err_t ret = i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
|
||||||
|
xSemaphoreGive(main_i2c_mutex);
|
||||||
i2c_cmd_link_delete(cmd);
|
i2c_cmd_link_delete(cmd);
|
||||||
xSemaphoreGive(i2c0_mutex);
|
|
||||||
|
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send data to LCD: %s", esp_err_to_name(ret));
|
ESP_LOGE(TAG, "Failed to send data to LCD: %s", esp_err_to_name(ret));
|
||||||
@@ -346,15 +350,15 @@ static void lcd_write_i2c(i2c_lcd_pcf8574_handle_t* lcd, uint8_t data, bool is_d
|
|||||||
data |= lcd->backlight_mask;
|
data |= lcd->backlight_mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
xSemaphoreTake(i2c0_mutex, portMAX_DELAY);
|
|
||||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
i2c_master_start(cmd);
|
i2c_master_start(cmd);
|
||||||
i2c_master_write_byte(cmd, (lcd->i2c_addr << 1) | I2C_MASTER_WRITE, true);
|
i2c_master_write_byte(cmd, (lcd->i2c_addr << 1) | I2C_MASTER_WRITE, true);
|
||||||
i2c_master_write_byte(cmd, data, true);
|
i2c_master_write_byte(cmd, data, true);
|
||||||
i2c_master_stop(cmd);
|
i2c_master_stop(cmd);
|
||||||
|
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
|
||||||
esp_err_t ret = i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
|
esp_err_t ret = i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
|
||||||
|
xSemaphoreGive(main_i2c_mutex);
|
||||||
i2c_cmd_link_delete(cmd);
|
i2c_cmd_link_delete(cmd);
|
||||||
xSemaphoreGive(i2c0_mutex);
|
|
||||||
|
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to write to LCD: %s", esp_err_to_name(ret));
|
ESP_LOGE(TAG, "Failed to write to LCD: %s", esp_err_to_name(ret));
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ void lcd_autoscroll(i2c_lcd_pcf8574_handle_t* lcd);
|
|||||||
void lcd_no_autoscroll(i2c_lcd_pcf8574_handle_t* lcd);
|
void lcd_no_autoscroll(i2c_lcd_pcf8574_handle_t* lcd);
|
||||||
|
|
||||||
// Set backlight brightness
|
// Set backlight brightness
|
||||||
void lcd_set_backlight(i2c_lcd_pcf8574_handle_t* lcd, uint8_t brightness);
|
void lcd_set_backlight_to(i2c_lcd_pcf8574_handle_t* lcd, uint8_t brightness);
|
||||||
|
|
||||||
// Create a custom character
|
// Create a custom character
|
||||||
void lcd_create_char(i2c_lcd_pcf8574_handle_t* lcd, uint8_t location, const uint8_t charmap[]);
|
void lcd_create_char(i2c_lcd_pcf8574_handle_t* lcd, uint8_t location, const uint8_t charmap[]);
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define LED_COUNT 21
|
#define LED_COUNT 21
|
||||||
#define NEOPIXEL_PIN GPIO_NUM_7
|
#define NEOPIXEL_PIN GPIO_NUM_0
|
||||||
// 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
|
// 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
|
||||||
#define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000)
|
#define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
#include "nvs.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "bottom_half.h"
|
||||||
|
#include "char_lcd.h"
|
||||||
|
|
||||||
|
static const char* TAG = "nvs";
|
||||||
|
|
||||||
|
static const char* HWDATA_NAMESPACE = "hwdata";
|
||||||
|
static HWData hw_data;
|
||||||
|
|
||||||
|
bool init_nvs() {
|
||||||
|
ESP_LOGI(TAG, "Initializing NVS...");
|
||||||
|
esp_err_t ret = nvs_flash_init();
|
||||||
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
|
// NVS partition was truncated, erase and retry
|
||||||
|
ESP_LOGE(TAG, "Failed to init nvs flash: %s.", esp_err_to_name(ret));
|
||||||
|
lcd_print(1, 0, "NVS: ");
|
||||||
|
lcd_print(1, 4, esp_err_to_name(ret));
|
||||||
|
lcd_print(2, 0, "Press Yellow to skip");
|
||||||
|
lcd_print(3, 0, "Press Red to erase");
|
||||||
|
|
||||||
|
ButtonKey button;
|
||||||
|
while (!( get_button_pressed(&button) && (button == ButtonKey::button_red || button == ButtonKey::button_yellow) )) vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
|
||||||
|
lcd_clear();
|
||||||
|
|
||||||
|
if (button == ButtonKey::button_yellow) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (button == ButtonKey::button_red) {
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
|
ret = nvs_flash_init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(ret);
|
||||||
|
|
||||||
|
nvs_handle_t hw_handle;
|
||||||
|
ret = nvs_open(HWDATA_NAMESPACE, NVS_READONLY, &hw_handle);
|
||||||
|
if (ret == ESP_ERR_NVS_NOT_FOUND) {
|
||||||
|
ESP_LOGW(TAG, "Partition \"%s\" has not been initialized. Loading defaults.", HWDATA_NAMESPACE);
|
||||||
|
hw_data = HWData();
|
||||||
|
} else {
|
||||||
|
ESP_ERROR_CHECK(ret);
|
||||||
|
hw_data = HWData::load(hw_handle);
|
||||||
|
nvs_close(hw_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "NVS initialized!");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
HWData& get_hw_data() {
|
||||||
|
return hw_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void save_hw_data(bool force) {
|
||||||
|
nvs_handle_t hw_handle;
|
||||||
|
ESP_ERROR_CHECK(nvs_open(HWDATA_NAMESPACE, NVS_READWRITE, &hw_handle));
|
||||||
|
hw_data.save(hw_handle);
|
||||||
|
nvs_close(hw_handle);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef NVS_H
|
||||||
|
#define NVS_H
|
||||||
|
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
#include "hwdata.h"
|
||||||
|
|
||||||
|
/// @brief Initializes the NVS.
|
||||||
|
bool init_nvs();
|
||||||
|
|
||||||
|
/// Gets the HWData stored in NVS.
|
||||||
|
HWData& get_hw_data();
|
||||||
|
|
||||||
|
#endif /* NVS_H */
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#include "perh.h"
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef PERH_H
|
||||||
|
#define PERH_H
|
||||||
|
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
|
||||||
|
#define PIN_PERH0 GPIO_NUM_6
|
||||||
|
#define PIN_PERH1 GPIO_NUM_5
|
||||||
|
#define PIN_PERH2 GPIO_NUM_4
|
||||||
|
#define PIN_PERH3 GPIO_NUM_2
|
||||||
|
#define PIN_PERH4 GPIO_NUM_1
|
||||||
|
|
||||||
|
#endif /* PERH_H */
|
||||||
+39
-12
@@ -1,5 +1,6 @@
|
|||||||
#include "power.h"
|
#include "power.h"
|
||||||
#include "char_lcd.h"
|
#include "char_lcd.h"
|
||||||
|
#include "starcode.h"
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
|
||||||
static const char* TAG = "power";
|
static const char* TAG = "power";
|
||||||
@@ -11,9 +12,9 @@ void bat_monitor_task(void* arg) {
|
|||||||
sprintf(str_buf, "%d.%03dV", voltage / 1000, voltage % 1000);
|
sprintf(str_buf, "%d.%03dV", voltage / 1000, voltage % 1000);
|
||||||
|
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
lcd_print(1, 0, str_buf);
|
lcd_print(0, 1, str_buf);
|
||||||
|
|
||||||
int16_t current = lipo.current(current_measure::AVG);
|
int16_t current = lipo.current();
|
||||||
sprintf(str_buf, "%dmA", current);
|
sprintf(str_buf, "%dmA", current);
|
||||||
|
|
||||||
lcd_print(1, 1, str_buf);
|
lcd_print(1, 1, str_buf);
|
||||||
@@ -22,12 +23,12 @@ void bat_monitor_task(void* arg) {
|
|||||||
int16_t total_cap = lipo.capacity(capacity_measure::FULL);
|
int16_t total_cap = lipo.capacity(capacity_measure::FULL);
|
||||||
sprintf(str_buf, "%dmAh", total_cap);
|
sprintf(str_buf, "%dmAh", total_cap);
|
||||||
|
|
||||||
lcd_print(1, 2, str_buf);
|
lcd_print(2, 1, str_buf);
|
||||||
|
|
||||||
int16_t soc = lipo.soc(soc_measure::FILTERED);
|
int16_t soc = lipo.soc(soc_measure::FILTERED);
|
||||||
sprintf(str_buf, "%d%%", soc);
|
sprintf(str_buf, "%d%%", soc);
|
||||||
|
|
||||||
lcd_print(1, 3, str_buf);
|
lcd_print(3, 1, str_buf);
|
||||||
|
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(250));
|
vTaskDelay(pdMS_TO_TICKS(250));
|
||||||
@@ -56,18 +57,44 @@ uint16_t get_bat_voltage() {
|
|||||||
|
|
||||||
void lcd_print_header_bat() {
|
void lcd_print_header_bat() {
|
||||||
if (!lcd_header_enabled()) return;
|
if (!lcd_header_enabled()) return;
|
||||||
|
if (lcd_starcode_displaying_result()) return;
|
||||||
|
|
||||||
uint8_t soc = lipo.soc();
|
uint8_t soc = lipo.soc();
|
||||||
char buf[5];
|
int16_t current = lipo.current();
|
||||||
if (soc < 5) {
|
char buf[6];
|
||||||
sprintf(buf, "LOW ");
|
if (soc < 5 && current <= 0) {
|
||||||
|
snprintf(buf, sizeof(buf), " LOW");
|
||||||
|
} else if (soc == 100) {
|
||||||
|
snprintf(buf, sizeof(buf), " 100");
|
||||||
} else {
|
} else {
|
||||||
snprintf(buf, sizeof(buf), "%3d%%", soc);
|
if (current > 0) {
|
||||||
|
snprintf(buf, sizeof(buf), " %2d+", soc);
|
||||||
|
} else {
|
||||||
|
snprintf(buf, sizeof(buf), " %2d%%", soc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lipo.current() > 0) {
|
lcd_print(0, 16, buf);
|
||||||
buf[3] = '+';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lcd_print(16, 0, buf);
|
// memory version
|
||||||
}
|
// void lcd_print_header_bat() {
|
||||||
|
// if (!lcd_header_enabled()) return;
|
||||||
|
// if (lcd_starcode_displaying_result()) return;
|
||||||
|
|
||||||
|
// // Show memory usage percentage instead of battery percentage
|
||||||
|
// char buf[6];
|
||||||
|
// size_t free_heap = heap_caps_get_free_size(MALLOC_CAP_DEFAULT);
|
||||||
|
// size_t total_heap = heap_caps_get_total_size(MALLOC_CAP_DEFAULT);
|
||||||
|
// uint8_t mem_percent = 0;
|
||||||
|
// if (total_heap > 0) {
|
||||||
|
// mem_percent = (uint8_t)(100 - ((free_heap * 100) / total_heap));
|
||||||
|
// }
|
||||||
|
// if (mem_percent >= 100) {
|
||||||
|
// snprintf(buf, sizeof(buf), " 100");
|
||||||
|
// } else {
|
||||||
|
// snprintf(buf, sizeof(buf), " %2d%%", mem_percent);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// lcd_print(0, 16, buf);
|
||||||
|
// }
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ void init_power_board();
|
|||||||
/// @return battery voltage in mV.
|
/// @return battery voltage in mV.
|
||||||
uint16_t get_bat_voltage();
|
uint16_t get_bat_voltage();
|
||||||
|
|
||||||
/// @brief Prints the battery section of the header to the char_lcd. (row 0, columns 16-19)
|
/// @brief Prints the battery section of the header to the char_lcd. (row 0, columns 17-19)
|
||||||
void lcd_print_header_bat();
|
void lcd_print_header_bat();
|
||||||
|
|
||||||
#endif /* POWER_H */
|
#endif /* POWER_H */
|
||||||
|
|||||||
+4
-4
@@ -51,10 +51,10 @@ bool init_sd() {
|
|||||||
ESP_LOGE(TAG, "Failed to mount sd card: %s.", esp_err_to_name(ret));
|
ESP_LOGE(TAG, "Failed to mount sd card: %s.", esp_err_to_name(ret));
|
||||||
|
|
||||||
lcd_print(0, 0, "SD: ");
|
lcd_print(0, 0, "SD: ");
|
||||||
lcd_print(4, 0, esp_err_to_name(ret));
|
lcd_print(0, 4, esp_err_to_name(ret));
|
||||||
lcd_print(0, 1, "Press Green to retry");
|
lcd_print(1, 0, "Press Green to retry");
|
||||||
lcd_print(0, 2, "Press Yellow to skip");
|
lcd_print(2, 0, "Press Yellow to skip");
|
||||||
lcd_print(0, 3, "Press Red to format");
|
lcd_print(3, 0, "Press Red to format");
|
||||||
|
|
||||||
ButtonKey button;
|
ButtonKey button;
|
||||||
while (!( get_button_pressed(&button) && (button == ButtonKey::button_green || button == ButtonKey::button_red || button == ButtonKey::button_yellow) )) vTaskDelay(pdMS_TO_TICKS(10));
|
while (!( get_button_pressed(&button) && (button == ButtonKey::button_green || button == ButtonKey::button_red || button == ButtonKey::button_yellow) )) vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
|||||||
+6
-6
@@ -12,12 +12,12 @@
|
|||||||
|
|
||||||
extern sdmmc_card_t *card;
|
extern sdmmc_card_t *card;
|
||||||
|
|
||||||
#define SD_PIN_CLK GPIO_NUM_48
|
#define SD_PIN_CLK GPIO_NUM_39
|
||||||
#define SD_PIN_CMD GPIO_NUM_45
|
#define SD_PIN_CMD GPIO_NUM_40
|
||||||
#define SD_PIN_D0 GPIO_NUM_47
|
#define SD_PIN_D0 GPIO_NUM_38
|
||||||
#define SD_PIN_D1 GPIO_NUM_21
|
#define SD_PIN_D1 GPIO_NUM_45
|
||||||
#define SD_PIN_D2 GPIO_NUM_39
|
#define SD_PIN_D2 GPIO_NUM_42
|
||||||
#define SD_PIN_D3 GPIO_NUM_38
|
#define SD_PIN_D3 GPIO_NUM_41
|
||||||
|
|
||||||
/// @brief Initializes the SD card
|
/// @brief Initializes the SD card
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "sd.h"
|
#include "sd.h"
|
||||||
|
|
||||||
#define SPEAKER_PIN_BCLK GPIO_NUM_46
|
#define SPEAKER_PIN_BCLK GPIO_NUM_11
|
||||||
#define SPEAKER_PIN_WS GPIO_NUM_9
|
#define SPEAKER_PIN_WS GPIO_NUM_12
|
||||||
#define SPEAKER_PIN_DOUT GPIO_NUM_3
|
#define SPEAKER_PIN_DOUT GPIO_NUM_3
|
||||||
#define SAMPLE_RATE 44100
|
#define SAMPLE_RATE 44100
|
||||||
// The maximum number of clips that can be queued at one time.
|
// The maximum number of clips that can be queued at one time.
|
||||||
|
|||||||
+2
-2
@@ -4,8 +4,8 @@
|
|||||||
#include "TM1640/TM1640.h"
|
#include "TM1640/TM1640.h"
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
|
||||||
#define SSEG_PIN_DATA GPIO_NUM_10
|
#define SSEG_PIN_DATA GPIO_NUM_46
|
||||||
#define SSEG_PIN_CLK GPIO_NUM_11
|
#define SSEG_PIN_CLK GPIO_NUM_48
|
||||||
|
|
||||||
extern TM1640* sseg;
|
extern TM1640* sseg;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "star_code.h"
|
#include "starcode.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "drivers/bottom_half.h"
|
#include "drivers/bottom_half.h"
|
||||||
#include "char_lcd.h"
|
#include "char_lcd.h"
|
||||||
#include "esp_timer.h"
|
#include "esp_timer.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
|
||||||
static const char* TAG = "star_code";
|
static const char* TAG = "star_code";
|
||||||
|
|
||||||
@@ -14,23 +15,34 @@ volatile bool handling_new_starcodes = false;
|
|||||||
static volatile bool system_initialized = false;
|
static volatile bool system_initialized = false;
|
||||||
|
|
||||||
// TODO: use the semaphore, convert to RWLock?
|
// TODO: use the semaphore, convert to RWLock?
|
||||||
static volatile SemaphoreHandle_t star_codes_sem;
|
static volatile SemaphoreHandle_t star_codes_mutex;
|
||||||
static std::vector<StarCodeEntry> star_codes;
|
static std::vector<StarCodeEntry> star_codes;
|
||||||
|
|
||||||
static const char EMPTY_STAR_CODE_HEADER[] = " ";
|
static const char EMPTY_STAR_CODE_HEADER[] = " ";
|
||||||
|
|
||||||
esp_timer_handle_t starcode_delay_timer;
|
esp_timer_handle_t starcode_delay_timer;
|
||||||
static volatile bool processing_starcode;
|
/// @brief `true` if we are delaying for a starcode
|
||||||
|
static volatile bool delaying_for_starcode;
|
||||||
static volatile StarCodeEntry* current_starcode = nullptr;
|
static volatile StarCodeEntry* current_starcode = nullptr;
|
||||||
|
/// @brief `true` when we are handling user input for a starcode
|
||||||
static volatile bool doing_starcode = false;
|
static volatile bool doing_starcode = false;
|
||||||
static uint16_t starcode_waiting_on_release;
|
static uint16_t starcode_waiting_on_release;
|
||||||
static char current[STARCODE_MAX_LEN + 1];
|
static char current[STARCODE_MAX_LEN + 1];
|
||||||
static size_t current_idx;
|
static size_t current_idx;
|
||||||
|
|
||||||
static void starcode_trigger_cb(void* arg) {
|
// Task handle for the starcode callback task
|
||||||
|
static TaskHandle_t starcode_callback_task_handle = nullptr;
|
||||||
|
|
||||||
|
static void starcode_callback_task(void* arg) {
|
||||||
(void) arg;
|
(void) arg;
|
||||||
|
|
||||||
processing_starcode = false;
|
while (true) {
|
||||||
|
// Wait for notification from starcode_trigger_cb
|
||||||
|
uint32_t notification_value;
|
||||||
|
if (xTaskNotifyWait(0, ULONG_MAX, ¬ification_value, portMAX_DELAY) == pdTRUE) {
|
||||||
|
// Process the starcode callback
|
||||||
|
delaying_for_starcode = false;
|
||||||
|
lcd_print_header();
|
||||||
|
|
||||||
if (current_starcode != nullptr) {
|
if (current_starcode != nullptr) {
|
||||||
if (current_starcode->triggered_sem != nullptr)
|
if (current_starcode->triggered_sem != nullptr)
|
||||||
@@ -40,14 +52,22 @@ static void starcode_trigger_cb(void* arg) {
|
|||||||
|
|
||||||
current_starcode = nullptr;
|
current_starcode = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rename star code everywhere to starcode
|
|
||||||
lcd_print_header_star_code();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void starcode_trigger_cb(void* arg) {
|
||||||
|
(void) arg;
|
||||||
|
|
||||||
|
if (starcode_callback_task_handle != nullptr) {
|
||||||
|
xTaskNotify(starcode_callback_task_handle, 1, eSetBits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: rename star code everywhere to starcode
|
||||||
|
|
||||||
|
|
||||||
void star_code_handle_keypad(uint16_t* just_pressed, uint16_t* just_released) {
|
void star_code_handle_keypad(uint16_t* just_pressed, uint16_t* just_released) {
|
||||||
if ((!processing_starcode) && handling_new_starcodes && (*just_pressed & (1 << KeypadKey::star))) {
|
if ((!delaying_for_starcode) && handling_new_starcodes && (*just_pressed & (1 << KeypadKey::star))) {
|
||||||
current_idx = 0;
|
current_idx = 0;
|
||||||
current[current_idx] = '\0';
|
current[current_idx] = '\0';
|
||||||
doing_starcode = true;
|
doing_starcode = true;
|
||||||
@@ -89,8 +109,9 @@ void star_code_handle_keypad(uint16_t* just_pressed, uint16_t* just_released) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_star_code_system() {
|
void init_star_code_system() {
|
||||||
star_codes_sem = xSemaphoreCreateBinary();
|
star_codes_mutex = xSemaphoreCreateMutex();
|
||||||
xSemaphoreGive(star_codes_sem);
|
|
||||||
|
xTaskCreate(starcode_callback_task, "starcode_cb", 4096, NULL, 3, &starcode_callback_task_handle);
|
||||||
|
|
||||||
const esp_timer_create_args_t timer_args = {
|
const esp_timer_create_args_t timer_args = {
|
||||||
.callback = &starcode_trigger_cb,
|
.callback = &starcode_trigger_cb,
|
||||||
@@ -125,10 +146,13 @@ static bool check_code_match(const char* triggered, const char* expected) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool add_star_code(StarCodeEntry code) {
|
bool add_star_code(StarCodeEntry code) {
|
||||||
|
ESP_LOGI(TAG, "Adding starcode: %s", code.code);
|
||||||
if (code.code == nullptr || strlen(code.code) > STARCODE_MAX_LEN) {
|
if (code.code == nullptr || strlen(code.code) > STARCODE_MAX_LEN) {
|
||||||
|
ESP_LOGW(TAG, "invalid code");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (code.display_text != nullptr && strlen(code.display_text) > STARCODE_MAX_LEN + 1) {
|
if (code.display_text != nullptr && strlen(code.display_text) > STARCODE_DISPLAY_TEXT_MAX_LEN) {
|
||||||
|
ESP_LOGW(TAG, "invalid display_text");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +163,7 @@ bool add_star_code(StarCodeEntry code) {
|
|||||||
|
|
||||||
if (it != star_codes.end()) {
|
if (it != star_codes.end()) {
|
||||||
// existing star code found!
|
// existing star code found!
|
||||||
ESP_LOGW(TAG, "Failed to add star code %s", code.code);
|
ESP_LOGW(TAG, "Duplicate starcode %s", code.code);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +182,8 @@ bool add_star_codes(const StarCodeEntry* codes, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool rm_star_code(const char* code) {
|
bool rm_star_code(const char* code) {
|
||||||
|
ESP_LOGI(TAG, "Removing starcode: %s", code);
|
||||||
|
|
||||||
auto it = std::find_if(star_codes.begin(), star_codes.end(), [&](const StarCodeEntry& star_code) {
|
auto it = std::find_if(star_codes.begin(), star_codes.end(), [&](const StarCodeEntry& star_code) {
|
||||||
return strcmp(code, star_code.code) == 0;
|
return strcmp(code, star_code.code) == 0;
|
||||||
});
|
});
|
||||||
@@ -196,18 +222,12 @@ void clear_star_codes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool trigger_star_code(const char* code) {
|
bool trigger_star_code(const char* code) {
|
||||||
ESP_LOGI(TAG, "Star codes to checK:");
|
|
||||||
for (const auto& entry : star_codes) {
|
|
||||||
ESP_LOGI(TAG, "%s", entry.code);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
auto it = std::find_if(star_codes.begin(), star_codes.end(), [&](const StarCodeEntry& other) {
|
auto it = std::find_if(star_codes.begin(), star_codes.end(), [&](const StarCodeEntry& other) {
|
||||||
return check_code_match(code, other.code);
|
return check_code_match(code, other.code);
|
||||||
});
|
});
|
||||||
|
|
||||||
uint64_t delay_us = 2'000'000;
|
uint64_t delay_us = 2'000'000;
|
||||||
processing_starcode = true;
|
delaying_for_starcode = true;
|
||||||
if (it != star_codes.end()) {
|
if (it != star_codes.end()) {
|
||||||
current_starcode = &*it;
|
current_starcode = &*it;
|
||||||
delay_us = current_starcode->delay_us;
|
delay_us = current_starcode->delay_us;
|
||||||
@@ -231,22 +251,25 @@ void lcd_print_header_star_code() {
|
|||||||
if (!lcd_header_enabled()) return;
|
if (!lcd_header_enabled()) return;
|
||||||
|
|
||||||
// TODO: consider upping the display text size to be able to overwrite the game_state area.
|
// TODO: consider upping the display text size to be able to overwrite the game_state area.
|
||||||
if (processing_starcode) {
|
if (delaying_for_starcode) {
|
||||||
if (current_starcode == nullptr) {
|
if (current_starcode == nullptr) {
|
||||||
lcd_print(0, 0, "Invalid ");
|
lcd_print(0, 0, "Invalid starcode ");
|
||||||
} else if (current_starcode->display_text != nullptr) {
|
} else if (current_starcode->display_text != nullptr) {
|
||||||
char buf[STARCODE_MAX_LEN + 2];
|
char buf[21];
|
||||||
snprintf(buf, sizeof(buf), "%s", current_starcode->display_text);
|
snprintf(buf, sizeof(buf), "%-20s", current_starcode->display_text);
|
||||||
lcd_print(0, 0, buf);
|
lcd_print(0, 0, buf);
|
||||||
} else {
|
} else {
|
||||||
lcd_print(0, 0, EMPTY_STAR_CODE_HEADER);
|
lcd_print(0, 0, EMPTY_STAR_CODE_HEADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (doing_starcode) {
|
} else if (doing_starcode) {
|
||||||
char buf[STARCODE_MAX_LEN + 2];
|
char buf[STARCODE_MAX_LEN + 2];
|
||||||
snprintf(buf, sizeof(buf), "*%-8s", current);
|
snprintf(buf, sizeof(buf), "*%-9s", current);
|
||||||
lcd_print(0, 0, buf);
|
lcd_print(0, 0, buf);
|
||||||
} else {
|
} else {
|
||||||
lcd_print(0, 0, EMPTY_STAR_CODE_HEADER);
|
lcd_print(0, 0, EMPTY_STAR_CODE_HEADER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool lcd_starcode_displaying_result() {
|
||||||
|
return delaying_for_starcode;
|
||||||
|
}
|
||||||
@@ -6,19 +6,20 @@
|
|||||||
#include <freertos/semphr.h>
|
#include <freertos/semphr.h>
|
||||||
|
|
||||||
/// The max length of a starcode (not counting the star)
|
/// The max length of a starcode (not counting the star)
|
||||||
#define STARCODE_MAX_LEN 8
|
#define STARCODE_MAX_LEN 9
|
||||||
|
#define STARCODE_DISPLAY_TEXT_MAX_LEN 20
|
||||||
|
|
||||||
/// @brief A handler for a specific star code
|
/// @brief A handler for a specific star code
|
||||||
struct StarCodeEntry {
|
struct StarCodeEntry {
|
||||||
/// @brief The star code without the star
|
/// @brief The star code without the star
|
||||||
///
|
///
|
||||||
/// This must be <= 8 characters.
|
/// This must be <= 9 characters.
|
||||||
///
|
///
|
||||||
/// You may include a * in the code to match on any character
|
/// You may include a * in the code to match on any character
|
||||||
const char* code;
|
const char* code;
|
||||||
/// @brief The text to display when the star code is entered (or null).
|
/// @brief The text to display when the star code is entered (or null).
|
||||||
///
|
///
|
||||||
/// This must be <= 9 characters.
|
/// This must be <= 20 characters.
|
||||||
const char* display_text;
|
const char* display_text;
|
||||||
/// @brief The number of microseconds to delay when the star code is entered before calling the handler.
|
/// @brief The number of microseconds to delay when the star code is entered before calling the handler.
|
||||||
uint64_t delay_us;
|
uint64_t delay_us;
|
||||||
@@ -77,11 +78,13 @@ bool trigger_star_code(const char* code);
|
|||||||
/// If one is being handled currently, it is canceled.
|
/// If one is being handled currently, it is canceled.
|
||||||
void set_star_code_sys_enabled(bool enable);
|
void set_star_code_sys_enabled(bool enable);
|
||||||
|
|
||||||
/// @brief Gets weather or not the star code system is handling new star codes.
|
/// @return `true` iff the star code system is handling star codes.
|
||||||
/// @return `true` if the star code system is handling star codes.
|
|
||||||
bool star_code_sys_enabled();
|
bool star_code_sys_enabled();
|
||||||
|
|
||||||
/// @brief Prints the star code section of the header to the char_lcd. (row 0, columns 0-9)
|
/// @brief Prints the star code section of the header to the char_lcd. (row 0, columns 0-9)
|
||||||
void lcd_print_header_star_code();
|
void lcd_print_header_star_code();
|
||||||
|
|
||||||
|
/// @return `true` iff the starcode system is using the full header.
|
||||||
|
bool lcd_starcode_displaying_result();
|
||||||
|
|
||||||
#endif /* STAR_CODE_H */
|
#endif /* STAR_CODE_H */
|
||||||
+4
-4
@@ -44,11 +44,11 @@
|
|||||||
#define SPI_MAX_TRANSFER_SIZE 32768
|
#define SPI_MAX_TRANSFER_SIZE 32768
|
||||||
|
|
||||||
#define TFT_PIN_MOSI GPIO_NUM_17
|
#define TFT_PIN_MOSI GPIO_NUM_17
|
||||||
#define TFT_PIN_MISO GPIO_NUM_18
|
#define TFT_PIN_MISO GPIO_NUM_16
|
||||||
#define TFT_PIN_CLK GPIO_NUM_16
|
#define TFT_PIN_CLK GPIO_NUM_18
|
||||||
#define TFT_PIN_CS GPIO_NUM_NC
|
#define TFT_PIN_CS GPIO_NUM_NC
|
||||||
#define TFT_PIN_DC GPIO_NUM_15
|
#define TFT_PIN_DC GPIO_NUM_8
|
||||||
#define TFT_PIN_RESET GPIO_NUM_8
|
#define TFT_PIN_RESET GPIO_NUM_9
|
||||||
|
|
||||||
#define TFT_INVERT_COLOR false
|
#define TFT_INVERT_COLOR false
|
||||||
|
|
||||||
|
|||||||
+22
-5
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
extern uint32_t current_step;
|
extern uint32_t current_step;
|
||||||
|
|
||||||
|
/// The mutex for accessing `I2C_NUM_1` (wires I2C bus).
|
||||||
|
SemaphoreHandle_t wires_i2c_mutex;
|
||||||
|
|
||||||
uint32_t total_strikes;
|
uint32_t total_strikes;
|
||||||
uint32_t step_strikes[N_STEPS] = {0};
|
uint32_t step_strikes[N_STEPS] = {0};
|
||||||
uint32_t step_finish_times[N_STEPS] = {0};
|
uint32_t step_finish_times[N_STEPS] = {0};
|
||||||
@@ -26,8 +29,8 @@ static void receive_button(void);
|
|||||||
void init_wires(void) {
|
void init_wires(void) {
|
||||||
i2c_config_t wires_conf = {
|
i2c_config_t wires_conf = {
|
||||||
.mode = I2C_MODE_MASTER,
|
.mode = I2C_MODE_MASTER,
|
||||||
.sda_io_num = GPIO_NUM_41,
|
.sda_io_num = PIN_WIRES_SDA,
|
||||||
.scl_io_num = GPIO_NUM_42,
|
.scl_io_num = PIN_WIRES_SCL,
|
||||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
.master = {
|
.master = {
|
||||||
@@ -35,12 +38,16 @@ void init_wires(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
gpio_reset_pin(GPIO_NUM_41);
|
gpio_reset_pin(PIN_WIRES_SDA);
|
||||||
gpio_reset_pin(GPIO_NUM_42);
|
gpio_reset_pin(PIN_WIRES_SCL);
|
||||||
|
|
||||||
ESP_ERROR_CHECK(i2c_param_config(WIRES_I2C_NUM, &wires_conf));
|
ESP_ERROR_CHECK(i2c_param_config(WIRES_I2C_NUM, &wires_conf));
|
||||||
ESP_ERROR_CHECK(i2c_driver_install(WIRES_I2C_NUM, wires_conf.mode, 0, 0, 0));
|
ESP_ERROR_CHECK(i2c_driver_install(WIRES_I2C_NUM, wires_conf.mode, 0, 0, 0));
|
||||||
|
|
||||||
|
// Create mutex for wires I2C bus
|
||||||
|
wires_i2c_mutex = xSemaphoreCreateMutex();
|
||||||
|
assert(wires_i2c_mutex != NULL);
|
||||||
|
|
||||||
gpio_config_t int_pin_conf = {};
|
gpio_config_t int_pin_conf = {};
|
||||||
// delta_pin_conf.intr_type = GPIO_INTR_LOW_LEVEL;
|
// delta_pin_conf.intr_type = GPIO_INTR_LOW_LEVEL;
|
||||||
int_pin_conf.mode = GPIO_MODE_INPUT;
|
int_pin_conf.mode = GPIO_MODE_INPUT;
|
||||||
@@ -85,33 +92,41 @@ void clear_wires_pressed_released_cut(void) {
|
|||||||
|
|
||||||
void strike(const char* reason) {
|
void strike(const char* reason) {
|
||||||
ESP_LOGW("strike!", "%s", reason);
|
ESP_LOGW("strike!", "%s", reason);
|
||||||
lcd_print(0, 3, reason);
|
lcd_print(3, 0, reason);
|
||||||
time_penalty(STRIKE_TIME_PENALTY);
|
time_penalty(STRIKE_TIME_PENALTY);
|
||||||
if (current_step > 0 && current_step <= N_STEPS) {
|
if (current_step > 0 && current_step <= N_STEPS) {
|
||||||
total_strikes += 1;
|
total_strikes += 1;
|
||||||
step_strikes[current_step - 1] += 1;
|
step_strikes[current_step - 1] += 1;
|
||||||
}
|
}
|
||||||
uint8_t reg = 6;
|
uint8_t reg = 6;
|
||||||
|
xSemaphoreTake(wires_i2c_mutex, portMAX_DELAY);
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_to_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, (100 / portTICK_PERIOD_MS)));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_to_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, (100 / portTICK_PERIOD_MS)));
|
||||||
|
xSemaphoreGive(wires_i2c_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_leds(uint8_t led_states) {
|
void set_leds(uint8_t led_states) {
|
||||||
buf[0] = 5; // register 5
|
buf[0] = 5; // register 5
|
||||||
buf[1] = led_states;
|
buf[1] = led_states;
|
||||||
|
xSemaphoreTake(wires_i2c_mutex, portMAX_DELAY);
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_to_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, buf, 2, (100 / portTICK_PERIOD_MS)));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_to_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, buf, 2, (100 / portTICK_PERIOD_MS)));
|
||||||
|
xSemaphoreGive(wires_i2c_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t receive_delta(void) {
|
static uint8_t receive_delta(void) {
|
||||||
uint8_t reg = 1;
|
uint8_t reg = 1;
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
|
xSemaphoreTake(wires_i2c_mutex, portMAX_DELAY);
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, buf, 1, (100 / portTICK_PERIOD_MS)));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, buf, 1, (100 / portTICK_PERIOD_MS)));
|
||||||
|
xSemaphoreGive(wires_i2c_mutex);
|
||||||
return buf[0];
|
return buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void receive_wires(void) {
|
static void receive_wires(void) {
|
||||||
uint8_t reg = 2;
|
uint8_t reg = 2;
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
|
xSemaphoreTake(wires_i2c_mutex, portMAX_DELAY);
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, buf, 1, (100 / portTICK_PERIOD_MS)));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, buf, 1, (100 / portTICK_PERIOD_MS)));
|
||||||
|
xSemaphoreGive(wires_i2c_mutex);
|
||||||
uint8_t new_wires = buf[0];
|
uint8_t new_wires = buf[0];
|
||||||
|
|
||||||
uint8_t just_cut = ~new_wires & wires_state;
|
uint8_t just_cut = ~new_wires & wires_state;
|
||||||
@@ -123,7 +138,9 @@ static void receive_wires(void) {
|
|||||||
static void receive_button(void) {
|
static void receive_button(void) {
|
||||||
uint8_t reg = 3;
|
uint8_t reg = 3;
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
|
xSemaphoreTake(wires_i2c_mutex, portMAX_DELAY);
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, buf, 1, (100 / portTICK_PERIOD_MS)));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, buf, 1, (100 / portTICK_PERIOD_MS)));
|
||||||
|
xSemaphoreGive(wires_i2c_mutex);
|
||||||
bool new_button = buf[0] != 0;
|
bool new_button = buf[0] != 0;
|
||||||
|
|
||||||
bool just_pressed = new_button & !button_state;
|
bool just_pressed = new_button & !button_state;
|
||||||
|
|||||||
@@ -5,14 +5,22 @@
|
|||||||
#include <driver/i2c.h>
|
#include <driver/i2c.h>
|
||||||
#include <driver/gpio.h>
|
#include <driver/gpio.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/semphr.h"
|
||||||
#include "drivers/char_lcd.h"
|
#include "drivers/char_lcd.h"
|
||||||
#include "drivers/game_timer.h"
|
#include "drivers/game_timer.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "perh.h"
|
||||||
|
|
||||||
#define WIRES_PIN_DELTA GPIO_NUM_2
|
#define WIRES_PIN_DELTA PIN_PERH3
|
||||||
|
#define PIN_WIRES_SDA PIN_PERH1
|
||||||
|
#define PIN_WIRES_SCL PIN_PERH2
|
||||||
#define WIRES_I2C_NUM I2C_NUM_1
|
#define WIRES_I2C_NUM I2C_NUM_1
|
||||||
#define WIRES_I2C_ADDR 125
|
#define WIRES_I2C_ADDR 125
|
||||||
|
|
||||||
|
/// The mutex for accessing `I2C_NUM_1` (wires I2C bus).
|
||||||
|
extern SemaphoreHandle_t wires_i2c_mutex;
|
||||||
|
|
||||||
#define DELTA_BIT_WIRES 0
|
#define DELTA_BIT_WIRES 0
|
||||||
#define DELTA_BIT_BUTTON 1
|
#define DELTA_BIT_BUTTON 1
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ void print_wires(WireColor* wires, int editing_idx) {
|
|||||||
lcd_print(1, 1, string_buf);
|
lcd_print(1, 1, string_buf);
|
||||||
|
|
||||||
cut_to_string(cut, string_buf);
|
cut_to_string(cut, string_buf);
|
||||||
lcd_print(1, 2, string_buf);
|
lcd_print(2, 1, string_buf);
|
||||||
|
|
||||||
wires_state = get_wires();
|
wires_state = get_wires();
|
||||||
for (int i = 0; i < NUM_WIRES; i++) {
|
for (int i = 0; i < NUM_WIRES; i++) {
|
||||||
@@ -21,9 +21,10 @@ void print_wires(WireColor* wires, int editing_idx) {
|
|||||||
string_buf[i] = '!';
|
string_buf[i] = '!';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lcd_print(1, 3, string_buf);
|
lcd_print(3, 1, string_buf);
|
||||||
|
|
||||||
lcd_set_cursor_pos(editing_idx+1, 1);
|
lcd_set_cursor_vis(true);
|
||||||
|
lcd_set_cursor_resting_position(1, editing_idx+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_wires(void) {
|
void setup_wires(void) {
|
||||||
|
|||||||
+23
-15
@@ -59,15 +59,22 @@ void step0() {
|
|||||||
StarCodeEntry star_codes[] = {
|
StarCodeEntry star_codes[] = {
|
||||||
{
|
{
|
||||||
.code = "9819",
|
.code = "9819",
|
||||||
.display_text = "Defusal Initiated",
|
.display_text = "Diffusal Initiated",
|
||||||
.delay_us = 2'000'000,
|
.delay_us = 2'000'000,
|
||||||
.callback = nullptr,
|
.callback = nullptr,
|
||||||
.triggered_sem = continue_sem,
|
.triggered_sem = continue_sem,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.code = "59862",
|
.code = "59860",
|
||||||
.display_text = "Set Up Wires",
|
.display_text = "Hardware Config",
|
||||||
.delay_us = 10'000'000,
|
.delay_us = 2'000'000,
|
||||||
|
.callback = hardware_config,
|
||||||
|
.triggered_sem = nullptr,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.code = "59861",
|
||||||
|
.display_text = "Setup Wires",
|
||||||
|
.delay_us = 2'000'000,
|
||||||
.callback = setup_wires,
|
.callback = setup_wires,
|
||||||
.triggered_sem = nullptr,
|
.triggered_sem = nullptr,
|
||||||
},
|
},
|
||||||
@@ -80,7 +87,7 @@ void step0() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
.code = "59863",
|
.code = "59863",
|
||||||
.display_text = "Debug Switches",
|
.display_text = "Debug switches",
|
||||||
.delay_us = 2'000'000,
|
.delay_us = 2'000'000,
|
||||||
.callback = debug_switches,
|
.callback = debug_switches,
|
||||||
.triggered_sem = nullptr,
|
.triggered_sem = nullptr,
|
||||||
@@ -192,7 +199,7 @@ void step0() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
.code = "1113",
|
.code = "1113",
|
||||||
.display_text = "replay_last",
|
.display_text = "replay",
|
||||||
.delay_us = 2'000'000,
|
.delay_us = 2'000'000,
|
||||||
.callback = replay_last,
|
.callback = replay_last,
|
||||||
.triggered_sem = continue_sem,
|
.triggered_sem = continue_sem,
|
||||||
@@ -214,7 +221,8 @@ static void _update_display(uint8_t* digits, uint8_t cursor_pos) {
|
|||||||
lcd_print(1, 1, str_buf);
|
lcd_print(1, 1, str_buf);
|
||||||
cursor_pos = MAX(0, MIN(4, cursor_pos));
|
cursor_pos = MAX(0, MIN(4, cursor_pos));
|
||||||
int mapped_cursor_pos = CURSOR_POS_MAP[cursor_pos];
|
int mapped_cursor_pos = CURSOR_POS_MAP[cursor_pos];
|
||||||
lcd_set_cursor_pos(mapped_cursor_pos, 1);
|
|
||||||
|
lcd_set_cursor_resting_position(1, mapped_cursor_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_game_time() {
|
static void set_game_time() {
|
||||||
@@ -335,32 +343,32 @@ static void debug_switches() {
|
|||||||
while (1) {
|
while (1) {
|
||||||
if (get_button_pressed(&button)) {
|
if (get_button_pressed(&button)) {
|
||||||
sprintf(buf, "Button Pressed: %d ", button);
|
sprintf(buf, "Button Pressed: %d ", button);
|
||||||
lcd_print(0, 3, buf);
|
lcd_print(3, 0, buf);
|
||||||
ESP_LOGI(TAG, "%s", buf);
|
ESP_LOGI(TAG, "%s", buf);
|
||||||
}
|
}
|
||||||
if (get_button_released(&button)) {
|
if (get_button_released(&button)) {
|
||||||
sprintf(buf, "Button Released: %d", button);
|
sprintf(buf, "Button Released: %d", button);
|
||||||
lcd_print(0, 3, buf);
|
lcd_print(3, 0, buf);
|
||||||
ESP_LOGI(TAG, "%s", buf);
|
ESP_LOGI(TAG, "%s", buf);
|
||||||
}
|
}
|
||||||
if (get_switch_flipped_down(&switch_)) {
|
if (get_switch_flipped_down(&switch_)) {
|
||||||
sprintf(buf, "Switch Down: %d ", switch_);
|
sprintf(buf, "Switch Down: %d ", switch_);
|
||||||
lcd_print(0, 3, buf);
|
lcd_print(3, 0, buf);
|
||||||
ESP_LOGI(TAG, "%s", buf);
|
ESP_LOGI(TAG, "%s", buf);
|
||||||
}
|
}
|
||||||
if (get_switch_flipped_up(&switch_)) {
|
if (get_switch_flipped_up(&switch_)) {
|
||||||
sprintf(buf, "Switch Up: %d ", switch_);
|
sprintf(buf, "Switch Up: %d ", switch_);
|
||||||
lcd_print(0, 3, buf);
|
lcd_print(3, 0, buf);
|
||||||
ESP_LOGI(TAG, "%s", buf);
|
ESP_LOGI(TAG, "%s", buf);
|
||||||
}
|
}
|
||||||
if (get_switch_touch_pressed(&switch_)) {
|
if (get_switch_touch_pressed(&switch_)) {
|
||||||
sprintf(buf, "Switch Touch: %d ", switch_);
|
sprintf(buf, "Switch Touch: %d ", switch_);
|
||||||
lcd_print(0, 3, buf);
|
lcd_print(3, 0, buf);
|
||||||
ESP_LOGI(TAG, "%s", buf);
|
ESP_LOGI(TAG, "%s", buf);
|
||||||
}
|
}
|
||||||
if (get_switch_touch_released(&switch_)) {
|
if (get_switch_touch_released(&switch_)) {
|
||||||
sprintf(buf, "Switch Un-touch: %d", switch_);
|
sprintf(buf, "Switch Un-touch: %d", switch_);
|
||||||
lcd_print(0, 3, buf);
|
lcd_print(3, 0, buf);
|
||||||
ESP_LOGI(TAG, "%s", buf);
|
ESP_LOGI(TAG, "%s", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,7 +377,7 @@ static void debug_switches() {
|
|||||||
switch_touch_state = new_switch_touch_state;
|
switch_touch_state = new_switch_touch_state;
|
||||||
print_4bin_rev(bin_buf, switch_touch_state);
|
print_4bin_rev(bin_buf, switch_touch_state);
|
||||||
sprintf(buf, "t: %s", bin_buf);
|
sprintf(buf, "t: %s", bin_buf);
|
||||||
lcd_print(1, 0, buf);
|
lcd_print(0, 1, buf);
|
||||||
ESP_LOGI(TAG, "%s", buf);
|
ESP_LOGI(TAG, "%s", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,7 +395,7 @@ static void debug_switches() {
|
|||||||
button_state = new_button_state;
|
button_state = new_button_state;
|
||||||
print_4bin_rev(bin_buf, button_state);
|
print_4bin_rev(bin_buf, button_state);
|
||||||
sprintf(buf, "b: %s", bin_buf);
|
sprintf(buf, "b: %s", bin_buf);
|
||||||
lcd_print(1, 2, buf);
|
lcd_print(2, 1, buf);
|
||||||
ESP_LOGI(TAG, "%s", buf);
|
ESP_LOGI(TAG, "%s", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ static int generate_part(void) {
|
|||||||
static void update_lcd_count(int times) {
|
static void update_lcd_count(int times) {
|
||||||
char buf[16] = {0};
|
char buf[16] = {0};
|
||||||
sprintf(buf, "%d/15", times);
|
sprintf(buf, "%d/15", times);
|
||||||
lcd_print(14, 1, buf);
|
lcd_print(1, 14, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool play_part(uint32_t time) {
|
static bool play_part(uint32_t time) {
|
||||||
|
|||||||
@@ -729,7 +729,7 @@ void step5(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// display expression
|
// display expression
|
||||||
lcd_print(1, 2, display_expression.c_str());
|
lcd_print(2, 1, display_expression.c_str());
|
||||||
|
|
||||||
// set LEDs
|
// set LEDs
|
||||||
const uint32_t COLORS[] = {
|
const uint32_t COLORS[] = {
|
||||||
@@ -790,8 +790,8 @@ void step5(void) {
|
|||||||
|
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
lcd_print(1, 1, "What");
|
lcd_print(1, 1, "What");
|
||||||
lcd_print(1, 2, display_expression.c_str());
|
lcd_print(2, 1, display_expression.c_str());
|
||||||
lcd_print(1, 3, entered_string.c_str());
|
lcd_print(3, 1, entered_string.c_str());
|
||||||
}
|
}
|
||||||
if (get_module_time() <= 0) {
|
if (get_module_time() <= 0) {
|
||||||
strike("Ran out of time!");
|
strike("Ran out of time!");
|
||||||
@@ -849,7 +849,7 @@ void step5(void) {
|
|||||||
|
|
||||||
// ESP_LOGI(TAG, "color string: %s", color_string.c_str());
|
// ESP_LOGI(TAG, "color string: %s", color_string.c_str());
|
||||||
|
|
||||||
lcd_print(1, 2, color_string.c_str());
|
lcd_print(2, 1, color_string.c_str());
|
||||||
|
|
||||||
std::string entered_string;
|
std::string entered_string;
|
||||||
|
|
||||||
@@ -880,8 +880,8 @@ void step5(void) {
|
|||||||
|
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
lcd_print(1, 1, "Plink");
|
lcd_print(1, 1, "Plink");
|
||||||
lcd_print(1, 2, color_string.c_str());
|
lcd_print(2, 1, color_string.c_str());
|
||||||
lcd_print(1, 3, entered_string.c_str());
|
lcd_print(3, 1, entered_string.c_str());
|
||||||
}
|
}
|
||||||
if (get_module_time() <= 0) {
|
if (get_module_time() <= 0) {
|
||||||
strike("Ran out of time!");
|
strike("Ran out of time!");
|
||||||
|
|||||||
@@ -539,7 +539,7 @@ CONFIG_PARTITION_TABLE_MD5=y
|
|||||||
#
|
#
|
||||||
# BLK_BOX Config
|
# BLK_BOX Config
|
||||||
#
|
#
|
||||||
CONFIG_USE_NEW_DISPLAY=y
|
# CONFIG_USE_NEW_DISPLAY is not set
|
||||||
# end of BLK_BOX Config
|
# end of BLK_BOX Config
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -1035,9 +1035,11 @@ CONFIG_SPIRAM=y
|
|||||||
#
|
#
|
||||||
# SPI RAM config
|
# SPI RAM config
|
||||||
#
|
#
|
||||||
# CONFIG_SPIRAM_MODE_QUAD is not set
|
CONFIG_SPIRAM_MODE_QUAD=y
|
||||||
CONFIG_SPIRAM_MODE_OCT=y
|
# CONFIG_SPIRAM_MODE_OCT is not set
|
||||||
CONFIG_SPIRAM_TYPE_AUTO=y
|
CONFIG_SPIRAM_TYPE_AUTO=y
|
||||||
|
# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set
|
||||||
|
# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set
|
||||||
# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set
|
# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set
|
||||||
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
|
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
|
||||||
CONFIG_SPIRAM_CLK_IO=30
|
CONFIG_SPIRAM_CLK_IO=30
|
||||||
@@ -1045,10 +1047,10 @@ CONFIG_SPIRAM_CS_IO=26
|
|||||||
# CONFIG_SPIRAM_XIP_FROM_PSRAM is not set
|
# CONFIG_SPIRAM_XIP_FROM_PSRAM is not set
|
||||||
# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set
|
# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set
|
||||||
# CONFIG_SPIRAM_RODATA is not set
|
# CONFIG_SPIRAM_RODATA is not set
|
||||||
|
# CONFIG_SPIRAM_SPEED_120M is not set
|
||||||
# CONFIG_SPIRAM_SPEED_80M is not set
|
# CONFIG_SPIRAM_SPEED_80M is not set
|
||||||
CONFIG_SPIRAM_SPEED_40M=y
|
CONFIG_SPIRAM_SPEED_40M=y
|
||||||
CONFIG_SPIRAM_SPEED=40
|
CONFIG_SPIRAM_SPEED=40
|
||||||
# CONFIG_SPIRAM_ECC_ENABLE is not set
|
|
||||||
CONFIG_SPIRAM_BOOT_INIT=y
|
CONFIG_SPIRAM_BOOT_INIT=y
|
||||||
# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set
|
# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set
|
||||||
# CONFIG_SPIRAM_USE_MEMMAP is not set
|
# CONFIG_SPIRAM_USE_MEMMAP is not set
|
||||||
|
|||||||
Reference in New Issue
Block a user