Skip to content

Commit ede70d9

Browse files
committed
Use common::Atof in PixelDmx params parsing
Switch floating-point parsing in PixelDmxParams from `json::Atof` to `common::Atof` and include `utils_string.h` to match the new utility source. Also normalize several preprocessor guards from `#if defined(...)`/`#if !defined(...)` to `#ifdef`/`#ifndef` for consistency without changing behavior.
1 parent edc775a commit ede70d9

2 files changed

Lines changed: 32 additions & 29 deletions

File tree

lib-pixeldmx/src/json/pixeldmxparams.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "configstore.h"
3535
#include "configurationstore.h"
3636
#include "common/utils/utils_flags.h"
37+
#include "common/utils/utils_string.h"
3738
#include "pixelconfiguration.h"
3839
#include "pixeldmxconfiguration.h"
3940
#if defined(CONFIG_PIXELDMX_ENABLE_GAMMATABLE)
@@ -94,14 +95,14 @@ void PixelDmxParams::SetGroupingCount(const char* val, uint32_t len) {
9495
}
9596

9697
void PixelDmxParams::SetLowCode(const char* val, uint32_t len) {
97-
store_dmxled.low_code = pixel::ConvertTxH(json::Atof(val, len));
98+
store_dmxled.low_code = pixel::ConvertTxH(common::Atof(val, len));
9899
}
99100

100101
void PixelDmxParams::SetHighCode(const char* val, uint32_t len) {
101-
store_dmxled.high_code = pixel::ConvertTxH(json::Atof(val, len));
102+
store_dmxled.high_code = pixel::ConvertTxH(common::Atof(val, len));
102103
}
103104

104-
#if defined(OUTPUT_DMX_PIXEL_MULTI)
105+
#ifdef OUTPUT_DMX_PIXEL_MULTI
105106
void PixelDmxParams::SetActiveOutputs(const char* val, uint32_t len) {
106107
store_dmxled.active_outputs = ParseValue<uint8_t>(val, len);
107108
}
@@ -134,13 +135,13 @@ void PixelDmxParams::SetStartUniPort(const char* key, uint32_t key_len, const ch
134135
store_dmxled.start_universe[index] = ParseValue<uint16_t>(val, val_len);
135136
}
136137

137-
#if defined(RDM_RESPONDER)
138+
#ifdef RDM_RESPONDER
138139
void PixelDmxParams::SetDmxStartAddress(const char* val, uint32_t len) {
139140
store_dmxled.dmx_start_address = ParseValue<uint16_t>(val, len);
140141
}
141142
#endif
142143

