Compare commits
4 Commits
b7cd8d18e8
...
2aaffd8ba1
| Author | SHA1 | Date | |
|---|---|---|---|
| 2aaffd8ba1 | |||
| 54a02ad149 | |||
| 208643a286 | |||
| f258fced41 |
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
bleak>="1.0.0"
|
||||
@ -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):
|
||||
@ -35,13 +35,15 @@ def posColorByte(pos, section, color):
|
||||
async def setOnUserInput(client, chars):
|
||||
while True:
|
||||
configZone = input("Input Zone [Up, Down, Left, Right, Inner, Outer]: ")
|
||||
if configZone not in list(LampArray.keys()):
|
||||
continue
|
||||
configColor = input("Input Color [000000]: ")
|
||||
configColorCenter = input("Input Color for Center Lamp [000000]: ")
|
||||
await setLampToColor(client, chars, configZone, configColor, configColorCenter)
|
||||
|
||||
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]
|
||||
@ -73,11 +75,17 @@ async def connect_to_ble_device(device_name):
|
||||
else:
|
||||
print(f"Failed to connect to {target_device.name}")
|
||||
exit(1)
|
||||
services = client.services
|
||||
services = sorted(client.services, key=lambda serv: serv.handle)
|
||||
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 +100,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,7 +108,8 @@ 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.handle != 1:
|
||||
await setOnUserInput(client, sorted_characteristics)
|
||||
|
||||
else:
|
||||
print(f"Device '{device_name}' not found.")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user