Refresh rate implementation

pull/183/head
Karai Csaba 9 years ago committed by cskarai
parent 8a44d16ae0
commit ec6dc0c4c3
  1. 16
      examples/dummy-web-server.pl
  2. BIN
      examples/web-server/GZipped.html.gz
  3. 10
      examples/web-server/Voltage.html
  4. 21
      html/userpage.js

@ -423,6 +423,17 @@ sub process_user_comm_led
return content_response($r, $http->{url});
}
sub process_user_comm_voltage
{
my ($http) = @_;
my $voltage = (((time - $startTime) % 60) - 30) / 30.0 + 4.0;
$voltage = sprintf("%.2f V", $voltage);
my $r = '{"voltage": "' . $voltage . '"}';
return content_response($r, $http->{url});
}
sub process_user_comm()
{
my ($http) = @_;
@ -431,4 +442,9 @@ sub process_user_comm()
{
return process_user_comm_led($http);
}
if( $http->{url} eq '/Voltage.html.json' )
{
return process_user_comm_voltage($http);
}
}

@ -0,0 +1,10 @@
<meta name="refresh-rate" content="500" />
<div class="header">
<h1>Voltage measurement</h1>
</div>
<div class="content">
<p id="voltage" align="center" style="font-size: 800%"/>
</div>
</body></html>

@ -1,6 +1,8 @@
//===== Java script for user pages
var loadCounter = 0;
var refreshRate = 0;
var refreshTimer;
function notifyResponse( data )
{
@ -42,6 +44,14 @@ function notifyResponse( data )
}
}
});
if( refreshRate != 0 )
{
clearTimeout(refreshTimer);
refreshTimer = setTimeout( function () {
ajaxJson("GET", window.location.pathname + ".json?reason=refresh", notifyResponse );
}, refreshRate );
}
}
function notifyButtonPressed( btnId )
@ -101,6 +111,17 @@ document.addEventListener("DOMContentLoaded", function(){
};
}
// collect metas
var metas = document.getElementsByTagName("meta");
for (ndx = 0; ndx < metas.length; ndx++) {
var meta = metas[ndx];
if( meta.getAttribute("name") == "refresh-rate" )
{
refreshRate = meta.getAttribute("content");
}
}
// load variables at first time
var loadVariables = function() {
ajaxJson("GET", window.location.pathname + ".json?reason=load", notifyResponse,

Loading…
Cancel
Save