-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathPixelOverlay-Clock.php
More file actions
91 lines (75 loc) · 3.37 KB
/
Copy pathPixelOverlay-Clock.php
File metadata and controls
91 lines (75 loc) · 3.37 KB
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
#!/usr/bin/php
<?php
#############################################################################
# Setup some variables (this is the part you want to edit for font, color, etc.)
$host = "localhost"; # Host/ip of the FPP instance with the matrix
$name = "Matrix"; # PixelOverlay Model Name
$color = "#FF0000"; # Text Color (also names like 'red', 'blue', etc.)
$font = "Helvetica"; # Font Name
$size = 14; # Font size
$pos = "Center"; # Position: 'Center', 'L2R', 'R2L', 'T2B', 'B2T'
$pps = 5; # Pixels Per Second
$antiAlias = false; # Anti-Alias the text
#############################################################################
# This function will get called once per second and returns the text string
# to be displayed at that point in time.
function GetNextMessage() {
$msg = date("g:i:s");
return $msg;
}
function do_put($url, $data) {
//Initiate cURL.
$ch = curl_init($url);
//Tell cURL that we want to send a PUT request.
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
//Attach our encoded JSON string to the PUT fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Execute the request
$result = curl_exec($ch);
return $result;
}
#############################################################################
# setup a signal handler to clear the screen if ctrl-c is used to
# stop the script
$running = true;
declare(ticks=1); // PHP internal, make signal handling work
function signalHandler($signo) {
global $running;
$running = false;
}
pcntl_signal(SIGINT, 'signalHandler');
#############################################################################
# Main part of program
# Clear the block, probably not necessary
file_get_contents("http://$host/api/overlays/model/$name/clear");
# Enable the block (pass 2 for transparent mode, or 3 for transparent RGB)
$data = array( 'State' => 1 );
do_put("http://$host/api/overlays/model/$name/state",
json_encode($data));
# Loop forever (ie, you'll need to CTRL-C to stop this script or kill it)
while ($running) {
$msg = GetNextMessage();
$data = array('Message' => $msg,
'Color' => $color,
'Font' => $font,
'FontSize' => $size,
'AntiAlias' => $antiAlias,
'Position' => $pos,
'PixelsPerSecond' => $pps);
do_put("http://$host/api/overlays/model/$name/text",
json_encode($data));
sleep(1);
}
# Clear the block
file_get_contents("http://$host/api/overlays/model/$name/clear");
# Disable the block
$data = array('State' => 0);
do_put("http://$host/api/overlays/model/$name/state",
json_encode($data));
# Exit cleanly (shouldn't make it here with the above "while (1)" loop)
exit(0);
#############################################################################
?>