From 6bf9ede793f2f0e9830b8818a5bac06a217a81d5 Mon Sep 17 00:00:00 2001 From: Tempest Date: Wed, 17 Sep 2025 12:47:12 +0700 Subject: [PATCH] Changing firmware for modifying the whole lamp at the same time. --- .../esp32_test0/.theia/launch.json | 8 --- .../esp32_test0/esp32_test0.ino | 52 +++++++++++++------ 2 files changed, 36 insertions(+), 24 deletions(-) delete mode 100644 src/lightingFirmware/esp32_test0/.theia/launch.json diff --git a/src/lightingFirmware/esp32_test0/.theia/launch.json b/src/lightingFirmware/esp32_test0/.theia/launch.json deleted file mode 100644 index 7e4253b..0000000 --- a/src/lightingFirmware/esp32_test0/.theia/launch.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - "version": "0.2.0", - "configurations": [ - - ] -} diff --git a/src/lightingFirmware/esp32_test0/esp32_test0.ino b/src/lightingFirmware/esp32_test0/esp32_test0.ino index 5686d36..cc657f8 100644 --- a/src/lightingFirmware/esp32_test0/esp32_test0.ino +++ b/src/lightingFirmware/esp32_test0/esp32_test0.ino @@ -12,6 +12,10 @@ #include #include +bool debugMode = true; +int bleCharCount; +const int channelPerLamp = 4; + struct Button { const uint8_t PIN; uint32_t numberKeyPresses; @@ -234,8 +238,7 @@ void dmxSetup() { dmx_set_pin(dmx_num, tx_pin, rx_pin, rts_pin); Serial.print("Done\n"); } - - void serialRead(){ +void serialRead(){ String incomingByte; if (Serial.available() > 0) { // read the incoming byte: @@ -283,10 +286,18 @@ void setup() { // Create the BLE Service BLEService *pService = pServer->createService(SERVICE_UUID,52); - + const bool debugMode = true; + // Serial.printf(debugMode); // Create a BLE Characteristic + Serial.printf("\nCalculating BLE Charateristic Count"); + 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("Done!\n"); - for (uint32_t i = 0; i < panelAmount; i++){ + for (uint32_t i = 0; i < bleCharCount; i++){ UUID uuid; uuid.seed(i+1); uuid.generate(); @@ -294,6 +305,7 @@ void setup() { pCharacteristics[i] = pService->createCharacteristic( i+1, +// BLEUUID(uuid.toCharArray()), BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | @@ -316,19 +328,21 @@ void setup() { } void loop() { - dmx_send(DMX_NUM_1); // Save Old Mode int modeOld = mode; - uint8_t* btMessage[panelAmount]; + int msgSize; + uint8_t* btMessage[bleCharCount]; // notify changed value if (deviceConnected) { - Serial.printf("\nI received the following bytes: "); - for (int i = 0; i < panelAmount;i++){ + for (int i = 0; i < bleCharCount;i++){ btMessage[i] = pCharacteristics[i]->getData(); - for (int j = 0; j < sizeof(btMessage[i]); j++){ - Serial.printf("%d ",btMessage[i][j]); - }; - }; + msgSize = pCharacteristics[i]->getLength(); + Serial.printf("\nI have received %i bytes.", msgSize); + //for (int j = 0; j < msgSize; j++){ + // Serial.printf("[%i - %d] ",j,btMessage[i][j]); + //}; + //Serial.printf("\n"); + } } // disconnecting if (!deviceConnected && oldDeviceConnected) { @@ -352,12 +366,17 @@ void loop() { // Serial.printf("\nConstructing Payload using "); if (deviceConnected){ // Serial.printf("Bluetooth Data ..."); - for (int i = 0; i < panelAmount; i++){ - for (int j = 0; j < sizeof(btMessage[i]); j++){ - dmxData[i*4 + j + 1] = btMessage[i][j]; -// Serial.printf("."); + Serial.printf("\nConstructing DMX Payload: "); + for (int i = 0; i < bleCharCount; i++){ + for (int j = 0; j < msgSize; j++){ + int packet = btMessage[i][j]; + int k = i*3 + j; + int dmxAddress = (k / 3) * 4 + k % 3 + 1; + dmxData[dmxAddress] = packet; + Serial.printf("[[%i,%i] %i - %i] ",i , j, dmxAddress, packet); }; }; + Serial.printf("\n"); } else{ // Serial.printf("Preset Data ..."); @@ -373,4 +392,5 @@ void loop() { dmx_wait_sent(DMX_NUM_1, DMX_TIMEOUT_TICK); // Now write the packet synchronously! dmx_write(DMX_NUM_1, dmxData, 100); + dmx_send(DMX_NUM_1); }