-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepd2in13b_V4.ts
154 lines (127 loc) · 3.63 KB
/
epd2in13b_V4.ts
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
// deno-lint-ignore-file no-explicit-any
import {
BUSY_PIN,
CS_PIN,
DC_PIN,
EPD_HEIGHT,
EPD_WIDTH,
RaspberryPi,
RST_PIN,
} from "./core.ts";
export class EPaperDisplay {
resetPin = RST_PIN;
dcPin = DC_PIN;
busyPin = BUSY_PIN;
csPin = CS_PIN;
width = EPD_WIDTH;
height = EPD_HEIGHT;
reset() {
RaspberryPi.digitalWrite(this.resetPin, true);
RaspberryPi.delay(200);
RaspberryPi.digitalWrite(this.resetPin, false);
RaspberryPi.delay(200);
RaspberryPi.digitalWrite(this.resetPin, true);
RaspberryPi.delay(200);
}
sendCommand(command: any) {
RaspberryPi.digitalWrite(this.dcPin, false);
RaspberryPi.digitalWrite(this.csPin, false);
RaspberryPi.spiWriteByte(command);
RaspberryPi.digitalWrite(this.csPin, true);
}
sendData(data: Uint8Array | number) {
RaspberryPi.digitalWrite(this.dcPin, true);
RaspberryPi.digitalWrite(this.csPin, false);
RaspberryPi.spiWriteByte(data);
RaspberryPi.digitalWrite(this.csPin, true);
}
busy() {
while (RaspberryPi.digitalRead(this.busyPin) === 0) {
RaspberryPi.delay(100);
}
}
setWindows(
{ start, end }: {
start: { x: number; y: number };
end: { x: number; y: number };
},
) {
this.sendCommand(0x44); // SET_RAM_X_ADDRESS_START_END_POSITION
this.sendData((start.x >> 3) & 0xff);
this.sendData((end.x >> 3) & 0xff);
this.sendCommand(0x45); // SET_RAM_Y_ADDRESS_START_END_POSITION
this.sendData(start.y & 0xff);
this.sendData((start.y >> 8) & 0xff);
this.sendData(end.y & 0xff);
this.sendData((end.y >> 8) & 0xff);
}
setCursor({ x, y }: { x: number; y: number }) {
this.sendCommand(0x4E); // SET_RAM_X_ADDRESS_COUNTER
this.sendData(x & 0xff);
this.sendCommand(0x4F); // SET_RAM_Y_ADDRESS_COUNTER
this.sendData(y & 0xff);
this.sendData((y >> 8) & 0xff);
}
init() {
RaspberryPi.moduleInit();
this.reset();
this.busy();
this.sendCommand(0x12); // SWRESET
this.busy();
this.sendCommand(0x01); // Driver output control
this.sendData(0xf9);
this.sendData(0x00);
this.sendData(0x00);
this.sendCommand(0x11); // data entry mode
this.sendData(0x03);
this.setWindows({
start: { x: 0, y: 0 },
end: { x: this.width - 1, y: this.height - 1 },
});
this.setCursor({ x: 0, y: 0 });
this.sendCommand(0x3C); // BorderWavefrom
this.sendData(0x05);
this.sendCommand(0x18); // Read built-in temperature sensor
this.sendData(0x80);
this.sendCommand(0x21); // Display update control
this.sendData(0x80);
this.sendData(0x80);
this.busy();
}
onDisplay() {
this.sendCommand(0x20);
}
display(imageBlack: Uint8Array, imageRed: Uint8Array) {
this.sendCommand(0x24); // WRITE_RAM
for (let i = 0; i < this.width / 8 * this.height; i++) {
this.sendData(imageBlack[i]);
}
this.sendCommand(0x26); // WRITE_RAM
for (let i = 0; i < this.width / 8 * this.height; i++) {
this.sendData(imageRed[i]);
}
this.sendCommand(0x22); // DISPLAY REFRESH
this.sendCommand(0xC7); // DISPLAY REFRESH
this.sendData(0xC4); // DISPLAY REFRESH
RaspberryPi.delay(100);
this.busy();
}
clear() {
const lineWidth = this.width % 8 === 0
? this.width / 8
: this.width / 8 + 1;
const line = new Uint8Array(lineWidth * this.height);
line.fill(0xff);
this.sendCommand(0x24);
this.sendData(line);
this.sendCommand(0x26);
this.sendData(line);
this.onDisplay();
}
sleep() {
this.sendCommand(0x10) // DEEP_SLEEP
this.sendData(0x01) // check code
RaspberryPi.delay(2000)
RaspberryPi.moduleExit()
}
}