periph 1.2.1 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/examples/accelerometer/bma150/complete.js +62 -0
- package/examples/accelerometer/bma150/demo.js +65 -0
- package/examples/accelerometer/bma150/minimal.js +18 -0
- package/examples/adc_dac/hy3131/complete.js +66 -0
- package/examples/adc_dac/hy3131/demo.js +37 -0
- package/examples/adc_dac/hy3131/minimal.js +18 -0
- package/examples/discovery/complete.js +25 -0
- package/examples/discovery/demo.js +30 -0
- package/examples/discovery/minimal.js +12 -0
- package/examples/display/il0373/complete.js +71 -0
- package/examples/display/il0373/demo.js +49 -0
- package/examples/display/il0373/minimal.js +26 -0
- package/examples/display/ssd1331/complete.js +83 -0
- package/examples/display/ssd1331/demo.js +49 -0
- package/examples/display/ssd1331/minimal.js +27 -0
- package/examples/display/st7036/complete.js +71 -0
- package/examples/display/st7036/demo.js +56 -0
- package/examples/display/st7036/minimal.js +21 -0
- package/examples/display/uc1611s/complete.js +135 -0
- package/examples/display/uc1611s/complete_spi.js +128 -0
- package/examples/display/uc1611s/demo.js +90 -0
- package/examples/display/uc1611s/demo_spi.js +91 -0
- package/examples/display/uc1611s/minimal.js +28 -0
- package/examples/display/uc1611s/minimal_spi.js +30 -0
- package/examples/display/uc8159/complete.js +64 -0
- package/examples/display/uc8159/demo.js +41 -0
- package/examples/display/uc8159/minimal.js +28 -0
- package/examples/display/uc8276c/complete.js +73 -0
- package/examples/display/uc8276c/demo.js +49 -0
- package/examples/display/uc8276c/minimal.js +26 -0
- package/examples/environmental/bme280/complete.js +1 -1
- package/examples/environmental/bme280/demo.js +1 -1
- package/examples/environmental/bme280/minimal.js +1 -1
- package/examples/gyroscope/l3g4200d/complete.js +1 -1
- package/examples/gyroscope/l3g4200d/demo.js +1 -1
- package/examples/gyroscope/l3g4200d/minimal.js +1 -1
- package/examples/memory/23x1024/complete.js +54 -0
- package/examples/memory/23x1024/demo.js +51 -0
- package/examples/memory/23x1024/minimal.js +22 -0
- package/examples/memory/mx25l12845e/complete.js +66 -0
- package/examples/memory/mx25l12845e/demo.js +66 -0
- package/examples/memory/mx25l12845e/minimal.js +27 -0
- package/examples/memory/sd_spi/complete.js +55 -0
- package/examples/memory/sd_spi/demo.js +67 -0
- package/examples/memory/sd_spi/minimal.js +32 -0
- package/examples/pressure/bmp280/complete.js +1 -1
- package/examples/pressure/bmp280/demo.js +1 -1
- package/examples/pressure/bmp280/minimal.js +1 -1
- package/examples/pressure/bmp581/complete.js +1 -1
- package/examples/pressure/bmp581/demo.js +1 -1
- package/examples/pressure/bmp581/minimal.js +1 -1
- package/examples/pressure/lps22df/complete.js +1 -1
- package/examples/pressure/lps22df/demo.js +1 -1
- package/examples/pressure/lps22df/minimal.js +1 -1
- package/package.json +1 -1
- package/src/chips/accelerometer/adxl345.js +10 -31
- package/src/chips/accelerometer/adxl362.js +7 -7
- package/src/chips/accelerometer/bma150.js +419 -0
- package/src/chips/adc_dac/ad7705.js +36 -9
- package/src/chips/adc_dac/ad7706.js +39 -9
- package/src/chips/adc_dac/hy3131.js +311 -0
- package/src/chips/display/il0373.js +607 -0
- package/src/chips/display/ssd1331.js +412 -0
- package/src/chips/display/st7036.js +401 -0
- package/src/chips/display/uc1611s.js +648 -0
- package/src/chips/display/uc8159.js +394 -0
- package/src/chips/display/uc8276c.js +658 -0
- package/src/chips/environmental/bme280.js +31 -46
- package/src/chips/environmental/bme680.js +38 -43
- package/src/chips/gas/ens160.js +18 -26
- package/src/chips/gyroscope/l3g4200d.js +34 -50
- package/src/chips/gyroscope/l3gd20h.js +24 -40
- package/src/chips/imu/mpu6050.js +29 -41
- package/src/chips/imu/mpu9250.js +42 -66
- package/src/chips/imu/mpu9255.js +51 -75
- package/src/chips/io_expander/mcp23017.js +24 -33
- package/src/chips/light/apds-9930.js +52 -60
- package/src/chips/light/apds9960.js +69 -77
- package/src/chips/magnetometer/as5600.js +13 -27
- package/src/chips/magnetometer/hmc5883l.js +32 -29
- package/src/chips/memory/_23x1024.js +228 -0
- package/src/chips/memory/_24aa02uid.js +8 -11
- package/src/chips/memory/mx25l12845e.js +467 -0
- package/src/chips/memory/sd_spi.js +486 -0
- package/src/chips/motor/drv8830.js +4 -4
- package/src/chips/other/mpr121.js +7 -7
- package/src/chips/power/ina219.js +5 -8
- package/src/chips/power/ina226.js +5 -8
- package/src/chips/power/ina3221.js +5 -8
- package/src/chips/pressure/bmp085.js +17 -11
- package/src/chips/pressure/bmp180.js +7 -7
- package/src/chips/pressure/bmp280.js +21 -33
- package/src/chips/pressure/bmp384.js +28 -39
- package/src/chips/pressure/bmp581.js +59 -70
- package/src/chips/pressure/lps22df.js +50 -52
- package/src/chips/pressure/lps28dfw.js +15 -13
- package/src/chips/pressure/lps33hw.js +7 -5
- package/src/chips/rtc/ds3231.js +8 -8
- package/src/chips/rtc/pcf8523.js +8 -14
- package/src/chips/temperature/mcp9808.js +9 -7
- package/src/chips/temperature/tmp117.js +4 -4
- package/src/connection/connection.js +6 -4
- package/src/connection/dhtxx.js +5 -3
- package/src/connection/display.js +278 -0
- package/src/connection/display_mock.js +77 -0
- package/src/connection/hx711.js +5 -3
- package/src/connection/i2c.js +6 -4
- package/src/connection/i2c_mock.js +47 -0
- package/src/connection/input_pin.js +36 -5
- package/src/connection/register.js +14 -0
- package/src/connection/register_connection.js +65 -0
- package/src/connection/sipo.js +4 -2
- package/src/connection/sipo_mock.js +49 -0
- package/src/connection/smbus.js +6 -4
- package/src/connection/softspi.js +73 -0
- package/src/connection/spi.js +110 -23
- package/src/connection/spi_mock.js +50 -0
- package/src/connection/uart.js +2 -1
- package/src/discovery/discovery.js +218 -0
- package/src/discovery/registry.js +85 -0
- package/src/storage/block_device.js +95 -0
- package/src/storage/ram_block_device.js +72 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// UC1611s demo example: EA DOGXL240-7 (240 x 128, 3.3 V only) over I2C on a Raspberry Pi (Node.js).
|
|
2
|
+
// Wiring: SDA=GPIO2, SCL=GPIO3 (/dev/i2c-1), VDD = 3V3; module pins BM0 = D13 = VDD, CD = A2 = A3 = VSS -> command 0x38 / data 0x39.
|
|
3
|
+
// Capacitors: 4 x 4.7 uF/5 V (VA0, VA1, VB0, VB1 pairs), 470 nF/25 V on VLCD; pull-ups 2-4.7 k to 3.3 V. Demo: a bouncing ball with partial page updates, a contrast sweep, inverse flashes, hardware scroll, a second RAM screen and sleep.
|
|
4
|
+
'use strict';
|
|
5
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
6
|
+
const { UC1611sFull } = require('../../../src/chips/display/uc1611s');
|
|
7
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
8
|
+
|
|
9
|
+
const command = new I2CConnection(1, 0x38); // Create command connection, (busNumber=1, addr=0x38)
|
|
10
|
+
const data = new I2CConnection(1, 0x39); // Create data connection, (busNumber=1, addr=0x39)
|
|
11
|
+
const lcd = new UC1611sFull(command, data); // Create UC1611s driver, (command, data, width=240, height=128)
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
await lcd.ready();
|
|
15
|
+
// --- Draw the frame once ---
|
|
16
|
+
// A one-pixel border around the whole 240 x 128 panel; the ball bounces inside it.
|
|
17
|
+
lcd.clear(); // Clear framebuffer, ()
|
|
18
|
+
lcd.drawRect(0, 0, 240, 128); // Draw rectangle, (x, y, w, h, on=true, fill=false)
|
|
19
|
+
await lcd.show(); // Send framebuffer to the display, () → Promise<void>
|
|
20
|
+
|
|
21
|
+
// --- Bounce an 8 x 8 ball with partial page updates ---
|
|
22
|
+
// Only the page rows the ball touches are re-sent, so the animation runs at about
|
|
23
|
+
// 20 frames per second even at 400 kHz, instead of the 8 of a full-frame show().
|
|
24
|
+
let bx = 20, by = 12, dx = 3, dy = 2;
|
|
25
|
+
for (let frame = 0; frame < 200; frame++) {
|
|
26
|
+
const oldy = by;
|
|
27
|
+
lcd.drawRect(bx, by, 8, 8, false, true); // Draw rectangle, (x, y, w, h, on=true, fill=false)
|
|
28
|
+
bx += dx;
|
|
29
|
+
by += dy;
|
|
30
|
+
if (bx < 2 || bx > 229) { dx = -dx; bx += 2 * dx; }
|
|
31
|
+
if (by < 2 || by > 118) { dy = -dy; by += 2 * dy; }
|
|
32
|
+
lcd.drawRect(bx, by, 8, 8, true, true); // Draw rectangle, (x, y, w, h, on=true, fill=false)
|
|
33
|
+
for (let page = Math.floor(Math.min(oldy, by) / 8); page <= Math.floor((Math.max(oldy, by) + 7) / 8); page++) {
|
|
34
|
+
await lcd.showPage(page); // Send one framebuffer page, (page 0..15) → Promise<void>
|
|
35
|
+
}
|
|
36
|
+
await sleep(20);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// --- Contrast sweep around the working point ---
|
|
40
|
+
// The contrast is set once in normal use; sweeping PM shows the usable range of the panel.
|
|
41
|
+
for (let pm = 0x8F; pm >= 0x70; pm -= 2) {
|
|
42
|
+
await lcd.setContrast(pm); // Set contrast, (value 0..255) → Promise<void>
|
|
43
|
+
await sleep(40);
|
|
44
|
+
}
|
|
45
|
+
for (let pm = 0x70; pm <= 0x8F; pm += 2) {
|
|
46
|
+
await lcd.setContrast(pm); // Set contrast, (value 0..255) → Promise<void>
|
|
47
|
+
await sleep(40);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// --- Flash the inverse display twice ---
|
|
51
|
+
for (let i = 0; i < 2; i++) {
|
|
52
|
+
await lcd.setInvert(true); // Invert display, (on) → Promise<void>
|
|
53
|
+
await sleep(400);
|
|
54
|
+
await lcd.setInvert(false); // Invert display, (on) → Promise<void>
|
|
55
|
+
await sleep(400);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// --- Hardware scroll ---
|
|
59
|
+
// The image moves up in the controller, no data is re-sent; a blank band enters from the bottom
|
|
60
|
+
// because RAM rows 128..159 are empty.
|
|
61
|
+
for (let line = 0; line <= 32; line++) {
|
|
62
|
+
await lcd.setScrollLine(line); // Scroll the image up, (line 0..159 - 2 * fixed) → Promise<void>
|
|
63
|
+
await sleep(40);
|
|
64
|
+
}
|
|
65
|
+
for (let line = 32; line >= 0; line--) {
|
|
66
|
+
await lcd.setScrollLine(line); // Scroll the image up, (line 0..159 - 2 * fixed) → Promise<void>
|
|
67
|
+
await sleep(40);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// --- Second screen in RAM ---
|
|
71
|
+
// The chip holds four black/white screens; draw a cross into screen 1 and switch to it.
|
|
72
|
+
lcd.setWritePattern(1); // Select RAM screen to write, (pattern 0..3)
|
|
73
|
+
lcd.fill(false); // Fill framebuffer, (on=true)
|
|
74
|
+
lcd.drawLine(0, 0, 239, 127); // Draw line, (x0, y0, x1, y1, on=true)
|
|
75
|
+
lcd.drawLine(0, 127, 239, 0); // Draw line, (x0, y0, x1, y1, on=true)
|
|
76
|
+
await lcd.show(); // Send framebuffer to the display, () → Promise<void>
|
|
77
|
+
await lcd.setDisplayPattern(1); // Select displayed RAM screen, (pattern 0..3) → Promise<void>
|
|
78
|
+
await sleep(2000);
|
|
79
|
+
await lcd.setDisplayPattern(0); // Select displayed RAM screen, (pattern 0..3) → Promise<void>
|
|
80
|
+
lcd.setWritePattern(0); // Select RAM screen to write, (pattern 0..3)
|
|
81
|
+
await sleep(1500);
|
|
82
|
+
|
|
83
|
+
// --- Power down ---
|
|
84
|
+
// Sleep stops the charge pump and the drivers (below 1 uA); RAM and registers are kept.
|
|
85
|
+
await lcd.sleep(); // Enter sleep, () → Promise<void>
|
|
86
|
+
console.log(`done (I2C retries ${lcd.retryCount()}, unrecovered ${lcd.errorCount()})`);
|
|
87
|
+
command.close();
|
|
88
|
+
data.close();
|
|
89
|
+
process.exit(0);
|
|
90
|
+
})().catch((e) => { console.error(e); process.exit(1); });
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// UC1611s demo example (4-wire SPI): EA DOGXL240-7 (240 x 128, 3.3 V only) on a Raspberry Pi (Node.js).
|
|
2
|
+
// Wiring: SI=GPIO10 (SPI0 MOSI), SCK=GPIO11, CS0=GPIO8 (CE0), CD=GPIO25, RST=GPIO17; VDD=3V3; module pins BM0 = D13 = VSS (4-wire SPI).
|
|
3
|
+
// Capacitors: 4 x 4.7 uF/5 V (VA0, VA1, VB0, VB1 pairs), 470 nF/25 V on VLCD. Demo: a bouncing ball with partial page updates, a contrast sweep, inverse flashes, hardware scroll, a second RAM screen and sleep.
|
|
4
|
+
'use strict';
|
|
5
|
+
const { Default } = require('opengpio');
|
|
6
|
+
const { DisplayConnection } = require('../../../src/connection/display');
|
|
7
|
+
const { GpioOutputPin } = require('../../../src/connection/output_pin');
|
|
8
|
+
const { UC1611sSpiFull } = require('../../../src/chips/display/uc1611s');
|
|
9
|
+
|
|
10
|
+
const dc = new GpioOutputPin(Default.output({ chip: 0, line: 25 })); // Create CD (D/C) pin, (chip, line=25) → OutputPin
|
|
11
|
+
const res = new GpioOutputPin(Default.output({ chip: 0, line: 17 })); // Create RST pin, (chip, line=17) → OutputPin
|
|
12
|
+
const connection = new DisplayConnection({ busNumber: 0, deviceNumber: 0, dc, res, maxSpeedHz: 4000000 }); // Create display connection, (busNumber, deviceNumber, dc, res, busy=none, maxSpeedHz=4 MHz)
|
|
13
|
+
const lcd = new UC1611sSpiFull(connection); // Create UC1611s driver, (connection, width=240, height=128, topView=false, contrast=0x8F)
|
|
14
|
+
|
|
15
|
+
(async () => {
|
|
16
|
+
await lcd.ready();
|
|
17
|
+
// --- Draw the frame once ---
|
|
18
|
+
// A one-pixel border around the whole 240 x 128 panel; the ball bounces inside it.
|
|
19
|
+
lcd.clear(); // Clear framebuffer, ()
|
|
20
|
+
lcd.drawRect(0, 0, 240, 128); // Draw rectangle, (x, y, w, h, on=true, fill=false)
|
|
21
|
+
await lcd.show(); // Send framebuffer to the display, () → Promise<void>
|
|
22
|
+
|
|
23
|
+
// --- Bounce an 8 x 8 ball with partial page updates ---
|
|
24
|
+
// Only the page rows the ball touches are re-sent, so the animation runs at about
|
|
25
|
+
// 20 frames per second, instead of the 8 of a full-frame show().
|
|
26
|
+
let bx = 20, by = 12, dx = 3, dy = 2;
|
|
27
|
+
for (let frame = 0; frame < 200; frame++) {
|
|
28
|
+
const oldy = by;
|
|
29
|
+
lcd.drawRect(bx, by, 8, 8, false, true); // Draw rectangle, (x, y, w, h, on=true, fill=false)
|
|
30
|
+
bx += dx;
|
|
31
|
+
by += dy;
|
|
32
|
+
if (bx < 2 || bx > 229) { dx = -dx; bx += 2 * dx; }
|
|
33
|
+
if (by < 2 || by > 118) { dy = -dy; by += 2 * dy; }
|
|
34
|
+
lcd.drawRect(bx, by, 8, 8, true, true); // Draw rectangle, (x, y, w, h, on=true, fill=false)
|
|
35
|
+
for (let page = Math.floor(Math.min(oldy, by) / 8); page <= Math.floor((Math.max(oldy, by) + 7) / 8); page++) {
|
|
36
|
+
await lcd.showPage(page); // Send one framebuffer page, (page 0..15) → Promise<void>
|
|
37
|
+
}
|
|
38
|
+
await sleep(20);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// --- Contrast sweep around the working point ---
|
|
42
|
+
// The contrast is set once in normal use; sweeping PM shows the usable range of the panel.
|
|
43
|
+
for (let pm = 0x8F; pm >= 0x70; pm -= 2) {
|
|
44
|
+
await lcd.setContrast(pm); // Set contrast, (value 0..255) → Promise<void>
|
|
45
|
+
await sleep(40);
|
|
46
|
+
}
|
|
47
|
+
for (let pm = 0x70; pm <= 0x8F; pm += 2) {
|
|
48
|
+
await lcd.setContrast(pm); // Set contrast, (value 0..255) → Promise<void>
|
|
49
|
+
await sleep(40);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// --- Flash the inverse display twice ---
|
|
53
|
+
for (let i = 0; i < 2; i++) {
|
|
54
|
+
await lcd.setInvert(true); // Invert display, (on) → Promise<void>
|
|
55
|
+
await sleep(400);
|
|
56
|
+
await lcd.setInvert(false); // Invert display, (on) → Promise<void>
|
|
57
|
+
await sleep(400);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// --- Hardware scroll ---
|
|
61
|
+
// The image moves up in the controller, no data is re-sent; a blank band enters from the bottom
|
|
62
|
+
// because RAM rows 128..159 are empty.
|
|
63
|
+
for (let line = 0; line <= 32; line++) {
|
|
64
|
+
await lcd.setScrollLine(line); // Scroll the image up, (line 0..159 - 2 * fixed) → Promise<void>
|
|
65
|
+
await sleep(40);
|
|
66
|
+
}
|
|
67
|
+
for (let line = 32; line >= 0; line--) {
|
|
68
|
+
await lcd.setScrollLine(line); // Scroll the image up, (line 0..159 - 2 * fixed) → Promise<void>
|
|
69
|
+
await sleep(40);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// --- Second screen in RAM ---
|
|
73
|
+
// The chip holds four black/white screens; draw a cross into screen 1 and switch to it.
|
|
74
|
+
lcd.setWritePattern(1); // Select RAM screen to write, (pattern 0..3)
|
|
75
|
+
lcd.fill(false); // Fill framebuffer, (on=true)
|
|
76
|
+
lcd.drawLine(0, 0, 239, 127); // Draw line, (x0, y0, x1, y1, on=true)
|
|
77
|
+
lcd.drawLine(0, 127, 239, 0); // Draw line, (x0, y0, x1, y1, on=true)
|
|
78
|
+
await lcd.show(); // Send framebuffer to the display, () → Promise<void>
|
|
79
|
+
await lcd.setDisplayPattern(1); // Select displayed RAM screen, (pattern 0..3) → Promise<void>
|
|
80
|
+
await sleep(2000);
|
|
81
|
+
await lcd.setDisplayPattern(0); // Select displayed RAM screen, (pattern 0..3) → Promise<void>
|
|
82
|
+
lcd.setWritePattern(0); // Select RAM screen to write, (pattern 0..3)
|
|
83
|
+
await sleep(1500);
|
|
84
|
+
|
|
85
|
+
// --- Power down ---
|
|
86
|
+
// Sleep stops the charge pump and the drivers (below 1 uA); RAM and registers are kept.
|
|
87
|
+
await lcd.sleep(); // Enter sleep, () → Promise<void>
|
|
88
|
+
console.log('done');
|
|
89
|
+
connection.close();
|
|
90
|
+
process.exit(0);
|
|
91
|
+
})().catch((e) => { console.error(e); process.exit(1); });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// UC1611s minimal example: EA DOGXL240-7 (240 x 128, 3.3 V only) over I2C on a Raspberry Pi (Node.js).
|
|
2
|
+
// Wiring: SDA=GPIO2, SCL=GPIO3 (/dev/i2c-1), VDD = 3V3; module pins BM0 = D13 = VDD, CD = A2 = A3 = VSS -> command 0x38 / data 0x39.
|
|
3
|
+
// Capacitors: 4 x 4.7 uF/5 V (VA0, VA1, VB0, VB1 pairs), 470 nF/25 V on VLCD; pull-ups 2-4.7 k to 3.3 V. Minimal use: a border and a diagonal on the 240 x 128 panel.
|
|
4
|
+
'use strict';
|
|
5
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
6
|
+
const { UC1611sMinimal } = require('../../../src/chips/display/uc1611s');
|
|
7
|
+
|
|
8
|
+
const command = new I2CConnection(1, 0x38); // Create command connection, (busNumber=1, addr=0x38)
|
|
9
|
+
const data = new I2CConnection(1, 0x39); // Create data connection, (busNumber=1, addr=0x39)
|
|
10
|
+
const lcd = new UC1611sMinimal(command, data); // Create UC1611s driver, (command, data, width=240, height=128)
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
await lcd.ready();
|
|
14
|
+
lcd.clear(); // Clear framebuffer, ()
|
|
15
|
+
for (let x = 0; x < 240; x++) {
|
|
16
|
+
lcd.setPixel(x, 0); // Set pixel, (x 0..239, y 0..127, on=true)
|
|
17
|
+
lcd.setPixel(x, 127); // Set pixel, (x 0..239, y 0..127, on=true)
|
|
18
|
+
lcd.setPixel(x, Math.floor(x * 127 / 239)); // Set pixel, (x 0..239, y 0..127, on=true)
|
|
19
|
+
}
|
|
20
|
+
for (let y = 0; y < 128; y++) {
|
|
21
|
+
lcd.setPixel(0, y); // Set pixel, (x 0..239, y 0..127, on=true)
|
|
22
|
+
lcd.setPixel(239, y); // Set pixel, (x 0..239, y 0..127, on=true)
|
|
23
|
+
}
|
|
24
|
+
await lcd.show(); // Send framebuffer to the display, () → Promise<void>
|
|
25
|
+
command.close();
|
|
26
|
+
data.close();
|
|
27
|
+
process.exit(0);
|
|
28
|
+
})().catch((e) => { console.error(e); process.exit(1); });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// UC1611s minimal example (4-wire SPI): EA DOGXL240-7 (240 x 128, 3.3 V only) on a Raspberry Pi (Node.js).
|
|
2
|
+
// Wiring: SI=GPIO10 (SPI0 MOSI), SCK=GPIO11, CS0=GPIO8 (CE0), CD=GPIO25, RST=GPIO17; VDD=3V3; module pins BM0 = D13 = VSS (4-wire SPI).
|
|
3
|
+
// Capacitors: 4 x 4.7 uF/5 V (VA0, VA1, VB0, VB1 pairs), 470 nF/25 V on VLCD. Minimal use: a border and a diagonal on the 240 x 128 panel.
|
|
4
|
+
'use strict';
|
|
5
|
+
const { Default } = require('opengpio');
|
|
6
|
+
const { DisplayConnection } = require('../../../src/connection/display');
|
|
7
|
+
const { GpioOutputPin } = require('../../../src/connection/output_pin');
|
|
8
|
+
const { UC1611sSpiMinimal } = require('../../../src/chips/display/uc1611s');
|
|
9
|
+
|
|
10
|
+
const dc = new GpioOutputPin(Default.output({ chip: 0, line: 25 })); // Create CD (D/C) pin, (chip, line=25) → OutputPin
|
|
11
|
+
const res = new GpioOutputPin(Default.output({ chip: 0, line: 17 })); // Create RST pin, (chip, line=17) → OutputPin
|
|
12
|
+
const connection = new DisplayConnection({ busNumber: 0, deviceNumber: 0, dc, res, maxSpeedHz: 4000000 }); // Create display connection, (busNumber, deviceNumber, dc, res, busy=none, maxSpeedHz=4 MHz)
|
|
13
|
+
const lcd = new UC1611sSpiMinimal(connection); // Create UC1611s driver, (connection, width=240, height=128)
|
|
14
|
+
|
|
15
|
+
(async () => {
|
|
16
|
+
await lcd.ready();
|
|
17
|
+
lcd.clear(); // Clear framebuffer, ()
|
|
18
|
+
for (let x = 0; x < 240; x++) {
|
|
19
|
+
lcd.setPixel(x, 0); // Set pixel, (x 0..239, y 0..127, on=true)
|
|
20
|
+
lcd.setPixel(x, 127); // Set pixel, (x 0..239, y 0..127, on=true)
|
|
21
|
+
lcd.setPixel(x, Math.floor(x * 127 / 239)); // Set pixel, (x 0..239, y 0..127, on=true)
|
|
22
|
+
}
|
|
23
|
+
for (let y = 0; y < 128; y++) {
|
|
24
|
+
lcd.setPixel(0, y); // Set pixel, (x 0..239, y 0..127, on=true)
|
|
25
|
+
lcd.setPixel(239, y); // Set pixel, (x 0..239, y 0..127, on=true)
|
|
26
|
+
}
|
|
27
|
+
await lcd.show(); // Send framebuffer to the display, () → Promise<void>
|
|
28
|
+
connection.close();
|
|
29
|
+
process.exit(0);
|
|
30
|
+
})().catch((e) => { console.error(e); process.exit(1); });
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// UC8159 complete example: every Full method, Waveshare 5.65inch e-Paper (F) on a Raspberry Pi.
|
|
2
|
+
// Wiring: DIN=GPIO10, CLK=GPIO11, CS=GPIO8, DC=GPIO25, RST=GPIO17, BUSY=GPIO24. The read* calls
|
|
3
|
+
// need DOUT: spi-device has no 3-wire mode, so join DIN and DOUT through a ~1 kOhm resistor to MISO
|
|
4
|
+
// (GPIO9) and use HALF_DUPLEX_PIN. Each refresh takes about 17 s.
|
|
5
|
+
'use strict';
|
|
6
|
+
const { Default } = require('opengpio');
|
|
7
|
+
const { DisplayConnection, WireMode } = require('../../../src/connection/display');
|
|
8
|
+
const { GpioOutputPin } = require('../../../src/connection/output_pin');
|
|
9
|
+
const { PollingInputPin } = require('../../../src/connection/input_pin');
|
|
10
|
+
const { UC8159Full, BLACK, WHITE, GREEN, BLUE, RED, ORANGE } = require('../../../src/chips/display/uc8159');
|
|
11
|
+
|
|
12
|
+
const dc = new GpioOutputPin(Default.output({ chip: 0, line: 25 })); // Create D/C# pin, (chip, line=25) → OutputPin
|
|
13
|
+
const res = new GpioOutputPin(Default.output({ chip: 0, line: 17 })); // Create RES# pin, (chip, line=17) → OutputPin
|
|
14
|
+
const busyIn = Default.input({ chip: 0, line: 24 });
|
|
15
|
+
const busy = new PollingInputPin(() => (busyIn.value ? 1 : 0), 1000); // Create BUSY pin, (chip, line=24) → InputPin
|
|
16
|
+
const connection = new DisplayConnection({
|
|
17
|
+
busNumber: 0, deviceNumber: 0, maxSpeedHz: 1000000, dc, res, busy,
|
|
18
|
+
wireMode: WireMode.HALF_DUPLEX_PIN,
|
|
19
|
+
}); // Create display connection, ({busNumber, deviceNumber, maxSpeedHz, dc, res, busy, wireMode})
|
|
20
|
+
const epd = new UC8159Full(connection); // Create UC8159 driver, (connection, {busyTimeoutMs=60000})
|
|
21
|
+
// reset and the vendor init commands; panel unchanged until show()
|
|
22
|
+
|
|
23
|
+
(async () => {
|
|
24
|
+
await epd.ready();
|
|
25
|
+
epd.clear(WHITE); // Fill framebuffer, (color=WHITE)
|
|
26
|
+
// every pixel set to white
|
|
27
|
+
epd.setPixel(5, 5, BLACK); // Set one pixel, (x, y, color=BLACK)
|
|
28
|
+
// colour code 0..7
|
|
29
|
+
epd.drawRect(20, 20, 200, 120, RED, true); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
|
|
30
|
+
// filled red block
|
|
31
|
+
epd.drawRect(240, 20, 200, 120, BLUE); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
|
|
32
|
+
// blue outline
|
|
33
|
+
epd.drawLine(0, 0, 599, 447, GREEN); // Draw line, (x0, y0, x1, y1, color=BLACK)
|
|
34
|
+
// Bresenham diagonal
|
|
35
|
+
epd.blit(460, 20, [0xFF, 0x81, 0x81, 0xFF], 8, 4, ORANGE); // Copy 1-bpp bitmap, (x, y, data, w, h, color=BLACK)
|
|
36
|
+
// 8 x 4 box, MSB first
|
|
37
|
+
const colour = epd.getPixel(30, 30); // Read framebuffer pixel, (x, y) → number colour code
|
|
38
|
+
// RED here
|
|
39
|
+
await epd.setFlip(false, false); // Mirror output, (horizontal, vertical)
|
|
40
|
+
// PSR.SHL / UD at power-on values
|
|
41
|
+
await epd.setFrameRate(0x3C); // Set PLL frame rate code, (code)
|
|
42
|
+
// 50 Hz, the vendor value
|
|
43
|
+
await epd.setInterval(7, WHITE, 1); // Set VCOM/data interval, (cdi 0–15, border=WHITE, polarity=1)
|
|
44
|
+
// white border, 10 hsync
|
|
45
|
+
await epd.setTemperatureSensor(false, 0); // Select temperature sensor, (external, offset -8..7 °C)
|
|
46
|
+
// internal sensor, no offset
|
|
47
|
+
const status = await epd.readStatus(); // Read FLG, () → number bitfield
|
|
48
|
+
// needs DOUT wired (half-duplex)
|
|
49
|
+
const temperature = await epd.readTemperature(); // Read sensor, () → number °C
|
|
50
|
+
// signed internal temperature
|
|
51
|
+
await epd.show(); // Refresh panel, () → Promise<void>
|
|
52
|
+
// DTM1, PON, DRF, POF; takes about 30 s
|
|
53
|
+
const ready = await epd.waitBusy(1000); // Wait for BUSY high, (timeoutMs) → boolean
|
|
54
|
+
// true when the controller is idle
|
|
55
|
+
await epd.sendCommand(0x50, [0x37]); // Send raw command, (command, data=[])
|
|
56
|
+
// rewrites CDI with the vendor value
|
|
57
|
+
await epd.sleep(); // Enter deep sleep, () → Promise<void>
|
|
58
|
+
await epd.wake(); // Reset and re-initialise, () → Promise<void>
|
|
59
|
+
// framebuffer is kept
|
|
60
|
+
console.log({ colour, status, temperature, ready });
|
|
61
|
+
connection.close();
|
|
62
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
63
|
+
process.exit(0);
|
|
64
|
+
})().catch((e) => { console.error(e); process.exit(1); });
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// UC8159 demo: status card on a Waveshare 5.65inch e-Paper (F), Raspberry Pi (Node.js).
|
|
2
|
+
// Wiring: DIN=GPIO10, CLK=GPIO11, CS=GPIO8, DC=GPIO25, RST=GPIO17, BUSY=GPIO24.
|
|
3
|
+
// The printed refresh time is the number the spec's Timing Constraints are missing.
|
|
4
|
+
'use strict';
|
|
5
|
+
const { Default } = require('opengpio');
|
|
6
|
+
const { DisplayConnection, WireMode } = require('../../../src/connection/display');
|
|
7
|
+
const { GpioOutputPin } = require('../../../src/connection/output_pin');
|
|
8
|
+
const { PollingInputPin } = require('../../../src/connection/input_pin');
|
|
9
|
+
const { UC8159Full, BLACK, WHITE } = require('../../../src/chips/display/uc8159');
|
|
10
|
+
|
|
11
|
+
const dc = new GpioOutputPin(Default.output({ chip: 0, line: 25 })); // Create D/C# pin, (chip, line=25) → OutputPin
|
|
12
|
+
const res = new GpioOutputPin(Default.output({ chip: 0, line: 17 })); // Create RES# pin, (chip, line=17) → OutputPin
|
|
13
|
+
const busyIn = Default.input({ chip: 0, line: 24 });
|
|
14
|
+
const busy = new PollingInputPin(() => (busyIn.value ? 1 : 0), 1000); // Create BUSY pin, (chip, line=24) → InputPin
|
|
15
|
+
const connection = new DisplayConnection({ busNumber: 0, deviceNumber: 0, dc, res, busy }); // Create display connection, (busNumber, deviceNumber, dc, res, busy)
|
|
16
|
+
const epd = new UC8159Full(connection); // Create UC8159 driver, (connection, {busyTimeoutMs=60000})
|
|
17
|
+
|
|
18
|
+
(async () => {
|
|
19
|
+
await epd.ready();
|
|
20
|
+
|
|
21
|
+
// --- Compose the colour chart in the framebuffer ---
|
|
22
|
+
// White page, seven vertical bars (black, white, green, blue, red, yellow, orange) and a
|
|
23
|
+
// one-pixel black frame inset by 4 px (a frame on the very edge is hidden by the bezel).
|
|
24
|
+
epd.clear(WHITE); // Fill framebuffer, (color=WHITE)
|
|
25
|
+
for (let c = 0; c < 7; c++) {
|
|
26
|
+
epd.drawRect(20 + c * 80, 40, 80, 368, c, true); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
|
|
27
|
+
}
|
|
28
|
+
epd.drawRect(4, 4, 592, 440, BLACK); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
|
|
29
|
+
|
|
30
|
+
// --- Refresh and time it ---
|
|
31
|
+
// show() resolves after the whole DTM1/PON/DRF/POF sequence: about 30 s.
|
|
32
|
+
const start = Date.now();
|
|
33
|
+
await epd.show(); // Refresh panel, () → Promise<void>
|
|
34
|
+
console.log('refresh took', (Date.now() - start) / 1000, 's');
|
|
35
|
+
|
|
36
|
+
// --- Save the image and power down ---
|
|
37
|
+
// The panel keeps the picture without power; deep sleep stops the controller drawing current.
|
|
38
|
+
await epd.sleep(); // Enter deep sleep, () → Promise<void>
|
|
39
|
+
connection.close();
|
|
40
|
+
process.exit(0);
|
|
41
|
+
})().catch((e) => { console.error(e); process.exit(1); });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// UC8159 minimal example: Waveshare 5.65inch e-Paper (F) on a Raspberry Pi.
|
|
2
|
+
// Wiring: DIN=GPIO10 (SPI0 MOSI), CLK=GPIO11, CS=GPIO8 (CE0), DC=GPIO25, RST=GPIO17, BUSY=GPIO24.
|
|
3
|
+
'use strict';
|
|
4
|
+
const { Default } = require('opengpio');
|
|
5
|
+
const { DisplayConnection, WireMode } = require('../../../src/connection/display');
|
|
6
|
+
const { GpioOutputPin } = require('../../../src/connection/output_pin');
|
|
7
|
+
const { PollingInputPin } = require('../../../src/connection/input_pin');
|
|
8
|
+
const { UC8159Minimal, WHITE } = require('../../../src/chips/display/uc8159');
|
|
9
|
+
|
|
10
|
+
const dc = new GpioOutputPin(Default.output({ chip: 0, line: 25 })); // Create D/C# pin, (chip, line=25) → OutputPin
|
|
11
|
+
const res = new GpioOutputPin(Default.output({ chip: 0, line: 17 })); // Create RES# pin, (chip, line=17) → OutputPin
|
|
12
|
+
const busyIn = Default.input({ chip: 0, line: 24 });
|
|
13
|
+
const busy = new PollingInputPin(() => (busyIn.value ? 1 : 0), 1000); // Create BUSY pin, (chip, line=24) → InputPin
|
|
14
|
+
const connection = new DisplayConnection({ busNumber: 0, deviceNumber: 0, dc, res, busy }); // Create display connection, (busNumber, deviceNumber, dc, res, busy)
|
|
15
|
+
const epd = new UC8159Minimal(connection); // Create UC8159 driver, (connection, {busyTimeoutMs=60000})
|
|
16
|
+
|
|
17
|
+
(async () => {
|
|
18
|
+
await epd.ready();
|
|
19
|
+
epd.clear(WHITE); // Fill framebuffer, (color=WHITE)
|
|
20
|
+
for (let x = 0; x < 600; x++) {
|
|
21
|
+
const colour = Math.floor((x * 7) / 600); // seven vertical bars: black .. orange
|
|
22
|
+
for (let y = 0; y < 448; y++) epd.setPixel(x, y, colour); // Set one pixel, (x, y, color=BLACK)
|
|
23
|
+
}
|
|
24
|
+
await epd.show(); // Refresh panel (about 30 s), () → Promise<void>
|
|
25
|
+
await epd.sleep(); // Enter deep sleep, () → Promise<void>
|
|
26
|
+
connection.close();
|
|
27
|
+
process.exit(0);
|
|
28
|
+
})().catch((e) => { console.error(e); process.exit(1); });
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// UC8276C complete example: every Full method, Waveshare 4.2inch e-Paper (B) on a Raspberry Pi.
|
|
2
|
+
// Wiring: DIN=GPIO10, CLK=GPIO11, CS=GPIO8, DC=GPIO25, RST=GPIO17, BUSY=GPIO24. The read* calls
|
|
3
|
+
// need DOUT: spi-device has no 3-wire mode, so join DIN and DOUT through a ~1 kOhm resistor to MISO
|
|
4
|
+
// (GPIO9) and use HALF_DUPLEX_PIN. Each refresh takes about 17 s.
|
|
5
|
+
'use strict';
|
|
6
|
+
const { Default } = require('opengpio');
|
|
7
|
+
const { DisplayConnection, WireMode } = require('../../../src/connection/display');
|
|
8
|
+
const { GpioOutputPin } = require('../../../src/connection/output_pin');
|
|
9
|
+
const { PollingInputPin } = require('../../../src/connection/input_pin');
|
|
10
|
+
const { UC8276CFull, BLACK, WHITE, RED, MODE_KWR } = require('../../../src/chips/display/uc8276c');
|
|
11
|
+
|
|
12
|
+
const dc = new GpioOutputPin(Default.output({ chip: 0, line: 25 })); // Create D/C# pin, (chip, line=25) → OutputPin
|
|
13
|
+
const res = new GpioOutputPin(Default.output({ chip: 0, line: 17 })); // Create RES# pin, (chip, line=17) → OutputPin
|
|
14
|
+
const busyIn = Default.input({ chip: 0, line: 24 });
|
|
15
|
+
const busy = new PollingInputPin(() => (busyIn.value ? 1 : 0), 1000); // Create BUSY_N pin, (chip, line=24) → InputPin
|
|
16
|
+
const connection = new DisplayConnection({
|
|
17
|
+
busNumber: 0, deviceNumber: 0, maxSpeedHz: 1000000, dc, res, busy,
|
|
18
|
+
wireMode: WireMode.HALF_DUPLEX_PIN,
|
|
19
|
+
}); // Create display connection, ({busNumber, deviceNumber, maxSpeedHz, dc, res, busy, wireMode})
|
|
20
|
+
const epd = new UC8276CFull(connection); // Create UC8276C driver, (connection, {width=400, height=300, busyTimeoutMs=30000})
|
|
21
|
+
// reset, PSR 0x0F, CDI 0xD7; panel unchanged until show()
|
|
22
|
+
|
|
23
|
+
(async () => {
|
|
24
|
+
await epd.ready();
|
|
25
|
+
epd.clear(WHITE); // Fill framebuffer, (color=WHITE)
|
|
26
|
+
// both planes set to white
|
|
27
|
+
epd.setPixel(5, 5, BLACK); // Set one pixel, (x, y, color=BLACK)
|
|
28
|
+
// clears the B/W bit for that pixel
|
|
29
|
+
epd.drawRect(20, 20, 100, 60, RED, true); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
|
|
30
|
+
// filled red block
|
|
31
|
+
epd.drawLine(0, 0, 399, 299, BLACK); // Draw line, (x0, y0, x1, y1, color=BLACK)
|
|
32
|
+
// Bresenham diagonal
|
|
33
|
+
epd.blit(150, 20, [0xFF, 0x81, 0x81, 0xFF], 8, 4); // Copy 1-bpp bitmap, (x, y, data, w, h, color=BLACK)
|
|
34
|
+
// 8 x 4 box, MSB first
|
|
35
|
+
const colour = epd.getPixel(30, 30); // Read framebuffer pixel, (x, y) → number colour
|
|
36
|
+
// RED here
|
|
37
|
+
await epd.setMode(MODE_KWR); // Select pixel mode, (mode=MODE_KWR)
|
|
38
|
+
// PSR.KW/R cleared: black/white/red
|
|
39
|
+
await epd.setFlip(false, false); // Mirror output, (horizontal, vertical)
|
|
40
|
+
// PSR.SHL / UD at power-on values
|
|
41
|
+
await epd.setPower(10.0, 10.0, 10.0, 16.0); // Set source/gate power, (vdh V, vdl V, vdhr V, vgh=16 V)
|
|
42
|
+
// panel-layout PWR: +-10 V sources, +-16 V gates
|
|
43
|
+
await epd.setFrameRate(50); // Set frame rate, (hz 4–200)
|
|
44
|
+
// nearest PLL M/N entry (M7 N4)
|
|
45
|
+
await epd.setSoftStart(0x17, 0x17, 0x17); // Set booster soft start, (a, b, c)
|
|
46
|
+
// vendor BTST phases
|
|
47
|
+
await epd.setInterval(7); // Set VCOM/data interval, (cdi 0–15, border=3, polarity=1)
|
|
48
|
+
// keeps DDX = 01 so the framebuffer mapping holds
|
|
49
|
+
await epd.setTemperatureSensor(false, 0); // Select temperature sensor, (external, offset -8..7 °C)
|
|
50
|
+
// internal sensor, no offset
|
|
51
|
+
const status = await epd.readStatus(); // Read FLG, () → number bitfield
|
|
52
|
+
// needs DOUT wired (half-duplex)
|
|
53
|
+
const temperature = await epd.readTemperature(); // Read sensor, () → number °C
|
|
54
|
+
// signed internal temperature
|
|
55
|
+
const revision = await epd.readRevision(); // Read REV, (length=1) → [chipRev, lutRev]
|
|
56
|
+
// panel form: chipRev is null
|
|
57
|
+
await epd.show(); // Refresh panel, () → Promise<void>
|
|
58
|
+
// DTM1, DTM2, PON, DRF, POF; takes ~17 s
|
|
59
|
+
epd.drawRect(40, 100, 80, 40, BLACK, true); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
|
|
60
|
+
await epd.showRegion(40, 100, 80, 40); // Refresh a window, (x, y, w, h)
|
|
61
|
+
// sends only the window's rows (RAM saving)
|
|
62
|
+
const ready = await epd.waitBusy(1000); // Wait for BUSY_N high, (timeoutMs) → boolean
|
|
63
|
+
// true when the controller is idle
|
|
64
|
+
await epd.sendCommand(0x50, [0xD7]); // Send raw command, (command, data=[])
|
|
65
|
+
// rewrites CDI with its default
|
|
66
|
+
await epd.sleep(); // Enter deep sleep, () → Promise<void>
|
|
67
|
+
await epd.wake(); // Reset and re-initialise, () → Promise<void>
|
|
68
|
+
// framebuffer is kept
|
|
69
|
+
console.log({ colour, status, temperature, revision, ready });
|
|
70
|
+
connection.close();
|
|
71
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
72
|
+
process.exit(0);
|
|
73
|
+
})().catch((e) => { console.error(e); process.exit(1); });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// UC8276C demo: status card on a Waveshare 4.2inch e-Paper (B), Raspberry Pi (Node.js).
|
|
2
|
+
// Wiring: DIN=GPIO10, CLK=GPIO11, CS=GPIO8, DC=GPIO25, RST=GPIO17, BUSY=GPIO24.
|
|
3
|
+
// The printed refresh time is the number the spec's Timing Constraints are missing.
|
|
4
|
+
'use strict';
|
|
5
|
+
const { Default } = require('opengpio');
|
|
6
|
+
const { DisplayConnection, WireMode } = require('../../../src/connection/display');
|
|
7
|
+
const { GpioOutputPin } = require('../../../src/connection/output_pin');
|
|
8
|
+
const { PollingInputPin } = require('../../../src/connection/input_pin');
|
|
9
|
+
const { UC8276CFull, BLACK, WHITE, RED } = require('../../../src/chips/display/uc8276c');
|
|
10
|
+
|
|
11
|
+
const dc = new GpioOutputPin(Default.output({ chip: 0, line: 25 })); // Create D/C# pin, (chip, line=25) → OutputPin
|
|
12
|
+
const res = new GpioOutputPin(Default.output({ chip: 0, line: 17 })); // Create RES# pin, (chip, line=17) → OutputPin
|
|
13
|
+
const busyIn = Default.input({ chip: 0, line: 24 });
|
|
14
|
+
const busy = new PollingInputPin(() => (busyIn.value ? 1 : 0), 1000); // Create BUSY_N pin, (chip, line=24) → InputPin
|
|
15
|
+
const connection = new DisplayConnection({ busNumber: 0, deviceNumber: 0, dc, res, busy }); // Create display connection, (busNumber, deviceNumber, dc, res, busy)
|
|
16
|
+
const epd = new UC8276CFull(connection); // Create UC8276C driver, (connection, {width=400, height=300, busyTimeoutMs=30000})
|
|
17
|
+
|
|
18
|
+
(async () => {
|
|
19
|
+
await epd.ready();
|
|
20
|
+
|
|
21
|
+
// --- Compose the status card in the framebuffer ---
|
|
22
|
+
// White page, a one-pixel black border inset by 4 px (a frame on the very edge is
|
|
23
|
+
// hidden by the panel bezel) and a red header bar across the top 40 rows.
|
|
24
|
+
epd.clear(WHITE); // Fill framebuffer, (color=WHITE)
|
|
25
|
+
epd.drawRect(4, 4, 392, 292, BLACK); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
|
|
26
|
+
epd.drawRect(5, 5, 390, 40, RED, true); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
|
|
27
|
+
|
|
28
|
+
// --- Bar chart of eight readings ---
|
|
29
|
+
// Axes first, then one filled bar per value; the tallest bar is red to flag the peak.
|
|
30
|
+
const values = [30, 55, 80, 45, 120, 90, 60, 100];
|
|
31
|
+
epd.drawLine(30, 270, 370, 270, BLACK); // Draw line, (x0, y0, x1, y1, color=BLACK)
|
|
32
|
+
epd.drawLine(30, 70, 30, 270, BLACK); // Draw line, (x0, y0, x1, y1, color=BLACK)
|
|
33
|
+
const peak = Math.max(...values);
|
|
34
|
+
values.forEach((v, i) => {
|
|
35
|
+
epd.drawRect(45 + i * 40, 270 - v, 28, v, v === peak ? RED : BLACK, true); // Draw rectangle, (x, y, w, h, color=BLACK, fill=false)
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// --- Refresh and time it ---
|
|
39
|
+
// show() resolves after the whole DTM1/DTM2/PON/DRF/POF sequence.
|
|
40
|
+
const start = Date.now();
|
|
41
|
+
await epd.show(); // Refresh panel, () → Promise<void>
|
|
42
|
+
console.log('refresh took', (Date.now() - start) / 1000, 's');
|
|
43
|
+
|
|
44
|
+
// --- Save the image and power down ---
|
|
45
|
+
// The panel keeps the picture without power; deep sleep stops the controller drawing current.
|
|
46
|
+
await epd.sleep(); // Enter deep sleep, () → Promise<void>
|
|
47
|
+
connection.close();
|
|
48
|
+
process.exit(0);
|
|
49
|
+
})().catch((e) => { console.error(e); process.exit(1); });
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// UC8276C minimal example: Waveshare 4.2inch e-Paper (B) on a Raspberry Pi.
|
|
2
|
+
// Wiring: DIN=GPIO10 (SPI0 MOSI), CLK=GPIO11, CS=GPIO8 (CE0), DC=GPIO25, RST=GPIO17, BUSY=GPIO24.
|
|
3
|
+
'use strict';
|
|
4
|
+
const { Default } = require('opengpio');
|
|
5
|
+
const { DisplayConnection, WireMode } = require('../../../src/connection/display');
|
|
6
|
+
const { GpioOutputPin } = require('../../../src/connection/output_pin');
|
|
7
|
+
const { PollingInputPin } = require('../../../src/connection/input_pin');
|
|
8
|
+
const { UC8276CMinimal, BLACK, WHITE, RED } = require('../../../src/chips/display/uc8276c');
|
|
9
|
+
|
|
10
|
+
const dc = new GpioOutputPin(Default.output({ chip: 0, line: 25 })); // Create D/C# pin, (chip, line=25) → OutputPin
|
|
11
|
+
const res = new GpioOutputPin(Default.output({ chip: 0, line: 17 })); // Create RES# pin, (chip, line=17) → OutputPin
|
|
12
|
+
const busyIn = Default.input({ chip: 0, line: 24 });
|
|
13
|
+
const busy = new PollingInputPin(() => (busyIn.value ? 1 : 0), 1000); // Create BUSY_N pin, (chip, line=24) → InputPin
|
|
14
|
+
const connection = new DisplayConnection({ busNumber: 0, deviceNumber: 0, dc, res, busy }); // Create display connection, (busNumber, deviceNumber, dc, res, busy)
|
|
15
|
+
const epd = new UC8276CMinimal(connection); // Create UC8276C driver, (connection, {width=400, height=300, busyTimeoutMs=30000})
|
|
16
|
+
|
|
17
|
+
(async () => {
|
|
18
|
+
await epd.ready();
|
|
19
|
+
epd.clear(WHITE); // Fill framebuffer, (color=WHITE)
|
|
20
|
+
epd.setPixel(10, 10, BLACK); // Set one pixel, (x, y, color=BLACK)
|
|
21
|
+
for (let x = 20; x < 120; x++) epd.setPixel(x, 40, RED); // Set one pixel, (x, y, color=BLACK)
|
|
22
|
+
await epd.show(); // Refresh panel (about 17 s), () → Promise<void>
|
|
23
|
+
await epd.sleep(); // Enter deep sleep, () → Promise<void>
|
|
24
|
+
connection.close();
|
|
25
|
+
process.exit(0);
|
|
26
|
+
})().catch((e) => { console.error(e); process.exit(1); });
|
|
@@ -6,7 +6,7 @@ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
7
|
|
|
8
8
|
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
-
const bme = new BME280Full(connection); // Create BME280 driver, (connection
|
|
9
|
+
const bme = new BME280Full(connection); // Create BME280 driver, (connection)
|
|
10
10
|
|
|
11
11
|
(async () => {
|
|
12
12
|
const cid = await bme.chipId(); // Read chip ID, () → number
|
|
@@ -22,7 +22,7 @@ async function sleep(ms) {
|
|
|
22
22
|
// BME280 datasheet "weather monitoring" preset: minimum power,
|
|
23
23
|
// single-shot, 8 ms typ / 9.3 ms max per cycle. Sleep between samples
|
|
24
24
|
// to demonstrate battery-friendly indoor monitoring.
|
|
25
|
-
const bme = new BME280Full(connection); // Create BME280 driver, (connection
|
|
25
|
+
const bme = new BME280Full(connection); // Create BME280 driver, (connection)
|
|
26
26
|
await bme.configure(BME280Full.OSRS_X1, BME280Full.OSRS_X1, BME280Full.OSRS_X1, BME280Full.MODE_FORCED, BME280Full.FILTER_OFF, BME280Full.T_SB_0_5_MS); // Configure chip, (osrsT=×1, osrsP=×1, osrsH=×1, mode=forced, filter=off, tSb=0) → void
|
|
27
27
|
|
|
28
28
|
const temps = [], hums = [], pressures = [], alts = [], dews = [];
|
|
@@ -6,7 +6,7 @@ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
7
|
|
|
8
8
|
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
-
const bme = new BME280Minimal(connection); // Create BME280 driver, (connection
|
|
9
|
+
const bme = new BME280Minimal(connection); // Create BME280 driver, (connection)
|
|
10
10
|
|
|
11
11
|
(async () => {
|
|
12
12
|
for (let i = 0; i < 5; i++) {
|
|
@@ -8,7 +8,7 @@ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x68', 16);
|
|
|
8
8
|
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
9
|
|
|
10
10
|
(async () => {
|
|
11
|
-
const gyro = new L3G4200DFull(connection); // Create L3G4200D driver, (connection
|
|
11
|
+
const gyro = new L3G4200DFull(connection); // Create L3G4200D driver, (connection)
|
|
12
12
|
const cid = await gyro.whoAmI(); // Read WHO_AM_I, () → number
|
|
13
13
|
// returns 0xD3 for L3G4200D
|
|
14
14
|
await gyro.configure(1, 0, 500); // Configure chip, (odr 0–3, bandwidth 0–3, full_scale 250/500/2000) → undefined
|
|
@@ -13,7 +13,7 @@ const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
|
13
13
|
// --- Rotation detector: 200 Hz, ±500 dps, FIFO stream with watermark 10 ---
|
|
14
14
|
// 200 Hz ODR gives 5 ms per sample — fast enough to catch hand motion but
|
|
15
15
|
// not so noisy that the FIFO drains before the watermark is reached.
|
|
16
|
-
const gyro = new L3G4200DFull(connection); // Create L3G4200D driver, (connection
|
|
16
|
+
const gyro = new L3G4200DFull(connection); // Create L3G4200D driver, (connection)
|
|
17
17
|
await gyro.configure(1, 0, 500); // Configure chip, (odr=200Hz, bandwidth=0, full_scale=500) → undefined
|
|
18
18
|
await gyro.enableHighpass(0, 4); // Enable high-pass, (mode=0, cutoff=4) → undefined
|
|
19
19
|
// cutoff index 4 at 200 Hz ODR ≈ 1 Hz; strips DC drift
|
|
@@ -6,7 +6,7 @@ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x68', 16);
|
|
7
7
|
|
|
8
8
|
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
-
const gyro = new L3G4200DMinimal(connection); // Create L3G4200D driver, (connection
|
|
9
|
+
const gyro = new L3G4200DMinimal(connection); // Create L3G4200D driver, (connection)
|
|
10
10
|
|
|
11
11
|
(async () => {
|
|
12
12
|
for (let i = 0; i < 10; i++) {
|