Skip to content

Commit

Permalink
pixelcade: add support for detecting color swap from firmware (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsm174 authored May 10, 2024
1 parent 0b58af9 commit fc29cd7
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/libdmdutil.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions dmdserver.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions include/DMDUtil/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/DMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions src/PixelcadeDMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,15 +47,15 @@ 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;

if (pDevice && *pDevice != 0)
{
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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions src/PixelcadeDMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/dmdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ int main(int argc, char* argv[])
// Pixelcade
pConfig->SetPixelcade(r.Get<bool>("Pixelcade", "Enabled", true));
pConfig->SetPixelcadeDevice(r.Get<string>("Pixelcade", "Device", "").c_str());
pConfig->SetPixelcadeMatrix(r.Get<int>("Pixelcade", "Matrix", -1));

if (opt_verbose) DMDUtil::Log(DMDUtil_LogLevel_INFO, "Loaded config file");
}
Expand Down

0 comments on commit fc29cd7

Please sign in to comment.