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 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
35 changes: 28 additions & 7 deletions lib/M5ez/src/M5ez.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,9 @@ void ezSettings::defaults() {
uint8_t ezBacklight::_brightness;
uint8_t ezBacklight::_inactivity;
uint32_t ezBacklight::_last_activity;
uint8_t ezBacklight::_MinimumBrightness;
uint8_t ezBacklight::_Step = 0;
uint8_t ezBacklight::_MaxSteps = 8;
bool ezBacklight::_backlight_off = false;

void ezBacklight::begin() {
Expand All @@ -801,7 +804,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 @@ -819,19 +834,25 @@ void ezBacklight::menu() {
blmenu.addItem("Inactivity timeout");
blmenu.addItem("Back");
blmenu.downOnLast("first");
_Step = (_brightness - _MinimumBrightness) * _MaxSteps
/ (256 - _MinimumBrightness); // Calculate step from brightness
while (true) {
switch (blmenu.runOnce()) {
case 1: {
ezProgressBar bl("Backlight brightness", "Set brightness", "Adjust#Back");
while (true) {
String b = ez.buttons.poll();
if (b == "Adjust") {
if (_brightness >= 48 && _brightness < 248)
_brightness += 20;
else
_brightness = 48;
if (_brightness >= _MinimumBrightness && _Step < _MaxSteps - 1) {
_Step++;
_brightness =
_MinimumBrightness + (_Step * (255 - _MinimumBrightness) / (_MaxSteps - 1));
} else {
_Step = 0;
_brightness = _MinimumBrightness;
}
}
float p = float(_brightness) / 2.48;
float p = ((float)_Step / (_MaxSteps - 1)) * 100.0f;
bl.value(p);
M5.Display.setBrightness(_brightness);
if (b == "Back")
Expand Down Expand Up @@ -907,7 +928,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
3 changes: 3 additions & 0 deletions lib/M5ez/src/M5ez.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ class ezBacklight {
static uint8_t _brightness;
static uint8_t _inactivity;
static uint32_t _last_activity;
static uint8_t _MinimumBrightness;
static uint8_t _Step;
static uint8_t _MaxSteps;
static bool _backlight_off;
//
};
Expand Down