Skip to content

Commit

Permalink
Merge pull request #658 from rennancockles/dev
Browse files Browse the repository at this point in the history
Store led settings into bruceConfig
  • Loading branch information
rennancockles authored Jan 7, 2025
2 parents 842c2bd + 8225e6e commit 70630d2
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 91 deletions.
34 changes: 33 additions & 1 deletion src/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ JsonDocument BruceConfig::toJson() const {
setting["soundEnabled"] = soundEnabled;
setting["wifiAtStartup"] = wifiAtStartup;

setting["ledBright"] = ledBright;
setting["ledColor"] = String(ledColor, HEX);

JsonObject _webUI = setting.createNestedObject("webUI");
_webUI["user"] = webUI.user;
_webUI["pwd"] = webUI.pwd;
Expand Down Expand Up @@ -99,6 +102,9 @@ void BruceConfig::fromFile() {
if(!setting["soundEnabled"].isNull()) { soundEnabled = setting["soundEnabled"].as<int>(); } else { count++; log_e("Fail"); }
if(!setting["wifiAtStartup"].isNull()) { wifiAtStartup = setting["wifiAtStartup"].as<int>(); } else { count++; log_e("Fail"); }

if(!setting["ledBright"].isNull()) { ledBright = setting["ledBright"].as<int>(); } else { count++; log_e("Fail"); }
if(!setting["ledColor"].isNull()) { ledColor = strtoul(setting["ledColor"], nullptr, 16); } else { count++; log_e("Fail"); }

if(!setting["webUI"].isNull()) {
JsonObject webUIObj = setting["webUI"].as<JsonObject>();
webUI.user = webUIObj["user"].as<String>();
Expand Down Expand Up @@ -182,7 +188,7 @@ void BruceConfig::saveFile() {

file.close();

if (setupSdCard()) copyToFs(LittleFS, SD, filepath,false);
if (setupSdCard()) copyToFs(LittleFS, SD, filepath, false);
}


Expand All @@ -194,6 +200,8 @@ void BruceConfig::validateConfig() {
validateTmzValue();
validateSoundEnabledValue();
validateWifiAtStartupValue();
validateLedBrightValue();
validateLedColorValue();
validateRfScanRangeValue();
validateRfModuleValue();
validateRfidModuleValue();
Expand Down Expand Up @@ -291,6 +299,30 @@ void BruceConfig::validateWifiAtStartupValue() {
}


void BruceConfig::setLedBright(int value) {
ledBright = value;
validateLedBrightValue();
saveFile();
}


void BruceConfig::validateLedBrightValue() {
ledBright = max(0, min(100, ledBright));
}


void BruceConfig::setLedColor(uint32_t value) {
ledColor = value;
validateLedColorValue();
saveFile();
}


void BruceConfig::validateLedColorValue() {
ledColor = max((uint32_t)0, min(0xFFFFFFFF, ledColor));
}


void BruceConfig::setWebUICreds(const String& usr, const String& pwd) {
webUI.user = usr;
webUI.pwd = pwd;
Expand Down
33 changes: 29 additions & 4 deletions src/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,53 @@ class BruceConfig {
uint16_t secColor = DEFAULT_PRICOLOR-0x2000;
uint16_t bgColor = 0x0000;

// Settings
int rotation = ROTATION > 1 ? 3 : 1;
int dimmerSet = 10;
int bright = 100;
int tmz = 0;
int soundEnabled = 1;
int wifiAtStartup = 0;

// Led
int ledBright = 75;
uint32_t ledColor = 0;

// Wifi
Credential webUI = {"admin", "bruce"};
WiFiCredential wifiAp = {"BruceNet", "brucenet"};
std::map<String, String> wifi = {};

// IR
int irTx = LED;
int irRx = GROVE_SCL;

// RF
int rfTx = GROVE_SDA;
int rfRx = GROVE_SCL;
int rfModule = M5_RF_MODULE;
float rfFreq = 433.92;
int rfFxdFreq = 1;
int rfScanRange = 3;

// RFID
int rfidModule = M5_RFID2_MODULE;

// GPS
int gpsBaudrate = 9600;

// Misc
String startupApp = "";
String wigleBasicToken = "";
int devMode = 0;

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

std::vector<QrCodeEntry> qrCodes = {
{"Bruce AP", "WIFI:T:WPA;S:BruceNet;P:brucenet;;"},
{"Bruce Wiki", "https://github.com/pr3y/Bruce/wiki"},
{"Bruce Site", "https://bruce.computer"},
{"Rickroll", "https://youtu.be/dQw4w9WgXcQ"}
{"Bruce AP", "WIFI:T:WPA;S:BruceNet;P:brucenet;;"},
{"Bruce Wiki", "https://github.com/pr3y/Bruce/wiki"},
{"Bruce Site", "https://bruce.computer"},
{"Rickroll", "https://youtu.be/dQw4w9WgXcQ"}
};

/////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -95,9 +106,11 @@ class BruceConfig {
void validateConfig();
JsonDocument toJson() const;

// Theme
void setTheme(uint16_t primary, uint16_t secondary = NULL, uint16_t background = NULL);
void validateTheme();

// Settings
void setRotation(int value);
void validateRotationValue();
void setDimmer(int value);
Expand All @@ -111,16 +124,25 @@ class BruceConfig {
void setWifiAtStartup(int value);
void validateWifiAtStartupValue();

// Led
void setLedBright(int value);
void validateLedBrightValue();
void setLedColor(uint32_t value);
void validateLedColorValue();

// Wifi
void setWebUICreds(const String& usr, const String& pwd);
void setWifiApCreds(const String& ssid, const String& pwd);
void addWifiCredential(const String& ssid, const String& pwd);
void addQrCodeEntry(const String& menuName, const String& content);
void removeQrCodeEntry(const String& menuName);
String getWifiPassword(const String& ssid) const;

// IR
void setIrTxPin(int value);
void setIrRxPin(int value);

// RF
void setRfTxPin(int value);
void setRfRxPin(int value);
void setRfModule(RFModules value);
Expand All @@ -130,12 +152,15 @@ class BruceConfig {
void setRfScanRange(int value, int fxdFreq = 0);
void validateRfScanRangeValue();

// RFID
void setRfidModule(RFIDModules value);
void validateRfidModuleValue();

// GPS
void setGpsBaudrate(int value);
void validateGpsBaudrateValue();

// Misc
void setStartupApp(String value);
void setWigleBasicToken(String value);
void setDevMode(int value);
Expand Down
17 changes: 12 additions & 5 deletions src/core/menu_items/ConfigMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
#include "core/settings.h"
#include "core/i2c_finder.h"
#include "core/wifi_common.h"
#ifdef HAS_RGB_LED
#include "modules/others/led_control.h"
#endif

void ConfigMenu::optionsMenu() {
options = {
{"Brightness", [=]() { setBrightnessMenu(); }},
{"Dim Time", [=]() { setDimmerTimeMenu(); }},
{"Orientation", [=]() { gsetRotation(true); }},
{"UI Color", [=]() { setUIColor(); }},
#ifdef HAS_RGB_LED
{"LED Color", [=]() { setLedColorConfig(); }},
{"LED Brightness",[=]() { setLedBrightnessConfig(); }},
#endif
{"Sound On/Off", [=]() { setSoundConfig(); }},
{"Startup WiFi", [=]() { setWifiStartupConfig(); }},
{"Startup App", [=]() { setStartupApp(); }},
Expand All @@ -19,12 +26,12 @@ void ConfigMenu::optionsMenu() {
{"Restart", [=]() { ESP.restart(); }},
};

#if defined(T_EMBED_1101)
options.push_back({"Turn-off", [=]() { digitalWrite(PIN_POWER_ON,LOW); esp_sleep_enable_ext0_wakeup(GPIO_NUM_6,LOW); esp_deep_sleep_start(); }});
#endif
if (bruceConfig.devMode) options.push_back({"Dev Mode", [=]() { devMenu(); }});
#if defined(T_EMBED_1101)
options.emplace_back("Turn-off", [=]() { digitalWrite(PIN_POWER_ON,LOW); esp_sleep_enable_ext0_wakeup(GPIO_NUM_6,LOW); esp_deep_sleep_start(); });
#endif
if (bruceConfig.devMode) options.emplace_back("Dev Mode", [=]() { devMenu(); });

options.push_back({"Main Menu", [=]() { backToMenu(); }});
options.emplace_back("Main Menu", [=]() { backToMenu(); });

loopOptions(options,false,true,"Config");
}
Expand Down
15 changes: 1 addition & 14 deletions src/core/menu_items/OthersMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
#include "OthersMenu.h"
#include "core/display.h"
#include "core/sd_functions.h"
#include "core/utils.h"
#include "modules/others/openhaystack.h"
#include "modules/others/tururururu.h"
#include "modules/others/webInterface.h"
#include "modules/others/qrcode_menu.h"
#include "modules/others/mic.h"
#include "modules/bjs_interpreter/interpreter.h"
#include "modules/others/timer.h"
#include "core/utils.h"

#include "modules/others/clicker.h"
#include "modules/others/bad_usb.h"
#ifdef HAS_RGB_LED
#include "modules/others/led_control.h"
#endif

void OthersMenu::optionsMenu() {
options = {
{"SD Card", [=]() { loopSD(SD); }},
{"LittleFS", [=]() { loopSD(LittleFS); }},
{"WebUI", [=]() { loopOptionsWebUi(); }},
{"QRCodes", [=]() { qrcode_menu(); }},
{"Megalodon", [=]() { shark_setup(); }},
#ifdef MIC_SPM1423
Expand All @@ -30,10 +21,6 @@ void OthersMenu::optionsMenu() {
#ifdef HAS_KEYBOARD_HID
{"USB Keyboard", [=]() { usb_keyboard(); }},
#endif
#ifdef HAS_RGB_LED
{"LED Control", [=]() { ledColorConfig(); }},
{"LED Brightness", [=]() { ledBrightnessConfig(); }},
#endif
#ifdef USB_as_HID
{"Clicker", [=]() { clicker_setup(); }},
#endif
Expand Down
25 changes: 19 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ keyStroke KeyStroke;

TaskHandle_t xHandle;
void __attribute__((weak)) taskInputHandler(void *parameter) {
while (true) {
while (true) {
checkPowerSaveTime();
NextPress=false;
PrevPress=false;
Expand Down Expand Up @@ -88,7 +88,7 @@ uint8_t buff[1024] = {0};
TFT_eSprite sprite = TFT_eSprite(&tft);
TFT_eSprite draw = TFT_eSprite(&tft);
volatile int tftWidth = TFT_HEIGHT;
#ifdef HAS_TOUCH
#ifdef HAS_TOUCH
volatile int tftHeight = TFT_WIDTH-20; // 20px to draw the TouchFooter(), were the btns are being read in touch devices.
#else
volatile int tftHeight = TFT_WIDTH;
Expand All @@ -109,6 +109,7 @@ uint8_t buff[1024] = {0};
#include "core/settings.h"
#include "core/serialcmds.h"
#include "core/wifi_common.h"
#include "modules/others/led_control.h"
#include "modules/others/audio.h" // for playAudioFile
#include "modules/rf/rf.h" // for initCC1101once
#include "modules/bjs_interpreter/interpreter.h" // for JavaScript interpreter
Expand Down Expand Up @@ -167,7 +168,7 @@ void begin_tft(){
tft.setRotation(bruceConfig.rotation); //sometimes it misses the first command
tft.setRotation(bruceConfig.rotation);
tftWidth = tft.width();
#ifdef HAS_TOUCH
#ifdef HAS_TOUCH
tftHeight = tft.height() - 20;
#else
tftHeight = tft.height();
Expand Down Expand Up @@ -221,7 +222,7 @@ void boot_screen_anim() {
}
drawn=true;
}
#if !defined(LITE_VERSION)
#if !defined(LITE_VERSION)
if(!boot_img && (millis()-i>2200) && (millis()-i)<2700) tft.drawRect(2*tftWidth/3,tftHeight/2,2,2,bruceConfig.priColor);
if(!boot_img && (millis()-i>2700) && (millis()-i)<2900) tft.fillRect(0,45,tftWidth,tftHeight-45,bruceConfig.bgColor);
if(!boot_img && (millis()-i>2900) && (millis()-i)<3400) tft.drawXBitmap(2*tftWidth/3 - 30 ,5+tftHeight/2,bruce_small_bits, bruce_small_width, bruce_small_height,bruceConfig.bgColor,bruceConfig.priColor);
Expand Down Expand Up @@ -258,6 +259,17 @@ void init_clock() {
}


/*********************************************************************
** Function: init_led
** Led initialisation
*********************************************************************/
void init_led() {
#ifdef HAS_RGB_LED
beginLed();
#endif
}


/*********************************************************************
** Function: startup_sound
** Play sound or tone depending on device hardware
Expand Down Expand Up @@ -318,11 +330,12 @@ void setup() {
bruceConfig.fromFile();
begin_tft();
init_clock();
init_led();

// Some GPIO Settings (such as CYD's brightness control must be set after tft and sdcard)
_post_setup_gpio();
// end of post gpio begin

// This task keeps running all the time, will never stop
xTaskCreate(
taskInputHandler, // Task function
Expand All @@ -331,7 +344,7 @@ void setup() {
NULL, // Task parameters
2, // Task priority (0 to 3), loopTask has priority 2.
&xHandle // Task handle (not used)
);
);
boot_screen_anim();

startup_sound();
Expand Down
Loading

0 comments on commit 70630d2

Please sign in to comment.