• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Help with MMM-PIR-Sensor tvservice logical evaluation

Scheduled Pinned Locked Moved Troubleshooting
3 Posts 2 Posters 1.5k Views 2 Watching
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 Offline
    orayoflighto Project Sponsor
    last edited by Jul 20, 2017, 10:41 AM

    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)

    S 1 Reply Last reply Jul 20, 2017, 9:20 PM Reply Quote 0
    • S Offline
      strawberry 3.141 Project Sponsor Module Developer @orayoflighto
      last edited by Jul 20, 2017, 9:20 PM

      @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 Offline
        orayoflighto Project Sponsor
        last edited by Jul 21, 2017, 11:46 AM

        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
        1 / 1
        • First post
          1/3
          Last post
        Enjoying MagicMirror? Please consider a donation!
        MagicMirror created by Michael Teeuw.
        Forum managed by Sam, technical setup by Karsten.
        This forum is using NodeBB as its core | Contributors
        Contact | Privacy Policy