Skip to content

Commit

Permalink
use a step counter in the loop
Browse files Browse the repository at this point in the history
  • Loading branch information
hijae committed Aug 13, 2024
1 parent 6314033 commit 1faf893
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/M5ez/src/M5ez.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,8 @@ 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 Down Expand Up @@ -832,19 +834,26 @@ 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 >= _MinimumBrightness && _brightness < (255 - _MinimumBrightness))
_brightness += (255 - _MinimumBrightness) / 7;
if (_brightness >= _MinimumBrightness && _Step < _MaxSteps - 1)
{
_Step++;
_brightness = _MinimumBrightness + (_Step * (255 - _MinimumBrightness) / (_MaxSteps - 1));
}
else
{
_Step = 0;
_brightness = _MinimumBrightness;
}
}
float p = float(_brightness - _MinimumBrightness) / (255 - _MinimumBrightness) * 100;
float p = ((float)_Step / (_MaxSteps - 1)) * 100.0f;
bl.value(p);
M5.Display.setBrightness(_brightness);
if (b == "Back")
Expand Down
2 changes: 2 additions & 0 deletions lib/M5ez/src/M5ez.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ class ezBacklight {
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

0 comments on commit 1faf893

Please sign in to comment.