Embedded Linux and Qt Handle Power Button Press

Embedded Linux and Qt Handle Power Button Press


Here are some notes on how to handle a Power Down button with Qt for Embedded Linux. We consider the case where you have a keypad with 2 drivers, 1 for the main keypad, and 1 for the power button. First, download evtest.c ( beagleboard.googlecode.com/files/evtest.c ) and cross-compile it for the embedded target. Boot the board and insert your power button driver and keypad driver ( if not auto-loaded ). Now run evtest on the /dev/input/<device> created by loading the driver. For the power button you should see something like this after pressing the button several times:

# ./evtest /dev/input/event2

Input driver version is 1.0.1

Input device ID: bus 0x0 vendor 0x0 product 0x0 version 0x0

Input device name: "twl4030_pwrbutton"

Supported events:

Event type 0 (Sync)

Event type 1 (Key)

Event code 116 (Power)

Testing ... (interrupt to exit)

Event: time 1370431888.296539, type 1 (Key), code 116 (Power), value 1

Event: time 1370431888.296539, -------------- Report Sync ------------

Event: time 1370431888.453338, type 1 (Key), code 116 (Power), value 0

Event: time 1370431888.453338, -------------- Report Sync ------------

Event: time 1370431890.855651, type 1 (Key), code 116 (Power), value 1

Event: time 1370431890.855682, -------------- Report Sync ------------

Event: time 1370431891.026885, type 1 (Key), code 116 (Power), value 0

Event: time 1370431891.026885, -------------- Report Sync ------------

Export the environment variable that contains both drivers for the keypad and power button:

export QWS_KEYBOARD="linuxinput:/dev/input/keypad linuxinput:/dev/input/by-path/platform-omap_i2c.1-platform-twl4030_pwrbutton-event"

Create a simple Qt Custom app to monitor the QWS received events and install an event filter:

// Install the event filter

bool TestApp::eventFilter( QObject *obj, QEvent *ev ) {

qDebug() << ev->type();

You will notice after pressing the power button that you receive events of type:

Qt::Key_PowerDown 0x0100010b

While still receiving events from the main keypad.

Cheers!



ClassyBits 2016