Skip to content

Commit

Permalink
Option to save flicker-free dimming per AC/DC state #3112
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed Sep 16, 2024
1 parent d0f0bd9 commit e71d283
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions app/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -691,4 +691,9 @@ public static bool IsForceMiniled()
return ContainsModel("G834JYR") || Is("force_miniled");
}

public static bool SaveDimming()
{
return Is("save_dimming");
}

}
24 changes: 21 additions & 3 deletions app/Display/VisualControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,32 @@ private static void BrightnessTimerTimer_Elapsed(object? sender, System.Timers.E
SetGamma(_brightness);
}

public static void InitBrightness()
{
if (!AppConfig.IsOLED()) return;
if (!AppConfig.SaveDimming()) return;

int brightness = GetBrightness();
if (brightness >= 0) SetBrightness(brightness);
}

private static bool IsOnBattery()
{
return AppConfig.SaveDimming() && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online;
}

public static int GetBrightness()
{
return AppConfig.Get(IsOnBattery() ? "brightness_battery" : "brightness", 100);
}

public static int SetBrightness(int brightness = -1, int delta = 0)
{
if (!AppConfig.IsOLED()) return -1;

if (brightness < 0) brightness = AppConfig.Get("brightness", 100);
if (brightness < 0) GetBrightness();

_brightness = Math.Max(0, Math.Min(100, brightness + delta));
AppConfig.Set("brightness", _brightness);
AppConfig.Set(IsOnBattery() ? "brightness_battery" : "brightness", _brightness);

brightnessTimer.Start();

Expand Down
2 changes: 2 additions & 0 deletions app/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ public static bool SetAutoModes(bool powerChanged = false, bool init = false)
settingsForm.AutoKeyboard();
}

VisualControl.InitBrightness();

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion app/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public void VisualiseBrightness()
Invoke(delegate
{
sliderGammaIgnore = true;
sliderGamma.Value = AppConfig.Get("brightness", 100);
sliderGamma.Value = VisualControl.GetBrightness();
labelGamma.Text = sliderGamma.Value + "%";
sliderGammaIgnore = false;
});
Expand Down

0 comments on commit e71d283

Please sign in to comment.