add nvidia/amd presets to steps in LG controller

This commit is contained in:
Vincent Maas committed 2021-07-04 16:18:59 +02:00
1 parent fa63d8dc4f
commit 90ca095954
9 files changed
+188 -22

No files matched your search

+2 -2
View File
@@ -13,8 +13,6 @@ namespace ColorControl
private ADLDisplayInfo _currentDisplay;
private AmdPreset _lastAppliedPreset;
public AmdService(string dataPath) : base(dataPath)
{
LoadPresets();
@@ -191,6 +189,8 @@ namespace ColorControl
_lastAppliedPreset = preset;
PresetApplied();
return result;
}
+1 -1
View File
@@ -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>
+37 -8
View File
@@ -18,6 +18,7 @@ namespace ColorControl
public Type EnumType { get; set; }
public decimal MinValue { get; set; }
public decimal MaxValue { get; set; }
public string Category { get; set; }
}
public enum PowerState
@@ -37,6 +38,7 @@ namespace ColorControl
}
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; }
@@ -61,8 +63,10 @@ namespace ColorControl
[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>();
@@ -91,6 +95,15 @@ namespace ColorControl
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)
@@ -104,7 +117,7 @@ namespace ColorControl
_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
{
@@ -112,7 +125,8 @@ namespace ColorControl
Function = new Func<Dictionary<string, string>, bool>(GenericPictureAction),
EnumType = type,
MinValue = minValue,
MaxValue = maxValue
MaxValue = maxValue,
Category = category
};
_invokableActions.Add(action);
@@ -165,7 +179,7 @@ namespace ColorControl
}
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(' ', '_');
@@ -176,9 +190,10 @@ namespace ColorControl
if (CurrentState == PowerState.Active)
{
if (payload.processing == null)
if (payload.processing == null && (DateTimeOffset.Now - _poweredOffViaAppDateTime).TotalMilliseconds > 500)
{
PoweredOffViaApp = false;
_poweredOffViaAppDateTime = DateTimeOffset.MinValue;
}
}
else {
@@ -190,6 +205,9 @@ namespace ColorControl
CurrentState = PowerState.Unknown;
Logger.Warn($"Unknown power state: {state}");
}
Logger.Debug($"PoweredOffBy: {PoweredOffBy}, PoweredOffViaApp: {PoweredOffViaApp}");
return true;
}
@@ -307,6 +325,13 @@ namespace ColorControl
continue;
}
if (ExternalServiceHandler != null && parameters != null)
{
if (ExternalServiceHandler(key, parameters))
{
continue;
}
}
if (keySpec.Length == 2)
{
@@ -327,7 +352,8 @@ namespace ColorControl
{
var keyValues = new Dictionary<string, string> {
{ "name", action.Name },
{ "value", parameters[0] }
{ "value", parameters[0] },
{ "category", action.Category }
};
function(keyValues);
@@ -366,12 +392,13 @@ namespace ColorControl
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();
@@ -558,7 +585,9 @@ namespace ColorControl
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;
+22 -4
View File
@@ -182,6 +182,8 @@
this.lbPlugins = new System.Windows.Forms.ListBox();
this.label7 = new System.Windows.Forms.Label();
this.lblInfo = new System.Windows.Forms.Label();
this.mnuLgNvPresets = new System.Windows.Forms.ToolStripMenuItem();
this.mnuLgAmdPresets = new System.Windows.Forms.ToolStripMenuItem();
this.tcMain.SuspendLayout();
this.tabNVIDIA.SuspendLayout();
this.mnuNvPresets.SuspendLayout();
@@ -1300,21 +1302,23 @@
this.mnuLgButtons.ImageScalingSize = new System.Drawing.Size(20, 20);
this.mnuLgButtons.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuLgRcButtons,
this.mnuLgActions});
this.mnuLgActions,
this.mnuLgNvPresets,
this.mnuLgAmdPresets});
this.mnuLgButtons.Name = "mnuLgButtons";
this.mnuLgButtons.Size = new System.Drawing.Size(116, 48);
this.mnuLgButtons.Size = new System.Drawing.Size(181, 114);
this.mnuLgButtons.Opening += new System.ComponentModel.CancelEventHandler(this.mnuLgButtons_Opening);
//
// mnuLgRcButtons
//
this.mnuLgRcButtons.Name = "mnuLgRcButtons";
this.mnuLgRcButtons.Size = new System.Drawing.Size(115, 22);
this.mnuLgRcButtons.Size = new System.Drawing.Size(180, 22);
this.mnuLgRcButtons.Text = "Buttons";
//
// mnuLgActions
//
this.mnuLgActions.Name = "mnuLgActions";
this.mnuLgActions.Size = new System.Drawing.Size(115, 22);
this.mnuLgActions.Size = new System.Drawing.Size(180, 22);
this.mnuLgActions.Text = "Actions";
//
// btnCloneLg
@@ -1828,6 +1832,18 @@
this.lblInfo.TabIndex = 1;
this.lblInfo.Text = "Info";
//
// mnuLgNvPresets
//
this.mnuLgNvPresets.Name = "mnuLgNvPresets";
this.mnuLgNvPresets.Size = new System.Drawing.Size(180, 22);
this.mnuLgNvPresets.Text = "NVIDIA presets";
//
// mnuLgAmdPresets
//
this.mnuLgAmdPresets.Name = "mnuLgAmdPresets";
this.mnuLgAmdPresets.Size = new System.Drawing.Size(180, 22);
this.mnuLgAmdPresets.Text = "AMD presets";
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -2037,6 +2053,8 @@
private System.Windows.Forms.ToolStripMenuItem miLgEnableMotionPro;
private System.Windows.Forms.ToolStripMenuItem miLgDisableMotionPro;
private System.Windows.Forms.ToolStripSeparator miLgExpertSeparator1;
private System.Windows.Forms.ToolStripMenuItem mnuLgNvPresets;
private System.Windows.Forms.ToolStripMenuItem mnuLgAmdPresets;
}
}
+108 -4
View File
@@ -118,6 +118,8 @@ namespace ColorControl
{
_nvService = new NvService(_dataDir);
FillNvPresets();
_nvService.AfterApplyPreset += NvServiceAfterApplyPreset;
}
catch (Exception)
{
@@ -127,12 +129,19 @@ namespace ColorControl
}
}
private void NvServiceAfterApplyPreset(object sender, NvPreset preset)
{
UpdateDisplayInfoItems();
}
private void InitAmdService()
{
try
{
_amdService = new AmdService(_dataDir);
FillAmdPresets();
_amdService.AfterApplyPreset += AmdServiceAfterApplyPreset;
}
catch (Exception)
{
@@ -142,6 +151,11 @@ namespace ColorControl
}
}
private void AmdServiceAfterApplyPreset(object sender, AmdPreset preset)
{
UpdateDisplayInfoItemsAmd();
}
private void InitLgService()
{
try
@@ -169,6 +183,8 @@ namespace ColorControl
}
_lgService.InstallEventHandlers();
LgDevice.ExternalServiceHandler = HandleExternalServiceForLgDevice;
}
catch (Exception e)
{
@@ -184,6 +200,25 @@ namespace ColorControl
}
}
private bool HandleExternalServiceForLgDevice(string serviceName, string[] parameters)
{
if (string.IsNullOrEmpty(serviceName) || parameters.Length == 0)
{
return false;
}
if (_nvService != null && serviceName.Equals("NvPreset", StringComparison.OrdinalIgnoreCase))
{
return _nvService.ApplyPreset(parameters[0]);
}
if (_amdService != null && serviceName.Equals("AmdPreset", StringComparison.OrdinalIgnoreCase))
{
return _amdService.ApplyPreset(parameters[0]);
}
return false;
}
private void InitInfo()
{
var fileVersionInfo = FileVersionInfo.GetVersionInfo(Path.GetFileName(Application.ExecutablePath));
@@ -1154,8 +1189,20 @@ namespace ColorControl
preset.steps.Clear();
if (!clearSteps)
{
text = text.Replace(" ", string.Empty);
//text = text.Replace(" ", string.Empty);
var steps = text.Split(',');
for (var i = 0; i < steps.Length; i++)
{
var step = steps[i];
if (step.IndexOf("(") > -1)
{
steps[i] = step.Trim();
}
else
{
steps[i] = step.Replace(" ", string.Empty);
}
}
preset.steps.AddRange(steps);
}
@@ -1519,7 +1566,6 @@ namespace ColorControl
throw new Exception("Error while applying NVIDIA preset. At least one setting could not be applied. Check the log for details.");
}
UpdateDisplayInfoItems();
return true;
}
catch (Exception e)
@@ -1543,7 +1589,6 @@ namespace ColorControl
throw new Exception("Error while applying AMD preset. At least one setting could not be applied. Check the log for details.");
}
UpdateDisplayInfoItemsAmd();
return true;
}
catch (Exception e)
@@ -1720,6 +1765,26 @@ namespace ColorControl
AddToLgSteps(text);
}
private void miLgAddNvPreset_Click(object sender, EventArgs e)
{
var item = sender as ToolStripItem;
var preset = item.Tag as NvPreset;
var text = $"NvPreset({preset.name})";
AddToLgSteps(text);
}
private void miLgAddAmdPreset_Click(object sender, EventArgs e)
{
var item = sender as ToolStripItem;
var preset = item.Tag as AmdPreset;
var text = $"AmdPreset({preset.name})";
AddToLgSteps(text);
}
private void AddToLgSteps(string step)
{
var text = edtStepsLg.Text;
@@ -2473,7 +2538,7 @@ Do you want to continue?";
var device = _lgService.GetPresetDevice(preset);
var actions = device?.GetInvokableActions();
foreach (var action in actions)
foreach (var action in actions.Where(a => a.Category == null || !a.Category.Equals("other")))
{
var text = action.Name;
@@ -2482,6 +2547,45 @@ Do you want to continue?";
item.Click += miLgAddAction_Click;
}
if (_nvService != null)
{
mnuLgNvPresets.DropDownItems.Clear();
foreach (var nvPreset in _nvService.GetPresets())
{
var text = nvPreset.name;
if (!string.IsNullOrEmpty(text))
{
var item = mnuLgNvPresets.DropDownItems.Add(text);
item.Tag = nvPreset;
item.Click += miLgAddNvPreset_Click;
}
}
}
if (_amdService != null)
{
mnuLgAmdPresets.DropDownItems.Clear();
foreach (var amdPreset in _amdService.GetPresets())
{
var text = amdPreset.name;
if (!string.IsNullOrEmpty(text))
{
var item = mnuLgAmdPresets.DropDownItems.Add(text);
item.Tag = amdPreset;
item.Click += miLgAddAmdPreset_Click;
}
}
}
mnuLgNvPresets.Visible = _nvService != null;
mnuLgAmdPresets.Visible = _amdService != null;
mnuLgNvPresets.Text = mnuLgNvPresets.DropDownItems.Count > 0 ? "NVIDIA presets" : "NVIDIA presets (no named presets found)";
mnuLgAmdPresets.Text = mnuLgAmdPresets.DropDownItems.Count > 0 ? "AMD presets" : "AMD presets (no named presets found)";
}
private void btnLgDeviceConvertToCustom_Click(object sender, EventArgs e)
+2 -1
View File
@@ -68,7 +68,6 @@ namespace ColorControl
};
private Display _currentDisplay;
private NvPreset _lastAppliedPreset;
public NvService(string dataPath) : base(dataPath)
{
@@ -254,6 +253,8 @@ namespace ColorControl
_lastAppliedPreset = preset;
PresetApplied();
return result;
}
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.2.2.0")]
[assembly: AssemblyFileVersion("3.2.2.0")]
[assembly: AssemblyVersion("3.3.0.0")]
[assembly: AssemblyFileVersion("3.3.0.0")]
+8
View File
@@ -7,12 +7,15 @@ namespace ColorControl
{
abstract class ServiceBase<T> where T : PresetBase
{
public event EventHandler<T> AfterApplyPreset;
protected string _dataPath;
protected string _presetsFilename;
protected JavaScriptSerializer _JsonSerializer;
protected JavaScriptSerializer _JsonDeserializer;
protected bool _initialized = false;
protected List<T> _presets;
protected T _lastAppliedPreset;
public ServiceBase(string dataPath)
{
@@ -54,5 +57,10 @@ namespace ColorControl
{
}
protected void PresetApplied()
{
AfterApplyPreset?.Invoke(this, _lastAppliedPreset);
}
}
}
+6
View File
@@ -34,6 +34,12 @@ namespace LgTv
high
}
public enum OffToOn
{
off,
on
}
public enum OffToAuto
{
off,