Skip to content

Commit

Permalink
Bugfix time!
Browse files Browse the repository at this point in the history
- Fix a service hang caused by missing keyboard backlight config

- Configurator: Only request keyboard backlight if present in the loaded config
  • Loading branch information
Sparronator9999 committed Sep 7, 2024
1 parent 0862779 commit 3a8e4a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 6 additions & 3 deletions YAMDCC.GUI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ private void MainWindow_Load(object sender, EventArgs e)
}

LoadConf(Path.Combine(DataPath, "CurrentConfig.xml"));

ServiceCommand command = new ServiceCommand(Command.GetKeyLightBright, "");
IPCClient.PushMessage(command);
}

private void MainWindow_Closing(object sender, FormClosingEventArgs e)
Expand Down Expand Up @@ -679,6 +676,12 @@ private void LoadConf(string configPath)
chkWinFnSwap.Enabled = lblWinFnSwap.Enabled = true;
}

if (Config.KeyLightConf is not null)
{
ServiceCommand command = new(Command.GetKeyLightBright, "");
IPCClient.PushMessage(command);
}

cboFanSel.Items.Clear();
for (int i = 0; i < Config.FanConfs.Length; i++)
{
Expand Down
16 changes: 13 additions & 3 deletions YAMDCC.Service/svcFanControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,19 @@ private int SetFullBlast(string name, string args)

private int GetKeyLightBright(string name)
{
if (Config.KeyLightConf is null)
{
return 0;
}

Log.Debug("Getting keyboard backlight brightness...");
if (EC.AcquireLock(500))
{
int offset = Config.KeyLightConf.MinVal;
if (_EC.ReadByte(Config.KeyLightConf.Reg, out byte brightness))
if (_EC.ReadByte(Config.KeyLightConf.Reg, out byte value))
{
int brightness = value - Config.KeyLightConf.MinVal;
Log.Debug($"Keyboard backlight brightness is {brightness}");
ServiceResponse response = new(Response.KeyLightBright, $"{brightness - offset}");
ServiceResponse response = new(Response.KeyLightBright, $"{brightness}");
IPCServer.PushMessage(response, name);
}
else
Expand All @@ -629,6 +634,11 @@ private int GetKeyLightBright(string name)

private int SetKeyLightBright(string name, string args)
{
if (Config.KeyLightConf is null)
{
return 0;
}

if (ParseArgs(args, 1, out int[] pArgs))
{
Log.Debug($"Setting keyboard backlight brightness to {pArgs[0]}...");
Expand Down

0 comments on commit 3a8e4a8

Please sign in to comment.