Results 1 to 4 of 4

Thread: How to read Rotary encoder pulses?

  1. #1
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How to read Rotary encoder pulses?

    Hi,
    I am new to this forum and QT applications. i hope the message is in right place.

    i have an ARM9 development board running linux on it. without using GUI i can use all devices on the board like hardware buttons (as interrupts), ADCs, eeproms etc...

    For external buttons, ı use this example (simply)
    Qt Code:
    1. fd = open("/dev/button", 0);
    2. if (fd < 0) {
    3. perror("error open device");
    4. exit(1);
    5. }
    6.  
    7. for (;;)
    8.  
    9. {
    10. char buttons[3];
    11.  
    12. read(fd, buttons, sizeof buttons);
    13. printf("%s %s %s", buttons[0] , buttons[1] , buttons[2] );
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    this prints the buttons state as 0 or 1

    How can i implement this to GUI. how can i read device data continuesly in a fast way? i want to connect a rotary encoder and count the number of pulses. using the console applıcation no problem but how can i make this using QT?

    thank you

  2. #2
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to read Rotary encoder pulses?

    muisei,
    thank you for answering.

    i will try to use second method. after some tials i will share the result here.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to read Rotary encoder pulses?

    Use QSocketNotifier on your /dev/button to be notified of changes in the button and only react when there actually is a change. There is no point in having a busy loop (and wasting cpu power and electricity) just for reading the button status.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:

    gazel (29th August 2010)

  5. #4
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to read Rotary encoder pulses?

    Quote Originally Posted by wysota View Post
    Use QSocketNotifier on your /dev/button to be notified of changes in the button and only react when there actually is a change. There is no point in having a busy loop (and wasting cpu power and electricity) just for reading the button status.
    Now i have tried both ways using processevents and Qsocketnotifier.
    placing process events in a loop made the application heavy since CPU load
    Qsocketnotifier works very good. now i have to check how fast the signals are caught.
    here is the part for the code:

    Qt Code:
    1. buttons_fd = ::open("/dev/buttons", 0);
    2. QSocketNotifier *sockerNotifier= new QSocketNotifier(buttons_fd,QSocketNotifier::Read,this);
    3. connect(sockerNotifier,SIGNAL(activated(int)),this,SLOT(notify()));
    To copy to clipboard, switch view to plain text mode 


    thank you for your help

Similar Threads

  1. How to read a CD
    By skepticalgeek in forum Qt Programming
    Replies: 7
    Last Post: 22nd March 2010, 09:27
  2. Read excel
    By psipsi in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 18:07
  3. Best way to read xml
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 26th September 2007, 18:38
  4. How to read Raw Information from CD in MAC?
    By vishal.chauhan in forum General Programming
    Replies: 0
    Last Post: 10th July 2007, 13:26
  5. How to read CD with read?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 29th June 2007, 09:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.