Skip to content

Commit 147a265

Browse files
committed
Added loop mode
-added loop mode for contiuous input of remote commands. -added help and loop command list
1 parent 5a66da7 commit 147a265

File tree

3 files changed

+234
-92
lines changed

3 files changed

+234
-92
lines changed

ConexusTS.lpr

Lines changed: 163 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{$IFDEF UNIX}{$IFDEF UseCThreads}
2222
cthreads,
2323
{$ENDIF}{$ENDIF}
24-
Classes, SysUtils, CustApp, StrUtils, TechniSatAPI
24+
Classes, SysUtils, CustApp, StrUtils, Keyboard, TechniSatAPI
2525
{ you can add units after this };
2626

2727
type
@@ -38,6 +38,7 @@ TApp = class(TCustomApplication)
3838
procedure HelpHint; virtual;
3939
procedure WaitPrint; virtual;
4040
procedure WaitClear; virtual;
41+
procedure ButtonRequest(URL: String; PIN: String; Button: Byte; INT_Timeout: Integer); virtual;
4142
end;
4243

4344
const
@@ -97,6 +98,7 @@ procedure TApp.DoRun;
9798
Buffer4: Integer;
9899
Buffer5: Integer;
99100
Buffer6: Integer;
101+
Buffer7: TKeyEvent;
100102

101103
begin
102104
//init variables
@@ -133,7 +135,7 @@ procedure TApp.DoRun;
133135
{$ENDIF}
134136

135137
// quick check parameters
136-
ErrorMsg:=CheckOptions('hbalnidu:p:c:s:t:r:', 'help build api license nobanner showbanner devicelist rcucommands url: pin: command: sendbutton: buttonstate: buttonrepeat:');
138+
ErrorMsg:=CheckOptions('hbalnidxu:p:c:s:t:r:oy', 'help build api license nobanner showbanner devicelist rcucommands url: pin: command: sendbutton: buttonstate: buttonrepeat: loop loopcommands');
137139
if (ErrorMsg<>'') or (ParamCount=0) then
138140
begin
139141
//write title banner
@@ -276,6 +278,61 @@ procedure TApp.DoRun;
276278
Exit;
277279
end;
278280

281+
//show loop command list
282+
if HasOption('y', 'loopcommands') then
283+
begin
284+
WriteLn('');
285+
WriteLn(' Key Name | Function ');
286+
WriteLn('----------|----------');
287+
WriteLn('0 |Button 0');
288+
WriteLn('1 |Button 1');
289+
WriteLn('2 |Button 2');
290+
WriteLn('3 |Button 3');
291+
WriteLn('4 |Button 4');
292+
WriteLn('5 |Button 5');
293+
WriteLn('6 |Button 6');
294+
WriteLn('7 |Button 7');
295+
WriteLn('8 |Button 8');
296+
WriteLn('9 |Button 9');
297+
WriteLn('UP |Up');
298+
WriteLn('DOWN |Down');
299+
WriteLn('LEFT |Left');
300+
WriteLn('RIGHT |Right');
301+
WriteLn('ENTER |OK');
302+
WriteLn('PAGE UP |Page up');
303+
WriteLn('PAGE DOWN |Page down');
304+
WriteLn('INSERT |Program up');
305+
WriteLn('DELETE |Program down');
306+
WriteLn('A |Audio');
307+
WriteLn('B |Back/Exit');
308+
WriteLn('E |EPG/SFI');
309+
WriteLn('H |HDMI');
310+
WriteLn('I |Info');
311+
WriteLn('L |TV/Radio list');
312+
WriteLn('M |Menu');
313+
WriteLn('N |Navigation');
314+
WriteLn('O |Option');
315+
WriteLn('P |PiP/PaP');
316+
WriteLn('R |Record');
317+
WriteLn('S |Standby');
318+
WriteLn('T |Teletext');
319+
WriteLn('V |Volume mute');
320+
WriteLn('X |Timer');
321+
WriteLn('Y |Still picture');
322+
WriteLn('Z |Zoom');
323+
WriteLn('F1 |Red');
324+
WriteLn('F2 |Green');
325+
WriteLn('F3 |Yellow');
326+
WriteLn('F4 |Blue');
327+
WriteLn('F5 |Rewind');
328+
WriteLn('F6 |Stop');
329+
WriteLn('F7 |Play/Pause');
330+
WriteLn('F8 |Forward wind');
331+
WriteLn(STR_Info+'All key mappings depend on a QWERTZ keyboard layout.');
332+
Terminate;
333+
Exit;
334+
end;
335+
279336
//check for existing command
280337
if HasOption('c', 'command') then
281338
begin
@@ -287,7 +344,7 @@ procedure TApp.DoRun;
287344
end
288345
else
289346
begin
290-
if not (HasOption('s', 'sendbutton')) then
347+
if not ((HasOption('s', 'sendbutton')) or (HasOption('o', 'loop'))) then
291348
begin
292349
WriteLn(STR_Error+'No command specified');
293350
HelpHint;
@@ -611,12 +668,80 @@ procedure TApp.DoRun;
611668
end
612669
else
613670
begin
614-
WriteLn(STR_Error+'No RCU code or button specified');
615-
HelpHint;
616-
Terminate;
617-
Exit;
671+
if not (HasOption('o', 'loop')) then
672+
begin
673+
WriteLn(STR_Error+'No RCU code or button specified');
674+
HelpHint;
675+
Terminate;
676+
Exit;
677+
end;
618678
end;
619679

