periph 1.2.1 → 1.3.0

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.
Files changed (123) hide show
  1. package/README.md +11 -0
  2. package/examples/accelerometer/bma150/complete.js +62 -0
  3. package/examples/accelerometer/bma150/demo.js +65 -0
  4. package/examples/accelerometer/bma150/minimal.js +18 -0
  5. package/examples/adc_dac/hy3131/complete.js +66 -0
  6. package/examples/adc_dac/hy3131/demo.js +37 -0
  7. package/examples/adc_dac/hy3131/minimal.js +18 -0
  8. package/examples/discovery/complete.js +25 -0
  9. package/examples/discovery/demo.js +30 -0
  10. package/examples/discovery/minimal.js +12 -0
  11. package/examples/display/il0373/complete.js +71 -0
  12. package/examples/display/il0373/demo.js +49 -0
  13. package/examples/display/il0373/minimal.js +26 -0
  14. package/examples/display/ssd1331/complete.js +83 -0
  15. package/examples/display/ssd1331/demo.js +49 -0
  16. package/examples/display/ssd1331/minimal.js +27 -0
  17. package/examples/display/st7036/complete.js +71 -0
  18. package/examples/display/st7036/demo.js +56 -0
  19. package/examples/display/st7036/minimal.js +21 -0
  20. package/examples/display/uc1611s/complete.js +135 -0
  21. package/examples/display/uc1611s/complete_spi.js +128 -0
  22. package/examples/display/uc1611s/demo.js +90 -0
  23. package/examples/display/uc1611s/demo_spi.js +91 -0
  24. package/examples/display/uc1611s/minimal.js +28 -0
  25. package/examples/display/uc1611s/minimal_spi.js +30 -0
  26. package/examples/display/uc8159/complete.js +64 -0
  27. package/examples/display/uc8159/demo.js +41 -0
  28. package/examples/display/uc8159/minimal.js +28 -0
  29. package/examples/display/uc8276c/complete.js +73 -0
  30. package/examples/display/uc8276c/demo.js +49 -0
  31. package/examples/display/uc8276c/minimal.js +26 -0
  32. package/examples/environmental/bme280/complete.js +1 -1
  33. package/examples/environmental/bme280/demo.js +1 -1
  34. package/examples/environmental/bme280/minimal.js +1 -1
  35. package/examples/gyroscope/l3g4200d/complete.js +1 -1
  36. package/examples/gyroscope/l3g4200d/demo.js +1 -1
  37. package/examples/gyroscope/l3g4200d/minimal.js +1 -1
  38. package/examples/memory/23x1024/complete.js +54 -0
  39. package/examples/memory/23x1024/demo.js +51 -0
  40. package/examples/memory/23x1024/minimal.js +22 -0
  41. package/examples/memory/mx25l12845e/complete.js +66 -0
  42. package/examples/memory/mx25l12845e/demo.js +66 -0
  43. package/examples/memory/mx25l12845e/minimal.js +27 -0
  44. package/examples/memory/sd_spi/complete.js +55 -0
  45. package/examples/memory/sd_spi/demo.js +67 -0
  46. package/examples/memory/sd_spi/minimal.js +32 -0
  47. package/examples/pressure/bmp280/complete.js +1 -1
  48. package/examples/pressure/bmp280/demo.js +1 -1
  49. package/examples/pressure/bmp280/minimal.js +1 -1
  50. package/examples/pressure/bmp581/complete.js +1 -1
  51. package/examples/pressure/bmp581/demo.js +1 -1
  52. package/examples/pressure/bmp581/minimal.js +1 -1
  53. package/examples/pressure/lps22df/complete.js +1 -1
  54. package/examples/pressure/lps22df/demo.js +1 -1
  55. package/examples/pressure/lps22df/minimal.js +1 -1
  56. package/package.json +1 -1
  57. package/src/chips/accelerometer/adxl345.js +10 -31
  58. package/src/chips/accelerometer/adxl362.js +7 -7
  59. package/src/chips/accelerometer/bma150.js +419 -0
  60. package/src/chips/adc_dac/ad7705.js +36 -9
  61. package/src/chips/adc_dac/ad7706.js +39 -9
  62. package/src/chips/adc_dac/hy3131.js +311 -0
  63. package/src/chips/display/il0373.js +607 -0
  64. package/src/chips/display/ssd1331.js +412 -0
  65. package/src/chips/display/st7036.js +401 -0
  66. package/src/chips/display/uc1611s.js +648 -0
  67. package/src/chips/display/uc8159.js +394 -0
  68. package/src/chips/display/uc8276c.js +658 -0
  69. package/src/chips/environmental/bme280.js +31 -46
  70. package/src/chips/environmental/bme680.js +38 -43
  71. package/src/chips/gas/ens160.js +18 -26
  72. package/src/chips/gyroscope/l3g4200d.js +34 -50
  73. package/src/chips/gyroscope/l3gd20h.js +24 -40
  74. package/src/chips/imu/mpu6050.js +29 -41
  75. package/src/chips/imu/mpu9250.js +42 -66
  76. package/src/chips/imu/mpu9255.js +51 -75
  77. package/src/chips/io_expander/mcp23017.js +24 -33
  78. package/src/chips/light/apds-9930.js +52 -60
  79. package/src/chips/light/apds9960.js +69 -77
  80. package/src/chips/magnetometer/as5600.js +13 -27
  81. package/src/chips/magnetometer/hmc5883l.js +32 -29
  82. package/src/chips/memory/_23x1024.js +228 -0
  83. package/src/chips/memory/_24aa02uid.js +8 -11
  84. package/src/chips/memory/mx25l12845e.js +467 -0
  85. package/src/chips/memory/sd_spi.js +486 -0
  86. package/src/chips/motor/drv8830.js +4 -4
  87. package/src/chips/other/mpr121.js +7 -7
  88. package/src/chips/power/ina219.js +5 -8
  89. package/src/chips/power/ina226.js +5 -8
  90. package/src/chips/power/ina3221.js +5 -8
  91. package/src/chips/pressure/bmp085.js +17 -11
  92. package/src/chips/pressure/bmp180.js +7 -7
  93. package/src/chips/pressure/bmp280.js +21 -33
  94. package/src/chips/pressure/bmp384.js +28 -39
  95. package/src/chips/pressure/bmp581.js +59 -70
  96. package/src/chips/pressure/lps22df.js +50 -52
  97. package/src/chips/pressure/lps28dfw.js +15 -13
  98. package/src/chips/pressure/lps33hw.js +7 -5
  99. package/src/chips/rtc/ds3231.js +8 -8
  100. package/src/chips/rtc/pcf8523.js +8 -14
  101. package/src/chips/temperature/mcp9808.js +9 -7
  102. package/src/chips/temperature/tmp117.js +4 -4
  103. package/src/connection/connection.js +6 -4
  104. package/src/connection/dhtxx.js +5 -3
  105. package/src/connection/display.js +278 -0
  106. package/src/connection/display_mock.js +77 -0
  107. package/src/connection/hx711.js +5 -3
  108. package/src/connection/i2c.js +6 -4
  109. package/src/connection/i2c_mock.js +47 -0
  110. package/src/connection/input_pin.js +36 -5
  111. package/src/connection/register.js +14 -0
  112. package/src/connection/register_connection.js +65 -0
  113. package/src/connection/sipo.js +4 -2
  114. package/src/connection/sipo_mock.js +49 -0
  115. package/src/connection/smbus.js +6 -4
  116. package/src/connection/softspi.js +73 -0
  117. package/src/connection/spi.js +110 -23
  118. package/src/connection/spi_mock.js +50 -0
  119. package/src/connection/uart.js +2 -1
  120. package/src/discovery/discovery.js +218 -0
  121. package/src/discovery/registry.js +85 -0
  122. package/src/storage/block_device.js +95 -0
  123. package/src/storage/ram_block_device.js +72 -0
