From ed9270663d24febd216c653b4da180b95af02440 Mon Sep 17 00:00:00 2001 From: Tempest Date: Fri, 15 Nov 2024 20:08:40 +0700 Subject: [PATCH] Preparing for the RDM module --- .../esp32_test0/esp32_test0.ino | 86 +++++++++---------- 1 file changed, 41 insertions(+), 45 deletions(-) diff --git a/src/lightingFirmware/esp32_test0/esp32_test0.ino b/src/lightingFirmware/esp32_test0/esp32_test0.ino index 4dd1e1d..5686d36 100644 --- a/src/lightingFirmware/esp32_test0/esp32_test0.ino +++ b/src/lightingFirmware/esp32_test0/esp32_test0.ino @@ -1,38 +1,28 @@ // Include Section #include "esp_dmx.h" +#include "rdm/controller.h" +#include "rdm/responder.h" #include "UUID.h" +#include "EEPROM.h" #define INTERRUPT_PIN 0 +#include +#include +#include +#include + struct Button { const uint8_t PIN; uint32_t numberKeyPresses; bool pressed; }; - -struct Panel { - int led0; - int led1; - int led2; - int led3 = 0; -}; - -#include -#include -#include -#include - +uint8_t dmxData[DMX_PACKET_SIZE] = {0}; BLEServer* pServer = NULL; -BLECharacteristic* pCharacteristic1 = NULL; -BLECharacteristic* pCharacteristic2 = NULL; bool deviceConnected = false; bool oldDeviceConnected = false; uint32_t value = 0; -String btmessage; - -// See the following for generating UUIDs: -// https://www.uuidgenerator.net/ uint16_t SERVICE_UUID = 20241115; const int panelAmount = 25; @@ -48,18 +38,6 @@ class MyServerCallbacks: public BLEServerCallbacks { deviceConnected = false; } }; -//void setupCharacteristic(BLEService *pService){ -// for(int i = 0; i < panelAmount - 1; i++){ -// pCharacteristics[i] = pService->createCharacteristic( -// CHARACTERISTIC_UUIDS[i], -// BLECharacteristic::PROPERTY_READ | -// BLECharacteristic::PROPERTY_WRITE | -// BLECharacteristic::PROPERTY_NOTIFY | -// BLECharacteristic::PROPERTY_INDICATE -// ); -// }; -//}; - // Defining BOOT button on ESP32 as our built-in button. Button button1 = {INTERRUPT_PIN, 0, false}; @@ -268,11 +246,35 @@ void dmxSetup() { } } + + void setup() { Serial.begin(115200); delay(2000); Serial.print("\nIf you receive this message, ESP32 module has finished setting up Serial Interface for communication."); - // Create the BLE Device + + pinMode(INTERRUPT_PIN, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), isr, RISING); + + //Begin of the DMX Setup + const dmx_port_t dmx_num = DMX_NUM_1; + dmxSetup(); + + Serial.println("Welcome to Pupilometer LED Billboard!"); + const int array_size = 25; + rdm_uid_t uids[array_size]; + + // This function blocks and may take some time to complete! + Serial.printf("Attempting to Discover the Existing DMX Network... "); + int num_uids = rdm_discover_devices_simple(DMX_NUM_1, uids, array_size); + Serial.printf("Done!\n"); + Serial.printf("Discovery found %i UIDs as following:\n", num_uids); + for (int i = 0; i < num_uids; i++){ + printf(UIDSTR "\n", UID2STR(uids[i])); + }; + + + // Create the BLE Device BLEDevice::init("Pupilometer LED Billboard"); // Create the BLE Server @@ -300,7 +302,7 @@ void setup() { // pCharacteristics[i]->addDescriptor(new BLE2902()); Serial.printf("Done\n"); }; - + // Start the service pService->start(); @@ -311,11 +313,6 @@ void setup() { pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter BLEDevice::startAdvertising(); - pinMode(INTERRUPT_PIN, INPUT_PULLUP); - attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), isr, RISING); - dmxSetup(); - const dmx_port_t dmx_num = DMX_NUM_1; - Serial.println("Welcome to Pupilometer LED Billboard!"); } void loop() { @@ -323,7 +320,6 @@ void loop() { // Save Old Mode int modeOld = mode; uint8_t* btMessage[panelAmount]; - uint8_t dmxData[DMX_PACKET_SIZE] = {0}; // notify changed value if (deviceConnected) { Serial.printf("\nI received the following bytes: "); @@ -353,9 +349,6 @@ void loop() { // Increment the value of each slot, excluding the start code. button1.pressed = false; // Reset button status to FALSE }; - if (modeOld != mode){ - Serial.printf("\nChanging Lighting Preset to Preset %d", mode); - } // Serial.printf("\nConstructing Payload using "); if (deviceConnected){ // Serial.printf("Bluetooth Data ..."); @@ -368,9 +361,12 @@ void loop() { } else{ // Serial.printf("Preset Data ..."); - for (int i = 0; i < sizeof(dataSeq[mode]); i++){ - dmxData[i] = dataSeq[mode][i]; - }; + if (modeOld != mode){ + Serial.printf("\nChanging Lighting Preset to Preset %d", mode); + for (int i = 0; i < sizeof(dataSeq[mode]); i++){ + dmxData[i] = dataSeq[mode][i]; + }; + } }; // Serial.printf(" Done"); // Wait until the packet is finished being sent before proceeding.