View Single Post
Old 04-15-2013, 10:58 AM   #1
PaulFreund
*
PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.
 
PaulFreund's Avatar
 
Posts: 35
Karma: 145852
Join Date: Apr 2013
Device: Kindle Touch
Notification about power button presses for the K5 and hopefully for the KPW

This requires a little bit of help from outside and I figured udev would be a good way to catch the event in the first place.
The following shell code from the WebLaunch start.sh script creates a udev rule that listens to 'yoshibutton' and executes a shell script.

Code:
###############################################################################
## Register powerbutton handler

FILE_RULES="/etc/udev/rules.d/98-yoshibutton.rules"
FILE_NOTIFY="/lib/udev/bin/notifyyoshibutton"

#------------------------------------------------------------------------------
# Rules
if [ ! -f $FILE_RULES ]
then
	mntroot rw
	echo "KERNEL==\"yoshibutton\",  RUN+=\"$FILE_NOTIFY\"" > $FILE_RULES
	udevadm control --reload-rules
	mntroot ro
fi

#------------------------------------------------------------------------------
# Notifier
if [ ! -f $FILE_NOTIFY ]
then
	mntroot rw
	echo '#!/bin/sh' > $FILE_NOTIFY
	echo '/usr/bin/lipc-send-event com.lab126.system.event yoshibutton' >> $FILE_NOTIFY
	chmod +x $FILE_NOTIFY
	mntroot ro
fi
The executed script will send an event through lipc with the command "lipc-send-event com.lab126.system.event yoshibutton"(thanks eureka) which can later be catched in a mesquite app (I use pillowHelper.js for this).

So when the app gets started ( 'go' event in a Kindle template ):

PHP Code:
//-------------------------------------------------------------
// Register power button callback
function registerPowerButtonCallback()
{            
    
// Register Callback and watch for power button
    
pillowHelper.RegisterStatusBarEventCallback(appName
        function(
value
        {
            if( 
value.eventName && value.eventName === 'yoshibutton')
                
closeApplication();
        }
    );

    
// Request powerbutton event
    
pillowHelper.RequestStatusBarEvent(
        
appName
        
'com.lab126.system.event'
        
'yoshibutton'
    
);

And when the app gets closed to clean up ('unload' or 'pause' in a Kindle template):

PHP Code:
pillowHelper.UnRegisterStatusBarEventCallback(appName); 
Now when the power button is pressed, the function closeApplication() is called in this example and that regardless of whether preventScreenSaver is set or not.

This method is implemented in WebLaunch and works for me on the K5. As I developed this for the PaperWhite where there is no home button it would be nice if somebody with a PW could test it ( for example by testing the implementation in the WebLaunch application ).

EDIT: It is now tested and works on the K5 and the KPW Thanks for testing twobob!

Last edited by PaulFreund; 04-15-2013 at 02:00 PM. Reason: Now known to work with KPW
PaulFreund is offline   Reply With Quote