Files
H1502_website/input.php
Martijn Scheepers 8dd7dbd045 more red spacer fixes
2017-11-16 15:29:06 +01:00

90 lines
2.8 KiB
PHP

<?php include('partialpage/header.php');?>
<?php include('partialpage/sidebar.php');?>
<script>
$( document ).ready(function() {
if(typeof(EventSource) !== "undefined") {
var inputstatus = new EventSource("helperpage/inputstatus.php");
inputstatus.onmessage = function(event) {
obj = JSON.parse(event.data);
for (i = 0; i < 8; i++) {
htmlcode = "<div class='w3-col m12 l4 w3-margin-bottom'>";
if (obj[i] == "1"){
htmlcode = htmlcode + "<div class='w3-container w3-red'>";
}else if(obj[i] == "0"){
htmlcode = htmlcode + "<div class='w3-container w3-green'>";
}else{
htmlcode = htmlcode + "<div class='w3-container w3-orange'>";
htmlcode = htmlcode + "<h1>Error: " + obj[i] + "</h1>";
}
htmlcode = htmlcode + "<h2 class='w3-opacity'><b>Input " + (i+1) + "</b></h2>";
if(obj[i] == "1"){
htmlcode = htmlcode + "<img src='/images/open-switch.png' alt='Switch Open' style='width:50%'><h3>Open</h3>";
}else if(obj[i] == "0"){
htmlcode = htmlcode + "<img src='/images/closed-switch.png' alt='Switch Closed' style='width:50%'><h3>Closed</h3>";
}
htmlcode = htmlcode + "</div></div>";
$("#input" + (i+1)).html(htmlcode);
}
};
} else {
$("#error").text("browser not supported, no auto updates");
}
});
</script>
<!-- !PAGE CONTENT! -->
<div class="w3-main" style="margin-left:340px;margin-right:40px">
<!-- Input Header -->
<div class="w3-container" id="Inputs" style="margin-top:75px">
<h1 class="w3-jumbo"><b>Inputs</b></h1>
<br>
<div style="border:5px solid red; width:100px" class="w3-round"></div>
<br>
<p>Inputs on the board.</p>
</div>
<?php
function inputblock($number, $pin){
echo "<!-- input $number -->";
echo "<div class='w3-row-padding' id='input$number'>";
echo "<div class='w3-col m4 w3-margin-bottom'>";
$command = "cat /sys/class/gpio/pioA$pin/value 2>&1";
$value = exec($command);
if ($value == "1"){
echo "<div class='w3-container w3-red'>";
}elseif($value == "0"){
echo "<div class='w3-container w3-green'>";
}else{
echo "<div class='w3-container w3-orange'>";
echo "<h1>Error: $value </h1>";
}
echo "<h2 class='w3-opacity'><b>Input $number</b></h2>";
if($value == "1"){
echo "<img src='/images/open-switch.png' alt='Switch Open' style='width:50%'><h3>Open</h3>";
}elseif($value == "0"){
echo "<img src='/images/closed-switch.png' alt='Switch Closed' style='width:50%'><h3>Closed</h3>";
}
echo "</div></div></div>";
echo "\n";
}
inputblock("1", "29");
inputblock("2", "28");
inputblock("3", "27");
inputblock("4", "26");
inputblock("5", "25");
inputblock("6", "24");
inputblock("7", "23");
inputblock("8", "22");
?>
<!-- End page content -->
</div>
<?php include('partialpage/footer.php');?>