power switch event for clean shutdown

Post Reply
jit
Posts: 147
Joined: Mon Mar 30, 2015 4:10 pm
languages_spoken: english, french
ODROIDs: odroid-w => portable retrogaming in a gameboy case,
C0 => custom portable retrogaming "GameOdroid C0"
C0 => Portable audiophile music player "Odrophile"
C0 => being prepared for a radio clock project...
C1 => in a dead project of a portable retrogaming in a gamegear case
C1+ => used to build C0 projects... maybe recycled as an Amiga one day
C2 => Multimedia box for TV
N1 => Home made rackable NAS
4xHC1 => docker swarm cluster
1xHC1 => reverse proxy
N2 => not yet started... should become another portable gaming device with 8" display...
XU4 + boom bonnet => for a not yet revealed project ;)
Has thanked: 0
Been thanked: 17 times
Contact:

power switch event for clean shutdown

Post by jit »

As the device have an hardware power switch, I'm searching a way to make a clean shutdown by pressing the button less than 5 sec when the Odroid-w is running (to avoid unclean shutdown).

On traditional x86 architecture, it's quite easy because of ACPI events... But AFAIK, there is no ACPI on ARM plateforms.

How can I detect a power button usage while running ? I may code if necessary... ;)

macemoneta
Posts: 62
Joined: Sun Jan 11, 2015 8:38 am
languages_spoken: english
ODROIDs: odroid-c1
Location: NJ
Has thanked: 0
Been thanked: 0
Contact:

Re: power switch event for clean shutdown

Post by macemoneta »

Just put a button on a GPIO. You can then shutdown when it's pressed with, for example (GPIO 27):

Code: Select all

#!/bin/bash
gpio wfi 27 rising
# We fall through when triggered
shutdown -h now

jit
Posts: 147
Joined: Mon Mar 30, 2015 4:10 pm
languages_spoken: english, french
ODROIDs: odroid-w => portable retrogaming in a gameboy case,
C0 => custom portable retrogaming "GameOdroid C0"
C0 => Portable audiophile music player "Odrophile"
C0 => being prepared for a radio clock project...
C1 => in a dead project of a portable retrogaming in a gamegear case
C1+ => used to build C0 projects... maybe recycled as an Amiga one day
C2 => Multimedia box for TV
N1 => Home made rackable NAS
4xHC1 => docker swarm cluster
1xHC1 => reverse proxy
N2 => not yet started... should become another portable gaming device with 8" display...
XU4 + boom bonnet => for a not yet revealed project ;)
Has thanked: 0
Been thanked: 17 times
Contact:

Re: power switch event for clean shutdown

Post by jit »

Well, you're right... but this makes me realise that my question was not precise enough.

I want to use only one button for both switch on and off. Using a GPIO to trigger to shutdown is not an option for me (I can do that with an onscreen menu).

macemoneta
Posts: 62
Joined: Sun Jan 11, 2015 8:38 am
languages_spoken: english
ODROIDs: odroid-c1
Location: NJ
Has thanked: 0
Been thanked: 0
Contact:

Re: power switch event for clean shutdown

Post by macemoneta »

You could use something like this:

Seachoice Toggle Switch - 3 Pos MOM ON/OFF/MOM ON

Wire one set of contacts to the power switch port contacts (J4), and wire the other set to the GPIO. Toggle up to boot, toggle down to shutdown.

jit
Posts: 147
Joined: Mon Mar 30, 2015 4:10 pm
languages_spoken: english, french
ODROIDs: odroid-w => portable retrogaming in a gameboy case,
C0 => custom portable retrogaming "GameOdroid C0"
C0 => Portable audiophile music player "Odrophile"
C0 => being prepared for a radio clock project...
C1 => in a dead project of a portable retrogaming in a gamegear case
C1+ => used to build C0 projects... maybe recycled as an Amiga one day
C2 => Multimedia box for TV
N1 => Home made rackable NAS
4xHC1 => docker swarm cluster
1xHC1 => reverse proxy
N2 => not yet started... should become another portable gaming device with 8" display...
XU4 + boom bonnet => for a not yet revealed project ;)
Has thanked: 0
Been thanked: 17 times
Contact:

Re: power switch event for clean shutdown

Post by jit »

Yes this could be a solution... I would have prefered a "simple" push button easier to integrate, but this could be a solution.

Isn't there any way to get the "power switch" event on OS side ? The PMIC hardware may have something for that. I never wrote a kernel driver, but (for now) I'm not afraid ;)

macemoneta
Posts: 62
Joined: Sun Jan 11, 2015 8:38 am
languages_spoken: english
ODROIDs: odroid-c1
Location: NJ
Has thanked: 0
Been thanked: 0
Contact:

Re: power switch event for clean shutdown

Post by macemoneta »

A power-on event happens before the OS is running. Even a 'wake on interrupt' from sleep would still require a separate switch.
Edit: You could add some additional logic to determine if power is up on the board (e.g., Pin 1) and if so pulse the GPIO, or if power is down pulse J4, if you think it's worth the effort.

