Updated for single BLE Characteristic communication, replacing for 1 Char 1 Lamp
This commit is contained in:
parent
b4cfbbe60b
commit
91d4f59a9f
@ -97,7 +97,9 @@ async def set_full_matrix_on_ble(colorSeries):
|
||||
colorSeries[24] = temp_color_12
|
||||
# =====================================================================
|
||||
|
||||
if DEBUG_MODE:
|
||||
# Ensure all characteristics are available before writing
|
||||
print(f"Confirmed DEBUG set to true.")
|
||||
if len(ble_characteristics) != lampAmount:
|
||||
print(f"Mismatch in lamp amount. Expected {lampAmount}, got {len(ble_characteristics)}.")
|
||||
return
|
||||
@ -107,6 +109,12 @@ async def set_full_matrix_on_ble(colorSeries):
|
||||
value_to_write = colorSeries[i]
|
||||
print(f"Setting Lamp {i} ({char.uuid}) to {value_to_write.hex()}")
|
||||
await ble_client.write_gatt_char(char.uuid, value_to_write)
|
||||
else:
|
||||
print(f"Confirmed DEBUG set to false.")
|
||||
value_to_write = b"".join([color for color in colorSeries])
|
||||
print(value_to_write)
|
||||
print(f"Setting lamps to {value_to_write.hex()}")
|
||||
await ble_client.write_gatt_char(ble_characteristics[0].uuid, value_to_write)
|
||||
|
||||
|
||||
async def connect_to_ble_device():
|
||||
|
||||
@ -15,20 +15,19 @@
|
||||
bool debugMode = true;
|
||||
int bleCharCount;
|
||||
const int channelPerLamp = 4;
|
||||
int expectedLampCount = 25;
|
||||
//DMX_PACKET_SIZE = 100;
|
||||
const int expectedLampCount = 25;
|
||||
const int dmxPacketSize = channelPerLamp * expectedLampCount + 1; //
|
||||
|
||||
struct Button {
|
||||
const uint8_t PIN;
|
||||
uint32_t numberKeyPresses;
|
||||
bool pressed;
|
||||
};
|
||||
uint8_t dmxData[101] = {0};
|
||||
uint8_t dmxData[DMX_PACKET_SIZE] = {0};
|
||||
BLEServer* pServer = NULL;
|
||||
|
||||
bool deviceConnected = false;
|
||||
bool oldDeviceConnected = false;
|
||||
uint32_t value = 0;
|
||||
|
||||
uint16_t SERVICE_UUID = 20241115;
|
||||
const int panelAmount = 25;
|
||||
@ -53,7 +52,7 @@ const int modeAmount = 16;
|
||||
uint8_t brightnessMax = 20;
|
||||
uint8_t universalBrightness = 10;
|
||||
|
||||
uint8_t dataSeq[modeAmount][101] =
|
||||
uint8_t dataSeq[modeAmount][DMX_PACKET_SIZE] =
|
||||
{
|
||||
{
|
||||
0,
|
||||
@ -295,8 +294,8 @@ void setup() {
|
||||
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("\nSetting BLE MTU to %i bytes... ", bleMTU);
|
||||
BLEDevice::setMTU(bleMTU + 3);
|
||||
Serial.printf("Done!\n");
|
||||
|
||||
for (uint32_t i = 0; i < bleCharCount; i++){
|
||||
@ -364,7 +363,7 @@ void loop() {
|
||||
serialRead();
|
||||
if (modeOld != mode){
|
||||
Serial.printf("\nChanging Lighting Preset to Preset %d", mode);
|
||||
uint8_t lampData[75];
|
||||
uint8_t lampData[DMX_PACKET_SIZE / 4 * 3];
|
||||
Serial.printf("\nDetected preset %i size: %i", mode, sizeof(dataSeq[mode]));
|
||||
for (int i = 0; i < sizeof(dataSeq[mode]); i++){
|
||||
dmxData[i] = dataSeq[mode][i];
|
||||
@ -376,7 +375,7 @@ void loop() {
|
||||
lampData[j] = dataSeq[mode][i];
|
||||
}
|
||||
};
|
||||
pCharacteristics[0]->setValue(lampData, 75);
|
||||
pCharacteristics[0]->setValue(lampData, expectedLampCount * 3);
|
||||
}
|
||||
Serial.printf("\nConstructing DMX Payload with size ");
|
||||
for (int i = 0; i < bleCharCount; i++){
|
||||
@ -388,7 +387,7 @@ void loop() {
|
||||
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("[[%i,%i] %i - %i] ",i , j, dmxAddress, packet);
|
||||
};
|
||||
};
|
||||
Serial.printf("\n");
|
||||
@ -397,6 +396,6 @@ void loop() {
|
||||
// Wait until the packet is finished being sent before proceeding.
|
||||
dmx_wait_sent(DMX_NUM_1, DMX_TIMEOUT_TICK);
|
||||
// Now write the packet synchronously!
|
||||
dmx_write(DMX_NUM_1, dmxData, 100);
|
||||
dmx_write(DMX_NUM_1, dmxData, DMX_PACKET_SIZE);
|
||||
dmx_send(DMX_NUM_1);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user