Skip to content

Commit

Permalink
Merge pull request #50 from esp-cpp/feature/24-battery-status-ui
Browse files Browse the repository at this point in the history
feat(ui): add battery status indication
  • Loading branch information
finger563 committed Dec 28, 2023
2 parents a558a2a + eb580f0 commit 9645f85
Show file tree
Hide file tree
Showing 32 changed files with 3,497 additions and 994 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ set(EMULATOR_COMPONENTS

set(
COMPONENTS
"main esptool_py esp_lcd esp_psram task format display display_drivers monitor esp-idf-cxx ${EMULATOR_COMPONENTS} box-emu-hal gui menu"
"main esptool_py esp_lcd esp_psram task format display display_drivers monitor timer ${EMULATOR_COMPONENTS} box-emu-hal gui menu"
CACHE STRING
"List of components to include"
)
Expand Down
2 changes: 1 addition & 1 deletion components/box-emu-hal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
idf_component_register(
INCLUDE_DIRS "include"
SRC_DIRS "src"
REQUIRES "driver" "heap" "fatfs" "esp_lcd" "esp_psram" "hal" "usb" "esp_tinyusb" "spi_flash" "nvs_flash" "codec" "aw9523" "display" "display_drivers" "mcp23x17" "input_drivers" "tt21100" "gt911" "drv2605" "event_manager" "i2c" "task" "timer"
REQUIRES "driver" "heap" "fatfs" "esp_lcd" "esp_psram" "hal" "usb" "esp_tinyusb" "spi_flash" "nvs_flash" "codec" "aw9523" "display" "display_drivers" "mcp23x17" "input_drivers" "tt21100" "gt911" "drv2605" "event_manager" "i2c" "task" "timer" "serialization"
)
10 changes: 10 additions & 0 deletions components/box-emu-hal/include/battery.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include "serialization.hpp"

static const std::string battery_topic = "battery";

struct BatteryInfo {
uint8_t level;
bool charging;
};
2 changes: 1 addition & 1 deletion components/espp
Submodule espp updated 110 files
3 changes: 2 additions & 1 deletion components/gui/generated/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ SET(SOURCES screens/ui_romscreen.c
screens/ui_settingsscreen.c
ui.c
components/ui_comp_hook.c
ui_helpers.c)
ui_helpers.c
ui_events.c)

add_library(ui ${SOURCES})
2 changes: 1 addition & 1 deletion components/gui/generated/components/ui_comp_hook.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.3.3
// SquareLine Studio version: SquareLine Studio 1.3.4
// LVGL version: 8.3.3
// Project name: emu

1 change: 1 addition & 0 deletions components/gui/generated/filelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ screens/ui_settingsscreen.c
ui.c
components/ui_comp_hook.c
ui_helpers.c
ui_events.c
24 changes: 23 additions & 1 deletion components/gui/generated/screens/ui_romscreen.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.3.3
// SquareLine Studio version: SquareLine Studio 1.3.4
// LVGL version: 8.3.3
// Project name: emu

Expand Down Expand Up @@ -29,6 +29,28 @@ lv_obj_set_height( ui_Screen1_Label2, LV_SIZE_CONTENT); /// 1
lv_obj_set_align( ui_Screen1_Label2, LV_ALIGN_CENTER );
lv_label_set_text(ui_Screen1_Label2,LV_SYMBOL_SETTINGS);

ui_battery_soc_symbol_1 = lv_label_create(ui_header);
lv_obj_set_width( ui_battery_soc_symbol_1, LV_SIZE_CONTENT); /// 1
lv_obj_set_height( ui_battery_soc_symbol_1, LV_SIZE_CONTENT); /// 1
lv_obj_set_x( ui_battery_soc_symbol_1, 52 );
lv_obj_set_y( ui_battery_soc_symbol_1, 5 );
lv_label_set_text(ui_battery_soc_symbol_1,LV_SYMBOL_BATTERY_EMPTY);

ui_battery_charging_symbol_1 = lv_label_create(ui_header);
lv_obj_set_width( ui_battery_charging_symbol_1, LV_SIZE_CONTENT); /// 1
lv_obj_set_height( ui_battery_charging_symbol_1, LV_SIZE_CONTENT); /// 1
lv_obj_set_x( ui_battery_charging_symbol_1, 70 );
lv_obj_set_y( ui_battery_charging_symbol_1, 5 );
lv_label_set_text(ui_battery_charging_symbol_1,"");

