Modified to accomodate bleak on Jetson AGX

This commit is contained in:
Tempest 2025-08-04 17:31:20 +07:00
parent f258fced41
commit 208643a286

View File

@ -23,7 +23,7 @@ def sectionSerializer(section, color):
result = sectionInitializer()
sectionResult = LampArray[section]
for pos in sectionResult:
result[pos] = int(color,16).to_bytes(3)
result[pos] = int(color,16).to_bytes(3,'big')
return result
def posColorByte(pos, section, color):
@ -41,7 +41,7 @@ async def setOnUserInput(client, chars):
async def setLampToColor(bleClient, bleChars, section, color, colorCenter):
sectionSerial = sectionSerializer(section, color)
sectionSerial[0] = int(colorCenter,16).to_bytes(3)
sectionSerial[0] = int(colorCenter,16).to_bytes(3,'big')
for char in bleChars:
lampPos = bleChars.index(char)
value = sectionSerial[lampPos]
@ -77,7 +77,13 @@ async def connect_to_ble_device(device_name):
print("\n--- Services and Characteristics ---")
for service in services:
print(f"\nService: {service.uuid} (Handle: {service.handle}) - {service.description}")
for char in service.characteristics:
# Get all characteristics for the current service
characteristics = service.characteristics
# Sort the characteristics by handle
sorted_characteristics = sorted(characteristics, key=lambda char: char.handle)
print("Characteristics sorted by handle:")
for char in sorted_characteristics:
print(f" Characteristic: {char.uuid} (Handle: {char.handle})")
print(f" Description: {char.description}")
print(f" Properties: {char.properties}")
@ -92,6 +98,7 @@ async def connect_to_ble_device(device_name):
print(f" Could not read characteristic {char.uuid}: {e}")
else:
print(" (Read not supported)")
# for color in colorArray:
# await setLampToColor(client, service.characteristics, Up, color)
# await setLampToColor(client, service.characteristics, Down, color)
@ -99,11 +106,12 @@ async def connect_to_ble_device(device_name):
# await setLampToColor(client, service.characteristics, Right, color)
# await setLampToColor(client, service.characteristics, Inner, color)
# await setLampToColor(client, service.characteristics, Outer, color)
await setOnUserInput(client, service.characteristics)
if service.uuid != 1:
await setOnUserInput(client, sorted_characteristics)
else:
print(f"Device '{device_name}' not found.")
if __name__ == "__main__":
# Replace 'YourDeviceName' with the actual name of your BLE device
asyncio.run(connect_to_ble_device("Pupilometer LED Billboard"))
asyncio.run(connect_to_ble_device("Pupilometer LED Billboard"))