From 9f6efa9a6afe750a2f83eae8dbd6e03e4d2c8dbd Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Thu, 9 May 2024 18:15:53 -0400 Subject: [PATCH 1/2] pixelcade: add support for detecting color swap from firmware --- .github/workflows/libdmdutil.yml | 2 +- README.md | 2 -- dmdserver.ini | 2 -- include/DMDUtil/Config.h | 3 --- src/Config.cpp | 1 - src/DMD.cpp | 2 +- src/PixelcadeDMD.cpp | 16 ++++++++-------- src/PixelcadeDMD.h | 8 ++++---- src/dmdServer.cpp | 1 - 9 files changed, 14 insertions(+), 23 deletions(-) diff --git a/.github/workflows/libdmdutil.yml b/.github/workflows/libdmdutil.yml index 4414547..0f0a25e 100644 --- a/.github/workflows/libdmdutil.yml +++ b/.github/workflows/libdmdutil.yml @@ -69,7 +69,7 @@ jobs: - if: (matrix.os == 'macos-latest') name: Add autoconf and automake (mac runner) run: | - brew install autoconf automake + brew install autoconf automake libtool - if: (!(matrix.platform == 'linux' && matrix.arch == 'aarch64')) name: Build libdmdutil-${{ matrix.platform }}-${{ matrix.arch }} run: | diff --git a/README.md b/README.md index 623b1ad..ec8d638 100644 --- a/README.md +++ b/README.md @@ -209,8 +209,6 @@ SaveSettings = 0 Enabled = 1 # Disable auto-detection and provide a fixed serial port Device = -# Set to 0 if RGB, 1 if RBG. -Matrix = 0 ``` ## Building: diff --git a/dmdserver.ini b/dmdserver.ini index 9c8aea4..ab737ed 100644 --- a/dmdserver.ini +++ b/dmdserver.ini @@ -39,5 +39,3 @@ SaveSettings = 0 Enabled = 1 # Disable auto-detection and provide a fixed serial port Device = -# Set to 0 if RGB, 1 if RBG. -Matrix = 0 diff --git a/include/DMDUtil/Config.h b/include/DMDUtil/Config.h index 9dad5e4..cc640dd 100644 --- a/include/DMDUtil/Config.h +++ b/include/DMDUtil/Config.h @@ -66,8 +66,6 @@ class DMDUTILAPI Config void SetPixelcade(bool pixelcade) { m_pixelcade = pixelcade; } void SetPixelcadeDevice(const char* port) { m_pixelcadeDevice = port; } const char* GetPixelcadeDevice() const { return m_pixelcadeDevice.c_str(); } - int GetPixelcadeMatrix() const { return m_pixelcadeMatrix; } - void SetPixelcadeMatrix(int matrix) { m_pixelcadeMatrix = matrix; } void SetDMDServer(bool dmdServer) { m_dmdServer = dmdServer; } bool IsDmdServer() { return m_dmdServer; } void SetDMDServerAddr(const char* addr) { m_dmdServerAddr = addr; } @@ -108,7 +106,6 @@ class DMDUTILAPI Config int m_dmdServerPort; bool m_pixelcade; std::string m_pixelcadeDevice; - int m_pixelcadeMatrix; DMDUtil_LogLevel m_logLevel; DMDUtil_LogCallback m_logCallback; DMDUtil_PUPTriggerCallbackContext m_pupTriggerCallbackContext; diff --git a/src/Config.cpp b/src/Config.cpp index 7b77b1f..edc5461 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -31,7 +31,6 @@ Config::Config() m_zedmdSaveSettings = false; m_pixelcade = true; m_pixelcadeDevice.clear(); - m_pixelcadeMatrix = 0; m_dmdServer = false; m_dmdServerAddr = "localhost"; m_dmdServerPort = 6789; diff --git a/src/DMD.cpp b/src/DMD.cpp index fe2fa35..f12a200 100644 --- a/src/DMD.cpp +++ b/src/DMD.cpp @@ -505,7 +505,7 @@ void DMD::FindDisplays() if (pConfig->IsPixelcade()) { pPixelcadeDMD = - PixelcadeDMD::Connect(pConfig->GetPixelcadeDevice(), pConfig->GetPixelcadeMatrix(), 128, 32); + PixelcadeDMD::Connect(pConfig->GetPixelcadeDevice(), 128, 32); if (pPixelcadeDMD) m_pPixelcadeDMDThread = new std::thread(&DMD::PixelcadeDMDThread, this); } diff --git a/src/PixelcadeDMD.cpp b/src/PixelcadeDMD.cpp index fe32a3b..60060a1 100644 --- a/src/PixelcadeDMD.cpp +++ b/src/PixelcadeDMD.cpp @@ -16,12 +16,12 @@ namespace DMDUtil { -PixelcadeDMD::PixelcadeDMD(struct sp_port* pSerialPort, int matrix, int width, int height) +PixelcadeDMD::PixelcadeDMD(struct sp_port* pSerialPort, int width, int height, bool colorSwap) { m_pSerialPort = pSerialPort; m_width = width; m_height = height; - m_matrix = matrix; + m_colorSwap = colorSwap; m_length = width * height; m_pThread = nullptr; m_running = false; @@ -47,7 +47,7 @@ PixelcadeDMD::~PixelcadeDMD() } } -PixelcadeDMD* PixelcadeDMD::Connect(const char* pDevice, int matrix, int width, int height) +PixelcadeDMD* PixelcadeDMD::Connect(const char* pDevice, int width, int height) { PixelcadeDMD* pPixelcadeDMD = nullptr; @@ -55,7 +55,7 @@ PixelcadeDMD* PixelcadeDMD::Connect(const char* pDevice, int matrix, int width, { Log(DMDUtil_LogLevel_INFO, "Connecting to Pixelcade on %s...", pDevice); - pPixelcadeDMD = Open(pDevice, matrix, width, height); + pPixelcadeDMD = Open(pDevice, width, height); if (!pPixelcadeDMD) Log(DMDUtil_LogLevel_INFO, "Unable to connect to Pixelcade on %s", pDevice); } @@ -69,7 +69,7 @@ PixelcadeDMD* PixelcadeDMD::Connect(const char* pDevice, int matrix, int width, { for (int i = 0; ppPorts[i]; i++) { - pPixelcadeDMD = Open(sp_get_port_name(ppPorts[i]), matrix, width, height); + pPixelcadeDMD = Open(sp_get_port_name(ppPorts[i]), width, height); if (pPixelcadeDMD) break; } sp_free_port_list(ppPorts); @@ -81,7 +81,7 @@ PixelcadeDMD* PixelcadeDMD::Connect(const char* pDevice, int matrix, int width, return pPixelcadeDMD; } -PixelcadeDMD* PixelcadeDMD::Open(const char* pDevice, int matrix, int width, int height) +PixelcadeDMD* PixelcadeDMD::Open(const char* pDevice, int width, int height) { struct sp_port* pSerialPort = nullptr; enum sp_return result = sp_get_port_by_name(pDevice, &pSerialPort); @@ -141,7 +141,7 @@ PixelcadeDMD* PixelcadeDMD::Open(const char* pDevice, int matrix, int width, int Log(DMDUtil_LogLevel_INFO, "Pixelcade found: device=%s, Hardware ID=%s, Bootloader ID=%s, Firmware=%s", pDevice, hardwareId, bootloaderId, firmware); - return new PixelcadeDMD(pSerialPort, matrix, width, height); + return new PixelcadeDMD(pSerialPort, width, height, (firmware[4] == 'C')); } void PixelcadeDMD::Update(uint16_t* pData) @@ -176,7 +176,7 @@ void PixelcadeDMD::Run() int errors = 0; FrameUtil::ColorMatrix colorMatrix = - (m_matrix == 0) ? FrameUtil::ColorMatrix::Rgb : FrameUtil::ColorMatrix::Rbg; + (!m_colorSwap) ? FrameUtil::ColorMatrix::Rgb : FrameUtil::ColorMatrix::Rbg; while (m_running) { diff --git a/src/PixelcadeDMD.h b/src/PixelcadeDMD.h index 3bd873e..742b3c4 100644 --- a/src/PixelcadeDMD.h +++ b/src/PixelcadeDMD.h @@ -27,21 +27,21 @@ namespace DMDUtil class PixelcadeDMD { public: - PixelcadeDMD(struct sp_port* pSerialPort, int matrix, int width, int height); + PixelcadeDMD(struct sp_port* pSerialPort, int width, int height, bool colorSwap); ~PixelcadeDMD(); - static PixelcadeDMD* Connect(const char* pDevice, int matrix, int width, int height); + static PixelcadeDMD* Connect(const char* pDevice, int width, int height); void Update(uint16_t* pData); private: - static PixelcadeDMD* Open(const char* pDevice, int matrix, int width, int height); + static PixelcadeDMD* Open(const char* pDevice, int width, int height); void Run(); void EnableRgbLedMatrix(int shifterLen32, int rows); struct sp_port* m_pSerialPort; - int m_matrix; int m_width; int m_height; + bool m_colorSwap; int m_length; std::thread* m_pThread; diff --git a/src/dmdServer.cpp b/src/dmdServer.cpp index 385c87a..daf394d 100644 --- a/src/dmdServer.cpp +++ b/src/dmdServer.cpp @@ -289,7 +289,6 @@ int main(int argc, char* argv[]) // Pixelcade pConfig->SetPixelcade(r.Get("Pixelcade", "Enabled", true)); pConfig->SetPixelcadeDevice(r.Get("Pixelcade", "Device", "").c_str()); - pConfig->SetPixelcadeMatrix(r.Get("Pixelcade", "Matrix", -1)); if (opt_verbose) DMDUtil::Log(DMDUtil_LogLevel_INFO, "Loaded config file"); } From e628ae9fe1abd2c849571bcde20c5a1831c1259b Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Fri, 10 May 2024 07:33:11 -0400 Subject: [PATCH 2/2] pixelcade: fix rendering RGB24 and partial 128x16 frames --- src/DMD.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/DMD.cpp b/src/DMD.cpp index f12a200..f638e75 100644 --- a/src/DMD.cpp +++ b/src/DMD.cpp @@ -756,7 +756,7 @@ void DMD::PixelcadeDMDThread() if (m_pUpdateBufferQueue[bufferPosition]->hasData || m_pUpdateBufferQueue[bufferPosition]->hasSegData) { uint16_t width = m_pUpdateBufferQueue[bufferPosition]->width; - uint8_t height = m_pUpdateBufferQueue[bufferPosition]->height; + uint16_t height = m_pUpdateBufferQueue[bufferPosition]->height; int length = width * height; uint8_t depth = m_pUpdateBufferQueue[bufferPosition]->depth; @@ -776,7 +776,7 @@ void DMD::PixelcadeDMDThread() uint8_t scaledBuffer[128 * 32 * 3]; if (width == 128 && height == 32) - memcpy(scaledBuffer, m_pUpdateBufferQueue[bufferPosition]->segData, 128 * 32 * 3); + memcpy(scaledBuffer, rgb24Data, 128 * 32 * 3); else if (width == 128 && height == 16) FrameUtil::Helper::Center(scaledBuffer, 128, 32, rgb24Data, 128, 16, 24); else if (width == 192 && height == 64) @@ -786,7 +786,7 @@ void DMD::PixelcadeDMDThread() else continue; - for (int i = 0; i < length; i++) + for (int i = 0; i < 128 * 32; i++) { int pos = i * 3; uint32_t r = scaledBuffer[pos]; @@ -885,7 +885,7 @@ void DMD::PixelcadeDMDThread() if (update) { - for (int i = 0; i < length; i++) + for (int i = 0; i < 128 * 32; i++) { int pos = renderBuffer[i] * 3; uint32_t r = palette[pos]; @@ -1389,7 +1389,7 @@ void DMD::PupDMDThread() m_pUpdateBufferQueue[bufferPosition]->mode == Mode::Data && m_pUpdateBufferQueue[bufferPosition]->depth != 24) { uint16_t width = m_pUpdateBufferQueue[bufferPosition]->width; - uint8_t height = m_pUpdateBufferQueue[bufferPosition]->height; + uint16_t height = m_pUpdateBufferQueue[bufferPosition]->height; int length = width * height; if (memcmp(renderBuffer, m_pUpdateBufferQueue[bufferPosition]->data, length) != 0)