8000 Led color by emericklaw · Pull Request #1 · emericklaw/Bruce · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Led color #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: dev-matt
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions boards/lilygo-t-embed-cc1101/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,17 @@ void InputHandler(void) {
if (_last_dir > 0) {
_last_dir = 0;
PrevPress = true;
#ifdef HAS_ENCODER_LED
EncoderLedChange = -1;
#endif
tm2 = millis();
}
if (_last_dir < 0) {
_last_dir = 0;
NextPress = true;
#ifdef HAS_ENCODER_LED
EncoderLedChange = 1;
#endif
tm2 = millis();
}

Expand Down
6 changes: 5 additions & 1 deletion boards/lilygo-t-embed-cc1101/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ static const uint8_t RX = SERIAL_RX;
#define LED_ORDER GRB
#define LED_TYPE_IS_RGBW 0
#define LED_COUNT 8
#define LED_COLOR_STEP 5
#define HAS_ENCODER_LED 1

// BadUSB
#define USB_as_HID 1
Expand Down Expand Up @@ -289,13 +291,15 @@ static const uint8_t SCL = GROVE_SCL;
// #define FM_RSTPIN 40

// RGB LED
#define HAS_RGB_LED
#define HAS_RGB_LED 1
#define RGB_LED 42
#define RGB_LED_CLK 45
#define LED_TYPE APA102
#define LED_ORDER BGR
#define LED_TYPE_IS_RGBW 0
#define LED_COUNT 8
#define LED_COLOR_STEP 5
#define HAS_ENCODER_LED 1

// BadUSB
#define USB_as_HID 1
Expand Down
2 changes: 2 additions & 0 deletions boards/m5stack-cardputer/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@ static const uint8_t _kb_asciimap[128] = {
0 // DEL
};

#define HAS_RGB_LED 1
#define LED_TYPE SK6812
#define LED_ORDER GRB
#define LED_TYPE_IS_RGBW 1
#define LED_COUNT 1
#define LED_COLOR_STEP 15

// Deepsleep
#define DEEPSLEEP_WAKEUP_PIN 0
Expand Down
3 changes: 2 additions & 1 deletion boards/smoochiee-board/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ static const uint8_t SCK = 18;
#define LED_TYPE WS2812B
#define LED_ORDER GRB
#define LED_TYPE_IS_RGBW 0
#define LED_COUNT 16
#define LED_COUNT 16
#define LED_COLOR_STEP 15

#define USE_BQ25896

Expand Down
4 changes: 4 additions & 0 deletions include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ extern volatile bool PrevPagePress;

extern volatile bool LongPress;

#ifdef HAS_ENCODER_LED
extern volatile int EncoderLedChange;
#endif

extern volatile int forceMenuOption;

extern volatile uint8_t menuOptionType; // updates when drawing loopoptions, to send to remote controller
Expand Down
74 changes: 69 additions & 5 deletions src/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ JsonDocument BruceConfig::toJson() const {
setting["ledBright"] = ledBright;
setting["ledColor"] = String(ledColor, HEX);
setting["ledBlinkEnabled"] = ledBlinkEnabled;
setting["ledEffect"] = ledEffect;
setting["ledEffectSpeed"] = ledEffectSpeed;
setting["ledEffectDirection"] = ledEffectDirection;

JsonObject _webUI = setting["webUI"].to<JsonObject>();
_webUI["user"] = webUI.user;
Expand Down Expand Up @@ -78,11 +81,16 @@ JsonDocument BruceConfig::toJson() const {
return jsonDoc;
}

void BruceConfig::fromFile() {
void BruceConfig::fromFile(bool checkFS) {
FS *fs;
if (!getFsStorage(fs)) {
log_i("Fail getting filesystem for config");
return;
if (checkFS) {
if (!getFsStorage(fs)) {
log_i("Fail getting filesystem for config");
return;
}
} else {
if (checkLittleFsSize()) fs = &LittleFS;
else return;
}

if (!fs->exists(filepath)) {
Expand Down Expand Up @@ -207,6 +215,24 @@ void BruceConfig::fromFile() {
count++;
log_e("Fail");
}
if (!setting["ledEffect"].isNull()) {
ledEffect = setting["ledEffect"].as<int>();
} else {
count++;
log_e("Fail");
}
if (!setting["ledEffectSpeed"].isNull()) {
ledEffectSpeed = setting["ledEffectSpeed"].as<int>();
} else {
count++;
log_e("Fail");
}
if (!setting["ledEffectDirection"].isNull()) {
ledEffectDirection = setting["ledEffectDirection"].as<int>();
} else {
count++;
log_e("Fail");
}

if (!setting["webUI"].isNull()) {
JsonObject webUIObj = setting["webUI"].as<JsonObject>();
Expand Down Expand Up @@ -422,7 +448,6 @@ void BruceConfig::factoryReset() {
}

void BruceConfig::validateConfig() {
validateUiColor();
validateRotationValue();
validateDimmerValue();
validateBrightValue();
Expand All @@ -433,6 +458,9 @@ void BruceConfig::validateConfig() {
validateLedBrightValue();
validateLedColorValue();
validateLedBlinkEnabledValue();
validateLedEffectValue();
validateLedEffectSpeedValue();
validateLedEffectDirectionValue();
validateRfScanRangeValue();
validateRfModuleValue();
validateRfidModuleValue();
Expand Down Expand Up @@ -546,6 +574,42 @@ void BruceConfig::validateLedBlinkEnabledValue() {
if (ledBlinkEnabled > 1) ledBlinkEnabled = 1;
}

void BruceConfig::setLedEffect(int value) {
ledEffect = value;
validateLedEffectValue();
saveFile();
}

void BruceConfig::validateLedEffectValue() {
if (ledEffect < 0 || ledEffect > 5) ledEffect = 0;
}

void BruceConfig::setLedEffectSpeed(int value) {
ledEffectSpeed = value;
validateLedEffectSpeedValue();
saveFile();
}

void BruceConfig::validateLedEffectSpeedValue() {
#ifdef HAS_ENCODER_LED
if (ledEffectSpeed > 11) ledEffectSpeed = 11;
#else
if (ledEffectSpeed > 10) ledEffectSpeed = 10;
#endif
if (ledEffectSpeed < 0) ledEffectSpeed = 1;
}

void BruceConfig::setLedEffectDirection(int value) {
ledEffectDirection = value;
validateLedEffectDirectionValue();
saveFile();
}

void BruceConfig::validateLedEffectDirectionValue() {
if (ledEffectDirection > 1 || ledEffectDirection == 0) ledEffectDirection = 1;
if (ledEffectDirection < -1) ledEffectDirection = -1;
}

void BruceConfig::setWebUICreds(const String &usr, const String &pwd) {
webUI.user = usr;
webUI.pwd = pwd;
Expand Down
11 changes: 10 additions & 1 deletion src/core/config.h
< 10000 /tr>
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class BruceConfig : public BruceTheme {
int ledBright = 75;
uint32_t ledColor = 0;
int ledBlinkEnabled = 1;
int ledEffect = 0;
int ledEffectSpeed = 5;
int ledEffectDirection = 1;

// Wifi
Credential webUI = {"admin", "bruce"};
Expand Down Expand Up @@ -109,7 +112,7 @@ class BruceConfig : public BruceTheme {
// Operations
/////////////////////////////////////////////////////////////////////////////////////
void saveFile();
void fromFile();
void fromFile(bool checkFS = true);
void factoryReset();
void validateConfig();
JsonDocument toJson() const;
Expand Down Expand Up @@ -140,6 +143,12 @@ class BruceConfig : public BruceTheme {
void validateLedColorValue();
void setLedBlinkEnabled(int value);
void validateLedBlinkEnabledValue();
void setLedEffect(int value);
void validateLedEffectValue();
void setLedEffectSpeed(int value);
void validateLedEffectSpeedValue();
void setLedEffectDirection(int value);
void validateLedEffectDirectionValue();

// Wifi
void setWebUICreds(const String &usr, const String &pwd);
Expand Down
13 changes: 9 additions & 4 deletions src/core/configPins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ void BruceConfigPins::toJson(JsonObject obj) const {
#endif
}

void BruceConfigPins::loadFile(JsonDocument &jsonDoc) {
void BruceConfigPins::loadFile(JsonDocument &jsonDoc, bool checkFS) {
FS *fs;
if (!getFsStorage(fs)) return;
if (checkFS) {
if (!getFsStorage(fs)) return;
} else {
if (checkLittleFsSize()) fs = &LittleFS;
else return;
}

if (!fs->exists(filepath)) return createFile();

Expand All @@ -90,9 +95,9 @@ void BruceConfigPins::loadFile(JsonDocument &jsonDoc) {
serializeJsonPretty(jsonDoc, Serial);
}

void BruceConfigPins::fromFile() {
void BruceConfigPins::fromFile(bool checkFS) {
JsonDocument jsonDoc;
loadFile(jsonDoc);
loadFile(jsonDoc, checkFS);

if (!jsonDoc.isNull()) fromJson(jsonDoc.as<JsonObject>());
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/configPins.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class BruceConfigPins {
/////////////////////////////////////////////////////////////////////////////////////
void createFile();
void saveFile();
void fromFile();
void loadFile(JsonDocument &jsonDoc);
void fromFile(bool checkFS = true);
void loadFile(JsonDocument &jsonDoc, bool checkFS = true);
void factoryReset();
void validateConfig();
void fromJson(JsonObject obj);
Expand Down
30 changes: 22 additions & 8 deletions src/core/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,14 @@ int loopOptions(
if (!renderedByLambda) {
if (menuType == MENU_TYPE_SUBMENU) drawSubmenu(index, options, subText);
else
coord =
drawOptions(index, options, bruceConfig.priColor, bruceConfig.bgColor, firstRender);
coord = drawOptions(
index,
options,
bruceConfig.priColor,
bruceConfig.secColor,
bruceConfig.bgColor,
firstRender
);
}
firstRender = false;
redraw = false;
Expand Down Expand Up @@ -518,6 +524,7 @@ int loopOptions(
LongPress = false;
#endif
if (millis() - _tmp > 700) { // longpress detected to exit
index = -1;
break;
} else {
check(PrevPress);
Expand Down Expand Up @@ -554,7 +561,10 @@ int loopOptions(
if (interpreter_start && !interpreter) { break; }

#ifdef HAS_KEYBOARD
if (check(EscPress)) break;
if (check(EscPress)) {
index = -1;
break;
}
int pressed_number = checkNumberShortcutPress();
if (pressed_number >= 0) {
if (index == pressed_number) {
Expand All @@ -568,7 +578,10 @@ int loopOptions(
redraw = true;
}
#elif defined(T_EMBED) || defined(HAS_TOUCH)
if (menuType != MENU_TYPE_MAIN && check(EscPress)) break;
if (menuType != MENU_TYPE_MAIN && check(EscPress)) {
index = -1;
break;
}
#endif
}
return index;
Expand All @@ -593,8 +606,10 @@ void progressHandler(int progress, size_t total, String message) {
** Function name: drawOptions
** Description: Função para desenhar e mostrar as opçoes de contexto
***************************************************************************************/
Opt_Coord
drawOptions(int index, std::vector<Option> &options, uint16_t fgcolor, uint16_t bgcolor, bool firstRender) {
Opt_Coord drawOptions(
int index, std::vector<Option> &options, uint16_t fgcolor, uint16_t selcolor, uint16_t bgcolor,
bool firstRender
) {
Opt_Coord coord;
int menuSize = options.size();
if (options.size() > MAX_MENU_SIZE) { menuSize = MAX_MENU_SIZE; }
Expand Down Expand Up @@ -628,8 +643,7 @@ drawOptions(int index, std::vector<Option> &options, uint16_t fgcolor, uint16_t
if (index >= MAX_MENU_SIZE) init = index - MAX_MENU_SIZE + 1;
for (i = 0; i < menuSize; i++) {
if (i >= init) {
if (options[i].selected)
tft.setTextColor(getColorVariation(fgcolor), bgcolor); // if selected, change Text color
if (options[i].selected) tft.setTextColor(selcolor, bgcolor); // if selected, change Text color
else tft.setTextColor(fgcolor, bgcolor);

String text = "";
Expand Down
2 changes: 1 addition & 1 deletion src/core/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ inline int loopOptions(std::vector<Option> &options) {
}

Opt_Coord drawOptions(
int index, std::vector<Option> &options, uint16_t fgcolor, uint16_t bgcolor, bool firstRender = true
int index, std::vector<Option> &options, uint16_t fgcolor, uint16_t selcolor, uint16_t bgcolor, bool firstRender = true
);

void drawSubmenu(int index, std::vector<Option> &options, const char *title);
Expand Down
Loading
0