introduction of gui_registry
This commit is contained in:
parent
283684bdfc
commit
cbf1bf9b12
15 changed files with 112 additions and 39 deletions
|
@ -1,6 +1,7 @@
|
|||
#include <lvgl.h>
|
||||
#include "device_appleTV/device_appleTV.h"
|
||||
#include "gui_general_and_keys/gui_base.h"
|
||||
#include "gui_general_and_keys/gui_registry.h"
|
||||
#include "hardware/tft.h"
|
||||
#include "commandHandler.h"
|
||||
|
||||
|
@ -16,7 +17,7 @@ static void appleKey_event_cb(lv_event_t* e) {
|
|||
Serial.println(50 + (int)e->user_data);
|
||||
}
|
||||
|
||||
void init_gui_appleTV(lv_obj_t* tabview) {
|
||||
void init_gui_tab_appleTV(lv_obj_t* tabview) {
|
||||
|
||||
lv_obj_t* tab = lv_tabview_add_tab(tabview, "Apple TV");
|
||||
|
||||
|
@ -54,7 +55,7 @@ void init_gui_appleTV(lv_obj_t* tabview) {
|
|||
|
||||
}
|
||||
|
||||
void init_gui_pageIndicator_appleTV() {
|
||||
void init_gui_pageIndicator_appleTV(lv_obj_t* panel) {
|
||||
// Create actual (non-clickable) buttons for every tab
|
||||
lv_obj_t* btn = lv_btn_create(panel);
|
||||
lv_obj_clear_flag(btn, LV_OBJ_FLAG_CLICKABLE);
|
||||
|
@ -66,3 +67,7 @@ void init_gui_pageIndicator_appleTV() {
|
|||
lv_obj_set_style_bg_color(btn, color_primary, LV_PART_MAIN);
|
||||
|
||||
}
|
||||
|
||||
void register_gui_appleTV(void){
|
||||
register_gui(& init_gui_tab_appleTV, & init_gui_pageIndicator_appleTV);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <lvgl.h>
|
||||
|
||||
void init_gui_appleTV(lv_obj_t* tabview);
|
||||
void init_gui_pageIndicator_appleTV();
|
||||
void register_gui_appleTV(void);
|
||||
|
||||
#endif /*__GUI_APPLETV_H__*/
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <string>
|
||||
#include <lvgl.h>
|
||||
#include "gui_general_and_keys/gui_base.h"
|
||||
#include "gui_general_and_keys/gui_registry.h"
|
||||
#include "hardware/tft.h"
|
||||
#include "device_smarthome/device_smarthome.h"
|
||||
#include "commandHandler.h"
|
||||
|
@ -33,7 +34,7 @@ static void smartHomeSlider_event_cb(lv_event_t * e){
|
|||
#endif
|
||||
}
|
||||
|
||||
void init_gui_smarthome(lv_obj_t* tabview) {
|
||||
void init_gui_tab_smarthome(lv_obj_t* tabview) {
|
||||
|
||||
lv_obj_t* tab = lv_tabview_add_tab(tabview, "Smart Home");
|
||||
|
||||
|
@ -127,7 +128,7 @@ void init_gui_smarthome(lv_obj_t* tabview) {
|
|||
|
||||
}
|
||||
|
||||
void init_gui_pageIndicator_smarthome() {
|
||||
void init_gui_pageIndicator_smarthome(lv_obj_t* panel) {
|
||||
// Create actual (non-clickable) buttons for every tab
|
||||
lv_obj_t* btn = lv_btn_create(panel);
|
||||
lv_obj_clear_flag(btn, LV_OBJ_FLAG_CLICKABLE);
|
||||
|
@ -139,3 +140,7 @@ void init_gui_pageIndicator_smarthome() {
|
|||
lv_obj_set_style_bg_color(btn, color_primary, LV_PART_MAIN);
|
||||
|
||||
}
|
||||
|
||||
void register_gui_smarthome(void){
|
||||
register_gui(& init_gui_tab_smarthome, & init_gui_pageIndicator_smarthome);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <lvgl.h>
|
||||
|
||||
void init_gui_smarthome(lv_obj_t* tabview);
|
||||
void init_gui_pageIndicator_smarthome();
|
||||
void register_gui_smarthome(void);
|
||||
|
||||
#endif /*__GUI_SMARTHOME_H__*/
|
||||
|
|
|
@ -2,11 +2,7 @@
|
|||
#include "hardware/tft.h"
|
||||
#include "hardware/sleep.h"
|
||||
#include "gui_general_and_keys/gui_base.h"
|
||||
#include "gui_general_and_keys/gui_irReceiver.h"
|
||||
#include "gui_general_and_keys/gui_numpad.h"
|
||||
#include "gui_general_and_keys/gui_settings.h"
|
||||
#include "device_appleTV/gui_appleTV.h"
|
||||
#include "device_smarthome/gui_smarthome.h"
|
||||
#include "gui_general_and_keys/gui_registry.h"
|
||||
|
||||
lv_obj_t* panel;
|
||||
lv_color_t color_primary = lv_color_hex(0x303030); // gray
|
||||
|
@ -123,11 +119,7 @@ void init_gui(void) {
|
|||
lv_obj_align(tabview, LV_ALIGN_TOP_MID, 0, 20);
|
||||
|
||||
// Add all the tabs here
|
||||
init_gui_irReceiver(tabview);
|
||||
init_gui_settings(tabview);
|
||||
init_gui_numpad(tabview);
|
||||
init_gui_appleTV(tabview);
|
||||
init_gui_smarthome(tabview);
|
||||
create_gui_tabs_from_gui_registry(tabview);
|
||||
|
||||
// Set current page according to the current screen
|
||||
lv_tabview_set_act(tabview, currentScreen, LV_ANIM_OFF);
|
||||
|
@ -147,11 +139,7 @@ void init_gui(void) {
|
|||
lv_obj_set_style_opa(btn, LV_OPA_TRANSP, LV_PART_MAIN);
|
||||
|
||||
// Create actual (non-clickable) buttons for every tab
|
||||
init_gui_pageIndicator_irReceiver();
|
||||
init_gui_pageIndicator_settings();
|
||||
init_gui_pageIndicator_numpad();
|
||||
init_gui_pageIndicator_appleTV();
|
||||
init_gui_pageIndicator_smarthome();
|
||||
create_gui_pageIndicators_from_gui_registry(panel);
|
||||
|
||||
// This small hidden button enables the page indicator to scroll further
|
||||
btn = lv_btn_create(panel);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef __GUI_H__
|
||||
#define __GUI_H__
|
||||
#ifndef __GUI_BASE_H__
|
||||
#define __GUI_BASE_H__
|
||||
|
||||
#include <lvgl.h>
|
||||
#include "../hardware/tft.h"
|
||||
|
@ -9,7 +9,6 @@ LV_IMG_DECLARE(high_brightness);
|
|||
LV_IMG_DECLARE(low_brightness);
|
||||
extern lv_obj_t* objBattPercentage;
|
||||
extern lv_obj_t* objBattIcon;
|
||||
extern lv_obj_t* panel;
|
||||
extern lv_color_t color_primary;
|
||||
|
||||
extern lv_obj_t* WifiLabel;
|
||||
|
@ -20,4 +19,4 @@ extern byte currentScreen; // Current screen that is shown
|
|||
void init_gui(void);
|
||||
void gui_loop(void);
|
||||
|
||||
#endif /*__GUI_H__*/
|
||||
#endif /*__GUI_BASE_H__*/
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "hardware/sleep.h"
|
||||
#include "hardware/infrared_receiver.h"
|
||||
#include "gui_general_and_keys/gui_base.h"
|
||||
#include "gui_general_and_keys/gui_registry.h"
|
||||
|
||||
lv_obj_t* menuBoxToggle;
|
||||
lv_obj_t* menuBoxMessages;
|
||||
|
@ -82,7 +83,7 @@ static void IRReceiverOnSetting_event_cb(lv_event_t * e){
|
|||
}
|
||||
}
|
||||
|
||||
void init_gui_irReceiver(lv_obj_t* tabview) {
|
||||
void init_gui_tab_irReceiver(lv_obj_t* tabview) {
|
||||
|
||||
lv_obj_t* tab = lv_tabview_add_tab(tabview, "IR Receiver");
|
||||
|
||||
|
@ -121,7 +122,7 @@ void init_gui_irReceiver(lv_obj_t* tabview) {
|
|||
printReceivedMessages(true);
|
||||
}
|
||||
|
||||
void init_gui_pageIndicator_irReceiver() {
|
||||
void init_gui_pageIndicator_irReceiver(lv_obj_t* panel) {
|
||||
// Create actual (non-clickable) buttons for every tab
|
||||
lv_obj_t* btn = lv_btn_create(panel);
|
||||
lv_obj_clear_flag(btn, LV_OBJ_FLAG_CLICKABLE);
|
||||
|
@ -132,3 +133,7 @@ void init_gui_pageIndicator_irReceiver() {
|
|||
lv_obj_set_style_shadow_width(btn, 0, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(btn, color_primary, LV_PART_MAIN);
|
||||
}
|
||||
|
||||
void register_gui_irReceiver(void){
|
||||
register_gui(& init_gui_tab_irReceiver, & init_gui_pageIndicator_irReceiver);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
#include <lvgl.h>
|
||||
#include <string>
|
||||
|
||||
void init_gui_irReceiver(lv_obj_t* tabview);
|
||||
void init_gui_pageIndicator_irReceiver();
|
||||
void register_gui_irReceiver(void);
|
||||
void showNewIRmessage(String);
|
||||
|
||||
#endif /*__GUI_IRRECEIVER_H__*/
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <lvgl.h>
|
||||
#include "hardware/tft.h"
|
||||
#include "gui_general_and_keys/gui_base.h"
|
||||
#include "gui_general_and_keys/gui_registry.h"
|
||||
#include "commandHandler.h"
|
||||
|
||||
// Virtual Keypad Event handler
|
||||
|
@ -16,7 +17,7 @@ static void virtualKeypad_event_cb(lv_event_t* e) {
|
|||
executeCommand(KEYBOARD_SENDSTRING, numberStr);
|
||||
}
|
||||
|
||||
void init_gui_numpad(lv_obj_t* tabview) {
|
||||
void init_gui_tab_numpad(lv_obj_t* tabview) {
|
||||
|
||||
lv_obj_t* tab = lv_tabview_add_tab(tabview, "Numpad");
|
||||
|
||||
|
@ -71,7 +72,7 @@ void init_gui_numpad(lv_obj_t* tabview) {
|
|||
|
||||
}
|
||||
|
||||
void init_gui_pageIndicator_numpad() {
|
||||
void init_gui_pageIndicator_numpad(lv_obj_t* panel) {
|
||||
// Create actual (non-clickable) buttons for every tab
|
||||
lv_obj_t* btn = lv_btn_create(panel);
|
||||
lv_obj_clear_flag(btn, LV_OBJ_FLAG_CLICKABLE);
|
||||
|
@ -83,3 +84,7 @@ void init_gui_pageIndicator_numpad() {
|
|||
lv_obj_set_style_bg_color(btn, color_primary, LV_PART_MAIN);
|
||||
|
||||
}
|
||||
|
||||
void register_gui_numpad(void){
|
||||
register_gui(& init_gui_tab_numpad, & init_gui_pageIndicator_numpad);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <lvgl.h>
|
||||
|
||||
void init_gui_numpad(lv_obj_t* tabview);
|
||||
void init_gui_pageIndicator_numpad();
|
||||
void register_gui_numpad(void);
|
||||
|
||||
#endif /*__GUI_NUMPAD_H__*/
|
||||
|
|
31
Platformio/src/gui_general_and_keys/gui_registry.cpp
Normal file
31
Platformio/src/gui_general_and_keys/gui_registry.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <string>
|
||||
#include <list>
|
||||
#include <lvgl.h>
|
||||
#include "gui_registry.h"
|
||||
|
||||
// https://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work
|
||||
struct gui_functions {
|
||||
init_gui_tab this_init_gui_tab;
|
||||
init_gui_pageIndicator this_init_gui_pageIndicator;
|
||||
};
|
||||
|
||||
std::list<gui_functions> registered_guis;
|
||||
|
||||
void register_gui(init_gui_tab a_init_gui_tab, init_gui_pageIndicator a_gui_pageIndicator) {
|
||||
registered_guis.push_back(gui_functions{a_init_gui_tab, a_gui_pageIndicator});
|
||||
|
||||
}
|
||||
|
||||
void create_gui_tabs_from_gui_registry(lv_obj_t* tabview) {
|
||||
std::list<gui_functions>::iterator it;
|
||||
for (it = registered_guis.begin(); it != registered_guis.end(); ++it) {
|
||||
it->this_init_gui_tab(tabview);
|
||||
}
|
||||
}
|
||||
|
||||
void create_gui_pageIndicators_from_gui_registry(lv_obj_t* panel) {
|
||||
std::list<gui_functions>::iterator it;
|
||||
for (it = registered_guis.begin(); it != registered_guis.end(); ++it) {
|
||||
it->this_init_gui_pageIndicator(panel);
|
||||
}
|
||||
}
|
24
Platformio/src/gui_general_and_keys/gui_registry.h
Normal file
24
Platformio/src/gui_general_and_keys/gui_registry.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
If you want to create a new GUI for the touch screen, then
|
||||
- copy one of the existing GUIs, e.g. gui_numpad.cpp and gui_numpad.h
|
||||
- place the files in the right folder:
|
||||
- in folder "gui_general_and_keys" if they are of general purpose, not only for a specific device
|
||||
- in the device folder, if the GUI is specific for a certain device
|
||||
- in folder "scenes" if the GUI is intended for a specific scene
|
||||
It does not really matter where the files are placed, but doing so helps to keep a clean structure
|
||||
- rename the functions, they must not have the same name as the ones in the file you copied from
|
||||
- call "register_gui_<nameOfGUI>();" in main.cpp
|
||||
|
||||
Technically spoken, to register a GUI, you need to provide two function pointers:
|
||||
- one for creating the tab
|
||||
- one for creating the page indicator at the bottom of the tab
|
||||
*/
|
||||
#include <string>
|
||||
#include <lvgl.h>
|
||||
|
||||
typedef void (*init_gui_tab)(lv_obj_t* tabview);
|
||||
typedef void (*init_gui_pageIndicator)(lv_obj_t* tabview);
|
||||
|
||||
void register_gui(init_gui_tab a_init_gui_tab, init_gui_pageIndicator a_gui_pageIndicator);
|
||||
void create_gui_tabs_from_gui_registry(lv_obj_t* tabview);
|
||||
void create_gui_pageIndicators_from_gui_registry(lv_obj_t* panel);
|
|
@ -2,6 +2,7 @@
|
|||
#include "hardware/tft.h"
|
||||
#include "hardware/sleep.h"
|
||||
#include "gui_general_and_keys/gui_base.h"
|
||||
#include "gui_general_and_keys/gui_registry.h"
|
||||
|
||||
lv_obj_t* objBattSettingsVoltage;
|
||||
lv_obj_t* objBattSettingsPercentage;
|
||||
|
@ -35,7 +36,7 @@ static void timout_event_cb(lv_event_t * e){
|
|||
resetStandbyTimer();
|
||||
}
|
||||
|
||||
void init_gui_settings(lv_obj_t* tabview) {
|
||||
void init_gui_tab_settings(lv_obj_t* tabview) {
|
||||
|
||||
lv_obj_t* tab = lv_tabview_add_tab(tabview, "Settings");
|
||||
|
||||
|
@ -156,7 +157,7 @@ void init_gui_settings(lv_obj_t* tabview) {
|
|||
// lv_obj_align(objBattSettingsIscharging, LV_ALIGN_TOP_LEFT, 0, 64);
|
||||
}
|
||||
|
||||
void init_gui_pageIndicator_settings() {
|
||||
void init_gui_pageIndicator_settings(lv_obj_t* panel) {
|
||||
// Create actual (non-clickable) buttons for every tab
|
||||
lv_obj_t* btn = lv_btn_create(panel);
|
||||
lv_obj_clear_flag(btn, LV_OBJ_FLAG_CLICKABLE);
|
||||
|
@ -168,3 +169,7 @@ void init_gui_pageIndicator_settings() {
|
|||
lv_obj_set_style_bg_color(btn, color_primary, LV_PART_MAIN);
|
||||
|
||||
}
|
||||
|
||||
void register_gui_settings(void){
|
||||
register_gui(& init_gui_tab_settings, & init_gui_pageIndicator_settings);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ extern lv_obj_t* objBattSettingsVoltage;
|
|||
extern lv_obj_t* objBattSettingsPercentage;
|
||||
//extern lv_obj_t* objBattSettingsIscharging;
|
||||
|
||||
void init_gui_settings(lv_obj_t* tabview);
|
||||
void init_gui_pageIndicator_settings();
|
||||
void register_gui_settings(void);
|
||||
|
||||
#endif /*__GUI_SETTINGS_H__*/
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
#include "device_keyboard_ble/device_keyboard_ble.h"
|
||||
#include "gui_general_and_keys/keys.h"
|
||||
#include "gui_general_and_keys/gui_base.h"
|
||||
#include "gui_general_and_keys/gui_irReceiver.h"
|
||||
#include "gui_general_and_keys/gui_settings.h"
|
||||
#include "gui_general_and_keys/gui_numpad.h"
|
||||
#include "device_appleTV/gui_appleTV.h"
|
||||
#include "device_smarthome/gui_smarthome.h"
|
||||
#include "preferences_storage.h"
|
||||
#include "commandHandler.h"
|
||||
|
||||
|
@ -43,6 +48,12 @@ void setup() {
|
|||
// init TFT
|
||||
init_tft();
|
||||
|
||||
// Here you can register the GUIs you want to display. Will be displayed in the order they are registered.
|
||||
register_gui_irReceiver();
|
||||
register_gui_settings();
|
||||
register_gui_numpad();
|
||||
register_gui_appleTV();
|
||||
register_gui_smarthome();
|
||||
// init GUI
|
||||
init_gui();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue