from gpiozero import Buttonfrom subprocess import check_callfrom signal import pauseimport os.path
#String VarsdirShaders = "/opt/retropie/configs/all/retroarch/shaders/"dirGlobalRef = "/opt/retropie/configs/all/retroarch/config/"globalFname = "global.glslp"path2globalRef = dirGlobalRef + globalFnamepath2global = dirShaders + globalFname
#Functions>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#**********************CLEAR SHADERS**********************************def funcClearShaders(): print("funcClearShaders") file_exists = os.path.exists(path2globalRef) if file_exists: print ("global.glslp ref exists deleting") os.chdir(dirGlobalRef) check_call(['rm', globalFname])
#The following code is pointless since video_shader_watchFiles On in retroarch.cfg setting does not reload presets.#If it realoded the preset this would work.# file_exists = os.path.exists(path2global)# if file_exists:# os.chdir(dirShaders)# File_object = open(globalFname,"w")#Just Empty Contents# File_object.close()
#*************************SET_SHADER*********************************def funcSetShader(shaderfName): print("funcSetShader") print(shaderfName) file_exists = os.path.exists(path2globalRef) if not file_exists: print ("global.glslp ref does not exist adding") os.chdir(dirGlobalRef) File_object = open(globalFname,"w") File_object.write("#reference \"../shaders/global.glslp\"") File_object.close()
os.chdir(dirShaders) file_exists = os.path.exists(path2global) if file_exists: print("Truncating File") File_object = open(globalFname,"w")#Truncate Contents read_file = open(shaderfName, "r") for line in read_file: print(line) File_object.write(line) File_object.close() else: print ("copying file") check_call(['cp', '-f', shaderfName, globalFname])#Just copy the whole file if nothing is there yet.
#def onGpio3Closed():# print("gpio3Pressed")# Powers on PI When Circuit Closed, this script will not be running.
def onGpio3Open():#Arcade 1up switched to OFF
print("gpio3Released") check_call(['sudo', 'poweroff'])
def onGpio17Closed(): print("gpio17Pressed") # check_call(['sudo', './SetServoStik', '8']) funcSetShader("zfast_crt_standard_vertical.glslp")
def onGpio17Open(): print("gpio17Released") funcClearShaders()
def onGpio27Closed(): print("gpio27Pressed") #check_call(['sudo', './SetServoStik', '4']) funcSetShader("xbr-lv1-noblend.glslp")
def onGpio27Open(): print("gpio27Released") funcClearShaders()
#Main Execution Starts Here
gpio3Btn = Button(3)#gpio3Btn.when_pressed = onGpio3Closedgpio3Btn.when_released = onGpio3Open
gpio17Btn = Button(17)gpio17Btn.when_pressed = onGpio17Closedgpio17Btn.when_released = onGpio17Open
gpio27Btn = Button(27)gpio27Btn.when_pressed = onGpio27Closedgpio27Btn.when_released = onGpio27Open
pause()