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 <BLE2902.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user