forked from FalconChristmas/FPP-Plugin-Projector-Control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproj.php
executable file
·208 lines (161 loc) · 5.54 KB
/
proj.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/php
<?php
// pat added 3 lines below for debugging 2/4/2024
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
error_reporting(0); //commented out was in file pat 2/4/2024
//added Dec 3 2015
ob_implicit_flush();
$skipJSsettings = 1;
//include 'php_serial.class.php';
include 'PhpSerial.php'; //added as replacement pat 2/4/2024
include_once('projectorCommands.inc');
include_once 'functions.inc.php';
include_once 'commonFunctions.inc.php';
include_once '/opt/fpp/www/config.php';
include_once '/opt/fpp/www/common.php';
$logFile = $settings['logDirectory'] . "/".$pluginName.".log";
//$cfgServer="192.168.192.15";
$cfgPort="3001";
$cfgTimeOut=10;
$DEBUG=false;
$SERIAL_DEVICE="";
$callBackPid="";
$DEVICE = $pluginSettings['DEVICE'];
$DEVICE_CONNECTION_TYPE = $pluginSettings['PROJ_PROTOCOL'];
$IP = $pluginSettings['IP'];
$PORT = $pluginSettings['PORT'];
$ENABLED = urldecode($pluginSettings['ENABLED']);
$PROJECTOR = urldecode($pluginSettings['PROJECTOR']);
$PROJ_PASSWORD = urldecode($pluginSettings['PROJ_PASSWORD']);
logEntry("PROJECTOR: ".$PROJECTOR);
if(trim($PROJECTOR) == "") {
logEntry("No Projector configured in plugin, exiting");
exit(0);
}
if($ENABLED != "ON") {
logEntry("Plugin is DISABLED, exiting");
exit(0);
}
$options = getopt("c:");
$SERIAL_DEVICE="/dev/".$DEVICE;
if($options["z"] != "") {
$callBackPid = $options["z"];
}
logEntry("option C: ".$options["c"]);
$cmd= strtoupper(trim($options["c"]));
//@@@ is this needed? For loop initializes projectorIndex
$projectorIndex = 0;
//set the found flag, do not send a command if the name and command cannot be found
$PROJECTOR_FOUND=false;
for($projectorIndex=0;$projectorIndex<=count($PROJECTORS)-1;$projectorIndex++) {
if($PROJECTORS[$projectorIndex]['NAME'] == $PROJECTOR) {
logEntry("proj.php Projector found: ".$PROJECTOR);
logEntry("Looking for command string for cmd: ".$cmd);
foreach($PROJECTORS[$projectorIndex] as $key => $val) {
if(strtoupper(trim($key)) == $cmd) {
$PROJECTOR_FOUND=true;
$PROJECTOR_CMD = $val;
logEntry("--------------");
logEntry("PROJECTOR FOUND");
logEntry("PROJECTOR: ".$PROJECTOR);
if($PROJECTORS[$projectorIndex]['PROTOCOL'] == "PJLINK") {
$DEVICE_CONNECTION_TYPE = "PJLINK";
logEntry("PJLINK Projector");
if(trim($PROJECTORS[$projectorIndex]['IP']) != "") {
$IP= $PROJECTORS[$projectorIndex]['IP'];
}
if(trim($PROJECTORS[$projectorIndex]['PASSWORD']) != "") {
$PROJ_PASSWORD = $PROJECTORS[$projectorIndex]['PASSWORD'];
}
$PJLINK_CMD = $settings['pluginDirectory'] . "/" .$pluginName. "/pjlinkutil.pl ";
$PJLINK_CMD .= $IP." ";
$PJLINK_CMD .= $PROJECTOR_CMD." ";
$PJLINK_CMD .= "-p ".$PROJ_PASSWORD;
logEntry("PJLINK CMD: ".$PJLINK_CMD);
$PROJECTOR_CMD = $PJLINK_CMD;
} elseif ($PROJECTORS[$projectorIndex]['PROTOCOL'] == "TCP") {
$DEVICE_CONNECTION_TYPE = "IP";
logEntry("TCP/IP Projector");
if(trim($PROJECTORS[$projectorIndex]['IP']) != "") {
$IP= $PROJECTORS[$projectorIndex]['IP'];
}
if(trim($PROJECTORS[$projectorIndex]['PASSWORD']) != "") {
$PROJ_PASSWORD = $PROJECTORS[$projectorIndex]['PASSWORD'];
}
$PORT= $PROJECTORS[$projectorIndex]['PORT'];
logEntry("TCPIP IP: ".$IP." PORT: ".$PORT." CMD: ".$PROJECTOR_CMD);
} else {
if($pluginSettings['BAUD_RATE'] !="")
{
$PROJECTOR_BAUD = $pluginSettings['BAUD_RATE'];
} else {
$PROJECTOR_BAUD=$PROJECTORS[$projectorIndex]['BAUD_RATE'];
}
if($pluginSettings['CHAR_BITS'] !="")
{
$PROJECTOR_CHAR_BITS = $pluginSettings['CHAR_BITS'];
} else {
$PROJECTOR_CHAR_BITS=$PROJECTORS[$projectorIndex]['CHAR_BITS'];
}
if($pluginSettings['STOP_BITS'] !="")
{
$PROJECTOR_STOP_BITS = $pluginSettings['STOP_BITS'];
} else {
$PROJECTOR_STOP_BITS=$PROJECTORS[$projectorIndex]['STOP_BITS'];
}
if($pluginSettings['PARITY'] !="")
{
$PROJECTOR_PARITY = $pluginSettings['PARITY'];
} else {
$PROJECTOR_PARITY=$PROJECTORS[$projectorIndex]['PARITY'];
}
logEntry("BAUD RATE: ".$PROJECTOR_BAUD);
logEntry("CHAR BITS: ".$PROJECTOR_CHAR_BITS);
logEntry("STOP BITS: ".$PROJECTOR_STOP_BITS);
logEntry("PARITY: ".$PROJECTOR_PARITY);
}
}
}
}
}
if(!$PROJECTOR_FOUND) {
logEntry("projector command not found: exiting");
exit(0);
}
logEntry("-------");
$PCMD = hex_dump($PROJECTOR_CMD, $newline="\n");
logEntry("Sending command");
logEntry("HEX DECODED COMMAND: ".$PCMD);
switch ($DEVICE_CONNECTION_TYPE) {
case "PJLINK":
logEntry("Sending PJLINK Command");
logEntry("PJLINK CMD: ".$PROJECTOR_CMD);
system($PROJECTOR_CMD,$PJLINK_RESULT);
logEntry("PJLINK RESULT: ".$PJLINK_RESULT[0]);
exit(0);
break;
case "SERIAL":
logEntry("Sending SERIAL COMMAND");
logEntry("SERIAL DEVICE: ".$SERIAL_DEVICE);
$serial = new phpSerial;
$serial->deviceSet($SERIAL_DEVICE);
$serial->confBaudRate($PROJECTOR_BAUD);
$serial->confParity($PROJECTOR_PARITY);
$serial->confCharacterLength($PROJECTOR_CHAR_BITS);
$serial->confStopBits($PROJECTOR_STOP_BITS);
$serial->deviceOpen();
$serial->sendMessage("$PROJECTOR_CMD");
sleep(1);
logEntry("RETURN DATA: ".hex_dump($serial->readPort()));
$serial->deviceClose();
exit(0);
break;
case "IP":
logEntry("SENDING IP COMMAND");
sendTCP($IP, $PORT, $PROJECTOR_CMD);
exit(0);
break;
}
?>