libzedmd
ZeDMD.h
Go to the documentation of this file.
1
6#pragma once
7
8#define ZEDMD_VERSION_MAJOR 0 // X Digits
9#define ZEDMD_VERSION_MINOR 7 // Max 2 Digits
10#define ZEDMD_VERSION_PATCH 0 // Max 2 Digits
11
12#define _ZEDMD_STR(x) #x
13#define ZEDMD_STR(x) _ZEDMD_STR(x)
14
15#define ZEDMD_VERSION \
16 ZEDMD_STR(ZEDMD_VERSION_MAJOR) \
17 "." ZEDMD_STR(ZEDMD_VERSION_MINOR) "." ZEDMD_STR(ZEDMD_VERSION_PATCH)
18#define ZEDMD_MINOR_VERSION ZEDMD_STR(ZEDMD_VERSION_MAJOR) "." ZEDMD_STR(ZEDMD_VERSION_MINOR)
19
20#define ZEDMD_MAX_WIDTH 256
21#define ZEDMD_MAX_HEIGHT 64
22#define ZEDMD_MAX_PALETTE 192
23
24#ifdef _MSC_VER
25#define ZEDMDAPI __declspec(dllexport)
26#define ZEDMDCALLBACK __stdcall
27#else
28#define ZEDMDAPI __attribute__((visibility("default")))
29#define ZEDMDCALLBACK
30#endif
31
32#include <inttypes.h>
33#include <stdarg.h>
34
35#include <cstdio>
36
37typedef void(ZEDMDCALLBACK* ZeDMD_LogCallback)(const char* format, va_list args, const void* userData);
38
39class ZeDMDComm;
40class ZeDMDWiFi;
41
42class ZEDMDAPI ZeDMD
43{
44 public:
45 ZeDMD();
46 ~ZeDMD();
47
48 void SetLogCallback(ZeDMD_LogCallback callback, const void* userData);
49
65 void IgnoreDevice(const char* const ignore_device);
66
75 void SetDevice(const char* const device);
76
86 bool Open();
87
100 bool Open(uint16_t width, uint16_t height);
101
116 bool OpenWiFi(const char* ip, int port);
117
122 void Close();
123
128 void Reset();
129
144 void SetFrameSize(uint16_t width, uint16_t height);
145
152 uint16_t const GetWidth();
153
160 uint16_t const GetHeight();
161
169 bool const IsS3();
170
182 void SetPalette(uint8_t* pPalette, uint8_t numColors);
183
193 void SetPalette(uint8_t* pPalette);
194
204 void SetDefaultPalette(uint8_t bitDepth);
205
213 uint8_t* GetDefaultPalette(uint8_t bitDepth);
214
219 void LedTest();
220
227 void EnableDebug();
228
233 void DisableDebug();
234
243 void SetRGBOrder(uint8_t rgbOrder);
244
252 void SetBrightness(uint8_t brightness);
253
261 void SetWiFiSSID(const char* const ssid);
262
270 void SetWiFiPassword(const char* const password);
271
279 void SetWiFiPort(int port);
280
294 void SaveSettings();
295
302 void EnablePreDownscaling();
303
308 void DisablePreDownscaling();
309
316 void EnablePreUpscaling();
317
322 void DisablePreUpscaling();
323
336 void EnableUpscaling();
337
342 void DisableUpscaling();
343
362 void EnforceStreaming();
363
370 void DisableRGB24Streaming();
371
376 void ClearScreen();
377
386 void RenderGray2(uint8_t* frame);
387
396 void RenderGray4(uint8_t* frame);
397
410 void RenderColoredGray6(uint8_t* frame, uint8_t* rotations);
411
426 void RenderColoredGray6(uint8_t* frame, uint8_t* palette, uint8_t* rotations);
427
436 void RenderRgb24(uint8_t* frame);
437
445 void RenderRgb24EncodedAs565(uint8_t* frame);
446
454 void RenderRgb24EncodedAs16(uint8_t* frame) { RenderRgb24EncodedAs565(frame); }
455
462 void RenderRgb565(uint16_t* frame);
463
471 void RenderRgb16(uint16_t* frame) { RenderRgb565(frame); }
472
473 private:
474 bool UpdateFrameBuffer8(uint8_t* pFrame);
475 bool UpdateFrameBuffer24(uint8_t* pFrame);
476 bool UpdateFrameBuffer565(uint16_t* pFrame);
477 uint8_t GetScaleMode(uint16_t frameWidth, uint16_t frameHeight, uint16_t* pWidth, uint16_t* pHeight,
478 uint8_t* pXOffset, uint8_t* pYOffset);
479 int Scale(uint8_t* pScaledFrame, uint8_t* pFrame, uint8_t bytes, uint16_t* width, uint16_t* height);
480 int Scale16(uint8_t* pScaledFrame, uint16_t* pFrame, uint16_t* width, uint16_t* height, bool bigEndian);
481
482 ZeDMDComm* m_pZeDMDComm;
483 ZeDMDWiFi* m_pZeDMDWiFi;
484
485 uint16_t m_romWidth;
486 uint16_t m_romHeight;
487
488 bool m_usb = false;
489 bool m_wifi = false;
490 bool m_hd = false;
491 bool m_downscaling = false;
492 bool m_upscaling = false;
493 bool m_streaming = false;
494 bool m_rgb24Streaming = true;
495 bool m_paletteChanged = false;
496
497 uint8_t* m_pFrameBuffer;
498 uint8_t* m_pScaledFrameBuffer;
499 uint8_t* m_pCommandBuffer;
500 uint8_t* m_pPlanes;
501 uint8_t* m_pRgb565Buffer;
502
503 uint8_t m_palette4[4 * 3] = {0};
504 uint8_t m_palette16[16 * 3] = {0};
505 uint8_t m_palette64[64 * 3] = {0};
506 uint8_t m_DmdDefaultPalette2Bit[12] = {0, 0, 0, 144, 34, 0, 192, 76, 0, 255, 127, 0};
507 uint8_t m_DmdDefaultPalette4Bit[48] = {0, 0, 0, 51, 25, 0, 64, 32, 0, 77, 38, 0, 89, 44, 0, 102,
508 51, 0, 115, 57, 0, 128, 64, 0, 140, 70, 0, 153, 76, 0, 166, 83,
509 0, 179, 89, 0, 191, 95, 0, 204, 102, 0, 230, 114, 0, 255, 127, 0};
510};
511
512#ifdef __cplusplus
513extern "C"
514{
515#endif
516
517 extern ZEDMDAPI ZeDMD* ZeDMD_GetInstance();
518 extern ZEDMDAPI void ZeDMD_IgnoreDevice(ZeDMD* pZeDMD, const char* const ignore_device);
519 extern ZEDMDAPI void ZeDMD_SetDevice(ZeDMD* pZeDMD, const char* const device);
520 extern ZEDMDAPI bool ZeDMD_Open(ZeDMD* pZeDMD);
521 extern ZEDMDAPI bool ZeDMD_OpenWiFi(ZeDMD* pZeDMD, const char* ip, int port);
522 extern ZEDMDAPI void ZeDMD_Close(ZeDMD* pZeDMD);
523
524 extern ZEDMDAPI void ZeDMD_SetFrameSize(ZeDMD* pZeDMD, uint16_t width, uint16_t height);
525 extern ZEDMDAPI void ZeDMD_SetPalette(ZeDMD* pZeDMD, uint8_t* pPalette, uint8_t numColors);
526 extern ZEDMDAPI void ZeDMD_SetDefaultPalette(ZeDMD* pZeDMD, uint8_t bitDepth);
527 extern ZEDMDAPI uint8_t* ZeDMD_GetDefaultPalette(ZeDMD* pZeDMD, uint8_t bitDepth);
528 extern ZEDMDAPI void ZeDMD_LedTest(ZeDMD* pZeDMD);
529 extern ZEDMDAPI void ZeDMD_EnableDebug(ZeDMD* pZeDMD);
530 extern ZEDMDAPI void ZeDMD_DisableDebug(ZeDMD* pZeDMD);
531 extern ZEDMDAPI void ZeDMD_SetRGBOrder(ZeDMD* pZeDMD, uint8_t rgbOrder);
532 extern ZEDMDAPI void ZeDMD_SetBrightness(ZeDMD* pZeDMD, uint8_t brightness);
533 extern ZEDMDAPI void ZeDMD_SaveSettings(ZeDMD* pZeDMD);
534 extern ZEDMDAPI void ZeDMD_EnablePreDownscaling(ZeDMD* pZeDMD);
535 extern ZEDMDAPI void ZeDMD_DisablePreDownscaling(ZeDMD* pZeDMD);
536 extern ZEDMDAPI void ZeDMD_EnablePreUpscaling(ZeDMD* pZeDMD);
537 extern ZEDMDAPI void ZeDMD_DisablePreUpscaling(ZeDMD* pZeDMD);
538 extern ZEDMDAPI void ZeDMD_EnableUpscaling(ZeDMD* pZeDMD);
539 extern ZEDMDAPI void ZeDMD_DisableUpscaling(ZeDMD* pZeDMD);
540 extern ZEDMDAPI void ZeDMD_SetWiFiSSID(ZeDMD* pZeDMD, const char* const ssid);
541 extern ZEDMDAPI void ZeDMD_SetWiFiPassword(ZeDMD* pZeDMD, const char* const password);
542 extern ZEDMDAPI void ZeDMD_SetWiFiPort(ZeDMD* pZeDMD, int port);
543 extern ZEDMDAPI void ZeDMD_EnforceStreaming(ZeDMD* pZeDMD);
544
545 extern ZEDMDAPI void ZeDMD_ClearScreen(ZeDMD* pZeDMD);
546 extern ZEDMDAPI void ZeDMD_RenderGray2(ZeDMD* pZeDMD, uint8_t* frame);
547 extern ZEDMDAPI void ZeDMD_RenderGray4(ZeDMD* pZeDMD, uint8_t* frame);
548 extern ZEDMDAPI void ZeDMD_RenderColoredGray6(ZeDMD* pZeDMD, uint8_t* frame, uint8_t* rotations);
549 extern ZEDMDAPI void ZeDMD_RenderRgb24(ZeDMD* pZeDMD, uint8_t* frame);
550 extern ZEDMDAPI void ZeDMD_RenderRgb24EncodedAs565(ZeDMD* pZeDMD, uint8_t* frame);
551
552#ifdef __cplusplus
553}
554#endif
Definition: ZeDMDComm.h:92
Definition: ZeDMDWiFi.h:16
Definition: ZeDMD.h:43
void RenderRgb16(uint16_t *frame)
Render a RGB16 frame.
Definition: ZeDMD.h:471
void RenderRgb24EncodedAs16(uint8_t *frame)
Render a RGB24 frame.
Definition: ZeDMD.h:454