From f609471fd2c3343170b54ed596e5740662202e21 Mon Sep 17 00:00:00 2001 From: Vincent Maas Date: Fri, 31 Dec 2021 14:48:28 +0100 Subject: [PATCH] add label to set device config call, add EzAdjust service menu expert button --- ColorControl/ColorControl.csproj | 4 +-- ColorControl/LgDevice.cs | 39 ++++++++++++++++-------- ColorControl/LgPreset.cs | 6 ++-- ColorControl/MainForm.cs | 3 +- ColorControl/Utils.cs | 19 ++++++++++++ ColorControl/lgtv/LgTvApi.cs | 8 ++--- ColorControl/lgtv/LgWebOsMouseService.cs | 3 +- 7 files changed, 58 insertions(+), 24 deletions(-) diff --git a/ColorControl/ColorControl.csproj b/ColorControl/ColorControl.csproj index d5fa4c8..aed9d6f 100644 --- a/ColorControl/ColorControl.csproj +++ b/ColorControl/ColorControl.csproj @@ -18,8 +18,8 @@ Maassoft Maassoft 0 - 5.1.0.0 - 5.1.0.0 + 5.2.0.0 + 5.2.0.0 false true false diff --git a/ColorControl/LgDevice.cs b/ColorControl/LgDevice.cs index 6d2a0f7..e452961 100644 --- a/ColorControl/LgDevice.cs +++ b/ColorControl/LgDevice.cs @@ -162,8 +162,9 @@ namespace ColorControl AddInvokableAction("turnScreenOff", new Func, bool>(TurnScreenOffAction)); AddInvokableAction("turnScreenOn", new Func, bool>(TurnScreenOnAction)); - AddInternalPresetAction(new LgPreset("InStart", "com.webos.app.factorywin", new[] { "0", "4", "1", "3" })); - AddInternalPresetAction(new LgPreset("Software Update", "com.webos.app.softwareupdate")); + AddInternalPresetAction(new LgPreset("InStart", "com.webos.app.factorywin", new[] { "0", "4", "1", "3" }, new { id = "executeFactory", irKey = "inStart" })); + AddInternalPresetAction(new LgPreset("EzAdjust", "com.webos.app.factorywin", new[] { "0", "4", "1", "3" }, new { id = "executeFactory", irKey = "ezAdjust" })); + AddInternalPresetAction(new LgPreset("Software Update", "com.webos.app.softwareupdate", null, new { mode = "user", flagUpdate = true })); AddSetDeviceConfigAction("HDMI_1_icon", typeof(HdmiIcon), "HDMI 1 icon"); AddSetDeviceConfigAction("HDMI_2_icon", typeof(HdmiIcon), "HDMI 2 icon"); @@ -203,7 +204,7 @@ namespace ColorControl MinValue = minValue, MaxValue = maxValue, Category = category, - Title = title == null ? name.Substring(0, 1).ToUpper() + name.Substring(1) : title + Title = title == null ? Utils.FirstCharUpperCase(name) : title }; _invokableActions.Add(action); @@ -216,7 +217,7 @@ namespace ColorControl Name = name, Function = new Func, bool>(GenericDeviceConfigAction), EnumType = type, - Title = title == null ? name.Substring(0, 1).ToUpper() + name.Substring(1) : title + Title = title == null ? Utils.FirstCharUpperCase(name) : title }; _invokableActions.Add(action); @@ -409,15 +410,24 @@ namespace ColorControl { try { - dynamic @params = null; - if (config.ShowAdvancedActions && preset.appId.Equals("com.webos.app.softwareupdate")) + var @params = preset.AppParams; + if (@params == null && config.ShowAdvancedActions) { - @params = new { mode = "user", flagUpdate = true }; - } - - if (preset.appId.Equals("com.webos.app.factorywin")) - { - @params = new { id = "executeFactory", irKey = "inStart" }; + if (preset.appId.Equals("com.webos.app.softwareupdate")) + { + @params = new { mode = "user", flagUpdate = true }; + } + else if (preset.appId.Equals("com.webos.app.factorywin")) + { + if (preset.name.Contains("ezadjust", StringComparison.OrdinalIgnoreCase)) + { + @params = new { id = "executeFactory", irKey = "ezAdjust" }; + } + else + { + @params = new { id = "executeFactory", irKey = "inStart" }; + } + } } await _lgTvApi.LaunchApp(preset.appId, @params); @@ -827,7 +837,10 @@ namespace ColorControl var id = parameters["name"].ToString().Replace("_icon", string.Empty); var stringValues = parameters["value"] as string[]; var value = stringValues[0]; - var task = _lgTvApi.SetDeviceConfig(id, value); + + var description = Utils.GetDescriptionByEnumName(value); + + var task = _lgTvApi.SetDeviceConfig(id, value, description); Utils.WaitForTask(task); return true; diff --git a/ColorControl/LgPreset.cs b/ColorControl/LgPreset.cs index 7806577..49f9366 100644 --- a/ColorControl/LgPreset.cs +++ b/ColorControl/LgPreset.cs @@ -9,11 +9,10 @@ namespace ColorControl { public static List LgApps { get; set; } public static List LgDevices { get; set; } - - public string appId { get; set; } public List steps { get; set; } public string DeviceMacAddress { get; set; } + public dynamic AppParams { get; set; } [JsonIgnore] public int X { get; set; } @@ -37,7 +36,7 @@ namespace ColorControl } } - public LgPreset(string name, string appId, IEnumerable steps = null) : this() + public LgPreset(string name, string appId, IEnumerable steps = null, dynamic appParams = null) : this() { this.name = name; this.appId = appId; @@ -45,6 +44,7 @@ namespace ColorControl { this.steps.AddRange(steps); } + AppParams = appParams; } public LgPreset Clone() diff --git a/ColorControl/MainForm.cs b/ColorControl/MainForm.cs index 12e3d3e..ab78e97 100644 --- a/ColorControl/MainForm.cs +++ b/ColorControl/MainForm.cs @@ -1388,7 +1388,8 @@ namespace ColorControl if (preset == null) { var hdrEnabled = _nvService.IsHDREnabled(); - ditherBitsIndex = (int)(hdrEnabled ? NvDitherBits.Bits8 : NvDitherBits.Bits6); + var minBits = _nvService.GetPresets().Where(p => p.HDREnabled == hdrEnabled && p.applyDithering).DefaultIfEmpty().Min(p => p?.ditheringBits); + ditherBitsIndex = minBits.HasValue ? (int)minBits.Value : (int)(hdrEnabled ? NvDitherBits.Bits8 : NvDitherBits.Bits6); ditherModeIndex = (int)NvDitherMode.Temporal; } else diff --git a/ColorControl/Utils.cs b/ColorControl/Utils.cs index 1a129c2..7c7b30f 100644 --- a/ColorControl/Utils.cs +++ b/ColorControl/Utils.cs @@ -425,6 +425,25 @@ namespace ColorControl return bitmap; } + public static string FirstCharUpperCase(string name) + { + return name.Substring(0, 1).ToUpper() + name.Substring(1); + } + + public static string GetDescriptionByEnumName(string value) where T : IConvertible + { + string description = null; + + if (Enum.TryParse(typeof(T), value, out var result)) + { + description = (result as IConvertible)?.GetDescription(); + } + + description = description ?? FirstCharUpperCase(value); + + return description; + } + public static string GetDescription(this T e) where T : IConvertible { return GetDescription(e.GetType(), e); diff --git a/ColorControl/lgtv/LgTvApi.cs b/ColorControl/lgtv/LgTvApi.cs index cd7a78c..c97c35a 100644 --- a/ColorControl/lgtv/LgTvApi.cs +++ b/ColorControl/lgtv/LgTvApi.cs @@ -584,17 +584,17 @@ namespace LgTv await ExecuteRequest(lunauri, @params); } - public async Task SetDeviceConfig(string id, string label) + public async Task SetDeviceConfig(string id, string icon, string label) { var lunauri = "luna://com.webos.service.eim/setDeviceInfo"; - var icon = label + ".png"; + var iconPng = icon + ".png"; var @params = new { id = id, - //label = label, - icon = icon + label = label, + icon = iconPng }; await ExecuteRequest(lunauri, @params); diff --git a/ColorControl/lgtv/LgWebOsMouseService.cs b/ColorControl/lgtv/LgWebOsMouseService.cs index faa44f2..8edb1dd 100644 --- a/ColorControl/lgtv/LgWebOsMouseService.cs +++ b/ColorControl/lgtv/LgWebOsMouseService.cs @@ -54,7 +54,8 @@ namespace LgTv ASPECT_RATIO, RECENT, RECORD, - SCREEN_REMOTE + SCREEN_REMOTE, + MYAPPS } public class LgWebOsMouseService : IDisposable