Compare commits

...

3 Commits

Author SHA1 Message Date
Tempest
b7cd8d18e8 Final Commit for TUI 2025-07-25 18:15:11 +07:00
Tempest
528ca5da5b Splitted Center into its own value... ugly solution 2025-07-25 17:54:38 +07:00
Tempest
cf9a3d7c93 Implemented a basic Text-based User Interface 2025-07-25 16:57:16 +07:00

View File

@ -3,46 +3,57 @@ import time
from bleak import BleakScanner, BleakClient from bleak import BleakScanner, BleakClient
lampAmount = 25 lampAmount = 25
Center = [0] LampArray = {
Up = [1,2,8,9,10,11,12,13,23,24] "Center": [0],
Down = [4,5,6,15,16,17,18,19,20,21] "Up": [1,2,8,9,10,11,12,13,23,24],
Left = [6,3,8,9,19,20,21,22,23,12] "Down": [4,5,6,15,16,17,18,19,20,21],
Right = [2,7,4,11,24,13,14,15,16,17] "Left": [6,3,8,9,19,20,21,22,23,12],
Inner = [1,2,3,4,5,6,7,8] "Right": [2,7,4,11,24,13,14,15,16,17],
Outer = [9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24] "Inner": [1,2,3,4,5,6,7,8],
"Outer": [9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
}
colorArray = ["500000","005000","000050"] 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 = Center + 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):
intColor = int(color, 16) intColor = int(color, 16)
result = intColor * section[pos] result = int(intColor * section[pos])
print(result) print(result)
return result.to_bytes(3) return result.to_bytes(3)
async def setLampToColor(bleClient, bleChars, section, color): async def setOnUserInput(client, chars):
sectionSerial = sectionSerializer(section) while True:
configZone = input("Input Zone [Up, Down, Left, Right, Inner, Outer]: ")
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)
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)
time.sleep(10)
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}...")
devices = await BleakScanner.discover() devices = await BleakScanner.discover()
global services
global client
target_device = None target_device = None
for device in devices: for device in devices:
@ -81,13 +92,14 @@ 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)
await setLampToColor(client, service.characteristics, Left, color) # await setLampToColor(client, service.characteristics, Left, color)
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)
await setOnUserInput(client, service.characteristics)
else: else:
print(f"Device '{device_name}' not found.") print(f"Device '{device_name}' not found.")