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);
if (!dmx)
{
if (!dmx) {
USER_PRINTLN("DMX: Error: no context in rdmPersonalityChangedCb");
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);
DMXMode = std::min(DMX_MODE_PRESET, std::max(DMX_MODE_SINGLE_RGB, int(personality)));
doSerializeConfig = true;
@ -34,14 +32,12 @@ void rdmAddressChangedCb(dmx_port_t dmxPort, const rdm_header_t *header,
{
DMXInput *dmx = static_cast<DMXInput *>(context);
if (!dmx)
{
if (!dmx) {
USER_PRINTLN("DMX: Error: no context in rdmAddressChangedCb");
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);
DMXAddress = std::min(512, int(addr));
doSerializeConfig = true;
@ -53,7 +49,7 @@ static dmx_config_t createConfig()
{
dmx_config_t config;
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.product_category = RDM_PRODUCT_CATEGORY_FIXTURE;
config.software_version_id = VERSION;
@ -94,15 +90,12 @@ static dmx_config_t createConfig()
void dmxReceiverTask(void *context)
{
DMXInput *instance = static_cast<DMXInput *>(context);
if (instance == nullptr)
{
if (instance == nullptr) {
return;
}
if (instance->installDriver())
{
while (true)
{
if (instance->installDriver()) {
while (true) {
instance->updateInternal();
}
}
@ -112,8 +105,7 @@ bool DMXInput::installDriver()
{
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");
return false;
}
@ -141,26 +133,22 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo
// }
#endif
if (inputPortNum < 3 && inputPortNum > 0)
{
if (inputPortNum < 3 && inputPortNum > 0) {
this->inputPortNum = inputPortNum;
}
else
{
else {
USER_PRINTF("DMXInput: Error: invalid inputPortNum: %d\n", inputPortNum);
return;
}
if (rxPin > 0 && enPin > 0 && txPin > 0)
{
if (rxPin > 0 && enPin > 0 && txPin > 0) {
const managed_pin_type pins[] = {
{(int8_t)txPin, false}, // these are not used as gpio pins, thus isOutput is always false.
{(int8_t)rxPin, false},
{(int8_t)enPin, false}};
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("rx in use by: %s\n", pinManager.getPinOwnerText(rxPin).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
// pin to core 0 because wled is running on core 1
xTaskCreatePinnedToCore(dmxReceiverTask, "DMX_RCV_TASK", 10240, this, 2, &task, 0);
if (!task)
{
if (!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");
return;
}
@ -189,8 +175,7 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo
void DMXInput::updateInternal()
{
if (!initialized)
{
if (!initialized) {
return;
}
@ -198,25 +183,20 @@ void DMXInput::updateInternal()
dmx_packet_t packet;
unsigned long now = millis();
if (dmx_receive(inputPortNum, &packet, DMX_TIMEOUT_TICK))
{
if (!packet.err)
{
if (dmx_receive(inputPortNum, &packet, DMX_TIMEOUT_TICK)) {
if (!packet.err) {
connected = true;
identify = isIdentifyOn();
if (!packet.is_rdm)
{
if (!packet.is_rdm) {
const std::lock_guard<std::mutex> lock(dmxDataLock);
dmx_read(inputPortNum, dmxdata, packet.size);
}
}
else
{
else {
connected = false;
}
}
else
{
else {
connected = false;
}
}
@ -224,12 +204,10 @@ void DMXInput::updateInternal()
void DMXInput::update()
{
if (identify)
{
if (identify) {
turnOnAllLeds();
}
else if (connected)
{
else if (connected) {
const std::lock_guard<std::mutex> lock(dmxDataLock);
handleDMXData(1, 512, dmxdata, REALTIME_MODE_DMX, 0);
}
@ -249,15 +227,13 @@ void DMXInput::turnOnAllLeds()
void DMXInput::disable()
{
if (initialized)
{
if (initialized) {
dmx_driver_disable(inputPortNum);
}
}
void DMXInput::enable()
{
if (initialized)
{
if (initialized) {
dmx_driver_enable(inputPortNum);
}
}
@ -282,15 +258,13 @@ void DMXInput::checkAndUpdateConfig()
*/
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);
dmx_set_current_personality(inputPortNum, DMXMode);
}
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);
dmx_set_start_address(inputPortNum, DMXAddress);
}