Compare commits
No commits in common. "2aaffd8ba1ad4c2a534b5bf92f9909187906b7e4" and "b7cd8d18e81addb6a6f3f56c19084cc56bd4f919" have entirely different histories.
2aaffd8ba1
...
b7cd8d18e8
@ -1 +0,0 @@
|
|||||||
bleak>="1.0.0"
|
|
||||||
@ -23,7 +23,7 @@ def sectionSerializer(section, color):
|
|||||||
result = sectionInitializer()
|
result = sectionInitializer()
|
||||||
sectionResult = LampArray[section]
|
sectionResult = LampArray[section]
|
||||||
for pos in sectionResult:
|
for pos in sectionResult:
|
||||||
result[pos] = int(color,16).to_bytes(3,'big')
|
result[pos] = int(color,16).to_bytes(3)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def posColorByte(pos, section, color):
|
def posColorByte(pos, section, color):
|
||||||
@ -35,15 +35,13 @@ def posColorByte(pos, section, color):
|
|||||||
async def setOnUserInput(client, chars):
|
async def setOnUserInput(client, chars):
|
||||||
while True:
|
while True:
|
||||||
configZone = input("Input Zone [Up, Down, Left, Right, Inner, Outer]: ")
|
configZone = input("Input Zone [Up, Down, Left, Right, Inner, Outer]: ")
|
||||||
if configZone not in list(LampArray.keys()):
|
|
||||||
continue
|
|
||||||
configColor = input("Input Color [000000]: ")
|
configColor = input("Input Color [000000]: ")
|
||||||
configColorCenter = input("Input Color for Center Lamp [000000]: ")
|
configColorCenter = input("Input Color for Center Lamp [000000]: ")
|
||||||
await setLampToColor(client, chars, configZone, configColor, configColorCenter)
|
await setLampToColor(client, chars, configZone, configColor, configColorCenter)
|
||||||
|
|
||||||
async def setLampToColor(bleClient, bleChars, section, color, colorCenter):
|
async def setLampToColor(bleClient, bleChars, section, color, colorCenter):
|
||||||
sectionSerial = sectionSerializer(section, color)
|
sectionSerial = sectionSerializer(section, color)
|
||||||
sectionSerial[0] = int(colorCenter,16).to_bytes(3,'big')
|
sectionSerial[0] = int(colorCenter,16).to_bytes(3)
|
||||||
for char in bleChars:
|
for char in bleChars:
|
||||||
lampPos = bleChars.index(char)
|
lampPos = bleChars.index(char)
|
||||||
value = sectionSerial[lampPos]
|
value = sectionSerial[lampPos]
|
||||||
@ -75,17 +73,11 @@ async def connect_to_ble_device(device_name):
|
|||||||
else:
|
else:
|
||||||
print(f"Failed to connect to {target_device.name}")
|
print(f"Failed to connect to {target_device.name}")
|
||||||
exit(1)
|
exit(1)
|
||||||
services = sorted(client.services, key=lambda serv: serv.handle)
|
services = client.services
|
||||||
print("\n--- Services and Characteristics ---")
|
print("\n--- Services and Characteristics ---")
|
||||||
for service in services:
|
for service in services:
|
||||||
print(f"\nService: {service.uuid} (Handle: {service.handle}) - {service.description}")
|
print(f"\nService: {service.uuid} (Handle: {service.handle}) - {service.description}")
|
||||||
# Get all characteristics for the current service
|
for char in service.characteristics:
|
||||||
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" Characteristic: {char.uuid} (Handle: {char.handle})")
|
||||||
print(f" Description: {char.description}")
|
print(f" Description: {char.description}")
|
||||||
print(f" Properties: {char.properties}")
|
print(f" Properties: {char.properties}")
|
||||||
@ -100,7 +92,6 @@ async def connect_to_ble_device(device_name):
|
|||||||
print(f" Could not read characteristic {char.uuid}: {e}")
|
print(f" Could not read characteristic {char.uuid}: {e}")
|
||||||
else:
|
else:
|
||||||
print(" (Read not supported)")
|
print(" (Read not supported)")
|
||||||
|
|
||||||
# for color in colorArray:
|
# for color in colorArray:
|
||||||
# await setLampToColor(client, service.characteristics, Up, color)
|
# await setLampToColor(client, service.characteristics, Up, color)
|
||||||
# await setLampToColor(client, service.characteristics, Down, color)
|
# await setLampToColor(client, service.characteristics, Down, color)
|
||||||
@ -108,12 +99,11 @@ async def connect_to_ble_device(device_name):
|
|||||||
# await setLampToColor(client, service.characteristics, Right, color)
|
# await setLampToColor(client, service.characteristics, Right, color)
|
||||||
# await setLampToColor(client, service.characteristics, Inner, color)
|
# await setLampToColor(client, service.characteristics, Inner, color)
|
||||||
# await setLampToColor(client, service.characteristics, Outer, color)
|
# await setLampToColor(client, service.characteristics, Outer, color)
|
||||||
if service.handle != 1:
|
await setOnUserInput(client, service.characteristics)
|
||||||
await setOnUserInput(client, sorted_characteristics)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(f"Device '{device_name}' not found.")
|
print(f"Device '{device_name}' not found.")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Replace 'YourDeviceName' with the actual name of your BLE device
|
# 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"))
|
||||||
Loading…
Reference in New Issue
Block a user