Final Commit for TUI

This commit is contained in:
Tempest 2025-07-25 18:15:11 +07:00
parent 528ca5da5b
commit b7cd8d18e8

View File

@ -16,14 +16,14 @@ colorArray = ["500000","005000","000050"]
colorArrayTest = ["050000","000500"] colorArrayTest = ["050000","000500"]
def sectionInitializer(): def sectionInitializer():
result = [0] * lampAmount result = [b'\x00\x00\x00'] * lampAmount
return result return result
def sectionSerializer(section): def sectionSerializer(section, color):
result = sectionInitializer() result = sectionInitializer()
sectionResult = LampArray[section] sectionResult = LampArray[section]
for pos in sectionResult: for pos in sectionResult:
result[pos] = 1 result[pos] = int(color,16).to_bytes(3)
return result return result
def posColorByte(pos, section, color): def posColorByte(pos, section, color):
@ -40,14 +40,14 @@ async def setOnUserInput(client, chars):
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) sectionSerial = sectionSerializer(section, color)
colorCenterFactor = int(colorCenter, 16)/int(color,16) sectionSerial[0] = int(colorCenter,16).to_bytes(3)
sectionSerial[0] = colorCenterFactor
for char in bleChars: for char in bleChars:
lampPos = bleChars.index(char) lampPos = bleChars.index(char)
print(f"Setting Lamp number {lampPos}") value = sectionSerial[lampPos]
value = posColorByte(lampPos, sectionSerial, color) print(f"Setting Lamp number {lampPos} to {value}")
await bleClient.write_gatt_char(char.uuid, value)
await bleClient.write_gatt_char(char.uuid, value)
async def connect_to_ble_device(device_name): async def connect_to_ble_device(device_name):
print(f"Scanning for device: {device_name}...") print(f"Scanning for device: {device_name}...")