button-buddy/test_scripts/test1.py

22 lines
573 B
Python
Executable File

#!/usr/bin/env python3
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
NULL_CHAR = chr(0)
def write_report(report):
with open('/dev/hidg0', 'rb+') as fd:
fd.write(report.encode())
while True:
if not(GPIO.input(26)): # 26 = a
write_report(NULL_CHAR*2+chr(4)+NULL_CHAR*5)
write_report(NULL_CHAR*8)
if not(GPIO.input(16)): # 16 = b
write_report(chr(32)+NULL_CHAR+chr(5)+NULL_CHAR*5)
write_report(NULL_CHAR*8)