MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord

    Help with MMM-PIR-Sensor tvservice logical evaluation

    Troubleshooting
    2
    3
    1201
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      orayoflighto Project Sponsor last edited by

      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)

      strawberry 3.141 1 Reply Last reply Reply Quote 0
      • strawberry 3.141
        strawberry 3.141 Project Sponsor Module Developer @orayoflighto last edited by

        @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.

        Please create a github issue if you need help, so I can keep track

        1 Reply Last reply Reply Quote 0
        • O
          orayoflighto Project Sponsor last edited by

          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

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Enjoying MagicMirror? Please consider a donation!
          MagicMirror created by Michael Teeuw.
          Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
          This forum is using NodeBB as its core | Contributors
          Contact | Privacy Policy