Skip to content

Commit b554117

Browse files
committed
Fix format specifiers and minor code cleanup
Replace %d with %u for unsigned types in printf/snprintf calls, adding explicit static_cast<unsigned> casts for correctness. Add missing <cstdarg> include in uart0.cpp. Remove duplicate `private:` label in dmxsend.h. Rename short variable names (v, kR/kG/kB) to more descriptive names. Reformat brace styles and if/else blocks for consistency. Add [[nodiscard]] to GetOutputStyle().
1 parent 5cc360b commit b554117

11 files changed

Lines changed: 95 additions & 98 deletions

File tree

lib-displayudf/src/json/displayudfparams.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,34 @@ DisplayUdfParams::DisplayUdfParams() {
4949
}
5050

5151
void DisplayUdfParams::SetIntensity(const char* val, uint32_t len) {
52-
if (len > 3) return;
52+
if (len > 3) {
53+
return;
54+
}
5355
store_displayudf.intensity = ParseValue<uint8_t>(val, len);
5456
}
5557

5658
void DisplayUdfParams::SetSleepTimeout(const char* val, uint32_t len) {
57-
if (len > 3) return;
59+
if (len > 3) {
60+
return;
61+
}
5862
store_displayudf.sleep_timeout = ParseValue<uint8_t>(val, len);
5963
}
6064

6165
void DisplayUdfParams::SetFlipVertically(const char* val, uint32_t len) {
62-
if (len != 1) return;
66+
if (len != 1) {
67+
return;
68+
}
6369
store_displayudf.flags = common::SetFlagValue(store_displayudf.flags, Flags::Flag::kFlipVertically, val[0] != '0');
6470
}
6571

