forked from pixelmatix/SmartMatrix
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSmartMatrix.h
More file actions
186 lines (156 loc) · 6.84 KB
/
SmartMatrix.h
File metadata and controls
186 lines (156 loc) · 6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* SmartMatrix Library - Main Header File for SmartMatrix Class
*
* Copyright (c) 2014 Louis Beaudoin (Pixelmatix)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SmartMatrix_h
#define SmartMatrix_h
#include "Arduino.h"
#include <stdint.h>
// include one of the MatrixHardware_*.h files here:
#include "MatrixHardware_KitV1_32x32.h"
//#include "MatrixHardware_KitV1_16x32.h"
// scroll text
const int textLayerMaxStringLength = 50;
typedef enum ScrollMode {
wrapForward,
bounceForward,
bounceReverse,
stopped,
off
} ScrollMode;
// font
#include "MatrixFontCommon.h"
extern const bitmap_font apple3x5;
extern const bitmap_font apple5x7;
extern const bitmap_font apple6x10;
extern const bitmap_font apple8x13;
typedef enum fontChoices {
font3x5,
font5x7,
font6x10,
font8x13,
} fontChoices;
// color
typedef struct rgb24 {
uint8_t red;
uint8_t green;
uint8_t blue;
} rgb24;
typedef enum colorCorrectionModes {
ccNone,
cc24,
cc12
} colorCorrectionModes;
#define RGB24_ISEQUAL(a, b) ((a.red == b.red) && (a.green == b.green) && (a.blue == b.blue))
// config
typedef enum rotationDegrees {
rotation0,
rotation90,
rotation180,
rotation270
} rotationDegrees;
typedef struct screen_config {
rotationDegrees rotation;
uint16_t localWidth;
uint16_t localHeight;
} screen_config;
class SmartMatrix {
public:
SmartMatrix();
void begin();
// drawing functions
void swapBuffers(bool copy = true);
void drawPixel(int16_t x, int16_t y, rgb24 color);
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, rgb24 color);
void drawFastVLine(int16_t x, int16_t y0, int16_t y1, rgb24 color);
void drawFastHLine(int16_t x0, int16_t x1, int16_t y, rgb24 color);
void drawCircle(int16_t x0, int16_t y0, uint16_t radius, rgb24 color);
void fillCircle(int16_t x0, int16_t y0, uint16_t radius, rgb24 outlineColor, rgb24 fillColor);
void fillCircle(int16_t x0, int16_t y0, uint16_t radius, rgb24 color);
void drawTriangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, rgb24 color);
void fillTriangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, rgb24 fillColor);
void fillTriangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, rgb24 outlineColor, rgb24 fillColor);
void drawRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, rgb24 color);
void fillRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, rgb24 color);
void fillRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, rgb24 outlineColor, rgb24 fillColor);
void drawRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t radius, rgb24 outlineColor);
void fillRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t radius, rgb24 fillColor);
void fillRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t radius, rgb24 outlineColor, rgb24 fillColor);
void fillScreen(rgb24 color);
void drawChar(int16_t x, int16_t y, rgb24 charColor, char character);
void drawString(int16_t x, int16_t y, rgb24 charColor, const char text[]);
void drawMonoBitmap(int16_t x, int16_t y, uint8_t width, uint8_t height, rgb24 bitmapColor, uint8_t *bitmap);
rgb24 readPixel(int16_t x, int16_t y);
rgb24 *backBuffer();
// scroll text
void scrollText(const char inputtext[], int numScrolls);
void setScrollMode(ScrollMode mode);
void setScrollSpeed(unsigned char pixels_per_second);
void setScrollFont(fontChoices newFont);
void setScrollColor(rgb24 newColor);
void setScrollOffsetFromEdge(int offset);
void stopScrollText(void);
int getScrollStatus(void);
// configuration
void setRotation(rotationDegrees rotation);
uint16_t getScreenWidth(void);
uint16_t getScreenHeight(void);
void setBrightness(uint8_t brightness);
void setColorCorrection(colorCorrectionModes mode);
void setFont(fontChoices newFont);
// functions called by ISR (not meant for user but can't be private)
static void matrixCalculations(void);
private:
// functions for refreshing
static void loadMatrixBuffers(unsigned char currentRow);
static uint8_t colorCorrection8bit(uint8_t inputcolor);
static void getPixel(uint8_t hardwareX, uint8_t hardwareY, rgb24 *xyPixel);
static void handleBufferSwap(void);
static void updateForeground(void);
static bool getForegroundPixel(uint8_t x, uint8_t y, rgb24 *xyPixel);
static void redrawForeground(void);
// drawing functions not meant for user
void drawHardwareHLine(uint8_t x0, uint8_t x1, uint8_t y, rgb24 color);
void drawHardwareVLine(uint8_t x, uint8_t y0, uint8_t y1, rgb24 color);
void bresteepline(int16_t x3, int16_t y3, int16_t x4, int16_t y4, rgb24 color);
void fillFlatSideTriangleInt(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, rgb24 color);
// configuration helper functions
static void calculateTimerLut(void);
// color functions (replace with class and copy constructor?)
static void copyRgb24(rgb24 *dst, rgb24 *src);
static void copyRgb24(rgb24 *dst, rgb24 src);
// configuration
static colorCorrectionModes _ccmode;
static screen_config screenConfig;
static volatile bool brightnessChange;
static int dimmingFactor;
static const int dimmingMaximum;
// keeping track of drawing buffer
static unsigned char currentDrawBuffer;
static unsigned char currentRefreshBuffer;
static volatile bool swapPending;
static bool swapWithCopy;
// font
static bool getBitmapFontPixelAtXY(unsigned char letter, unsigned char x, unsigned char y, const bitmap_font *font);
const bitmap_font *fontLookup(fontChoices font);
static uint16_t getBitmapFontRowAtXY(unsigned char letter, unsigned char y, const bitmap_font *font);
};
#endif