Skip to content

Commit fa530e6

Browse files
committed
Implement option to set HDMI input on system startup/resume and command line parameters
1 parent 502fd29 commit fa530e6

12 files changed

Lines changed: 299 additions & 66 deletions

File tree

LGTV Companion Service/LGTV Companion Service.vcxproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,32 @@
2323
<Keyword>Win32Proj</Keyword>
2424
<ProjectGuid>{fd236504-e0d5-44bf-a119-41634eabd159}</ProjectGuid>
2525
<RootNamespace>LGTVCompanionService</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
2727
</PropertyGroup>
2828
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2929
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
3030
<ConfigurationType>Application</ConfigurationType>
3131
<UseDebugLibraries>true</UseDebugLibraries>
32-
<PlatformToolset>v142</PlatformToolset>
32+
<PlatformToolset>v143</PlatformToolset>
3333
<CharacterSet>Unicode</CharacterSet>
3434
</PropertyGroup>
3535
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3636
<ConfigurationType>Application</ConfigurationType>
3737
<UseDebugLibraries>false</UseDebugLibraries>
38-
<PlatformToolset>v142</PlatformToolset>
38+
<PlatformToolset>v143</PlatformToolset>
3939
<WholeProgramOptimization>true</WholeProgramOptimization>
4040
<CharacterSet>Unicode</CharacterSet>
4141
</PropertyGroup>
4242
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4343
<ConfigurationType>Application</ConfigurationType>
4444
<UseDebugLibraries>true</UseDebugLibraries>
45-
<PlatformToolset>v142</PlatformToolset>
45+
<PlatformToolset>v143</PlatformToolset>
4646
<CharacterSet>Unicode</CharacterSet>
4747
</PropertyGroup>
4848
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
4949
<ConfigurationType>Application</ConfigurationType>
5050
<UseDebugLibraries>false</UseDebugLibraries>
51-
<PlatformToolset>v142</PlatformToolset>
51+
<PlatformToolset>v143</PlatformToolset>
5252
<WholeProgramOptimization>true</WholeProgramOptimization>
5353
<CharacterSet>Unicode</CharacterSet>
5454
</PropertyGroup>

LGTV Companion Service/Service.cpp

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ VOID WINAPI SvcMain(DWORD dwArgc, LPTSTR* lpszArgv)
331331

332332
SvcReportEvent(EVENTLOG_INFORMATION_TYPE, L"The service has started.");
333333

334+
DispatchSystemPowerEvent(SYSTEM_EVENT_BOOT);
335+
334336
// Wait until service stops
335337
WaitForSingleObject(ghSvcStopEvent, INFINITE);
336338

@@ -504,7 +506,6 @@ DWORD SvcCtrlHandler(DWORD dwCtrl, DWORD dwEventType, LPVOID lpEventData, LPVOI
504506
DispatchSystemPowerEvent(SYSTEM_EVENT_UNSURE);
505507
}
506508

507-
//copy paste from the STOP event below
508509
ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 20000);
509510

510511
do
@@ -720,31 +721,36 @@ void InitDeviceSessions()
720721

721722
SESSIONPARAMETERS params;
722723

