diff --git a/src/controllerSoftware/app.py b/src/controllerSoftware/app.py index 0fb368b..cd18cd0 100644 --- a/src/controllerSoftware/app.py +++ b/src/controllerSoftware/app.py @@ -97,16 +97,24 @@ async def set_full_matrix_on_ble(colorSeries): colorSeries[24] = temp_color_12 # ===================================================================== - # Ensure all characteristics are available before writing - if len(ble_characteristics) != lampAmount: - print(f"Mismatch in lamp amount. Expected {lampAmount}, got {len(ble_characteristics)}.") - return - print(f"Constructed the following matrix data: {colorSeries}") - # Write each byte string to its corresponding characteristic - for i, char in enumerate(ble_characteristics): - value_to_write = colorSeries[i] - print(f"Setting Lamp {i} ({char.uuid}) to {value_to_write.hex()}") - await ble_client.write_gatt_char(char.uuid, value_to_write) + if DEBUG_MODE: + # Ensure all characteristics are available before writing + print(f"Confirmed DEBUG set to true.") + if len(ble_characteristics) != lampAmount: + print(f"Mismatch in lamp amount. Expected {lampAmount}, got {len(ble_characteristics)}.") + return + print(f"Constructed the following matrix data: {colorSeries}") + # Write each byte string to its corresponding characteristic + for i, char in enumerate(ble_characteristics): + value_to_write = colorSeries[i] + print(f"Setting Lamp {i} ({char.uuid}) to {value_to_write.hex()}") + await ble_client.write_gatt_char(char.uuid, value_to_write) + else: + print(f"Confirmed DEBUG set to false.") + value_to_write = b"".join([color for color in colorSeries]) + print(value_to_write) + print(f"Setting lamps to {value_to_write.hex()}") + await ble_client.write_gatt_char(ble_characteristics[0].uuid, value_to_write) async def connect_to_ble_device(): diff --git a/src/lightingFirmware/esp32_test0/esp32_test0.ino b/src/lightingFirmware/esp32_test0/esp32_test0.ino index b3e568f..d7c6707 100644 --- a/src/lightingFirmware/esp32_test0/esp32_test0.ino +++ b/src/lightingFirmware/esp32_test0/esp32_test0.ino @@ -15,20 +15,19 @@ bool debugMode = true; int bleCharCount; const int channelPerLamp = 4; -int expectedLampCount = 25; -//DMX_PACKET_SIZE = 100; +const int expectedLampCount = 25; +const int dmxPacketSize = channelPerLamp * expectedLampCount + 1; // struct Button { const uint8_t PIN; uint32_t numberKeyPresses; bool pressed; }; -uint8_t dmxData[101] = {0}; +uint8_t dmxData[DMX_PACKET_SIZE] = {0}; BLEServer* pServer = NULL; bool deviceConnected = false; bool oldDeviceConnected = false; -uint32_t value = 0; uint16_t SERVICE_UUID = 20241115; const int panelAmount = 25; @@ -53,7 +52,7 @@ const int modeAmount = 16; uint8_t brightnessMax = 20; uint8_t universalBrightness = 10; -uint8_t dataSeq[modeAmount][101] = +uint8_t dataSeq[modeAmount][DMX_PACKET_SIZE] = { { 0, @@ -295,8 +294,8 @@ void setup() { bleCharCount = (panelAmount * debugMode) + !debugMode; Serial.printf("\nCalculating BLE MTU ..."); uint16_t bleMTU = ((panelAmount * 3) / bleCharCount) + 3; - // Serial.printf("\nSetting BLE MTU to %i bytes... ", bleMTU); - // BLEDevice::setMTU(bleMTU + 3); + Serial.printf("\nSetting BLE MTU to %i bytes... ", bleMTU); + BLEDevice::setMTU(bleMTU + 3); Serial.printf("Done!\n"); for (uint32_t i = 0; i < bleCharCount; i++){ @@ -364,7 +363,7 @@ void loop() { serialRead(); if (modeOld != mode){ Serial.printf("\nChanging Lighting Preset to Preset %d", mode); - uint8_t lampData[75]; + uint8_t lampData[DMX_PACKET_SIZE / 4 * 3]; Serial.printf("\nDetected preset %i size: %i", mode, sizeof(dataSeq[mode])); for (int i = 0; i < sizeof(dataSeq[mode]); i++){ dmxData[i] = dataSeq[mode][i]; @@ -376,7 +375,7 @@ void loop() { lampData[j] = dataSeq[mode][i]; } }; - pCharacteristics[0]->setValue(lampData, 75); + pCharacteristics[0]->setValue(lampData, expectedLampCount * 3); } Serial.printf("\nConstructing DMX Payload with size "); for (int i = 0; i < bleCharCount; i++){ @@ -388,7 +387,7 @@ void loop() { int lampSum = i*3 + j; int dmxAddress = (lampSum / 3) * 4 + lampSum % 3 + 1; dmxData[dmxAddress] = packet; - Serial.printf("[[%i,%i] %i - %i] ",i , j, dmxAddress, packet); + // Serial.printf("[[%i,%i] %i - %i] ",i , j, dmxAddress, packet); }; }; Serial.printf("\n"); @@ -397,6 +396,6 @@ void loop() { // Wait until the packet is finished being sent before proceeding. dmx_wait_sent(DMX_NUM_1, DMX_TIMEOUT_TICK); // Now write the packet synchronously! - dmx_write(DMX_NUM_1, dmxData, 100); + dmx_write(DMX_NUM_1, dmxData, DMX_PACKET_SIZE); dmx_send(DMX_NUM_1); }