Skip to content

Commit

Permalink
add LG expert button to test new way of changing settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Maassoft committed May 30, 2021
1 parent 26a91dc commit 4614886
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 19 deletions.
4 changes: 4 additions & 0 deletions ColorControl/AppContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
public class AppContext
{
public static AppContext CurrentContext { get; private set; }

public Config Config { get; private set; }

public StartUpParams StartUpParams { get; private set; }
Expand All @@ -10,6 +12,8 @@ public AppContext(Config config, StartUpParams startUpParams)
{
Config = config;
StartUpParams = startUpParams;

CurrentContext = this;
}
}
}
2 changes: 1 addition & 1 deletion ColorControl/ColorControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<ProductName>ColorControl</ProductName>
<PublisherName>Maassoft</PublisherName>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>3.0.0.0</ApplicationVersion>
<ApplicationVersion>3.1.0.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down
27 changes: 27 additions & 0 deletions ColorControl/LgDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -58,6 +59,8 @@ public async Task<bool> Connect(int retries = 3)
_lgTvApi = await LgTvApi.CreateLgTvApi(IpAddress, retries);

//Test();
//_lgTvApi.Test3();
//_lgTvApi.SetSystemSettings();
return _lgTvApi != null;
}
catch (Exception ex)
Expand Down Expand Up @@ -310,6 +313,15 @@ internal async Task<bool> WakeAndConnectWithRetries(int retries = 5)
}
}

if (result)
{
var resumeScript = Path.Combine(Program.DataDir, "ResumeScript.bat");
if (File.Exists(resumeScript))
{
Utils.StartProcess(resumeScript);
}
}

return result;
}

Expand Down Expand Up @@ -354,5 +366,20 @@ internal void ConvertToCustom()
{
IsCustom = true;
}

internal async Task SetBacklight(int backlight)
{
await _lgTvApi.SetSystemSettings("backlight", backlight.ToString());
}

public async Task SetOLEDMotionPro(string mode)
{
await _lgTvApi.SetConfig("tv.model.motionProMode", mode);
}

internal async Task SetConfig(string key, string value)
{
await _lgTvApi.SetConfig(key, value);
}
}
}
6 changes: 6 additions & 0 deletions ColorControl/LgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,12 @@ private void PowerModeChanged(object sender, PowerModeChangedEventArgs e)
NativeMethods.SetThreadExecutionState(NativeConstants.ES_CONTINUOUS | NativeConstants.ES_SYSTEM_REQUIRED | NativeConstants.ES_AWAYMODE_REQUIRED);
try
{
var standByScript = Path.Combine(Program.DataDir, "StandByScript.bat");
if (File.Exists(standByScript))
{
Utils.StartProcess(standByScript);
}

Logger.Debug("Powering off tv...");
var task = PowerOffOnShutdownOrResume(PowerOnOffState.StandBy);
Utils.WaitForTask(task);
Expand Down
76 changes: 71 additions & 5 deletions ColorControl/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 53 additions & 3 deletions ColorControl/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

Expand Down Expand Up @@ -1565,12 +1566,15 @@ private void LoadLog()
{
var filename = Path.Combine(_dataDir, "LogFile.txt");

var log = "No log file found";
var lines = new[] { "No log file found" };
if (File.Exists(filename))
{
log = File.ReadAllText(filename);
lines = File.ReadAllLines(filename);
}
edtLog.Text = log;
var reversedLines = lines.Reverse().ToList();
var builder = new StringBuilder();
reversedLines.ForEach(line => builder.AppendLine(line));
edtLog.Text = builder.ToString();
}

private void LoadInfo()
Expand Down Expand Up @@ -2433,5 +2437,51 @@ private void chkLgRemoteControlShow_CheckedChanged(object sender, EventArgs e)
scLgController.Panel2Collapsed = !chkLgRemoteControlShow.Checked;
_lgService.Config.ShowRemoteControl = chkLgRemoteControlShow.Checked;
}

private void mnuLgExpert_Opening(object sender, CancelEventArgs e)
{
mnuLgOLEDMotionPro.Visible = _lgService.SelectedDevice?.Name.Contains("C9") ?? _lgService.SelectedDevice?.Name.Contains("B9") ?? false;

if (mnuLgExpertBacklight.DropDownItems.Count == 0)
{
for (var i = 0; i <= 10; i++)
{
var name = (i * 10).ToString();

var item = mnuLgExpertBacklight.DropDownItems.Add(name);
item.Click += btnLgExpertBacklight_Click;
}
}
}

private void btnLgExpert_Click(object sender, EventArgs e)
{
mnuLgExpert.Show(btnLgExpert, btnLgExpert.PointToClient(Cursor.Position));
}

private void btnLgExpertBacklight_Click(object sender, EventArgs e)
{
var item = sender as ToolStripItem;
var backlight = int.Parse(item.Text);

_lgService.SelectedDevice?.SetBacklight(backlight);
}

private void miLgEnableMotionPro_Click(object sender, EventArgs e)
{
if (MessageForms.QuestionYesNo("Are you sure you want to enable OLED Motion Pro? This app and its creator are in no way accountable for any damages it may cause to your tv.") == DialogResult.Yes)
{
_lgService.SelectedDevice?.SetOLEDMotionPro("OLED Motion Pro");

MessageForms.InfoOk("Setting applied.");
}
}

private void miLgDisableMotionPro_Click(object sender, EventArgs e)
{
_lgService.SelectedDevice?.SetOLEDMotionPro("OLED Motion");

MessageForms.InfoOk("Setting applied.");
}
}
}
3 changes: 3 additions & 0 deletions ColorControl/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<metadata name="mnuAmdPresets.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>278, 17</value>
</metadata>
<metadata name="mnuLgExpert.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>583, 17</value>
</metadata>
<metadata name="mnuLgButtons.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>147, 17</value>
</metadata>
Expand Down
4 changes: 2 additions & 2 deletions ColorControl/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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.0.0.0")]
[assembly: AssemblyFileVersion("3.0.0.0")]
[assembly: AssemblyVersion("3.1.0.0")]
[assembly: AssemblyFileVersion("3.1.0.0")]
2 changes: 1 addition & 1 deletion ColorControl/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ public static Process GetProcessByName(string name, bool skipCurrent = true)
return null;
}

public static void StartProcess(string fileName, string arguments)
public static void StartProcess(string fileName, string arguments = null)
{
var process = Process.Start(fileName, arguments);
}
Expand Down
Loading

0 comments on commit 4614886

Please sign in to comment.