04-28-2021, 01:16 AM
(This post was last modified: 04-28-2021, 01:18 AM by donutswdad.
Edit Reason: name change
)
I used the PiIR library to make a version of your script that barely uses any CPU and is much simpler. PiIR requires the use of python3, so it can still be used along side your guide except change the references from "python" to "python3".
Thought I would share it with everyone.
Thought I would share it with everyone.
Code:
from piir.io import receive
from piir.decode import decode
import subprocess,piir,sys
# GPIO of IR receiver
pinr = 24
# unique IR snippet (not entire dict) in button press of apple remote
# captured using "test" mode of this script
ok = r"xee\x87\\\xab"
menu = r"xee\x87\x03\xab"
down = r"xee\x87\x0c\xab"
up = r"xee\x87\n\xab"
left = r"xee\x87\t\xab"
right = r"xee\x87\x06\xab"
play = r"xee\x87_\xab"
# if 'test' is entered as argument then only show remote button press codes
# ex: python3 moode_ir_control.py test
# used to capture button press snippets as shown in previous section
if (len(sys.argv) - 1):
if sys.argv[1] == 'test':
while True:
print(decode(receive(pinr)))
while True:
data = str(decode(receive(pinr)))
if ok in data:
subprocess.call(["mpc", "toggle"])
elif menu in data:
subprocess.call(["mpc", "stop"])
elif down in data:
subprocess.call(["mpc", "seek","-5%"])
elif up in data:
subprocess.call(["mpc", "seek","+5%"])
elif left in data:
subprocess.call(["mpc", "prev"])
elif right in data:
subprocess.call(["mpc", "next"])