Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lakka patch & safe shutdown script & audio fix #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions GPi_Case2_patch_lakka3.6/install_patch.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@echo off

set Pan=.\
set OrgFolder=original_files\
set OverlaysFolder=overlays\
set ConfigFile=config.txt
set Dpi24File=dpi24.dtbo

if exist %Pan%%OrgFolder%%ConfigFile% (
echo config.txt is backuped
) else (
copy .\..\config.txt .\original_files\config.txt
)

::if exist %Pan%%OrgFolder%%OverlaysFolder%%Dpi24File% (
:: echo dpi24.dtbo is backuped
::) else (
:: copy .\..\overlays\dpi24.dtbo .\original_files\overlays\dpi24.dtbo
::)

copy .\patch_files\config.txt .\..\config.txt
copy .\patch_files\config_lcd.txt .\..\config_lcd.txt
copy .\patch_files\config_hdmi.txt .\..\config_hdmi.txt
::copy .\patch_files\overlays\dpi24.dtbo .\..\overlays\dpi24.dtbo
::copy .\patch_files\overlays\pwm-audio-pi-zero.dtbo .\..\overlays\pwm-audio-pi-zero.dtbo

echo .
echo -----------------------Successful configuration-----------------------
echo .


pause
95 changes: 95 additions & 0 deletions GPi_Case2_patch_lakka3.6/patch_files/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2009-2014 Stephan Raue ([email protected])
# Copyright (C) 2016-present Team LibreELEC (https://libreelec.tv)
################################################################################
# Bootloader configuration - config.txt
################################################################################

################################################################################
# Memory (System/GPU configuration )
################################################################################

# Default GPU memory split - at least 288M is needed for some 4k HEVC files
gpu_mem=384

################################################################################
# For overclocking and various other settings, see:
# https://www.raspberrypi.org/documentation/configuration/config-txt.md
################################################################################
# Set 'force_turbo=1' to disable dynamic overclocking and enable overclocking always.
force_turbo=0

# Force HDMI even if unplugged or powered off
# hdmi_force_hotplug=1

# Doesn't sent initial active source message.
# Avoids bringing CEC (enabled TV) out of standby and channel switch when
# rebooting.
hdmi_ignore_cec_init=1

################################################################################
# End of default configuration
################################################################################

# Choose between DVI and HDMI output
# 1 = DVI mode (no sound)
# 2 = HDMI mode (sound will be sent if supported and enabled)
# hdmi_drive=2

################################################################################
# Include distribution specific config file if it exists.
################################################################################
[all]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
# Preferred 'Full' Kernel Mode Setting (KMS)
# dtoverlay=vc4-kms-v3d-pi4
# Optional 'Fake' KMS for displays that won't work with 'Full' KMS
dtoverlay=vc4-fkms-v3d

dtoverlay=rpivid-v4l2
disable_overscan=1
disable_splash=1
dtparam=audio=on
hdmi_max_pixel_freq:0=200000000
hdmi_max_pixel_freq:1=200000000
arm_64bit=1
kernel=kernel.img

# if you plug your tv at the same time as your rpi and that the rpi switches from the hdmi or give a low resolution because tv had no enough time to initialize it
# boot_delay=3

# uncomment if you have slow sound issues on composite output
#audio_pwm_mode=0

# enable UART (required for for retroflag)
# affect rpi performances
# enable_uart=1

# activate USB sockets
dtoverlay=dwc2,dr_mode=host

# Ensure only one display output can be used on the Pi4
max_framebuffers=1

[DPI]
# Put any DPI required display code here
# i.e. Official 7" DSI Raspberry Pi Touch Display for 'Full' KMS
#ignore_lcd=1
#dtoverlay=vc4-kms-dsi-7inch
display_rotate=0
dtoverlay=dpi24
overscan_left=0
overscan_right=0
overscan_top=0
overscan_bottom=0
framebuffer_width=640
framebuffer_height=480
#framebuffer_depth=8
enable_dpi_lcd=1
display_default_lcd=1
dpi_group=2
dpi_mode=87
dpi_output_format=0x00016
hdmi_timings=640 0 41 40 41 480 0 18 9 18 0 0 0 60 0 24000000 1 #80hz
#hdmi_timings=640 0 20 1 20 480 0 1 1 2 0 0 0 60 0 24000000 1 #59hz