jit
Posts: 147
Joined: Mon Mar 30, 2015 4:10 pm
languages_spoken: english, french
ODROIDs: odroid-w => portable retrogaming in a gameboy case,
C0 => custom portable retrogaming "GameOdroid C0"
C0 => Portable audiophile music player "Odrophile"
C0 => being prepared for a radio clock project...
C1 => in a dead project of a portable retrogaming in a gamegear case
C1+ => used to build C0 projects... maybe recycled as an Amiga one day
C2 => Multimedia box for TV
N1 => Home made rackable NAS
4xHC1 => docker swarm cluster
1xHC1 => reverse proxy
N2 => not yet started... should become another portable gaming device with 8" display...
XU4 + boom bonnet => for a not yet revealed project ;)
Has thanked: 0
Been thanked: 17 times
Contact:

Re: power switch event for clean shutdown

Post by jit »

The problem is not really the "power ON" event, but the "power OFF" one. The main objective is to trigger the OS shutdown command by pressing the on/off switch while the odroid-w is running.

jit
Posts: 147
Joined: Mon Mar 30, 2015 4:10 pm
languages_spoken: english, french
ODROIDs: odroid-w => portable retrogaming in a gameboy case,
C0 => custom portable retrogaming "GameOdroid C0"
C0 => Portable audiophile music player "Odrophile"
C0 => being prepared for a radio clock project...
C1 => in a dead project of a portable retrogaming in a gamegear case
C1+ => used to build C0 projects... maybe recycled as an Amiga one day
C2 => Multimedia box for TV
N1 => Home made rackable NAS
4xHC1 => docker swarm cluster
1xHC1 => reverse proxy
N2 => not yet started... should become another portable gaming device with 8" display...
XU4 + boom bonnet => for a not yet revealed project ;)
Has thanked: 0
Been thanked: 17 times
Contact:

Re: power switch event for clean shutdown

Post by jit »

The ricoh 5t619 input driver may be a solution : https://github.com/hardkernel/linux/blo ... 9-pwrkey.c
It seems to implement a KEY_POWER event which is registered in /dev/input/event0.

I tested with evtest, but the event seems not to be triggered... does someone know what exatly trigger this event ?

GHhost
Posts: 10
Joined: Wed Jan 07, 2015 6:46 pm
languages_spoken: english
ODROIDs: odroid w
Has thanked: 0
Been thanked: 0
Contact:

Re: power switch event for clean shutdown

Post by GHhost »

it seems input driver is broken or it may be for different pmic model, i try to debug it in low level, it's not see this keypress at all => no any event to OS.

Soulsavior
Posts: 11
Joined: Sun May 01, 2016 1:55 am
languages_spoken: english
ODROIDs: Odroid C2
Has thanked: 0
Been thanked: 0
Contact:

Re: power switch event for clean shutdown

Post by Soulsavior »

Hello!
I know that this is an old topic, but can someone explain me in details How to do Macemoneta's trick on a Odroid C2, using two MOM buttons, one for shutting down and one for waking the device once it has shutdown? I'm a complete newbie concerning these board computers, but am pretty good at soldering on consoles and boards.To make it worse, i also am french so it's hard to follow what you guys says, so please make it simple, with diagrams and line codes (with how to add them) if possible... :lol:
I'd also like to know how to wire an extra activity LED on the GPIO.
Many thanks in advance for your help, guys! ;)

Jojo
Posts: 532
Joined: Mon May 18, 2015 12:13 am
languages_spoken: english, german
ODROIDs: C1, C1+, C2, HC1, HC2, VU8C
Location: Germany
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: power switch event for clean shutdown

Post by Jojo »

Soulsavior wrote:Hello!
I know that this is an old topic, but can someone explain me in details How to do Macemoneta's trick on a Odroid C2, using two MOM buttons, one for shutting down and one for waking the device once it has shutdown? I'm a complete newbie concerning these board computers, but am pretty good at soldering on consoles and boards.To make it worse, i also am french so it's hard to follow what you guys says, so please make it simple, with diagrams and line codes (with how to add them) if possible... :lol:
I'd also like to know how to wire an extra activity LED on the GPIO.
Many thanks in advance for your help, guys! ;)
Hi,

maybe you should open an new thread about this in the C2 section. The C2 is... well... "very different" from the W . And it is always a good thing to choose a useful titel for new threads, if you are going to open up a new one ;) .
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html

Soulsavior
Posts: 11
Joined: Sun May 01, 2016 1:55 am
languages_spoken: english
ODROIDs: Odroid C2
Has thanked: 0
Been thanked: 0
Contact:

Re: power switch event for clean shutdown

Post by Soulsavior »

Jojo wrote: Hi,

maybe you should open an new thread about this in the C2 section. The C2 is... well... "very different" from the W . And it is always a good thing to choose a useful titel for new threads, if you are going to open up a new one ;) .
OK, will do if you think that's better, thanks for the advice ;)

Post Reply

Return to “Debian(Raspbian)”

Who is online

Users browsing this forum: No registered users and 3 guests