Skip to content

Commit

Permalink
Finish implementing keyboard light commands
Browse files Browse the repository at this point in the history
Again, this is hacked together and will have proper checks added soon
  • Loading branch information
Sparronator9999 committed Sep 7, 2024
1 parent 9199d1d commit 6db5a46
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 41 deletions.
80 changes: 41 additions & 39 deletions YAMDCC.GUI/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions YAMDCC.GUI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ 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 @@ -231,6 +234,17 @@ private void IPC_MessageReceived(object sender, PipeMessageEventArgs<ServiceResp
UpdateFanMon(value, 2);
}
break;
case Response.KeyLightBright:
if (int.TryParse(args[0], out value))
{
tbKeyLight.Invoke(new Action(delegate
{
tbKeyLight.Maximum = Config.KeyLightConf.MaxVal - Config.KeyLightConf.MinVal;
tbKeyLight.Value = value;
tbKeyLight.Enabled = true;
}));
}
break;
}
}
}
Expand Down Expand Up @@ -544,6 +558,12 @@ private void chkWinFnSwap_CheckedChanged(object sender, EventArgs e)
Config.KeySwapConf.Enabled = chkWinFnSwap.Checked;
}

private void tbKeyLight_Scroll(object sender, EventArgs e)
{
ServiceCommand command = new(Command.SetKeyLightBright, $"{tbKeyLight.Value}");
IPCClient.PushMessage(command);
}

private void btnRevert_Click(object sender, EventArgs e)
{

Expand Down
33 changes: 31 additions & 2 deletions YAMDCC.Service/svcFanControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ private void IPCClientMessage(object sender, PipeMessageEventArgs<ServiceCommand
case Command.GetKeyLightBright:
error = GetKeyLightBright(e.Connection.Name);
break;
case Command.SetKeyLightBright:
error = SetKeyLightBright(e.Connection.Name, e.Message.Arguments);
break;
default: // Unknown command
Log.Error(Strings.GetString("errBadCmd"), e.Message);
break;
Expand Down Expand Up @@ -607,17 +610,43 @@ private int SetFullBlast(string name, string args)

private int GetKeyLightBright(string name)
{
Log.Debug("Getting keyboard backlight brightness...");
if (EC.AcquireLock(500))
{
int offset = Config.KeyLightConf.MaxVal - Config.KeyLightConf.MinVal;
int offset = Config.KeyLightConf.MinVal;
if (_EC.ReadByte(Config.KeyLightConf.Reg, out byte brightness))
{
Log.Debug($"Keyboard backlight brightness is {brightness}");
ServiceResponse response = new(Response.KeyLightBright, $"{brightness - offset}");
IPCServer.PushMessage(response, name);
}
else
{
LogECReadError(Config.KeyLightConf.Reg);
}
EC.ReleaseLock();
return 0;
}
return 0;
return 3;
}

private int SetKeyLightBright(string name, string args)
{
if (ParseArgs(args, 1, out int[] pArgs))
{
Log.Debug($"Setting keyboard backlight brightness to {pArgs[0]}...");
if (EC.AcquireLock(500))
{
if (!_EC.WriteByte(Config.KeyLightConf.Reg, (byte)(pArgs[0] + Config.KeyLightConf.MinVal)))
{
LogECWriteError(Config.KeyLightConf.Reg);
}
EC.ReleaseLock();
return 0;
}
return 3;
}
return 2;
}

private static void LogUnhandledException(object sender, UnhandledExceptionEventArgs e)
Expand Down

0 comments on commit 6db5a46

Please sign in to comment.