From bc872606a80533e9f0902f32ba318618b0e8f615 Mon Sep 17 00:00:00 2001 From: Vincent Maas Date: Fri, 4 Dec 2020 13:53:53 +0100 Subject: [PATCH] add device filter --- ColorControl/ColorControl.csproj | 2 +- ColorControl/ColorDataConverter.cs | 2 +- ColorControl/LgService.cs | 4 +- ColorControl/LgServiceConfig.cs | 3 ++ ColorControl/MainForm.Designer.cs | 69 +++++++++++++++---------- ColorControl/MainForm.cs | 23 ++++++++- ColorControl/NvService.cs | 10 +++- ColorControl/Properties/AssemblyInfo.cs | 4 +- ColorControl/Utils.cs | 4 +- 9 files changed, 80 insertions(+), 41 deletions(-) diff --git a/ColorControl/ColorControl.csproj b/ColorControl/ColorControl.csproj index cd80e32..16abca2 100644 --- a/ColorControl/ColorControl.csproj +++ b/ColorControl/ColorControl.csproj @@ -27,7 +27,7 @@ ColorControl Maassoft 0 - 1.3.5.0 + 1.3.6.0 false true true diff --git a/ColorControl/ColorDataConverter.cs b/ColorControl/ColorDataConverter.cs index 7928308..de541a6 100644 --- a/ColorControl/ColorDataConverter.cs +++ b/ColorControl/ColorDataConverter.cs @@ -48,7 +48,7 @@ namespace ColorControl { selectionPolicy = (ColorDataSelectionPolicy)Enum.ToObject(typeof(ColorDataSelectionPolicy), value); } - return new ColorData(format, dynamicRange: dynamicRange, colorimetry: colorimetry, colorDepth: colorDepth, colorSelectionPolicy: selectionPolicy); + return new ColorData(format, dynamicRange: dynamicRange, colorimetry: colorimetry, colorDepth: colorDepth, colorSelectionPolicy: selectionPolicy, desktopColorDepth: ColorDataDesktopDepth.Default); } } } diff --git a/ColorControl/LgService.cs b/ColorControl/LgService.cs index 15360b5..50c9cb2 100644 --- a/ColorControl/LgService.cs +++ b/ColorControl/LgService.cs @@ -18,8 +18,6 @@ namespace ColorControl { public static string LgListAppsJson = "listApps.json"; - public static string LgDeviceSearchKey = "[LG]"; - private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger(); public string FriendlyScreenName { get; private set; } @@ -88,7 +86,7 @@ namespace ColorControl public async Task RefreshDevices(bool connect = true) { - var devices = await Utils.GetPnpDevices(LgDeviceSearchKey); + var devices = await Utils.GetPnpDevices(Config.DeviceSearchKey); SetDevices(devices); if (connect && SelectedDevice != null) { diff --git a/ColorControl/LgServiceConfig.cs b/ColorControl/LgServiceConfig.cs index 9433524..1d82e33 100644 --- a/ColorControl/LgServiceConfig.cs +++ b/ColorControl/LgServiceConfig.cs @@ -14,9 +14,12 @@ public string PreferredMacAddress { get; set; } + public string DeviceSearchKey { get; set; } + public LgServiceConfig() { PowerOnDelayAfterResume = 5000; + DeviceSearchKey = "[LG]"; } } } diff --git a/ColorControl/MainForm.Designer.cs b/ColorControl/MainForm.Designer.cs index 1e1e4d6..5ac7bc8 100644 --- a/ColorControl/MainForm.Designer.cs +++ b/ColorControl/MainForm.Designer.cs @@ -71,8 +71,8 @@ this.btnDeleteLg = new System.Windows.Forms.Button(); this.cbxLgApps = new System.Windows.Forms.ComboBox(); this.label5 = new System.Windows.Forms.Label(); - this.label4 = new System.Windows.Forms.Label(); - this.edtLgTvName = new System.Windows.Forms.TextBox(); + this.lblDeviceFilter = new System.Windows.Forms.Label(); + this.edtLgDeviceFilter = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.edtNameLg = new System.Windows.Forms.TextBox(); this.edtStepsLg = new System.Windows.Forms.TextBox(); @@ -104,6 +104,7 @@ this.chkStartMinimized = new System.Windows.Forms.CheckBox(); this.chkStartAfterLogin = new System.Windows.Forms.CheckBox(); this.tabLog = new System.Windows.Forms.TabPage(); + this.btnClearLog = new System.Windows.Forms.Button(); this.edtLog = new System.Windows.Forms.TextBox(); this.tabInfo = new System.Windows.Forms.TabPage(); this.grpNVIDIAInfo = new System.Windows.Forms.GroupBox(); @@ -113,7 +114,7 @@ this.lbPlugins = new System.Windows.Forms.ListBox(); this.label7 = new System.Windows.Forms.Label(); this.lblInfo = new System.Windows.Forms.Label(); - this.btnClearLog = new System.Windows.Forms.Button(); + this.btnLgDeviceFilterRefresh = new System.Windows.Forms.Button(); this.tcMain.SuspendLayout(); this.tabNVIDIA.SuspendLayout(); this.mnuNvPresets.SuspendLayout(); @@ -442,6 +443,7 @@ // // tabLG // + this.tabLG.Controls.Add(this.btnLgDeviceFilterRefresh); this.tabLG.Controls.Add(this.clbLgPower); this.tabLG.Controls.Add(this.btnLgAddButton); this.tabLG.Controls.Add(this.label3); @@ -451,8 +453,8 @@ this.tabLG.Controls.Add(this.btnDeleteLg); this.tabLG.Controls.Add(this.cbxLgApps); this.tabLG.Controls.Add(this.label5); - this.tabLG.Controls.Add(this.label4); - this.tabLG.Controls.Add(this.edtLgTvName); + this.tabLG.Controls.Add(this.lblDeviceFilter); + this.tabLG.Controls.Add(this.edtLgDeviceFilter); this.tabLG.Controls.Add(this.label1); this.tabLG.Controls.Add(this.edtNameLg); this.tabLG.Controls.Add(this.edtStepsLg); @@ -586,22 +588,22 @@ this.label5.TabIndex = 25; this.label5.Text = "App:"; // - // label4 + // lblDeviceFilter // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(466, 9); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(110, 13); - this.label4.TabIndex = 24; - this.label4.Text = "Friendly screen name:"; + this.lblDeviceFilter.AutoSize = true; + this.lblDeviceFilter.Location = new System.Drawing.Point(374, 10); + this.lblDeviceFilter.Name = "lblDeviceFilter"; + this.lblDeviceFilter.Size = new System.Drawing.Size(66, 13); + this.lblDeviceFilter.TabIndex = 24; + this.lblDeviceFilter.Text = "Device filter:"; // - // edtLgTvName + // edtLgDeviceFilter // - this.edtLgTvName.Enabled = false; - this.edtLgTvName.Location = new System.Drawing.Point(579, 6); - this.edtLgTvName.Name = "edtLgTvName"; - this.edtLgTvName.Size = new System.Drawing.Size(142, 20); - this.edtLgTvName.TabIndex = 23; + this.edtLgDeviceFilter.Location = new System.Drawing.Point(446, 6); + this.edtLgDeviceFilter.Name = "edtLgDeviceFilter"; + this.edtLgDeviceFilter.Size = new System.Drawing.Size(142, 20); + this.edtLgDeviceFilter.TabIndex = 23; + this.edtLgDeviceFilter.TextChanged += new System.EventHandler(this.edtLgDeviceFilter_TextChanged); // // label1 // @@ -962,6 +964,16 @@ this.tabLog.Text = "Log"; this.tabLog.UseVisualStyleBackColor = true; // + // btnClearLog + // + this.btnClearLog.Location = new System.Drawing.Point(6, 6); + this.btnClearLog.Name = "btnClearLog"; + this.btnClearLog.Size = new System.Drawing.Size(75, 23); + this.btnClearLog.TabIndex = 2; + this.btnClearLog.Text = "Clear log"; + this.btnClearLog.UseVisualStyleBackColor = true; + this.btnClearLog.Click += new System.EventHandler(this.btnClearLog_Click); + // // edtLog // this.edtLog.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -1061,15 +1073,15 @@ this.lblInfo.TabIndex = 1; this.lblInfo.Text = "Info"; // - // btnClearLog + // btnLgDeviceFilterRefresh // - this.btnClearLog.Location = new System.Drawing.Point(6, 6); - this.btnClearLog.Name = "btnClearLog"; - this.btnClearLog.Size = new System.Drawing.Size(75, 23); - this.btnClearLog.TabIndex = 2; - this.btnClearLog.Text = "Clear log"; - this.btnClearLog.UseVisualStyleBackColor = true; - this.btnClearLog.Click += new System.EventHandler(this.btnClearLog_Click); + this.btnLgDeviceFilterRefresh.Location = new System.Drawing.Point(594, 5); + this.btnLgDeviceFilterRefresh.Name = "btnLgDeviceFilterRefresh"; + this.btnLgDeviceFilterRefresh.Size = new System.Drawing.Size(75, 23); + this.btnLgDeviceFilterRefresh.TabIndex = 35; + this.btnLgDeviceFilterRefresh.Text = "Refresh"; + this.btnLgDeviceFilterRefresh.UseVisualStyleBackColor = true; + this.btnLgDeviceFilterRefresh.Click += new System.EventHandler(this.btnLgDeviceFilterRefresh_Click); // // MainForm // @@ -1153,8 +1165,8 @@ private System.Windows.Forms.TextBox edtNameLg; private System.Windows.Forms.Button btnNvPresetDelete; private System.Windows.Forms.Button btnAddModesNv; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.TextBox edtLgTvName; + private System.Windows.Forms.Label lblDeviceFilter; + private System.Windows.Forms.TextBox edtLgDeviceFilter; private System.Windows.Forms.ComboBox cbxLgApps; private System.Windows.Forms.Label label5; private System.Windows.Forms.ToolStripMenuItem miNvApply; @@ -1203,6 +1215,7 @@ private System.Windows.Forms.TabPage tabAMD; private System.Windows.Forms.Label lblErrorAMD; private System.Windows.Forms.Button btnClearLog; + private System.Windows.Forms.Button btnLgDeviceFilterRefresh; } } diff --git a/ColorControl/MainForm.cs b/ColorControl/MainForm.cs index e3baa2c..ba03eb5 100644 --- a/ColorControl/MainForm.cs +++ b/ColorControl/MainForm.cs @@ -172,6 +172,7 @@ namespace ColorControl clbLgPower.SetItemChecked(2, _lgService.Config.PowerOffOnShutdown); clbLgPower.SetItemChecked(3, _lgService.Config.PowerOffOnStandby); edtLgPowerOnAfterResumeDelay.Value = _lgService.Config.PowerOnDelayAfterResume; + edtLgDeviceFilter.Text = _lgService.Config.DeviceSearchKey; } catch (Exception e) { @@ -1420,7 +1421,7 @@ namespace ColorControl var devices = _lgService.Devices; if (devices == null || !devices.Any()) { - _lgService.RefreshDevices(false).ContinueWith((task) => BeginInvoke(new Action(FillLgDevices))); + RefreshLgDevices(); } else { @@ -1440,6 +1441,7 @@ namespace ColorControl private void FillLgDevices() { + cbxLgDevices.Items.Clear(); var devices = _lgService.Devices; foreach (var device in devices) { @@ -1458,7 +1460,6 @@ namespace ColorControl if (cbxLgApps.Items.Count == 0 && _lgService.SelectedDevice != null) { _lgService.RefreshApps().ContinueWith((task) => BeginInvoke(new Action>>(FillLgApps), new[] { task })); - edtLgTvName.Text = _lgService.FriendlyScreenName; } } @@ -1890,5 +1891,23 @@ Do you want to continue?"; edtLog.Clear(); } } + + private void edtLgDeviceFilter_TextChanged(object sender, EventArgs e) + { + if (_lgService != null) + { + _lgService.Config.DeviceSearchKey = edtLgDeviceFilter.Text; + } + } + + private void btnLgDeviceFilterRefresh_Click(object sender, EventArgs e) + { + RefreshLgDevices(); + } + + private void RefreshLgDevices() + { + _lgService.RefreshDevices(false).ContinueWith((task) => BeginInvoke(new Action(FillLgDevices))); + } } } \ No newline at end of file diff --git a/ColorControl/NvService.cs b/ColorControl/NvService.cs index ce70a09..de8586a 100644 --- a/ColorControl/NvService.cs +++ b/ColorControl/NvService.cs @@ -88,8 +88,14 @@ namespace ColorControl if (preset.applyColorData) { var display = GetCurrentDisplay(); - //var data = new ColorData(ColorDataFormat.YUV444, ColorDataColorimetry.YCC709, ColorDataDynamicRange.Auto, ColorDataDepth.BPC8, preset.colorData.SelectionPolicy, ColorDataDesktopDepth.Default); - display.DisplayDevice.SetColorData(preset.colorData); + //var data = new ColorData(ColorDataFormat.YUV444, ColorDataColorimetry.Auto, ColorDataDynamicRange.Auto, ColorDataDepth.BPC10, preset.colorData.SelectionPolicy, ColorDataDesktopDepth.Default); + try + { + display.DisplayDevice.SetColorData(preset.colorData); + } + catch (Exception ex) + { + } //var master = display.DisplayDevice.HDRColorData.MasteringDisplayData; //var newMaster = new MasteringDisplayColorData(master.FirstColorCoordinate, master.SecondColorCoordinate, master.ThirdColorCoordinate, new ColorDataColorCoordinate(0.25f, 0.25f), 50, 0, 50, 50); diff --git a/ColorControl/Properties/AssemblyInfo.cs b/ColorControl/Properties/AssemblyInfo.cs index 99e6a9c..8be8584 100644 --- a/ColorControl/Properties/AssemblyInfo.cs +++ b/ColorControl/Properties/AssemblyInfo.cs @@ -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("1.3.5.0")] -[assembly: AssemblyFileVersion("1.3.5.0")] +[assembly: AssemblyVersion("1.3.6.0")] +[assembly: AssemblyFileVersion("1.3.6.0")] diff --git a/ColorControl/Utils.cs b/ColorControl/Utils.cs index 946cf0f..a423299 100644 --- a/ColorControl/Utils.cs +++ b/ColorControl/Utils.cs @@ -240,7 +240,7 @@ namespace ColorControl } else { - value = objValue.ToString(); + value = objValue?.ToString(); } } @@ -272,7 +272,7 @@ namespace ColorControl var ipAddress = GetDeviceProperty(dev2, "System.Devices.IpAddress"); var macAddress = GetDeviceProperty(dev2, PKEY_PNPX_PhysicalAddress); - if (!devices.Any(x => x.Name.Equals(name) && x.IpAddress.Equals(ipAddress))) + if (!devices.Any(x => x.Name.Equals(name) && x.IpAddress != null && x.IpAddress.Equals(ipAddress))) { var device = new PnpDev(dev, dev2, name, ipAddress, macAddress); devices.Add(device);