Skip to content
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

111, 112 Backlight handling improve #113

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 18 additions & 5 deletions lib/M5ez/src/M5ez.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ void ezSettings::defaults() {
uint8_t ezBacklight::_brightness;
uint8_t ezBacklight::_inactivity;
uint32_t ezBacklight::_last_activity;
uint8_t ezBacklight::_MinimumBrightness;
bool ezBacklight::_backlight_off = false;

void ezBacklight::begin() {
Expand All @@ -801,7 +802,19 @@ void ezBacklight::begin() {
Preferences prefs;
prefs.begin("M5ez", true); // read-only
_brightness = prefs.getUChar("brightness", 128);
if (_brightness < 48) {
switch (M5.getBoard()) {
case m5::board_t::board_M5StickCPlus2:
case m5::board_t::board_M5StackCore2:
_MinimumBrightness = 16;
break;
case m5::board_t::board_M5StickCPlus:
case m5::board_t::board_M5StickC:
_MinimumBrightness = 48;
break;
default:
_MinimumBrightness = 64;
}
if (_brightness < _MinimumBrightness) {
_brightness = 100;
}
_inactivity = prefs.getUChar("inactivity", 1);
Expand All @@ -826,10 +839,10 @@ void ezBacklight::menu() {
while (true) {
String b = ez.buttons.poll();
if (b == "Adjust") {
if (_brightness >= 48 && _brightness < 248)
_brightness += 20;
if (_brightness >= _MinimumBrightness && _brightness < (255 - _MinimumBrightness))
_brightness += (255 - _MinimumBrightness) / 8;
else
_brightness = 48;
_brightness = _MinimumBrightness + (255 - _MinimumBrightness) / 8;
}
float p = float(_brightness) / 2.48;
hijae marked this conversation as resolved.
Show resolved Hide resolved
bl.value(p);
Expand Down Expand Up @@ -907,7 +920,7 @@ uint16_t ezBacklight::loop(void *private_data) {
if (!_backlight_off && _inactivity) {
if (millis() > _last_activity + 30000 * _inactivity) {
_backlight_off = true;
M5.Display.setBrightness(64);
M5.Display.setBrightness(_MinimumBrightness);
changeCpuPower(true);
while (true) {
if (M5.BtnA.wasClicked() || M5.BtnB.wasClicked())
Expand Down
1 change: 1 addition & 0 deletions lib/M5ez/src/M5ez.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ class ezBacklight {
static uint8_t _brightness;
static uint8_t _inactivity;
static uint32_t _last_activity;
static uint8_t _MinimumBrightness;
static bool _backlight_off;
//
};
Expand Down