Update ras_pi_RRCS_BusyLight.py
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
os.environ['RPI_LGPIO_REVISION'] = "800012"
|
||||
|
||||
import requests
|
||||
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
RED = "\033[91m"
|
||||
GREEN = "\033[92m"
|
||||
RESET = "\033[0m"
|
||||
|
||||
|
||||
BenBusyRRCSdataRising = '''<?xml version="1.0"?>
|
||||
<methodCall>
|
||||
@@ -15,8 +21,8 @@ BenBusyRRCSdataRising = '''<?xml version="1.0"?>
|
||||
<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> <!-- IsVirtKey -->
|
||||
<param><value><boolean>1</boolean></value></param> <!-- Press/Release -->
|
||||
<param><value><boolean>1</boolean></value></param>
|
||||
<param><value><boolean>1</boolean></value></param>
|
||||
<param><value><int>1</int></value></param>
|
||||
</params>
|
||||
</methodCall>
|
||||
@@ -33,31 +39,36 @@ BenBusyRRCSdataFalling = '''<?xml version="1.0"?>
|
||||
<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> <!-- IsVirtKey -->
|
||||
<param><value><boolean>0</boolean></value></param> <!-- Press/Release -->
|
||||
<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_callbackRising(channel):
|
||||
print("Button was pushed!")
|
||||
r = requests.post('http://10.75.120.229:8193', headers = {'content-type': 'text/xml'}, data = BenBusyRRCSdataRising)
|
||||
print (r.text)
|
||||
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
|
||||
)
|
||||
else:
|
||||
print(f"{GREEN}Button released{RESET}")
|
||||
r = requests.post(
|
||||
'http://10.75.120.229:8193',
|
||||
headers={'content-type': 'text/xml'},
|
||||
data=BenBusyRRCSdataFalling
|
||||
)
|
||||
print(r.text)
|
||||
|
||||
def button_callbackFalling(channel):
|
||||
print("Button was Released!")
|
||||
r = requests.post('http://10.75.120.229:8193', headers = {'content-type': 'text/xml'}, data = BenBusyRRCSdataFalling)
|
||||
print (r.text)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setmode(GPIO.BOARD)
|
||||
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
|
||||
GPIO.setwarnings(False) # Ignore warning for now
|
||||
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
|
||||
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 10 to be an input pin and set initial value to be pulle>
|
||||
# One event detector, both edges:
|
||||
GPIO.add_event_detect(12, GPIO.BOTH, callback=button_callback, bouncetime=200)
|
||||
|
||||
GPIO.add_event_detect(12,GPIO.RISING,callback=button_callbackRising) # Setup event on pin 10 rising edge
|
||||
|
||||
GPIO.add_event_detect(12,GPIO.FALLING,callback=button_callbackFalling)
|
||||
|
||||
message = input("Press enter to quit\n\n") # Run until someone presses enter
|
||||
|
||||
GPIO.cleanup() # Clean up
|
||||
input("Press enter to quit\n\n")
|
||||
GPIO.cleanup()
|
||||
Reference in New Issue
Block a user