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. Problem with button debounce in Qt4.8 embedded
Forum Updated to NodeBB v4.3 + New Features

Problem with button debounce in Qt4.8 embedded

Scheduled Pinned Locked Moved Mobile and Embedded
8 Posts 3 Posters 5.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.
  • G Offline
    G Offline
    GregWilsonLindberg
    wrote on 12 Jun 2014, 16:40 last edited by
    #1

    I'm writing an application for the BeagleBone Black, currently running on an Angstrom Linux Distribution and Qt Embedded 4.8 and a 5.7" LCD screen with a resistive touch screen.

    My problem is that when I press any of my on screen buttons I frequently get multiple presses sent. I'm using the pressed signal in my button handling code. Is there any way to adjust the button press debounce timing so the display is less sensitive?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 12 Jun 2014, 20:56 last edited by
      #2

      Hi,

      If you can't do it at the driver level, you can use a QTimer that you restart when you get something from your button. Doing so you can add easily a minimal delay that will allow to only trigger your Qt signal once after your button finishes to bounce.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GregWilsonLindberg
        wrote on 12 Jun 2014, 21:01 last edited by
        #3

        I was hoping to not have to implement debounce code in every button handler, at this point I've probably got 50 buttons.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Jun 2014, 21:07 last edited by
          #4

          Well, why not make a class that does that ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • G Offline
            G Offline
            GregWilsonLindberg
            wrote on 12 Jun 2014, 21:11 last edited by
            #5

            If there isn't code in Qt that handles input bounce then there should be code in the underlying driver that tries to handle it and I'll have to do more research to find out where to look.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 12 Jun 2014, 21:37 last edited by
              #6

              There is no code in Qt for that since it's not its job to handle driver level stuff

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Ken A
                wrote on 19 Sept 2014, 18:09 last edited by
                #7

                You can implement debouncing at application level, using one function.
                Install an event filter on QApplication and spurious mouse events can be blocked.

                I ran into this same problem and could not find an answer so I solved myself. See below.
                Basically, if the touch screen was pressed to quickly after release, treat it as a bounce.

                @class MyApp : public QApplication
                {
                public:
                MyApp(int& argc, char **argv, Type type) :
                QApplication(argc, argv, type)
                {
                installEventFilter(this);
                }

                private:

                /*!
                Intercept events at the topmost level.
                @param o The object watched (in this case, it is MyApp and can be ignored.
                @param e The event.
                @return true to consume the event.
                */
                bool eventFilter(QObject *o, QEvent *e)
                {
                static QTime t;
                static bool isBounced = false;
                int msec;
                switch(e->type())
                {
                case QEvent::MouseButtonPress:
                case QEvent::MouseButtonDblClick:
                msec = t.elapsed();
                isBounced = (msec < 20); // Experiment with this number
                if (isBounced)
                return true;
                break;
                case QEvent::MouseButtonRelease:
                t.restart();
                if (isBounced)
                return true;
                break;
                default:
                break;
                }
                // Let Qt handle events that were not consumed here.
                return QApplication::eventFilter(o, e);
                }

                int main(int argc, char **argv)
                {
                MyApp a(argc, argv, QApplication::GuiServer);

                // your code
                return a.exec(&#41;;
                

                }
                @

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  GregWilsonLindberg
                  wrote on 22 Sept 2014, 15:58 last edited by
                  #8

                  Thanks for the suggestion Ken. I had put a debounce timer in a common class, but I have to call it from every button handler. The event filter looks much better.

                  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