143-
#if defined(CONFIG_PIXELDMX_ENABLE_GAMMATABLE)
144+
#ifdef CONFIG_PIXELDMX_ENABLE_GAMMATABLE
144145
void PixelDmxParams::SetGammaCorrection(const char* val, uint32_t len) {
145146
if (len == 1) {
146147
store_dmxled.flags = common::SetFlagValue(store_dmxled.flags, Flags::Flag::kEnableGamma, v[0] != '0');
@@ -157,7 +158,7 @@ void PixelDmxParams::SetGammaValue(const char* val, uint32_t len) {
157158
return;
158159
}
159160

160-
const auto kV = gamma::GetValidValue(static_cast<uint32_t>(json::Atof(val, 3) * 10));
161+
const auto kV = gamma::GetValidValue(static_cast<uint32_t>(common::Atof(val, 3) * 10));
161162
store_dmxled.gamma_value = static_cast<uint8_t>(kV);
162163
}
163164
#endif
@@ -181,16 +182,16 @@ void PixelDmxParams::Set() {
181182
pixel_configuration.SetLowCode(store_dmxled.low_code);
182183
pixel_configuration.SetHighCode(store_dmxled.high_code);
183184
pixel_configuration.SetClockSpeedHz(store_dmxled.spi_speed_hz);
184-
#if defined(CONFIG_PIXELDMX_ENABLE_GAMMATABLE)
185+
#ifdef CONFIG_PIXELDMX_ENABLE_GAMMATABLE
185186
pixel_configuration.SetEnableGammaCorrection(common::IsFlagSet(store_dmxled.flags, Flags::Flag::kEnableGamma));
186187
pixel_configuration.SetGammaTable(store_dmxled.gamma_value);
187188
#endif
188189
auto& pixel_dmx_configuration = PixelDmxConfiguration::Get();
189190
pixel_dmx_configuration.SetGroupingCount(store_dmxled.grouping_count);
190-
#if defined(OUTPUT_DMX_PIXEL_MULTI)
191+
#ifdef OUTPUT_DMX_PIXEL_MULTI
191192
pixel_dmx_configuration.SetOutputPorts(store_dmxled.active_outputs);
192193
#endif
193-
#if !defined(OUTPUT_DMX_PIXEL_MULTI)
194+
#ifndef OUTPUT_DMX_PIXEL_MULTI
194195
pixel_dmx_configuration.SetDmxStartAddress(store_dmxled.dmx_start_address);
195196
#endif
196197

@@ -270,16 +271,16 @@ void PixelDmxParams::Dump() {
270271
for (uint32_t i = 0; i < kMaxStartUniverses; i++) {
271272
printf(" %s=%d\n", PixelDmxParamsConst::kStartUniPort[i].name, store_dmxled.start_universe[i]);
272273
}
273-
#if defined(OUTPUT_DMX_PIXEL_MULTI)
274+
#ifdef OUTPUT_DMX_PIXEL_MULTI
274275
printf(" %s=%d\n", DmxLedParamsConst::kActiveOutputPorts.name, store_dmxled.active_outputs);
275276
#endif
276277
printf(" %s=%u\n", DmxLedParamsConst::kTestPattern.name, static_cast<unsigned>(store_dmxled.test_pattern));
277278
printf(" %s=%u\n", DmxLedParamsConst::kSpiSpeedHz.name, static_cast<unsigned>(store_dmxled.spi_speed_hz));
278279
printf(" %s=%u\n", DmxLedParamsConst::kGlobalBrightness.name, static_cast<unsigned>(store_dmxled.global_brightness));
279-
#if defined(RDM_RESPONDER)
280+
#ifdef RDM_RESPONDER
280281
printf(" %s=%u\n", PixelDmxParamsConst::kDmxStartAddress.name, static_cast<unsigned>(store_dmxled.dmx_start_address));
281282
#endif
282-
#if defined(CONFIG_PIXELDMX_ENABLE_GAMMATABLE)
283+
#ifdef CONFIG_PIXELDMX_ENABLE_GAMMATABLE
283284
printf(" %s=%d\n", DmxLedParamsConst::kGammaCorrection.name, common::IsFlagSet(store_dmxled.flags, Flags::Flag::kEnableGamma));
284285
printf(" %s=%1.1f [%u]\n", DmxLedParamsConst::kGammaValue.name, static_cast<float>(store_dmxled.gamma_value) / 10.0f, store_dmxled.gamma_value);
285286
#endif

lib-showfile/src/json/json_action_showfile.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file json_action_showfile.cpp
33
*/
4-
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
4+
/* Copyright (C) 2025-2026 by Arjan van Vught mailto:info@gd32-dmx.org
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -26,10 +26,11 @@
2626

2727
#include "json/json_key.h"
2828
#include "json/json_parser.h"
29-
#include "json/json_parsehelper.h"
29+
#include "common/utils/utils_string.h"
3030
#include "showfile.h"
3131

32-
static void SetPlayer(const char* val, uint32_t len) {
32+
namespace {
33+
void SetPlayer(const char* val, uint32_t len) {
3334
if (memcmp(val, "play", len) == 0) {
3435
ShowFile::Instance().Play();
3536
return;
@@ -45,35 +46,36 @@ static void SetPlayer(const char* val, uint32_t len) {
4546
return;
4647
}
4748

48-
#if !defined(CONFIG_SHOWFILE_DISABLE_RECORD)
49+
#ifndef CONFIG_SHOWFILE_DISABLE_RECORD
4950
if (memcmp(val, "record", len) == 0) {
5051
ShowFile::Instance().Record();
5152
return;
5253
}
5354
#endif
5455
}
5556

56-
static void SetLoop(const char* val, uint32_t len) {
57-
if (len != 1) return;
57+
void SetLoop(const char* val, uint32_t len) {
58+
if (len != 1) {
59+
return;
60+
}
5861

5962
ShowFile::Instance().DoLoop(val[0] != '0');
6063
}
6164

62-
static void SetShow(const char* val, uint32_t len) {
63-
if (len > 2) return;
65+
void SetShow(const char* val, uint32_t len) {
66+
if (len > 2) {
67+
return;
68+
}
6469

65-
ShowFile::Instance().SetPlayerShowFileCurrent(json::Atoi(val, len));
70+
ShowFile::Instance().SetPlayerShowFileCurrent(common::Atoi(val, len));
6671
}
6772

68-
static constexpr auto kPlayer = json::MakeSimpleKey("player");
69-
static constexpr auto kLoop = json::MakeSimpleKey("loop");
70-
static constexpr auto kShow = json::MakeSimpleKey("show");
73+
constexpr auto kPlayer = json::MakeSimpleKey("player");
74+
constexpr auto kLoop = json::MakeSimpleKey("loop");
75+
constexpr auto kShow = json::MakeSimpleKey("show");
7176

72-
static constexpr json::Key kActionKeys[] = {
73-
json::MakeKey(SetPlayer, kPlayer),
74-
json::MakeKey(SetLoop, kLoop),
75-
json::MakeKey(SetShow, kShow)
76-
};
77+
constexpr json::Key kActionKeys[] = {json::MakeKey(SetPlayer, kPlayer), json::MakeKey(SetLoop, kLoop), json::MakeKey(SetShow, kShow)};
78+
} // namespace
7779

7880
namespace json::action {
7981
void SetShowFile(const char* buffer, uint32_t buffer_size) {

0 commit comments

Comments
 (0)