2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-05-04 20:17:45 +00:00

Slider on the room level added

git-svn-id: https://svn.fhem.de/fhem/trunk@1513 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2012-05-01 09:19:03 +00:00
parent f7b417d8eb
commit ba86d3fcb8
5 changed files with 124 additions and 55 deletions

View File

@ -17,21 +17,20 @@ export PATH
export LD_LIBRARY_PATH=$home/lib export LD_LIBRARY_PATH=$home/lib
export PERL5LIB=$home/lib/perl5/site_perl/5.12.2/mips-linux:$home/lib/perl5/site_perl/5.12.2:$home/lib/perl5/5.12.2/mips-linux:$home/lib/perl5/5.12.2 export PERL5LIB=$home/lib/perl5/site_perl/5.12.2/mips-linux:$home/lib/perl5/site_perl/5.12.2:$home/lib/perl5/5.12.2/mips-linux:$home/lib/perl5/5.12.2
########### START fhem-user
# let FHEM run as user boxusr80 by adding user fhem with uid of boxusr80 # let FHEM run as user boxusr80 by adding user fhem with uid of boxusr80
# Using this feature the following will not work: ping,WOL,lcd4linux # Using this feature the following will not work: ping,WOL,lcd4linux
# start fhem-user #id fhem > /dev/null 2>&1
id fhem > /dev/null 2>&1 #if [ "$?" -ne "0" ]; then
if [ "$?" -ne "0" ]; then # echo "user fhem does not exist. Adding it."
echo "user fhem does not exist. Adding it." # echo "fhem:any:1080:0:fhem:/home-not-used:/bin/sh" >>/var/tmp/passwd
echo "fhem:any:1080:0:fhem:/home-not-used:/bin/sh" >>/var/tmp/passwd #fi
fi #chown root ${home}/dfu-programmer
# end fhem-user #chmod 4755 ${home}/dfu-programmer
########### END fhem-user
# set file ownership # set file ownership, so that the webinterface can read it.
chown -R boxusr80 ${home}/log chown -R boxusr80 ${home}/log
chown -R boxusr80 ${home}/FHEM chown -R boxusr80 ${home}/FHEM
chown root ${home}/dfu-programmer
chmod 4755 ${home}/dfu-programmer
perl fhem.pl fhem.cfg perl fhem.pl fhem.cfg

View File

@ -8031,12 +8031,25 @@ KlikAanKlikUit, NEXA, CHACON, HomeEasy UK. <br> You need to define an RFXtrx433
<a name="webCmd"></a> <a name="webCmd"></a>
<li>webCmd<br> <li>webCmd<br>
Colon separated list of commands to be shown in the room overview for a Colon separated list of commands to be shown in the room overview for a
certain device. Example: certain device. On smallscreen devices only the first value is
accessible.<br>
If the first value references a command, for which "set
device ?" lists a number possible choices (e.g. desired-temp for FHT
devices), then a select widget will be displayed. If the values are
"slider,min,step,max", then a javascript driven slider is displayed. If
the command is state, then the value will be used as a command.<br>
Examples:
<ul> <ul>
attr lamp webCmd on:off:on-for-timer 10 attr lamp webCmd on:off:on-for-timer 10<br>
define d1 dummy<br>
attr d1 webCmd state<br>
attr d1 set setList state:on,off<br>
define d2 dummy<br>
attr d2 webCmd state<br>
attr d2 set setList state:slider,0,1,10<br>
</ul> </ul>
On smallscreen devices only the first value is accessible.<br> Note: this an attribute for the displayed device, not for the FHEMWEB
Note: this a device, not a FHEMWEB attribute. instance.
</li> </li>
<br> <br>

View File

