-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepd.h
158 lines (135 loc) · 5.94 KB
/
epd.h
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
/**
* Known Bugs:
* 1. After using the REFRESH command the HANDSHAKE command will return "OK" immediately, but other Get
* commands (such as GET_BAUD_RATE) will not work until the panel finishes refreshing.
* 2. In testing on othe Arduino Yun, communicating with the panel at the default 115200 Baud Rate yields
* a lot of noise on signal line coming out of the panel. Decreasing the Baud Rate to 57600 solved this
* problem in my testing.
* 3. The command GET_STORAGE_AREA is returning "OK" instead of a '0' or '1' like expected
*
*/
#ifndef EPD_h
#define EPD_h
#include "Arduino.h"
namespace EPD {
enum Color : byte {
BLACK = 0x00,
DARK_GREY = 0x01,
LIGHT_GREY = 0x02,
WHITE = 0x03
};
enum StorageArea : byte {
NAND_FLASH = 0x00,
MICRO_SD = 0x01
};
enum DisplayDirection : byte {
NORMAL = 0x00,
INVERTED = 0x01
};
enum FontSize : byte {
DOTS_MATRIX_32 = 0x01,
DOTS_MATRIX_48 = 0x02,
DOTS_MATRIX_64 = 0x03
};
enum Command : byte {
/* System Control Commands */
HANDSHAKE = 0x00,
SET_BAUD_RATE = 0x01,
GET_BAUD_RATE = 0x02,
GET_STORAGE_AREA = 0x06,
SET_STORAGE_AREA = 0x07,
ENTER_SLEEP = 0x08,
REFRESH = 0x0A,
GET_DISP_DIRECTION = 0x0C,
SET_DISP_DIRECTION = 0x0D,
IMPORT_FONT_LIBRARY = 0x0E,
IMPORT_IMAGE = 0x0F,
/* Display Parameter Configuration Commands */
SET_DRAWING_COLOR = 0x10,
GET_DRAWING_COLOR = 0x11,
GET_ENGLISH_FONT_SIZE = 0x1C,
GET_CHINESE_FONT_SIZE = 0x1D,
SET_ENGLISH_FONT_SIZE = 0x1E,
SET_CHINESE_FONT_SIZE = 0x1F,
/* Basic Drawing Commands */
DRAW_POINT = 0x20,
DRAW_LINE = 0x22,
FILL_RECTANGLE = 0x24,
DRAW_RECTANGLE = 0x25,
DRAW_CIRCLE = 0x26,
FILL_CIRCLE = 0x27,
DRAW_TRIANGLE = 0x28,
FILL_TRIANGLE = 0x29,
CLEAR_SCREEN = 0x2E,
DISPLAY_TEXT = 0x30,
DISPLAY_IMAGE = 0x70
};
class Display {
public:
Display(HardwareSerial &s, int wakeUpPin, int resetPin);
/* Hardware Control Functions */
void reset();
void wakeUp();
/* System Control Functions */
bool handshake();
bool setBaudRate(long baudRate);
long getBaudRate();
StorageArea getStorageArea();
bool setStorageArea(StorageArea storageArea);
void enterSleep();
bool refresh();
DisplayDirection getDisplayDirection();
bool setDisplayDirection(DisplayDirection displayDirection);
bool importFontLibrary();
bool importImage();
/* Display Parameter Configuration Functions */
bool setDrawingColor(Color color, Color backgroundColor);
Color getDrawingColor();
Color getBackgroundColor();
FontSize getEnglishFontSize();
FontSize getChineseFontSize();
bool setEnglishFontSize(FontSize fontSize);
bool setChineseFontSize(FontSize fontSize);
/* Basic Drawing Functions */
bool drawPoint(unsigned int x, unsigned int y);
bool drawLine(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1);
bool fillRectangle(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1);
bool drawRectangle(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1);
bool drawCircle(unsigned int x, unsigned int y, unsigned int radius);
bool fillCircle(unsigned int x, unsigned int y, unsigned int radius);
bool drawTriangle(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2);
bool fillTriangle(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2);
bool clearScreen();
bool displayText(unsigned int x, unsigned int y, const void *str);
bool displayImage(unsigned int x, unsigned int y, const void *fileName);
private:
static const short WAIT_FOR_RESPONSE_MS = 20;
static const byte FRAME_HEADER = 0xA5;
static const byte FRAME_END[4];
/* System Control Command Packets */
static const byte HANDSHAKE_PACKET[9];
static const byte GET_BAUD_RATE_PACKET[9];
static const byte GET_STORAGE_AREA_PACKET[9];
static const byte ENTER_SLEEP_PACKET[9];
static const byte REFRESH_PACKET[9];
static const byte GET_DISP_DIRECTION_PACKET[9];
static const byte IMPORT_FONT_LIBRARY_PACKET[9];
static const byte IMPORT_IMAGE_PACKET[9];
static const byte CLEAR_SCREEN_PACKET[9];
static const byte GET_DRAWING_COLOR_PACKET[9];
static const byte GET_ENGLISH_FONT_SIZE_PACKET[9];
static const byte GET_CHINESE_FONT_SIZE_PACKET[9];
HardwareSerial &serial;
int wakeUpPin;
int resetPin;
byte outputBuffer[1033];
byte inBuffer[256];
byte calculateParityByte(const byte *data, int length);
void sendData(const byte *data, int length);
void flushInputStream();
bool checkOkResponse();
Color charToColor(char inByte);
FontSize charToFontSize(char inByte);
};
};
#endif