Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pixelcade: add support for rbg matrix #20

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ SaveSettings=
Enabled=
# Disable auto-detection and provide a fixed serial port
Device=
# Set to 0 if rgb, 1 if rbg
Matrix=0
```

## Building:
Expand Down
3 changes: 3 additions & 0 deletions include/DMDUtil/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ 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 @@ -73,6 +75,7 @@ class DMDUTILAPI Config
int m_dmdServerPort;
bool m_pixelcade;
std::string m_pixelcadeDevice;
int m_pixelcadeMatrix;
DMDUtil_LogCallback m_logCallback;
};

Expand Down
1 change: 1 addition & 0 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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 @@ -461,7 +461,7 @@ void DMD::FindDisplays()

if (pConfig->IsPixelcade())
{
pPixelcadeDMD = PixelcadeDMD::Connect(pConfig->GetPixelcadeDevice(), 128, 32);
pPixelcadeDMD = PixelcadeDMD::Connect(pConfig->GetPixelcadeDevice(), pConfig->GetPixelcadeMatrix(), 128, 32);
if (pPixelcadeDMD) m_pPixelcadeDMDThread = new std::thread(&DMD::PixelcadeDMDThread, this);
}

Expand Down
18 changes: 10 additions & 8 deletions src/PixelcadeDMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
namespace DMDUtil
{

PixelcadeDMD::PixelcadeDMD(struct sp_port* pSerialPort, int width, int height)
PixelcadeDMD::PixelcadeDMD(struct sp_port* pSerialPort, int matrix, int width, int height)
{
m_pSerialPort = pSerialPort;
m_width = width;
m_height = height;
m_matrix = matrix;
m_length = width * height;
m_pThread = nullptr;
m_running = false;
Expand All @@ -46,15 +47,15 @@ PixelcadeDMD::~PixelcadeDMD()
}
}

PixelcadeDMD* PixelcadeDMD::Connect(const char* pDevice, int width, int height)
PixelcadeDMD* PixelcadeDMD::Connect(const char* pDevice, int matrix, int width, int height)
{
PixelcadeDMD* pPixelcadeDMD = nullptr;

if (pDevice && *pDevice != 0)
{
Log("Connecting to Pixelcade on %s...", pDevice);

pPixelcadeDMD = Open(pDevice, width, height);
pPixelcadeDMD = Open(pDevice, matrix, width, height);

if (!pPixelcadeDMD) Log("Unable to connect to Pixelcade on %s", pDevice);
}
Expand All @@ -68,7 +69,7 @@ PixelcadeDMD* PixelcadeDMD::Connect(const char* pDevice, int width, int height)
{
for (int i = 0; ppPorts[i]; i++)
{
pPixelcadeDMD = Open(sp_get_port_name(ppPorts[i]), width, height);
pPixelcadeDMD = Open(sp_get_port_name(ppPorts[i]), matrix, width, height);
if (pPixelcadeDMD) break;
}
sp_free_port_list(ppPorts);
Expand All @@ -80,7 +81,7 @@ PixelcadeDMD* PixelcadeDMD::Connect(const char* pDevice, int width, int height)
return pPixelcadeDMD;
}

PixelcadeDMD* PixelcadeDMD::Open(const char* pDevice, int width, int height)
PixelcadeDMD* PixelcadeDMD::Open(const char* pDevice, int matrix, int width, int height)
{
struct sp_port* pSerialPort = nullptr;
enum sp_return result = sp_get_port_by_name(pDevice, &pSerialPort);
Expand Down Expand Up @@ -140,7 +141,7 @@ PixelcadeDMD* PixelcadeDMD::Open(const char* pDevice, int width, int height)
Log("Pixelcade found: device=%s, Hardware ID=%s, Bootloader ID=%s, Firmware=%s", pDevice, hardwareId, bootloaderId,
firmware);

return new PixelcadeDMD(pSerialPort, width, height);
return new PixelcadeDMD(pSerialPort, matrix, width, height);
}

void PixelcadeDMD::Update(uint16_t* pData)
Expand Down Expand Up @@ -174,6 +175,7 @@ void PixelcadeDMD::Run()
EnableRgbLedMatrix(4, 16);

int errors = 0;
ColorMatrix colorMatrix = (m_matrix == 0) ? ColorMatrix::Rgb : ColorMatrix::Rbg;

while (m_running)
{
Expand All @@ -198,12 +200,12 @@ void PixelcadeDMD::Run()
{
uint8_t planes[128 * 32 * 3 / 2];
if (m_width == 128 && m_height == 32)
FrameUtil::SplitIntoRgbPlanes(pFrame, 128 * 32, 128, 16, (uint8_t*)planes);
FrameUtil::SplitIntoRgbPlanes(pFrame, 128 * 32, 128, 16, (uint8_t*)planes, colorMatrix);
else
{
uint16_t scaledFrame[128 * 32];
FrameUtil::ResizeRgb565Bilinear(pFrame, m_width, m_height, scaledFrame, 128, 32);
FrameUtil::SplitIntoRgbPlanes(scaledFrame, 128 * 32, 128, 16, (uint8_t*)planes);
FrameUtil::SplitIntoRgbPlanes(scaledFrame, 128 * 32, 128, 16, (uint8_t*)planes, colorMatrix);
}

static uint8_t command = PIXELCADE_COMMAND_RGB_LED_MATRIX_FRAME;
Expand Down
7 changes: 4 additions & 3 deletions src/PixelcadeDMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ namespace DMDUtil
class PixelcadeDMD
{
public:
PixelcadeDMD(struct sp_port* pSerialPort, int width, int height);
PixelcadeDMD(struct sp_port* pSerialPort, int matrix, int width, int height);
~PixelcadeDMD();

static PixelcadeDMD* Connect(const char* pDevice, int width, int height);
static PixelcadeDMD* Connect(const char* pDevice, int matrix, int width, int height);
void Update(uint16_t* pData);

private:
static PixelcadeDMD* Open(const char* pDevice, int width, int height);
static PixelcadeDMD* Open(const char* pDevice, int matrix, 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;
int m_length;
Expand Down
1 change: 1 addition & 0 deletions src/dmdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ int main(int argc, char* argv[])
// Pixelcade
pConfig->SetPixelcade(r.Get<bool>("Pixelcade", "Enabled"));
pConfig->SetPixelcadeDevice(r.Get<string>("Pixelcade", "Device").c_str());
pConfig->SetPixelcadeMatrix(r.Get<int>("Pixelcade", "Matrix"));
}
else if (identifier == 'o')
{
Expand Down