Added: radio button implementation

pull/183/head
Karai Csaba 9 years ago committed by cskarai
parent a8fad5b265
commit 8a44d16ae0
  1. 14
      examples/dummy-web-server.pl
  2. 43
      examples/web-server/LED.html
  3. 23
      html/userpage.js

@ -12,7 +12,7 @@ my $ledLabel : shared = "LED is turned off";
my $ledFreq : shared = 10; my $ledFreq : shared = 10;
my @ledHistory : shared; my @ledHistory : shared;
my $startTime : shared = time; my $startTime : shared = time;
my $pattern : shared = "50_50";
# auto-flush on socket # auto-flush on socket
$| = 1; $| = 1;
@ -401,13 +401,21 @@ sub process_user_comm_led
if( exists $http->{postArgs}{frequency} ) if( exists $http->{postArgs}{frequency} )
{ {
$ledFreq = $http->{postArgs}{frequency}; $ledFreq = $http->{postArgs}{frequency};
led_add_history("Set LED frequency to $ledFreq Hz"); led_add_history("Set frequency to $ledFreq Hz");
}
if( exists $http->{postArgs}{pattern} )
{
$pattern = $http->{postArgs}{pattern};
my $out = $pattern;
$out =~ s/_/\% - /;
$out .= "%";
led_add_history("Set pattern to $out");
} }
return simple_response(204, "OK"); return simple_response(204, "OK");
} }
elsif( $http->{urlArgs}{reason} eq "load" ) elsif( $http->{urlArgs}{reason} eq "load" )
{ {
$loadData = ', "frequency": ' . $ledFreq; $loadData = ', "frequency": ' . $ledFreq . ', "pattern": "' . $pattern . '"';
} }
my $list = ", \"led_history\": [" . join(", ", map { "\"$_\"" } @ledHistory ) . "]"; my $list = ", \"led_history\": [" . join(", ", map { "\"$_\"" } @ledHistory ) . "]";

@ -3,21 +3,32 @@
</div> </div>
<div class="content"> <div class="content">
<p> <div class="pure-g"><div class="pure-u-1 pure-u-md-1-2">
<button id="btn_on" type="button">Turn on</button> <div class="card">
<button id="btn_blink" type="button">Start blinking</button> <h1>Control</h1>
<button id="btn_off" type="button">Turn off</button> <button id="btn_on" type="button">Turn on</button>
</p> <button id="btn_blink" type="button">Start blinking</button>
<p id="text"/> <button id="btn_off" type="button">Turn off</button>
<p> <p id="text"/>
<form> </div>
Frequency: <div class="card">
<input type="range" name="frequency" min="1" max="25"> <h1>Frequency and pattern</h1>
<input type="submit"> <form>
</form> <b>Pattern:</b><br/>
</p> <input type="radio" name="pattern" value="25_75">25% on 75% off</input><br/>
<p> <input type="radio" name="pattern" value="50_50">50% on 50% off</input><br/>
<ul id="led_history"/> <input type="radio" name="pattern" value="75_25">75% on 25% off</input><br/>
</p>
<b>Frequency:</b><br/>
<input type="range" name="frequency" min="1" max="25"><br/>
<input type="submit">
</form>
</div></div>
<div class="pure-u-1 pure-u-md-1-2">
<div class="card" style="min-height: 400px">
<h1>Logs</h1>
<ul id="led_history"/>
</div>
</div></div>
</div> </div>
</body></html> </body></html>

@ -12,7 +12,14 @@ function notifyResponse( data )
var el = elems[ndx]; var el = elems[ndx];
if(el.tagName == "INPUT") if(el.tagName == "INPUT")
{ {
el.value = data[v]; if( el.type == "radio" )
{
el.checked = data[v] == el.value;
}
else
{
el.value = data[v];
}
} }
} }
var elem = document.getElementById(v); var elem = document.getElementById(v);
@ -20,18 +27,18 @@ function notifyResponse( data )
{ {
if(elem.tagName == "P" || elem.tagName == "DIV") if(elem.tagName == "P" || elem.tagName == "DIV")
{ {
elem.innerHTML = data[v]; elem.innerHTML = data[v];
} }
if(elem.tagName == "UL" || elem.tagName == "OL") if(elem.tagName == "UL" || elem.tagName == "OL")
{ {
var list = data[v]; var list = data[v];
var html = ""; var html = "";
for (var i=0; i<list.length; i++) { for (var i=0; i<list.length; i++) {
html = html.concat("<li>" + list[i] + "</li>"); html = html.concat("<li>" + list[i] + "</li>");
} }
elem.innerHTML = html; elem.innerHTML = html;
} }
} }
}); });
@ -49,8 +56,8 @@ function refreshFormData()
notifyResponse(resp); notifyResponse(resp);
if( loadCounter > 0 ) if( loadCounter > 0 )
{ {
loadCounter--; loadCounter--;
refreshFormData(); refreshFormData();
} }
} ); } );
} , 250); } , 250);

Loading…
Cancel
Save