add main menu

This commit is contained in:
Benjamin Wiegand
2025-09-10 17:08:34 -07:00
parent d450c20108
commit aed06067e4
5 changed files with 85 additions and 83 deletions
+1
View File
@@ -51,6 +51,7 @@ add_executable(BattMITM_2.0
defused/batt_gui_util.c
defused/aod.c
defused/menu_list.c
defused/main_menu.c
defused/stat_browser.c
defused/stat_page/general_info.c
defused/stat_page/health_info.c
+7 -5
View File
@@ -23,12 +23,14 @@
*/
// the gui is codename "defused" because I think it's funny
#include "defused/gui.h"
#include "defused/aod.h"
#include "defused/stat_browser.h"
#include "display.h"
#include "config.h"
#include "graphics.h"
#include "defused/aod.h"
#include "defused/stat_browser.h"
#include "defused/main_menu.h"
// active menu
menu_binding_t* defused_current_binding = NULL;
@@ -203,13 +205,13 @@ void init_gui() {
title->alignment_mode = TEXT_ALIGN_CENTER;
title->y1 = display_area_height() / 2 - g_text_box_height(title) / 2;
graphics_add_text_box(title);
graphics_render();
sleep_ms(2000);
graphics_reset();
init_main_menu();
bind_stat_browser();
while (true) defused_loop();
+47
View File
@@ -0,0 +1,47 @@
/**
MIT License
Copyright (c) 2025 Benjamin Wiegand
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#include "defused/main_menu.h"
#include "defused/gui.h"
#include "display.h"
#include "defused/menu_list.h"
#include "defused/stat_browser.h"
menu_list_def_t* main_menu_def = NULL;
void init_main_menu() {
if (main_menu_def != NULL) return; // only do this once
main_menu_def = create_menu_list("main menu", COLOR_FAINT_BLUE, 2, (menu_list_item_t[]) {
create_menu_list_item_callback("battery stats", &bind_stat_browser),
create_menu_list_item_callback("sleep", (void*) &defused_enter_inactive_mode),
});
}
void bind_main_menu() {
menu_list_set(main_menu_def);
bind_menu_list();
}
+26
View File
@@ -0,0 +1,26 @@
/**
MIT License
Copyright (c) 2025 Benjamin Wiegand
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
void init_main_menu();
void bind_main_menu();
+4 -78
View File
@@ -26,19 +26,17 @@
#include "display.h"
#include <stdlib.h>
#include "defused/main_menu.h"
#include "defused/stat_page/general_info.h"
#include "defused/stat_page/health_info.h"
#include "defused/stat_page/cell_voltage_info.h"
#include "defused/stat_page/manufacture_info.h"
#include "defused/menu_list.h"
g_text_box_t* stat_browser_page_number_text;
g_text_box_t* stat_browser_page_title_text;
g_rectangle_t* stat_browser_bottom_bar;
menu_list_def_t* the_menu_tree = NULL;
struct stat_browser_page {
char* title;
void (*update_display)();
@@ -89,13 +87,10 @@ void defused_stat_browser_on_nav_down() {
void defused_stat_browser_on_pre_select() {}
void defused_stat_browser_on_cancel_select() {}
void defused_stat_browser_on_select() {
menu_list_set(the_menu_tree);
bind_menu_list();
}
void defused_stat_browser_on_select() {}
bool defused_stat_browser_on_select_held() {
defused_enter_inactive_mode();
bind_main_menu();
return true;
}
@@ -157,75 +152,6 @@ void defused_stat_browser_init() {
graphics_add_text_box(stat_browser_page_title_text);
graphics_add_text_box(stat_browser_page_number_text);
if (the_menu_tree == NULL) {
the_menu_tree = create_menu_list("menu", COLOR_RED, 2, (menu_list_item_t[]) {
create_menu_list_item_callback("back", &bind_stat_browser),
create_menu_list_item_tree("t",
create_menu_list("t", COLOR_GREEN, 2, (menu_list_item_t[]) {
create_menu_list_item_tree_back("back"),
create_menu_list_item_tree("r",
create_menu_list("tr", COLOR_BLUE, 2, (menu_list_item_t[]) {
create_menu_list_item_tree_back("back"),
create_menu_list_item_tree("e",
create_menu_list("tre", COLOR_PURPLE, 2, (menu_list_item_t[]) {
create_menu_list_item_tree_back("back"),
create_menu_list_item_tree("e",
create_menu_list("tree", COLOR_GRAY, 2, (menu_list_item_t[]) {
create_menu_list_item_tree_back("back"),
create_menu_list_item_tree("e",
create_menu_list("treee", COLOR_ORANGE, 2, (menu_list_item_t[]) {
create_menu_list_item_tree_back("back"),
create_menu_list_item_tree("e",
create_menu_list("treeee", COLOR_YELLOW, 2, (menu_list_item_t[]) {
create_menu_list_item_tree_back("back"),
create_menu_list_item_tree("!",
create_menu_list("treeee!", COLOR_FAINT_RED, 3, (menu_list_item_t[]) {
create_menu_list_item_tree_back("back"),
create_menu_list_item_tree("bro menu tree bro its sick",
create_menu_list("you've hit a leaf!", COLOR_FAINT_GREEN, 1, (menu_list_item_t[]) {
create_menu_list_item_tree_back("back"),
})
),
create_menu_list_item_callback("exit", &bind_stat_browser)
})
)
})
)
})
)
})
)
})
)
})
)
})
),
});
}
}