Move globals to top of file and change scope to compile unit only.

Some minor cleanup changes
This commit is contained in:
Arne 2023-08-14 14:14:33 +02:00 committed by Will Tatam
parent f06a1e8b49
commit 789d68e80d

View File

@ -9,7 +9,9 @@
*/ */
static dmx_port_t dmxInputPort = 2; //TODO make this configurable static dmx_port_t dmxInputPort = 2; //TODO make this configurable
bool dmxInputInitialized = false; //true once initDmx finished successfully static bool dmxInputInitialized = false; //true once initDmx finished successfully
static bool dmxIsConnected = false;
static unsigned long dmxLastUpdate = 0;
void initDMXInput() { void initDMXInput() {
@ -21,6 +23,8 @@ void initDMXInput() {
* - attach callback for address change and store in flash * - attach callback for address change and store in flash
* - load dmx address from flash and set in config on startup * - load dmx address from flash and set in config on startup
* - attach callback to rdm identify and flash leds when on * - attach callback to rdm identify and flash leds when on
* - Turn this into a class
* - Make all important config variables available via rdm
*/ */
if(dmxInputReceivePin > 0 && dmxInputEnablePin > 0 && dmxInputTransmitPin > 0) if(dmxInputReceivePin > 0 && dmxInputEnablePin > 0 && dmxInputTransmitPin > 0)
{ {
@ -40,7 +44,6 @@ void initDMXInput() {
return; return;
} }
dmx_config_t config{ dmx_config_t config{
255, /*alloc_size*/ 255, /*alloc_size*/
0, /*model_id*/ 0, /*model_id*/
@ -54,7 +57,7 @@ void initDMXInput() {
}; };
const std::string versionString = "WLED_V" + std::to_string(VERSION); const std::string versionString = "WLED_V" + std::to_string(VERSION);
strncpy(config.software_version_label, versionString.c_str(), 32); strncpy(config.software_version_label, versionString.c_str(), 32);
config.software_version_label[32] = '\0';//zero termination in case our string was longer than 32 chars config.software_version_label[32] = '\0';//zero termination in case versionString string was longer than 32 chars
if(!dmx_driver_install(dmxInputPort, &config, DMX_INTR_FLAGS_DEFAULT)) if(!dmx_driver_install(dmxInputPort, &config, DMX_INTR_FLAGS_DEFAULT))
{ {
@ -74,12 +77,8 @@ void initDMXInput() {
USER_PRINTLN("DMX input disabled due to dmxInputReceivePin, dmxInputEnablePin or dmxInputTransmitPin not set"); USER_PRINTLN("DMX input disabled due to dmxInputReceivePin, dmxInputEnablePin or dmxInputTransmitPin not set");
return; return;
} }
} }
static bool dmxIsConnected = false;
static unsigned long dmxLastUpdate = 0;
void handleDMXInput() { void handleDMXInput() {
if(!dmxInputInitialized) { if(!dmxInputInitialized) {
return; return;
@ -88,10 +87,7 @@ void handleDMXInput() {
dmx_packet_t packet; dmx_packet_t packet;
unsigned long now = millis(); unsigned long now = millis();
if (dmx_receive(dmxInputPort, &packet, 0)) { if (dmx_receive(dmxInputPort, &packet, 0)) {
/* We should check to make sure that there weren't any DMX errors. */
if (!packet.err) { if (!packet.err) {
/* If this is the first DMX data we've received, lets log it! */
if (!dmxIsConnected) { if (!dmxIsConnected) {
USER_PRINTLN("DMX is connected!"); USER_PRINTLN("DMX is connected!");
dmxIsConnected = true; dmxIsConnected = true;
@ -102,12 +98,10 @@ void handleDMXInput() {
dmxLastUpdate = now; dmxLastUpdate = now;
} else { } else {
/* Oops! A DMX error occurred! Don't worry, this can happen when you first /*This can happen when you first connect or disconnect your DMX devices.
connect or disconnect your DMX devices. If you are consistently getting If you are consistently getting DMX errors, then something may have gone wrong. */
DMX errors, then something may have gone wrong with your code or
something is seriously wrong with your DMX transmitter. */
DEBUG_PRINT("A DMX error occurred - "); DEBUG_PRINT("A DMX error occurred - ");
DEBUG_PRINTLN(packet.err); DEBUG_PRINTLN(packet.err); //TODO translate err code to string for output
} }
} }
else if (dmxIsConnected && (now - dmxLastUpdate > 5000)) { else if (dmxIsConnected && (now - dmxLastUpdate > 5000)) {