Python helper scripts for testing

This commit is contained in:
Snoweuph 2025-01-12 03:09:25 +01:00
parent d7fdb2a10f
commit 4a4e615105
Signed by: snoweuph
GPG key ID: BEFC41DA223CEC55
3 changed files with 66 additions and 0 deletions

47
drivers/helpers/listen.py Normal file
View file

@ -0,0 +1,47 @@
import hid
import time
import sys
import threading
# Vendor ID and Product ID for the iBridge device
TOUCHBAR_VENDOR_ID = 0x05ac
TOUCHBAR_PRODUCT_ID = 0x8600
exit_flag = False
def listen_to_touchbar(device):
global exit_flag
print("Listening for incoming data from the Touch Bar...")
while not exit_flag:
try:
data = device.read(64)
if data:
print(f"Received data: {data}")
except Exception as e:
print(f"Error reading data: {e}")
break
device = hid.device()
try:
device.open(TOUCHBAR_VENDOR_ID, TOUCHBAR_PRODUCT_ID)
print("Device opened successfully")
listener_thread = threading.Thread(target=listen_to_touchbar, args=(device,))
listener_thread.daemon = True
listener_thread.start()
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
print("\nInterrupted by user. Exiting...")
exit_flag = True
listener_thread.join()
break
except OSError as e:
print(f"Failed to open device: {e}")
sys.exit(1)
finally:
device.close()
print("Device closed")

View file

@ -0,0 +1 @@
hidapi

18
drivers/helpers/send.py Normal file
View file

@ -0,0 +1,18 @@
import hid
import time
# Vendor ID and Product ID for the iBridge device
TOUCHBAR_VENDOR_ID = 0x05ac
TOUCHBAR_PRODUCT_ID = 0x8600
device = hid.device()
try:
device.open(TOUCHBAR_VENDOR_ID, TOUCHBAR_PRODUCT_ID)
device.write([0x02, 0x01]) # Sending Data
except OSError as e:
print(f"Failed to open device: {e}")
finally:
device.close()
print("Device closed")