update starcodes
This commit is contained in:
parent
cfc307ee72
commit
8bddceca66
@ -1,4 +1,5 @@
|
|||||||
#include "game_info.h"
|
#include "game_info.h"
|
||||||
|
#include "star_code.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "char_lcd.h"
|
#include "char_lcd.h"
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ void reset_game_state() {
|
|||||||
|
|
||||||
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(11, 0, game_state);
|
lcd_print(11, 0, game_state);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "power.h"
|
#include "power.h"
|
||||||
#include "char_lcd.h"
|
#include "char_lcd.h"
|
||||||
|
#include "star_code.h"
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
|
||||||
static const char* TAG = "power";
|
static const char* TAG = "power";
|
||||||
@ -56,10 +57,11 @@ 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();
|
||||||
uint8_t current = lipo.current();
|
uint8_t current = lipo.current();
|
||||||
char buf[4];
|
char buf[5];
|
||||||
if (soc < 5 && current <= 0) {
|
if (soc < 5 && current <= 0) {
|
||||||
snprintf(buf, sizeof(buf), "LOW");
|
snprintf(buf, sizeof(buf), "LOW");
|
||||||
} else if (soc == 100) {
|
} else if (soc == 100) {
|
||||||
|
|||||||
@ -20,8 +20,10 @@ 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];
|
||||||
@ -30,7 +32,7 @@ static size_t current_idx;
|
|||||||
static void starcode_trigger_cb(void* arg) {
|
static void starcode_trigger_cb(void* arg) {
|
||||||
(void) arg;
|
(void) arg;
|
||||||
|
|
||||||
processing_starcode = false;
|
delaying_for_starcode = false;
|
||||||
|
|
||||||
if (current_starcode != nullptr) {
|
if (current_starcode != nullptr) {
|
||||||
if (current_starcode->triggered_sem != nullptr)
|
if (current_starcode->triggered_sem != nullptr)
|
||||||
@ -42,12 +44,12 @@ static void starcode_trigger_cb(void* arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rename star code everywhere to starcode
|
// TODO: rename star code everywhere to starcode
|
||||||
lcd_print_header_star_code();
|
lcd_print_header();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
@ -130,7 +132,7 @@ bool add_star_code(StarCodeEntry code) {
|
|||||||
ESP_LOGW(TAG, "invalid code");
|
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");
|
ESP_LOGW(TAG, "invalid display_text");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -206,7 +208,7 @@ bool trigger_star_code(const char* 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;
|
||||||
@ -230,12 +232,12 @@ 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), "%-10s", 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);
|
||||||
@ -248,3 +250,7 @@ void lcd_print_header_star_code() {
|
|||||||
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;
|
||||||
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
/// The max length of a starcode (not counting the star)
|
/// The max length of a starcode (not counting the star)
|
||||||
#define STARCODE_MAX_LEN 9
|
#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 {
|
||||||
@ -18,7 +19,7 @@ struct StarCodeEntry {
|
|||||||
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 <= 10 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 */
|
||||||
@ -59,28 +59,28 @@ void step0() {
|
|||||||
StarCodeEntry star_codes[] = {
|
StarCodeEntry star_codes[] = {
|
||||||
{
|
{
|
||||||
.code = "9819",
|
.code = "9819",
|
||||||
.display_text = "Diffuse",
|
.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 = "59861",
|
.code = "59861",
|
||||||
.display_text = "Set Wires",
|
.display_text = "Setup Wires",
|
||||||
.delay_us = 10'000'000,
|
.delay_us = 10'000'000,
|
||||||
.callback = setup_wires,
|
.callback = setup_wires,
|
||||||
.triggered_sem = nullptr,
|
.triggered_sem = nullptr,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.code = "59862",
|
.code = "59862",
|
||||||
.display_text = "Set Time",
|
.display_text = "Set Game Time",
|
||||||
.delay_us = 2'000'000,
|
.delay_us = 2'000'000,
|
||||||
.callback = set_game_time,
|
.callback = set_game_time,
|
||||||
.triggered_sem = nullptr,
|
.triggered_sem = nullptr,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.code = "59863",
|
.code = "59863",
|
||||||
.display_text = "DBG switch",
|
.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,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user