some header work
This commit is contained in:
parent
e27fb6f015
commit
4a47558ef6
@ -6,6 +6,7 @@ set(SOURCES
|
|||||||
"esp_lcd_ili9488/esp_lcd_ili9488.c"
|
"esp_lcd_ili9488/esp_lcd_ili9488.c"
|
||||||
"bottom_half.cpp"
|
"bottom_half.cpp"
|
||||||
"char_lcd.cpp"
|
"char_lcd.cpp"
|
||||||
|
"game_info.cpp"
|
||||||
"game_timer.cpp"
|
"game_timer.cpp"
|
||||||
"i2c_lcd_pcf8574.c"
|
"i2c_lcd_pcf8574.c"
|
||||||
"i2c.cpp"
|
"i2c.cpp"
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include "state_tracking.h"
|
#include "state_tracking.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include "power.h"
|
||||||
|
|
||||||
i2c_lcd_pcf8574_handle_t lcd;
|
i2c_lcd_pcf8574_handle_t lcd;
|
||||||
|
|
||||||
@ -223,6 +224,7 @@ void lcd_create_char(uint8_t location, uint8_t* charmap) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: switch to row, col
|
||||||
void lcd_print(uint8_t col, uint8_t row, const char* str) {
|
void lcd_print(uint8_t col, uint8_t row, const char* str) {
|
||||||
lcd_set_cursor_pos(col, row);
|
lcd_set_cursor_pos(col, row);
|
||||||
lcd_print(&lcd, str);
|
lcd_print(&lcd, str);
|
||||||
@ -236,7 +238,7 @@ void lcd_print(uint8_t col, uint8_t row, const char* str) {
|
|||||||
void set_lcd_header_enabled(bool enable) {
|
void set_lcd_header_enabled(bool enable) {
|
||||||
if (!header_enabled && enable) {
|
if (!header_enabled && enable) {
|
||||||
// enabling header
|
// enabling header
|
||||||
// TODO: enable header
|
lcd_print_header();
|
||||||
} else if (header_enabled && !enable) {
|
} else if (header_enabled && !enable) {
|
||||||
// disabling header
|
// disabling header
|
||||||
lcd_print(1, 1, EMPTY_ROW);
|
lcd_print(1, 1, EMPTY_ROW);
|
||||||
@ -254,14 +256,4 @@ void lcd_print_header() {
|
|||||||
lcd_print_header_bat();
|
lcd_print_header_bat();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_print_header_star_code() {
|
// TODO: add task to continoususly print the header.
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void lcd_print_header_step() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void lcd_print_header_bat() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
20
main/drivers/game_info.cpp
Normal file
20
main/drivers/game_info.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "game_info.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "char_lcd.h"
|
||||||
|
|
||||||
|
static char game_state[GAME_STATE_MAX_LEN+1] = " ";
|
||||||
|
|
||||||
|
void set_game_state(char* new_state) {
|
||||||
|
snprintf(game_state, sizeof(game_state), "%-5s", new_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset_game_state() {
|
||||||
|
for (int i = 0; i < GAME_STATE_MAX_LEN; i++) {
|
||||||
|
game_state[i] = '\0';
|
||||||
|
}
|
||||||
|
game_state[GAME_STATE_MAX_LEN] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcd_print_header_step() {
|
||||||
|
lcd_print(11, 1, game_state);
|
||||||
|
}
|
||||||
17
main/drivers/game_info.h
Normal file
17
main/drivers/game_info.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef GAME_INFO_H
|
||||||
|
#define GAME_INFO_H
|
||||||
|
|
||||||
|
#define GAME_STATE_MAX_LEN 5
|
||||||
|
|
||||||
|
/// @brief Sets the game state, used for the header.
|
||||||
|
///
|
||||||
|
/// Must be <= 5 characters
|
||||||
|
void set_game_state(char* new_state);
|
||||||
|
|
||||||
|
/// @brief Resets the game state to be blank.
|
||||||
|
void reset_game_state();
|
||||||
|
|
||||||
|
/// @brief Prints the game state section of the header to the char_lcd. (row 1, columns 11-15)
|
||||||
|
void lcd_print_header_step();
|
||||||
|
|
||||||
|
#endif /* GAME_INFO_H */
|
||||||
@ -53,3 +53,19 @@ void init_power_board() {
|
|||||||
uint16_t get_bat_voltage() {
|
uint16_t get_bat_voltage() {
|
||||||
return lipo.voltage();
|
return lipo.voltage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lcd_print_header_bat() {
|
||||||
|
uint8_t soc = lipo.soc();
|
||||||
|
char buf[5];
|
||||||
|
if (soc < 5) {
|
||||||
|
sprintf(buf, "LOW ");
|
||||||
|
} else {
|
||||||
|
snprintf(buf, sizeof(buf), "%3d%%", soc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lipo.chgFlag()) {
|
||||||
|
buf[4] = '+';
|
||||||
|
}
|
||||||
|
|
||||||
|
lcd_print(17, 1, buf);
|
||||||
|
}
|
||||||
|
|||||||
@ -14,4 +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 1, columns 17-20)
|
||||||
|
void lcd_print_header_bat();
|
||||||
|
|
||||||
#endif /* POWER_H */
|
#endif /* POWER_H */
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include "drivers/bottom_half.h"
|
#include "drivers/bottom_half.h"
|
||||||
|
#include "char_lcd.h"
|
||||||
|
|
||||||
static const char* TAG = "star_code";
|
static const char* TAG = "star_code";
|
||||||
|
|
||||||
@ -14,6 +15,8 @@ static volatile bool system_initialized = false;
|
|||||||
static volatile SemaphoreHandle_t star_codes_sem;
|
static volatile SemaphoreHandle_t star_codes_sem;
|
||||||
static std::vector<StarCodeEntry> star_codes;
|
static std::vector<StarCodeEntry> star_codes;
|
||||||
|
|
||||||
|
static const char EMPTY_STAR_CODE_HEADER[] = " ";
|
||||||
|
|
||||||
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];
|
||||||
@ -185,3 +188,13 @@ void pause_star_code_system() {
|
|||||||
void resume_star_code_system() {
|
void resume_star_code_system() {
|
||||||
handling_new_starcodes = system_initialized;
|
handling_new_starcodes = system_initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lcd_print_header_star_code() {
|
||||||
|
if (doing_starcode) {
|
||||||
|
char buf[STARCODE_MAX_LEN + 2];
|
||||||
|
sprintf(buf, "*%-8s", current);
|
||||||
|
lcd_print(1, 1, buf);
|
||||||
|
} else {
|
||||||
|
lcd_print(1, 1, EMPTY_STAR_CODE_HEADER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -81,4 +81,7 @@ void set_star_code_sys_enabled(bool enable);
|
|||||||
/// @return `true` if 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 1, columns 1-10)
|
||||||
|
void lcd_print_header_star_code();
|
||||||
|
|
||||||
#endif /* STAR_CODE_H */
|
#endif /* STAR_CODE_H */
|
||||||
Loading…
Reference in New Issue
Block a user