Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions sd_files/themes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Themes are supposed to change the UI experience of the User by allowing you to c
* If displaying the Labels on the Main Menu
* Setting the Primary Font color
* Setting the Secondary Font Color (Non selected submenu item)
* Setting the Background Color.
* Setting the Background Color
* Setting the LED color and effects

## Images
Bruce accepts **.bmp** **.jpg** **.gif** and **.png** (not available on LITE_VERSION) to be used in the Main menu, but the bigger they are, greater will be the time to draw them on screen, **please, try to keep them small**.
Expand Down Expand Up @@ -43,15 +44,21 @@ Theme settings are stored in a **.json** file, following this structure:
"border":0,
"label":0,
"boot_img":"boot.gif",
"boot_sound":"boot.wav"
"boot_sound":"boot.wav",
"ledBright": 100,
"ledColor": "960064",
"ledEffect": 0,
"ledEffectSpeed": 3,
"ledEffectDirection": 1
}
```
* Colors: Codes are in **RGB565**, 16bit pattern, so you need to convert it using [this tool](https://rgbcolorpicker.com/565).
* Colors (excluding LED): Codes are in **RGB565**, 16bit pattern, so you need to convert it using [this tool](https://rgbcolorpicker.com/565).
* LED Colors: Codes are in HEX.
* border: 0 or 1, 1 to keep UI Borders
* label: 0 or 1, 1 to use UI Labels (Use 50px smaller images in this case)

## Theme creator
You can use **Theme_Builder.html** to setup and prepare your images and .json file, it will give you a .zip file that you **need to unzip** somewhere in your device, LittleFS or SD Card.
You can use [Bruce Theme Builder](https://bruce.computer/build_theme.html) to setup and prepare your images, settings and .json file, it will give you a .zip file that you **need to unzip** somewhere in your device, LittleFS or SD Card.

## Setting a Theme
Config > UI Theme > (Choose FS) > select the .json file and the theme will be set.
Expand Down
8 changes: 8 additions & 0 deletions src/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ JsonDocument BruceConfig::toJson() const {
setting["wifiAtStartup"] = wifiAtStartup;
setting["instantBoot"] = instantBoot;

#ifdef HAS_RGB_LED
setting["ledBright"] = ledBright;
setting["ledColor"] = String(ledColor, HEX);
setting["ledBlinkEnabled"] = ledBlinkEnabled;
setting["ledEffect"] = ledEffect;
setting["ledEffectSpeed"] = ledEffectSpeed;
setting["ledEffectDirection"] = ledEffectDirection;
#endif

JsonObject _webUI = setting["webUI"].to<JsonObject>();
_webUI["user"] = webUI.user;
Expand Down Expand Up @@ -207,6 +209,7 @@ void BruceConfig::fromFile(bool checkFS) {
log_e("Fail");
}

#ifdef HAS_RGB_LED
if (!setting["ledBright"].isNull()) {
ledBright = setting["ledBright"].as<int>();
} else {
Expand Down Expand Up @@ -243,6 +246,7 @@ void BruceConfig::fromFile(bool checkFS) {
count++;
log_e("Fail");
}
#endif

if (!setting["webUI"].isNull()) {
JsonObject webUIObj = setting["webUI"].as<JsonObject>();
Expand Down Expand Up @@ -499,12 +503,14 @@ void BruceConfig::validateConfig() {
validateSoundEnabledValue();
validateSoundVolumeValue();
validateWifiAtStartupValue();
#ifdef HAS_RGB_LED
validateLedBrightValue();
validateLedColorValue();
validateLedBlinkEnabledValue();
validateLedEffectValue();
validateLedEffectSpeedValue();
validateLedEffectDirectionValue();
#endif
validateRfScanRangeValue();
validateRfModuleValue();
validateRfidModuleValue();
Expand Down Expand Up @@ -593,6 +599,7 @@ void BruceConfig::validateWifiAtStartupValue() {
if (wifiAtStartup > 1) wifiAtStartup = 1;
}

#ifdef HAS_RGB_LED
void BruceConfig::setLedBright(int value) {
ledBright = value;
validateLedBrightValue();
Expand Down Expand Up @@ -656,6 +663,7 @@ void BruceConfig::validateLedEffectDirectionValue() {
if (ledEffectDirection > 1 || ledEffectDirection == 0) ledEffectDirection = 1;
if (ledEffectDirection < -1) ledEffectDirection = -1;
}
#endif

void BruceConfig::setWebUICreds(const String &usr, const String &pwd) {
webUI.user = usr;
Expand Down
8 changes: 6 additions & 2 deletions src/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ class BruceConfig : public BruceTheme {
int wifiAtStartup = 0;
int instantBoot = 0;

#ifdef HAS_RGB_LED
// Led
int ledBright = 75;
uint32_t ledColor = 0;
int ledBright = 50;
uint32_t ledColor = 0x960064;
int ledBlinkEnabled = 1;
int ledEffect = 0;
int ledEffectSpeed = 5;
int ledEffectDirection = 1;
#endif

// Wifi
Credential webUI = {"admin", "bruce"};
Expand Down Expand Up @@ -157,6 +159,7 @@ class BruceConfig : public BruceTheme {
void setWifiAtStartup(int value);
void validateWifiAtStartupValue();

#ifdef HAS_RGB_LED
// Led
void setLedBright(int value);
void validateLedBrightValue();
Expand All @@ -170,6 +173,7 @@ class BruceConfig : public BruceTheme {
void validateLedEffectSpeedValue();
void setLedEffectDirection(int value);
void validateLedEffectDirectionValue();
#endif

// Wifi
void setWebUICreds(const String &usr, const String &pwd);
Expand Down
13 changes: 12 additions & 1 deletion src/core/settings.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "settings.h"
#include "core/led_control.h"
#include "core/wifi/wifi_common.h"
#include "display.h"
#include "modules/ble_api/ble_api.hpp"
Expand Down Expand Up @@ -444,6 +445,7 @@ void setSoundVolume() {
loopOptions(options, bruceConfig.soundVolume);
}

#ifdef HAS_RGB_LED
/*********************************************************************
** Function: setLedBlinkConfig
** Enable or disable led blink
Expand All @@ -455,6 +457,7 @@ void setLedBlinkConfig() {
};
loopOptions(options, bruceConfig.ledBlinkEnabled);
}
#endif

/*********************************************************************
** Function: setWifiStartupConfig
Expand Down Expand Up @@ -1351,6 +1354,14 @@ void setTheme() {
bruceConfig.secColor = DEFAULT_SECCOLOR;
bruceConfig.bgColor = TFT_BLACK;
bruceConfig.setUiColor(DEFAULT_PRICOLOR);
#ifdef HAS_RGB_LED
bruceConfig.ledBright = 50;
bruceConfig.ledColor = 0x960064;
bruceConfig.ledEffect = 0;
bruceConfig.ledEffectSpeed = 5;
bruceConfig.ledEffectDirection = 1;
ledSetup();
#endif
bruceConfig.saveFile();
fs = nullptr;
} },
Expand All @@ -1363,7 +1374,7 @@ void setTheme() {
if (fs == nullptr) return;

String filepath = loopSD(*fs, true, "JSON");
if (bruceConfig.openThemeFile(fs, filepath)) {
if (bruceConfig.openThemeFile(fs, filepath, true)) {
bruceConfig.themePath = filepath;
if (fs == &LittleFS) bruceConfig.theme.fs = 1;
else if (fs == &SD) bruceConfig.theme.fs = 2;
Expand Down
2 changes: 2 additions & 0 deletions src/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ void setSoundConfig();

void setSoundVolume();

#ifdef HAS_RGB_LED
void setLedBlinkConfig();
#endif

void setWifiStartupConfig();

Expand Down
33 changes: 24 additions & 9 deletions src/core/theme.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "theme.h"
#include "core/led_control.h"
#include "display.h"

struct ThemeEntry {
Expand All @@ -16,7 +17,7 @@ FS *BruceTheme::themeFS(void) {
else if (theme.fs == 2) return &SD;
return &LittleFS; // always get back to safety
}
bool BruceTheme::openThemeFile(FS *fs, String filepath) {
bool BruceTheme::openThemeFile(FS *fs, String filepath, bool overwriteConfigSettings) {

if (fs == nullptr) return true;
if (!fs->exists(filepath)) return false;
Expand Down Expand Up @@ -72,18 +73,32 @@ bool BruceTheme::openThemeFile(FS *fs, String filepath) {
}
}

uint16_t _priColor = bruceConfig.priColor;
uint16_t _secColor = bruceConfig.secColor;
uint16_t _bgColor = bruceConfig.bgColor;
file.close();

if (!_th["priColor"].isNull()) { _priColor = strtoul(_th["priColor"], nullptr, 16); }
if (!_th["secColor"].isNull()) { _secColor = strtoul(_th["secColor"], nullptr, 16); }
if (!_th["bgColor"].isNull()) { _bgColor = strtoul(_th["bgColor"], nullptr, 16); }
if (!_th["border"].isNull()) { theme.border = _th["border"].as<int>(); }
if (!_th["label"].isNull()) { theme.label = _th["label"].as<int>(); }

file.close();
_setUiColor(_priColor, &_secColor, &_bgColor);
if (overwriteConfigSettings) {
uint16_t _priColor = bruceConfig.priColor;
uint16_t _secColor = bruceConfig.secColor;
uint16_t _bgColor = bruceConfig.bgColor;

if (!_th["priColor"].isNull()) { _priColor = strtoul(_th["priColor"], nullptr, 16); }
if (!_th["secColor"].isNull()) { _secColor = strtoul(_th["secColor"], nullptr, 16); }
if (!_th["bgColor"].isNull()) { _bgColor = strtoul(_th["bgColor"], nullptr, 16); }
_setUiColor(_priColor, &_secColor, &_bgColor);

#ifdef HAS_RGB_LED
if (!_th["ledBright"].isNull()) { bruceConfig.ledBright = _th["ledBright"].as<int>(); }
if (!_th["ledColor"].isNull()) { bruceConfig.ledColor = strtoul(_th["ledColor"], nullptr, 16); }
if (!_th["ledEffect"].isNull()) { bruceConfig.ledEffect = _th["ledEffect"].as<int>(); }
if (!_th["ledEffectSpeed"].isNull()) { bruceConfig.ledEffectSpeed = _th["ledEffectSpeed"].as<int>(); }
if (!_th["ledEffectDirection"].isNull()) {
bruceConfig.ledBright = _th["ledEffectDirection"].as<int>();
}
ledSetup();
#endif
}

if (fs == &LittleFS) theme.fs = 1;
else if (fs == &SD) theme.fs = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/core/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class BruceTheme {
// UI Color
void _setUiColor(uint16_t primary, uint16_t *secondary = nullptr, uint16_t *background = nullptr);

bool openThemeFile(FS *fs, String filepath);
bool openThemeFile(FS *fs, String filepath, bool overwriteConfigSettings);
bool validateImgFile(FS *fs, String filepath);
String getThemeItemImg(String item) {
return themePath.substring(0, themePath.lastIndexOf('/')) + "/" + item;
Expand Down
Loading