diff --git a/lib/M5ez/src/M5ez.cpp b/lib/M5ez/src/M5ez.cpp index 0562f8f..3a99734 100644 --- a/lib/M5ez/src/M5ez.cpp +++ b/lib/M5ez/src/M5ez.cpp @@ -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() { @@ -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); @@ -819,6 +834,8 @@ 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: { @@ -826,12 +843,16 @@ void ezBacklight::menu() { 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") @@ -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()) diff --git a/lib/M5ez/src/M5ez.h b/lib/M5ez/src/M5ez.h index f447c04..56e86b5 100644 --- a/lib/M5ez/src/M5ez.h +++ b/lib/M5ez/src/M5ez.h @@ -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; // };