From a1121c165feb88c9f5b6488bbfa38f4066a4d1e4 Mon Sep 17 00:00:00 2001 From: Vincent Maas Date: Sat, 16 Jul 2022 15:04:07 +0200 Subject: [PATCH] fix some issues, add LG aspect ratio/zoom actions --- ColorControl/ColorControl.csproj | 16 +- ColorControl/Common/Utils.cs | 5 + ColorControl/Forms/FormUtils.cs | 37 ++++- ColorControl/MainForm.cs | 137 ++++++++++++++---- ColorControl/Services/Common/PresetBase.cs | 15 +- .../Services/Common/ServiceManager.cs | 27 ++++ ColorControl/Services/LG/LgDevice.cs | 11 +- ColorControl/Services/LG/LgService.cs | 3 + ColorControl/Services/NVIDIA/NvPreset.cs | 3 +- ColorControl/Services/NVIDIA/NvService.cs | 59 +++++++- ColorControl/lgtv/LgTvApi.cs | 76 ++++++---- Nspector/Nspector.csproj | 2 +- 12 files changed, 304 insertions(+), 87 deletions(-) create mode 100644 ColorControl/Services/Common/ServiceManager.cs diff --git a/ColorControl/ColorControl.csproj b/ColorControl/ColorControl.csproj index e34f189..880b7b6 100644 --- a/ColorControl/ColorControl.csproj +++ b/ColorControl/ColorControl.csproj @@ -1,6 +1,6 @@  - net6.0-windows10.0.17763.0 + net6.0-windows10.0.20348.0 WinExe false publish\ @@ -18,8 +18,8 @@ Maassoft Maassoft 0 - 7.0.0.0 - 7.0.0.0 + 7.1.0.0 + 7.1.0.0 false true false @@ -28,7 +28,7 @@ false true pngbarn.ico - 10.0.17763.0 + 10.0.20348.0 2020-2022 Maassoft Maassoft CF0BC153EA664CD97AC6F234B91F45D34630958F @@ -89,11 +89,11 @@ - - + + - - + + diff --git a/ColorControl/Common/Utils.cs b/ColorControl/Common/Utils.cs index 8ce2d22..4304034 100644 --- a/ColorControl/Common/Utils.cs +++ b/ColorControl/Common/Utils.cs @@ -814,5 +814,10 @@ namespace ColorControl.Common return null; } + + public static bool NormEquals(this string str1, string str2) + { + return str1.Trim().Replace(" ", string.Empty).Equals(str2.Trim().Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase); + } } } diff --git a/ColorControl/Forms/FormUtils.cs b/ColorControl/Forms/FormUtils.cs index 30c01ad..e5b7eb6 100644 --- a/ColorControl/Forms/FormUtils.cs +++ b/ColorControl/Forms/FormUtils.cs @@ -51,10 +51,10 @@ namespace ColorControl.Forms t.GetMethod("UpdateIcon", hidden).Invoke(ni, new object[] { true }); } - public static ToolStripMenuItem BuildDropDownMenuEx(ContextMenuStrip mnuParent, string name, Type enumType, EventHandler clickEvent, object tag = null, int min = 0, int max = 0) + public static ToolStripMenuItem BuildDropDownMenuEx(ToolStripItemCollection items, string parentName, string name, Type enumType, EventHandler clickEvent, object tag = null, int min = 0, int max = 0, bool noSubItems = false) { - var subMenuName = $"{mnuParent.Name}_{name}"; - var subMenuItems = mnuParent.Items.Find(subMenuName, false); + var subMenuName = $"{parentName}_{name}"; + var subMenuItems = items.Find(subMenuName, false); if (subMenuItems.Length > 0) { @@ -62,9 +62,17 @@ namespace ColorControl.Forms } ToolStripMenuItem subMenuItem; - subMenuItem = (ToolStripMenuItem)mnuParent.Items.Add(name); + subMenuItem = (ToolStripMenuItem)items.Add(name); subMenuItem.Name = subMenuName; + if (noSubItems) + { + subMenuItem.Tag = tag; + subMenuItem.Click += clickEvent; + + return subMenuItem; + } + if (enumType != null) { foreach (var enumValue in Enum.GetValues(enumType)) @@ -81,12 +89,25 @@ namespace ColorControl.Forms item.Click += clickEvent; } } - else if (min >= 0 && max > min) + else if (max > min) { - for (var i = 0; i <= 10; i++) - { - var value = i * (max / 10); + List range; + if (max - min <= 20) + { + range = Enumerable.Range(min, (max - min) + 1).ToList(); + } + else + { + range = new List(); + for (var i = 0; i <= 10; i++) + { + range.Add(i * (max / 10)); + } + } + + foreach (var value in range) + { var subSubItemName = $"{subMenuName}_{value}"; var item = subMenuItem.DropDownItems.Add(value.ToString()); diff --git a/ColorControl/MainForm.cs b/ColorControl/MainForm.cs index 396abc1..27caeba 100644 --- a/ColorControl/MainForm.cs +++ b/ColorControl/MainForm.cs @@ -328,6 +328,10 @@ namespace ColorControl { return _nvService.ApplyPreset(parameters[0]); } + if (_nvService != null && serviceName.Equals("GsyncEnabled", StringComparison.OrdinalIgnoreCase)) + { + return _nvService.IsGsyncEnabled(); + } if (_amdService != null && serviceName.Equals("AmdPreset", StringComparison.OrdinalIgnoreCase)) { return _amdService.ApplyPreset(parameters[0]); @@ -2055,10 +2059,29 @@ namespace ColorControl { var filename = Path.Combine(_dataDir, "LogFile.txt"); - var lines = new[] { "No log file found" }; - if (File.Exists(filename)) + var lines = new List { "No log file found" }; + + try { - lines = File.ReadAllLines(filename); + if (File.Exists(filename)) + { + using var fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + + using var reader = new StreamReader(fs); + + String line; + + while ((line = reader.ReadLine()) != null) + { + lines.Add(line); + } + + //lines = File.ReadAllLines(filename); + } + } + catch (Exception ex) + { + lines = new List { $"Cannot load log file: {ex.Message}" }; } var reversedLines = lines.ToList(); var builder = new StringBuilder(); @@ -2139,6 +2162,18 @@ namespace ColorControl var item = sender as ToolStripItem; var action = item.Tag as LgDevice.InvokableAction; + var value = ShowLgActionForm(action); + + if (!string.IsNullOrEmpty(value)) + { + var text = $"{action.Name}({value})"; + + FormUtils.AddStepToTextBox(edtStepsLg, text); + } + } + + private string ShowLgActionForm(LgDevice.InvokableAction action) + { var text = action.Name; var title = action.Title ?? action.Name; @@ -2154,7 +2189,7 @@ namespace ColorControl { fields.Add(new MessageForms.FieldDefinition { - Label = "Enter desired " + item.Text, + Label = "Enter desired " + title, FieldType = MessageForms.FieldType.Numeric, MinValue = action.MinValue, MaxValue = action.MaxValue, @@ -2173,11 +2208,11 @@ namespace ColorControl })); } - var values = MessageForms.ShowDialog("Enter value", fields); + var values = MessageForms.ShowDialog($"Enter value for {title}", fields); if (!values.Any()) { - return; + return null; } if (values.Count > 1) @@ -2210,7 +2245,7 @@ namespace ColorControl if (!values.Any()) { - return; + return null; } value = values.First().Value.ToString(); @@ -2221,12 +2256,7 @@ namespace ColorControl } } - if (!string.IsNullOrEmpty(value)) - { - text += $"({value})"; - } - - FormUtils.AddStepToTextBox(edtStepsLg, text); + return value; } private void miLgAddNvPreset_Click(object sender, EventArgs e) @@ -3112,31 +3142,40 @@ Do you want to continue?" const string gameBarName = "miGameBar"; - foreach (var action in actions.Where(a => !a.Name.Contains("uhd", StringComparison.OrdinalIgnoreCase) && + var expertActions = actions.Where(a => !a.Name.Contains("uhd", StringComparison.OrdinalIgnoreCase) && !a.Name.Contains("gameOpt", StringComparison.OrdinalIgnoreCase) && !a.Name.Contains("hdmiPc", StringComparison.OrdinalIgnoreCase) && - (a.EnumType != null || a.MinValue >= 0 && a.MaxValue > a.MinValue))) + (a.EnumType != null || a.MaxValue > a.MinValue)).ToList(); + + var categories = expertActions.Select(a => a.Category ?? "misc").Where(c => !string.IsNullOrEmpty(c)).Distinct(); + + foreach (var category in categories) { - var menu = FormUtils.BuildDropDownMenuEx(mnuLgExpert, action.Title, action.EnumType, btnLgExpertColorGamut_Click, action, (int)action.MinValue, (int)action.MaxValue); + var catMenuItem = FormUtils.BuildDropDownMenuEx(mnuLgExpert.Items, mnuLgExpert.Name, Utils.FirstCharUpperCase(category), null, null, category); - if (!gameBarActions.Contains(action)) + foreach (var action in expertActions.Where(a => (a.Category ?? "misc") == category)) { - continue; - } + var menu = FormUtils.BuildDropDownMenuEx(catMenuItem.DropDownItems, catMenuItem.Name, action.Title, action.EnumType, btnLgExpertColorGamut_Click, action, (int)action.MinValue, (int)action.MaxValue, action.NumberOfValues > 1); - var itemName = $"{menu.Name}_{gameBarName}"; - var gameBarItem = (ToolStripMenuItem)menu.DropDownItems.Find(itemName, false).FirstOrDefault(); + if (!gameBarActions.Contains(action)) + { + continue; + } - if (gameBarItem == null) - { - var separator = new ToolStripSeparator(); - menu.DropDownItems.Add(separator); + var itemName = $"{menu.Name}_{gameBarName}"; + var gameBarItem = (ToolStripMenuItem)menu.DropDownItems.Find(itemName, false).FirstOrDefault(); - gameBarItem = (ToolStripMenuItem)menu.DropDownItems.Add("Show in Game Bar", null, miLgGameBarToggle_Click); - gameBarItem.CheckOnClick = true; - gameBarItem.Checked = activatedGameBarActions.Contains(action); - gameBarItem.Name = itemName; - gameBarItem.Tag = action.Name; + if (gameBarItem == null) + { + var separator = new ToolStripSeparator(); + menu.DropDownItems.Add(separator); + + gameBarItem = (ToolStripMenuItem)menu.DropDownItems.Add("Show in Game Bar", null, miLgGameBarToggle_Click); + gameBarItem.CheckOnClick = true; + gameBarItem.Checked = activatedGameBarActions.Contains(action); + gameBarItem.Name = itemName; + gameBarItem.Tag = action.Name; + } } } @@ -3157,7 +3196,7 @@ Do you want to continue?" foreach (var presetAction in presetActions) { - var menu = FormUtils.BuildDropDownMenuEx(mnuLgExpert, presetAction.Name, null, btnLgExpertPresetAction_Click, presetAction.Preset); + var menu = FormUtils.BuildDropDownMenuEx(mnuLgExpert.Items, mnuLgExpert.Name, presetAction.Name, null, btnLgExpertPresetAction_Click, presetAction.Preset); } } @@ -3192,9 +3231,29 @@ Do you want to continue?" var action = item.Tag as LgDevice.InvokableAction; var value = item.AccessibleName ?? item.Text; + if (action.NumberOfValues > 1) + { + ApplyLgExpertValueRange(action); + return; + } + _lgService.SelectedDevice?.ExecuteAction(action, new[] { value }); } + private void ApplyLgExpertValueRange(LgDevice.InvokableAction action) + { + var value = ShowLgActionForm(action); + + if (value == null) + { + return; + } + + var values = value.Split(";"); + + _lgService.SelectedDevice?.ExecuteAction(action, values); + } + private void btnLgExpertPresetAction_Click(object sender, EventArgs e) { var item = sender as ToolStripItem; @@ -3850,6 +3909,14 @@ The InStart and Software Update items are now visible under the Expert-button." return; } + var point = listView.PointToClient(Cursor.Position); + + if (point.X >= 20) + { + e.Item.Checked = !e.Item.Checked; + return; + } + checkedPreset.ShowInQuickAccess = e.Item.Checked; var preset = listView.GetSelectedItemTag(); @@ -3879,6 +3946,14 @@ The InStart and Software Update items are now visible under the Expert-button." return; } + + var point = listView.PointToClient(Cursor.Position); + + if (point.X >= 20) + { + return; + } + var listItem = listView.Items[e.Index]; if (listItem.Tag == null) diff --git a/ColorControl/Services/Common/PresetBase.cs b/ColorControl/Services/Common/PresetBase.cs index 8fa9b0e..a48c5b0 100644 --- a/ColorControl/Services/Common/PresetBase.cs +++ b/ColorControl/Services/Common/PresetBase.cs @@ -42,6 +42,10 @@ namespace ColorControl.Services.Common FullScreen = 4, [Description("Notifications Disabled")] NotificationsDisabled = 8, + [Description("G-SYNC Disabled")] + GsyncDisabled = 16, + [Description("G-SYNC Enabled")] + GsyncEnabled = 32 } class PresetTrigger @@ -59,7 +63,9 @@ namespace ColorControl.Services.Common public bool TriggerActive(PresetTriggerContext context) { - var active = Conditions == PresetConditionType.None || (Conditions.HasFlag(PresetConditionType.SDR) && !context.IsHDRActive) || (Conditions.HasFlag(PresetConditionType.HDR) && context.IsHDRActive); + var active = Conditions == PresetConditionType.None || + (Conditions.HasFlag(PresetConditionType.SDR) ? !context.IsHDRActive : true) && (Conditions.HasFlag(PresetConditionType.HDR) ? context.IsHDRActive : true) && + (Conditions.HasFlag(PresetConditionType.GsyncDisabled) ? !context.IsGsyncActive : true) && (Conditions.HasFlag(PresetConditionType.GsyncEnabled) ? context.IsGsyncActive : true); var allProcesses = IncludedProcesses.Contains("*"); if (Trigger == PresetTriggerType.ProcessSwitch) @@ -68,12 +74,12 @@ namespace ColorControl.Services.Common if (active) { - var included = allProcesses || context.ChangedProcesses.Any(cp => IncludedProcesses.Any(ip => cp.ProcessName.Equals(ip, StringComparison.OrdinalIgnoreCase))); - var excluded = context.ChangedProcesses.Any(cp => ExcludedProcesses.Any(ep => cp.ProcessName.Equals(ep, StringComparison.OrdinalIgnoreCase))); + var included = allProcesses || context.ChangedProcesses.Any(cp => IncludedProcesses.Any(ip => cp.ProcessName.NormEquals(ip))); + var excluded = context.ChangedProcesses.Any(cp => ExcludedProcesses.Any(ep => cp.ProcessName.NormEquals(ep))); var screenSizeCheck = (!Conditions.HasFlag(PresetConditionType.FullScreen) && !context.ForegroundProcessIsFullScreen) || (context.ForegroundProcess != null && context.ForegroundProcessIsFullScreen && - (allProcesses || IncludedProcesses.Any(ip => context.ForegroundProcess.ProcessName.Equals(ip, StringComparison.OrdinalIgnoreCase)))); + (allProcesses || IncludedProcesses.Any(ip => context.ForegroundProcess.ProcessName.NormEquals(ip)))); var notificationsDisabledCheck = !Conditions.HasFlag(PresetConditionType.NotificationsDisabled) || context.IsNotificationDisabled; @@ -103,6 +109,7 @@ namespace ColorControl.Services.Common class PresetTriggerContext { public bool IsHDRActive { get; set; } + public bool IsGsyncActive { get; set; } public Process ForegroundProcess { get; set; } public bool ForegroundProcessIsFullScreen { get; set; } public List ChangedProcesses { get; set; } diff --git a/ColorControl/Services/Common/ServiceManager.cs b/ColorControl/Services/Common/ServiceManager.cs new file mode 100644 index 0000000..2ba05c2 --- /dev/null +++ b/ColorControl/Services/Common/ServiceManager.cs @@ -0,0 +1,27 @@ +namespace ColorControl.Services.Common +{ + class ServiceManager + { + public static ServiceManager Instance + { + get + { + if (_instance == null) + { + _instance = new ServiceManager(); + } + + return _instance; + } + } + private static ServiceManager _instance { get; set; } + + //private List> _services = new(); + + public void Initialize() + { + + } + + } +} diff --git a/ColorControl/Services/LG/LgDevice.cs b/ColorControl/Services/LG/LgDevice.cs index 526dd44..6a77651 100644 --- a/ColorControl/Services/LG/LgDevice.cs +++ b/ColorControl/Services/LG/LgDevice.cs @@ -147,6 +147,7 @@ namespace ColorControl.Services.LG AddGenericPictureAction("colorGamut", typeof(ColorGamut), title: "Color Gamut"); AddGenericPictureAction("dynamicContrast", typeof(OffToHigh), title: "Dynamic Contrast"); AddGenericPictureAction("gamma", typeof(GammaExp)); + AddGenericPictureAction("colorTemperature", minValue: 0, maxValue: 50, title: "Color Temperature"); AddGenericPictureAction("whiteBalanceColorTemperature", typeof(WhiteBalanceColorTemperature), title: "White Balance Color Temperature"); //AddGenericPictureAction("dynamicColor", typeof(OffToAuto)); //AddGenericPictureAction("superResolution", typeof(OffToAuto)); @@ -155,6 +156,14 @@ namespace ColorControl.Services.LG AddGenericPictureAction("energySaving", typeof(EnergySaving), title: "Energy Saving"); AddGenericPictureAction("hdrDynamicToneMapping", typeof(DynamicTonemapping), title: "HDR Dynamic Tone Mapping"); AddGenericPictureAction("blackLevel", typeof(BlackLevel), title: "HDMI Black Level"); + AddGenericPictureAction("arcPerApp", typeof(AspectRatio), title: "Aspect Ratio", category: "aspectRatio"); + AddGenericPictureAction("justScan", typeof(OffToAuto2), title: "Just Scan", category: "aspectRatio"); + AddGenericPictureAction("allDirZoomHRatio", minValue: 0, maxValue: 10, title: "All-Direction Zoom Horizontal Ratio", category: "aspectRatio"); + AddGenericPictureAction("allDirZoomVRatio", minValue: 0, maxValue: 9, title: "All-Direction Zoom Verical Ratio", category: "aspectRatio"); + AddGenericPictureAction("allDirZoomHPosition", minValue: -10, maxValue: 9, title: "All-Direction Zoom Horizontal Position", category: "aspectRatio"); + AddGenericPictureAction("allDirZoomVPosition", minValue: -9, maxValue: 9, title: "All-Direction Zoom Vertical Position", category: "aspectRatio"); + AddGenericPictureAction("vertZoomVPosition", minValue: -8, maxValue: 9, title: "Vertical Zoom Position", category: "aspectRatio"); + AddGenericPictureAction("vertZoomVRatio", minValue: 0, maxValue: 9, title: "Vertical Zoom Ratio", category: "aspectRatio"); //AddGenericPictureAction("ambientLightCompensation", typeof(OffToAuto2)); AddGenericPictureAction("truMotionMode", typeof(TruMotionMode), title: "TruMotion"); AddGenericPictureAction("truMotionJudder", minValue: 0, maxValue: 10, title: "TruMotion Judder"); @@ -368,7 +377,7 @@ namespace ColorControl.Services.LG { Logger.Debug($"[{Name}] Power state change: {JsonConvert.SerializeObject(payload)}"); - var state = ((string)payload.state).Replace(' ', '_'); + var state = payload.state != null ? ((string)payload.state).Replace(' ', '_') : PowerState.Unknown.ToString(); PowerState newState; if (Enum.TryParse(state, out newState)) diff --git a/ColorControl/Services/LG/LgService.cs b/ColorControl/Services/LG/LgService.cs index e616e77..594bb0f 100644 --- a/ColorControl/Services/LG/LgService.cs +++ b/ColorControl/Services/LG/LgService.cs @@ -753,9 +753,12 @@ namespace ColorControl.Services.LG var isHDRActive = context.Devices.Any(d => d.IsUsingHDRPictureMode()); + var isGsyncActive = LgDevice.ExternalServiceHandler("GsyncEnabled", new[] { "" }); + var triggerContext = new PresetTriggerContext { IsHDRActive = isHDRActive, + IsGsyncActive = isGsyncActive, ForegroundProcess = context.ForegroundProcess, ForegroundProcessIsFullScreen = context.ForegroundProcessIsFullScreen, ChangedProcesses = changedProcesses, diff --git a/ColorControl/Services/NVIDIA/NvPreset.cs b/ColorControl/Services/NVIDIA/NvPreset.cs index b2f9de3..87a7e06 100644 --- a/ColorControl/Services/NVIDIA/NvPreset.cs +++ b/ColorControl/Services/NVIDIA/NvPreset.cs @@ -93,8 +93,7 @@ namespace ColorControl.Services.NVIDIA public static string[] GetColumnNames() { - //return new[] { "BPC", "Format", "Dynamic range", "Toggle HDR", "Shortcut" }; - return new[] { "[Quick Access] Name", "Display|140", "Color settings (BPC, format, dyn. range, color space)|260", "Refresh rate|100", "Resolution|120", "Dithering", "HDR", "Driver settings|300", "Shortcut", "Apply on startup" }; + return new[] { "Name", "Display|140", "Color settings (BPC, format, dyn. range, color space)|260", "Refresh rate|100", "Resolution|120", "Dithering", "HDR", "Driver settings|300", "Shortcut", "Apply on startup" }; } public override List GetDisplayValues(Config config = null) diff --git a/ColorControl/Services/NVIDIA/NvService.cs b/ColorControl/Services/NVIDIA/NvService.cs index d0f4e26..dab957e 100644 --- a/ColorControl/Services/NVIDIA/NvService.cs +++ b/ColorControl/Services/NVIDIA/NvService.cs @@ -13,6 +13,8 @@ using System.ComponentModel; using System.IO; using System.Linq; using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; using System.Windows.Forms; namespace ColorControl.Services.NVIDIA @@ -91,6 +93,8 @@ namespace ColorControl.Services.NVIDIA private DrsSettingsMetaService _meta; private List _settings = new List(); + private Semaphore _semaphore = new Semaphore(1, 1); + public const uint DRS_GSYNC_APPLICATION_MODE = 294973784; public const uint DRS_VSYNC_CONTROL = 11041231; //public const uint DRS_ULTRA_LOW_LATENCY = 0x10835000; @@ -680,7 +684,7 @@ namespace ColorControl.Services.NVIDIA public List GetVisibleSettings() { - return _settings.Where(s => _driverSettingIds.Contains(s.SettingId)).ToList(); + return GetSettings().Where(s => _driverSettingIds.Contains(s.SettingId)).ToList(); } public SettingMeta GetSettingMeta(uint settingId) @@ -688,6 +692,38 @@ namespace ColorControl.Services.NVIDIA return _meta.GetSettingMeta(settingId); } + public bool IsGsyncEnabled() + { + var setting = GetSettings().FirstOrDefault(s => s.SettingId == DRS_GSYNC_APPLICATION_MODE); + if (setting == null) + { + return false; + } + + var settingMeta = GetSettingMeta(setting.SettingId); + var settingValue = settingMeta.DwordValues.FirstOrDefault(s => s.ValueName == setting.ValueText); + + return settingValue.Value >= 1; + } + + protected List GetSettings() + { + _semaphore.WaitOne(); + try + { + if (!_settings.Any()) + { + RefreshProfileSettings(); + } + + return _settings; + } + finally + { + _semaphore.Release(); + } + } + protected override void Initialize() { NvAPIWrapper.NVIDIA.Initialize(); @@ -698,16 +734,27 @@ namespace ColorControl.Services.NVIDIA _drs.GetProfileNames(ref _baseProfileName, false); - RefreshProfileSettings(); + Task.Run(() => + { + RefreshProfileSettings(); + }); } private void RefreshProfileSettings() { - var applications = new Dictionary(); - var normalSettings = _drs.GetSettingsForProfile(_baseProfileName, SettingViewMode.Normal, ref applications); + _semaphore.WaitOne(); + try + { + var applications = new Dictionary(); + var normalSettings = _drs.GetSettingsForProfile(_baseProfileName, SettingViewMode.Normal, ref applications); - _settings = new List(); - _settings.AddRange(normalSettings); + _settings = new List(); + _settings.AddRange(normalSettings); + } + finally + { + _semaphore.Release(); + } } protected override void Uninitialize() diff --git a/ColorControl/lgtv/LgTvApi.cs b/ColorControl/lgtv/LgTvApi.cs index 262cb12..9eaab5c 100644 --- a/ColorControl/lgtv/LgTvApi.cs +++ b/ColorControl/lgtv/LgTvApi.cs @@ -1,5 +1,4 @@ -using ColorControl; -using ColorControl.Common; +using ColorControl.Common; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; @@ -14,7 +13,7 @@ namespace LgTv public enum ControlButtons { - Back,Down,Left,Right, + Back, Down, Left, Right, OK, Exit } @@ -22,9 +21,9 @@ namespace LgTv public enum PictureMode { cinema, eco, expert1, expert2, game, normal, photo, sports, technicolor, vivid, hdrEffect, filmMaker, - - hdrCinema, hdrCinemaBright, hdrExternal, hdrGame, hdrStandard, hdrTechnicolor, hdrVivid, hdrFilmMaker, - + + hdrCinema, hdrCinemaBright, hdrExternal, hdrGame, hdrStandard, hdrTechnicolor, hdrVivid, hdrFilmMaker, + dolbyHdrCinema, dolbyHdrCinemaBright, dolbyHdrDarkAmazon, dolbyHdrGame, dolbyHdrStandard, dolbyHdrVivid, dolbyStandard } @@ -143,6 +142,26 @@ namespace LgTv auto } + public enum AspectRatio + { + _21x9, + _16x9, + _4x3, + _14x9, + _32x9, + _32x12, + just_scan, + original, + full_wide, + limited, + zoom, + zoom2, + cinema_zoom, + vertZoom, + allDirZoom, + twinZoom + } + public enum HdmiIcon { [Description("HDMI")] @@ -225,7 +244,7 @@ namespace LgTv wisa_speaker, } - public class LgTvApi:IDisposable + public class LgTvApi : IDisposable { public bool ConnectionClosed { get => _connection?.ConnectionClosed ?? true; } @@ -289,7 +308,7 @@ namespace LgTv _keyStore.SaveClientKey(result.clientKey); _keyStore.SaveHandShake(registerJson); } - + public async Task Connect() { @@ -303,7 +322,7 @@ namespace LgTv var requestMessage = new RequestMessage("ssap://com.webos.service.networkinput/getPointerInputSocket", new { }); var s = await _connection.SendCommandAsync(requestMessage); var socketPath = (string)s.socketPath; - + _mouseConnection = new LgWebOsMouseService(new LgTvApiCore()); await _mouseConnection.Connect(socketPath); return _mouseConnection; @@ -337,10 +356,10 @@ namespace LgTv } public async Task ShowToast() { - var requestMessage = new RequestMessage("ssap://system.notifications/createToast",new {message = "Co tam u Ciebie?"}); + var requestMessage = new RequestMessage("ssap://system.notifications/createToast", new { message = "Co tam u Ciebie?" }); await _connection.SendCommandAsync(requestMessage); } - + //public async Task LaunchApp(string appId,Uri uri) //{ // var url = uri.ToString(); @@ -354,7 +373,7 @@ namespace LgTv var requestMessage = new RequestMessage("volumedown", "ssap://audio/volumeDown"); await _connection.SendCommandAsync(requestMessage); } - public async Task VolumeUp() + public async Task VolumeUp() { var requestMessage = new RequestMessage("volumeup", "ssap://audio/volumeUp"); await _connection.SendCommandAsync(requestMessage); @@ -365,12 +384,12 @@ namespace LgTv await _connection.SendCommandAsync(requestMessage); } - public async Task SetChannel(string channelId) + public async Task SetChannel(string channelId) { var requestMessage = new RequestMessage("ssap://tv/openChannel", new { channelId }); await _connection.SendCommandAsync(requestMessage); } - public async Task SetMute(bool value) + public async Task SetMute(bool value) { var requestMessage = new RequestMessage("ssap://audio/setMute", new { mute = value }); await _connection.SendCommandAsync(requestMessage); @@ -386,7 +405,7 @@ namespace LgTv return (bool)(await command).mute; } - public async Task SetVolume(int value) + public async Task SetVolume(int value) { if (value >= 0 && value <= 100) { @@ -394,11 +413,11 @@ namespace LgTv await _connection.SendCommandAsync(requestMessage); } } - public async Task TurnOff() + public async Task TurnOff() { - await _connection.SendCommandAsync(new RequestMessage("","ssap://system/turnOff")); + await _connection.SendCommandAsync(new RequestMessage("", "ssap://system/turnOff")); } - public async Task Play() + public async Task Play() { await _connection.SendCommandAsync(new RequestMessage("play", "ssap://media.controls/play")); } @@ -416,7 +435,7 @@ namespace LgTv await _connection.SendCommandAsync(new RequestMessage("channelDown", "ssap://tv/channelDown")); } - public async Task Stop() + public async Task Stop() { await _connection.SendCommandAsync(new RequestMessage("stop", "ssap://media.controls/stop")); } @@ -445,7 +464,7 @@ namespace LgTv //Response: { returnValue: true, status3D: { status: true, pattern: ’2Dto3D’ } } var requestMessage = new RequestMessage("status3D", "ssap://com.webos.service.tv.display/get3DStatus"); var o = await _connection.SendCommandAsync(requestMessage); - return (bool)o.status3D.status; + return (bool)o.status3D.status; } public async Task GetVolume() @@ -465,12 +484,12 @@ namespace LgTv // } var requestMessage = new RequestMessage("status", "ssap://audio/getVolume"); var o = await _connection.SendCommandAsync(requestMessage); - return( (bool)o.muted) ? -1 :(int) o.volume; + return ((bool)o.muted) ? -1 : (int)o.volume; } public async Task> GetInputList() { - var requestMessage = new RequestMessage("input","ssap://tv/getExternalInputList"); - var results = await _connection.SendCommandAsync(requestMessage); + var requestMessage = new RequestMessage("input", "ssap://tv/getExternalInputList"); + var results = await _connection.SendCommandAsync(requestMessage); var l = new List(); foreach (var result in results) { @@ -482,7 +501,7 @@ namespace LgTv return l; } - public async Task SetInput(string id) + public async Task SetInput(string id) { var requestMessage = new RequestMessage("ssap://tv/switchInput", new { inputId = id }); await _connection.SendCommandAsync(requestMessage); @@ -677,6 +696,11 @@ namespace LgTv } else { + if (key.Equals("arcPerApp") && value.ToString().StartsWith("_")) + { + value = value.ToString().Substring(1); + } + jsonValue = $"\"{value}\""; } @@ -718,7 +742,7 @@ namespace LgTv label = label, icon = iconPng }; - + await ExecuteRequest(lunauri, @params); } @@ -819,7 +843,7 @@ namespace LgTv } public void Dispose() { - _connection?.Dispose(); + _connection?.Dispose(); } } } \ No newline at end of file diff --git a/Nspector/Nspector.csproj b/Nspector/Nspector.csproj index 7cf8561..0bc3504 100644 --- a/Nspector/Nspector.csproj +++ b/Nspector/Nspector.csproj @@ -1,7 +1,7 @@  - net6.0-windows10.0.17763.0 + net6.0-windows10.0.20348.0 enable true enable