-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.php
More file actions
170 lines (130 loc) · 6.02 KB
/
settings.php
File metadata and controls
170 lines (130 loc) · 6.02 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
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
<?php
/*
* Settings Page for Module
*
* This is included into a full page wrapper to be displayed.
*/
?>
<!-- BEGIN FORM CONTENTS -->
<fieldset>
<input type="hidden" name="digital_path" value="<?php echo $moduleSettings['digital_path']; ?>">
<input type="hidden" name="analog_path" value="<?php echo $moduleSettings['analog_path']; ?>">
<!-- *************************************************************************** -->
<legend>Configure Digital Sensors</legend>
<p>(May still add a toggle variable here to turn this section on & off)</p>
<p>Some simple examples of digital events (On/Off, Open/shut) - Door open/close, Generator active/standby, Primary power available (vs running on generator), water sensor, fire sensor</p>
<div id="digitalWrap">
<?php
$digitalTypesArray = [
'door' => 'Door',
'fuel' => 'Fuel',
'water' => 'Water',
'fire' => 'Fire',
'solar' => 'Solar Charging',
'battery' => 'Battery'
];
// Hidden DIV to pass above array to JavaScript as json array
echo '<div id="digitalTypeArray" style="display:none;">' . json_encode($digitalTypesArray) . '</div>';
$idNumDigital = 1; // This will be replaced by a loop to load exsiting values
if ($moduleSettings['digital']) {
ksort($moduleSettings['digital']);
foreach($moduleSettings['digital'] as $cur_parent_array => $cur_child_array) { ?>
<p class="sensorRow<?php if ($idNumDigital == 1) { echo ' first'; } else { echo ' additional'; } ?>">
<span class="num">
<input type="hidden" name="digitalNum[]" value="<?php echo $idNumDigital; ?>">
<?php echo $idNumDigital; ?>
</span>
<span>
<input id="digitalLabel<?php echo $idNumDigital; ?>" type="text" name="digitalLabel[]" placeholder="Digital Label" value="<?php echo $cur_child_array['label']; ?>" class="digitalLabel" required>
<select id="digitalType<?php echo $idNumDigital; ?>" name="digitalType[]" class="digitalType" required>
<option>Select Type</option>
<?php
foreach($digitalTypesArray as $value => $label) {
if($cur_child_array['type'] == $value) { $sel_option = 'selected'; } else { $sel_option = ''; }
echo '<option value="'.$value.'" '.$sel_option.'>'.$label.'</option>';
}
?>
</select>
<input id="digitalGPIO<?php echo $idNumDigital; ?>" type="text" name="digitalGPIO[]" placeholder="GPIO" value="<?php echo $cur_child_array['gpio']; ?>" class="digitalGPIO" required>
<select id="digitalActive<?php echo $idNumDigital; ?>" name="digitalActive[]" class="digitalActive" required>
<?php
if($cur_child_array['active'] == 'low') {
echo '<option value="low" selected>Active Low</option>';
echo '<option value="high">Active High</option>';
} else {
echo '<option value="low">Active Low</option>';
echo '<option value="high" selected>Active High</option>';
}
?>
</select>
</span>
<?php if ($idNumDigital == 1) {
echo '<a href="#" id="addDigital" title="Add a digital sensor"><i class="icon-plus-sign"></i></a>';
} else {
echo '<a href="#" id="removeDigital" title="Remove this digital sensor"><i class="icon-minus-sign"></i></a>';
} ?>
</p>
<?php
$idNumDigital++;
}
} else {
echo "there are no digital sensors...";
}
?>
</div>
<div id="digitalCount"></div>
<br>
<!-- *************************************************************************** -->
<legend>Configure Analog Sensors</legend>
<p>(May still add a toggle variable here to turn this section on & off)</p>
<p>Some simple examples of Analog events (sliding scale inputs) - Fuel levels for generator, battery voltage, temperature, primary power supply voltage</p>
<div id="analogWrap">
<?php
$analogTypesArray = [
'temperature' => 'Temperature',
'battery_voltage' => 'Battery Voltage'
];
// Hidden DIV to pass above array to JavaScript as json array
echo '<div id="analogTypeArray" style="display:none;">' . json_encode($analogTypesArray) . '</div>';
$idNumAnalog = 1; // This will be replaced by a loop to load exsiting values
if ($moduleSettings['analog']) {
ksort($moduleSettings['analog']);
foreach($moduleSettings['analog'] as $cur_parent_array => $cur_child_array) { ?>
<p class="sensorRow<?php if ($idNumAnalog == 1) { echo ' first'; } else { echo ' additional'; } ?>">
<span class="num">
<input type="hidden" name="analogNum[]" value="<?php echo $idNumAnalog; ?>">
<?php echo $idNumAnalog; ?>
</span>
<span>
<input id="analogLabel<?php echo $idNumAnalog; ?>" type="text" name="analogLabel[]" placeholder="Analog Label" value="<?php echo $cur_child_array['label']; ?>" class="analogLabel" required>
<select id="analogType<?php echo $idNumDigital; ?>" name="analogType[]" class="analogType" required>
<option>Select Type</option>
<?php
foreach($analogTypesArray as $value => $label) {
if($cur_child_array['type'] == $value) { $sel_option = 'selected'; } else { $sel_option = ''; }
echo '<option value="'.$value.'" '.$sel_option.'>'.$label.'</option>';
}
?>
</select>
<input id="analogGPIO<?php echo $idNumAnalog; ?>" type="text" name="analogGPIO[]" placeholder="GPIO" value="<?php echo $cur_child_array['gpio']; ?>" class="analogGPIO" required>
<input id="analogHysterisis<?php echo $idNumAnalog; ?>" type="number" name="analogHysterisis[]" placeholder="Hysterisis" value="<?php echo $cur_child_array['hysterisis']; ?>" class="analogHysterisis" required>
</span>
<?php if ($idNumAnalog == 1) {
echo '<a href="#" id="addAnalog" title="Add a analog sensor"><i class="icon-plus-sign"></i></a>';
} else {
echo '<a href="#" id="removeAnalog" title="Remove this analog sensor"><i class="icon-minus-sign"></i></a>';
} ?>
</p>
<?php
$idNumAnalog++;
}
} else {
echo "there are no analog sensors...";
}
?>
</div>
<div id="analogCount"></div>
<br>
<!-- *************************************************************************** -->
</fieldset>
<!-- END FORM CONTENTS -->