Skip to content

Commit 8a95228

Browse files
committed
Add SetFactoryDefaults hook and ConfigStore Reset
Introduce a weak rdm::device::SetFactoryDefaults() implementation and expose its prototype in rdmdevice.h, replacing the previous configstore::SetFactoryDefaults call site in RDMDeviceResponder so callers use the RDM device namespace. Add lib-rdm/src/rdm_device.cpp with a stub that logs "Not implemented." to allow platform-specific overrides. Add ConfigStore::Reset() to clear stored config and mark status changed, and reformat kStateNames for readability. These changes provide a hook for device-specific factory-default behavior and a way to reset the config in code.
1 parent b76a1ab commit 8a95228

5 files changed

Lines changed: 70 additions & 9 deletions

File tree

lib-configstore/include/configstore.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ class ConfigStore : StoreDevice
5555
kWriting
5656
};
5757

58-
[[maybe_unused]] static constexpr char kStateNames[7][16] = {"IDLE", "CHANGED", "CHANGED_WAITING", "ERASING", "ERASED", "ERASED_WAITING", "WRITING"};
58+
[[maybe_unused]] static constexpr char kStateNames[7][16] =
59+
{
60+
"IDLE",
61+
"CHANGED",
62+
"CHANGED_WAITING",
63+
"ERASING",
64+
"ERASED",
65+
"ERASED_WAITING",
66+
"WRITING"
67+
};
5968

6069
public:
6170
ConfigStore()
@@ -118,6 +127,12 @@ class ConfigStore : StoreDevice
118127
ConfigStore& operator=(ConfigStore&&) = delete;
119128

120129
~ConfigStore() = default;
130+
131+
void Reset()
132+
{
133+
memset(s_store, 0, sizeof(s_store));
134+
SetStatusChanged();
135+
}
121136

122137
bool Commit() { return Flash(); }
123138

lib-dmxnode/include/dmxnode_outputtype.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,23 @@ enum class OutputType
4848
kUndefined
4949
};
5050

51-
inline constexpr const char* kOutputTypeNames[static_cast<uint32_t>(OutputType::kUndefined)] = {
52-
"DMX", "DMX/RDM", "Pixel", "Pixel/DMX", "PWM", "RGB Panel", "Serial", "OSC", "Monitor", "Stepper", "Player", "Art-Net", "Timecode", "None"};
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"
67+
};
5368

5469
inline const char* GetOutputType(OutputType type)
5570
{

lib-rdm/include/rdmdevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ uint32_t BootSoftwareVersionId();
4646
uint32_t SoftwareVersionId();
4747
const char* SoftwareVersionLabel(uint32_t& length);
4848
const char* RootLabel(uint8_t& length);
49+
void SetFactoryDefaults();
4950

5051
class Device
5152
{

lib-rdm/include/rdmdeviceresponder.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@
4040
#include "dmxnode.h"
4141
#include "dmxnode_outputtype.h"
4242

43-
namespace configstore
44-
{
45-
void SetFactoryDefaults();
46-
} // namespace configstore
47-
4843
class RDMDeviceResponder
4944
{
5045
static constexpr char kLanguage[2] = {'e', 'n'};
@@ -192,7 +187,7 @@ class RDMDeviceResponder
192187
checksum_ = CalculateChecksum();
193188
is_factory_defaults_ = true;
194189

195-
configstore::SetFactoryDefaults();
190+
rdm::device::SetFactoryDefaults();
196191

197192
DEBUG_EXIT();
198193
}

lib-rdm/src/rdm_device.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @file rdm_device.cpp
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+
#include "rdmdevice.h"
27+
#include "firmware/debug/debug_debug.h"
28+
29+
namespace rdm::device
30+
{
31+
__attribute__((weak)) void SetFactoryDefaults()
32+
{
33+
DEBUG_PUTS("Not implemented.");
34+
}
35+
} // namespace rdm::device

0 commit comments

Comments
 (0)