Remove misc file and modified firmware flow to commit data to BLE buffer
This commit is contained in:
parent
6bf9ede793
commit
bda937a889
@ -1,88 +0,0 @@
|
|||||||
#include <BLEDevice.h>
|
|
||||||
#include <BLEServer.h>
|
|
||||||
#include <BLEUtils.h>
|
|
||||||
#include <BLE2902.h>
|
|
||||||
|
|
||||||
BLEServer* pServer = NULL;
|
|
||||||
BLECharacteristic* pCharacteristic = NULL;
|
|
||||||
bool deviceConnected = false;
|
|
||||||
bool oldDeviceConnected = false;
|
|
||||||
uint32_t value = 0;
|
|
||||||
String btmessage;
|
|
||||||
|
|
||||||
// See the following for generating UUIDs:
|
|
||||||
// https://www.uuidgenerator.net/
|
|
||||||
|
|
||||||
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
|
|
||||||
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
|
||||||
|
|
||||||
|
|
||||||
class MyServerCallbacks: public BLEServerCallbacks {
|
|
||||||
void onConnect(BLEServer* pServer) {
|
|
||||||
deviceConnected = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
void onDisconnect(BLEServer* pServer) {
|
|
||||||
deviceConnected = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
Serial.begin(115200);
|
|
||||||
|
|
||||||
// Create the BLE Device
|
|
||||||
BLEDevice::init("ESP32");
|
|
||||||
|
|
||||||
// Create the BLE Server
|
|
||||||
pServer = BLEDevice::createServer();
|
|
||||||
pServer->setCallbacks(new MyServerCallbacks());
|
|
||||||
|
|
||||||
// Create the BLE Service
|
|
||||||
BLEService *pService = pServer->createService(SERVICE_UUID);
|
|
||||||
|
|
||||||
// Create a BLE Characteristic
|
|
||||||
pCharacteristic = pService->createCharacteristic(
|
|
||||||
CHARACTERISTIC_UUID,
|
|
||||||
BLECharacteristic::PROPERTY_READ |
|
|
||||||
BLECharacteristic::PROPERTY_WRITE |
|
|
||||||
BLECharacteristic::PROPERTY_NOTIFY |
|
|
||||||
BLECharacteristic::PROPERTY_INDICATE
|
|
||||||
);
|
|
||||||
|
|
||||||
// https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
|
|
||||||
// Create a BLE Descriptor
|
|
||||||
pCharacteristic->addDescriptor(new BLE2902());
|
|
||||||
|
|
||||||
// Start the service
|
|
||||||
pService->start();
|
|
||||||
|
|
||||||
// Start advertising
|
|
||||||
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
|
|
||||||
pAdvertising->addServiceUUID(SERVICE_UUID);
|
|
||||||
pAdvertising->setScanResponse(false);
|
|
||||||
pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter
|
|
||||||
BLEDevice::startAdvertising();
|
|
||||||
Serial.println("Waiting a client connection to notify...");
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
// notify changed value
|
|
||||||
if (deviceConnected) {
|
|
||||||
btmessage = pCharacteristic->getData();
|
|
||||||
mode = btmessage;
|
|
||||||
}
|
|
||||||
// disconnecting
|
|
||||||
if (!deviceConnected && oldDeviceConnected) {
|
|
||||||
delay(500); // give the bluetooth stack the chance to get things ready
|
|
||||||
pServer->startAdvertising(); // restart advertising
|
|
||||||
Serial.println("Start advertising");
|
|
||||||
oldDeviceConnected = deviceConnected;
|
|
||||||
}
|
|
||||||
// connecting
|
|
||||||
if (deviceConnected && !oldDeviceConnected) {
|
|
||||||
// do stuff here on connecting
|
|
||||||
oldDeviceConnected = deviceConnected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"requires": [
|
|
||||||
"CONFIG_BT_ENABLED=y",
|
|
||||||
"CONFIG_BLUEDROID_ENABLED=y"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -15,13 +15,15 @@
|
|||||||
bool debugMode = true;
|
bool debugMode = true;
|
||||||
int bleCharCount;
|
int bleCharCount;
|
||||||
const int channelPerLamp = 4;
|
const int channelPerLamp = 4;
|
||||||
|
int expectedLampCount = 25;
|
||||||
|
//DMX_PACKET_SIZE = 100;
|
||||||
|
|
||||||
struct Button {
|
struct Button {
|
||||||
const uint8_t PIN;
|
const uint8_t PIN;
|
||||||
uint32_t numberKeyPresses;
|
uint32_t numberKeyPresses;
|
||||||
bool pressed;
|
bool pressed;
|
||||||
};
|
};
|
||||||
uint8_t dmxData[DMX_PACKET_SIZE] = {0};
|
uint8_t dmxData[101] = {0};
|
||||||
BLEServer* pServer = NULL;
|
BLEServer* pServer = NULL;
|
||||||
|
|
||||||
bool deviceConnected = false;
|
bool deviceConnected = false;
|
||||||
@ -51,7 +53,7 @@ const int modeAmount = 16;
|
|||||||
uint8_t brightnessMax = 20;
|
uint8_t brightnessMax = 20;
|
||||||
uint8_t universalBrightness = 10;
|
uint8_t universalBrightness = 10;
|
||||||
|
|
||||||
uint8_t dataSeq[modeAmount][DMX_PACKET_SIZE] =
|
uint8_t dataSeq[modeAmount][101] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
0,
|
0,
|
||||||
@ -286,22 +288,22 @@ void setup() {
|
|||||||
|
|
||||||
// Create the BLE Service
|
// Create the BLE Service
|
||||||
BLEService *pService = pServer->createService(SERVICE_UUID,52);
|
BLEService *pService = pServer->createService(SERVICE_UUID,52);
|
||||||
const bool debugMode = true;
|
const bool debugMode = false;
|
||||||
// Serial.printf(debugMode);
|
// Serial.printf(debugMode);
|
||||||
// Create a BLE Characteristic
|
// Create a BLE Characteristic
|
||||||
Serial.printf("\nCalculating BLE Charateristic Count");
|
Serial.printf("\nCalculating BLE Charateristic Count");
|
||||||
bleCharCount = (panelAmount * debugMode) + !debugMode;
|
bleCharCount = (panelAmount * debugMode) + !debugMode;
|
||||||
Serial.printf("\nCalculating BLE MTU");
|
Serial.printf("\nCalculating BLE MTU ...");
|
||||||
uint16_t bleMTU = ((panelAmount * 3) / bleCharCount) + 3;
|
uint16_t bleMTU = ((panelAmount * 3) / bleCharCount) + 3;
|
||||||
// Serial.printf("\nSetting BLE MTU to %i bytes... ", bleMTU);
|
// Serial.printf("\nSetting BLE MTU to %i bytes... ", bleMTU);
|
||||||
// BLEDevice::setMTU(bleMTU + 3);
|
// BLEDevice::setMTU(bleMTU + 3);
|
||||||
Serial.printf("Done!\n");
|
Serial.printf("Done!\n");
|
||||||
|
|
||||||
for (uint32_t i = 0; i < bleCharCount; i++){
|
for (uint32_t i = 0; i < bleCharCount; i++){
|
||||||
UUID uuid;
|
//UUID uuid;
|
||||||
uuid.seed(i+1);
|
//uuid.seed(i+1);
|
||||||
uuid.generate();
|
//uuid.generate();
|
||||||
Serial.printf("Creating BLE Characteristic with UUID %s ...", uuid.toCharArray());
|
//Serial.printf("Creating BLE Characteristic with UUID %s ...", BLEUUID(i+1));
|
||||||
|
|
||||||
pCharacteristics[i] = pService->createCharacteristic(
|
pCharacteristics[i] = pService->createCharacteristic(
|
||||||
i+1,
|
i+1,
|
||||||
@ -311,8 +313,10 @@ void setup() {
|
|||||||
BLECharacteristic::PROPERTY_NOTIFY |
|
BLECharacteristic::PROPERTY_NOTIFY |
|
||||||
BLECharacteristic::PROPERTY_INDICATE
|
BLECharacteristic::PROPERTY_INDICATE
|
||||||
);
|
);
|
||||||
|
Serial.printf("Created BLE Characteristic with UUID %s ...", pCharacteristics[i]->getUUID().toString().c_str());
|
||||||
|
|
||||||
// pCharacteristics[i]->addDescriptor(new BLE2902());
|
// pCharacteristics[i]->addDescriptor(new BLE2902());
|
||||||
Serial.printf("Done\n");
|
// Serial.printf("Done\n");
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start the service
|
// Start the service
|
||||||
@ -332,17 +336,10 @@ void loop() {
|
|||||||
int modeOld = mode;
|
int modeOld = mode;
|
||||||
int msgSize;
|
int msgSize;
|
||||||
uint8_t* btMessage[bleCharCount];
|
uint8_t* btMessage[bleCharCount];
|
||||||
|
// uint8_t dmxData[DMX_PACKET_SIZE] = {0};
|
||||||
// notify changed value
|
// notify changed value
|
||||||
if (deviceConnected) {
|
if (deviceConnected) {
|
||||||
for (int i = 0; i < bleCharCount;i++){
|
|
||||||
btMessage[i] = pCharacteristics[i]->getData();
|
|
||||||
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
|
// disconnecting
|
||||||
if (!deviceConnected && oldDeviceConnected) {
|
if (!deviceConnected && oldDeviceConnected) {
|
||||||
@ -357,36 +354,45 @@ void loop() {
|
|||||||
oldDeviceConnected = deviceConnected;
|
oldDeviceConnected = deviceConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
serialRead();
|
// Serial.printf("\nConstructing Payload using ");
|
||||||
|
// Serial.printf("Bluetooth Data ...");
|
||||||
if (button1.pressed){
|
if (button1.pressed){
|
||||||
if (mode < modeAmount - 1){mode++;} else {mode = 0;};
|
if (mode < modeAmount - 1){mode++;} else {mode = 0;};
|
||||||
// Increment the value of each slot, excluding the start code.
|
// Increment the value of each slot, excluding the start code.
|
||||||
button1.pressed = false; // Reset button status to FALSE
|
button1.pressed = false; // Reset button status to FALSE
|
||||||
};
|
};
|
||||||
// Serial.printf("\nConstructing Payload using ");
|
serialRead();
|
||||||
if (deviceConnected){
|
if (modeOld != mode){
|
||||||
// Serial.printf("Bluetooth Data ...");
|
Serial.printf("\nChanging Lighting Preset to Preset %d", mode);
|
||||||
Serial.printf("\nConstructing DMX Payload: ");
|
uint8_t lampData[75];
|
||||||
for (int i = 0; i < bleCharCount; i++){
|
Serial.printf("\nDetected preset %i size: %i", mode, sizeof(dataSeq[mode]));
|
||||||
for (int j = 0; j < msgSize; j++){
|
for (int i = 0; i < sizeof(dataSeq[mode]); i++){
|
||||||
int packet = btMessage[i][j];
|
dmxData[i] = dataSeq[mode][i];
|
||||||
int k = i*3 + j;
|
int sublampIndex = i % 4;
|
||||||
int dmxAddress = (k / 3) * 4 + k % 3 + 1;
|
//Serial.printf("[%i]", sublampIndex, j);
|
||||||
dmxData[dmxAddress] = packet;
|
if (sublampIndex > 0) {
|
||||||
Serial.printf("[[%i,%i] %i - %i] ",i , j, dmxAddress, packet);
|
int j = (i / 4) * 3 + sublampIndex - 1;
|
||||||
};
|
Serial.printf("[%i](%i)", j, sublampIndex);
|
||||||
|
lampData[j] = dataSeq[mode][i];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Serial.printf("\n");
|
pCharacteristics[0]->setValue(lampData, 75);
|
||||||
}
|
}
|
||||||
else{
|
Serial.printf("\nConstructing DMX Payload with size ");
|
||||||
// Serial.printf("Preset Data ...");
|
for (int i = 0; i < bleCharCount; i++){
|
||||||
if (modeOld != mode){
|
btMessage[i] = pCharacteristics[i]->getData();
|
||||||
Serial.printf("\nChanging Lighting Preset to Preset %d", mode);
|
msgSize = pCharacteristics[i]->getLength();
|
||||||
for (int i = 0; i < sizeof(dataSeq[mode]); i++){
|
Serial.printf("%i bytes ", msgSize);
|
||||||
dmxData[i] = dataSeq[mode][i];
|
for (int j = 0; j < msgSize; j++){
|
||||||
};
|
int packet = btMessage[i][j];
|
||||||
}
|
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("\n");
|
||||||
|
|
||||||
// Serial.printf(" Done");
|
// Serial.printf(" Done");
|
||||||
// Wait until the packet is finished being sent before proceeding.
|
// Wait until the packet is finished being sent before proceeding.
|
||||||
dmx_wait_sent(DMX_NUM_1, DMX_TIMEOUT_TICK);
|
dmx_wait_sent(DMX_NUM_1, DMX_TIMEOUT_TICK);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user