@ -575,7 +575,8 @@ FW_digestCgi($)
} }
$cmd.=" $dev{$c}" if(defined($dev{$c})); $cmd.=" $dev{$c}" if(defined($dev{$c}));
$cmd.=" $arg{$c}" if(defined($arg{$c})); $cmd.=" $arg{$c}" if(defined($arg{$c}) &&
($arg{$c} ne "state" || $cmd !~ m/^set/));
$cmd.=" $val{$c}" if(defined($val{$c})); $cmd.=" $val{$c}" if(defined($val{$c}));
return $cmd; return $cmd;
} }
@ -669,7 +670,7 @@ FW_makeSelect($$$$)
my @al = sort map { s/:.*//;$_ } split(" ", $list); my @al = sort map { s/:.*//;$_ } split(" ", $list);
my $selEl = $al[0]; my $selEl = $al[0];
$selEl = $1 if($list =~ m/([^ ]*):slider,/); # if available $selEl = $1 if($list =~ m/([^ ]*):slider,/); # promote a slider if available
$selEl = "room" if($list =~ m/room:/); $selEl = "room" if($list =~ m/room:/);
FW_pO "<form method=\"get\" action=\"$FW_ME$FW_subdir\">"; FW_pO "<form method=\"get\" action=\"$FW_ME$FW_subdir\">";
@ -699,6 +700,7 @@ FW_doDetail($)
my $t = $defs{$d}{TYPE}; my $t = $defs{$d}{TYPE};
FW_pO "<div id=\"content\">"; FW_pO "<div id=\"content\">";
if($FW_ss) { # FS20MS2 special: on and off, is not the same as toggle if($FW_ss) { # FS20MS2 special: on and off, is not the same as toggle
my $webCmd = AttrVal($d, "webCmd", undef); my $webCmd = AttrVal($d, "webCmd", undef);
if($webCmd) { if($webCmd) {
@ -713,7 +715,7 @@ FW_doDetail($)
} }
} }
FW_pO "<table><tr><td>"; FW_pO "<table><tr><td>";
FW_makeSelect($d, "set", getAllSets($d),"set"); FW_makeSelect($d, "set", getAllSets($d), "set");
FW_makeTable($d, $defs{$d}); FW_makeTable($d, $defs{$d});
FW_pO "Readings" if($defs{$d}{READINGS}); FW_pO "Readings" if($defs{$d}{READINGS});
FW_makeTable($d, $defs{$d}{READINGS}); FW_makeTable($d, $defs{$d}{READINGS});
@ -913,7 +915,9 @@ FW_showRoom()
my %group; my %group;
foreach my $dev (@devs) { foreach my $dev (@devs) {
next if($defs{$dev}{TYPE} eq "weblink"); next if($defs{$dev}{TYPE} eq "weblink");
$group{AttrVal($dev, "group", $defs{$dev}{TYPE})}{$dev} = 1; foreach my $grp (split(",", AttrVal($dev, "group", $defs{$dev}{TYPE}))) {
$group{$grp}{$dev} = 1;
}
} }
# row counter # row counter
@ -952,26 +956,61 @@ FW_showRoom()
if(!$FW_ss) { if(!$FW_ss) {
FW_pO "</td>"; FW_pO "</td>";
if($cmdlist) { if($cmdlist) {
foreach my $cmd (split(":", $cmdlist)) { my @cList = split(":", $cmdlist);
FW_pH "cmd.$d=set $d $cmd$rf", ReplaceEventMap($d,$cmd,1),1,"col3"; my @rList = map { ReplaceEventMap($d,$_,1) } @cList;
my $firstIdx = 0;
# Special handling (slider, dropdown)
my $cmd = $cList[0];
if($allSets && $allSets =~ m/$cmd:([^ ]*)/) {
my $values = $1;
if($values =~ m/^slider,(.*),(.*),(.*)/) { ##### Slider
my ($min,$stp, $max) = ($1, $2, $3);
my $srf = $FW_room ? "&room=$FW_room" : "";
my $curr = ReadingsVal($d, $cmd, Value($d));
$cmd = "" if($cmd eq "state");
$curr=~s/[^\d\.]//g;
FW_pO "<td colspan='2'>".
"<div class='slider' id='slider.$d'>".
"<div class='handle'>$min</div></div>".
"</div>".
"<script type=\"text/javascript\">" .
"Slider(document.getElementById('slider.$d'),".
"'$min','$stp','$max','$curr',".
"'$FW_ME?cmd=set $d $cmd %$srf')".
"</script>".
"</td>";
$firstIdx=1;
} else { ##### Dropdown
$firstIdx=1;
my @tv = split(",", $values);
if($cmd eq "desired-temp") {
$txt = ReadingsVal($d, "measured-temp", "");
$txt =~ s/ .*//; # Cut off Celsius
$txt = sprintf("%2.1f", int(2*$txt)/2) if($txt =~ m/[0-9.-]/);
$txt = int($txt*20)/$txt if($txt =~ m/^[0-9].$/); # ???
} else {
$txt = Value($d);
$txt =~ s/$cmd //;
}
FW_pO "<td>".
FW_hidden("arg.$d", $cmd) .
FW_hidden("dev.$d", $d) .
($FW_room ? FW_hidden("room", $FW_room) : "") .
FW_select("val.$d", \@tv, $txt, "dropdown").
"</td><td>".
FW_submit("cmd.$d", "set").
"</td>";
}
} }
} elsif($allSets =~ m/ desired-temp:([^ ]*)/) { for(my $idx=$firstIdx; $idx < @cList; $idx++) {
my @tv = split(",", $1); FW_pH "cmd.$d=set $d $cList[$idx]$rf",
$txt = ReadingsVal($d, "measured-temp", ""); ReplaceEventMap($d,$cList[$idx],1),1,"col3";
$txt =~ s/ .*//; }
$txt = sprintf("%2.1f", int(2*$txt)/2) if($txt =~ m/[0-9.-]/);
$txt = int($txt*20)/$txt if($txt =~ m/^[0-9].$/);
FW_pO "<td>".
FW_hidden("arg.$d", "desired-temp") .
FW_hidden("dev.$d", $d) .
($FW_room ? FW_hidden("room", $FW_room) : "") .
FW_select("val.$d", \@tv,
ReadingsVal($d, "desired-temp", $txt),"fht") .
"</td><td>".
FW_submit("cmd.$d", "set").
"</td>";
} elsif($type eq "FileLog") { } elsif($type eq "FileLog") {
$row = FW_dumpFileLog($d, 1, $row); $row = FW_dumpFileLog($d, 1, $row);
@ -2021,20 +2060,21 @@ FW_FlushInform($)
CommandDelete(undef, $name); CommandDelete(undef, $name);
} }
###################
# Compute the state (==second) column
sub sub
FW_devState($$) FW_devState($$)
{ {
my ($d, $rf) = @_; my ($d, $rf) = @_;
my ($allSets, $hasOnOff, $cmdlist, $link); my ($hasOnOff, $cmdlist, $link);
my $webCmd = AttrVal($d, "webCmd", "");
my $webCmd = AttrVal($d, "webCmd", "");
my $allSets = " " . getAllSets($d) . " ";
my $state = $defs{$d}{STATE}; my $state = $defs{$d}{STATE};
$state = "" if(!defined($state)); $state = "" if(!defined($state));
my $txt = $state;
if(!$webCmd) { if(!$webCmd) {
$allSets = " " . getAllSets($d) . " ";
$hasOnOff = ($allSets =~ m/ on / && $allSets =~ m/ off /); $hasOnOff = ($allSets =~ m/ on / && $allSets =~ m/ off /);
my $em = AttrVal($d, "eventMap", ""); my $em = AttrVal($d, "eventMap", "");
@ -2048,14 +2088,16 @@ FW_devState($$)
} }
} }
my $txt = $state;
if(defined(AttrVal($d, "showtime", undef))) { if(defined(AttrVal($d, "showtime", undef))) {
my $v = $defs{$d}{READINGS}{state}{TIME}; my $v = $defs{$d}{READINGS}{state}{TIME};
$txt = $v if(defined($v)); $txt = $v if(defined($v));
} elsif($allSets && $allSets =~ m/ desired-temp:/) { } elsif($allSets =~ m/ desired-temp:/) {
$txt = ReadingsVal($d, "measured-temp", ""); $txt = ReadingsVal($d, "measured-temp", "");
$txt =~ s/ .*//; $txt =~ s/ .*//;
$txt .= "&deg;" $txt .= "&deg;";
$cmdlist = "desired-temp";
} else { } else {
my $icon; my $icon;

View File

@ -52,10 +52,22 @@ FW_delayedStart()
/*************** SLIDER **************/ /*************** SLIDER **************/
function function
Slider(slider, min, stp, max) Slider(slider, min, stp, max, curr, cmd)
{ {
var sh = slider.firstChild; var sh = slider.firstChild;
var lastX=-1, offX=-1, minX, maxX, val=-1; var lastX=-1, offX=0, maxX=0, val=-1;
function
init()
{
maxX = slider.offsetWidth-sh.offsetWidth;
if(curr) {
offX += curr*maxX/(max-min);
sh.innerHTML = curr;
sh.setAttribute('style', 'left:'+offX+'px;');
}
}
init();
function function
touchFn(e, fn) touchFn(e, fn)
@ -73,10 +85,8 @@ Slider(slider, min, stp, max)
var oldFn1 = document.onmousemove, oldFn2 = document.onmouseup, var oldFn1 = document.onmousemove, oldFn2 = document.onmouseup,
oldFn3 = document.ontouchmove, oldFn4 = document.ontouchend; oldFn3 = document.ontouchmove, oldFn4 = document.ontouchend;
if(offX == -1) { if(maxX == 0)
minX = offX = slider.offsetLeft; init();
maxX = minX+slider.offsetWidth-sh.offsetWidth;
}
lastX = e.clientX; lastX = e.clientX;
function function
@ -84,9 +94,9 @@ Slider(slider, min, stp, max)
{ {
var diff = e.clientX-lastX; lastX = e.clientX; var diff = e.clientX-lastX; lastX = e.clientX;
offX += diff; offX += diff;
if(offX < minX) offX = minX; if(offX < 0) offX = 0;
if(offX > maxX) offX = maxX; if(offX > maxX) offX = maxX;
val = min+((offX-minX)/(maxX-minX) * (max-min)); val = min+(offX/maxX * (max-min));
val = Math.floor(Math.floor(val/stp)*stp); val = Math.floor(Math.floor(val/stp)*stp);
sh.innerHTML = val; sh.innerHTML = val;
sh.setAttribute('style', 'left:'+offX+'px;'); sh.setAttribute('style', 'left:'+offX+'px;');
@ -98,7 +108,11 @@ Slider(slider, min, stp, max)
{ {
document.onmousemove = oldFn1; document.onmouseup = oldFn2; document.onmousemove = oldFn1; document.onmouseup = oldFn2;
document.ontouchmove = oldFn3; document.ontouchend = oldFn4; document.ontouchmove = oldFn3; document.ontouchend = oldFn4;
slider.nextSibling.setAttribute('value', val); if(cmd) {
document.location = cmd.replace('%',val);
} else {
slider.nextSibling.setAttribute('value', val);
}
}; };
}; };
@ -140,7 +154,7 @@ FW_selChange(sel, list, elName)
newEl.innerHTML= newEl.innerHTML=
'<div class="slider"><div class="handle">'+min+'</div></div>'+ '<div class="slider"><div class="handle">'+min+'</div></div>'+
'<input type="hidden" name="'+name+'" value="'+min+'">'; '<input type="hidden" name="'+name+'" value="'+min+'">';
Slider(newEl.firstChild, min, stp, max); Slider(newEl.firstChild, min, stp, max, undefined, undefined);
} else { } else {
newEl = document.createElement('select'); newEl = document.createElement('select');

View File

@ -32,8 +32,9 @@ div#dist { padding-top:0.3em; }
a img { border-style:none; } a img { border-style:none; }
.set,.attr { margin-bottom:5px; float:left; } .set,.attr { margin-bottom:5px; float:left; }
.slider { float:right; width:250px; height:26px; background:#F0F0D8; .slider { float:right; width:250px; height:26px; }
margin-left:10px; -moz-border-radius:8px; border-radius:8px; } .set .slider { margin-left:10px; background:#F0F0D8;
.handle { position:absolute; cursor:pointer; width:50px; height:20px; line-height:20px; -moz-border-radius:8px; border-radius:8px; }
.handle { position:relative; cursor:pointer; width:50px; height:20px; line-height:20px;
border:3px solid; color:#278727; text-align:center; } border:3px solid; color:#278727; text-align:center; }
.downText { margin-top:2px; } .downText { margin-top:2px; }