ui_battery_soc_text_1 = lv_label_create(ui_header);
lv_obj_set_width( ui_battery_soc_text_1, LV_SIZE_CONTENT); /// 1
lv_obj_set_height( ui_battery_soc_text_1, LV_SIZE_CONTENT); /// 1
lv_obj_set_x( ui_battery_soc_text_1, 52 );
lv_obj_set_y( ui_battery_soc_text_1, -5 );
lv_obj_set_align( ui_battery_soc_text_1, LV_ALIGN_BOTTOM_LEFT );
lv_label_set_text(ui_battery_soc_text_1,"100%");

ui_Screen1_Label1 = lv_label_create(ui_header);
lv_obj_set_width( ui_Screen1_Label1, LV_SIZE_CONTENT); /// 1
lv_obj_set_height( ui_Screen1_Label1, LV_SIZE_CONTENT); /// 1
Expand Down
26 changes: 25 additions & 1 deletion components/gui/generated/screens/ui_settingsscreen.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.3.3
// SquareLine Studio version: SquareLine Studio 1.3.4
// LVGL version: 8.3.3
// Project name: emu

Expand All @@ -16,6 +16,28 @@ lv_obj_set_width( ui_header1, lv_pct(100));
lv_obj_set_align( ui_header1, LV_ALIGN_TOP_MID );
lv_obj_clear_flag( ui_header1, LV_OBJ_FLAG_SCROLLABLE ); /// Flags

ui_battery_charging_symbol = lv_label_create(ui_header1);
lv_obj_set_width( ui_battery_charging_symbol, LV_SIZE_CONTENT); /// 1
lv_obj_set_height( ui_battery_charging_symbol, LV_SIZE_CONTENT); /// 1
lv_obj_set_x( ui_battery_charging_symbol, 70 );
lv_obj_set_y( ui_battery_charging_symbol, 5 );
lv_label_set_text(ui_battery_charging_symbol,"");

ui_battery_soc_symbol = lv_label_create(ui_header1);
lv_obj_set_width( ui_battery_soc_symbol, LV_SIZE_CONTENT); /// 1
lv_obj_set_height( ui_battery_soc_symbol, LV_SIZE_CONTENT); /// 1
lv_obj_set_x( ui_battery_soc_symbol, 52 );
lv_obj_set_y( ui_battery_soc_symbol, 5 );
lv_label_set_text(ui_battery_soc_symbol,LV_SYMBOL_BATTERY_EMPTY);

ui_battery_soc_text = lv_label_create(ui_header1);
lv_obj_set_width( ui_battery_soc_text, LV_SIZE_CONTENT); /// 1
lv_obj_set_height( ui_battery_soc_text, LV_SIZE_CONTENT); /// 1
lv_obj_set_x( ui_battery_soc_text, 52 );
lv_obj_set_y( ui_battery_soc_text, -5 );
lv_obj_set_align( ui_battery_soc_text, LV_ALIGN_BOTTOM_LEFT );
lv_label_set_text(ui_battery_soc_text,"100%");

ui_closebutton = lv_btn_create(ui_header1);
lv_obj_set_width( ui_closebutton, 48);
lv_obj_set_height( ui_closebutton, 48);
Expand Down Expand Up @@ -54,6 +76,7 @@ lv_obj_clear_flag( ui_volumepanel, LV_OBJ_FLAG_SCROLLABLE ); /// Flags

ui_volumebar = lv_bar_create(ui_volumepanel);
lv_bar_set_value(ui_volumebar,25,LV_ANIM_OFF);
lv_bar_set_start_value(ui_volumebar, 0, LV_ANIM_OFF);
lv_obj_set_width( ui_volumebar, 130);
lv_obj_set_height( ui_volumebar, 10);
lv_obj_set_x( ui_volumebar, 25 );
Expand Down Expand Up @@ -111,6 +134,7 @@ lv_obj_clear_flag( ui_brightnesspanel, LV_OBJ_FLAG_SCROLLABLE ); /// Flags

ui_brightnessbar = lv_bar_create(ui_brightnesspanel);
lv_bar_set_value(ui_brightnessbar,100,LV_ANIM_OFF);
lv_bar_set_start_value(ui_brightnessbar, 0, LV_ANIM_OFF);
lv_obj_set_width( ui_brightnessbar, 180);
lv_obj_set_height( ui_brightnessbar, 10);
lv_obj_set_align( ui_brightnessbar, LV_ALIGN_CENTER );
Expand Down
8 changes: 7 additions & 1 deletion components/gui/generated/ui.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.3.3
// SquareLine Studio version: SquareLine Studio 1.3.4
// LVGL version: 8.3.3
// Project name: emu