680+
//start remote loop
681+
if HasOption('o', 'loop') then
682+
begin
683+
writeln(STR_Info+'Loop entered. Press a key for a remote action. Leave loop with [CTRL+C] or [ESC].');
684+
while true do
685+
begin
686+
InitKeyboard;
687+
if KeyPressed then
688+
begin
689+
Buffer7:=PollKeyEvent;
690+
{$IFDEF PROG_DEBUG}
691+
writeln(STR_Debug+KeyEventToString(Buffer7));
692+
{$ENDIF}
693+
case GetKeyEventCode(Buffer7) of
694+
283: begin writeln(STR_Info+'[ESC] Leaving loop.'); break; end;
695+
561: begin ButtonRequest(URL, PIN, 1, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(1)); end; //1
696+
818: begin ButtonRequest(URL, PIN, 2, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(2)); end; //2
697+
1075: begin ButtonRequest(URL, PIN, 3, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(3)); end; //3
698+
1332: begin ButtonRequest(URL, PIN, 4, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(4)); end; //4
699+
1589: begin ButtonRequest(URL, PIN, 5, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(5)); end; //5
700+
1846: begin ButtonRequest(URL, PIN, 6, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(6)); end; //6
701+
2103: begin ButtonRequest(URL, PIN, 7, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(7)); end; //7
702+
2360: begin ButtonRequest(URL, PIN, 8, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(8)); end; //8
703+
2617: begin ButtonRequest(URL, PIN, 9, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(9)); end; //9
704+
2864: begin ButtonRequest(URL, PIN, 0, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(0)); end; //0
705+
20736: begin ButtonRequest(URL, PIN, 64, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(64)); end; //page down
706+
18688: begin ButtonRequest(URL, PIN, 63, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(63)); end; //page up
707+
20480: begin ButtonRequest(URL, PIN, 31, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(31)); end; //down
708+
18432: begin ButtonRequest(URL, PIN, 30, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(30)); end; //up
709+
19200: begin ButtonRequest(URL, PIN, 34, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(34)); end; //left
710+
19712: begin ButtonRequest(URL, PIN, 35, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(35)); end; //right
711+
7181: begin ButtonRequest(URL, PIN, 36, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(36)); end; //ok
712+
12654: begin ButtonRequest(URL, PIN, 62, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(62)); end; //nav
713+
12909: begin ButtonRequest(URL, PIN, 32, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(32)); end; //menu
714+
11386: begin ButtonRequest(URL, PIN, 45, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(45)); end; //zoom
715+
6512: begin ButtonRequest(URL, PIN, 44, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(44)); end; //pip/pap
716+
9064: begin ButtonRequest(URL, PIN, 47, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(47)); end; //hdmi
717+
6255: begin ButtonRequest(URL, PIN, 41, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(41)); end; //option
718+
5236: begin ButtonRequest(URL, PIN, 25, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(25)); end; //teletext
719+
12386: begin ButtonRequest(URL, PIN, 20, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(20)); end; //back
720+
5993: begin ButtonRequest(URL, PIN, 29, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(29)); end; //info
721+
4709: begin ButtonRequest(URL, PIN, 23, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(23)); end; //epg
722+
9836: begin ButtonRequest(URL, PIN, 33, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(33)); end; //tv/radio
723+
8051: begin ButtonRequest(URL, PIN, 11, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(11)); end; //standby
724+
12150: begin ButtonRequest(URL, PIN, 12, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(12)); end; //mute
725+
7777: begin ButtonRequest(URL, PIN, 21, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(21)); end; //audio
726+
11640: begin ButtonRequest(URL, PIN, 67, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(67)); end; //timer
727+
5497: begin ButtonRequest(URL, PIN, 22, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(22)); end; //still
728+
20992: begin ButtonRequest(URL, PIN, 18, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(18)); end; //prog+
729+
21248: begin ButtonRequest(URL, PIN, 19, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(19)); end; //prog-
730+
15104: begin ButtonRequest(URL, PIN, 37, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(37)); end; //red
731+
15360: begin ButtonRequest(URL, PIN, 38, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(38)); end; //green
732+
15616: begin ButtonRequest(URL, PIN, 39, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(39)); end; //yellow
733+
15872: begin ButtonRequest(URL, PIN, 40, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(40)); end; //blue
734+
16128: begin ButtonRequest(URL, PIN, 49, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(49)); end; //rewind
735+
16384: begin ButtonRequest(URL, PIN, 50, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(50)); end; //stop
736+
16640: begin ButtonRequest(URL, PIN, 51, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(51)); end; //play/pause
737+
16896: begin ButtonRequest(URL, PIN, 52, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(52)); end; //forward
738+
4978: begin ButtonRequest(URL, PIN, 43, INT_Timeout); writeln(STR_Info+tsapi_BtnDescByCode(43)); end; //record
739+
else writeln(STR_Info+'Unknown or not supported key '+IntToStr(GetKeyEventCode(Buffer7)));
740+
end;
741+
DoneKeyboard;
742+
end;
743+
end;
744+
end;
620745
// stop program loop
621746
Terminate;
622747
end;
@@ -646,13 +771,18 @@ procedure TApp.WriteHelp;
646771
WriteLn(' ', ExtractFileName(ExeName), ' --url=[IP or LOCAL DOMAIN] --pin=[DEVICE PIN] --command=[COMMAND]:[+/-VALUE]');
647772
WriteLn(' or');
648773
WriteLn(' ', ExtractFileName(ExeName), ' -u [IP or LOCAL DOMAIN] -p [DEVICE PIN] -c [COMMAND]:[+/-VALUE]');
774+
WriteLn(' or');
775+
WriteLn(' ', ExtractFileName(ExeName), ' --url=[IP or LOCAL DOMAIN] --pin=[DEVICE PIN] --loop');
776+
WriteLn(' or');
777+
WriteLn(' ', ExtractFileName(ExeName), ' -u [IP or LOCAL DOMAIN] -p [DEVICE PIN] -o');
649778
WriteLn('');
650779
WriteLn('General usage examples: ', ExtractFileName(ExeName), ' --url=192.168.0.34 --pin=1234 --sendbutton=BTN_OK');
651780
WriteLn(' ', ExtractFileName(ExeName), ' --url=192.168.0.34 --pin=1234 --command=DEVICEINFO');
652781
WriteLn(' ', ExtractFileName(ExeName), ' --url="@0008abcdef123456" -p 1234 -s 12');
653782
WriteLn(' ', ExtractFileName(ExeName), ' -u TECHNIVISTA-SL.fritz.box -p 9999 -c keepalive');
654783
WriteLn(' ', ExtractFileName(ExeName), ' -u "@TECHNIBOX UHD S" -p 1234 -s 12');
655784
WriteLn(' ', ExtractFileName(ExeName), ' --url=192.168.0.34 -p 1234 -s BTN_1 --buttonstate="pressed" --buttonrepeat=2');
785+
WriteLn(' ', ExtractFileName(ExeName), ' --url=192.168.0.34 -p 1234 -o');
656786
WriteLn(' ', ExtractFileName(ExeName), ' --url=192.168.0.34 -p 1234 --command="zoom:-2"');
657787
WriteLn(' ', ExtractFileName(ExeName), ' --url=192.168.0.34 -p 1234 --command="mousemove:-15:10"');
658788
WriteLn(' ', ExtractFileName(ExeName), ' --url=192.168.0.34 -p 1234 --command="mouseclick:left"');
@@ -677,9 +807,12 @@ procedure TApp.WriteHelp;
677807
WriteLn('TEXT: Send a text when virtual keyboard is open. Add /CR and the end of the text for sending an ENTER.');
678808
WriteLn('');
679809
WriteLn('Program functions:');
680-
WriteLn('Special commands ', ExtractFileName(ExeName), ' -c (--command)');
810+
WriteLn('Special commands: ', ExtractFileName(ExeName), ' -c (--command)');
681811
WriteLn(' Send a special command.'+#13#10);
682-
WriteLn('Target device URL ', ExtractFileName(ExeName), ' -u (--URL)');
812+
WriteLn('Device list: ', ExtractFileName(ExeName), ' -d (--devicelist)');
813+
WriteLn(' Broadcast network scan of supported active devices if available.');
814+
WriteLn(' This scan may take up around to 5 seconds.'+#13#10);
815+
WriteLn('Target device URL: ', ExtractFileName(ExeName), ' -u (--url)');
683816
WriteLn(' This defines the target device URL adress. This might be a local IP or domain.');
684817
WriteLn(' Optionally the device name or serial can be used with a preceding @, for e.g. -u "@DIGIPLUS UHD S".');
685818
WriteLn(' The serial should start with 0008xxxxxxxxxxxx.');
@@ -689,17 +822,27 @@ procedure TApp.WriteHelp;
689822
WriteLn(' Using the device name is not recommended if more devices are using the same name within the ');
690823
WriteLn(' same network. In this case the IP or device serial should be preferred over the name.');
691824
WriteLn(' Using the name or serial instead of the IP slows down the RCU sendbutton process a little bit.'+#13#10);
692-
WriteLn('PIN ', ExtractFileName(ExeName), ' -p (--pin)');
825+
WriteLn('PIN: ', ExtractFileName(ExeName), ' -p (--pin)');
693826
WriteLn(' PIN for the authentication. The PIN can only be set in the target device.'+#13#10);
694-
WriteLn('Send RCU button ', ExtractFileName(ExeName), ' -s (--sendbutton)');
827+
WriteLn('Send RCU button: ', ExtractFileName(ExeName), ' -s (--sendbutton)');
695828
WriteLn(' Send a RCU button. URL and PIN are also required. See possible buttons with -r (--rcucommands).'+#13#10);
696-
WriteLn('Use button state ', ExtractFileName(ExeName), ' -t (--buttonstate)');
829+
WriteLn('RCU command list: ', ExtractFileName(ExeName), ' -x (--rcucommands)');
830+
WriteLn(' Show all available RCU commands with code, name and description.');
831+
WriteLn(' Button names start with "BTN_" but for compability issues also "KEY_" is allowed.');
832+
WriteLn(' For e.g. "KEY_OK" can be used as equal replacement for "BTN_OK".'+#13#10);
833+
WriteLn('Use button state: ', ExtractFileName(ExeName), ' -t (--buttonstate)');
697834
WriteLn(' Optionally defines a state for the to send RCU button.');
698835
WriteLn(' Allowed states are "pressed", "released" and "hold".');
699836
WriteLn(' Depending on the send RCU button the sendbutton command must be used twice');
700837
WriteLn(' one time with "pressed" and again with "released".'+#13#10);
701-
WriteLn('Use button repeat ', ExtractFileName(ExeName), ' -r (--buttonrepeat)');
838+
WriteLn('Use button repeat: ', ExtractFileName(ExeName), ' -r (--buttonrepeat)');
702839
WriteLn(' Optionally defines how often to send the same RCU button. Default is one time.'+#13#10);
840+
WriteLn('Loop: ', ExtractFileName(ExeName), ' -o (--loop)');
841+
WriteLn(' Enter loop mode. URL and PIN are also required.');
842+
WriteLn(' In loop mode it is possible to send continuously buttons to the target device via keyboard keys.');
843+
WriteLn(' The programm window must be in foreground/active to catch key presses.'+#13#10);
844+
WriteLn('Loop command list: ', ExtractFileName(ExeName), ' -y (--loopcommands)');
845+
WriteLn(' Show all available loop commands with with the mapped keyboard key.'+#13#10);
703846
WriteLn('Help: ', ExtractFileName(ExeName), ' -h (--help)');
704847
WriteLn(' Show this help text.'+#13#10);
705848
WriteLn('Build info: ', ExtractFileName(ExeName), ' -b (--build)');
@@ -712,13 +855,6 @@ procedure TApp.WriteHelp;
712855
WriteLn(' Just show the banner (overrides -n --nobanner).'+#13#10);
713856
WriteLn('License info: ', ExtractFileName(ExeName), ' -l (--license)');
714857
WriteLn(' Show license info.'+#13#10);
715-
WriteLn('Device list: ', ExtractFileName(ExeName), ' -d (--devicelist)');
716-
WriteLn(' Broadcast network scan of supported active devices if available.');
717-
WriteLn(' This scan may take up around to 5 seconds.'+#13#10);
718-
WriteLn('RCU command list: ', ExtractFileName(ExeName), ' -x (--rcucommands)');
719-
WriteLn(' Show all available RCU commands with code, name and description.');
720-
WriteLn(' Button names start with "BTN_" but for compability issues also "KEY_" is allowed.');
721-
WriteLn(' For e.g. "KEY_OK" can be used as equal replacement for "BTN_OK".'+#13#10);
722858
end;
723859

724860
procedure TApp.HelpHint;
@@ -740,6 +876,13 @@ procedure TApp.WaitClear;
740876
Write(StringOfChar(#8, Length(STR_Info)+Length(STR_WaitingMsg))+StringOfChar(' ', Length(STR_Info)+Length(STR_WaitingMsg)));
741877
end;
742878

879+
procedure TApp.ButtonRequest(URL: String; PIN: String; Button: Byte; INT_Timeout: Integer);
880+
//Simple sendbutton procedure without result check
881+
begin
882+
tsapi_rcuButtonRequest(URL, PIN, Button, tsapi_ButtonStates[0], INT_Timeout);
883+
tsapi_rcuButtonRequest(URL, PIN, Button, tsapi_ButtonStates[1], INT_Timeout);
884+
end;
885+
743886
var
744887
Application: TApp;
745888
begin

0 commit comments

Comments
 (0)