Skip to content

Commit

Permalink
chore: cleanup. rename CALLBACK to ZEDMDCALLBACK. bump to 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jsm174 committed Jan 6, 2024
1 parent d9e8475 commit efb3a33
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 52 deletions.
14 changes: 7 additions & 7 deletions src/ZeDMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ ZeDMD::ZeDMD()
memset(m_palette16, 0, sizeof(m_palette16));
memset(m_palette64, 0, sizeof(m_palette64));

m_pFrameBuffer = NULL;
m_pScaledFrameBuffer = NULL;
m_pCommandBuffer = NULL;
m_pPlanes = NULL;
m_pFrameBuffer = nullptr;
m_pScaledFrameBuffer = nullptr;
m_pCommandBuffer = nullptr;
m_pPlanes = nullptr;

m_pZeDMDComm = new ZeDMDComm();
m_pZeDMDWiFi = new ZeDMDWiFi();
Expand All @@ -40,10 +40,10 @@ ZeDMD::~ZeDMD()
delete m_pPlanes;
}

void ZeDMD::SetLogMessageCallback(ZeDMD_LogMessageCallback callback, const void *userData)
void ZeDMD::SetLogCallback(ZeDMD_LogCallback callback, const void *userData)
{
m_pZeDMDComm->SetLogMessageCallback(callback, userData);
m_pZeDMDWiFi->SetLogMessageCallback(callback, userData);
m_pZeDMDComm->SetLogCallback(callback, userData);
m_pZeDMDWiFi->SetLogCallback(callback, userData);
}

void ZeDMD::Close()
Expand Down
12 changes: 6 additions & 6 deletions src/ZeDMD.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#define ZEDMD_VERSION_MAJOR 0 // X Digits
#define ZEDMD_VERSION_MINOR 3 // Max 2 Digits
#define ZEDMD_VERSION_PATCH 2 // Max 2 Digits
#define ZEDMD_VERSION_MINOR 4 // Max 2 Digits
#define ZEDMD_VERSION_PATCH 0 // Max 2 Digits

#define _ZEDMD_STR(x) #x
#define ZEDMD_STR(x) _ZEDMD_STR(x)
Expand All @@ -16,17 +16,17 @@

#ifdef _MSC_VER
#define ZEDMDAPI __declspec(dllexport)
#define CALLBACK __stdcall
#define ZEDMDCALLBACK __stdcall
#else
#define ZEDMDAPI __attribute__((visibility("default")))
#define CALLBACK
#define ZEDMDCALLBACK
#endif

#include <inttypes.h>
#include <stdio.h>
#include <stdarg.h>

typedef void(CALLBACK *ZeDMD_LogMessageCallback)(const char *format, va_list args, const void *userData);
typedef void(ZEDMDCALLBACK *ZeDMD_LogCallback)(const char *format, va_list args, const void *userData);

class ZeDMDComm;
class ZeDMDWiFi;
Expand All @@ -37,7 +37,7 @@ class ZEDMDAPI ZeDMD
ZeDMD();
~ZeDMD();

void SetLogMessageCallback(ZeDMD_LogMessageCallback callback, const void *userData);
void SetLogCallback(ZeDMD_LogCallback callback, const void *userData);

void IgnoreDevice(const char *const ignore_device);
void SetDevice(const char *const device);
Expand Down
46 changes: 23 additions & 23 deletions src/ZeDMDComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

ZeDMDComm::ZeDMDComm()
{
m_pThread = NULL;
m_pThread = nullptr;
#if !((defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || defined(__ANDROID__))
m_pSerialPort = NULL;
m_pSerialPortConfig = NULL;
m_pSerialPort = nullptr;
m_pSerialPortConfig = nullptr;
#endif
}

Expand All @@ -23,27 +23,27 @@ ZeDMDComm::~ZeDMDComm()
}
}

void ZeDMDComm::SetLogMessageCallback(ZeDMD_LogMessageCallback callback, const void *userData)
void ZeDMDComm::SetLogCallback(ZeDMD_LogCallback callback, const void *userData)
{
m_logMessageCallback = callback;
m_LogCallback = callback;
m_logMessageUserData = userData;
}

