Skip to content

Commit

Permalink
handle dmx rdm identify
Browse files Browse the repository at this point in the history
  • Loading branch information
arneboe committed Aug 14, 2023
1 parent e28efbf commit ba6f8f8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
36 changes: 29 additions & 7 deletions wled00/dmx_input.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "wled.h"

#ifdef WLED_ENABLE_DMX_INPUT
#include "dmx_input.h"
#include <esp_dmx.h>

#ifdef ESP8266
#error DMX input is only supported on ESP32
#endif

#include "dmx_input.h"
#include <rdm/responder.h>

void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPortNum)
{

Expand Down Expand Up @@ -102,8 +103,20 @@ void DMXInput::update()
connected = true;
}

dmx_read(inputPortNum, dmxdata, packet.size);
handleDMXData(1, 512, dmxdata, REALTIME_MODE_DMX, 0);
uint8_t identify = 0;
rdm_get_identify_device(inputPortNum, &identify); // TODO error handling
if (identify)
{
turnOnAllLeds();
}
else
{
if (!packet.is_rdm)
{
dmx_read(inputPortNum, dmxdata, packet.size);
handleDMXData(1, 512, dmxdata, REALTIME_MODE_DMX, 0);
}
}
lastUpdate = now;
}
else
Expand All @@ -121,7 +134,16 @@ void DMXInput::update()
}
}

#else
void DMXInput::init(uint8_t, uint8_t, uint8_t, uint8_t) {}
void DMXInput::update() {}
void DMXInput::turnOnAllLeds()
{
// TODO not sure if this is the correct way?
const uint16_t numPixels = strip.getLengthTotal();
for (uint16_t i = 0; i < numPixels; ++i)
{
strip.setPixelColor(i, 255, 255, 255, 255);
}
strip.setBrightness(255, true);
strip.show();
}

#endif
8 changes: 6 additions & 2 deletions wled00/dmx_input.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <cstdint>

#include <esp_dmx.h>
/*
* Support for DMX/RDM input via serial (e.g. max485) on ESP32
* ESP32 Library from:
Expand All @@ -10,9 +10,13 @@ class DMXInput
{
public:
void init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPortNum);
void update();
void update();

private:

/// overrides everything and turns on all leds
void turnOnAllLeds();

uint8_t inputPortNum = 255; // TODO make this configurable
/// True once the dmx input has been initialized successfully
bool initialized = false; // true once init finished successfully
Expand Down

0 comments on commit ba6f8f8

Please sign in to comment.