Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QFileSystemWatcher + /sys/class/gpio
Forum Updated to NodeBB v4.3 + New Features

QFileSystemWatcher + /sys/class/gpio

Scheduled Pinned Locked Moved Mobile and Embedded
8 Posts 3 Posters 6.8k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    titan83
    wrote on last edited by
    #1

    Hello.
    I run my Qt (4.8.4) application on Linux 3.2.18. Platform is AT91SAM9G45.
    I want to watch for changes in the file /sys/class/gpio/gpioXXX/value, which displays a current state of signal on one of pin board.
    This file may contain two values: "0" or "1", if i manual change pin value i can see this change with 'cat /sys/class/gpio/gpioXXX/value', but QFileSystemWatcher does not catch these changes. However, the files are changed manually or by other programs respond correctly.
    I try to use poll:
    watcher.setObjectName(QLatin1String("_qt_autotest_force_engine_poller"));
    No results.
    Any ideas?
    Thank.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2
      1. Are you running your program by sudo privileges ?
      2. Have you added full file path(viz. /sys/class/gpio/gpioXXX/value) using addPath ( const QString & path ) ?

      157

      1 Reply Last reply
      0
      • T Offline
        T Offline
        titan83
        wrote on last edited by
        #3

        [quote author="p3c0" date="1379068293"]1. Are you running your program by sudo privileges ?
        2. Have you added full file path(viz. /sys/class/gpio/gpioXXX/value) using addPath ( const QString & path ) ?
        [/quote]
        i have only one user in this system - root
        file path added. on other files function work properly.

        1 Reply Last reply
        0
        • W Offline
          W Offline
          wickwire
          wrote on last edited by
          #4

          I'm also interested in this, using Qt5 on Raspberry Pi

          My tests show that even running my demo app as root, I only get events when I do any of the following, using the CLI:

          • touch the value file for the gpio pin
          • echo some string into it - it fails to write but my running demo app picks up the event
            If I attempt to trigger the change in the value using the sensor on the GPIO port, CLI shows that the GPIO pin value changes, but my demo app won't pick it up...
          1 Reply Last reply
          0
          • T Offline
            T Offline
            titan83
            wrote on last edited by
            #5

            After some experiments i decided to use QSocketNotifier, but and here i failed - this component based on select() function and generate signal on EOF, i.e. always.
            Now i wrote my one simple class based on poll() and QTimer - work fine.

            1 Reply Last reply
            0
            • W Offline
              W Offline
              wickwire
              wrote on last edited by
              #6

              I ended up using a similar approach - QFile and QTimer to poll the /sys/class/gpio/gpioXXX/value every 200msec

              It wasn't the desired soluion, but it doesn't seem to affect Pi's perfomance and the use of QThreads prevents UI thread blocking.

              I did find however - and it did work - how to use GPIO interrupts and WiringPi to achieve the initial objective, for later Qt integration:

              http://cs.smith.edu/dftwiki/index.php/Tutorial:_Interrupt-Driven_Event-Counter_on_the_Raspberry_Pi

              1 Reply Last reply
              0
              • p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #7

                Is this file "/sys/class/gpio/gpioXXX/value" renamed(to a temporary file for negligible amount of time and then back to original file name) or deleted anytime whenever its value is updated ?

                Because according to the docs,

                bq. Note that QFileSystemWatcher stops monitoring files once they have been renamed or removed from disk, and directories once they have been removed from disk.

                157

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  wickwire
                  wrote on last edited by
                  #8

                  I'm not sure, but I'd say it's just updated in content, by the system itself. If you attempt to manually edit the file and change the content from 0 to 1 or vice-versa, even as root you might get a warning and the value would remain unchanged - however, in that case, QFileSystemWatcher reacts to "something" and notifies.

                  The issue with QFileSystemWatcher is that it never picks up a change in content - in the scenario you describe, it would stand to reason that at least on a first attempt, QFileSystemWatcher would be triggered - and afterwards become silent, either because the value file had been deleted or renamed.

                  From what I found online about this so far, I believe the issue lies with the file type we're working with - device files - and QFileSystemWatcher isn't quite the proper tool to work with them.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved