2023-08-14 13:18:54 +00:00
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
2023-08-14 13:54:19 +00:00
|
|
|
#include <esp_dmx.h>
|
2023-08-14 13:18:54 +00:00
|
|
|
/*
|
|
|
|
* Support for DMX/RDM input via serial (e.g. max485) on ESP32
|
|
|
|
* ESP32 Library from:
|
|
|
|
* https://github.com/sparkfun/SparkFunDMX
|
|
|
|
*/
|
|
|
|
class DMXInput
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPortNum);
|
2023-08-14 13:54:19 +00:00
|
|
|
void update();
|
2023-08-14 13:18:54 +00:00
|
|
|
|
2023-08-17 14:53:48 +00:00
|
|
|
/**disable dmx receiver (do this before disabling the cache)*/
|
|
|
|
void disable();
|
|
|
|
void enable();
|
|
|
|
|
2023-08-14 13:18:54 +00:00
|
|
|
private:
|
2023-08-18 13:43:14 +00:00
|
|
|
/// @return true if rdm identify is active
|
|
|
|
bool isIdentifyOn() const;
|
2023-08-14 13:54:19 +00:00
|
|
|
|
2023-08-18 13:44:27 +00:00
|
|
|
/**
|
|
|
|
* Checks if the global dmx config has changed and updates the changes in rdm
|
|
|
|
*/
|
|
|
|
void checkAndUpdateConfig();
|
|
|
|
|
2023-08-14 13:54:19 +00:00
|
|
|
/// overrides everything and turns on all leds
|
|
|
|
void turnOnAllLeds();
|
|
|
|
|
2023-08-18 13:46:18 +00:00
|
|
|
dmx_config_t createConfig() const;
|
2023-08-18 13:47:01 +00:00
|
|
|
|
|
|
|
//is invoked whenver the dmx start address is changed via rdm
|
|
|
|
friend void rdmAddressChangedCb(dmx_port_t dmxPort, const rdm_header_t *header,
|
|
|
|
void *context);
|
|
|
|
|
2023-08-14 13:18:54 +00:00
|
|
|
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
|
|
|
|
/// True if dmx is currently connected
|
|
|
|
bool connected = false;
|
|
|
|
/// Timestamp of the last time a dmx frame was received
|
|
|
|
unsigned long lastUpdate = 0;
|
|
|
|
};
|