Skip to content

Commit 97f4ee5

Browse files
committed
Add utils_string and rename pixel constants
Add common/utils/utils_string.h providing common::ConstStrLen and update usages to use it. Replace manual ConstStrLen and sizeof hacks with common::ConstStrLen and common::ArraySize. Rename pixel max and single LED count constants from RGB/RGBW to kRgb/kRgbw and update references in PixelConfiguration and RDM parameter definitions. Update file header/copyright in utils_port.h. Changes consolidate string/array helpers and standardize naming without changing runtime behavior.
1 parent 67b9d13 commit 97f4ee5

5 files changed

Lines changed: 59 additions & 23 deletions

File tree

common/include/common/utils/utils_port.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* @file dmxnode_utils.h
2+
* @file utils_port.h
33
*
44
*/
5-
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2025-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @file utils_string.h
3+
*
4+
*/
5+
/* Copyright (C) 2026 by Arjan van Vught mailto:info@gd32-dmx.org
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
#ifndef COMMON_UTILS_UTILS_STRING_H_
27+
#define COMMON_UTILS_UTILS_STRING_H_
28+
29+
#include <cstdint>
30+
31+
namespace common
32+
{
33+
constexpr uint32_t ConstStrLen(const char* s)
34+
{
35+
uint32_t len = 0;
36+
while (s[len] != '\0')
37+
{
38+
++len;
39+
}
40+
return len;
41+
}
42+
} // namespace common
43+
44+
#endif // COMMON_UTILS_UTILS_STRING_H_

lib-pixel/include/pixelconfiguration.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ class PixelConfiguration
141141

142142
if (leds_per_pixel_ == 4)
143143
{
144-
count_ = count_ <= pixel::max::ledcount::RGBW ? count_ : pixel::max::ledcount::RGBW;
144+
count_ = count_ <= pixel::max::ledcount::kRgbw ? count_ : pixel::max::ledcount::kRgbw;
145145
}
146146
else
147147
{
148-
count_ = count_ <= pixel::max::ledcount::RGB ? count_ : pixel::max::ledcount::RGB;
148+
count_ = count_ <= pixel::max::ledcount::kRgb ? count_ : pixel::max::ledcount::kRgb;
149149
}
150150

151151
if (is_rtz_protocol_)

lib-pixel/include/pixeltype.h

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <cassert>
3131

3232
#include "common/utils/utils_enum.h"
33+
#include "common/utils/utils_string.h"
34+
#include "common/utils/utils_array.h"
3335

3436
namespace pixel
3537
{
@@ -157,26 +159,16 @@ inline constexpr TypeInfo kTypeInfo[] = {
157159
MakeSpiTypeInfo("P9813", LedCount::k3, 4000000, 25000000),
158160
};
159161

160-
constexpr uint32_t kTypeInfoCount = static_cast<uint32_t>(sizeof(kTypeInfo) / sizeof(kTypeInfo[0]));
162+
constexpr uint32_t kTypeInfoCount = common::ArraySize(kTypeInfo);
161163
static_assert(kTypeInfoCount == static_cast<uint32_t>(LedType::kUndefined), "kTypeInfo must match LedType");
162164

163-
constexpr uint32_t ConstStrLen(const char* s)
164-
{
165-
uint32_t len = 0;
166-
while (s[len] != '\0')
167-
{
168-
++len;
169-
}
170-
return len;
171-
}
172-
173165
constexpr uint32_t GetMaxTypeNameLength()
174166
{
175167
uint32_t max_len = 0;
176168

177169
for (uint32_t i = 0; i < kTypeInfoCount; ++i)
178170
{
179-
const uint32_t kLen = ConstStrLen(kTypeInfo[i].name);
171+
const uint32_t kLen = common::ConstStrLen(kTypeInfo[i].name);
180172
if (kLen > max_len)
181173
{
182174
max_len = kLen;
@@ -194,7 +186,7 @@ constexpr uint32_t GetMaxLedMapNameLength()
194186

195187
for (uint32_t i = 0; i < kMapsCount; ++i)
196188
{
197-
const uint32_t kLen = ConstStrLen(kMaps[i]);
189+
const uint32_t kLen = common::ConstStrLen(kMaps[i]);
198190
if (kLen > max_len)
199191
{
200192
max_len = kLen;
@@ -277,14 +269,14 @@ inline LedMap GetMapByName(const char* string)
277269

278270
namespace max::ledcount
279271
{
280-
inline constexpr uint32_t RGB = (4 * 170);
281-
inline constexpr uint32_t RGBW = (4 * 128);
272+
inline constexpr uint32_t kRgb = (4 * 170);
273+
inline constexpr uint32_t kRgbw = (4 * 128);
282274
} // namespace max::ledcount
283275

284276
namespace single
285277
{
286-
inline constexpr uint32_t RGB = 24;
287-
inline constexpr uint32_t RGBW = 32;
278+
inline constexpr uint32_t kRgb = 24;
279+
inline constexpr uint32_t kRgbw = 32;
288280
} // namespace single
289281

290282
namespace defaults

lib-pixeldmx/src/pixeldmxrdm/rdm_manufacturer_pid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ const rdmhandler::ParameterDescription RDMHandler::PARAMETER_DESCRIPTIONS[] = {
8888
#else
8989
E120_CC_GET,
9090
#endif
91-
0, E120_UNITS_NONE, E120_PREFIX_NONE, 0, __builtin_bswap32(pixel::defaults::kCount), __builtin_bswap32(pixel::max::ledcount::RGB),
91+
0, E120_UNITS_NONE, E120_PREFIX_NONE, 0, __builtin_bswap32(pixel::defaults::kCount), __builtin_bswap32(pixel::max::ledcount::kRgb),
9292
rdmhandler::Description<PixelCount, sizeof(PixelCount::kDescription)>::kValue, RDMHandler::PdlParameterDescription(sizeof(PixelCount::kDescription))},
9393
{E120_MANUFACTURER_PIXEL_GROUPING_COUNT::kCode, 2, E120_DS_UNSIGNED_WORD,
9494
#if defined(CONFIG_RDM_MANUFACTURER_PIDS_SET)
9595
E120_CC_GET_SET,
9696
#else
9797
E120_CC_GET,
9898
#endif
99-
0, E120_UNITS_NONE, E120_PREFIX_NONE, 0, __builtin_bswap32(pixel::defaults::kCount), __builtin_bswap32(pixel::max::ledcount::RGB),
99+
0, E120_UNITS_NONE, E120_PREFIX_NONE, 0, __builtin_bswap32(pixel::defaults::kCount), __builtin_bswap32(pixel::max::ledcount::kRgb),
100100
rdmhandler::Description<PixelGroupingCount, sizeof(PixelGroupingCount::kDescription)>::kValue,
101101
RDMHandler::PdlParameterDescription(sizeof(PixelGroupingCount::kDescription))},
102102
{E120_MANUFACTURER_PIXEL_MAP::kCode, rdmhandler::kDeviceDescriptionMaxLength, E120_DS_ASCII,

0 commit comments

Comments
 (0)