Help with MMM-PIR-Sensor tvservice logical evaluation



  • Can someone help shed some light on this piece of code in the MMM-PIR-Sensor module? In the node_helper.js there is:

          // Check if hdmi output is already on
          exec("/opt/vc/bin/tvservice -s").stdout.on('data', function(data) {
            if (data.indexOf("0x120002") !== -1)
              exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null);
    

    I understand what it is doing. It is checking if the monitor is in standby [TV is off] and if so then it turns it on. This bit of code also executes when the monitor is on though which is the part that I am having trouble with. I understand that 0x120002 is what tvservice reports when the monitor is off. I don’t understand the!== -1

    Any help? I would like to change the logic so it doesn’t execute that line when the monitor is on (0x12000a)



  • @orayoflighto if there is no occurence of the string 0x120002, the method indexOf returns -1. So he checks if the string 0x120002 is part of the variable data.



  • I figured it out. There are missing brackets for the if statement. In node_helper.js:

    From:

            if (data.indexOf("0x120002") !== -1)
              exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null);
    

    To:

            if (data.indexOf("0x120002") !== -1){
              exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null);
           }
    

    @paviro


Log in to reply
 

Looks like your connection to MagicMirror Forum was lost, please wait while we try to reconnect.