Skip to content

Commit

Permalink
pixelcade: add support for detecting color swap from firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
jsm174 committed May 9, 2024
1 parent 0b58af9 commit 1e39fe3
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 22 deletions.
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
2 changes: 1 addition & 1 deletion 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
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 1e39fe3

Please sign in to comment.