Skip to content

Commit

Permalink
try to wake device first when lookup fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Maassoft committed Feb 2, 2021
1 parent 48b13b1 commit 91fd44d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
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>1.5.2.0</ApplicationVersion>
<ApplicationVersion>1.5.3.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down
42 changes: 28 additions & 14 deletions ColorControl/LgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LgService

private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();

public string FriendlyScreenName { get; private set; }
//public string FriendlyScreenName { get; private set; }

public List<PnpDev> Devices { get; private set; }
public PnpDev SelectedDevice
Expand Down Expand Up @@ -53,16 +53,16 @@ public LgService(string dataDir, bool allowPowerOn)
LoadConfig();
LoadRemoteControlButtons();

foreach (var screen in Screen.AllScreens)
{
var name = screen.DeviceFriendlyName();
if (name.Contains("LG"))
{
FriendlyScreenName = name;
}
}
//foreach (var screen in Screen.AllScreens)
//{
// var name = screen.DeviceFriendlyName();
// if (name.Contains("LG"))
// {
// FriendlyScreenName = name;
// }
//}

RefreshDevices();
RefreshDevices(afterStartUp: true);
}

~LgService()
Expand Down Expand Up @@ -167,10 +167,23 @@ public void SaveRemoteControlButtons()
File.WriteAllText(_rcButtonsFilename, json);
}

public async Task RefreshDevices(bool connect = true)
public async Task RefreshDevices(bool connect = true, bool afterStartUp = false)
{
var devices = await Utils.GetPnpDevices(Config.DeviceSearchKey);
SetDevices(devices);

if (afterStartUp && SelectedDevice == null && Config.PowerOnAfterStartup && !string.IsNullOrEmpty(Config.PreferredMacAddress))
{
Logger.Debug("No device has been found, trying to wake it first...");

WakeSelectedDevice(Config.PreferredMacAddress);

await Task.Delay(4000);
await RefreshDevices();

return;
}

if (connect && SelectedDevice != null)
{
if (Config.PowerOnAfterStartup && _allowPowerOn)
Expand Down Expand Up @@ -374,11 +387,12 @@ internal async Task<bool> PowerOff()
return true;
}

internal void WakeSelectedDevice()
internal void WakeSelectedDevice(string macAddress = null)
{
if (SelectedDevice != null)
macAddress = macAddress == null ? SelectedDevice?.MacAddress : macAddress;
if (macAddress != null)
{
WOL.WakeFunction(SelectedDevice.MacAddress);
WOL.WakeFunction(macAddress);
_justWokeUp = true;
}
else
Expand Down
2 changes: 1 addition & 1 deletion ColorControl/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public MainForm(StartUpParams startUpParams)
}
catch (Exception e)
{
Debug.WriteLine(e);
Logger.Error("Error initializing LgService: " + e.ToLogString());
}

InitInfo();
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("1.5.2.0")]
[assembly: AssemblyFileVersion("1.5.2.0")]
[assembly: AssemblyVersion("1.5.3.0")]
[assembly: AssemblyFileVersion("1.5.3.0")]
8 changes: 4 additions & 4 deletions ColorControl/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ public static string GetDeviceProperty(PnpObject device, string propertyName)
object objValue;
string value = null;

foreach (var key in device.Properties.Keys)
{
Debug.WriteLine(key);
}
//foreach (var key in device.Properties.Keys)
//{
// Debug.WriteLine(key);
//}

if (device.Properties.TryGetValue(propertyName, out objValue))
{
Expand Down

0 comments on commit 91fd44d

Please sign in to comment.