Skip to content

Commit 3086f1a

Browse files
committed
Refactor dmxnode headers and fix DMX guards
Replace OUTPUT_DMX_SEND/OUTPUT_DMX_SEND_MULTI guards with DMXNODE_OUTPUT_DMX/DMX_MAX_PORTS macros for consistency. Apply code style cleanup: brace formatting, remove redundant inline on constexpr functions, add [[nodiscard]] attributes, fix indentation, and remove duplicate private: labels.
1 parent 64a68b3 commit 3086f1a

13 files changed

Lines changed: 121 additions & 175 deletions

lib-displayudf/include/displayudf.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
#if defined(RDM_RESPONDER)
5252
#include "rdmdeviceresponder.h"
5353
#endif
54-
#if defined(OUTPUT_DMX_SEND) || defined(OUTPUT_DMX_SEND_MULTI)
54+
#include "dmxnode_outputtype.h"
55+
#if defined(DMXNODE_OUTPUT_DMX)
5556
#include "dmx.h"
56-
#include "dmxconst.h"
5757
#endif
5858
#if defined(RDM_RESPONDER) || defined(OUTPUT_DMX_MONITOR) || defined(OUTPUT_DMX_PCA9685) || defined(OUTPUT_DMX_PIXEL) || defined(OUTPUT_DMX_TLC59711)
5959
#define HAVE_DMX_START_ADDRESS
@@ -117,7 +117,7 @@ class DisplayUdf final : public Display {
117117
void SetTitle(const char* format, ...);
118118
void Set(uint32_t line, displayudf::Labels label);
119119

120-
uint8_t GetLabel(uint32_t index) const {
120+
[[nodiscard]] uint8_t GetLabel(uint32_t index) const {
121121
if (index < static_cast<uint32_t>(displayudf::Labels::kUnknown)) {
122122
return labels_[index];
123123
}
@@ -195,8 +195,6 @@ class DisplayUdf final : public Display {
195195
ClearEndOfLine();
196196
Printf(labels_[static_cast<uint32_t>(displayudf::Labels::kIp)], "DHCP renewing");
197197
break;
198-
case network::dhcp::State::kBound:
199-
break;
200198
default:
201199
break;
202200
}

lib-displayudf/include/json/displayudfparams.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#include "json/json_params_base.h"
3333
#include "displayudf.h"
3434
#include "common/utils/utils_array.h"
35+
#include "dmxnode_outputtype.h"
36+
#if defined(DMXNODE_OUTPUT_DMX)
37+
#include "dmx.h"
38+
#endif
3539

3640
static_assert(common::ArraySize(json::DisplayUdfParamsConst::kLabels) == static_cast<size_t>(displayudf::Labels::kUnknown), "Mismatch between enum and kArray");
3741

lib-displayudf/include/json/displayudfparamsconst.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
#if defined(NODE_ARTNET) || defined(NODE_ARTNET_MULTI)
3535
#include "json/artnetparamsconst.h"
3636
#endif
37-
#if defined(OUTPUT_DMX_SEND) || defined(OUTPUT_DMX_SEND_MULTI)
37+
#include "dmxnode_outputtype.h"
38+
#if defined(DMXNODE_OUTPUT_DMX)
3839
#include "dmx.h"
3940
#endif
4041

lib-dmxnode/include/dmxnode.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ inline Personality GetPersonality(const char* personality) {
115115
return Personality::kArtnet;
116116
}
117117

118-
[[nodiscard]] inline constexpr const char* GetPersonality(Personality personality) {
118+
[[nodiscard]] constexpr const char* GetPersonality(Personality personality) {
119119
if (personality == Personality::kNode) {
120120
return "node";
121121
}
@@ -136,7 +136,7 @@ inline MergeMode GetMergeMode(const char* merge_mode) {
136136
return MergeMode::kHtp;
137137
}
138138

139-
[[nodiscard]] inline constexpr const char* GetMergeMode(MergeMode merge_mode, bool to_upper = false) {
139+
[[nodiscard]] constexpr const char* GetMergeMode(MergeMode merge_mode, bool to_upper = false) {
140140
if (to_upper) {
141141
return (merge_mode == MergeMode::kHtp) ? mergemode::kHtpUpper : mergemode::kLtpUpper;
142142
}
@@ -161,7 +161,7 @@ inline Direction PortDirection(const char* port_direction) {
161161
return Direction::kOutput;
162162
}
163163

164-
[[nodiscard]] inline constexpr const char* PortDirection(Direction port_direction) {
164+
[[nodiscard]] constexpr const char* PortDirection(Direction port_direction) {
165165
if (port_direction == Direction::kInput) {
166166
return "input";
167167
}
@@ -197,7 +197,7 @@ inline FailSafe GetFailsafe(const char* failsafe) {
197197
return FailSafe::kHold;
198198
}
199199

200-
[[nodiscard]] inline constexpr const char* GetFailsafe(FailSafe failsafe) {
200+
[[nodiscard]] constexpr const char* GetFailsafe(FailSafe failsafe) {
201201
switch (failsafe) {
202202
case FailSafe::kHold:
203203
return failsafe::kHold;
@@ -228,7 +228,7 @@ inline OutputStyle GetOutputStyle(const char* output_style) {
228228
return OutputStyle::kDelta;
229229
}
230230

231-
[[nodiscard]] inline constexpr const char* GetOutputStyle(OutputStyle output_style, bool to_upper = false) {
231+
[[nodiscard]] constexpr const char* GetOutputStyle(OutputStyle output_style, bool to_upper = false) {
232232
if (to_upper) {
233233
return (output_style == OutputStyle::kDelta) ? "DELTA" : "CONST";
234234
}
@@ -273,7 +273,7 @@ class DmxNode {
273273
port.label[dmxnode::kPortNameLength - 1] = '\0';
274274
}
275275

276-
const char* GetPortName(uint32_t port_index) const {
276+
[[nodiscard]] const char* GetPortName(uint32_t port_index) const {
277277
assert(port_index < dmxnode::kMaxPorts);
278278
const auto& port = port_[port_index];
279279

lib-dmxnode/include/dmxnode_data.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,16 @@
3131
#include "dmxnode_outputtype.h"
3232
#include "dmxnodedata.h"
3333

34-
namespace dmxnode
35-
{
36-
inline void DataSet(DmxNodeOutputType* const kDmxNodeOutputType, uint32_t port_index)
37-
{
34+
namespace dmxnode {
35+
inline void DataSet(DmxNodeOutputType* const kDmxNodeOutputType, uint32_t port_index) {
3836
assert(kDmxNodeOutputType != nullptr);
3937
kDmxNodeOutputType->SetData<false>(port_index, dmxnode::Data::Backup(port_index), dmxnode::Data::GetLength(port_index));
4038
}
4139

42-
inline void DataOutput(DmxNodeOutputType* const kDmxNodeOutputType, uint32_t port_index)
43-
{
40+
inline void DataOutput(DmxNodeOutputType* const kDmxNodeOutputType, uint32_t port_index) {
4441
assert(kDmxNodeOutputType != nullptr);
4542
kDmxNodeOutputType->SetData<true>(port_index, dmxnode::Data::Backup(port_index), dmxnode::Data::GetLength(port_index));
4643
}
4744
} // namespace dmxnode
4845

49-
#endif // DMXNODE_DATA_H_
46+
#endif // DMXNODE_DATA_H_

lib-dmxnode/include/dmxnode_outputtype.h

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,44 @@
2727

2828
#include <cstdint>
2929

30-
namespace dmxnode
31-
{
32-
enum class OutputType
33-
{
34-
kDmx,
35-
kDmxRdm,
36-
kPixel,
37-
kPixelDmx,
38-
kPwm,
39-
kRgbPanel,
40-
kSerial,
41-
kOsc,
42-
kMonitor,
43-
kStepper,
44-
kPlayer,
45-
kArtNet,
46-
kTimeCode,
47-
kNone,
48-
kUndefined
30+
namespace dmxnode {
31+
enum class OutputType {
32+
kDmx, //
33+
kDmxRdm, //
34+
kPixel, //
35+
kPixelDmx, //
36+
kPwm, //
37+
kRgbPanel, //
38+
kSerial, //
39+
kOsc, //
40+
kMonitor, //
41+
kStepper, //
42+
kPlayer, //
43+
kArtNet, //
44+
kTimeCode, //
45+
kNone, //
46+
kUndefined //
4947
};
5048

51-
inline constexpr const char* kOutputTypeNames[static_cast<uint32_t>(OutputType::kUndefined)] =
52-
{
53-
"DMX",
54-
"DMX/RDM",
55-
"Pixel",
56-
"Pixel/DMX",
57-
"PWM",
58-
"RGB Panel",
59-
"Serial",
60-
"OSC",
61-
"Monitor",
62-
"Stepper",
63-
"Player",
64-
"Art-Net",
65-
"Timecode",
66-
"None"
49+
inline constexpr const char* kOutputTypeNames[static_cast<uint32_t>(OutputType::kUndefined)] = {
50+
"DMX", //
51+
"DMX/RDM", //
52+
"Pixel", //
53+
"Pixel/DMX", //
54+
"PWM", //
55+
"RGB Panel", //
56+
"Serial", //
57+
"OSC", //
58+
"Monitor", //
59+
"Stepper", //
60+
"Player", //
61+
"Art-Net", //
62+
"Timecode", //
63+
"None" //
6764
};
6865

69-
inline const char* GetOutputType(OutputType type)
70-
{
71-
if (type < OutputType::kUndefined)
72-
{
66+
inline const char* GetOutputType(OutputType type) {
67+
if (type < OutputType::kUndefined) {
7368
return kOutputTypeNames[static_cast<uint32_t>(type)];
7469
}
7570

@@ -171,8 +166,7 @@ using DmxNodeOutputType = PCA9685DmxSet;
171166
using DmxNodeOutputType = TLC59711Dmx;
172167
#endif
173168

174-
namespace dmxnode
175-
{
169+
namespace dmxnode {
176170
#if defined(DMXNODE_OUTPUT_DMX) && defined(RDM_CONTROLLER)
177171
inline constexpr auto kOutputType = OutputType::kDmxRdm;
178172
#elif defined(DMXNODE_OUTPUT_DMX)

lib-dmxnode/include/dmxnodedata.h

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,10 @@
4646
#define SECTION_LIGHTSET
4747
#endif
4848

49-
namespace dmxnode
50-
{
51-
class Data
52-
{
49+
namespace dmxnode {
50+
class Data {
5351
public:
54-
static Data& Get()
55-
{
52+
static Data& Get() {
5653
static Data instance SECTION_LIGHTSET;
5754
return instance;
5855
}
@@ -76,19 +73,16 @@ class Data
7673
static void Restore(uint32_t port_index, const uint8_t* data) { Get().IRestore(port_index, data); }
7774

7875
private:
79-
void IMergeSourceA(uint32_t port_index, const uint8_t* data, uint32_t length, MergeMode merge_mode)
80-
{
76+
void IMergeSourceA(uint32_t port_index, const uint8_t* data, uint32_t length, MergeMode merge_mode) {
8177
assert(port_index < kPorts);
8278
assert(data != nullptr);
8379

8480
memcpy(output_port_[port_index].source_a.data, data, length);
8581

8682
output_port_[port_index].length = length;
8783

88-
if (merge_mode == MergeMode::kHtp)
89-
{
90-
for (uint32_t i = 0; i < length; i++)
91-
{
84+
if (merge_mode == MergeMode::kHtp) {
85+
for (uint32_t i = 0; i < length; i++) {
9286
const auto kData = std::max(output_port_[port_index].source_a.data[i], output_port_[port_index].source_b.data[i]);
9387
output_port_[port_index].data[i] = kData;
9488
}
@@ -99,19 +93,16 @@ class Data
9993
memcpy(output_port_[port_index].data, data, length);
10094
}
10195

102-
void IMergeSourceB(uint32_t port_index, const uint8_t* data, uint32_t length, MergeMode merge_mode)
103-
{
96+
void IMergeSourceB(uint32_t port_index, const uint8_t* data, uint32_t length, MergeMode merge_mode) {
10497
assert(port_index < kPorts);
10598
assert(data != nullptr);
10699

107100
memcpy(output_port_[port_index].source_b.data, data, length);
108101

109102
output_port_[port_index].length = length;
110103

111-
if (merge_mode == MergeMode::kHtp)
112-
{
113-
for (uint32_t i = 0; i < length; i++)
114-
{
104+
if (merge_mode == MergeMode::kHtp) {
105+
for (uint32_t i = 0; i < length; i++) {
115106
const auto kData = std::max(output_port_[port_index].source_a.data[i], output_port_[port_index].source_b.data[i]);
116107
output_port_[port_index].data[i] = kData;
117108
}
@@ -122,41 +113,35 @@ class Data
122113
memcpy(output_port_[port_index].data, data, length);
123114
}
124115

125-
void IClear(uint32_t port_index)
126-
{
116+
void IClear(uint32_t port_index) {
127117
assert(port_index < kPorts);
128118

129119
memset(output_port_[port_index].data, 0, dmxnode::kUniverseSize);
130120
output_port_[port_index].length = dmxnode::kUniverseSize;
131121
}
132122

133-
void IClearLength(uint32_t port_index)
134-
{
123+
void IClearLength(uint32_t port_index) {
135124
assert(port_index < kPorts);
136125
output_port_[port_index].length = 0;
137126
}
138127

139-
uint32_t IGetLength(uint32_t port_index) const
140-
{
141-
assert(port_index < kPorts);
142-
return output_port_[port_index].length;
143-
}
128+
uint32_t IGetLength(uint32_t port_index) const {
129+
assert(port_index < kPorts);
130+
return output_port_[port_index].length;
131+
}
144132

145-
const uint8_t* IBackup(uint32_t port_index)
146-
{
133+
const uint8_t* IBackup(uint32_t port_index) {
147134
assert(port_index < kPorts);
148135
return const_cast<const uint8_t*>(output_port_[port_index].data);
149136
}
150137

151-
void IRestore(uint32_t port_index, const uint8_t* data)
152-
{
138+
void IRestore(uint32_t port_index, const uint8_t* data) {
153139
assert(port_index < kPorts);
154140
assert(data != nullptr);
155141

156142
memcpy(output_port_[port_index].data, data, dmxnode::kUniverseSize);
157143
}
158144

159-
private:
160145
#if !defined(DMXNODE_PORTS)
161146
#define DMXNODE_PORTS 0
162147
#endif
@@ -167,13 +152,11 @@ class Data
167152
static constexpr auto kPorts = DMXNODE_PORTS;
168153
#endif
169154

170-
struct Source
171-
{
155+
struct Source {
172156
uint8_t data[dmxnode::kUniverseSize] __attribute__((aligned(4)));
173157
};
174158

175-
struct OutputPort
176-
{
159+
struct OutputPort {
177160
Source source_a;
178161
Source source_b;
179162
uint8_t data[dmxnode::kUniverseSize] __attribute__((aligned(4)));
@@ -184,4 +167,4 @@ class Data
184167
};
185168
} // namespace dmxnode
186169

187-
#endif // DMXNODEDATA_H_
170+
#endif // DMXNODEDATA_H_

lib-dmxnode/include/dmxnodemsgconst.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
#ifndef DMXNODEMSGCONST_H_
2626
#define DMXNODEMSGCONST_H_
2727

28-
struct DmxNodeMsgConst
29-
{
28+
struct DmxNodeMsgConst {
3029
static inline const char START[] = "Starting DMX Node";
3130
static inline const char STARTED[] = "DMX Node started";
3231
static inline const char RDM_RUN[] = "Running RDM Discovery";
3332
};
3433

35-
#endif // DMXNODEMSGCONST_H_
34+
#endif // DMXNODEMSGCONST_H_

lib-dmxnode/include/dmxnodenode.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@
3434
#include "json/e131params.h"
3535
#endif
3636

37-
class DmxNodeNode final : public DmxNodeNodeType
38-
{
37+
class DmxNodeNode final : public DmxNodeNodeType {
3938
public:
40-
DmxNodeNode()
41-
{
39+
DmxNodeNode() {
4240
{
4341
json::DmxNodeParams dmxnode_params;
4442
dmxnode_params.Load();
@@ -61,4 +59,4 @@ class DmxNodeNode final : public DmxNodeNodeType
6159
}
6260
};
6361

64-
#endif // DMXNODENODE_H_
62+
#endif // DMXNODENODE_H_

0 commit comments

Comments
 (0)