-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.ts
92 lines (83 loc) · 2.11 KB
/
core.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
import { Button } from "./gpiozero/button.ts";
import { LED } from "./gpiozero/led.ts";
export const EPD_WIDTH = 122;
export const EPD_HEIGHT = 250;
export const RST_PIN = 17;
export const DC_PIN = 25;
export const CS_PIN = 8;
export const BUSY_PIN = 24;
export const PWR_PIN = 18;
export const MOSI_PIN = 10;
export const SCLK_PIN = 11;
export class RaspberryPi {
// SPI;
static GPIO_RST_PIN = new LED(RST_PIN);
static GPIO_DC_PIN = new LED(DC_PIN);
static GPIO_CS_PIN = new LED(CS_PIN);
static GPIO_PWR_PIN = new LED(PWR_PIN);
static GPIO_BUSY_PIN = new Button(BUSY_PIN);
static digitalWrite(pin: number, value?: boolean) {
switch (pin) {
case RST_PIN:
if (value) {
this.GPIO_RST_PIN.on();
break;
}
this.GPIO_RST_PIN.off();
break;
case DC_PIN:
if (value) {
this.GPIO_DC_PIN.on();
break;
}
this.GPIO_DC_PIN.off();
break;
case CS_PIN:
if (value) {
this.GPIO_CS_PIN.on();
break;
}
this.GPIO_CS_PIN.off();
break;
case PWR_PIN:
if (value) {
this.GPIO_PWR_PIN.on();
break;
}
this.GPIO_PWR_PIN.off();
break;
}
}
static digitalRead(pin: number) {
switch (pin) {
case BUSY_PIN:
return this.GPIO_BUSY_PIN.gpio.getValue();
case RST_PIN:
return this.GPIO_RST_PIN.gpio.getValue();
case DC_PIN:
return this.GPIO_DC_PIN.gpio.getValue();
case CS_PIN:
return this.GPIO_CS_PIN.gpio.getValue();
case PWR_PIN:
return this.GPIO_PWR_PIN.gpio.getValue();
}
}
static delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
static spiWriteByte(bytes: Uint8Array | number) {
console.log("SPI write byte:", bytes);
}
static moduleInit() {
this.GPIO_RST_PIN.off();
this.GPIO_DC_PIN.off();
this.GPIO_CS_PIN.off();
this.GPIO_PWR_PIN.on();
}
static moduleExit() {
this.GPIO_RST_PIN.off();
this.GPIO_DC_PIN.off();
this.GPIO_CS_PIN.off();
this.GPIO_PWR_PIN.off();
}
}