diff --git a/src/ZeDMD.cpp b/src/ZeDMD.cpp index 7228304..3b88508 100644 --- a/src/ZeDMD.cpp +++ b/src/ZeDMD.cpp @@ -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(); @@ -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() diff --git a/src/ZeDMD.h b/src/ZeDMD.h index a51fbe7..3b28c27 100644 --- a/src/ZeDMD.h +++ b/src/ZeDMD.h @@ -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) @@ -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 #include #include -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; @@ -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); diff --git a/src/ZeDMDComm.cpp b/src/ZeDMDComm.cpp index 5616954..cab0e3e 100644 --- a/src/ZeDMDComm.cpp +++ b/src/ZeDMDComm.cpp @@ -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 } @@ -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()) { @@ -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"); }); } @@ -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) @@ -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); @@ -302,7 +302,7 @@ bool ZeDMDComm::Connect() } if (!success) - LogMessage("Unable to find ZeDMD"); + Log("Unable to find ZeDMD"); } #endif @@ -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 } @@ -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; } @@ -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; @@ -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 @@ -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); } } @@ -504,7 +504,7 @@ bool ZeDMDComm::StreamBytes(ZeDMDFrame *pFrame) m_flowControlCounter = 1; } else { - LogMessage("No Ready Signal"); + Log("No Ready Signal"); } free(data); diff --git a/src/ZeDMDComm.h b/src/ZeDMDComm.h index b1adf6c..35cd44c 100644 --- a/src/ZeDMDComm.h +++ b/src/ZeDMDComm.h @@ -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 #include #include @@ -12,14 +16,10 @@ #include #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 @@ -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 { @@ -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); @@ -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; diff --git a/src/ZeDMDWiFi.h b/src/ZeDMDWiFi.h index c8068fd..56add51 100644 --- a/src/ZeDMDWiFi.h +++ b/src/ZeDMDWiFi.h @@ -1,15 +1,14 @@ #pragma once +#include "ZeDMDComm.h" + #if defined(_WIN32) || defined(_WIN64) #include -#define CALLBACK __stdcall #else #include #include #include -#define CALLBACK #endif -#include "ZeDMDComm.h" #define ZEDMD_WIFI_ZONES_BYTES_LIMIT 1800 diff --git a/src/test.cpp b/src/test.cpp index 81cd446..3b221f6 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -4,7 +4,7 @@ #include #include -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); @@ -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)) {