add some buttons to control LG TV (volume/mute)

add preliminary remote control form
This commit is contained in:
Vincent Maas committed 2021-01-11 19:43:53 +01:00
1 parent 038a70cc81
commit 43a4660cc5
11 files changed
+424 -8

No files matched your search

+10 -1
View File
@@ -27,7 +27,7 @@
<ProductName>ColorControl</ProductName>
<PublisherName>Maassoft</PublisherName>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.3.6.0</ApplicationVersion>
<ApplicationVersion>1.4.0.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
@@ -175,6 +175,12 @@
<Compile Include="GraphicsService.cs" />
<Compile Include="AmdService.cs" />
<Compile Include="AmdPreset.cs" />
<Compile Include="RemoteControlForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="RemoteControlForm.Designer.cs">
<DependentUpon>RemoteControlForm.cs</DependentUpon>
</Compile>
<Compile Include="StartUpParams.cs" />
<Compile Include="LgServiceConfig.cs" />
<Compile Include="WOL.cs" />
@@ -223,6 +229,9 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="RemoteControlForm.resx">
<DependentUpon>RemoteControlForm.cs</DependentUpon>
</EmbeddedResource>
<None Include="ColorControl_TemporaryKey.pfx" />
<Content Include="LgPresets.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+12
View File
@@ -48,6 +48,18 @@ namespace ColorControl
}
}
protected void OpenDisplaySettings(int delay = 1000)
{
Process.Start("ms-settings:display");
Thread.Sleep(delay);
var process = Process.GetProcessesByName("SystemSettings").FirstOrDefault();
if (process != null)
{
System.Windows.Forms.SendKeys.SendWait("%{F4}");
}
}
protected bool SetRefreshRateInternal(string displayName, uint refreshRate, bool portrait, int horizontal, int vertical)
{
uint i = 0;
+78
View File
@@ -9,6 +9,7 @@ using System.Linq;
using System.Runtime;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using Windows.Data.Json;
@@ -41,12 +42,16 @@ namespace ColorControl
private bool _allowPowerOn;
private bool _justWokeUp;
private PnpDev _selectedDevice;
private string _rcButtonsFilename;
private List<LgPreset> _remoteControlButtons;
private JavaScriptSerializer _JsonDeserializer = new JavaScriptSerializer();
public LgService(string dataDir, bool allowPowerOn)
{
_dataDir = dataDir;
_allowPowerOn = allowPowerOn;
LoadConfig();
LoadRemoteControlButtons();
foreach (var screen in Screen.AllScreens)
{
@@ -63,6 +68,7 @@ namespace ColorControl
~LgService()
{
SaveConfig();
SaveRemoteControlButtons();
}
private void LoadConfig()
@@ -78,12 +84,84 @@ namespace ColorControl
}
}
private void LoadRemoteControlButtons()
{
var defaultButtons = GenerateDefaultRemoteControlButtons();
_rcButtonsFilename = Path.Combine(_dataDir, "LgRemoteControlButtons.json");
if (File.Exists(_rcButtonsFilename))
{
var json = File.ReadAllText(_rcButtonsFilename);
_remoteControlButtons = _JsonDeserializer.Deserialize<List<LgPreset>>(json);
var missingButtons = defaultButtons.Where(b => !_remoteControlButtons.Any(x => x.name.Equals(b.name)));
_remoteControlButtons.AddRange(missingButtons);
}
else
{
_remoteControlButtons = defaultButtons;
}
}
public List<LgPreset> GetRemoteControlButtons()
{
return _remoteControlButtons;
}
private List<LgPreset> GenerateDefaultRemoteControlButtons()
{
var list = new List<LgPreset>();
for (var i = 1; i < 11; i++)
{
var button = i < 10 ? i : 0;
list.Add(GeneratePreset(button.ToString()));
}
list.Add(GeneratePreset("Settings", appId: "com.palm.app.settings"));
list.Add(GeneratePreset("Vol +", step: "VOLUMEUP"));
list.Add(GeneratePreset("Vol -", step: "VOLUMEDOWN"));
list.Add(GeneratePreset("Mute", step: "MUTE"));
list.Add(GeneratePreset("Up", step: "UP"));
list.Add(GeneratePreset("Down", step: "DOWN"));
list.Add(GeneratePreset("Left", step: "LEFT"));
list.Add(GeneratePreset("Right", step: "RIGHT"));
list.Add(GeneratePreset("Enter", step: "ENTER"));
list.Add(GeneratePreset("Exit", step: "EXIT"));
return list;
}
private LgPreset GeneratePreset(string name, string step = null, string appId = null)
{
var preset = new LgPreset();
preset.name = name;
preset.appId = appId;
if (appId == null)
{
preset.steps.Add(step == null ? name : step);
}
return preset;
}
public void SaveConfig()
{
var json = JsonConvert.SerializeObject(Config);
File.WriteAllText(_configFilename, json);
}
public void SaveRemoteControlButtons()
{
var json = JsonConvert.SerializeObject(_remoteControlButtons);
File.WriteAllText(_rcButtonsFilename, json);
}
public async Task RefreshDevices(bool connect = true)
{
var devices = await Utils.GetPnpDevices(Config.DeviceSearchKey);
+13
View File
@@ -71,6 +71,7 @@
this.tabAMD = new System.Windows.Forms.TabPage();
this.lblErrorAMD = new System.Windows.Forms.Label();
this.tabLG = new System.Windows.Forms.TabPage();
this.btnLGRemoteControl = new System.Windows.Forms.Button();
this.btnLgDeviceFilterRefresh = new System.Windows.Forms.Button();
this.clbLgPower = new System.Windows.Forms.CheckedListBox();
this.btnLgAddButton = new System.Windows.Forms.Button();
@@ -550,6 +551,7 @@
//
// tabLG
//
this.tabLG.Controls.Add(this.btnLGRemoteControl);
this.tabLG.Controls.Add(this.btnLgDeviceFilterRefresh);
this.tabLG.Controls.Add(this.clbLgPower);
this.tabLG.Controls.Add(this.btnLgAddButton);
@@ -581,6 +583,16 @@
this.tabLG.Text = "LG controller";
this.tabLG.UseVisualStyleBackColor = true;
//
// btnLGRemoteControl
//
this.btnLGRemoteControl.Location = new System.Drawing.Point(675, 5);
this.btnLGRemoteControl.Name = "btnLGRemoteControl";
this.btnLGRemoteControl.Size = new System.Drawing.Size(95, 23);
this.btnLGRemoteControl.TabIndex = 36;
this.btnLGRemoteControl.Text = "Remote Control";
this.btnLGRemoteControl.UseVisualStyleBackColor = true;
this.btnLGRemoteControl.Click += new System.EventHandler(this.btnLGRemoteControl_Click);
//
// btnLgDeviceFilterRefresh
//
this.btnLgDeviceFilterRefresh.Location = new System.Drawing.Point(594, 5);
@@ -1426,6 +1438,7 @@
private System.Windows.Forms.ToolStripMenuItem spatialDynamic2x2ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem spatialStatic2x2ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem temporalToolStripMenuItem;
private System.Windows.Forms.Button btnLGRemoteControl;
}
}
+8 -1
View File
@@ -19,7 +19,6 @@ using System.Reflection;
// 1. Import the InteropServices type
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;
@@ -1736,6 +1735,7 @@ namespace ColorControl
{
_lgService.SelectedDevice = (PnpDev)cbxLgDevices.SelectedItem;
}
btnLGRemoteControl.Enabled = _lgService.SelectedDevice != null;
}
private void WarningOk(string text)
@@ -1997,5 +1997,12 @@ Do you want to continue?";
AddOrUpdateItem();
}
private void btnLGRemoteControl_Click(object sender, EventArgs e)
{
var buttons = _lgService.GetRemoteControlButtons();
var remoteControlForm = new RemoteControlForm(_lgService, buttons);
remoteControlForm.Show();
}
}
}
+5
View File
@@ -178,6 +178,11 @@ namespace ColorControl
{
ToggleHDR();
}
else if (enabled)
{
// Currectly there seems to be a bug that after enabling HDR via NVAPI, some settings are only applied upon opening the Display Settings...
OpenDisplaySettings();
}
}
public void SetDithering(bool enabled, uint bits = 1, uint mode = 4, NvPreset preset = null)
+3 -3
View File
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Maassoft")]
[assembly: AssemblyProduct("ColorControl")]
[assembly: AssemblyCopyright("Copyright © Maassoft 2020")]
[assembly: AssemblyCopyright("Copyright © Maassoft 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -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.6.0")]
[assembly: AssemblyFileVersion("1.3.6.0")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
+101
View File
@@ -0,0 +1,101 @@
namespace ColorControl
{
partial class RemoteControlForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.flowPanel = new System.Windows.Forms.FlowLayoutPanel();
this.btnClose = new System.Windows.Forms.Button();
this.lblUC = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// flowPanel
//
this.flowPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.flowPanel.Location = new System.Drawing.Point(12, 16);
this.flowPanel.Name = "flowPanel";
this.flowPanel.Size = new System.Drawing.Size(326, 349);
this.flowPanel.TabIndex = 0;
this.flowPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.RemoteControlForm_MouseDown);
//
// btnClose
//
this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnClose.FlatAppearance.BorderColor = System.Drawing.Color.DarkGray;
this.btnClose.FlatAppearance.BorderSize = 0;
this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnClose.ForeColor = System.Drawing.Color.White;
this.btnClose.Location = new System.Drawing.Point(335, 0);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(14, 23);
this.btnClose.TabIndex = 1;
this.btnClose.Text = "x";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// lblUC
//
this.lblUC.AutoSize = true;
this.lblUC.ForeColor = System.Drawing.Color.Maroon;
this.lblUC.Location = new System.Drawing.Point(130, 0);
this.lblUC.Name = "lblUC";
this.lblUC.Size = new System.Drawing.Size(100, 13);
this.lblUC.TabIndex = 0;
this.lblUC.Text = "Under construction!";
//
// RemoteControlForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(350, 377);
this.Controls.Add(this.lblUC);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.flowPanel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "RemoteControlForm";
this.Opacity = 0.8D;
this.Text = "RemoteControlForm";
this.Load += new System.EventHandler(this.RemoteControlForm_Load);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.RemoteControlForm_MouseDown);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.FlowLayoutPanel flowPanel;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Label lblUC;
}
}
+66
View File
@@ -0,0 +1,66 @@
using NWin32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ColorControl
{
partial class RemoteControlForm : Form
{
private LgService _lgService;
private List<LgPreset> _buttons;
public RemoteControlForm(LgService lgService, List<LgPreset> buttons)
{
_lgService = lgService;
_buttons = buttons;
InitializeComponent();
}
private void RemoteControlForm_Load(object sender, EventArgs e)
{
foreach (var preset in _buttons)
{
var button = new Button();
button.ForeColor = Color.White;
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderColor = Color.DarkGray;
button.FlatAppearance.MouseOverBackColor = Color.DarkGray;
button.Text = preset.name;
button.Click += ButtonClick;
button.Tag = preset;
button.Parent = flowPanel;
}
}
private void ButtonClick(object sender, EventArgs e)
{
var preset = (LgPreset)(sender as Button).Tag;
_lgService.ApplyPreset(preset);
}
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
private void RemoteControlForm_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
NativeMethods.ReleaseCapture();
var intPtr = new UIntPtr(2);
NativeMethods.SendMessageW(Handle, NativeConstants.WM_NCLBUTTONDOWN, intPtr, IntPtr.Zero);
}
}
}
}
+120
View File
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
+8 -3
View File
@@ -1,5 +1,4 @@
using NStandard;
using System;
using System;
using System.Threading.Tasks;
namespace LgTv
@@ -28,7 +27,13 @@ namespace LgTv
_8,
_9,
_0,
POWER
POWER,
VOLUMEUP,
VOLUMEDOWN,
MUTE,
MENU,
CC,
DASH
}
public class LgWebOsMouseService : IDisposable