Welcome! Log In Create A New Profile

Advanced

nsa325 copy button event

Posted by ptosch 
nsa325 copy button event
February 01, 2017 09:08AM
Hi all,

i have some problems catching the copy button press event.

Buttzy10169 wrote on December 08, 2013 this comment:

Quote
Buttzy10169
And the following python script lets you do something with the copy button:

from evdev import InputDevice
from select import select
from subprocess import call

dev = InputDevice('/dev/input/event0')

while True:
        r,w,x = select([dev], [], [])
        for event in dev.read():
                if event.code == 133:
                        call(["shutdown", "-r", "now", "\"this is a test\""])

The problem is, there are two events happening, so my script is beeing executed two times.
It seems, "buttondown" and "buttonup" are catched by the script.
I thought, it might be useful to add a sleep command after the last line, but the events seem to be cached and appear after the sleep.

What could be done now? I added a "print event.code" line to the code; these are the events, when pressing and releasing the button:
Event Code: 133
Event Code: 0
Event Code: 133
Event Code: 0

There are even 4 events ... now thats weird ....



Edited 1 time(s). Last edit at 02/01/2017 09:09AM by ptosch.
Re: nsa325 copy button event
February 01, 2017 02:03PM
ptosch,

Instead of the input script (which was deprecated long ago in Linux), you can install esekeyd (multimedia keyboard daemon for Linux). It is way better.

apt-get install esekeyd

And set it up in the conf file. Here is my test version, where the button push will print out to syslog. Replace it with your own action or scripts to do certain things such as shutdown, backup,....

cat /etc/esekeyd.conf
POWER:/usr/bin/logger -s -i "POWER button pushed"
RESTART:/usr/bin/logger -s -i "RESTART button pushed"
COPY:/usr/bin/logger -s -i "COPY Button pushed"

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner



Edited 1 time(s). Last edit at 02/01/2017 02:04PM by bodhi.
Re: nsa325 copy button event
February 02, 2017 06:24AM
Hey Bodhi,
I even read something about esekeyd when flying though the threads, but still decided to use the more complicated way...
Half-asperger-mind ;)

Once again thank You, installing and configuring took 5 minutes, everything works now as expected!

Cheers,
Peter
Re: nsa325 copy button event
March 05, 2017 10:25AM
hi ptosch and bodhi,

i am trying to get the buttons doing something but without luck.
I followed the instructions here http://forum.doozan.com/read.php?2,26391,26478#msg-26478

then i set START_ESEKEYD in /etc/default/esekeyd to true and rebooted but the buttons do nothing.
Do i have to add some commands so that they will do?
Re: nsa325 copy button event
March 05, 2017 02:24PM
saschadd,

In the instruction post you linked, my example is to test the button with syslog.

#POWER:/sbin/shutdown -h now
#RESTART:/sbin/shutdown -r now
POWER:/usr/bin/logger -s -i "POWER button pushed"
RESTART:/usr/bin/logger -s -i "RESTART button pushed"
COPY:/usr/bin/logger -s -i "COPY Button pushed"

So run
logread -f
And push the button, observe the log event.

Or if you use systemd, then run that syslog to see the last action.

Once you see that it works, replace the command below with a real action such as a script to do something like backup, copy, ...
/usr/bin/logger -s -i "COPY Button pushed"

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner



Edited 2 time(s). Last edit at 03/05/2017 02:35PM by bodhi.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: