-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_setup.php
275 lines (226 loc) · 10.7 KB
/
plugin_setup.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
<?php
//$DEBUG=true;
include_once "/opt/fpp/www/common.php";
include_once "functions.inc.php";
include_once 'commonFunctions.inc.php';
$pluginName = "FPP-GPIO-Toggle";
$pluginVersion = "1.0";
//$DEBUG=true;
$myPid = getmypid();
$gitURL = "https://github.com/jaredb7/FPP-GPIO-Toggle.git";
$pluginUpdateFile = $settings['pluginDirectory'] . "/" . $pluginName . "/" . "pluginUpdate.inc";
$logFile = $settings['logDirectory'] . "/" . $pluginName . ".log";
logEntry("plugin update file: " . $pluginUpdateFile);
if (isset($_POST['updatePlugin'])) {
$updateResult = updatePluginFromGitHub($gitURL, $branch = "master", $pluginName);
echo $updateResult . "<br/> \n";
}
if (isset($_POST['submit'])) {
WriteSettingToFile("ENABLED", urlencode($_POST["ENABLED"]), $pluginName);
WriteSettingToFile("TOGGLE_TIME", urlencode($_POST["TOGGLE_TIME"]), $pluginName);
}
sleep(1);
$TOGGLE_TIME = 1000;
$pluginConfigFile = $settings['configDirectory'] . "/plugin." . $pluginName;
if (file_exists($pluginConfigFile)) {
$pluginSettings = parse_ini_file($pluginConfigFile);
$ENABLED = $pluginSettings['ENABLED'];
$TOGGLE_TIME = $pluginSettings['TOGGLE_TIME'];
}
//$ENABLED = ReadSettingFromFile('ENABLED', $pluginName);
//$CNTRL_LIST = array_map('trim', explode(",", $pluginSettings['CNTRL_LIST']));
//$CNTRL_LOG_FILE = urldecode($pluginSettings['CNTRL_LOG_FILE']);
//Set a default value
//if (trim($CNTRL_LOG_FILE) == "") {
// $CNTRL_LOG_FILE = "/tmp/FPP.GPIO-Toggle.log";
//}
?>
<html>
<head>
<script>
function ToggleGpio(gpio_pin, toggle, toggleval, toggletime) {
//set default toggle time if none set
if (typeof toggletime === 'undefined' || toggletime === null) {
//set default
toggletime = 1000
}
//default to toggle
if (typeof toggle === 'undefined' || toggle === null) {
//set default
toggle = true
}
var xmlhttp = new XMLHttpRequest();
var url = "fppxml.php?command=extGPIO&gpio=" + gpio_pin + "&mode=Output&val=" + toggleval;
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send();
//If we should actually toggle
if (toggle) {
//sleep then toggle
setTimeout(
function () {
//invert the output value
if (toggleval === 0) {
toggleval = 1
} else {
toggleval = 0
}
url = "fppxml.php?command=extGPIO&gpio=" + gpio_pin + "&mode=Output&val=" + toggleval;
//Toggle back
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send();
}
, toggletime);
}
}
</script>
</head>
<div id="GPIO-Toggle" class="settings">
<fieldset>
<legend>FPP-GPIO-Toggle Support Instructions</legend>
<p>Known Issues:
<ul>
<li>None</li>
</ul>
<p>Configuration:
<ul>
<li>This plugin uses the GPIO Outputs set under Channel Outputs and allows you to control them directly via the web interface</li>
<li>1. Setup Your GPIO Output under <a href="http://<? echo $_SERVER['SERVER_NAME'] ?>/channeloutputs.php#tab-other">Channel Outputs</a> > Other
</li>
<li>2. Return here and there should be buttons to toggle the state of the GPIO Output, it will toggle from
the current setting to either LOW or HIGH depending on the current GPIO value.
</li>
<li>3. Optionally Set the toggle time (delay between on and off), default 2000ms ( 2 seconds )</li>
</ul>
<p>
<p>To report a bug, please file it against the FPP-GPIO-Toggle plugin project on Git: <?echo $gitURL?></p>
<form method="post"
action="http://<? echo $_SERVER['SERVER_NAME'] ?>/plugin.php?plugin=<? echo $pluginName; ?>&page=plugin_setup.php">
<?
$restart = 0;
$reboot = 0;
echo "<b>ENABLE PLUGIN:</b> ";
//if($ENABLED== 1 || $ENABLED == "on") {
// echo "<input type=\"checkbox\" checked name=\"ENABLED\"> \n";
PrintSettingCheckbox(" Plugin" . $pluginName, "ENABLED", $restart = 0, $reboot = 0, "ON", "OFF", $pluginName, $callbackName = "");
// } else {
// echo "<input type=\"checkbox\" name=\"ENABLED\"> \n";
//}
?>
<br>
<br>
<b>Toggle Time (in ms)</b>
<input type="text" size="15" value="<? if ($TOGGLE_TIME != "") {
echo $TOGGLE_TIME;
} else {
echo "2000";
} ?>" name="TOGGLE_TIME" id="TOGGLE_TIME">
<small>Set the toggle time (delay between on and off)</small>
<br>
<br>
<input id="submit_button" name="submit" type="submit" class="buttons" value="Save Config">
<br>
<br>
<?
if (file_exists($pluginUpdateFile)) {
//echo "updating plugin included";
include $pluginUpdateFile;
}
?>
</form>
<br>
<br>
<h3>GPIO Outputs</h3>
<table id="tblGpioOutputs" class="channelOutputTable">
<tr class="tblheader">
<td width="5%" align="left">Output #</td>
<td width="10%" align="left">Active</td>
<td width="10%" align="left">Output Type</td>
<td width="10%" align="left">FPP Start Channel</td>
<td width="5%" align="left">Inverted</td>
<td width="10%" align="left">Current Value</td>
<td width="10%" align="left">Toggle</td>
</tr>
<?
//Read the channelouputs file in the root of the fpp storage media
// ./channeloutputs
//Write a copy locally as well
$channeloutputs_file_contents = file_get_contents($settings['co-other']);
//Explode the contents by new lines first, then process each fo the entries separately
//$exploded_channel_output_data = explode("\n", $channeloutputs_file_contents);
$exploded_channel_output_data = json_decode($channeloutputs_file_contents,true);
//loop over each line and extract info
foreach ($exploded_channel_output_data['channelOutputs'] as $channel_config_data) {
// $channel_config_explode = explode(",", $channel_config_data);
//first entry is if that output is enabled or now
$channel_enabled = $channel_config_data['enabled'];
//channel type
$channel_type = $channel_config_data['type'];
//channel start
$channel_start_channel = $channel_config_data['startChannel'];
//channel length/range
$channel_length = $channel_config_data['channelCount'];
//gpio & invert
//$channel_gpio_pin = explode("=", explode(";", $channel_config_explode[4])[0])[1];
$channel_gpio_pin = $channel_config_data['gpio'];
//$channel_gpio_invert = explode("=", explode(";", $channel_config_explode[4])[1])[1];
$channel_gpio_invert = $channel_config_data['invert'];
//get current GPIO value, so we have somewhere to start the toggle
//use a different method for the BBB
if ($settings['Platform'] == "BeagleBone Black"){
$current_gpio_value = shell_exec("cat /sys/class/gpio/gpio$channel_gpio_pin/value");
}else{
$current_gpio_value = shell_exec("/usr/local/bin/gpio -g read $channel_gpio_pin");
}
// attempt to only set valid values
if (isset($current_gpio_value) && in_array($current_gpio_value, array('1', '0'))) {
$toggle_output_val = $current_gpio_value;
} else{
$toggle_output_val = 0;
}
//if the channel should be inverted start with a LOW (opposite of the current value), it'll toggle LOW then HIGH
//basically toggle opposite
if ($channel_gpio_invert == 1) {
$toggle_output_val = 0;
}
//If enabled generate a button
if (strtolower($channel_type) == 'gpio') {
?>
<tr class="rowGpioDetails <? echo $channel_enabled == 0 ? 'rowDisabled' : '' ?>">
<td align="center"><? echo $channel_gpio_pin ?></td>
<td align="center"><? echo $channel_enabled == 1 ? '<b>Yes</b>' : 'No' ?></td>
<td align="center"><? echo $channel_type ?></td>
<td align="center"><? echo $channel_start_channel ?></td>
<td align="center"><? echo $channel_gpio_invert == 1 ? 'Yes' : 'No' ?></td>
<td align="center"><? echo $current_gpio_value == 1 ? 'HIGH (1)' : 'LOW (0)' ?></td>
<td>
<input class="button"
onClick="ToggleGpio(<? echo $channel_gpio_pin; ?>,true,<? echo $toggle_output_val; ?>,<? echo $TOGGLE_TIME; ?>);"
type="submit"
value="Toggle Pin #<? echo $channel_gpio_pin; ?>"
<? echo $channel_enabled == 0 ? 'disabled' : '' ?>
/>
<input class="button"
onClick="ToggleGpio(<? echo $channel_gpio_pin; ?>,false,0,0);"
type="submit"
value="Set LOW Pin #<? echo $channel_gpio_pin; ?>"
<? echo $channel_enabled == 0 ? 'disabled' : '' ?>
/>
<input class="button"
onClick="ToggleGpio(<? echo $channel_gpio_pin; ?>,false,1,0);"
type="submit"
value="Set HIGH Pin #<? echo $channel_gpio_pin; ?>"
<? echo $channel_enabled == 0 ? 'disabled' : '' ?>
/>
</td>
</tr>
<?
}
}
?>
</table>
</fieldset>
</div>
<br/>
</html>