Expand All @@ -16,6 +16,9 @@ lv_obj_t *ui_header;
void ui_event_settingsbutton( lv_event_t * e);
lv_obj_t *ui_settingsbutton;
lv_obj_t *ui_Screen1_Label2;
lv_obj_t *ui_battery_soc_symbol_1;
lv_obj_t *ui_battery_charging_symbol_1;
lv_obj_t *ui_battery_soc_text_1;
lv_obj_t *ui_Screen1_Label1;
lv_obj_t *ui_playbutton;
lv_obj_t *ui_Screen1_Label3;
Expand All @@ -28,6 +31,9 @@ lv_obj_t *ui_boxart;
void ui_settingsscreen_screen_init(void);
lv_obj_t *ui_settingsscreen;
lv_obj_t *ui_header1;
lv_obj_t *ui_battery_charging_symbol;
lv_obj_t *ui_battery_soc_symbol;
lv_obj_t *ui_battery_soc_text;
void ui_event_closebutton( lv_event_t * e);
lv_obj_t *ui_closebutton;
lv_obj_t *ui_Screen1_Label4;
Expand Down
8 changes: 7 additions & 1 deletion components/gui/generated/ui.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.3.3
// SquareLine Studio version: SquareLine Studio 1.3.4
// LVGL version: 8.3.3
// Project name: emu

Expand All @@ -21,6 +21,9 @@ extern lv_obj_t *ui_header;
void ui_event_settingsbutton( lv_event_t * e);
extern lv_obj_t *ui_settingsbutton;
extern lv_obj_t *ui_Screen1_Label2;
extern lv_obj_t *ui_battery_soc_symbol_1;
extern lv_obj_t *ui_battery_charging_symbol_1;
extern lv_obj_t *ui_battery_soc_text_1;
extern lv_obj_t *ui_Screen1_Label1;
extern lv_obj_t *ui_playbutton;
extern lv_obj_t *ui_Screen1_Label3;
Expand All @@ -31,6 +34,9 @@ extern lv_obj_t *ui_boxart;
void ui_settingsscreen_screen_init(void);
extern lv_obj_t *ui_settingsscreen;
extern lv_obj_t *ui_header1;
extern lv_obj_t *ui_battery_charging_symbol;
extern lv_obj_t *ui_battery_soc_symbol;
extern lv_obj_t *ui_battery_soc_text;
void ui_event_closebutton( lv_event_t * e);
extern lv_obj_t *ui_closebutton;
extern lv_obj_t *ui_Screen1_Label4;
Expand Down
2 changes: 1 addition & 1 deletion components/gui/generated/ui_events.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.3.3
// SquareLine Studio version: SquareLine Studio 1.3.4
// LVGL version: 8.3.3
// Project name: emu

Expand Down
2 changes: 1 addition & 1 deletion components/gui/generated/ui_helpers.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.3.3
// SquareLine Studio version: SquareLine Studio 1.3.4
// LVGL version: 8.3.3
// Project name: emu

Expand Down
2 changes: 1 addition & 1 deletion components/gui/generated/ui_helpers.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.3.3
// SquareLine Studio version: SquareLine Studio 1.3.4
// LVGL version: 8.3.3
// Project name: emu

Expand Down
9 changes: 8 additions & 1 deletion components/gui/include/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "task.hpp"
#include "logger.hpp"

#include "battery.hpp"
#include "fs_init.hpp"
#include "input.h"
#include "hal_events.hpp"
Expand Down Expand Up @@ -52,12 +53,16 @@ class Gui {
espp::EventManager::get().add_subscriber(mute_button_topic,
"gui",
std::bind(&Gui::on_mute_button_pressed, this, _1));
espp::EventManager::get().add_subscriber(battery_topic,
"gui",
std::bind(&Gui::on_battery, this, _1));
}

~Gui() {
espp::EventManager::get().remove_subscriber(mute_button_topic, "gui");
espp::EventManager::get().remove_subscriber(battery_topic, "gui");
task_->stop();
deinit_ui();
espp::EventManager::get().remove_subscriber(mute_button_topic, "gui");
}

void ready_to_play(bool new_state) {
Expand Down Expand Up @@ -152,6 +157,8 @@ class Gui {
set_mute(is_muted());
}

void on_battery(const std::vector<uint8_t>& data);

lv_img_dsc_t make_boxart(const std::string& path) {
// load the file
// auto start = std::chrono::high_resolution_clock::now();
Expand Down
Loading

0 comments on commit 9645f85

Please sign in to comment.