Files
RRCS-Scripts/ras_pi_RRCS_BusyLight.py
Ben Nicholson 1d7e56f837 Change GPIO Both to Rising
Change how the GPI detection workes, so it only does things on the rising edge
2025-11-19 11:19:57 +11:00

63 lines
2.0 KiB
Python

#!/usr/bin/python3
import os
os.environ['RPI_LGPIO_REVISION'] = "800012"
import time
import requests
import RPi.GPIO as GPIO
RED = "\033[91m"
GREEN = "\033[92m"
RESET = "\033[0m"
BenBusyRRCSdataRising = '''<?xml version="1.0"?>
<methodCall>
<methodName>PressKeyEx</methodName>
<params>
<param><value><string>C0000000001</string></value></param>
<param><value><i4>64</i4></value></param>
<param><value><i4>46</i4></value></param>
<param><value><boolean>0</boolean></value></param>
<param><value><int>2</int></value></param>
<param><value><int>0</int></value></param>
<param><value><int>1</int></value></param>
<param><value><boolean>1</boolean></value></param>
<param><value><boolean>1</boolean></value></param>
<param><value><int>1</int></value></param>
</params>
</methodCall>
'''
BenBusyRRCSdataFalling = '''<?xml version="1.0"?>
<methodCall>
<methodName>PressKeyEx</methodName>
<params>
<param><value><string>C0000000002</string></value></param>
<param><value><i4>64</i4></value></param>
<param><value><i4>46</i4></value></param>
<param><value><boolean>0</boolean></value></param>
<param><value><int>2</int></value></param>
<param><value><int>0</int></value></param>
<param><value><int>1</int></value></param>
<param><value><boolean>1</boolean></value></param>
<param><value><boolean>0</boolean></value></param>
<param><value><int>1</int></value></param>
</params>
</methodCall>
'''
def button_callback(channel):
if GPIO.input(channel):
print(f"{RED}Button pressed{RESET}")
r = requests.post('http://10.75.120.229:8193',headers={'content-type': 'text/xml'},data=BenBusyRRCSdataRising)
time.sleep(0.05)
print(f"{GREEN}Button released{RESET}")
r = requests.post('http://10.75.120.229:8193',headers={'content-type': 'text/xml'},data=BenBusyRRCSdataFalling)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(12, GPIO.RISING, callback=button_callback, bouncetime=200)
input("Press enter to quit\n\n")
GPIO.cleanup()