From 479c12b5a4c778b43ec21325e7bd1b8510efe429 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sun, 4 Aug 2019 20:03:37 +0000 Subject: [PATCH] fhemweb.js: implement the bitfield widget, used in ZWave (Forum #102579) git-svn-id: https://svn.fhem.de/fhem/trunk@19950 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/10_ZWave.pm | 16 +++++++++++-- fhem/www/pgm2/console.js | 2 +- fhem/www/pgm2/fhemweb.js | 50 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/fhem/FHEM/10_ZWave.pm b/fhem/FHEM/10_ZWave.pm index 02d3c9ce2..025571557 100644 --- a/fhem/FHEM/10_ZWave.pm +++ b/fhem/FHEM/10_ZWave.pm @@ -2689,6 +2689,7 @@ ZWave_configParseModel($;$) } my $partial=""; + my $bsHelp=""; while($gz->gzreadline($line)) { last if($line =~ m+^\s*+); if($line =~ m/^\s*,) { + $bsHelp = "Bit $1: "; + next; + } if($line =~ m,, && $line !~ m,,) { # Multiline Help $partial = $line; next; } if($partial) { if($line =~ m,,) { - $line = $partial.$line; + $line = $bsHelp.$partial.$line; $line =~ s/[\r\n]//gs; $partial = ""; + $bsHelp=""; } else { $partial .= $line; next; } } - $hash{$cmdName}{Help} .= "$1
" if($line =~ m+(.*)+s); + if($line =~ m+(.*)+s) { + $hash{$cmdName}{Help} .= "$bsHelp$1
"; + $bsHelp=""; + } if($line =~ m/^\s*{Item}}) if($h->{Item}); $zwave_cmdArgs{set}{$caName} = "noArg" if($h->{type} eq "button"); + $zwave_cmdArgs{set}{$caName} = "bitfield,".$h->{size}*8 + if($h->{type} eq "bitset"); $zwave_cmdArgs{get}{$caName} = "noArg"; } diff --git a/fhem/www/pgm2/console.js b/fhem/www/pgm2/console.js index 50089dc5f..8fe89f3c2 100644 --- a/fhem/www/pgm2/console.js +++ b/fhem/www/pgm2/console.js @@ -64,7 +64,7 @@ consUpdate(evt) var rTab = {'<':'<', '>':'>',' ':' '}; var isTa = $("#console").is("textarea"); // 102773 new_content = new_content.replace(/(.*)
[\r\n]/g, function(all,p1) { - return p1.replace(/[<> ]/g, function(a){return rTab[a]})+(isTa ? "\n" : "
"); + return p1.replace(/[<> ]/g, function(a){return rTab[a]})+(isTa?"\n":"
"); }); $("#console").append(new_content); diff --git a/fhem/www/pgm2/fhemweb.js b/fhem/www/pgm2/fhemweb.js index fc6c4288d..abc2df79d 100644 --- a/fhem/www/pgm2/fhemweb.js +++ b/fhem/www/pgm2/fhemweb.js @@ -36,7 +36,7 @@ var FW_widgets = { textField: { createFn:FW_createTextField }, textFieldNL: { createFn:FW_createTextField, second:true }, "textField-long": { createFn:FW_createTextField, second:true }, - "textFieldNL-long":{ createFn:FW_createTextField, second:true } + bitfield: { createFn:FW_createBitfield }, }; window.onbeforeunload = function(e) @@ -1828,6 +1828,49 @@ FW_createMultiple(elName, devName, vArr, currVal, set, params, cmd) return newEl; } +function +FW_createBitfield(elName, devName, vArr, currVal, set, params, cmd) +{ + if(vArr[0] != "bitfield") + return undef; + elName = elName.replace(/[^A-Z0-9_]/ig, '_'); + var fieldSize = (vArr.length == 1 ? 8 : parseInt(vArr[1])); + var html = '
'+ + ''+ + ''; + for(var fs=fieldSize; fs>0; ) { + html += '\n'; + } + html += '
Bit '+fs+''; + for(var i1=0; i1<8 && fs>0; i1++, fs--) + html += ''; + html += '
'; + var newEl = $(html).get(0); + + newEl.activateFn = function() { + $("#"+elName+"_bitfield input").change(function(){ + var total = 0; + $("#"+elName+"_bitfield input").each(function(){ + if($(this).is(":checked")) { + var sv = parseInt($(this).attr("value"))-1, thisVal=1; + while(sv) { thisVal *= 2; sv--; } // << works on signed 32bit values + total += thisVal; + } + }); + $("[name="+elName+"]").val(total); + }); + } + + newEl.setValueFn = function(arg) { + var total = parseInt(arg); + for(var i1=1; i1<=fieldSize; i1++) { + $('#'+elName+'_bitfield input[value='+i1+']') + .prop("checked", (total%2 == 1)); + total = parseInt(total/2); + } + }; + return newEl; +} /*************** WIDGETS END **************/ @@ -1982,6 +2025,8 @@ FW_getSVG(emb) exponent, e.g. 0.0625.
  • select,<val1>,<val2>,... - show a dropdown with all values. NOTE: this is also the fallback, if no modifier is found.
  • +
  • bitfield,<size> - show a table of checkboxes (8 per line) + to set single bits. Default for size is 8.
  • =end html @@ -2012,6 +2057,9 @@ FW_getSVG(emb)
  • select,<val1>,<val2>,... - zeigt ein HTML select mit allen Werten. Achtung: so ein Widget wird auch dann angezeigt, falls kein passender Modifier gefunden wurde.
  • +
  • bitfield,<size> - zeigt eine Tabelle von Kontrollkästchen (8 + pro Zeile), um einzelne Bits setzen zu koennen. Die Voreinstellung fuer + size ist 8.
  • =end html_DE