void ZeDMDComm::LogMessage(const char *format, ...)
void ZeDMDComm::Log(const char *format, ...)
{
if (!m_logMessageCallback)
if (!m_LogCallback)
return;

va_list args;
va_start(args, format);
(*(m_logMessageCallback))(format, args, m_logMessageUserData);
(*(m_LogCallback))(format, args, m_logMessageUserData);
va_end(args);
}

void ZeDMDComm::Run()
{
m_pThread = new std::thread([this]() {
LogMessage("ZeDMDComm run thread starting");
Log("ZeDMDComm run thread starting");
int8_t lastStreamId = -1;

while (IsConnected()) {
Expand Down Expand Up @@ -118,7 +118,7 @@ void ZeDMDComm::Run()
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}

LogMessage("ZeDMDComm run thread finished");
Log("ZeDMDComm run thread finished");
});
}

Expand Down Expand Up @@ -173,7 +173,7 @@ void ZeDMDComm::QueueCommand(char command, uint8_t value)

void ZeDMDComm::QueueCommand(char command)
{
QueueCommand(command, NULL, 0);
QueueCommand(command, nullptr, 0);
}

void ZeDMDComm::QueueCommand(char command, uint8_t *data, int size, uint16_t width, uint16_t height)
Expand Down Expand Up @@ -272,15 +272,15 @@ bool ZeDMDComm::Connect()

#if !((defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || defined(__ANDROID__))
if (*m_device != 0) {
LogMessage("Connecting to ZeDMD on %s...", m_device);
Log("Connecting to ZeDMD on %s...", m_device);

success = Connect(m_device);

if (!success)
LogMessage("Unable to connect to ZeDMD on %s", m_device);
Log("Unable to connect to ZeDMD on %s", m_device);
}
else {
LogMessage("Searching for ZeDMD...");
Log("Searching for ZeDMD...");

struct sp_port** ppPorts;
enum sp_return result = sp_list_ports(&ppPorts);
Expand All @@ -302,7 +302,7 @@ bool ZeDMDComm::Connect()
}

if (!success)
LogMessage("Unable to find ZeDMD");
Log("Unable to find ZeDMD");
}
#endif

Expand All @@ -319,11 +319,11 @@ void ZeDMDComm::Disconnect()
#if !((defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || defined(__ANDROID__))
sp_set_config(m_pSerialPort, m_pSerialPortConfig);
sp_free_config(m_pSerialPortConfig);
m_pSerialPortConfig = NULL;
m_pSerialPortConfig = nullptr;

sp_close(m_pSerialPort);
sp_free_port(m_pSerialPort);
m_pSerialPort = NULL;
m_pSerialPort = nullptr;
#endif
}

Expand All @@ -337,7 +337,7 @@ bool ZeDMDComm::Connect(char *pDevice)
result = sp_open(m_pSerialPort, SP_MODE_READ_WRITE);
if (result != SP_OK) {
sp_free_port(m_pSerialPort);
m_pSerialPort = NULL;
m_pSerialPort = nullptr;

return false;
}
Expand Down Expand Up @@ -399,10 +399,10 @@ bool ZeDMDComm::Connect(char *pDevice)
m_flowControlCounter = 1;

if (pDevice) {
LogMessage("ZeDMD found: device=%s, width=%d, height=%d", pDevice, m_width, m_height);
Log("ZeDMD found: device=%s, width=%d, height=%d", pDevice, m_width, m_height);
}
else {
LogMessage("ZeDMD found: width=%d, height=%d", m_width, m_height);
Log("ZeDMD found: width=%d, height=%d", m_width, m_height);
}

