Skip to content

Commit c5301f4

Browse files
committed
Refactor pixel init and add debug/logging
Propagate and expose pixel test-pattern state at startup and add debug logging across the pixel stack. Show() now accepts an explicit pattern and prints debug info; callers in multiple main.cpp files were updated to construct PixelTestPattern, read its pattern, and pass it to Show. PixelTestPattern/PixelPatterns received additional validation and DEBUG_PRINTF traces; PixelTestPattern::Get() now asserts. PixelConfiguration, PixelDmx, PixelDmxConfiguration and other headers had stylistic cleanup (brace placement, formatting) and minor logic/validation adjustments. Fixed panel LED namespace and added debug entry/exit in pixeldmx params Set(). Overall changes improve startup behavior for test patterns and increase runtime debug visibility.
1 parent 9b6705d commit c5301f4

13 files changed

Lines changed: 164 additions & 262 deletions

File tree

common/include/firmware/artnet/pixel/artnettriggerhandler.h

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@
3535
#include "pixeldmxconfiguration.h"
3636
#include "displayudf.h"
3737

38-
class ArtNetTriggerHandler : ArtNetTrigger
39-
{
38+
class ArtNetTriggerHandler : ArtNetTrigger {
4039
public:
41-
explicit ArtNetTriggerHandler(DmxNodeOutputType* output_type) : dmxnode_output_type_(output_type)
42-
{
40+
explicit ArtNetTriggerHandler(DmxNodeOutputType* output_type) : dmxnode_output_type_(output_type) {
4341
assert(s_this == nullptr);
4442
s_this = this;
4543

@@ -48,68 +46,55 @@ class ArtNetTriggerHandler : ArtNetTrigger
4846

4947
~ArtNetTriggerHandler() = default;
5048

51-
void static StaticCallbackFunction(const ArtNetTrigger* trigger)
52-
{
49+
void static StaticCallbackFunction(const ArtNetTrigger* trigger) {
5350
assert(s_this != nullptr);
5451
s_this->Handler(trigger);
5552
}
5653

5754
private:
58-
void Handler(const ArtNetTrigger* trigger)
59-
{
60-
if (trigger->key == ArtTriggerKey::kArtTriggerKeyShow)
61-
{
55+
void Handler(const ArtNetTrigger* trigger) {
56+
if (trigger->key == ArtTriggerKey::kArtTriggerKeyShow) {
6257
ArtNetNode::Get()->SetOutput(dmxnode_output_type_);
6358

6459
const auto kShow = static_cast<pixelpatterns::Pattern>(trigger->sub_key);
6560

66-
if (kShow == PixelTestPattern::Get()->GetPattern())
67-
{
61+
if (kShow == PixelTestPattern::Get()->GetPattern()) {
6862
return;
6963
}
7064

7165
const auto kIsSet = PixelTestPattern::Get()->SetPattern(kShow);
7266

73-
if (!kIsSet)
74-
{
67+
if (!kIsSet) {
7568
return;
7669
}
7770

78-
if (static_cast<pixelpatterns::Pattern>(kShow) != pixelpatterns::Pattern::kNone)
79-
{
71+
if (static_cast<pixelpatterns::Pattern>(kShow) != pixelpatterns::Pattern::kNone) {
8072
ArtNetNode::Get()->SetOutput(nullptr);
8173
Display::Get()->ClearLine(6);
8274
Display::Get()->Printf(6, "%s:%u", PixelPatterns::GetName(kShow), static_cast<uint32_t>(kShow));
83-
}
84-
else
85-
{
75+
} else {
8676
dmxnode_output_type_->Blackout(true);
8777
DisplayUdf::Get()->Show();
8878
}
8979

9080
return;
9181
}
9282

93-
if (trigger->key == ArtTriggerKey::kArtTriggerUndefined)
94-
{
95-
if (trigger->sub_key == 0)
96-
{
83+
if (trigger->key == ArtTriggerKey::kArtTriggerUndefined) {
84+
if (trigger->sub_key == 0) {
9785
const auto kIsSet = PixelTestPattern::Get()->SetPattern(pixelpatterns::Pattern::kNone);
9886

99-
if (!kIsSet)
100-
{
87+
if (!kIsSet) {
10188
return;
10289
}
10390

10491
ArtNetNode::Get()->SetOutput(nullptr);
10592

10693
auto& configuration = PixelDmxConfiguration::Get();
10794
const auto* trigger_data = &trigger->data[0];
108-
const uint32_t kColour = trigger_data[0] | (static_cast<uint32_t>(trigger_data[1]) << 8) | (static_cast<uint32_t>(trigger_data[2]) << 16) |
109-
(static_cast<uint32_t>(trigger_data[3]) << 24);
95+
const uint32_t kColour = trigger_data[0] | (static_cast<uint32_t>(trigger_data[1]) << 8) | (static_cast<uint32_t>(trigger_data[2]) << 16) | (static_cast<uint32_t>(trigger_data[3]) << 24);
11096

111-
for (uint32_t active_port = 0; active_port < configuration.GetOutputPorts(); active_port++)
112-
{
97+
for (uint32_t active_port = 0; active_port < configuration.GetOutputPorts(); active_port++) {
11398
pixel::SetPixelColour(active_port, kColour);
11499
}
115100

common/include/firmware/pixeldmx/show.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,34 @@
2929
#include <cstdint>
3030

3131
#include "pixeldmxconfiguration.h"
32-
#include "display.h"
32+
#include "display.h" // IWYU pragma: keep
3333
#include "pixelpatterns.h"
34+
#include "firmware/debug/debug_debug.h"
3435

3536
namespace common::firmware::pixeldmx {
36-
inline void Show(uint32_t line, pixelpatterns::Pattern pattern = pixelpatterns::Pattern::kNone) {
37+
inline void Show(uint32_t line, pixelpatterns::Pattern pattern) {
38+
DEBUG_PRINTF("line=%u, pattern=%u", line, static_cast<uint32_t>(pattern));
39+
3740
auto& configuration = PixelDmxConfiguration::Get();
3841
auto* display = Display::Get();
3942
assert(display != nullptr);
4043

4144
display->ClearEndOfLine();
4245
display->Printf(line, "%s:%d G%d %s",
4346
pixel::GetTypeName(configuration.GetType()),
44-
configuration.GetCount(), configuration.GetGroupingCount(),
45-
pixel::GetMapName(configuration.GetMap()));
47+
configuration.GetCount(),
48+
configuration.GetGroupingCount(),
49+
pixel::GetMapName(configuration.GetMap())
50+
);
51+
4652
display->ClearLine(8); // Status line
4753

54+
display->ClearLine(6);
4855
if (pattern != pixelpatterns::Pattern::kNone) {
49-
display->ClearLine(6);
50-
display->Printf(6, "%s:%u", PixelPatterns::GetName(pattern), static_cast<uint32_t>(pattern));
56+
display->Printf(6, "%s:%u",
57+
PixelPatterns::GetName(pattern),
58+
static_cast<uint32_t>(pattern)
59+
);
5160
}
5261
}
5362
} // namespace common::firmware::pixeldmx

gd32_emac_artnet_pixel_multi/firmware/main.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,17 @@ int main() // NOLINT
6565
fw.Print("Art-Net 4 Pixel controller {" STR(CONFIG_DMXNODE_PIXEL_MAX_PORTS) " Ports}");
6666

6767
DmxNodeNode dmxnode_node;
68-
6968
PixelDmxMulti pixeldmx_multi;
69+
PixelTestPattern pixeltest_pattern(pixelpatterns::Pattern::kNone, CONFIG_DMXNODE_PIXEL_MAX_PORTS);
7070

7171
json::PixelDmxParams pixeldmx_params;
7272
pixeldmx_params.Load();
7373
pixeldmx_params.Set();
7474

7575
const auto kPixelActivePorts = pixeldmx_multi.GetOutputPorts();
76-
const auto kTestPattern = common::FromValue<pixelpatterns::Pattern>(ConfigStore::Instance().DmxLedGet(&common::store::DmxLed::test_pattern));
77-
78-
PixelTestPattern pixeltest_pattern(kTestPattern, kPixelActivePorts);
76+
const auto kTestPattern = pixeltest_pattern.GetPattern();
7977

80-
if (PixelTestPattern::Get()->GetPattern() != pixelpatterns::Pattern::kNone) {
78+
if (kTestPattern != pixelpatterns::Pattern::kNone) {
8179
dmxnode_node.SetOutput(nullptr);
8280
} else {
8381
dmxnode_node.SetOutput(&pixeldmx_multi);
@@ -103,9 +101,9 @@ int main() // NOLINT
103101
displayudf_params.Load();
104102
displayudf_params.SetAndShow();
105103

106-
common::firmware::pixeldmx::Show(7);
104+
common::firmware::pixeldmx::Show(7, kTestPattern);
107105

108-
RemoteConfig remote_config(remoteconfig::Output::PIXEL, dmxnode_node.GetActiveOutputPorts());
106+
RemoteConfig remote_config(remoteconfig::Output::PIXEL, kPixelActivePorts);
109107

110108
display.TextStatus(DmxNodeMsgConst::START, ansi::Colours::Colour::kYellow);
111109

gd32_emac_ddp_pixel_multi/firmware/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ int main() // NOLINT
6969
network::apps::mdns::ServiceRecordAdd(nullptr, network::apps::mdns::Services::kDdp, "type=display");
7070

7171
PixelDmxMulti pixeldmx_multi;
72+
PixelTestPattern pixeltest_pattern(pixelpatterns::Pattern::kNone, 8);
7273

7374
json::PixelDmxParams pixeldmx_params;
7475
pixeldmx_params.Load();
@@ -80,8 +81,7 @@ int main() // NOLINT
8081

8182
ddpdisplay.SetCount(pixeldmx_multi.GetGroups(), pixeldmx_multi.GetLedsPerPixel(), kActivePorts);
8283

83-
const auto kTestPattern = common::FromValue<pixelpatterns::Pattern>(ConfigStore::Instance().DmxLedGet(&common::store::DmxLed::test_pattern));
84-
PixelTestPattern pixeltest_pattern(kTestPattern, kActivePorts);
84+
const auto kTestPattern = pixeltest_pattern.GetPattern();
8585

8686
ddpdisplay.SetOutput(&pixeldmx_multi);
8787
ddpdisplay.Print();
@@ -102,7 +102,7 @@ int main() // NOLINT
102102
displayudf_params.Load();
103103
displayudf_params.SetAndShow();
104104

105-
common::firmware::pixeldmx::Show(7);
105+
common::firmware::pixeldmx::Show(7, kTestPattern);
106106

107107
RemoteConfig remote_config(remoteconfig::Output::PIXEL, kActivePorts);
108108

gd32_emac_e131_pixel_multi/firmware/main.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#include "configstore.h"
4646
#include "firmwareversion.h"
4747
#include "software_version.h"
48-
#include "common/utils/utils_flags.h"
49-
#include "configurationstore.h"
5048

5149
namespace hal {
5250
void RebootHandler() {
@@ -67,17 +65,16 @@ int main() // NOLINT
6765

6866
DmxNodeNode dmxnode_node;
6967
PixelDmxMulti pixeldmx_multi;
68+
PixelTestPattern pixeltest_pattern(pixelpatterns::Pattern::kNone, CONFIG_DMXNODE_PIXEL_MAX_PORTS);
7069

7170
json::PixelDmxParams pixeldmx_params;
7271
pixeldmx_params.Load();
7372
pixeldmx_params.Set();
7473

7574
const auto kPixelActivePorts = pixeldmx_multi.GetOutputPorts();
76-
const auto kTestPattern = common::FromValue<pixelpatterns::Pattern>(ConfigStore::Instance().DmxLedGet(&common::store::DmxLed::test_pattern));
75+
const auto kTestPattern = pixeltest_pattern.GetPattern();
7776

78-
PixelTestPattern pixeltest_pattern(kTestPattern, kPixelActivePorts);
79-
80-
if (PixelTestPattern::Get()->GetPattern() != pixelpatterns::Pattern::kNone) {
77+
if (kTestPattern != pixelpatterns::Pattern::kNone) {
8178
dmxnode_node.SetOutput(nullptr);
8279
} else {
8380
dmxnode_node.SetOutput(&pixeldmx_multi);
@@ -100,7 +97,7 @@ int main() // NOLINT
10097
displayudf_params.Load();
10198
displayudf_params.SetAndShow();
10299

103-
common::firmware::pixeldmx::Show(7);
100+
common::firmware::pixeldmx::Show(7, kTestPattern);
104101

105102
RemoteConfig remote_config(remoteconfig::Output::PIXEL, dmxnode_node.GetActiveOutputPorts());
106103

gd32_emac_pp_pixel_multi/firmware/main.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ int main() // NOLINT
6868
network::apps::mdns::ServiceRecordAdd(nullptr, network::apps::mdns::Services::kPp);
6969

7070
PixelDmxMulti pixeldmx_multi;
71+
PixelTestPattern pixeltest_pattern(pixelpatterns::Pattern::kNone, 8);
7172

7273
json::PixelDmxParams pixeldmx_params;
7374
pixeldmx_params.Load();
@@ -79,9 +80,7 @@ int main() // NOLINT
7980

8081
pp.SetCount(pixeldmx_multi.GetGroups(), kActivePorts, false);
8182

82-
const auto kTestPattern = common::FromValue<pixelpatterns::Pattern>(ConfigStore::Instance().DmxLedGet(&common::store::DmxLed::test_pattern));
83-
84-
PixelTestPattern pixeltest_pattern(kTestPattern, kActivePorts);
83+
const auto kTestPattern = pixeltest_pattern.GetPattern();
8584

8685
pixeldmx_multi.Print();
8786

@@ -104,7 +103,7 @@ int main() // NOLINT
104103
displayudf_params.Load();
105104
displayudf_params.SetAndShow();
106105

107-
common::firmware::pixeldmx::Show(7);
106+
common::firmware::pixeldmx::Show(7, kTestPattern);
108107

109108
RemoteConfig remote_config(remoteconfig::Output::PIXEL, kActivePorts);
110109

lib-gd32/include/board/16x4u-pixel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
// Panel LEDs
113113
#ifdef __cplusplus
114114
#include <cstdint>
115-
namespace hal::panelled {
115+
namespace panelled {
116116
inline constexpr uint32_t kActivity = 0;
117117
inline constexpr uint32_t kArtnet = 0;
118118
inline constexpr uint32_t kDdp = 0;
@@ -127,7 +127,7 @@ inline constexpr uint32_t kTcnet = 0;
127127
// DMX
128128
static constexpr uint32_t kPortARx = 0;
129129
static constexpr uint32_t kPortATx = 0;
130-
} // namespace hal::panelled
130+
} // namespace panelled
131131
#endif
132132

133133
/**

0 commit comments

Comments
 (0)