Skip to content

Commit

Permalink
added setting to disable menu items, moved file manager to top-level (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
eadmaster committed Nov 30, 2024
1 parent defe2fa commit 81bb8fc
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 5 deletions.
22 changes: 21 additions & 1 deletion src/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ JsonDocument BruceConfig::toJson() const {
for (const auto& pair : wifi) {
_wifi[pair.first] = pair.second;
}

setting["irTx"] = irTx;
setting["irRx"] = irRx;

Expand All @@ -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;
}
Expand Down Expand Up @@ -119,6 +124,14 @@ void BruceConfig::fromFile() {
if(!setting["wigleBasicToken"].isNull()) { wigleBasicToken = setting["wigleBasicToken"].as<String>(); } else { count++; log_e("Fail"); }
if(!setting["devMode"].isNull()) { devMode = setting["devMode"].as<int>(); } else { count++; log_e("Fail"); }

if(!setting["disabledMenus"].isNull()) {
disabledMenus.clear();
JsonArray dm = setting["disabledMenus"].as<JsonArray>();
for (JsonVariant e : dm) {
disabledMenus.push_back(e.as<String>());
}
} else { count++; log_e("Fail"); }

validateConfig();
if (count>0) saveFile();

Expand Down Expand Up @@ -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();
}
6 changes: 5 additions & 1 deletion src/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Arduino.h>
#include <ArduinoJson.h>
#include <map>
#include <vector>

#define DEFAULT_PRICOLOR 0xA80F

Expand Down Expand Up @@ -64,6 +65,8 @@ class BruceConfig {
String startupApp = "";
String wigleBasicToken = "";
int devMode = 0;

std::vector<String> disabledMenus = {};

/////////////////////////////////////////////////////////////////////////////////////
// Constructor
Expand Down Expand Up @@ -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
19 changes: 18 additions & 1 deletion src/core/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

MainMenu::MainMenu() {
_menuItems = {
&fileMenu,
&wifiMenu,
&bleMenu,
&rfMenu,
Expand Down Expand Up @@ -37,6 +38,7 @@ MainMenu::~MainMenu() {}
void MainMenu::previous(){
_currentIndex--;
if (_currentIndex < 0) _currentIndex = _totalItems - 1;
_checkDisabledMenus(false);
}

/***************************************************************************************
Expand All @@ -46,6 +48,7 @@ void MainMenu::previous(){
void MainMenu::next(){
_currentIndex++;
if (_currentIndex >= _totalItems) _currentIndex = 0;
_checkDisabledMenus(true);
}


Expand All @@ -57,7 +60,6 @@ void MainMenu::openMenuOptions(){
_menuItems[_currentIndex]->optionsMenu();
}


/***************************************************************************************
** Function name: draw
** Description: Função para desenhar e mostrar o menu principal
Expand All @@ -83,3 +85,18 @@ void MainMenu::draw() {
TouchFooter();
#endif
}


void MainMenu::_checkDisabledMenus(bool next_button) {
MenuItemInterface* current_menu = _menuItems[_currentIndex];
std::vector<String> 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();
}
}
3 changes: 3 additions & 0 deletions src/core/main_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -19,6 +20,7 @@

class MainMenu {
public:
FileMenu fileMenu;
BleMenu bleMenu;
ClockMenu clockMenu;
ConnectMenu connectMenu;
Expand Down Expand Up @@ -46,6 +48,7 @@ class MainMenu {
int _currentIndex = 0;
int _totalItems = 0;
std::vector<MenuItemInterface*> _menuItems;
void _checkDisabledMenus(bool next_button);
};

#endif
26 changes: 26 additions & 0 deletions src/core/menu_items/FileMenu.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
17 changes: 17 additions & 0 deletions src/core/menu_items/FileMenu.h
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/core/menu_items/OthersMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }},
Expand Down
1 change: 1 addition & 0 deletions src/core/serialcmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ bool processSerialCommand(String cmd_str) {
if(setting_name=="rfidModule") bruceConfig.setRfidModule(static_cast<RFIDModules>(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;
}

Expand Down

0 comments on commit 81bb8fc

Please sign in to comment.