chore: adapt code style

This commit is contained in:
Arne 2023-10-22 20:32:46 +02:00 committed by Will Tatam
parent 6598265f9b
commit 8570922dcc

View File

@ -14,14 +14,12 @@ void rdmPersonalityChangedCb(dmx_port_t dmxPort, const rdm_header_t *header,
{ {
DMXInput *dmx = static_cast<DMXInput *>(context); DMXInput *dmx = static_cast<DMXInput *>(context);
if (!dmx) if (!dmx) {
{
USER_PRINTLN("DMX: Error: no context in rdmPersonalityChangedCb"); USER_PRINTLN("DMX: Error: no context in rdmPersonalityChangedCb");
return; return;
} }
if (header->cc == RDM_CC_SET_COMMAND_RESPONSE) if (header->cc == RDM_CC_SET_COMMAND_RESPONSE) {
{
const uint8_t personality = dmx_get_current_personality(dmx->inputPortNum); const uint8_t personality = dmx_get_current_personality(dmx->inputPortNum);
DMXMode = std::min(DMX_MODE_PRESET, std::max(DMX_MODE_SINGLE_RGB, int(personality))); DMXMode = std::min(DMX_MODE_PRESET, std::max(DMX_MODE_SINGLE_RGB, int(personality)));
doSerializeConfig = true; doSerializeConfig = true;
@ -34,14 +32,12 @@ void rdmAddressChangedCb(dmx_port_t dmxPort, const rdm_header_t *header,
{ {
DMXInput *dmx = static_cast<DMXInput *>(context); DMXInput *dmx = static_cast<DMXInput *>(context);
if (!dmx) if (!dmx) {
{
USER_PRINTLN("DMX: Error: no context in rdmAddressChangedCb"); USER_PRINTLN("DMX: Error: no context in rdmAddressChangedCb");
return; return;
} }
if (header->cc == RDM_CC_SET_COMMAND_RESPONSE) if (header->cc == RDM_CC_SET_COMMAND_RESPONSE) {
{
const uint16_t addr = dmx_get_start_address(dmx->inputPortNum); const uint16_t addr = dmx_get_start_address(dmx->inputPortNum);
DMXAddress = std::min(512, int(addr)); DMXAddress = std::min(512, int(addr));
doSerializeConfig = true; doSerializeConfig = true;
@ -53,7 +49,7 @@ static dmx_config_t createConfig()
{ {
dmx_config_t config; dmx_config_t config;
config.pd_size = 255; config.pd_size = 255;
config.dmx_start_address = DMXAddress; // TODO split between input and output address config.dmx_start_address = DMXAddress;
config.model_id = 0; config.model_id = 0;
config.product_category = RDM_PRODUCT_CATEGORY_FIXTURE; config.product_category = RDM_PRODUCT_CATEGORY_FIXTURE;
config.software_version_id = VERSION; config.software_version_id = VERSION;
@ -94,15 +90,12 @@ static dmx_config_t createConfig()
void dmxReceiverTask(void *context) void dmxReceiverTask(void *context)
{ {
DMXInput *instance = static_cast<DMXInput *>(context); DMXInput *instance = static_cast<DMXInput *>(context);
if (instance == nullptr) if (instance == nullptr) {
{
return; return;
} }
if (instance->installDriver()) if (instance->installDriver()) {
{ while (true) {
while (true)
{
instance->updateInternal(); instance->updateInternal();
} }
} }
@ -112,8 +105,7 @@ bool DMXInput::installDriver()
{ {
const auto config = createConfig(); const auto config = createConfig();
if (!dmx_driver_install(inputPortNum, &config, DMX_INTR_FLAGS_DEFAULT)) if (!dmx_driver_install(inputPortNum, &config, DMX_INTR_FLAGS_DEFAULT)) {
{
USER_PRINTF("Error: Failed to install dmx driver\n"); USER_PRINTF("Error: Failed to install dmx driver\n");
return false; return false;
} }
@ -141,26 +133,22 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo
// } // }
#endif #endif
if (inputPortNum < 3 && inputPortNum > 0) if (inputPortNum < 3 && inputPortNum > 0) {
{
this->inputPortNum = inputPortNum; this->inputPortNum = inputPortNum;
} }
else else {
{
USER_PRINTF("DMXInput: Error: invalid inputPortNum: %d\n", inputPortNum); USER_PRINTF("DMXInput: Error: invalid inputPortNum: %d\n", inputPortNum);
return; return;
} }
if (rxPin > 0 && enPin > 0 && txPin > 0) if (rxPin > 0 && enPin > 0 && txPin > 0) {
{
const managed_pin_type pins[] = { const managed_pin_type pins[] = {
{(int8_t)txPin, false}, // these are not used as gpio pins, thus isOutput is always false. {(int8_t)txPin, false}, // these are not used as gpio pins, thus isOutput is always false.
{(int8_t)rxPin, false}, {(int8_t)rxPin, false},
{(int8_t)enPin, false}}; {(int8_t)enPin, false}};
const bool pinsAllocated = pinManager.allocateMultiplePins(pins, 3, PinOwner::DMX_INPUT); const bool pinsAllocated = pinManager.allocateMultiplePins(pins, 3, PinOwner::DMX_INPUT);
if (!pinsAllocated) if (!pinsAllocated) {
{
USER_PRINTF("DMXInput: Error: Failed to allocate pins for DMX_INPUT. Pins already in use:\n"); USER_PRINTF("DMXInput: Error: Failed to allocate pins for DMX_INPUT. Pins already in use:\n");
USER_PRINTF("rx in use by: %s\n", pinManager.getPinOwnerText(rxPin).c_str()); USER_PRINTF("rx in use by: %s\n", pinManager.getPinOwnerText(rxPin).c_str());
USER_PRINTF("tx in use by: %s\n", pinManager.getPinOwnerText(txPin).c_str()); USER_PRINTF("tx in use by: %s\n", pinManager.getPinOwnerText(txPin).c_str());
@ -175,13 +163,11 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo
// put dmx receiver into seperate task because it should not be blocked // put dmx receiver into seperate task because it should not be blocked
// pin to core 0 because wled is running on core 1 // pin to core 0 because wled is running on core 1
xTaskCreatePinnedToCore(dmxReceiverTask, "DMX_RCV_TASK", 10240, this, 2, &task, 0); xTaskCreatePinnedToCore(dmxReceiverTask, "DMX_RCV_TASK", 10240, this, 2, &task, 0);
if (!task) if (!task) {
{
USER_PRINTF("Error: Failed to create dmx rcv task"); USER_PRINTF("Error: Failed to create dmx rcv task");
} }
} }
else else {
{
USER_PRINTLN("DMX input disabled due to rxPin, enPin or txPin not set"); USER_PRINTLN("DMX input disabled due to rxPin, enPin or txPin not set");
return; return;
} }
@ -189,8 +175,7 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo
void DMXInput::updateInternal() void DMXInput::updateInternal()
{ {
if (!initialized) if (!initialized) {
{
return; return;
} }
@ -198,25 +183,20 @@ void DMXInput::updateInternal()
dmx_packet_t packet; dmx_packet_t packet;
unsigned long now = millis(); unsigned long now = millis();
if (dmx_receive(inputPortNum, &packet, DMX_TIMEOUT_TICK)) if (dmx_receive(inputPortNum, &packet, DMX_TIMEOUT_TICK)) {
{ if (!packet.err) {
if (!packet.err)
{
connected = true; connected = true;
identify = isIdentifyOn(); identify = isIdentifyOn();
if (!packet.is_rdm) if (!packet.is_rdm) {
{
const std::lock_guard<std::mutex> lock(dmxDataLock); const std::lock_guard<std::mutex> lock(dmxDataLock);
dmx_read(inputPortNum, dmxdata, packet.size); dmx_read(inputPortNum, dmxdata, packet.size);
} }
} }
else else {
{
connected = false; connected = false;
} }
} }
else else {
{
connected = false; connected = false;
} }
} }
@ -224,12 +204,10 @@ void DMXInput::updateInternal()
void DMXInput::update() void DMXInput::update()
{ {
if (identify) if (identify) {
{
turnOnAllLeds(); turnOnAllLeds();
} }
else if (connected) else if (connected) {
{
const std::lock_guard<std::mutex> lock(dmxDataLock); const std::lock_guard<std::mutex> lock(dmxDataLock);
handleDMXData(1, 512, dmxdata, REALTIME_MODE_DMX, 0); handleDMXData(1, 512, dmxdata, REALTIME_MODE_DMX, 0);
} }
@ -249,15 +227,13 @@ void DMXInput::turnOnAllLeds()
void DMXInput::disable() void DMXInput::disable()
{ {
if (initialized) if (initialized) {
{
dmx_driver_disable(inputPortNum); dmx_driver_disable(inputPortNum);
} }
} }
void DMXInput::enable() void DMXInput::enable()
{ {
if (initialized) if (initialized) {
{
dmx_driver_enable(inputPortNum); dmx_driver_enable(inputPortNum);
} }
} }
@ -282,15 +258,13 @@ void DMXInput::checkAndUpdateConfig()
*/ */
const uint8_t currentPersonality = dmx_get_current_personality(inputPortNum); const uint8_t currentPersonality = dmx_get_current_personality(inputPortNum);
if (currentPersonality != DMXMode) if (currentPersonality != DMXMode) {
{
DEBUG_PRINTF("DMX personality has changed from %d to %d\n", currentPersonality, DMXMode); DEBUG_PRINTF("DMX personality has changed from %d to %d\n", currentPersonality, DMXMode);
dmx_set_current_personality(inputPortNum, DMXMode); dmx_set_current_personality(inputPortNum, DMXMode);
} }
const uint16_t currentAddr = dmx_get_start_address(inputPortNum); const uint16_t currentAddr = dmx_get_start_address(inputPortNum);
if (currentAddr != DMXAddress) if (currentAddr != DMXAddress) {
{
DEBUG_PRINTF("DMX address has changed from %d to %d\n", currentAddr, DMXAddress); DEBUG_PRINTF("DMX address has changed from %d to %d\n", currentAddr, DMXAddress);
dmx_set_start_address(inputPortNum, DMXAddress); dmx_set_start_address(inputPortNum, DMXAddress);
} }