it just clicked thanks!
Posts by LineOfRahl
-
-
So this does work, but what impact is this polling going to have on the system resources? So that I understand the while loop embedded in the try method, is this while true value constantly being checked by the system? If there is an action taken at the same time as the while loop is being checked, will it cause any errors? I guess I thought the point of using wait for edge was to avoid while loops. I'm going to be adding another ky040 switch to this device also, so I want to be sure my scripts are efficient. Thank you both for your help so far.
-
Does it work if you change "python" to "/usr/bin/python" ?
This didn't seem to have an effect. I thought perhaps my scripts are bad, but if they were they would generate errors no? So I ran the other suggestion
Use journalctl -u kodi-autostart to see error messages.
This did produce an error, but one I'm not sure I know how to correct:
same error in both files. This explains why it works when run in the terminal via ssh and not when it's being launched at startup. There is no place to insert an input(at least that's what I'm assuming the issue is based on my understanding of the command). I assumed that the input command was being used to allow the encoder or the button to send information to the system. If this is not the case, what do I need to change? I don't want the script running using a polling method. I thought I figured it all out, had copied some work people had done, and understood what I was doing, now I feel humbled again.
Any suggestions? Here's a copy of the Rotary Encoder script. I'll leave out the setmode and setup stuff all three variables are GPIO.IN and set to GPIO.PUD_UP
Code
Display Moreclk = 17 dt = 18 sw = 27 clkInitialState - GPIO.input(clk) def my_callback(channel): global clkInitialState global counter try: clkCurrentState = GPIO.input(clk) if clkCurrentState != clkInitialState: dtCurrentState = GPIO.input(dt) if dtCurrentState !=clkCurrentState: counter -=1 os.system("kodi-send --action='RIGHT'") else: counter +=1 os.system("kodo-send --action='LEFT'") clkInitialState = clkCurrentState finally: pass def sw_callback(channel): if GPIO.input(sw) ==GPIO.LOW: time.sleep(.5) if GPIO.input(sw) == GPIO.LOW: os.system("kodi-send --action='PREVIOUSMENU'") elif GPIO.input(sw) == GPIO.HIGH: os.system("kodi-send --action='SELECT'") counter = 0 clkInitialState - GPIO.input(clk) GPIO.add_event_detect(clk,GPIO.FALLING, callback=my_callback,bouncetime=5) GPIO.add_event_detect(sw,GPIO.FALLING,callback=sw_callback,bouncetime=600) input("") #HERE'S THE ERROR. Is this a Python2 thing maybe? GPIO.cleanup()
-
-
Hello
I've got two scripts I've written in python with a lot of help I've gotten from various forums and threads. The scripts control a rotary encoder and a shutdown button. Basic stuff. I can ssh into my pi4 and run the scripts in libreelec using the code below, but ONLY one at a time until the script is exited
The scripts have been added to autostart.sh
Bash#!/bin/bash (python /storage/scripts/script-for-shutdown.py)& (python /storage/scripts/script-for-encoder.py)& exit
I've verified that I ran chmod +x on both files.
I'm simply at a loss for what I've done wrong. When the scripts are run via the terminal, they seem to work well.
Any help would be GREATLY appreciated. I'm sure it's something stupid I'm doing.
Thanks!