46 changes: 46 additions & 0 deletions GPi_Case2_patch_lakka3.6/patch_files/config_hdmi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2009-2014 Stephan Raue ([email protected])
# Copyright (C) 2016-present Team LibreELEC (https://libreelec.tv)
################################################################################
# Bootloader configuration - config.txt
################################################################################

################################################################################
# Memory (System/GPU configuration )
################################################################################

# Default GPU memory split - at least 288M is needed for some 4k HEVC files
gpu_mem=384

################################################################################
# For overclocking and various other settings, see:
# https://www.raspberrypi.org/documentation/configuration/config-txt.md
################################################################################
# Set 'force_turbo=1' to disable dynamic overclocking and enable overclocking always.
force_turbo=0

# Force HDMI even if unplugged or powered off
# hdmi_force_hotplug=1

# Doesn't sent initial active source message.
# Avoids bringing CEC (enabled TV) out of standby and channel switch when
# rebooting.
hdmi_ignore_cec_init=1

################################################################################
# End of default configuration
################################################################################

# Choose between DVI and HDMI output
# 1 = DVI mode (no sound)
# 2 = HDMI mode (sound will be sent if supported and enabled)
# hdmi_drive=2

################################################################################
# Include distribution specific config file if it exists.
################################################################################
[all]
include distroconfig.txt

# activate USB sockets
dtoverlay=dwc2,dr_mode=host
95 changes: 95 additions & 0 deletions GPi_Case2_patch_lakka3.6/patch_files/config_lcd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2009-2014 Stephan Raue ([email protected])
# Copyright (C) 2016-present Team LibreELEC (https://libreelec.tv)
################################################################################
# Bootloader configuration - config.txt
################################################################################

################################################################################
# Memory (System/GPU configuration )
################################################################################

# Default GPU memory split - at least 288M is needed for some 4k HEVC files
gpu_mem=384

################################################################################
# For overclocking and various other settings, see:
# https://www.raspberrypi.org/documentation/configuration/config-txt.md
################################################################################
# Set 'force_turbo=1' to disable dynamic overclocking and enable overclocking always.
force_turbo=0

# Force HDMI even if unplugged or powered off
# hdmi_force_hotplug=1

# Doesn't sent initial active source message.
# Avoids bringing CEC (enabled TV) out of standby and channel switch when
# rebooting.
hdmi_ignore_cec_init=1

################################################################################
# End of default configuration
################################################################################

# Choose between DVI and HDMI output
# 1 = DVI mode (no sound)
# 2 = HDMI mode (sound will be sent if supported and enabled)
# hdmi_drive=2

################################################################################
# Include distribution specific config file if it exists.
################################################################################
[all]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
# Preferred 'Full' Kernel Mode Setting (KMS)
# dtoverlay=vc4-kms-v3d-pi4
# Optional 'Fake' KMS for displays that won't work with 'Full' KMS
dtoverlay=vc4-fkms-v3d

dtoverlay=rpivid-v4l2
disable_overscan=1
disable_splash=1
dtparam=audio=on
hdmi_max_pixel_freq:0=200000000
hdmi_max_pixel_freq:1=200000000
arm_64bit=1
kernel=kernel.img

# if you plug your tv at the same time as your rpi and that the rpi switches from the hdmi or give a low resolution because tv had no enough time to initialize it
# boot_delay=3

# uncomment if you have slow sound issues on composite output
#audio_pwm_mode=0

# enable UART (required for for retroflag)
# affect rpi performances
# enable_uart=1

# activate USB sockets
dtoverlay=dwc2,dr_mode=host

# Ensure only one display output can be used on the Pi4
max_framebuffers=1

