forked from LightsOnHudson/FPP-Plugin-Matrix-Message
-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.inc.php
executable file
·372 lines (279 loc) · 9.47 KB
/
functions.inc.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<?php
include_once dirname(__FILE__) . "/../fpp-matrixtools/scripts/matrixtools.php.inc";
function outputMessages($queueMessages) {
global $DEBUG, $pluginDirectory,$MESSAGE_TIMEOUT, $fpp_matrixtools_Plugin, $fpp_matrixtools_Plugin_Script,$Matrix,$MATRIX_FONT,$MATRIX_FONT_SIZE,$MATRIX_PIXELS_PER_SECOND,$COLOR, $INCLUDE_TIME, $TIME_FORMAT, $HOUR_FORMAT,$SEPARATOR, $MATRIX_FONT_ANTIALIAS, $waitForScroll,$DURATION,$overlayMode;
//print_r($queueMessages);
if($DEBUG)
logEntry("MESSAGE QUEUE: Inside function ".__METHOD__,0,__FILE__,__LINE__);
if (count($queueMessages) <=0) {
logEntry("No messages to output ");
return;
}
If (strtoupper(trim($COLOR)) == "RANDOM") {
//print_r ("Start counter");
$counter=rand(0,5);
//print_r ("Start switch");
switch ($counter) {
case "0":
$mycolor = "indigo";
//echo $mycolor;
break;
case "1":
$mycolor = "red";
//echo $mycolor;
break;
case "2":
$mycolor = "green";
//echo $mycolor;
break;
case "3":
$mycolor = "blue";
//echo $mycolor;
break;
case "4":
$mycolor = "yellow";
//echo $mycolor;
break;
case "5":
$mycolor = "purple";
//echo $mycolor;
break;
}
logEntry("MATRIX MESSAGE: Selecting RANDOM COLOR: ".$mycolor);
//print_r ("End switch");
$COLOR=($mycolor);
//print_r ($COLOR);
}
$auto = "false";
if ($waitForScroll == false) {
if ($overlayMode == 1) {
$auto = "Enabled";
} else if ($overlayMode == 2) {
$auto = "Transparent";
}
if ($overlayMode == 3) {
$auto = "Transparent RGB";
}
}
if ($auto == "false") {
enableMatrixToolOutput($Matrix);
}
for ($i=0;$i<=count($queueMessages)-1;$i++) {
$messageText = "";
if($INCLUDE_TIME == 1 || $INCLUDE_TIME == "on") {
switch ($HOUR_FORMAT) {
case "12":
$messageTime = date($TIME_FORMAT);
break;
case "24":
$messageTime = date($TIME_FORMAT);
break;
}
logEntry( "Message time: ".$messageTime);
$messageText = "Time: ".$messageTime." ".$SEPARATOR." ";
}
$messageParts = explode("|",$queueMessages[$i]);
//echo "0: ".$messageParts[0]."\n";
//echo "1: ".$messageParts[1]."\n";
//echo "2: " .$messageParts[2]."\n";
//echo "3: ".$messageParts[3]."\n";
$messageText .= urldecode($messageParts[1]);
logEntry("MATRIX PLUGIN: Writing last read for plugin BEFORE sending Message!: ".urldecode($messageParts[2]). ": ".urldecode($messageParts[0]));
WriteSettingToFile("LAST_READ",urldecode($messageParts[0]),urldecode($messageParts[2]));
$MATRIX_PIXELS_PER_SECOND = intval($MATRIX_PIXELS_PER_SECOND);
$MATRIX_FONT_SIZE = intval($MATRIX_FONT_SIZE);
$Position = "R2L";
if ($MATRIX_PIXELS_PER_SECOND == 0) {
$Position = "Center";
}
// echo "$Matrix, $messageText, $Position, $MATRIX_FONT, $MATRIX_FONT_SIZE, $COLOR, $MATRIX_PIXELS_PER_SECOND, $MATRIX_FONT_ANTIALIAS";
DisplayTextOnModel("localhost", $Matrix, $messageText, $Position, $MATRIX_FONT, $MATRIX_FONT_SIZE, $COLOR, $MATRIX_PIXELS_PER_SECOND, $MATRIX_FONT_ANTIALIAS, $DURATION, $auto);
if ($waitForScroll) {
if ($Position != "Center") {
$isLocked = GetModelData("localhost", $Matrix)["isLocked"];
while ($isLocked) {
sleep(1);
$isLocked = GetModelData("localhost", $Matrix)["isLocked"];
}
} else {
sleep($DURATION);
}
}
}
if ($waitForScroll == true) {
disableMatrixToolOutput($Matrix);
}
}
function getInstalledPlugins($host) {
include_once 'excluded_plugins.inc.php';
if ($host == "") {
$host = "localhost";
}
$ch = curl_init("http://" . $host . "/api/plugin");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$pluginsInstalled = json_decode($data, true);
$pluginList = [];
for($i=0;$i<=count($pluginsInstalled)-1;$i++) {
if(in_array($pluginsInstalled[$i],$EXCLUDE_PLUGIN_ARRAY)) {
continue;
}
$pluginList[$pluginsInstalled[$i]]=$pluginsInstalled[$i];
}
//error_log( $test = var_dump($pluginList), 0);
return $pluginList;
}
function getScrollSpeed(){
$MAX_PIXELS_PER_SECOND = 200;
for($i=0;$i<=$MAX_PIXELS_PER_SECOND;$i++) {
$scrollSpeed[$i]= $i;
}
return $scrollSpeed;
}
function getDuration(){
$MAX_DURATION = 300;
for($i=1;$i<=$MAX_DURATION;$i++) {
$maxDuration[$i]= $i;
}
return $maxDuration;
}
function getFontSizes(){
$maxFontSize = 80;
for($i=5; $i<=$maxFontSize; $i++) {
$fontSize[$i]=$i;
}
return $fontSize;
}
function getFontsInstalled() {
$fontsList = GetFonts("localhost"); // this uses the fpp-matrix tools plugin to get the fonts that it can use!
for($i=1;$i<=count($fontsList)-1;$i++) {
$installedFonts[$fontsList[$i]]=$fontsList[$i];
}
return $installedFonts;
}
//is fppd running?????
function isFPPDRunning() {
$FPPDStatus=null;
logEntry("Checking to see if fpp is running...");
exec("if ps cax | grep -i fppd; then echo \"True\"; else echo \"False\"; fi",$output);
if($output[1] == "True" || $output[1] == 1 || $output[1] == "1") {
$FPPDStatus = "RUNNING";
}
//print_r($output);
return $FPPDStatus;
//interate over the results and see if avahi is running?
}
//get current running playlist
function getRunningPlaylist() {
global $sequenceDirectory;
$playlistName = null;
$i=0;
//can we sleep here????
//sleep(10);
//FPPD is running and we shoud expect something back from it with the -s status query
// #,#,#,Playlist name
// #,1,# = running
$currentFPP = file_get_contents("/tmp/FPP.playlist");
logEntry("Reading /tmp/FPP.playlist : ".$currentFPP);
if($currentFPP == "false") {
logEntry("We got a FALSE status from fpp -s status file.. we should not really get this, the daemon is locked??");
}
$fppParts="";
$fppParts = explode(",",$currentFPP);
// logEntry("FPP Parts 1 = ".$fppParts[1]);
//check to see the second variable is 1 - meaning playing
if($fppParts[1] == 1 || $fppParts[1] == "1") {
//we are playing
$playlistParts = pathinfo($fppParts[3]);
$playlistName = $playlistParts['basename'];
logEntry("We are playing a playlist...: ".$playlistName);
} else {
logEntry("FPPD Daemon is starting up or no active playlist.. please try again");
}
//now we should have had something
return $playlistName;
}
function logEntry($data,$logLevel=1, $sourceFile = "", $sourceLine = "") {
global $logFile,$myPid, $LOG_LEVEL;
if($logLevel <= $LOG_LEVEL)
//return
if($sourceFile == "") {
$sourceFile = $_SERVER['PHP_SELF'];
}
$data = $sourceFile." : [".$myPid."] ".$data;
if($sourceLine !="") {
$data .= " (Line: ".$sourceLine.")";
}
$logWrite= fopen($logFile, "a") or die("Unable to open file!");
fwrite($logWrite, date('Y-m-d h:i:s A',time()).": ".$data."\n");
fclose($logWrite);
}
function processCallback($argv) {
global $DEBUG,$pluginName;
if($DEBUG)
print_r($argv);
$registrationType = $argv[2];
$data = $argv[4];
logEntry("PROCESSING CALLBACK: ".$registrationType);
$clearMessage=FALSE;
switch ($registrationType)
{
case "media":
if($argv[3] == "--data")
{
$data=trim($data);
logEntry("DATA: ".$data);
$obj = json_decode($data);
$type = $obj->{'type'};
logEntry("Type: ".$type);
switch ($type) {
case "sequence":
logEntry("media sequence name received: ");
processSequenceName($obj->{'Sequence'},"STATUS");
break;
case "media":
logEntry("We do not support type media at this time");
//$songTitle = $obj->{'title'};
//$songArtist = $obj->{'artist'};
//sendMessage($songTitle, $songArtist);
//exit(0);
break;
case "both":
logEntry("We do not support type media/both at this time");
// logEntry("MEDIA ENTRY: EXTRACTING TITLE AND ARTIST");
// $songTitle = $obj->{'title'};
// $songArtist = $obj->{'artist'};
// if($songArtist != "") {
// sendMessage($songTitle, $songArtist);
//exit(0);
break;
default:
logEntry("We do not understand: type: ".$obj->{'type'}. " at this time");
exit(0);
break;
}
}
break;
exit(0);
case "playlist":
logEntry("playlist type received");
if($argv[3] == "--data")
{
$data=trim($data);
logEntry("DATA: ".$data);
$obj = json_decode($data);
$sequenceName = $obj->{'sequence0'}->{'Sequence'};
$sequenceAction = $obj->{'Action'};
processSequenceName($sequenceName,$sequenceAction);
//logEntry("We do not understand: type: ".$obj->{'type'}. " at this time");
// logEntry("We do not understand: type: ".$obj->{'type'}. " at this time");
}
break;
exit(0);
default:
exit(0);
}
}
?>