724+
//DEVICEID
723725
params.DeviceId = item.key();
724726
s << params.DeviceId << ", ";
727+
//NAME
725728
if (item.value()["Name"].is_string())
726729
params.Name = item.value()["Name"].get<string>();
727-
s << params.Name << ", with IP ";
728-
730+
s << params.Name;
731+
//IP
732+
s << ", with IP ";
729733
if(item.value()["IP"].is_string())
730734
params.IP = item.value()["IP"].get<string>();
731735
s << params.IP << " initiated (";
732-
736+
//ENABLED
733737
if (item.value()["Enabled"].is_boolean())
734738
params.Enabled = item.value()["Enabled"].get<bool>();
735739
s << "Enabled:" << (params.Enabled?"yes":"no") << ", ";
736-
740+
//SUBNET AND WOL TYPE
737741
if (item.value()["Subnet"].is_string())
738742
params.Subnet = item.value()["Subnet"].get<string>();
739743
if (item.value()["WOL"].is_number())
740744
params.WOLtype = item.value()["WOL"].get<int>();
741745
s << "WOL:" << params.WOLtype << ", ";
742746
if (params.WOLtype == WOL_SUBNETBROADCAST && params.Subnet != "")
743747
s << "SubnetMask:" << params.Subnet << ", ";
748+
//PAIRING KEY
744749
if(item.value()["SessionKey"].is_string())
745750
params.SessionKey = item.value()["SessionKey"].get<string>();
746-
s << "Pairing key:" << (params.SessionKey =="" ? "n/a" : params.SessionKey) << ", MAC: ";
747-
751+
s << "PairingKey:" << (params.SessionKey == "" ? "n/a" : params.SessionKey);
752+
//MAC
753+
s << ", MAC: ";
748754
j = item.value()["MAC"];
749755
if (!j.empty() && j.size() > 0)
750756
{
@@ -756,22 +762,33 @@ void InitDeviceSessions()
756762
}
757763
else
758764
s << "n/a";
759-
s << ", HDMI input control:";
765+
//POWER OFF HDMI INPUT VERIFICATION
766+
s << ", VerifyHdmiInput:";
760767
if (item.value()["HDMIinputcontrol"].is_boolean())
761768
params.HDMIinputcontrol = item.value()["HDMIinputcontrol"].get<bool>();
762-
763769
if (item.value()["OnlyTurnOffIfCurrentHDMIInputNumberIs"].is_number())
764770
params.OnlyTurnOffIfCurrentHDMIInputNumberIs = item.value()["OnlyTurnOffIfCurrentHDMIInputNumberIs"].get<int>();
765771
if (params.HDMIinputcontrol) {
766772
s << params.OnlyTurnOffIfCurrentHDMIInputNumberIs;
767773
}
768774
else
769775
s << "off";
770-
s << ", Blank when idle:";
771-
776+
//SET HDMI INPUT ON BOOT/RESUME
777+
s << ", SetHdmiInput:";
778+
if (item.value()["SetHDMIInputOnResume"].is_boolean())
779+
params.SetHDMIInputOnResume = item.value()["SetHDMIInputOnResume"].get<bool>();
780+
if (item.value()["SetHDMIInputOnResumeToNumber"].is_number())
781+
params.SetHDMIInputOnResumeToNumber = item.value()["SetHDMIInputOnResumeToNumber"].get<int>();
782+
if (params.SetHDMIInputOnResume)
783+
{
784+
s << params.SetHDMIInputOnResumeToNumber;
785+
}
786+
else
787+
s << "off";
788+
//SCREEN BLANKING ON USER IDLE
789+
s << ", BlankOnIdle:";
772790
params.BlankWhenIdle = Prefs.BlankWhenIdle;
773791
params.BlankScreenWhenIdleDelay = Prefs.BlankScreenWhenIdleDelay;
774-
775792
if (params.BlankWhenIdle) {
776793
s << "on(";
777794
s << params.BlankScreenWhenIdleDelay;
@@ -1014,6 +1031,14 @@ void IPCThread(void)
10141031
param1 = APP_CMDLINE_SCREENON;
10151032
else if (param == "-screenoff")
10161033
param1 = APP_CMDLINE_SCREENOFF;
1034+
else if (param == "-sethdmi1")
1035+
param1 = APP_CMDLINE_SETHDMI1;
1036+
else if (param == "-sethdmi2")
1037+
param1 = APP_CMDLINE_SETHDMI2;
1038+
else if (param == "-sethdmi3")
1039+
param1 = APP_CMDLINE_SETHDMI3;
1040+
else if (param == "-sethdmi4")
1041+
param1 = APP_CMDLINE_SETHDMI4;
10171042
else if (param1 > 0)
10181043
{
10191044
if (param1 == APP_IPC_DAEMON)
@@ -1096,6 +1121,34 @@ void IPCThread(void)
10961121
device.Stop();
10971122

10981123
}
1124+
else if (param1 == APP_CMDLINE_SETHDMI1 && (id == param || name == param))
1125+
{
1126+
string w = "IPC, set HDMI input 1:";
1127+
w += param;
1128+
Log(w);
1129+
device.SystemEvent(SYSTEM_EVENT_FORCESETHDMI, 1);
1130+
}
1131+
else if (param1 == APP_CMDLINE_SETHDMI2 && (id == param || name == param))
1132+
{
1133+
string w = "IPC, set HDMI input 2:";
1134+
w += param;
1135+
Log(w);
1136+
device.SystemEvent(SYSTEM_EVENT_FORCESETHDMI, 2);
1137+
}
1138+
else if (param1 == APP_CMDLINE_SETHDMI1 && (id == param || name == param))
1139+
{
1140+
string w = "IPC, set HDMI input 3:";
1141+
w += param;
1142+
Log(w);
1143+
device.SystemEvent(SYSTEM_EVENT_FORCESETHDMI, 3);
1144+
}
1145+
else if (param1 == APP_CMDLINE_SETHDMI1 && (id == param || name == param))
1146+
{
1147+
string w = "IPC, set HDMI input 4:";
1148+
w += param;
1149+
Log(w);
1150+
device.SystemEvent(SYSTEM_EVENT_FORCESETHDMI, 4);
1151+
}
10991152
}
11001153
}
11011154

LGTV Companion Service/Service.h

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636