[DPI]
# Put any DPI required display code here
# i.e. Official 7" DSI Raspberry Pi Touch Display for 'Full' KMS
#ignore_lcd=1
#dtoverlay=vc4-kms-dsi-7inch
display_rotate=0
dtoverlay=dpi24
overscan_left=0
overscan_right=0
overscan_top=0
overscan_bottom=0
framebuffer_width=640
framebuffer_height=480
#framebuffer_depth=8
enable_dpi_lcd=1
display_default_lcd=1
dpi_group=2
dpi_mode=87
dpi_output_format=0x00016
hdmi_timings=640 0 41 40 41 480 0 18 9 18 0 0 0 60 0 24000000 1 #80hz
#hdmi_timings=640 0 20 1 20 480 0 1 1 2 0 0 0 60 0 24000000 1 #59hz

37 changes: 37 additions & 0 deletions GPi_Case2_patch_lakka3.6/uninstall_patch.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@echo off

set Pan=.\
set UpFolder=..\
set OrgFolder=original_files\
set OverlaysFolder=overlays\
set ConfigFile=config.txt
set Dpi24File=dpi24.dtbo
set PwmAudiFile=pwm-audio-pi-zero.dtbo

if exist %Pan%%OrgFolder%%ConfigFile% (
copy .\original_files\config.txt .\..\config.txt
) else (
echo .\original_files\config.txt is not exist
)

::if exist %Pan%%OrgFolder%%OverlaysFolder%%Dpi24File% (
:: copy .\original_files\overlays\dpi24.dtbo .\..\overlays\dpi24.dtbo
:: echo .
:: echo -----------------------Successful configuration-----------------------
:: echo .
::) else (
:: echo .\original_files\overlays\dpi24.dtbo is not exist
::)

::if exist %Pan%%UpFolder%%OverlaysFolder%%PwmAudiFile% (
:: del .\..\overlays\pwm-audio-pi-zero.dtbo
::)
if exist %Pan%%UpFolder%%ConfigHDMIFile% (
del .\..\config_hdmi.txt
del .\..\config_lcd.txt
)
echo .
echo -----------------------Successful configuration-----------------------
echo .

pause
61 changes: 61 additions & 0 deletions lakka_SafeShutdown_gpi2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import RPi.GPIO as GPIO
import os
import time
from multiprocessing import Process

#initialize pins
#powerPin = 3 #pin 5
#ledPin = 14 #TXD
#resetPin = 2 #pin 13
#powerenPin = 4 #pin 5

powerPin = 26
powerenPin = 27

#initialize GPIO settings
def init():
GPIO.setmode(GPIO.BCM)
GPIO.setup(powerPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(powerenPin, GPIO.OUT, initial=GPIO.HIGH)
GPIO.output(powerenPin, GPIO.HIGH)
GPIO.setwarnings(False)

#waits for user to hold button up to 1 second before issuing poweroff command
def poweroff():
while True:
#self.assertEqual(GPIO.input(powerPin), GPIO.LOW)
GPIO.wait_for_edge(powerPin, GPIO.FALLING)
#start = time.time()
#while GPIO.input(powerPin) == GPIO.HIGH:
# time.sleep(0.5)
os.system("systemctl stop retroarch")
time.sleep(1)
os.system("systemctl poweroff")

def lcdrun():
while True:
os.system("sh /storage/.RetroFlag/lcdnext.sh")
time.sleep(1)

def audiofix():
while True:
time.sleep(0.5)
os.system("systemctl restart retroarch")
break

if __name__ == "__main__":
#initialize GPIO settings
init()
#create a multiprocessing.Process instance for each function to enable parallelism
powerProcess = Process(target = poweroff)
powerProcess.start()
lcdrunProcess = Process(target = lcdrun)
lcdrunProcess.start()
audiofixProcess = Process(target = audiofix)
audiofixProcess.start()

powerProcess.join()
lcdrunProcess.join()
audiofixProcess.join()

GPIO.cleanup()
Loading