Development Board custom keyboard driver for QT

Source: Internet
Author: User

For the QT program on the Development Board, You need to receive keyboard buttons. This project uses a custom keyboard. Therefore, QT needs to recognize the buttons on the custom keyboard.

The flowchart is as follows:

 

Step-1:

Add the following two files under qt-everywhere-opensource-src-4.6.3/src/GUI/Embedded:

---------------------------------

Qkbd_my_qws.h

++

# Ifndef qkbd_my_qws_h
# Define qkbd_my_qws_h

# Include <qtgui/qkbd_qws.h>

Qt_begin_header

Qt_begin_namespace

Qt_module (GUI)

# Ifndef qt_no_qws_keyboard

# Ifndef qt_no_qws_kbd_my
Class qwsmykbprivate;

Class qwsmykeyboardhandler: Public qwskeyboardhandler
{
Public:
Qwsmykeyboardhandler (const qstring &);
Virtual ~ Qwsmykeyboardhandler ();
PRIVATE:
Qwsmykbprivate * D;
};
# Endif // qt_no_qws_kbd_my

# Endif // qt_no_qws_keyboard

Qt_end_namespace

Qt_end_header

# Endif // qkbd_my_qws_h

 

---------------------------------

--------------------------------

Qkbd_my_qws.cpp

++

# Include "qkbd_my_qws.h"

# Ifndef qt_no_qws_kbd_my
# Include <qsocketnotifier>
# Include <qstringlist>
# Include <qstring>

# Include <sys/types. h>
# Include <sys/STAT. h>
# Include <sys/IOCTL. h>
# Include <fcntl. h>
# Include <termios. h>
# Include <unistd. h>
# Include <errno. h>
# Include <private/qcore_unix_p.h>
# Include <qsocketnotifier. h>
# Include <Linux/input. h>

Qt_begin_namespace

Class qwsmykbprivate: Public qobject
{
Q_object
Public:
Qwsmykbprivate (qwsmykeyboardhandler * Handler, const qstring & device );
~ Qwsmykbprivate ();
Bool isopen () {return buttonfd> 0 ;}

Private q_slots:
Void readkeyboarddata ();

PRIVATE:
Qwsmykeyboardhandler * m_handler;
Qstring terminalname;
Int buttonfd;
Int kbdidx;
Int kbdbufferlen;
Unsigned char * kbdbuffer;
Qsocketnotifier * notifier;
};

Qwsmykeyboardhandler: qwsmykeyboardhandler (const qstring & device)
: Qwskeyboardhandler (device)
{
D = new qwsmykbprivate (this, device );
}

Qwsmykeyboardhandler ::~ Qwsmykeyboardhandler ()
{
Delete D;
}

Qwsmykbprivate: qwsmykbprivate (qwsmykeyboardhandler * H, const qstring & device)
: M_handler (h)
{
Terminalname = device. isempty ()? "/Dev/input/event1": device; // device. tolatin1 ();
Buttonfd =-1;
Notifier = 0;
If (buttonfd = qt_open (terminalname. tolatin1 (). constdata (), o_rdonly | o_ndelay) <0)
{
Qwarning ("cannot open % s \ n", terminalname); // terminalname. tolatin1 ());
}
Printf ("open my USR keyboard success !! \ N ");
If (buttonfd> = 0)
{
Notifier = new qsocketnotifier (buttonfd, qsocketnotifier: read, this );
Connect (notifier, signal (activated (INT), this, slot (readkeyboarddata ()));
}
Kbdbufferlen = 80;
Kbdbuffer = new unsigned char [kbdbufferlen];
Kbdidx = 0;
}

Qwsmykbprivate ::~ Qwsmykbprivate ()
{
If (buttonfd> 0)
{
: Close (buttonfd );
Buttonfd =-1;
}
Delete notifier;
Notifier = 0;
Delete [] kbdbuffer ;;
}

Void qwsmykbprivate: readkeyboarddata ()
{
Struct input_event event;
// Inputdata ;//

Int n = read (buttonfd, & event, sizeof (struct input_event ));

If (n! = Sizeof (struct input_event ))
{
Printf ("Key pressed: N = % d \ n", N );
Return;
}
Qt: keyboardmodifiers modifiers = QT: nomodifier;
Int Unicode = 0 xFFFF;
Int key_code = 0;

If (ev_key = event. type)
{
// You can set it based on your specific hardware value.
Switch (event. Code)
{

Case 0x25:
Key_code = QT: key_0;
Unicode = 0 xFFFF;
Break;

Case 0x6a:
Key_code = QT: key_1;
Unicode = 0 xFFFF;
Break;

Case 0x1e:
Key_code = QT: key_f1;
Unicode = 0 xFFFF;
Break;

Case 0x24:
Key_code = QT: key_f2;
Unicode = 0 xFFFF;
Break;

Default:
Qdebug ("Default: % d \ n", event. Code );
Break;

}

M_handler-> processkeyevent (UNICODE, key_code, modifiers, event. value! = 0, false );
}

If (ev_syn = event. type)
Printf ("syn event \ n ");

}

Qt_end_namespace

# Include "qkbd_my_qws.moc"

# Endif // qt_no_qws_kbd_my

--------------------------------

 

Step 2:

In the qkbddriverfactory_qws.cpp file:

# Include "qkbd_my_qws.h"

.....

Qwskeyboardhandler * qkbddriverfactory: Create (const qstring & Key, const qstring & device)
{
Qstring driver = key. tolower ();
# Ifndef qt_no_qws_kbd_my

If (driver = qlatin1string ("my") | driver. isempty ())
{
Printf ("TSC keyboard ");
Return new qwsmykeyboardhandler (device );
}
# Endif

.......

}

 

....

Qstringlist qkbddriverfactory: Keys ()
{
Qstringlist list;
# Ifndef qt_no_qws_kbd_my
List <qlatin1string ("my ");
# Endif

...........

}

Step-3:

Modify configure under the qt-everywhere-opensource-src-4.6.3/directory

Make the following changes:
Export _kbd_available = "my TTY linuxinput qvfb"
Export _kbd_on = "my" # default, see qmakevar abve ------ it turns out to be tty

# Qmakevar add KBD-drivers "tty" --- original
Qmakevar add KBD-drivers "My

 

Re-configure and add the-QT-KBD-my option.

 

Step 4:

Enter qt-everywhere-opensource-src-4.6.3/src/GUI/embedded
Make-F makefile in this directory

Make install

 

Step-5:

Copy the compiled libqtgui * library file to the library file path of the Development Board's file system (/usr/lib)
CP ~ /QT/output/Qt-arm/lib/libqtgui *~ /Targetfs/usr/lib/

 

Complete ~~~~~

 

In this way, you can receive messages from custom buttons.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.