6672
void DisplayUdfParams::SetLabel(const char* key, uint32_t key_len, const char* val, uint32_t val_len) {
67-
if (val_len > 1) return;
73+
if (val_len > 1) {
74+
return;
75+
}
6876

6977
DEBUG_PRINTF("%.*s ->%.*s", key_len, key, val_len, val);
7078

71-
const uint32_t kHash = Fnv1a32Runtime(key, static_cast<uint32_t>(key_len));
79+
const uint32_t kHash = Fnv1a32Runtime(key, key_len);
7280
bool matched = false;
7381
size_t i = 0;
7482
size_t j = 0;

lib-dmx/include/dmxsend.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class DmxSend {
4444
public:
4545
void Start(uint32_t port_index) {
4646
DEBUG_ENTRY();
47-
DEBUG_PRINTF("port_index=%d", port_index);
47+
DEBUG_PRINTF("port_index=%u", static_cast<unsigned>(port_index));
4848

4949
assert(port_index < CHAR_BIT);
5050

@@ -66,7 +66,7 @@ class DmxSend {
6666

6767
void Stop(uint32_t port_index) {
6868
DEBUG_ENTRY();
69-
DEBUG_PRINTF("port_index=%d -> %u", port_index, IsStarted(started_, static_cast<uint8_t>(port_index)));
69+
DEBUG_PRINTF("port_index=%u -> %u", static_cast<unsigned>(port_index), IsStarted(started_, static_cast<uint8_t>(port_index)));
7070

7171
assert(port_index < CHAR_BIT);
7272

@@ -121,7 +121,7 @@ class DmxSend {
121121
Dmx::Get()->SetOutputStyle(port_index, output_style == dmxnode::OutputStyle::kConstant ? dmx::OutputStyle::kConstant : dmx::OutputStyle::kDelta);
122122
}
123123

124-
dmxnode::OutputStyle GetOutputStyle(uint32_t port_index) const {
124+
[[nodiscard]] dmxnode::OutputStyle GetOutputStyle(uint32_t port_index) const {
125125
return Dmx::Get()->GetOutputStyle(port_index) == dmx::OutputStyle::kConstant ? dmxnode::OutputStyle::kConstant : dmxnode::OutputStyle::kDelta;
126126
}
127127
#endif
@@ -154,7 +154,6 @@ class DmxSend {
154154
private:
155155
static constexpr bool IsStarted(uint8_t v, uint32_t p) { return (v & (1U << p)) == (1U << p); }
156156

157-
private:
158157
#if defined(CONFIG_DMXSEND_ENABLE_CONFIGUDP)
159158
DmxConfigUdp dmx_config_udp_;
160159
#endif

lib-dmxnode/include/dmxnode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class DmxNode {
269269
assert(port_index < dmxnode::kMaxPorts);
270270
auto& port = port_[port_index];
271271

272-
snprintf(port.label, dmxnode::kPortNameLength - 1, "Port %u", (1U + port_index));
272+
snprintf(port.label, dmxnode::kPortNameLength - 1, "Port %u", static_cast<unsigned>((1U + port_index)));
273273
port.label[dmxnode::kPortNameLength - 1] = '\0';
274274
}
275275

lib-gd32/src/uart0/uart0.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <cstdint>
3030
#include <cstdio>
31+
#include <cstdarg>
3132

3233
#include "gd32_uart.h"
3334
#if defined(CONFIG_USART0_ENABLE_TX_DMA) || defined(CONFIG_USART0_ENABLE_RX_DMA)

lib-pixel/include/pixelconfiguration.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ class PixelConfiguration {
141141
high_code_ = 0;
142142
}
143143

144-
uint8_t low_code, high_code;
144+
uint8_t low_code;
145+
uint8_t high_code;
145146

146147
pixel::GetTxH(type_, low_code, high_code);
147148

@@ -208,11 +209,11 @@ class PixelConfiguration {
208209

209210
void Print() {
210211
puts("Pixel configuration");
211-
printf(" Type : %s [%d] <%d leds/pixel>\n", pixel::GetTypeName(type_), static_cast<int>(type_), static_cast<int>(leds_per_pixel_));
212-
printf(" Count : %d\n", count_);
212+
printf(" Type : %s [%u] <%u leds/pixel>\n", pixel::GetTypeName(type_), static_cast<unsigned>(type_), static_cast<unsigned>(leds_per_pixel_));
213+
printf(" Count : %u\n", static_cast<unsigned>(count_));
213214

214215
if (is_rtz_protocol_) {
215-
printf(" Mapping : %s [%d]\n", pixel::GetMapName(map_), static_cast<int>(map_));
216+
printf(" Mapping : %s [%u]\n", pixel::GetMapName(map_), static_cast<unsigned>(map_));
216217
printf(" T0H : %.2f [0x%X]\n", pixel::ConvertTxH(low_code_), low_code_);
217218
printf(" T1H : %.2f [0x%X]\n", pixel::ConvertTxH(high_code_), high_code_);
218219
} else {
@@ -227,7 +228,7 @@ class PixelConfiguration {
227228
#if defined(CONFIG_PIXELDMX_ENABLE_GAMMATABLE)
228229
printf(" Gamma correction %s\n", enable_gamma_correction_ ? "Yes" : "No");
229230
if (enable_gamma_correction_) {
230-
printf(" Value = %u\n", gamma_value_);
231+
printf(" Value = %u\n", static_cast<unsigned>(gamma_value_));
231232
}
232233
#endif
233234
}

lib-pixel/include/pixelpatterns.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ class PixelPatterns {
7070
public:
7171
explicit PixelPatterns(uint32_t active_ports) {
7272
DEBUG_ENTRY();
73-
DEBUG_PRINTF("active_ports=%u", active_ports);
73+
DEBUG_PRINTF("active_ports=%u", static_cast<unsigned>(active_ports));
7474

7575
s_active_ports = std::min(pixelpatterns::kMaxPorts, active_ports);
7676

77-
DEBUG_PRINTF("s_active_ports=%u", s_active_ports);
77+
DEBUG_PRINTF("s_active_ports=%u", static_cast<unsigned>(s_active_ports));
7878
DEBUG_EXIT();
7979
}
8080

@@ -88,7 +88,7 @@ class PixelPatterns {
8888
return "Unknown";
8989
}
9090

91-
inline uint32_t GetActivePorts() const { return s_active_ports; }
91+
uint32_t GetActivePorts() const { return s_active_ports; }
9292

9393
void RainbowCycle(uint32_t port_index, uint32_t interval, pixelpatterns::Direction direction = pixelpatterns::Direction::kForward) {
9494
Clear(port_index);
@@ -137,7 +137,7 @@ class PixelPatterns {
137137

138138
void None(uint32_t port_index) {
139139
DEBUG_ENTRY();
140-
DEBUG_PRINTF("port_index=%u", port_index);
140+
DEBUG_PRINTF("port_index=%u", static_cast<unsigned>(port_index));
141141

142142
Clear(port_index);
143143

@@ -210,11 +210,11 @@ class PixelPatterns {
210210

211211
const auto kInterp = [=](uint8_t a, uint8_t b) -> uint8_t { return static_cast<uint8_t>((a * kInvIndex + b * kIndex) / kTotalSteps); };
212212

213-
const auto kR = kInterp(kColor1.Red(), kColor2.Red());
214-
const auto kG = kInterp(kColor1.Green(), kColor2.Green());
215-
const auto kB = kInterp(kColor1.Blue(), kColor2.Blue());
213+
const auto kRed = kInterp(kColor1.Red(), kColor2.Red());
214+
const auto kGreen = kInterp(kColor1.Green(), kColor2.Green());
215+
const auto kBlue = kInterp(kColor1.Blue(), kColor2.Blue());
216216

217-
pixel::SetPixelColour(port_index, pixel::GetColour(kR, kG, kB));
217+
pixel::SetPixelColour(port_index, pixel::GetColour(kRed, kGreen, kBlue));
218218

219219
Increment(port_index);
220220
}
@@ -294,7 +294,6 @@ class PixelPatterns {
294294

295295
void Clear(uint32_t port_index) { pixel::SetPixelColour(port_index, 0); }
296296

297-
private:
298297
static inline uint32_t s_active_ports;
299298

300299
struct PortConfig {

lib-pixel/include/pixeltestpattern.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ class PixelTestPattern final : PixelPatterns {
5454

5555
pattern_ = pattern;
5656

57-
DEBUG_PRINTF("pattern_=%u", static_cast<uint32_t>(pattern_));
57+
DEBUG_PRINTF("pattern_=%u", static_cast<unsigned>(pattern_));
5858

5959
const auto kColour1 = pixel::GetColour(0, 0, 0);
6060
const auto kColour2 = pixel::GetColour(100, 100, 100);
6161
constexpr auto kInterval = 100;
6262
constexpr auto kSteps = 10;
6363

6464
for (uint32_t i = 0; i < PixelPatterns::GetActivePorts(); i++) {
65-
DEBUG_PRINTF("i=%u", i);
65+
DEBUG_PRINTF("i=%u", static_cast<unsigned>(i));
6666

6767
switch (pattern) {
6868
case pixelpatterns::Pattern::kRainbowCycle:

lib-pixel/src/json/json_status_pixel.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,16 @@
3535
#if defined(OUTPUT_DMX_PIXEL) || defined(OUTPUT_DMX_PIXEL_MULTI)
3636
#include "pixelconfiguration.h"
3737

38-
namespace json::status
39-
{
40-
uint32_t Pixel(char* out_buffer, uint32_t out_buffer_size)
41-
{
38+
namespace json::status {
39+
uint32_t Pixel(char* out_buffer, uint32_t out_buffer_size) {
4240
auto& configuration = PixelConfiguration::Get();
4341
const auto kUserData = PixelOutputType::Get()->GetUserData();
4442

45-
return static_cast<uint32_t>(
46-
snprintf(out_buffer, out_buffer_size,
47-
"{\"refresh_rate\":\"%u\",\"frame_rate\":\"%u\"}",
48-
configuration.GetRefreshRate(),
49-
kUserData));
43+
return static_cast<uint32_t>(snprintf(out_buffer, out_buffer_size,
44+
"{\"refresh_rate\":\"%u\",\"frame_rate\":\"%u\"}",
45+
static_cast<unsigned>(configuration.GetRefreshRate()),
46+
static_cast<unsigned>(kUserData))
47+
);
5048
}
5149
} // namespace json::status
5250
#endif

lib-pixeldmx/include/pixeldmxconfiguration.h

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,16 @@
4141
#include "pixelconfiguration.h"
4242
#include "pixeltype.h"
4343

44-
namespace pixeldmxconfiguration
45-
{
46-
struct PortInfo
47-
{
44+
namespace pixeldmxconfiguration {
45+
struct PortInfo {
4846
uint16_t begin_index_port[4];
4947
uint16_t protocol_port_index_last;
5048
};
5149
} // namespace pixeldmxconfiguration
5250

5351
class PixelDmxConfiguration : public PixelConfiguration {
5452
public:
55-
PixelDmxConfiguration()
56-
{
53+
PixelDmxConfiguration() {
5754
DEBUG_ENTRY();
5855

5956
assert(s_this == nullptr);
@@ -79,10 +76,8 @@ class PixelDmxConfiguration : public PixelConfiguration {
7976

8077
pixeldmxconfiguration::PortInfo& GetPortInfo() { return port_info_; }
8178

82-
void SetDmxStartAddress(uint16_t dmx_start_address)
83-
{
84-
if ((dmx_start_address > 0) && (dmx_start_address <= dmxnode::kUniverseSize))
85-
{
79+
void SetDmxStartAddress(uint16_t dmx_start_address) {
80+
if ((dmx_start_address > 0) && (dmx_start_address <= dmxnode::kUniverseSize)) {
8681
dmx_start_address_ = dmx_start_address;
8782
return;
8883
}
@@ -92,17 +87,13 @@ class PixelDmxConfiguration : public PixelConfiguration {
9287

9388
uint16_t GetDmxFootprint() const { return dmx_footprint_; }
9489

95-
void Validate(uint32_t ports_max)
96-
{
90+
void Validate(uint32_t ports_max) {
9791
DEBUG_ENTRY();
9892

9993
PixelConfiguration::Validate();
10094

101-
if (!PixelConfiguration::IsRTZProtocol())
102-
{
103-
if (!((PixelConfiguration::GetType() == pixel::LedType::kWS2801) || (PixelConfiguration::GetType() == pixel::LedType::kAPA102) ||
104-
(PixelConfiguration::GetType() == pixel::LedType::kSK9822)))
105-
{
95+
if (!PixelConfiguration::IsRTZProtocol()) {
96+
if ((PixelConfiguration::GetType() != pixel::LedType::kWS2801) && (PixelConfiguration::GetType() != pixel::LedType::kAPA102) && (PixelConfiguration::GetType() != pixel::LedType::kSK9822)) {
10697
PixelConfiguration::SetType(pixel::LedType::kWS2801);
10798
}
10899

@@ -111,36 +102,32 @@ class PixelDmxConfiguration : public PixelConfiguration {
111102

112103
port_info_.begin_index_port[0] = 0;
113104

114-
if (PixelConfiguration::GetType() == pixel::LedType::kSK6812W)
115-
{
105+
if (PixelConfiguration::GetType() == pixel::LedType::kSK6812W) {
116106
port_info_.begin_index_port[1] = 128;
117107
port_info_.begin_index_port[2] = 256;
118108
port_info_.begin_index_port[3] = 384;
119-
}
120-
else
121-
{
109+
} else {
122110
port_info_.begin_index_port[1] = 170;
123111
port_info_.begin_index_port[2] = 340;
124112
port_info_.begin_index_port[3] = 510;
125113
}
126114

127-
if ((grouping_count_ == 0) || (grouping_count_ > PixelConfiguration::GetCount()))
128-
{
115+
if ((grouping_count_ == 0) || (grouping_count_ > PixelConfiguration::GetCount())) {
129116
grouping_count_ = PixelConfiguration::GetCount();
130117
}
131118

132119
groups_ = PixelConfiguration::GetCount() / grouping_count_;
133120
output_ports_ = std::min(ports_max, output_ports_);
134121
universes_ = (1U + (groups_ / (1U + port_info_.begin_index_port[1])));
135122
dmx_footprint_ = static_cast<uint16_t>(PixelConfiguration::GetLedsPerPixel() * groups_);
136-
if (dmx_start_address_ == 0) dmx_start_address_ = dmxnode::kStartAddressDefault;
123+
124+
if (dmx_start_address_ == 0) {
125+
dmx_start_address_ = dmxnode::kStartAddressDefault;
126+
}
137127

138-
if (ports_max == 1)
139-
{
128+
if (ports_max == 1) {
140129
port_info_.protocol_port_index_last = static_cast<uint16_t>(groups_ / (1U + port_info_.begin_index_port[1]));
141-
}
142-
else
143-
{
130+
} else {
144131
#if defined(NODE_DDP_DISPLAY)
145132
port_info_.protocol_port_index_last = static_cast<uint16_t>(((output_ports_ - 1U) * 4U) + universes_ - 1U);
146133
#else
@@ -151,23 +138,26 @@ class PixelDmxConfiguration : public PixelConfiguration {
151138
DEBUG_EXIT();
152139
}
153140

154-
void Print()
155-
{
141+
void Print() {
156142
PixelConfiguration::Print();
157143
puts("Pixel DMX configuration");
158-
printf(" Outputs : %u\n", output_ports_);
159-
printf(" Grouping count : %u [Groups : %u]\n", grouping_count_, groups_);
160-
printf(" Universes : %u\n", universes_);
161-
printf(" DmxFootprint : %u\n", dmx_footprint_);
144+
printf(" Outputs : %u\n", static_cast<unsigned>(output_ports_));
145+
printf(" Grouping count : %u [Groups : %u]\n", static_cast<unsigned>(grouping_count_), static_cast<unsigned>(groups_));
146+
printf(" Universes : %u\n", static_cast<unsigned>(universes_));
147+
printf(" DmxFootprint : %u\n", static_cast<unsigned>(dmx_footprint_));
162148

163149
#ifndef NDEBUG
164150
const auto& begin_index_port = port_info_.begin_index_port;
165-
printf(" %u:%u:%u:%u -> %u\n", begin_index_port[0], begin_index_port[1], begin_index_port[2], begin_index_port[3], port_info_.protocol_port_index_last);
151+
printf(" %u:%u:%u:%u -> %u\n",
152+
static_cast<unsigned>(begin_index_port[0]),
153+
static_cast<unsigned>(begin_index_port[1]),
154+
static_cast<unsigned>(begin_index_port[2]),
155+
static_cast<unsigned>(begin_index_port[3]),
156+
static_cast<unsigned>(port_info_.protocol_port_index_last));
166157
#endif
167158
}
168159

169-
static PixelDmxConfiguration& Get()
170-
{
160+
static PixelDmxConfiguration& Get() {
171161
assert(s_this != nullptr);
172162
return *s_this;
173163
}
@@ -184,4 +174,4 @@ class PixelDmxConfiguration : public PixelConfiguration {
184174
static inline PixelDmxConfiguration* s_this;
185175
};
186176

187-
#endif // PIXELDMXCONFIGURATION_H_
177+
#endif // PIXELDMXCONFIGURATION_H_

0 commit comments

Comments
 (0)