Changing firmware for modifying the whole lamp at the same time.
This commit is contained in:
parent
f3c2529394
commit
6bf9ede793
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -12,6 +12,10 @@
|
|||||||
#include <BLEUtils.h>
|
#include <BLEUtils.h>
|
||||||
#include <BLE2902.h>
|
#include <BLE2902.h>
|
||||||
|
|
||||||
|
bool debugMode = true;
|
||||||
|
int bleCharCount;
|
||||||
|
const int channelPerLamp = 4;
|
||||||
|
|
||||||
struct Button {
|
struct Button {
|
||||||
const uint8_t PIN;
|
const uint8_t PIN;
|
||||||
uint32_t numberKeyPresses;
|
uint32_t numberKeyPresses;
|
||||||
@ -234,8 +238,7 @@ void dmxSetup() {
|
|||||||
dmx_set_pin(dmx_num, tx_pin, rx_pin, rts_pin);
|
dmx_set_pin(dmx_num, tx_pin, rx_pin, rts_pin);
|
||||||
Serial.print("Done\n");
|
Serial.print("Done\n");
|
||||||
}
|
}
|
||||||
|
void serialRead(){
|
||||||
void serialRead(){
|
|
||||||
String incomingByte;
|
String incomingByte;
|
||||||
if (Serial.available() > 0) {
|
if (Serial.available() > 0) {
|
||||||
// read the incoming byte:
|
// read the incoming byte:
|
||||||
@ -283,10 +286,18 @@ 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;
|
||||||
|
// Serial.printf(debugMode);
|
||||||
// Create a BLE Characteristic
|
// 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 uuid;
|
||||||
uuid.seed(i+1);
|
uuid.seed(i+1);
|
||||||
uuid.generate();
|
uuid.generate();
|
||||||
@ -294,6 +305,7 @@ void setup() {
|
|||||||
|
|
||||||
pCharacteristics[i] = pService->createCharacteristic(
|
pCharacteristics[i] = pService->createCharacteristic(
|
||||||
i+1,
|
i+1,
|
||||||
|
// BLEUUID(uuid.toCharArray()),
|
||||||
BLECharacteristic::PROPERTY_READ |
|
BLECharacteristic::PROPERTY_READ |
|
||||||
BLECharacteristic::PROPERTY_WRITE |
|
BLECharacteristic::PROPERTY_WRITE |
|
||||||
BLECharacteristic::PROPERTY_NOTIFY |
|
BLECharacteristic::PROPERTY_NOTIFY |
|
||||||
@ -316,19 +328,21 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
dmx_send(DMX_NUM_1);
|
|
||||||
// Save Old Mode
|
// Save Old Mode
|
||||||
int modeOld = mode;
|
int modeOld = mode;
|
||||||
uint8_t* btMessage[panelAmount];
|
int msgSize;
|
||||||
|
uint8_t* btMessage[bleCharCount];
|
||||||
// notify changed value
|
// notify changed value
|
||||||
if (deviceConnected) {
|
if (deviceConnected) {
|
||||||
Serial.printf("\nI received the following bytes: ");
|
for (int i = 0; i < bleCharCount;i++){
|
||||||
for (int i = 0; i < panelAmount;i++){
|
|
||||||
btMessage[i] = pCharacteristics[i]->getData();
|
btMessage[i] = pCharacteristics[i]->getData();
|
||||||
for (int j = 0; j < sizeof(btMessage[i]); j++){
|
msgSize = pCharacteristics[i]->getLength();
|
||||||
Serial.printf("%d ",btMessage[i][j]);
|
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) {
|
||||||
@ -352,12 +366,17 @@ void loop() {
|
|||||||
// Serial.printf("\nConstructing Payload using ");
|
// Serial.printf("\nConstructing Payload using ");
|
||||||
if (deviceConnected){
|
if (deviceConnected){
|
||||||
// Serial.printf("Bluetooth Data ...");
|
// Serial.printf("Bluetooth Data ...");
|
||||||
for (int i = 0; i < panelAmount; i++){
|
Serial.printf("\nConstructing DMX Payload: ");
|
||||||
for (int j = 0; j < sizeof(btMessage[i]); j++){
|
for (int i = 0; i < bleCharCount; i++){
|
||||||
dmxData[i*4 + j + 1] = btMessage[i][j];
|
for (int j = 0; j < msgSize; j++){
|
||||||
// Serial.printf(".");
|
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{
|
else{
|
||||||
// Serial.printf("Preset Data ...");
|
// Serial.printf("Preset Data ...");
|
||||||
@ -373,4 +392,5 @@ void loop() {
|
|||||||
dmx_wait_sent(DMX_NUM_1, DMX_TIMEOUT_TICK);
|
dmx_wait_sent(DMX_NUM_1, DMX_TIMEOUT_TICK);
|
||||||
// Now write the packet synchronously!
|
// Now write the packet synchronously!
|
||||||
dmx_write(DMX_NUM_1, dmxData, 100);
|
dmx_write(DMX_NUM_1, dmxData, 100);
|
||||||
|
dmx_send(DMX_NUM_1);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user