diff --git a/src/core/config.cpp b/src/core/config.cpp index e13abee3..8591784b 100644 --- a/src/core/config.cpp +++ b/src/core/config.cpp @@ -29,7 +29,7 @@ JsonDocument BruceConfig::toJson() const { for (const auto& pair : wifi) { _wifi[pair.first] = pair.second; } - + setting["irTx"] = irTx; setting["irRx"] = irRx; @@ -45,6 +45,11 @@ JsonDocument BruceConfig::toJson() const { setting["startupApp"] = startupApp; setting["wigleBasicToken"] = wigleBasicToken; setting["devMode"] = devMode; + + JsonArray dm = setting.createNestedArray("disabledMenus"); + for(int i=0; i < disabledMenus.size(); i++){ + dm.add(disabledMenus[i]); + } return jsonDoc; } @@ -119,6 +124,14 @@ void BruceConfig::fromFile() { if(!setting["wigleBasicToken"].isNull()) { wigleBasicToken = setting["wigleBasicToken"].as(); } else { count++; log_e("Fail"); } if(!setting["devMode"].isNull()) { devMode = setting["devMode"].as(); } else { count++; log_e("Fail"); } + if(!setting["disabledMenus"].isNull()) { + disabledMenus.clear(); + JsonArray dm = setting["disabledMenus"].as(); + for (JsonVariant e : dm) { + disabledMenus.push_back(e.as()); + } + } else { count++; log_e("Fail"); } + validateConfig(); if (count>0) saveFile(); @@ -384,3 +397,10 @@ void BruceConfig::setDevMode(int value) { void BruceConfig::validateDevModeValue() { if (devMode > 1) devMode = 1; } + + +void BruceConfig::addDisabledMenu(String value) { + // TODO: check if duplicate + disabledMenus.push_back(value); + saveFile(); +} diff --git a/src/core/config.h b/src/core/config.h index b2c4075b..05bdf793 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -5,6 +5,7 @@ #include #include #include +#include #define DEFAULT_PRICOLOR 0xA80F @@ -64,6 +65,8 @@ class BruceConfig { String startupApp = ""; String wigleBasicToken = ""; int devMode = 0; + + std::vector disabledMenus = {}; ///////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -119,7 +122,8 @@ class BruceConfig { void setWigleBasicToken(String value); void setDevMode(int value); void validateDevModeValue(); - + void addDisabledMenu(String value); + // TODO: removeDisabledMenu(String value); }; #endif diff --git a/src/core/main_menu.cpp b/src/core/main_menu.cpp index f433bf13..66091ee8 100644 --- a/src/core/main_menu.cpp +++ b/src/core/main_menu.cpp @@ -5,6 +5,7 @@ MainMenu::MainMenu() { _menuItems = { + &fileMenu, &wifiMenu, &bleMenu, &rfMenu, @@ -37,6 +38,7 @@ MainMenu::~MainMenu() {} void MainMenu::previous(){ _currentIndex--; if (_currentIndex < 0) _currentIndex = _totalItems - 1; + _checkDisabledMenus(false); } /*************************************************************************************** @@ -46,6 +48,7 @@ void MainMenu::previous(){ void MainMenu::next(){ _currentIndex++; if (_currentIndex >= _totalItems) _currentIndex = 0; + _checkDisabledMenus(true); } @@ -57,7 +60,6 @@ void MainMenu::openMenuOptions(){ _menuItems[_currentIndex]->optionsMenu(); } - /*************************************************************************************** ** Function name: draw ** Description: Função para desenhar e mostrar o menu principal @@ -83,3 +85,18 @@ void MainMenu::draw() { TouchFooter(); #endif } + + +void MainMenu::_checkDisabledMenus(bool next_button) { + MenuItemInterface* current_menu = _menuItems[_currentIndex]; + std::vector l = bruceConfig.disabledMenus; + + String currName = current_menu->getName(); + if( find(l.begin(), l.end(), currName)!=l.end() ) { + // menu disabled, skip to the next/prev one and re-check + if(next_button) + next(); + else + previous(); + } +} \ No newline at end of file diff --git a/src/core/main_menu.h b/src/core/main_menu.h index 04b7ee7c..9b77d540 100644 --- a/src/core/main_menu.h +++ b/src/core/main_menu.h @@ -3,6 +3,7 @@ #include "menu_items/MenuItemInterface.h" +#include "menu_items/FileMenu.h" #include "menu_items/BleMenu.h" #include "menu_items/ClockMenu.h" #include "menu_items/ConfigMenu.h" @@ -19,6 +20,7 @@ class MainMenu { public: + FileMenu fileMenu; BleMenu bleMenu; ClockMenu clockMenu; ConnectMenu connectMenu; @@ -46,6 +48,7 @@ class MainMenu { int _currentIndex = 0; int _totalItems = 0; std::vector _menuItems; + void _checkDisabledMenus(bool next_button); }; #endif diff --git a/src/core/menu_items/FileMenu.cpp b/src/core/menu_items/FileMenu.cpp new file mode 100644 index 00000000..fbb4995a --- /dev/null +++ b/src/core/menu_items/FileMenu.cpp @@ -0,0 +1,26 @@ +#include "FileMenu.h" +#include "core/display.h" +#include "core/sd_functions.h" + +void FileMenu::optionsMenu() { + options = { + {"SD Card", [=]() { loopSD(SD); }}, + {"LittleFS", [=]() { loopSD(LittleFS); }}, + {"Main Menu", [=]() { backToMenu(); }}, + }; + + delay(200); + loopOptions(options,false,true,"Files"); +} + +String FileMenu::getName() { + return _name; +} + +void FileMenu::draw() { + tft.fillRect(iconX,iconY,80,80,bruceConfig.bgColor); + + tft.drawRect(15+iconX, 5+iconY, 50, 70, bruceConfig.priColor); + tft.fillRect(50+iconX, 5+iconY, 15, 15, bruceConfig.bgColor); + tft.drawTriangle(50+iconX, 5+iconY, 50+iconX, 19+iconY, 64+iconX, 19+iconY, bruceConfig.priColor); +} \ No newline at end of file diff --git a/src/core/menu_items/FileMenu.h b/src/core/menu_items/FileMenu.h new file mode 100644 index 00000000..397ac365 --- /dev/null +++ b/src/core/menu_items/FileMenu.h @@ -0,0 +1,17 @@ +#ifndef __FILE_MENU_H__ +#define __FILE_MENU_H__ + +#include "MenuItemInterface.h" + + +class FileMenu : public MenuItemInterface { +public: + void optionsMenu(void); + void draw(void); + String getName(void); + +private: + String _name = "Files"; +}; + +#endif diff --git a/src/core/menu_items/OthersMenu.cpp b/src/core/menu_items/OthersMenu.cpp index bf6e9ace..592df0de 100644 --- a/src/core/menu_items/OthersMenu.cpp +++ b/src/core/menu_items/OthersMenu.cpp @@ -16,8 +16,8 @@ void OthersMenu::optionsMenu() { options = { - {"SD Card", [=]() { loopSD(SD); }}, - {"LittleFS", [=]() { loopSD(LittleFS); }}, + //{"SD Card", [=]() { loopSD(SD); }}, + //{"LittleFS", [=]() { loopSD(LittleFS); }}, {"WebUI", [=]() { loopOptionsWebUi(); }}, {"QRCodes", [=]() { qrcode_menu(); }}, {"GPS Tracker", [=]() { GPSTracker(); }}, diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index b2e25d59..cedf6b3e 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -796,6 +796,7 @@ bool processSerialCommand(String cmd_str) { if(setting_name=="rfidModule") bruceConfig.setRfidModule(static_cast(setting_value.toInt())); if(setting_name=="wigleBasicToken") bruceConfig.setWigleBasicToken(setting_value); if(setting_name=="devMode") bruceConfig.setDevMode(setting_value.toInt()); + if(setting_name=="disabledMenus") bruceConfig.addDisabledMenu(setting_value); return true; }