Skip to content

Commit

Permalink
add nvidia/amd presets to steps in LG controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Maassoft committed Jul 4, 2021
1 parent fa63d8d commit 90ca095
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 22 deletions.
4 changes: 2 additions & 2 deletions ColorControl/AmdService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class AmdService : GraphicsService<AmdPreset>

private ADLDisplayInfo _currentDisplay;

private AmdPreset _lastAppliedPreset;

public AmdService(string dataPath) : base(dataPath)
{
LoadPresets();
Expand Down Expand Up @@ -191,6 +189,8 @@ public bool ApplyPreset(AmdPreset preset, AppContext appContext)

_lastAppliedPreset = preset;

PresetApplied();

return result;
}

Expand Down
2 changes: 1 addition & 1 deletion ColorControl/ColorControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<ProductName>ColorControl</ProductName>
<PublisherName>Maassoft</PublisherName>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>3.2.2.0</ApplicationVersion>
<ApplicationVersion>3.3.0.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down
45 changes: 37 additions & 8 deletions ColorControl/LgDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class InvokableAction
public Type EnumType { get; set; }
public decimal MinValue { get; set; }
public decimal MaxValue { get; set; }
public string Category { get; set; }
}

public enum PowerState
Expand All @@ -37,6 +38,7 @@ public enum PowerOffSource
}

protected static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
public static Func<string, string[], bool> ExternalServiceHandler;

public string Name { get; private set; }
public string IpAddress { get; private set; }
Expand All @@ -61,8 +63,10 @@ public enum PowerOffSource
[JsonIgnore]
public PowerOffSource PoweredOffBy { get; private set; }

[JsonIgnore]
public bool PoweredOffViaApp { get; private set; }

[JsonIgnore]
private DateTimeOffset _poweredOffViaAppDateTime { get; set; }
[JsonIgnore]
private List<InvokableAction> _invokableActions = new List<InvokableAction>();

Expand Down Expand Up @@ -91,6 +95,15 @@ public LgDevice(string name, string ipAddress, string macAddress, bool isCustom
AddGenericPictureAction("energySaving", typeof(EnergySaving));
//AddGenericPictureAction("truMotionMode", typeof(TruMotionMode));
AddGenericPictureAction("motionProOLED", typeof(OffToHigh));
AddGenericPictureAction("uhdDeepColorHDMI1", typeof(OffToOn), category: "other");
AddGenericPictureAction("uhdDeepColorHDMI2", typeof(OffToOn), category: "other");
AddGenericPictureAction("uhdDeepColorHDMI3", typeof(OffToOn), category: "other");
AddGenericPictureAction("uhdDeepColorHDMI4", typeof(OffToOn), category: "other");
//AddGenericPictureAction("hdmiPcMode", typeof(OffToOn), category: "other");
AddGenericPictureAction("gameOptimizationHDMI1", typeof(OffToOn), category: "other");
AddGenericPictureAction("gameOptimizationHDMI2", typeof(OffToOn), category: "other");
AddGenericPictureAction("gameOptimizationHDMI3", typeof(OffToOn), category: "other");
AddGenericPictureAction("gameOptimizationHDMI4", typeof(OffToOn), category: "other");
}

private void AddInvokableAction(string name, Func<Dictionary<string, string>, bool> function)
Expand All @@ -104,15 +117,16 @@ private void AddInvokableAction(string name, Func<Dictionary<string, string>, bo
_invokableActions.Add(action);
}

private void AddGenericPictureAction(string name, Type type = null, decimal minValue = 0, decimal maxValue = 0)
private void AddGenericPictureAction(string name, Type type = null, decimal minValue = 0, decimal maxValue = 0, string category = "picture")
{
var action = new InvokableAction
{
Name = name,
Function = new Func<Dictionary<string, string>, bool>(GenericPictureAction),
EnumType = type,
MinValue = minValue,
MaxValue = maxValue
MaxValue = maxValue,
Category = category
};

_invokableActions.Add(action);
Expand Down Expand Up @@ -165,7 +179,7 @@ public bool VolumeChanged(dynamic payload)
}
public bool PowerStateChanged(dynamic payload)
{
Logger.Debug($"[{Name}] Power state change: " + JsonConvert.SerializeObject(payload));
Logger.Debug($"[{Name}] Power state change: {JsonConvert.SerializeObject(payload)}");

var state = ((string)payload.state).Replace(' ', '_');

Expand All @@ -176,9 +190,10 @@ public bool PowerStateChanged(dynamic payload)

if (CurrentState == PowerState.Active)
{
if (payload.processing == null)
if (payload.processing == null && (DateTimeOffset.Now - _poweredOffViaAppDateTime).TotalMilliseconds > 500)
{
PoweredOffViaApp = false;
_poweredOffViaAppDateTime = DateTimeOffset.MinValue;
}
}
else {
Expand All @@ -190,6 +205,9 @@ public bool PowerStateChanged(dynamic payload)
CurrentState = PowerState.Unknown;
Logger.Warn($"Unknown power state: {state}");
}

Logger.Debug($"PoweredOffBy: {PoweredOffBy}, PoweredOffViaApp: {PoweredOffViaApp}");

return true;
}

Expand Down Expand Up @@ -307,6 +325,13 @@ private async Task ExecuteSteps(LgTvApi api, LgPreset preset)

continue;
}
if (ExternalServiceHandler != null && parameters != null)
{
if (ExternalServiceHandler(key, parameters))
{
continue;
}
}

if (keySpec.Length == 2)
{
Expand All @@ -327,7 +352,8 @@ private void ExecuteAction(InvokableAction action, string[] parameters)
{
var keyValues = new Dictionary<string, string> {
{ "name", action.Name },
{ "value", parameters[0] }
{ "value", parameters[0] },
{ "category", action.Category }
};

function(keyValues);
Expand Down Expand Up @@ -366,12 +392,13 @@ public async Task<IEnumerable<LgApp>> GetApps(bool force = false)

internal async Task<bool> PowerOff()
{
if (!await Connected(true))
if (!await Connected(true) || CurrentState != PowerState.Active)
{
return false;
}

PoweredOffViaApp = true;
_poweredOffViaAppDateTime = DateTimeOffset.Now;

await _lgTvApi.TurnOff();

Expand Down Expand Up @@ -558,7 +585,9 @@ private bool WakeAction(Dictionary<string, string> parameters)
private bool GenericPictureAction(Dictionary<string, string> parameters)
{
var settingName = parameters["name"];
var task = _lgTvApi.SetSystemSettings(settingName, parameters["value"]);
var value = parameters["value"];
var category = parameters["category"];
var task = _lgTvApi.SetSystemSettings(settingName, value, category);
Utils.WaitForTask(task);

return true;
Expand Down
26 changes: 22 additions & 4 deletions ColorControl/MainForm.Designer.cs

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

Loading

0 comments on commit 90ca095

Please sign in to comment.