Welcome! Log In Create A New Profile

Advanced

nsa325 copy button event

Posted by ptosch 
nsa325 copy button event
February 01, 2017 10: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 10:09AM by ptosch.
GPIO keys daemon setup
February 01, 2017 03: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"

UPDATE:

It has been reported various times that the key names POWER, RESTART, COPY no longer work in later esekeyd version (by Christian, and by Trond).

So depending on the box you are installing, use learnkeys as Trond showed in the tutorial Power button with regret option by esekeyd to find the key number and use them in esekeyd.conf.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 4 time(s). Last edit at 02/01/2023 05:33PM by bodhi.
Re: nsa325 copy button event
February 02, 2017 07: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 11: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 03: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
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 2 time(s). Last edit at 03/05/2017 03:35PM by bodhi.
Re: nsa325 copy button event
November 25, 2017 02:19PM
Thanks for the info!

I used
/usr/bin/keytest

A program from esekeyd that reports names of pressed key. Later checked with
tail /var/log/user.log
Thats where /usr/bin/logger -s -i "COPY Button pushed" writes stuff on my LG T1N1

Only key that the LG N1T1 showed for esekeyd was the back-up button (KEY_133), no other button did anything.

So I use the "red power button" for starting up and the "back-up" for shutdown, and made nice stickers saying so :)
Re: nsa325 copy button event
November 25, 2017 04:26PM
raffe,

> Only key that the LG N1T1 showed for esekeyd was
> the back-up button (KEY_133), no other button did
> anything.

> So I use the "red power button" for starting up
> and the "back-up" for shutdown, and made nice
> stickers saying so :)

:) well done.

So are there other buttons on this box, what are they? If there are, then they could be identified by looking at the GPL source. If I know the GPIO number for a button I can add it to the DTS to make it available to the kernel.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: nsa325 copy button event
November 26, 2017 04:28AM
On the back I have a red power button. One push to start and looong push to cut of power.
On front a "back-up" button and a eject button for the DVD.
I would be nice to find the red button. Then I can use same button for start and a shutdown.



Edited 1 time(s). Last edit at 11/26/2017 08:39AM by raffe.
fgh
Re: GPIO keys daemon setup
August 15, 2019 03:05PM
Ok, to save dumb people as me some time:

root@kerstin:~$ keytest
keytest (ESE Key Deamon 1.2.7, SVN-r63)

(input device name as 1st option override autodetection)

Pres ANY (fun)key... or Ctrl-C to exit...

KEY_116 KEY_116 KEY_133 KEY_133

Then:
root@kerstin:~$ cat /etc/esekeyd.conf
KEY_116:/usr/bin/logger -s -i "POWER button pushed"
RESTART:/usr/bin/logger -s -i "RESTART button pushed"
KEY_133:/usr/bin/logger -s -i "COPY Button pushed"
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: