diff --git a/src/controllerSoftware/run.py b/src/controllerSoftware/run.py index d3e76f8..d1fec9c 100644 --- a/src/controllerSoftware/run.py +++ b/src/controllerSoftware/run.py @@ -3,14 +3,15 @@ import time from bleak import BleakScanner, BleakClient lampAmount = 25 -Center = [0] -Up = [1,2,8,9,10,11,12,13,23,24] -Down = [4,5,6,15,16,17,18,19,20,21] -Left = [6,3,8,9,19,20,21,22,23,12] -Right = [2,7,4,11,24,13,14,15,16,17] -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] - +LampArray = { + "Center": [0], + "Up": [1,2,8,9,10,11,12,13,23,24], + "Down": [4,5,6,15,16,17,18,19,20,21], + "Left": [6,3,8,9,19,20,21,22,23,12], + "Right": [2,7,4,11,24,13,14,15,16,17], + "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"] colorArrayTest = ["050000","000500"] @@ -20,7 +21,7 @@ def sectionInitializer(): def sectionSerializer(section): result = sectionInitializer() - sectionResult = Center + section + sectionResult = LampArray["Center"] + LampArray[section] for pos in sectionResult: result[pos] = 1 return result @@ -31,18 +32,25 @@ def posColorByte(pos, section, color): print(result) return result.to_bytes(3) +async def setOnUserInput(client, chars): + while True: + configZone = input("Input Zone [Up, Down, Left, Right, Inner, Outer]: ") + configColor = input("Input Color [000000]: ") + await setLampToColor(client, chars, configZone, configColor) + async def setLampToColor(bleClient, bleChars, section, color): sectionSerial = sectionSerializer(section) for char in bleChars: lampPos = bleChars.index(char) print(f"Setting Lamp number {lampPos}") value = posColorByte(lampPos, sectionSerial, color) - await bleClient.write_gatt_char(char.uuid, value) - time.sleep(10) + await bleClient.write_gatt_char(char.uuid, value) async def connect_to_ble_device(device_name): print(f"Scanning for device: {device_name}...") devices = await BleakScanner.discover() + global services + global client target_device = None for device in devices: @@ -81,13 +89,14 @@ 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) - await setLampToColor(client, service.characteristics, Left, color) - await setLampToColor(client, service.characteristics, Right, color) - await setLampToColor(client, service.characteristics, Inner, color) - await setLampToColor(client, service.characteristics, Outer, color) +# for color in colorArray: +# await setLampToColor(client, service.characteristics, Up, color) +# await setLampToColor(client, service.characteristics, Down, color) +# await setLampToColor(client, service.characteristics, Left, color) +# 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) else: print(f"Device '{device_name}' not found.")