return true;
Expand All @@ -422,7 +422,7 @@ bool ZeDMDComm::Connect(char *pDevice)
bool ZeDMDComm::IsConnected()
{
#if !((defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || defined(__ANDROID__))
return (m_pSerialPort != NULL);
return (m_pSerialPort != nullptr);
#else
return false;
#endif
Expand Down Expand Up @@ -494,7 +494,7 @@ bool ZeDMDComm::StreamBytes(ZeDMDFrame *pFrame)
position += ZEDMD_COMM_MAX_SERIAL_WRITE_AT_ONCE;
else {
success = false;
LogMessage("Write bytes failure: response=%c", response);
Log("Write bytes failure: response=%c", response);
}
}

Expand All @@ -504,7 +504,7 @@ bool ZeDMDComm::StreamBytes(ZeDMDFrame *pFrame)
m_flowControlCounter = 1;
}
else {
LogMessage("No Ready Signal");
Log("No Ready Signal");
}

free(data);
Expand Down
22 changes: 11 additions & 11 deletions src/ZeDMDComm.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#if !((defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || defined(__ANDROID__))
#include "libserialport.h"
#endif

#include <thread>
#include <queue>
#include <string>
Expand All @@ -12,14 +16,10 @@
#include <TargetConditionals.h>
#endif

#if !((defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || defined(__ANDROID__))
#include "libserialport.h"
#endif

#if defined(_WIN32) || defined(_WIN64)
#define CALLBACK __stdcall
#ifdef _MSC_VER
#define ZEDMDCALLBACK __stdcall
#else
#define CALLBACK
#define ZEDMDCALLBACK
#endif

typedef enum
Expand Down Expand Up @@ -81,7 +81,7 @@ struct ZeDMDFrame
#define ZEDMD_COMM_FRAME_QUEUE_SIZE_MAX 8
#define ZEDMD_COMM_FRAME_QUEUE_SIZE_MAX_DELAYED 2

typedef void(CALLBACK *ZeDMD_LogMessageCallback)(const char *format, va_list args, const void *userData);
typedef void(ZEDMDCALLBACK *ZeDMD_LogCallback)(const char *format, va_list args, const void *userData);

class ZeDMDComm
{
Expand All @@ -93,7 +93,7 @@ class ZeDMDComm
ZeDMDComm();
~ZeDMDComm();

void SetLogMessageCallback(ZeDMD_LogMessageCallback callback, const void *userData);
void SetLogCallback(ZeDMD_LogCallback callback, const void *userData);

void IgnoreDevice(const char *ignore_device);
void SetDevice(const char *device);
Expand Down Expand Up @@ -121,11 +121,11 @@ class ZeDMDComm
uint8_t m_zoneHeight = 4;

private:
void LogMessage(const char *format, ...);
void Log(const char *format, ...);

bool Connect(char *pName);

ZeDMD_LogMessageCallback m_logMessageCallback = nullptr;
ZeDMD_LogCallback m_LogCallback = nullptr;
const void *m_logMessageUserData = nullptr;
uint64_t m_zoneHashes[128] = {0};
uint16_t m_width = 128;
Expand Down
5 changes: 2 additions & 3 deletions src/ZeDMDWiFi.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#pragma once

#include "ZeDMDComm.h"

#if defined(_WIN32) || defined(_WIN64)
#include <winsock2.h>
#define CALLBACK __stdcall
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#define CALLBACK
#endif
#include "ZeDMDComm.h"

#define ZEDMD_WIFI_ZONES_BYTES_LIMIT 1800

Expand Down
4 changes: 2 additions & 2 deletions src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <chrono>
#include <thread>

void CALLBACK OnLogMessage(const char* format, va_list args, const void* pUserData)
void ZEDMDCALLBACK LogCallback(const char* format, va_list args, const void* pUserData)
{
char buffer[1024];
vsnprintf(buffer, sizeof(buffer), format, args);
Expand Down Expand Up @@ -40,7 +40,7 @@ uint8_t* CreateImageRGB24()
int main(int argc, const char *argv[])
{
ZeDMD* pZeDMD = new ZeDMD();
pZeDMD->SetLogMessageCallback(OnLogMessage, NULL);
pZeDMD->SetLogCallback(LogCallback, nullptr);

if (pZeDMD->Open(128, 32))
{
Expand Down

0 comments on commit efb3a33

Please sign in to comment.