-
Notifications
You must be signed in to change notification settings - Fork 10
/
multi_switch086.sh
727 lines (604 loc) · 25.8 KB
/
multi_switch086.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
#!/bin/bash
# Multi Switch Shutdown
# based on ES shutdown codes posted by @cyperghost and @meleu
# v0.05 Initial version here in this repo Jan.2018 // cyperghost
# v0.07 added kill -9 switch to get rid off all emulators // julenvitoria
# v0.10 version for NESPi case // Yahmez, Semper-5
# v0.20 Added possibilty for regular shutoff (commented now!)
# v0.30 Added commandline parameters uncommented device shutdowns
# v0.32 Added privileges check and packages check
# v0.41 Added NESPi+ safe shutdown, corrected GPIO numbering
# v0.42 Added NESPi+ fan control shutoff // thx cloudlink & gollumer
# v0.50 Added support for generic Button connected to any GPIO
# v0.51 NESPi+ fan control is 100% working - place a script to systemd service like Pimoroni OnOffShim
# v0.70 Parameter control, added extended help pages
# v0.75 Parameter --CLOSEEMU is called --ES-CLOSEEMU (both can be used for backward compatibility!)
# v0.80 Introduced --ES-SYSTEMD parameter, now the ES gracefully shutdown service by @meleu can be used
# v0.85 Code cleanup, added watchdog to kill only persistent emulators with sig -9, added more helppages
# v0.86 Added Switch check to NESPi+ cases
# Up to now 5 devices are supported!
#
# NESPIcase! Install raspi-gpio via "sudo apt install raspi-gpio", no sudo needed, reset, poweroff
# NESPIplus! Install raspi-gpio via "sudo apt install raspi-gpio", no sudo needed, reset, poweroff
# GenericBt! Install raspi-gpio via "sudo apt install raspi-gpio", no sudo needed, poweroff
# Mausberry! Script needs to be called with sudo, poweroff supported
# SHIMOnOff! Script needs to be called with sudo, poweroff supported
# ---------------------------------------------------------------------------------------------
# --------------------------------- P I D D E T E C T I O N ---------------------------------
# ---------------------------------------------------------------------------------------------
# This function is called still all childPIDs are found
function get_childpids() {
local CPIDS="$(pgrep -P $1)"
for cpid in $CPIDS; do
pidarray+=($cpid)
get_childpids $CPIDS
done
}
# Abolish sleep timer! This one is much better!
# I added watchdog to kill emu-processes with sig 9 level after 2.0s
# If emulator PID ist active after 5.0s, return to call
# I will prevent ES from being termed with level 9 for sake of safe shutdown
function wait_forpid() {
local PID=$1
[[ -z $PID ]] && return 1
local RC_PID=$(check_emurun)
local watchdog=0
while [[ -e /proc/$PID ]]; do
sleep 0.10
watchdog=$((watchdog+1))
[[ $watchdog -eq 20 ]] && [[ $RC_PID -gt 0 ]] && kill -9 $PID
[[ $watchdog -eq 50 ]] && [[ $RC_PID -gt 0 ]] && return
done
}
# This will reverse ${pidarray} and close all emulators
# This function needs a valid pidarray
function close_emulators() {
for ((z=${#pidarray[*]}-1; z>-1; z--)); do
kill ${pidarray[z]}
wait_forpid ${pidarray[z]}
done
unset pidarray
}
# Emulator currently running?
# If yes return PID from runcommand.sh
# due caller funtion
function check_emurun() {
local RC_PID="$(pgrep -f -n runcommand.sh)"
echo $RC_PID
}
# Emulationstation currently running?
# If yes return PID from ES binary
# due caller funtion
function check_esrun() {
local ES_PID="$(pgrep -f "/opt/retropie/supplementary/.*/emulationstation([^.]|$)")"
echo $ES_PID
}
# ---------------------------------------------------------------------------------------------
# ------------------------------------ E S - A C T I O N S ------------------------------------
# ---------------------------------------------------------------------------------------------
# Helppage
function help--ES-SYSTEMCALLS () {
echo -e "Multi Switch ES-Commands: Detailed Help\n"
echo "--ES-PID: This parameter obtains the Process ID of the running ES binary."
echo " If running ES instance isn't found, then 0 is returned."
echo " You may directly use this ID to quit ES's running instance!"
echo "--RC-PID: This parameter obtains the PID of runcommand.sh only!"
echo " You may find this usefull to detect if emulators are running."
echo
echo "--ES-CLOSEEMU: This parameter tries to close all running emulators. The code"
echo " is trying to determinine all child PIDs of runcommand.sh"
echo "--ES-SYSTEMD: This is special. It will just terminate ES binary and ES will not"
echo " initiate any further system actions like shutdown or reboots!"
echo " This is a hook to use with ES-gracfully-shutdown service by meleu"
echo
echo "--ES-RESTART: This just restarts ES-binary and keeps Multi Switch active in BG"
echo "--ES-REBOOT: This reboots the whole system, this is initiated by ES itself!"
echo "--ES-POWEROFF: This shutdowns the system, also initiated by ES itself!"
echo
echo "All this commands can be used to control the behaviour of EmulationStation with"
echo "external written programms. Multi Switch just provides a kind of interface for"
echo "simple control. So you are not stick to bash, feel free to take python!"
echo "I made a quick coding example to read PIDs of ES. Please respect my work!"
echo "It can be found here: https://retropie.org.uk/forum/topic/17506"
}
# This function can be called with several parameters
# ES itself evaluates entries in /tmp directory
# es-shutdown, will close ES and force an poweroff
# es-sysrestart, will close ES and force an reboot
# es-restart, will close ES and restart it
function es_action() {
local CASE_SEL="$1"
case "$CASE_SEL" in
"--ES-CLOSEEMU")
# Closes running Emulators (if available)
RC_PID=$(check_emurun)
if [[ -n $RC_PID ]]; then
get_childpids $RC_PID
close_emulators
wait_forpid $RC_PID
fi
;;
"--ES-REBOOT")
# Initiate system reboot and give control back to ES
ES_PID=$(check_esrun)
if [[ -n $ES_PID ]]; then
touch /tmp/es-sysrestart
chown pi:pi /tmp/es-sysrestart
kill $ES_PID
wait_forpid $ES_PID
exit
fi
;;
"--ES-POWEROFF")
# Initiate system shutdown and give control back to ES
ES_PID=$(check_esrun)
if [[ -n $ES_PID ]]; then
touch /tmp/es-shutdown
chown pi:pi /tmp/es-shutdown
kill $ES_PID
wait_forpid $ES_PID
exit
fi
;;
"--ES-RESTART")
# Initiate restart of ES
ES_PID=$(check_esrun)
if [[ -n $ES_PID ]]; then
touch /tmp/es-restart
chown pi:pi /tmp/es-restart
kill $ES_PID
wait_forpid $ES_PID
fi
;;
"--ES-SYSTEMD")
# Just terminate ES binary and let other services do their job
ES_PID=$(check_esrun)
if [[ -n $ES_PID ]]; then
kill $ES_PID
wait_forpid $ES_PID
exit
fi
;;
*)
echo "Please parse argument to function es_action() - Error!" >&2
;;
esac
}
# ---------------------------------------------------------------------------------------------
# ----------------------------------- S W I T C H T Y P E S -----------------------------------
# ---------------------------------------------------------------------------------------------
# ------------------------------------- N E S P I C A S E -------------------------------------
# Help Page
# NESPi Case @YAHMEZ Shutdown Mod
function help--NESPICASE() {
echo -e "NESPi case: Detailed help\n"
echo "For building advicefor SAFE SHUTDOWN MOD by @YAHMEZ visit:"
echo " https://retropie.org.uk/forum/topic/12424"
echo
echo "We need a binary (raspi-gpio) to set internal pullup resistor!"
echo " raspi-gpio set PIN# ip pu will do this job"
echo
echo "This works with any user, no root rights needed"
echo "Install raspi-gpio with: sudo apt install raspi-gpio"
echo
echo "Default Settings:"
echo " ResetSwitch GPIO 23, input, set pullup resistor!"
echo " PowerSwitch GPIO 24, input, set pullup resistor!"
echo " PowerOnControl GPIO 25, output, high, power on control!"
echo
echo "Commandline Parameters:"
echo " ./multi_switch.sh --NESPICASE powerbtn= resetbtn= powerctrl="
echo " ./multi_switch.sh --NESPICASE powerctrl=17 sets Power On Ctrl to GPIO17"
echo
echo "For questions regarding the hardware modding please use the link above"
echo "Attention: You need a power device: POLOLU PO2811 or PO2810 to make this work!"
echo "For questions to this script visit retropie forum! -- cyperghost"
}
# NESPI CASE @Yahmez Mod
# https://retropie.org.uk/forum/topic/12424
# Button script by cyperghost
function NESPiCase() {
#Set GPIOs
[[ -z $1 || $1 == "-1" ]] && GPIO_resetswitch=23 || GPIO_resetswitch=$1
[[ -z $2 || $2 == "-1" ]] && GPIO_powerswitch=24 || GPIO_powerswitch=$2
[[ -z $3 || $3 == "-1" ]] && GPIO_poweronctrl=25 || GPIO_poweronctrl=$3
# Init: Use raspi-gpio to set pullup resistors!
raspi-gpio set $GPIO_resetswitch ip pu
raspi-gpio set $GPIO_powerswitch ip pu
raspi-gpio set $GPIO_poweronctrl op dh
until [[ $power == 0 ]]; do
power=$(raspi-gpio get $GPIO_powerswitch | grep -c "level=1 fsel=0 func=INPUT")
reset=$(raspi-gpio get $GPIO_resetswitch | grep -c "level=1 fsel=0 func=INPUT")
if [[ $reset == 0 ]]; then
RC_PID=$(check_emurun)
[[ -z $RC_PID ]] && es_action --ES-RESTART
[[ -n $RC_PID ]] && es_action --ES-CLOSEEMU
fi
sleep 1
done
# Initiate Shutdown per ES
es_action --ES-CLOSEEMU
es_action --ES-POWEROFF
# If ES isn't running use regular shutoff
sudo poweroff
}
# ------------------------------------- N E S P I P L U S -------------------------------------
# Help Page
# NESPi+ Case
function help--NESPI+() {
echo "NESPi+ case: Detailed help"
echo
echo "For wiring shematics take a look at: http://www.retroflag.com"
echo "With a small binary raspi-gpio we set internal pullup resistor!"
echo "raspi-gpio set PIN# ip pu will do this job"
echo "This works with any user, no root rights needed"
echo "Install raspi-gpio with: sudo apt install raspi-gpio"
echo
echo "Default Settings:"
echo " ResetSwitch GPIO 2 (I2C, SDA), input, set pullup resistor!"
echo " PowerSwitch GPIO 3 (I2C, SCL), input, set pullup resistor!"
echo " PowerOnControl GPIO 4 (BCM 4), output, high, power on control!"
echo " LEDiodeControl GPIO 14 (BCM 14,TxD ), output, high, low (flash LED)"
echo
echo "Command line Parameters:"
echo " ./multi_switch.sh --nespi+ powerbtn= resetbtn= ledctrl= powerctrl="
echo
echo "For complete shutoff a systemd call must be added. Install service with:"
echo " 1. cd /lib/systemd/system-shutdown"
echo " 2. sudo wget https://raw.githubusercontent.com/crcerror/ES-generic-shutdown/master/shutdown_fan"
echo " 3. sudo chmod +x shutdown_fan"
echo
echo "Additional Info: https://retropie.org.uk/forum/topic/17639"
}
# NesPI+ Case
# Get it from: http://www.retroflag.com
# Button Script by cyperghost
function NESPiPlus() {
#Set GPIOs
[[ -z $1 || $1 == "-1" ]] && GPIO_resetswitch=2 || GPIO_resetswitch=$1
[[ -z $2 || $2 == "-1" ]] && GPIO_powerswitch=3 || GPIO_powerswitch=$2
[[ -z $3 || $3 == "-1" ]] && GPIO_poweronctrl=4 || GPIO_poweronctrl=$3
[[ -z $4 || $4 == "-1" ]] && GPIO_lediodectrl=14 || GPIO_lediodectrl=$4
# Init: Use raspi-gpio to set pullup resistors!
raspi-gpio set $GPIO_resetswitch ip pu
raspi-gpio set $GPIO_powerswitch ip pu
raspi-gpio set $GPIO_poweronctrl op pn dh
raspi-gpio set $GPIO_lediodectrl op dh
#Precheck if you use momentary or latching switch
power=$(raspi-gpio get $GPIO_powerswitch | grep -c "level=1 fsel=0 func=INPUT")
[[ $power == "0" ]] && switchtype="1" # This is a latching switch
[[ $power == "1" ]] && switchtype="0" # This is a momentary push button
until [[ $power == $switchtype ]]; do
power=$(raspi-gpio get $GPIO_powerswitch | grep -c "level=1 fsel=0 func=INPUT")
reset=$(raspi-gpio get $GPIO_resetswitch | grep -c "level=1 fsel=0 func=INPUT")
if [[ $reset == 0 ]]; then
RC_PID=$(check_emurun)
[[ -z $RC_PID ]] && es_action --ES-RESTART
[[ -n $RC_PID ]] && es_action --ES-CLOSEEMU
fi
sleep 1
done
# Flashes LED 4 Times on PowerOff
for iteration in 1 2 3 4; do
raspi-gpio set $GPIO_lediodectrl op dl
sleep 0.25
raspi-gpio set $GPIO_lediodectrl op dh
sleep 0.25
done
# PowerOff LED
# Poweroff PowerCtrl needs script placed to /lib/systemd/system-shutdown/
raspi-gpio set $GPIO_lediodectrl op dl
# Initiate Shutdown per ES
es_action --ES-CLOSEEMU
es_action --ES-POWEROFF
# If ES isn't running use regular shutoff
sudo poweroff
}
# --------------------------------------- G E N E R I C ---------------------------------------
# Help Page
# Generic Button
function help--GENERIC() {
echo "Generic button: Detailed help"
echo
echo "For wiring shematics take a look at:"
echo "https://scribles.net/adding-power-switch-on-raspberry-pi/ and many others!"
echo
echo "Just connect any latching switch or momentary button to your desired GPIO"
echo "and to common ground. This can be done by using GPIO3 and use neighbour-pin"
echo "This is physical PIN 5 and 6 on Pie header"
echo
echo "With a small binary raspi-gpio we set internal pullup resistor!"
echo "raspi-gpio set PIN# ip pu will do this job"
echo
echo "This works with any user, no root rights needed"
echo "Install raspi-gpio with: sudo apt install raspi-gpio"
echo
echo "Default settings:"
echo " PowerSwitch GPIO 3 (I2C, SCL), input, set pullup resistor!"
echo
echo "GPIO3 provides shutdown and let the Raspberry be awakend from deepsleep"
echo
echo "Command line Parameters:"
echo " ./multi_switch.sh --generic powerbtn="
echo " ./multi_switch.sh --generic powerbtn=23 use GPIO 23 for powerswitch!"
}
# GENERIC Button
# This is the simplest way to integrate powerdown/repower ability to your Raspberry
# Button script by cyperghost
# For wiring shematics take a look at: https://scribles.net/adding-power-switch-on-raspberry-pi
function GenericButton() {
# Set GPIO
[[ -z $1 || $1 == "-1" ]] && GPIO_powerswitch=3 || GPIO_powerswitch=$1
# Init: Use raspi-gpio to set pullup resistors!
raspi-gpio set $GPIO_powerswitch ip pu
#Precheck if you use momentary or latching switch
power=$(raspi-gpio get $GPIO_powerswitch | grep -c "level=1 fsel=0 func=INPUT")
[[ $power == "0" ]] && switchtype="1" # This is a latching switch
[[ $power == "1" ]] && switchtype="0" # This is a momentary push button
until [[ $power == $switchtype ]]; do
power=$(raspi-gpio get $GPIO_powerswitch | grep -c "level=1 fsel=0 func=INPUT")
sleep 1
done
# Initiate Shutdown per ES
es_action --ES-CLOSEEMU
es_action --ES-POWEROFF
# If ES isn't running use regular shutoff
sudo poweroff
}
# ------------------------------------- M A U S B E R R Y -------------------------------------
# Help page
# Mausberry Switch
function help--MAUSBERRY() {
echo "Mausberry switch: Detailed help"
echo
echo "For wiring shematics and how to buy please visit:"
echo "https://mausberry-circuits.myshopify.com/"
echo
echo "Defaults Settings:"
echo " Labeled OUT: PowerSwitch GPIO 23, input, export via bash"
echo " Labeled IN: PowerOnControl GPIO 24, output, export high via bash"
echo
echo "This scrip must be called with ROOT right, so use sudo command to start script!"
echo
echo "Attention: This is needed only for momentary push buttons! Latching switches do"
echo " work. If you perform a software shutdown before, be sure to initiate"
echo " ouput signal to the button. Otherwise the mausberry switch will stuck"
echo
echo "I made a little hack with a diode to make this work! Connect the diode to a GPIO"
echo "to Mausberry Button ground und set a script to /lib/systemd/system-shutdown"
echo "I made description here: https://retropie.org.uk/forum/topic/13361 in 57th post"
echo
echo "Please respect the work of others - cyperghost"
}
# Mausberry original script by mausershop
# Sudo command needed
# https://mausberry-circuits.myshopify.com/pages/setup
function Mausberry() {
#Set GPIOs
#this is the GPIO pin connected to the lead on switch labeled OUT
[[ -z $1 || $1 == "-1" ]] && GPIO_powerswitch=23 || GPIO_powerswitch=$1
#this is the GPIO pin connected to the lead on switch labeled IN
[[ -z $2 || $2 == "-1" ]] && GPIO_poweronctrl=24 || GPIO_poweronctrl=$2
echo "$GPIO_powerswitch" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio$GPIO_powerswitch/direction
echo "$GPIO_poweronctrl" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$GPIO_poweronctrl/direction
echo "1" > /sys/class/gpio/gpio$GPIO_poweronctrl/value
while [ 1 = 1 ]; do
power=$(cat /sys/class/gpio/gpio$GPIO_powerswitch/value)
if [ $power = 0 ]; then
sleep 1
else
es_action --ES-CLOSEEMU
es_action --ES-POWEROFF
# If ES isn't running use regular shutoff
poweroff
fi
done
}
# ------------------------------------- O N O F F S H I M -------------------------------------
# Pimoroni SHIM ON OFF
# https://retropie.org.uk/forum/topic/15727
# Sudo command needed
# systemd shutoff needed! See forum post! This uses GPIO 4
# modified scripts by cyperghost
# Defaults are:
# PowerSwitch GPIO 17, input, export via bash
# PowerOnControl GPIO 4, ouput, high, setted low for shutdown!
function OnOffShim() {
#Set GPIO
#This is the GPIO pin connected to the lead on switch labeled BCM17:Status
#PowerOnControl will be shutoff by systemd - read forum post!!
[[ -z $1 || $1 == "-1" ]] && GPIO_powerswitch=17 || GPIO_powerswitch=$1
echo $GPIO_powerswitch > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio$GPIO_powerswitch/direction
power=$(cat /sys/class/gpio/gpio$GPIO_powerswitch/value)
# Here we can use Momentary and Fixed Switches
[[ $power == "0" ]] && switchtype="1"
[[ $power == "1" ]] && switchtype="0"
until [[ $power == $switchtype ]]; do
power=$(cat /sys/class/gpio/gpio$GPIO_powerswitch/value)
sleep 1
done
# Initiate Shutdown per ES
es_action --ES-CLOSEEMU
es_action --ES-POWEROFF
# If ES isn't running use regular shutoff
poweroff
}
# ---------------------------------------------------------------------------------------------
# ------------------------------------------ M A I N ------------------------------------------
# ---------------------------------------------------------------------------------------------
# -------------------------------- M A I N - F U N C T I O N ----------------------------------
# Parameter processing
# only integers from 0-99 are valid!
# Unvalid entries are assigned as -1
function cli_parameter() {
unset call
local PARAMETER=$@
for i in ${PARAMETER[@]}; do
value="${CLI#*$i}"
[[ $value != $PARAMETER ]] && value="${value%% *}" || value="-1"
[[ $value =~ ^[0-9]{1,2}$ ]] || value="-1"
call+=("$value")
done
}
# Check if raspi-gpio ist installed
function pack_check() {
local PACK_CHECK="$(dpkg -s $1|grep -c installed)"
if [[ $PACK_CHECK == 0 ]]; then
echo "raspi-gpio not found! Install!"
exit
fi
}
# -------------------------------- M A I N - P R O G R A M M ----------------------------------
CASE_SEL="${1^^}"
[[ ${2^^} == "HELP" ]] && HELP_ITEM="$CASE_SEL" && CASE_SEL="help"
shift
CLI="${*,,}"
case "$CASE_SEL" in
"--NESPICASE")
# NESPiCase with mod by Yahmez
# https://retropie.org.uk/forum/topic/12424
# Defaults are:
# ResetSwitch GPIO 23, input, set pullup resistor!
# PowerSwitch GPIO 24, input, set pullup resistor!
# PowerOnControl GPIO 25, output, high
# Enter other BCM connections to call
#
pack_check raspi-gpio
cli_parameter resetbtn= powerbtn= powerctrl=
NESPiCase ${call[@]}
;;
"--NESPI+")
# NESPI+ CASE
# http://www.retroflag.com
# Defaults are:
# ResetSwitch GPIO 2 (I2C, SDA), input, set pullup resistor!
# PowerSwitch GPIO 3 (I2C, SCL), input, set pullup resistor!
# PowerOnControl GPIO 4 (BCM 4), output, high, fan control!
# LEDiodeControl GPIO 14 (BCM 14,TxD ), output, high, low (flash LED)
# You will loose I2C function due connections using SDA und SCL
# Enter other BCM-connections to change behaviour
#
pack_check raspi-gpio
cli_parameter resetbtn= powerbtn= powerctrl= ledctrl=
NESPiPlus ${call[@]}
;;
"--GENERIC")
# Generic button
# https://scribles.net/adding-power-switch-on-raspberry-pi/ and many others!
# Just connect any button latching or momentary to your desired GPIO and to common ground
# With raspi-gpio we set internal pullup resistor!
# script by cyperghost
# This works with any user, no sudo needed
# Install raspi-gpio with: sudo apt install raspi-gpio
# Defaults are:
# PowerSwitch GPIO 3 (I2C, SCL), input, set pullup resistor!
# GPIO3 provides shutdown and let the Raspberry be awakend from deepsleep
#
pack_check raspi-gpio
cli_parameter powerbtn=
GenericButton ${call[@]}
;;
"--MAUSBERRY")
# Mausberry original script by mausershop
# Sudo command needed
# https://mausberry-circuits.myshopify.com/pages/setup
# Defaults are:
# PowerSwitch GPIO 23, input, export via bash
# PowerOnControl GPIO 24, output, export high via bash
#
[[ $USER != "root" ]] && echo "Need root privileges... use sudo" && exit
cli_parameter powerbtn= powerctrl=
Mausberry ${call[@]}
;;
"--ONOFFSHIM")
# Pimoroni SHIM ON OFF
# https://retropie.org.uk/forum/topic/15727
# Sudo command needed
# systemd shutoff needed
# modified scripts by cyperghost
# Defaults are:
# PowerSwitch GPIO 17, input, export via bash
# PowerOnControl GPIO 4, ouput, high, setted low for shutdown!
#
[[ $USER != "root" ]] && echo "Need root privileges... use sudo" && exit
cli_parameter powerbtn= powerctrl=
OnOffShim ${call[@]}
;;
"--ES-PID")
# Display ES PID to stdout
ES_PID=$(check_esrun)
[[ -n $ES_PID ]] && echo $ES_PID || echo 0
;;
"--RC-PID")
# Display runcommand.sh PID to stdout
# This helps to detect emulator is running or not
RC_PID=$(check_emurun)
[[ -n $RC_PID ]] && echo $RC_PID || echo 0
;;
"--ES-POWEROFF")
# Closes running Emulators (if available)
# Closes ES
# Perform poweroff
es_action --ES-CLOSEEMU
es_action --ES-POWEROFF
;;
"--ES-RESTART")
# Closes running Emulators (if available)
# Closes ES
# Perform restart of ES only
es_action --ES-CLOSEEMU
es_action --ES-RESTART
;;
"--ES-REBOOT")
# Closes running Emulators (if available)
# Closes ES
# Perform system reboot
es_action --ES-CLOSEEMU
es_action --ES-REBOOT
;;
"--SYSTEMD"|"--ES-SYSTEMD")
# Closes running Emulators (if available)
# Closes ES
# Wait for service to finish
es_action --ES-CLOSEEMU
es_action --ES-SYSTEMD
;;
"--CLOSEEMU"|"--ES-CLOSEEMU")
# Only closes running emulators
es_action --ES-CLOSEEMU
;;
"help")
# Callfunction with name help--DEVICE, help--MAUSBERRY for ex.
# This call suspresses errors and redirects stderr to /dev/null
[[ -z ${HELP_ITEM%--ES-*} || $HELP_ITEM == "--RC-PID" ]] && HELP_ITEM="--ES-SYSTEMCALLS"
help$HELP_ITEM 2>/dev/null
exit 1
;;
"-H"|"--HELP")
echo "Help Screen:"
echo -e "\nSystemcommands:"
echo "--es-pid Shows PID of ES, if ES is not found it outputs 0"
echo "--rc-pid Shows PID of runcommand.sh, if not found it outputs 0"
echo "--es-closeemu Tries to shutdown emulators with cyperghosts method"
echo "--es-systemd This can invoke the shutdown service by meleu"
echo "--es-poweroff Shutdown emulators (if running), Closes ES, performs poweroff"
echo "--es-reboot Shutdown emulators, Closes ES, performs system reboot"
echo "--es-restart Shutdown emulators (if running), Restart ES"
echo -e "\nSwitchDevices:"
echo "--mausberry If you have a Mausberry device, GPIO 23 24 used!"
echo "--onoffshim If you have the Pimoroni OnOff SHIM GPIO 17 and 4 used!"
echo "--nespicase If you use the NESPICASE with yahmez-mod GPIO 23 24 25 used!"
echo "--nespi+ If you own a NESPi+ Case, turn switch in ON position"
echo "--generic Connect latching or push button to GPIO and ground (def: GPIO3)"
echo -e "\nHints:"
echo "For detailed description of each command use: --command help"
echo "Please visit: https://retropie.org.uk/forum/ for questions // cyperghost 2018"
;;
*)
echo "--COMMAND help for detailed help pages!"
echo "--help or -h for overview of options available!"
;;
esac