@@ -0,0 +1,394 @@
1
+ 'use strict';
2
+
3
+ const BLACK = 0;
4
+ const WHITE = 1;
5
+ const GREEN = 2;
6
+ const BLUE = 3;
7
+ const RED = 4;
8
+ const YELLOW = 5;
9
+ const ORANGE = 6;
10
+ const CLEAN = 7;
11
+
12
+ const WIDTH = 600;
13
+ const HEIGHT = 448;
14
+ const FRAME_BYTES = WIDTH * HEIGHT / 2;
15
+
16
+ const _CMD_PSR = 0x00;
17
+ const _CMD_PWR = 0x01;
18
+ const _CMD_PFS = 0x03;
19
+ const _CMD_PON = 0x04;
20
+ const _CMD_POF = 0x02;
21
+ const _CMD_BTST = 0x06;
22
+ const _CMD_DSLP = 0x07;
23
+ const _CMD_DTM1 = 0x10;
24
+ const _CMD_DRF = 0x12;
25
+ const _CMD_PLL = 0x30;
26
+ const _CMD_TSC = 0x40;
27
+ const _CMD_TSE = 0x41;
28
+ const _CMD_CDI = 0x50;
29
+ const _CMD_LPD = 0x51;
30
+ const _CMD_TCON = 0x60;
31
+ const _CMD_TRES = 0x61;
32
+ const _CMD_PWS = 0xE3;
33
+ const _CMD_FLG = 0x71;
34
+ const _CMD_VV = 0x81;
35
+ const _CMD_VDCS = 0x82;
36
+
37
+ /**
38
+ * UC8159 seven-colour e-paper controller — minimal interface.
39
+ *
40
+ * Drives a 600 x 448 ACeP seven-colour electrophoretic panel such as the
41
+ * Waveshare 5.65inch e-Paper (F). The driver keeps the picture in a
42
+ * framebuffer in wire format (4 bits per pixel, 134 400 bytes) and sends it on
43
+ * show(). Every update is DTM1, PON, wait BUSY, DRF, wait BUSY, POF, wait BUSY;
44
+ * show() resolves only when the whole refresh (about 30 s) is done.
45
+ *
46
+ * The connection is a DisplayConnection (see specs/transport_display.md) that
47
+ * owns CS#, D/C#, RES# and BUSY. BUSY is active low.
48
+ *
49
+ * The constructor starts the initialisation sequence; every method waits for
50
+ * it, and `ready()` resolves (or rejects, e.g. on a BUSY timeout) when it is
51
+ * done.
52
+ *
53
+ * @param {object} connection - A DisplayConnection (SIMPLEX wiring is enough).
54
+ * @param {object} [options]
55
+ * @param {number|null} [options.busyTimeoutMs=60000] - Limit for every BUSY wait in
56
+ * milliseconds, or null for no limit.
57
+ */
58
+ class UC8159Minimal {
59
+ constructor(connection, { busyTimeoutMs = 60000 } = {}) {
60
+ this._conn = connection;
61
+ this._timeout = busyTimeoutMs;
62
+ this._fb = Buffer.alloc(FRAME_BYTES, 0x11);
63
+ this._psr = 0xEF;
64
+ this._cdi = 0x37;
65
+ this._asleep = false;
66
+ this._ready = this._initSequence();
67
+ this._ready.catch(() => {}); // surfaced through ready() and the first awaited call
68
+ }
69
+
70
+ /** @returns {number} Panel width in pixels (600). */
71
+ get width() { return WIDTH; }
72
+
73
+ /** @returns {number} Panel height in pixels (448). */
74
+ get height() { return HEIGHT; }
75
+
76
+ /**
77
+ * Resolves when initialisation has finished; rejects if it failed.
78
+ * @returns {Promise<void>}
79
+ */
80
+ ready() { return this._ready; }
81
+
82
+ /**
83
+ * Fill the framebuffer with one colour. The panel is unchanged until show().
84
+ * @param {number} [color=WHITE] - Colour code 0..7.
85
+ */
86
+ clear(color = WHITE) {
87
+ const c = color & 7;
88
+ this._fb.fill((c << 4) | c);
89
+ }
90
+
91
+ /**
92
+ * Set one pixel in the framebuffer. Out-of-range coordinates are ignored.
93
+ * @param {number} x - Column, 0 <= x < 600.
94
+ * @param {number} y - Row, 0 <= y < 448.
95
+ * @param {number} [color=BLACK] - Colour code 0..7.
96
+ */
97
+ setPixel(x, y, color = BLACK) {
98
+ if (x < 0 || y < 0 || x >= WIDTH || y >= HEIGHT) return;
99
+ const i = (y * WIDTH + x) >> 1;
100
+ const c = color & 7;
101
+ if (x & 1) this._fb[i] = (this._fb[i] & 0xF0) | c;
102
+ else this._fb[i] = (this._fb[i] & 0x0F) | (c << 4);
103
+ }
104
+
105
+ /**
106
+ * Send the frame and run a full display update (about 30 s): DTM1 + 134 400
107
+ * bytes, PON, wait BUSY, DRF, wait BUSY, POF, wait BUSY. A sleeping
108
+ * controller is woken (hardware reset + initialisation) first.
109
+ * @returns {Promise<void>}
110
+ * @throws {Error} If a BUSY wait exceeds busyTimeoutMs.
111
+ */
112
+ async show() {
113
+ await this._ready;
114
+ if (this._asleep) await this._wake();
115
+ await this._conn.sendCommand(_CMD_DTM1);
116
+ for (let off = 0; off < FRAME_BYTES; off += 4096) {
117
+ await this._conn.sendData(this._fb.subarray(off, Math.min(off + 4096, FRAME_BYTES)));
118
+ }
119
+ await this._conn.sendCommand(_CMD_PON);
120
+ await this._waitReady();
121
+ await this._conn.sendCommand(_CMD_DRF);
122
+ await this._waitReady();
123
+ await this._conn.sendCommand(_CMD_POF);
124
+ await this._waitReady();
125
+ }
126
+
127
+ /**
128
+ * Put the controller into deep sleep (DSLP with check code 0xA5).
129
+ * Only a hardware reset restores communication; show() and Full.wake() do
130
+ * that. The panel keeps its image.
131
+ * @returns {Promise<void>}
132
+ */
133
+ async sleep() {
134
+ await this._ready;
135
+ await this._conn.sendCommand(_CMD_DSLP, [0xA5]);
136
+ this._asleep = true;
137
+ }
138
+
139
+ async _waitReady(timeoutMs = this._timeout) {
140
+ if (!(await this._conn.waitBusy(false, timeoutMs))) {
141
+ throw new Error(`UC8159: BUSY did not go high within ${timeoutMs} ms`);
142
+ }
143
+ }
144
+
145
+ async _initSequence() {
146
+ if (typeof this._conn.ready === 'function') await this._conn.ready();
147
+ const c = this._conn;
148
+ // The vendor demo's initialisation commands (sigrok/tests/uc8159).
149
+ await c.reset();
150
+ await this._waitReady();
151
+ await c.sendCommand(_CMD_PSR, [this._psr, 0x08]);
152
+ await c.sendCommand(_CMD_PWR, [0x37, 0x00, 0x23, 0x23]);
153
+ await c.sendCommand(_CMD_PFS, [0x00]);
154
+ await c.sendCommand(_CMD_BTST, [0xC7, 0xC7, 0x1D]);
155
+ await c.sendCommand(_CMD_PLL, [0x3C]);
156
+ await c.sendCommand(_CMD_TSE, [0x00]);
157
+ await c.sendCommand(_CMD_CDI, [this._cdi]);
158
+ await c.sendCommand(_CMD_TCON, [0x22]);
159
+ await c.sendCommand(_CMD_TRES, [0x02, 0x58, 0x01, 0xC0]); // 600 x 448
160
+ await c.sendCommand(_CMD_PWS, [0xAA]);
161
+ }
162
+
163
+ async _wake() {
164
+ this._asleep = false;
165
+ await this._initSequence();
166
+ }
167
+ }
168
+
169
+ /**
170
+ * UC8159 seven-colour e-paper controller — full interface.
171
+ *
172
+ * Extends UC8159Minimal with drawing helpers, scan direction, frame rate,
173
+ * border/data interval, temperature-sensor source, VCOM_DC and the read
174
+ * commands (status, temperature, low power, VCOM). The read* methods need a
175
+ * half-duplex wire mode; with a SIMPLEX connection they reject.
176
+ */
177
+ class UC8159Full extends UC8159Minimal {
178
+ /**
179
+ * Colour code (0..7) of one framebuffer pixel.
180
+ * @param {number} x - Column.
181
+ * @param {number} y - Row.
182
+ * @returns {number} Colour code (BLACK when out of range).
183
+ */
184
+ getPixel(x, y) {
185
+ if (x < 0 || y < 0 || x >= WIDTH || y >= HEIGHT) return BLACK;
186
+ const b = this._fb[(y * WIDTH + x) >> 1];
187
+ return (x & 1) ? (b & 7) : ((b >> 4) & 7);
188
+ }
189
+
190
+ /**
191
+ * Bresenham line into the framebuffer.
192
+ * @param {number} x0 - Start column.
193
+ * @param {number} y0 - Start row.
194
+ * @param {number} x1 - End column.
195
+ * @param {number} y1 - End row.
196
+ * @param {number} [color=BLACK] - Colour code 0..7.
197
+ */
198
+ drawLine(x0, y0, x1, y1, color = BLACK) {
199
+ const dx = Math.abs(x1 - x0);
200
+ const dy = -Math.abs(y1 - y0);
201
+ const sx = x0 < x1 ? 1 : -1;
202
+ const sy = y0 < y1 ? 1 : -1;
203
+ let err = dx + dy;
204
+ for (;;) {
205
+ this.setPixel(x0, y0, color);
206
+ if (x0 === x1 && y0 === y1) break;
207
+ const e2 = 2 * err;
208
+ if (e2 >= dy) { err += dy; x0 += sx; }
209
+ if (e2 <= dx) { err += dx; y0 += sy; }
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Rectangle outline or filled rectangle into the framebuffer.
215
+ * @param {number} x - Left column.
216
+ * @param {number} y - Top row.
217
+ * @param {number} w - Width in pixels.
218
+ * @param {number} h - Height in pixels.
219
+ * @param {number} [color=BLACK] - Colour code 0..7.
220
+ * @param {boolean} [fill=false] - true fills the rectangle.
221
+ */
222
+ drawRect(x, y, w, h, color = BLACK, fill = false) {
223
+ if (w <= 0 || h <= 0) return;
224
+ if (fill) {
225
+ for (let j = 0; j < h; j++) {
226
+ for (let i = 0; i < w; i++) this.setPixel(x + i, y + j, color);
227
+ }
228
+ return;
229
+ }
230
+ this.drawLine(x, y, x + w - 1, y, color);
231
+ this.drawLine(x, y + h - 1, x + w - 1, y + h - 1, color);
232
+ this.drawLine(x, y, x, y + h - 1, color);
233
+ this.drawLine(x + w - 1, y, x + w - 1, y + h - 1, color);
234
+ }
235
+
236
+ /**
237
+ * Copy a 1-bit-per-pixel bitmap into the framebuffer. Row-major, MSB-first,
238
+ * rows padded to whole bytes. Set bits are drawn in color, clear bits leave
239
+ * the framebuffer unchanged.
240
+ * @param {number} x - Left column.
241
+ * @param {number} y - Top row.
242
+ * @param {Buffer|Uint8Array|number[]} data - Bitmap bytes.
243
+ * @param {number} w - Bitmap width in pixels.
244
+ * @param {number} h - Bitmap height in pixels.
245
+ * @param {number} [color=BLACK] - Colour code 0..7.
246
+ */
247
+ blit(x, y, data, w, h, color = BLACK) {
248
+ if (w <= 0 || h <= 0) return;
249
+ const rowBytes = Math.ceil(w / 8);
250
+ for (let j = 0; j < h; j++) {
251
+ for (let i = 0; i < w; i++) {
252
+ if (data[j * rowBytes + (i >> 3)] & (0x80 >> (i & 7))) this.setPixel(x + i, y + j, color);
253
+ }
254
+ }
255
+ }
256
+
257
+ /**
258
+ * Hardware reset and initialisation (exit from deep sleep). The framebuffer is kept.
259
+ * @returns {Promise<void>}
260
+ */
261
+ async wake() {
262
+ await this._ready;
263
+ await this._wake();
264
+ }
265
+
266
+ /**
267
+ * Wait for BUSY to go high.
268
+ * @param {number|null} [timeoutMs] - Limit in milliseconds, null for no limit;
269
+ * the constructor's busyTimeoutMs when omitted.
270
+ * @returns {Promise<boolean>} true when ready, false on timeout.
271
+ */
272
+ async waitBusy(timeoutMs = this._timeout) {
273
+ await this._ready;
274
+ return this._conn.waitBusy(false, timeoutMs);
275
+ }
276
+
277
+ /**
278
+ * Mirror the picture: horizontal clears SHL, vertical clears UD. The
279
+ * framebuffer is unchanged.
280
+ * @param {boolean} horizontal - Mirror left/right.
281
+ * @param {boolean} vertical - Mirror top/bottom.
282
+ * @returns {Promise<void>}
283
+ */
284
+ async setFlip(horizontal, vertical) {
285
+ if (horizontal) this._psr &= ~0x04 & 0xFF;
286
+ else this._psr |= 0x04;
287
+ if (vertical) this._psr &= ~0x08 & 0xFF;
288
+ else this._psr |= 0x08;
289
+ await this._ready;
290
+ await this._conn.sendCommand(_CMD_PSR, [this._psr, 0x08]);
291
+ }
292
+
293
+ /**
294
+ * Frame rate (PLL raw code): 0x3C = 50 Hz (default), 0x3A = 100 Hz,
295
+ * 0x39 = 200 Hz, 0x00..0x0F = 12.5 .. 200 Hz.
296
+ * @param {number} code - PLL code.
297
+ * @returns {Promise<void>}
298
+ */
299
+ async setFrameRate(code) {
300
+ await this._ready;
301
+ await this._conn.sendCommand(_CMD_PLL, [code & 0xFF]);
302
+ }
303
+
304
+ /**
305
+ * VCOM and data interval (CDI).
306
+ * @param {number} cdi - Interval, 0..15 (0b0111 = 10 hsync).
307
+ * @param {number} [border=WHITE] - Border colour code 0..7.
308
+ * @param {number} [polarity=1] - DDX, 1 = default (the colour codes assume 1).
309
+ * @returns {Promise<void>}
310
+ */
311
+ async setInterval(cdi, border = WHITE, polarity = 1) {
312
+ this._cdi = ((border & 7) << 5) | ((polarity & 1) << 4) | (cdi & 0x0F);
313
+ await this._ready;
314
+ await this._conn.sendCommand(_CMD_CDI, [this._cdi]);
315
+ }
316
+
317
+ /**
318
+ * Temperature sensor source (TSE): internal (default) or external LM75.
319
+ * @param {boolean} external - true selects the external sensor.
320
+ * @param {number} [offset=0] - Temperature offset, -8..+7 degrees Celsius.
321
+ * @returns {Promise<void>}
322
+ */
323
+ async setTemperatureSensor(external, offset = 0) {
324
+ await this._ready;
325
+ await this._conn.sendCommand(_CMD_TSE, [(external ? 0x80 : 0x00) | (offset & 0x0F)]);
326
+ }
327
+
328
+ /**
329
+ * VCOM_DC (VDCS): -0.10 .. -4.0 V in 0.05 V steps.
330
+ * @param {number} volts - VCOM voltage.
331
+ * @returns {Promise<void>}
332
+ */
333
+ async setVcomDc(volts) {
334
+ const code = Math.max(2, Math.min(0x50, Math.floor((-0.10 - volts) / 0.05 + 2.5)));
335
+ await this._ready;
336
+ await this._conn.sendCommand(_CMD_VDCS, [code]);
337
+ }
338
+
339
+ /**
340
+ * Send a raw command and parameters (escape hatch).
341
+ * @param {number} command - Command byte.
342
+ * @param {Buffer|number[]} [data=[]] - Parameter bytes.
343
+ * @returns {Promise<void>}
344
+ */
345
+ async sendCommand(command, data = []) {
346
+ await this._ready;
347
+ await this._conn.sendCommand(command, data);
348
+ }
349
+
350
+ /**
351
+ * Read FLG: bit 5 I2C_ERR, 4 I2C_BUSYN, 3 data_flag, 2 PON, 1 POF, 0 BUSY_N.
352
+ * @returns {Promise<number>} The status byte.
353
+ */
354
+ async readStatus() {
355
+ return (await this._read(_CMD_FLG, 1))[0];
356
+ }
357
+
358
+ /**
359
+ * Read the internal temperature sensor (TSC).
360
+ * @returns {Promise<number>} Signed degrees Celsius.
361
+ */
362
+ async readTemperature() {
363
+ const v = (await this._read(_CMD_TSC, 2))[0];
364
+ return v > 127 ? v - 256 : v;
365
+ }
366
+
367
+ /**
368
+ * Read low-power detection (LPD).
369
+ * @returns {Promise<boolean>} true when VDD is below 2.5 V.
370
+ */
371
+ async readLowPower() {
372
+ return ((await this._read(_CMD_LPD, 1))[0] & 1) === 0;
373
+ }
374
+
375
+ /**
376
+ * Read the measured VCOM (VV).
377
+ * @returns {Promise<number>} Volts, -0.10 V - 0.05 V x (VV - 2).
378
+ */
379
+ async readVcom() {
380
+ const c = (await this._read(_CMD_VV, 1))[0] & 0x7F;
381
+ return -0.10 - 0.05 * (c > 2 ? c - 2 : 0);
382
+ }
383
+
384
+ async _read(cmd, length) {
385
+ await this._ready;
386
+ await this._conn.sendCommand(cmd);
387
+ return this._conn.readData(length);
388
+ }
389
+ }
390
+
391
+ module.exports = {
392
+ UC8159Minimal, UC8159Full,
393
+ BLACK, WHITE, GREEN, BLUE, RED, YELLOW, ORANGE, CLEAN, WIDTH, HEIGHT,
394
+ };