Logic Machine Forum
Javascript, use value of the main knx object and display a icon - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Javascript, use value of the main knx object and display a icon (/showthread.php?tid=2311)



Javascript, use value of the main knx object and display a icon - equalizer - 30.10.2019

Greetings.

Im have a bit wise encoded knx objects (lots).  I would like to bitmask part out and animate a icon via the remaining part but have become stuck at the point of selecting the icons attached. 

Is it possible to select what icon is displayed (from a normal animated icon), eg if "faults" value = 0 show one icon 1 to 5 show a diffecent icon, >5 show another?  Or an I going down a dead end here and just create/calculate numeric ranges in the icon animation.

Baised from the "Group Address value in SVG icon" example
$(function(){
  $('.faultIcon').each(function(i, el) {
    var $el = $(el), addr = $el.data('object'); // or 'status-object'

    grp.listen(addr, function(obj) {
     var faults  =   obj.value & 3F000000;
     faults = faults >> 24;
     ?????????? 
    });

  });
});



Robert.


RE: Javascript, use value of the main knx object and display a icon - admin - 31.10.2019

You can use "Additional icons" to assign specific value to an icon. I suggest using virtual objects to display fault status values instead of Custom JS.


RE: Javascript, use value of the main knx object and display a icon - equalizer - 31.10.2019

I made a script spawn the hundereds of virtual group addresses in the end.

I guess the question is can custom JS "intercept" the knx value and process it before the browser selects what icon to display from the Aditional icons list?


RE: Javascript, use value of the main knx object and display a icon - admin - 31.10.2019

Another approach is to use image element, attach object listeners in Custom JS and change img src depending on the value.


RE: Javascript, use value of the main knx object and display a icon - equalizer - 05.11.2019

(31.10.2019, 14:24)admin Wrote: Another approach is to use image element, attach object listeners in Custom JS and change img src depending on the value.
Is that using a .lp file and creating a canvas to display the icon?  I started digging into that aproach and it started to get a little complex even with the image url paths hard coded :-)  I may have another look at that though as I didnt know about the object listener aproch I was also trying to make a custom basic client server via url parmiters data link happen...


RE: Javascript, use value of the main knx object and display a icon - admin - 06.11.2019

You don't need .lp files for that. Go to Scripting > Tools > Edit custom JavaScript. Here's an example of changing image based on value: https://forum.logicmachine.net/showthread.php?tid=2253&pid=14121#pid14121