3737
#define APPNAME L"LGTV Companion"
38-
#define APPVERSION L"1.5.0"
38+
#define APPVERSION L"1.6.0"
3939
#define SVCNAME L"LGTVsvc"
4040
#define SVCDISPLAYNAME L"LGTV Companion Service"
4141
#define SERVICE_PORT "3000"
@@ -57,20 +57,22 @@
5757
#define THREAD_WAIT 1 // wait to spawn new thread (seconds)
5858
#define DIMMED_OFF_DELAY_WAIT 20 // delay after a screen dim request
5959
#define MAX_RECORD_BUFFER_SIZE 0x10000 // 64K
60-
#define SYSTEM_EVENT_SHUTDOWN 0x0001
61-
#define SYSTEM_EVENT_REBOOT 0x0002
62-
#define SYSTEM_EVENT_RESUME 0x0004
63-
#define SYSTEM_EVENT_RESUMEAUTO 0x0008
64-
#define SYSTEM_EVENT_SUSPEND 0x0010
65-
#define SYSTEM_EVENT_DISPLAYOFF 0x0020
66-
#define SYSTEM_EVENT_DISPLAYON 0x0040
67-
#define SYSTEM_EVENT_UNSURE 0x0080
68-
#define SYSTEM_EVENT_FORCEON 0x0100
69-
#define SYSTEM_EVENT_FORCEOFF 0x0200
70-
#define SYSTEM_EVENT_DISPLAYDIMMED 0x0400
71-
#define SYSTEM_EVENT_FORCESCREENOFF 0x0800
72-
#define SYSTEM_EVENT_USERBUSY 0x1000
73-
#define SYSTEM_EVENT_USERIDLE 0x2000
60+
#define SYSTEM_EVENT_SHUTDOWN 1
61+
#define SYSTEM_EVENT_REBOOT 2
62+
#define SYSTEM_EVENT_RESUME 3
63+
#define SYSTEM_EVENT_RESUMEAUTO 4
64+
#define SYSTEM_EVENT_SUSPEND 5
65+
#define SYSTEM_EVENT_DISPLAYOFF 6
66+
#define SYSTEM_EVENT_DISPLAYON 7
67+
#define SYSTEM_EVENT_UNSURE 8
68+
#define SYSTEM_EVENT_FORCEON 9
69+
#define SYSTEM_EVENT_FORCEOFF 10
70+
#define SYSTEM_EVENT_DISPLAYDIMMED 11
71+
#define SYSTEM_EVENT_FORCESCREENOFF 12
72+
#define SYSTEM_EVENT_USERBUSY 13
73+
#define SYSTEM_EVENT_USERIDLE 14
74+
#define SYSTEM_EVENT_FORCESETHDMI 15
75+
#define SYSTEM_EVENT_BOOT 16
7476

7577
#define APP_CMDLINE_ON 1
7678
#define APP_CMDLINE_OFF 2
@@ -79,6 +81,10 @@
7981
#define APP_CMDLINE_SCREENON 5
8082
#define APP_CMDLINE_SCREENOFF 6
8183
#define APP_IPC_DAEMON 7
84+
#define APP_CMDLINE_SETHDMI1 8
85+
#define APP_CMDLINE_SETHDMI2 9
86+
#define APP_CMDLINE_SETHDMI3 10
87+
#define APP_CMDLINE_SETHDMI4 11
8288

8389
#define WOL_NETWORKBROADCAST 1
8490
#define WOL_IPSEND 2
@@ -124,6 +130,8 @@ struct SESSIONPARAMETERS {
124130
int OnlyTurnOffIfCurrentHDMIInputNumberIs = 1;
125131
bool BlankWhenIdle = false;
126132
int BlankScreenWhenIdleDelay = 10;
133+
bool SetHDMIInputOnResume = false;
134+
int SetHDMIInputOnResumeToNumber = 1;
127135
};
128136

129137
class CSession {
@@ -133,16 +141,19 @@ class CSession {
133141
~CSession();
134142
void Run();
135143
void Stop();
136-
void SystemEvent(DWORD);
144+
void SystemEvent(DWORD, int param = 0);
137145
SESSIONPARAMETERS GetParams();
138146
bool IsBusy();
139147
private:
140148
time_t ScreenDimmedRequestTime = 0;
141149
bool ThreadedOpDisplayOn = false;
142150
bool ThreadedOpDisplayOff = false;
151+
bool ThreadedOpDisplaySetHdmiInput = false;
143152
time_t ThreadedOpDisplayOffTime = 0;
144153
void TurnOnDisplay(void);
145154
void TurnOffDisplay(bool forced, bool dimmed, bool blankscreen);
155+
void SetDisplayHdmiInput(int HdmiInput);
156+
146157
SESSIONPARAMETERS Parameters;
147158
};
148159

@@ -166,6 +177,8 @@ std::wstring widen(std::string);
166177
std::string narrow(std::wstring);
167178
void DisplayPowerOnThread(SESSIONPARAMETERS *, bool *, int);
168179
void DisplayPowerOffThread(SESSIONPARAMETERS*, bool *, bool, bool);
180+
void SetDisplayHdmiInputThread(SESSIONPARAMETERS*, bool*, int, int);
181+
169182
void IPCThread(void);
170183
void WOLthread(SESSIONPARAMETERS*, bool*, int);
171184
std::vector<std::string> stringsplit(std::string str, std::string token);

0 commit comments

Comments
 (0)