Skip to content

Commit

Permalink
W.I.P. #5
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvught committed Mar 2, 2024
1 parent 1378bb6 commit 01d3913
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 125 deletions.
20 changes: 0 additions & 20 deletions gd32_rdm_responder/firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,6 @@ void main() {
pixelDmxParams.Load();
pixelDmxParams.Set(&pixelDmxConfiguration);

/*
* DMX Footprint = (Channels per Pixel * Groups) <= 512 (1 Universe)
* Groups = Led count / Grouping count
*
* Channels per Pixel * (Led count / Grouping count) <= 512
* Channels per Pixel * Led count <= 512 * Grouping count
*
* Led count <= (512 * Grouping count) / Channels per Pixel
*/

uint32_t nLedsPerPixel;
pixeldmxconfiguration::PortInfo portInfo;

pixelDmxConfiguration.Validate(1 , nLedsPerPixel, portInfo);

if (pixelDmxConfiguration.GetUniverses() > 1) {
const auto nCount = (512U * pixelDmxConfiguration.GetGroupingCount()) / nLedsPerPixel;
pixelDmxConfiguration.SetCount(nCount);
}

WS28xxDmx pixelDmx(pixelDmxConfiguration);

const auto nTestPattern = static_cast<pixelpatterns::Pattern>(pixelDmxParams.GetTestPattern());
Expand Down
63 changes: 60 additions & 3 deletions lib-ws28xxdmx/include/pixeldmxconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file pixeldmxconfiguration.h
*
*/
/* Copyright (C) 2021-2023 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2021-2024 by Arjan van Vught mailto:[email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -27,9 +27,13 @@
#define PIXELDMXCONFIGURATION_H_

#include <cstdint>
#include <cstdio>
#include <algorithm>

#include "pixelconfiguration.h"

#include "debug.h"

namespace pixeldmxconfiguration {
struct PortInfo {
uint32_t nBeginIndexPort[4];
Expand Down Expand Up @@ -71,9 +75,62 @@ class PixelDmxConfiguration: public PixelConfiguration {
return m_nDmxStartAddress;
}

void Validate(uint32_t nPortsMax, uint32_t& nLedsPerPixel, pixeldmxconfiguration::PortInfo& portInfo);
void Validate(const uint32_t nPortsMax, uint32_t& nLedsPerPixel, pixeldmxconfiguration::PortInfo& portInfo) {
DEBUG_ENTRY

PixelConfiguration::Validate(nLedsPerPixel);

if (!IsRTZProtocol()) {
const auto type = GetType();
if (!((type == pixel::Type::WS2801) || (type == pixel::Type::APA102) || (type == pixel::Type::SK9822))) {
SetType(pixel::Type::WS2801);
}

PixelConfiguration::Validate(nLedsPerPixel);
}

portInfo.nBeginIndexPort[0] = 0;

if (GetType() == pixel::Type::SK6812W) {
portInfo.nBeginIndexPort[1] = 128;
portInfo.nBeginIndexPort[2] = 256;
portInfo.nBeginIndexPort[3] = 384;
} else {
portInfo.nBeginIndexPort[1] = 170;
portInfo.nBeginIndexPort[2] = 340;
portInfo.nBeginIndexPort[3] = 510;
}

if ((m_nGroupingCount == 0) || (m_nGroupingCount > GetCount())) {
m_nGroupingCount = GetCount();
}

m_nGroups = GetCount() / m_nGroupingCount;

m_nOutputPorts = std::min(nPortsMax, m_nOutputPorts);
m_nUniverses = (1U + (m_nGroups / (1U + portInfo.nBeginIndexPort[1])));

if (nPortsMax == 1) {
portInfo.nProtocolPortIndexLast = (m_nGroups / (1U + portInfo.nBeginIndexPort[1]));
} else {
#if defined (NODE_DDP_DISPLAY)
portInfo.nProtocolPortIndexLast = (((m_nOutputPorts - 1U) * 4U) + m_nUniverses - 1U);
#else
portInfo.nProtocolPortIndexLast = ((m_nOutputPorts * m_nUniverses) - 1U);
#endif
}

DEBUG_PRINTF("portInfo.nProtocolPortIndexLast=%u", portInfo.nProtocolPortIndexLast);
DEBUG_EXIT
}

void Print() {
PixelConfiguration::Print();

void Print();
puts("Pixel DMX configuration");
printf(" Outputs : %d\n", m_nOutputPorts);
printf(" Grouping count : %d [Groups : %d]\n", m_nGroupingCount, m_nGroups);
}

private:
uint32_t m_nOutputPorts { 1 };
Expand Down
17 changes: 17 additions & 0 deletions lib-ws28xxdmx/src/dmx/ws28xxdmx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ WS28xxDmx::WS28xxDmx(PixelDmxConfiguration& pixelDmxConfiguration): m_pixelDmxCo
assert(s_pThis == nullptr);
s_pThis = this;

/*
* DMX Footprint = (Channels per Pixel * Groups) <= 512 (1 Universe)
* Groups = Led count / Grouping count
*
* Channels per Pixel * (Led count / Grouping count) <= 512
* Channels per Pixel * Led count <= 512 * Grouping count
*
* Led count <= (512 * Grouping count) / Channels per Pixel
*/

pixelDmxConfiguration.Validate(1 , m_nChannelsPerPixel, m_PortInfo);

if (pixelDmxConfiguration.GetUniverses() > 1) {
const auto nCount = (512U * pixelDmxConfiguration.GetGroupingCount()) / m_nChannelsPerPixel;
pixelDmxConfiguration.SetCount(nCount);
}

m_pixelDmxConfiguration.Validate(1 , m_nChannelsPerPixel, m_PortInfo);

m_pWS28xx = new WS28xx(m_pixelDmxConfiguration);
Expand Down
102 changes: 0 additions & 102 deletions lib-ws28xxdmx/src/pixeldmxconfiguration.cpp

This file was deleted.

0 comments on commit 01d3913

Please sign in to comment.