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

64 lines
1.9 KiB
PHP

<?php include('partialpage/header.php');?>
<?php include('partialpage/sidebar.php');?>
<script>
$( document ).ready(function() {
if(typeof(EventSource) !== "undefined") {
var relaystatus = new EventSource("helperpage/analoginputupdate.php");
relaystatus.onmessage = function(event) {
obj = JSON.parse(event.data);
for (i = 0; i < 5; i++) {
voltage = (obj[i] * (10.00 / 1024)).toFixed(2);
current = (obj[i] * (20.00 / 1024)).toFixed(2);
$("#voltage" + (i+1)).text(voltage + " Volt");
$("#current" + (i+1)).text(current + " mA");
}
};
} else {
$("#error").text("browser not supported.");
}
});
</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>Analog Inputs</b></h1>
<br>
<div style="border:5px solid red; width:100px" class="w3-round"></div>
<br>
<p>Analog inputs on the board.</p>
</div>
<?php
function inputblock($number, $pin){
echo "<!-- analoginput $number -->";
echo "<div class='w3-row-padding' id='analog$number'>";
echo "<div class='w3-col m12 l4 w3-margin-bottom'>";
$command = "cat /sys/bus/iio/devices/iio:device0/in_voltage{$pin}_raw 2>&1";
$value = exec($command);
echo "<div class='w3-container w3-teal'>";
echo "<h2 class='w3-opacity'><b>Analoginput $number</b></h2>";
$voltage = round(($value * (10.00 / 1024)), 2);
$current = round(($value * (20.00 / 1024)), 2 );
echo "<div class='w3-half w3-center'><h1 id='voltage$number'>{$voltage} Volt</h1></div>";
echo "<div class='w3-half w3-center'><h1 id='current$number'>{$current} mA</h1></div>";
echo "</div></div></div>";
echo "\n";
}
inputblock("1", "0");
inputblock("2", "1");
inputblock("3", "2");
inputblock("4", "3");
?>
<!-- End page content -->
</div>
<?php include('partialpage/footer.php');?>