GPIO ONOFF Powerswitch / Resetbutton Problem
-
@supernature2k does this fix on/off switches too? Or just the momentary button (in my case reset)?
-
@megakoni Sad to hear that it does not work..
Are you sure it's a recalbox command which triggers the reboot? Maybe it's a RPi function to shutdown/reboot if VCC drops a certain level? I don't know..
Because my shutdown / reboot scripts are not active -
@lackyluuk well, if i turn off the shutdown and reset scripts provided by the recalbox config, that issue dissappears. But i still want to use these buttons so i just have to wait and see if the next update can fix it
-
@megakoni here is the script if you want to test:
import RPi.GPIO as GPIO import time import os import thread import datetime import socket import sys import argpa**e from datetime import datetime from configgen import recalboxFiles # this last one retrieves emulators bin names pa**er = argpa**e.ArgumentPa**er(description='power manager') pa**er.add_argument("-m", help="mode onoff or push", type=str, required=True) args = pa**er.pa**e_args() mode = args.m IPADDR = "127.0.0.1" PORTNUM = 55355 # IP and port for retroarch network commands POWERPLUS = 3 RESETPLUS = 2 LED = 14 GPIO.setwarnings(False) # no warnings GPIO.setmode(GPIO.BCM) # set up BCM GPIO numbering GPIO.setup(RESETPLUS, GPIO.IN, pull_up_down=GPIO.PUD_UP) # GPIO on pin 3 is the GPIO 2 in BCM mode #to Reset+ GPIO.setup(POWERPLUS, GPIO.IN, pull_up_down=GPIO.PUD_UP) # GPIO on pin 5 is the GPIO 3 in BCM mode #to Power+ GPIO.setup(LED, GPIO.OUT) GPIO.output(LED, True) # GPIO on pin 8 is the GPIO 14 in BCM mode #to LED+ # Define a threaded callback function to run in another thread when events are detected def button_pressed(channel): if channel == POWERPLUS: speed=0.15 shutdownstring="shutdown -h now" nwcommand="QUIT" elif channel == RESETPLUS: speed=0.05 shutdownstring="shutdown -r now" nwcommand="RESET" timer = 0 flag = True while flag: if GPIO.input(channel) == False: timer += 1 print "Button pressed" elif GPIO.input(channel) == True: print "Button released" print timer #timer adds 1 each 0.1 seconds if timer = 10, button is pressed for 1s if (timer > 10): offreset(speed, shutdownstring) print "shutdown" elif (timer >1): retroarch(nwcommand) print "retroarch" killthats**t(channel) timer = 0 flag = False time.sleep(0.1) # on power short press, trying to kill all listed emus def killthats**t(channel): if channel == POWERPLUS: for bin in recalboxFiles.recalboxBins: print bin proc = os.path.basename(bin) print proc os.system("killall -9 "+proc) # on long button press clean stop of ES then shutdown -h or -r def offreset(speed, shutdownstring): thread.start_new_thread( blink, (speed, )) flag=True pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] os.system("/etc/init.d/S31emulationstation stop") while flag: flag = False for pid in pids: try: print pid commandpath = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read() if "emulationstation" in commandpath: flag = True except IOError: continue os.system(shutdownstring) # threaded blinking function for LED def blink(speed): while True: GPIO.output(LED, False) time.sleep(speed) GPIO.output(LED, True) time.sleep(speed) # sending network command to retroarch (only exit and reset atm) def retroarch(nwcommand): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) except socket.error: print 'Failed to create socket' sys.exit() s.sendto(nwcommand, (IPADDR, PORTNUM)) GPIO.add_event_detect(RESETPLUS, GPIO.BOTH, callback=button_pressed, bouncetime=2) GPIO.add_event_detect(POWERPLUS, GPIO.BOTH, callback=button_pressed, bouncetime=2) while True: time.sleep(0.2)
-
@supernature2k how do i implement that? I've never done that. Is here a tutorial for that in the forums?
And i'm curious about the network commands. Does power/reset only work if my wlan or lan is connected to my network? -
it works without network as we use the localhost loop (127.0.0.1)
-
@supernature2k
couldn't get the script to work on startup. It just didn't do anything for me. I used this tutorial step by step https://github.com/recalbox/recalbox-os/wiki/Add-your-own-startup-script-(EN) -
@supernature2k so i got the new update, but nothing changed. Or is it coming in the next update?
I didn't change the recalbox config, is there a new default one? -
@megakoni what is your issue?
-
@supernature2k i still get the power button triggered with pluging something into usb or audio jack and it shuts down. This only happens when the system.power.switch=PIN356ONOFFRESET script is enabled. So i was wondering if there is a new script for power and reset function since the new update
-
@megakoni no sorry, the fix is ready and should be in the next release.
Meanwhile, you can try the script posted above. -
@supernature2k ok thanks i'll wait then. I tried to implement (i'm a noob xD) the script but it didn't seem to run, so i don't know yet if it works
-
@supernature2k so i got the new update.
Can you explain me how exactly the new power switch works? Reset button is i guess like 3 seconds of pressing down to reboot.
But i don't know exactly how the power switch works to turn off.
Turning on is simple, just switch it to on.
But turning off it seems i have to switch 3 times, but sometimes it does not work.
Is there a specific period of time i have to wait for the 3 times switching? -
Also interrested here: looks like my power and reset buttons doesn't work anymore since the last update (X-MAS update)
Any hints? -
@megakoni said in GPIO ONOFF Powerswitch / Resetbutton Problem:
But i don't know exactly how the power switch works to turn off.
Well I managed to find out by myself: POWER button works the exact same way as RESET button: when Recalbox ON, push the power button during 3 seconds, release it --> shutdown launched.
So according to me, you don't have to push the button 3 times.
EDIT: to show they work the same way: they have the same code line:
# grep GPIO.add_event_detect /recalbox/scripts/rpi-pin356-power.py GPIO.add_event_detect(RESETPLUS, GPIO.BOTH, callback=button_pressed, bouncetime=2) GPIO.add_event_detect(POWERPLUS, GPIO.BOTH, callback=button_pressed, bouncetime=2)
-
@unik314r but i have a power switch, not a button. My Reset trigger is a momentary button. for power i use a switch (i build my raspberry into a snes case)
and i use the system.power.switch=PIN356ONOFFRESET that was commented in the recalbox.conf.And by the way, how and where can i find this script? And can i simply edit it?
-
Have a look here :
/recalbox/scripts/ -
@megakoni To edit a file: have a look at https://github.com/recalbox/recalbox-os/wiki/Edit-the-config.txt-file-(EN)
The file you're looking for is/recalbox/scripts/rpi-pin356-power.py
.--
I Also use a modified SNES but don't like switch buttons (Recalbox python script looks for a status change --> going from on to off is the same as going from off to on and I find it not very convenient)
So I turned the original power switch button into a momentary one (inside the SNES, a simple spring makes the button go back) so that when I want to turn on (or off) the SNES, it pushes a momentary button (that I glued inside the snes) and automatically comes back: that way, even if there is a general power cut and then power restored (or something else that electrically unplugs/plugs the SNES), the system doesn't boot with a power button positionned to off.But I suppose this is not what you're looking for^^
-
@unik314r thanks for the info. I also thought of glueing a button in the inside, so the "switch" then just bounces back.
But i think i stay with the switch. I just really enjoy that satisfying click sound and feel of using that original switch.
Then i'll just have to shut down switching 3 times or using the menu command. At least i get no shut downs anymore when i plug in something to usb etc. -
@megakoni I agree with you, the switch sound is oddly satisfying But I have it on my original non-modified SNES