periph 1.4.0 → 1.5.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.
- package/README.md +27 -0
- package/examples/adc_dac/ad5251/complete.js +66 -0
- package/examples/adc_dac/ad5251/demo.js +69 -0
- package/examples/adc_dac/ad5251/minimal.js +23 -0
- package/examples/adc_dac/ad5252/complete.js +66 -0
- package/examples/adc_dac/ad5252/demo.js +69 -0
- package/examples/adc_dac/ad5252/minimal.js +23 -0
- package/examples/adc_dac/ads7828/complete.js +46 -0
- package/examples/adc_dac/ads7828/demo.js +45 -0
- package/examples/adc_dac/ads7828/minimal.js +17 -0
- package/examples/adc_dac/cat5171/complete.js +52 -0
- package/examples/adc_dac/cat5171/demo.js +59 -0
- package/examples/adc_dac/cat5171/minimal.js +23 -0
- package/examples/adc_dac/cs43l22/complete.js +88 -0
- package/examples/adc_dac/cs43l22/demo.js +56 -0
- package/examples/adc_dac/cs43l22/minimal.js +20 -0
- package/examples/adc_dac/ds1881/complete.js +62 -0
- package/examples/adc_dac/ds1881/demo.js +61 -0
- package/examples/adc_dac/ds1881/minimal.js +25 -0
- package/examples/adc_dac/ds3502/complete.js +46 -0
- package/examples/adc_dac/ds3502/demo.js +54 -0
- package/examples/adc_dac/ds3502/minimal.js +28 -0
- package/examples/adc_dac/mcp3422/complete.js +48 -0
- package/examples/adc_dac/mcp3422/demo.js +49 -0
- package/examples/adc_dac/mcp3422/minimal.js +25 -0
- package/examples/display/sh1106/complete.js +101 -0
- package/examples/display/sh1106/demo.js +68 -0
- package/examples/display/sh1106/minimal.js +25 -0
- package/examples/display/ssd1305/complete.js +129 -0
- package/examples/display/ssd1305/demo.js +71 -0
- package/examples/display/ssd1305/minimal.js +25 -0
- package/examples/display/ssd1306/complete.js +115 -0
- package/examples/display/ssd1306/demo.js +70 -0
- package/examples/display/ssd1306/minimal.js +25 -0
- package/examples/environmental/am2315/complete.js +34 -0
- package/examples/environmental/am2315/demo.js +46 -0
- package/examples/environmental/am2315/minimal.js +21 -0
- package/examples/humidity/htu21df/complete.js +49 -0
- package/examples/humidity/htu21df/demo.js +50 -0
- package/examples/humidity/htu21df/minimal.js +22 -0
- package/examples/humidity/sht31/complete.js +53 -0
- package/examples/humidity/sht31/demo.js +53 -0
- package/examples/humidity/sht31/minimal.js +21 -0
- package/examples/humidity/si7021/complete.js +55 -0
- package/examples/humidity/si7021/demo.js +58 -0
- package/examples/humidity/si7021/minimal.js +21 -0
- package/examples/imu/bno055/complete.js +85 -0
- package/examples/imu/bno055/demo.js +70 -0
- package/examples/imu/bno055/minimal.js +20 -0
- package/examples/io_expander/pca6408a/complete.js +63 -0
- package/examples/io_expander/pca6408a/demo.js +58 -0
- package/examples/io_expander/pca6408a/minimal.js +20 -0
- package/examples/io_expander/pca6416a/complete.js +68 -0
- package/examples/io_expander/pca6416a/demo.js +60 -0
- package/examples/io_expander/pca6416a/minimal.js +20 -0
- package/examples/io_expander/pca9536/complete.js +63 -0
- package/examples/io_expander/pca9536/demo.js +57 -0
- package/examples/io_expander/pca9536/minimal.js +20 -0
- package/examples/io_expander/pca9539/complete.js +68 -0
- package/examples/io_expander/pca9539/demo.js +60 -0
- package/examples/io_expander/pca9539/minimal.js +20 -0
- package/examples/light/max44009/complete.js +56 -0
- package/examples/light/max44009/demo.js +49 -0
- package/examples/light/max44009/minimal.js +22 -0
- package/examples/memory/at24c02n/complete.js +39 -0
- package/examples/memory/at24c02n/demo.js +39 -0
- package/examples/memory/at24c02n/minimal.js +15 -0
- package/examples/memory/at24c64/complete.js +39 -0
- package/examples/memory/at24c64/demo.js +39 -0
- package/examples/memory/at24c64/minimal.js +15 -0
- package/examples/memory/cat24c512/complete.js +39 -0
- package/examples/memory/cat24c512/demo.js +39 -0
- package/examples/memory/cat24c512/minimal.js +15 -0
- package/examples/other/pca9541/complete.js +52 -0
- package/examples/other/pca9541/demo.js +61 -0
- package/examples/other/pca9541/minimal.js +23 -0
- package/examples/temperature/tmp102/complete.js +74 -0
- package/examples/temperature/tmp102/demo.js +71 -0
- package/examples/temperature/tmp102/minimal.js +20 -0
- package/examples/tof/vl6180x/complete.js +62 -0
- package/examples/tof/vl6180x/demo.js +77 -0
- package/examples/tof/vl6180x/minimal.js +23 -0
- package/package.json +1 -1
- package/src/chips/adc_dac/ad5251.js +345 -0
- package/src/chips/adc_dac/ad5252.js +345 -0
- package/src/chips/adc_dac/ads7828.js +225 -0
- package/src/chips/adc_dac/cat5171.js +213 -0
- package/src/chips/adc_dac/cs43l22.js +645 -0
- package/src/chips/adc_dac/ds1881.js +357 -0
- package/src/chips/adc_dac/ds3502.js +241 -0
- package/src/chips/adc_dac/mcp3422.js +312 -0
- package/src/chips/display/mono_oled.js +182 -0
- package/src/chips/display/sh1106.js +496 -0
- package/src/chips/display/ssd1305.js +655 -0
- package/src/chips/display/ssd1306.js +458 -0
- package/src/chips/environmental/am2315.js +237 -0
- package/src/chips/humidity/htu21df.js +222 -0
- package/src/chips/humidity/sht31.js +284 -0
- package/src/chips/humidity/si7021.js +282 -0
- package/src/chips/imu/bno055.js +496 -0
- package/src/chips/io_expander/pca6408a.js +407 -0
- package/src/chips/io_expander/pca6416a.js +455 -0
- package/src/chips/io_expander/pca9536.js +398 -0
- package/src/chips/io_expander/pca9539.js +457 -0
- package/src/chips/light/max44009.js +336 -0
- package/src/chips/memory/at24c02n.js +220 -0
- package/src/chips/memory/at24c64.js +220 -0
- package/src/chips/memory/cat24c512.js +221 -0
- package/src/chips/other/pca9541.js +315 -0
- package/src/chips/temperature/tmp102.js +361 -0
- package/src/chips/tof/vl6180x.js +580 -0
- package/src/discovery/registry.js +65 -13
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { MonoFramebuffer, I2cOledBus, SpiOledBus, I2C_CHUNK, SPI_CHUNK } = require('./mono_oled');
|
|
4
|
+
|
|
5
|
+
const WIDTH = 128;
|
|
6
|
+
const HEIGHT = 64;
|
|
7
|
+
|
|
8
|
+
const _CMD_ADDR_MODE = 0x20;
|
|
9
|
+
const _CMD_COL_RANGE = 0x21;
|
|
10
|
+
const _CMD_PAGE_RANGE = 0x22;
|
|
11
|
+
const _CMD_START_LINE = 0x40; // | A[5:0]
|
|
12
|
+
const _CMD_CONTRAST = 0x81;
|
|
13
|
+
const _CMD_CHARGE_PUMP = 0x8D;
|
|
14
|
+
const _CMD_SEG_REMAP = 0xA0; // | ADC
|
|
15
|
+
const _CMD_SCROLL_AREA = 0xA3;
|
|
16
|
+
const _CMD_ALL_ON = 0xA4; // | 1
|
|
17
|
+
const _CMD_INVERT = 0xA6; // | 1
|
|
18
|
+
const _CMD_MULTIPLEX = 0xA8;
|
|
19
|
+
const _CMD_DISPLAY = 0xAE; // | 1
|
|
20
|
+
const _CMD_PAGE = 0xB0; // | A[2:0]
|
|
21
|
+
const _CMD_SCAN = 0xC0; // | (scan << 3)
|
|
22
|
+
const _CMD_OFFSET = 0xD3;
|
|
23
|
+
const _CMD_CLOCK = 0xD5;
|
|
24
|
+
const _CMD_PRECHARGE = 0xD9;
|
|
25
|
+
const _CMD_COM = 0xDA;
|
|
26
|
+
const _CMD_VCOMH = 0xDB;
|
|
27
|
+
|
|
28
|
+
const sleepMs = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* SSD1306 128 x 64 OLED controller-driver — minimal interface (I²C).
|
|
32
|
+
*
|
|
33
|
+
* Drives a monochrome SSD1306 OLED panel (0.96" 128 x 64 or 128 x 32 modules) over I²C at 0x3C
|
|
34
|
+
* (SA0 = low) or 0x3D (SA0 = high). The chip has an exact 128-column RAM, so there is no column offset.
|
|
35
|
+
*
|
|
36
|
+
* All drawing goes into a framebuffer of width * height / 8 bytes (page-major, bit 0 = top pixel of
|
|
37
|
+
* the page); `show()` sends it page by page (page addressing, the reset default). The initialization
|
|
38
|
+
* follows the datasheet and the charge-pump application note: setup stream with the display off (charge
|
|
39
|
+
* pump, page addressing), RAM cleared, display on + 100 ms. With `externalVcc = false` (default) the
|
|
40
|
+
* internal charge pump makes the OLED supply VCC from VBAT. The constructor starts the initialisation;
|
|
41
|
+
* every method that talks to the chip waits for it, and `ready()` resolves (or rejects) when done.
|
|
42
|
+
*
|
|
43
|
+
* @param {object} connection - I2CConnection at 0x3C or 0x3D.
|
|
44
|
+
* @param {number} [width=128] - Visible columns, 1..128.
|
|
45
|
+
* @param {number} [height=64] - Rows, a multiple of 8, 16..64 (up to 32 uses sequential COM wiring).
|
|
46
|
+
* @param {boolean} [externalVcc=false] - True when the board supplies VCC (charge pump stays off).
|
|
47
|
+
* @param {object} [bus] - Internal: transport override used by the SPI classes.
|
|
48
|
+
*/
|
|
49
|
+
class SSD1306Minimal {
|
|
50
|
+
constructor(connection, width = 128, height = 64, externalVcc = false, bus = null) {
|
|
51
|
+
if (!(width >= 1 && width <= WIDTH)) throw new RangeError('width must be 1..128');
|
|
52
|
+
if (!(height >= 16 && height <= HEIGHT && height % 8 === 0)) throw new RangeError('height must be a multiple of 8, 16..64');
|
|
53
|
+
this._bus = bus || new I2cOledBus(connection);
|
|
54
|
+
this._canvas = new MonoFramebuffer(width, height);
|
|
55
|
+
this.width = width;
|
|
56
|
+
this.height = height;
|
|
57
|
+
this._pages = height / 8;
|
|
58
|
+
this._externalVcc = externalVcc;
|
|
59
|
+
this._adc = 0;
|
|
60
|
+
this._scan = 0;
|
|
61
|
+
this._mode = 'page';
|
|
62
|
+
this._scrolling = false;
|
|
63
|
+
this._ready = this._initSequence();
|
|
64
|
+
this._ready.catch(() => {}); // surfaced through ready() and the first awaited call
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Resolves when initialisation has finished; rejects if it failed.
|
|
69
|
+
* @returns {Promise<void>}
|
|
70
|
+
*/
|
|
71
|
+
ready() { return this._ready; }
|
|
72
|
+
|
|
73
|
+
// ---- internals -------------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
_command(...values) {
|
|
76
|
+
return this._bus.writeCommands(Buffer.from(values));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_addressBytes(page) {
|
|
80
|
+
return Buffer.from([_CMD_PAGE | (page & 7), 0x00, 0x10]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Datasheet power-on flow: reset, setup stream, RAM clear, display on. */
|
|
84
|
+
async _initSequence() {
|
|
85
|
+
await this._bus.hardwareReset();
|
|
86
|
+
await sleepMs(1);
|
|
87
|
+
await this._command(_CMD_DISPLAY,
|
|
88
|
+
_CMD_CLOCK, 0x80,
|
|
89
|
+
_CMD_MULTIPLEX, this.height - 1,
|
|
90
|
+
_CMD_OFFSET, 0x00,
|
|
91
|
+
_CMD_START_LINE,
|
|
92
|
+
_CMD_CHARGE_PUMP, this._externalVcc ? 0x10 : 0x14,
|
|
93
|
+
_CMD_ADDR_MODE, 0x02,
|
|
94
|
+
_CMD_SEG_REMAP | this._adc,
|
|
95
|
+
_CMD_SCAN | (this._scan << 3),
|
|
96
|
+
_CMD_COM, this.height > 32 ? 0x12 : 0x02,
|
|
97
|
+
_CMD_CONTRAST, 0x7F,
|
|
98
|
+
_CMD_PRECHARGE, 0x22,
|
|
99
|
+
_CMD_VCOMH, 0x20,
|
|
100
|
+
_CMD_ALL_ON,
|
|
101
|
+
_CMD_INVERT);
|
|
102
|
+
const blank = Buffer.alloc(WIDTH);
|
|
103
|
+
for (let page = 0; page < 8; page++) {
|
|
104
|
+
await this._bus.writeCommands(this._addressBytes(page));
|
|
105
|
+
await this._bus.writeData(blank);
|
|
106
|
+
}
|
|
107
|
+
await this._command(_CMD_DISPLAY | 1);
|
|
108
|
+
await sleepMs(100);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
_checkRamAccess() {
|
|
112
|
+
if (this._scrolling) throw new Error('RAM access while a scroll is active; call scrollStop() first');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async _showPage(page) {
|
|
116
|
+
await this._bus.writeCommands(this._addressBytes(page));
|
|
117
|
+
await this._bus.writeData(this._canvas.page(page));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async _showAll() {
|
|
121
|
+
this._checkRamAccess();
|
|
122
|
+
if (this._mode === 'page') {
|
|
123
|
+
for (let page = 0; page < this._pages; page++) await this._showPage(page);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
await this._command(_CMD_COL_RANGE, 0, this.width - 1, _CMD_PAGE_RANGE, 0, this._pages - 1);
|
|
127
|
+
await this._bus.writeData(this._mode === 'horizontal' ? this._canvas.data : this._canvas.transposed());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ---- public API ------------------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
/** Zero the framebuffer. Call `show()` to update the panel. */
|
|
133
|
+
clear() {
|
|
134
|
+
this._canvas.clear();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Set or clear one pixel in the framebuffer. Out-of-range coordinates are ignored.
|
|
139
|
+
* @param {number} x - Column, 0 .. width - 1.
|
|
140
|
+
* @param {number} y - Row, 0 .. height - 1.
|
|
141
|
+
* @param {boolean} [on=true] - True to set the pixel, false to clear it.
|
|
142
|
+
*/
|
|
143
|
+
setPixel(x, y, on = true) {
|
|
144
|
+
this._canvas.setPixel(x, y, on);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Write the whole framebuffer to the display RAM. Page addressing (default): per page a page +
|
|
149
|
+
* column command stream, then width data bytes. Horizontal / vertical addressing: column and
|
|
150
|
+
* page range commands, then one data stream.
|
|
151
|
+
* @returns {Promise<void>}
|
|
152
|
+
* @throws {Error} While a hardware scroll is active (call `scrollStop()` first).
|
|
153
|
+
*/
|
|
154
|
+
async show() {
|
|
155
|
+
await this._ready;
|
|
156
|
+
await this._showAll();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* SSD1306 OLED controller-driver — full interface (I²C).
|
|
162
|
+
*
|
|
163
|
+
* Extends SSD1306Minimal with drawing primitives, contrast, sleep, invert, all-on test, flip, start
|
|
164
|
+
* line, display offset, multiplex ratio, clock / oscillator, pre-charge, COM configuration, VCOMH
|
|
165
|
+
* level, charge pump, addressing mode, hardware scrolling and raw commands. The SSD1306 cannot be
|
|
166
|
+
* read over its serial interfaces.
|
|
167
|
+
*
|
|
168
|
+
* @param {object} connection - I2CConnection at 0x3C or 0x3D.
|
|
169
|
+
* @param {number} [width=128] - Visible columns, 1..128.
|
|
170
|
+
* @param {number} [height=64] - Rows, a multiple of 8, 16..64.
|
|
171
|
+
* @param {boolean} [externalVcc=false] - True when the board supplies VCC (charge pump off).
|
|
172
|
+
* @param {object} [bus] - Internal: transport override used by the SPI classes.
|
|
173
|
+
*/
|
|
174
|
+
class SSD1306Full extends SSD1306Minimal {
|
|
175
|
+
// ---- framebuffer -----------------------------------------------------------------------
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Return a framebuffer pixel; out-of-range coordinates read as false.
|
|
179
|
+
* @param {number} x - Column.
|
|
180
|
+
* @param {number} y - Row.
|
|
181
|
+
* @returns {boolean} True if the pixel is set.
|
|
182
|
+
*/
|
|
183
|
+
getPixel(x, y) { return this._canvas.getPixel(x, y); }
|
|
184
|
+
|
|
185
|
+
/** Set (or clear) the whole framebuffer. @param {boolean} [on=true] */
|
|
186
|
+
fill(on = true) { this._canvas.fill(on); }
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Draw a Bresenham line into the framebuffer.
|
|
190
|
+
* @param {number} x0 - Start column.
|
|
191
|
+
* @param {number} y0 - Start row.
|
|
192
|
+
* @param {number} x1 - End column.
|
|
193
|
+
* @param {number} y1 - End row.
|
|
194
|
+
* @param {boolean} [on=true] - True to set pixels, false to clear them.
|
|
195
|
+
*/
|
|
196
|
+
drawLine(x0, y0, x1, y1, on = true) { this._canvas.drawLine(x0, y0, x1, y1, on); }
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Draw a rectangle outline or a filled rectangle into the framebuffer.
|
|
200
|
+
* @param {number} x - Left column.
|
|
201
|
+
* @param {number} y - Top row.
|
|
202
|
+
* @param {number} w - Width in pixels.
|
|
203
|
+
* @param {number} h - Height in pixels.
|
|
204
|
+
* @param {boolean} [on=true] - True to set pixels, false to clear them.
|
|
205
|
+
* @param {boolean} [fill=false] - True for a filled rectangle.
|
|
206
|
+
*/
|
|
207
|
+
drawRect(x, y, w, h, on = true, fill = false) { this._canvas.drawRect(x, y, w, h, on, fill); }
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Copy a column-major bitmap (8 pixels per byte, bit 0 = top) into the framebuffer; y must be a multiple of 8.
|
|
211
|
+
* @param {number} x - Left column of the bitmap.
|
|
212
|
+
* @param {number} y - Top row, a multiple of 8.
|
|
213
|
+
* @param {Buffer|number[]} columns - Bitmap bytes, `heightPages` groups of columns page by page.
|
|
214
|
+
* @param {number} [heightPages=1] - Number of 8-pixel-high rows of the bitmap.
|
|
215
|
+
*/
|
|
216
|
+
blit(x, y, columns, heightPages = 1) { this._canvas.blit(x, y, columns, heightPages); }
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Write one framebuffer page to the display RAM (cheaper partial update).
|
|
220
|
+
* @param {number} page - Page 0 .. height / 8 - 1.
|
|
221
|
+
* @returns {Promise<void>}
|
|
222
|
+
* @throws {Error} While a hardware scroll is active (call `scrollStop()` first).
|
|
223
|
+
*/
|
|
224
|
+
async showPage(page) {
|
|
225
|
+
await this._ready;
|
|
226
|
+
this._checkRamAccess();
|
|
227
|
+
if (!(page >= 0 && page < this._pages)) return;
|
|
228
|
+
if (this._mode === 'page') {
|
|
229
|
+
await this._showPage(page);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
await this._command(_CMD_COL_RANGE, 0, this.width - 1, _CMD_PAGE_RANGE, page, page);
|
|
233
|
+
await this._bus.writeData(this._canvas.page(page));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// ---- display control -------------------------------------------------------------------
|
|
237
|
+
|
|
238
|
+
/** Set the segment output current (contrast). @param {number} value - 0..255 (reset 0x7F). @returns {Promise<void>} */
|
|
239
|
+
async setContrast(value) {
|
|
240
|
+
await this._ready;
|
|
241
|
+
await this._command(_CMD_CONTRAST, value & 0xFF);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Switch the display on or off (RAM and settings are kept). @param {boolean} on @returns {Promise<void>} */
|
|
245
|
+
async setDisplay(on) {
|
|
246
|
+
await this._ready;
|
|
247
|
+
await this._command(_CMD_DISPLAY | (on ? 1 : 0));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Display off (0xAE); RAM and settings are kept and stay writable. Switch VCC off afterwards. @returns {Promise<void>} */
|
|
251
|
+
sleep() { return this.setDisplay(false); }
|
|
252
|
+
|
|
253
|
+
/** Display on, then wait 100 ms (tAF) for SEG / COM to turn on. @returns {Promise<void>} */
|
|
254
|
+
async wake() {
|
|
255
|
+
await this.setDisplay(true);
|
|
256
|
+
await sleepMs(100);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Invert the displayed image without changing RAM. @param {boolean} on @returns {Promise<void>} */
|
|
260
|
+
async setInvert(on) {
|
|
261
|
+
await this._ready;
|
|
262
|
+
await this._command(_CMD_INVERT | (on ? 1 : 0));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Force all pixels on (test mode, RAM unchanged). @param {boolean} on @returns {Promise<void>} */
|
|
266
|
+
async setAllOn(on) {
|
|
267
|
+
await this._ready;
|
|
268
|
+
await this._command(_CMD_ALL_ON | (on ? 1 : 0));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Mirror columns (segment re-map) and/or rows (COM scan direction); the framebuffer is unchanged.
|
|
273
|
+
* @param {boolean} horizontal - True to reverse the segment mapping (ADC = 1).
|
|
274
|
+
* @param {boolean} vertical - True to reverse the COM scan direction (0xC8).
|
|
275
|
+
* @returns {Promise<void>}
|
|
276
|
+
*/
|
|
277
|
+
async setFlip(horizontal, vertical) {
|
|
278
|
+
await this._ready;
|
|
279
|
+
this._adc = horizontal ? 1 : 0;
|
|
280
|
+
this._scan = vertical ? 1 : 0;
|
|
281
|
+
await this._command(_CMD_SEG_REMAP | this._adc, _CMD_SCAN | (this._scan << 3));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Set the RAM line shown at COM0 (hardware vertical scroll). @param {number} line - 0..63. @returns {Promise<void>} */
|
|
285
|
+
async setStartLine(line) {
|
|
286
|
+
await this._ready;
|
|
287
|
+
await this._command(_CMD_START_LINE | (line & 0x3F));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Shift the COM mapping. @param {number} offset - 0..63. @returns {Promise<void>} */
|
|
291
|
+
async setDisplayOffset(offset) {
|
|
292
|
+
await this._ready;
|
|
293
|
+
await this._command(_CMD_OFFSET, offset & 0x3F);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Set the multiplex ratio. @param {number} ratio - 16..64. @returns {Promise<void>} */
|
|
297
|
+
async setMultiplex(ratio) {
|
|
298
|
+
await this._ready;
|
|
299
|
+
await this._command(_CMD_MULTIPLEX, (ratio - 1) & 0x3F);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Set the clock divide ratio and oscillator frequency.
|
|
304
|
+
* @param {number} divide - Divide ratio, 1..16.
|
|
305
|
+
* @param {number} osc - Oscillator setting, 0..15 (8 = reset value).
|
|
306
|
+
* @returns {Promise<void>}
|
|
307
|
+
*/
|
|
308
|
+
async setClock(divide, osc) {
|
|
309
|
+
await this._ready;
|
|
310
|
+
await this._command(_CMD_CLOCK, ((osc & 0x0F) << 4) | ((divide - 1) & 0x0F));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Set the pre-charge phase 1 and phase 2 periods in display clocks.
|
|
315
|
+
* @param {number} phase1 - 1..15.
|
|
316
|
+
* @param {number} phase2 - 1..15.
|
|
317
|
+
* @returns {Promise<void>}
|
|
318
|
+
*/
|
|
319
|
+
async setPrecharge(phase1, phase2) {
|
|
320
|
+
await this._ready;
|
|
321
|
+
await this._command(_CMD_PRECHARGE, ((phase2 & 0x0F) << 4) | (phase1 & 0x0F));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Select the COM pin configuration.
|
|
326
|
+
* @param {boolean} alternative - True alternative (reset), false sequential.
|
|
327
|
+
* @param {boolean} [remap=false] - True to enable the COM left / right remap.
|
|
328
|
+
* @returns {Promise<void>}
|
|
329
|
+
*/
|
|
330
|
+
async setComConfig(alternative, remap = false) {
|
|
331
|
+
await this._ready;
|
|
332
|
+
await this._command(_CMD_COM, 0x02 | (alternative ? 0x10 : 0) | (remap ? 0x20 : 0));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** Set the VCOMH deselect level (only bits 6:4 used). @param {number} value - 0x00..0x70 (reset 0x20). @returns {Promise<void>} */
|
|
336
|
+
async setVcomh(value) {
|
|
337
|
+
await this._ready;
|
|
338
|
+
await this._command(_CMD_VCOMH, value & 0x70);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Enable (0x14) or disable (0x10) the internal charge pump; takes effect with the display on.
|
|
343
|
+
* @param {boolean} enabled
|
|
344
|
+
* @returns {Promise<void>}
|
|
345
|
+
*/
|
|
346
|
+
async setChargePump(enabled) {
|
|
347
|
+
await this._ready;
|
|
348
|
+
await this._command(_CMD_CHARGE_PUMP, enabled ? 0x14 : 0x10);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Select how `show()` writes the display RAM.
|
|
353
|
+
* @param {'page'|'horizontal'|'vertical'} mode
|
|
354
|
+
* @returns {Promise<void>}
|
|
355
|
+
*/
|
|
356
|
+
async setAddressingMode(mode) {
|
|
357
|
+
const codes = { horizontal: 0, vertical: 1, page: 2 };
|
|
358
|
+
if (!(mode in codes)) throw new RangeError('mode must be page, horizontal or vertical');
|
|
359
|
+
await this._ready;
|
|
360
|
+
this._mode = mode;
|
|
361
|
+
await this._command(_CMD_ADDR_MODE, codes[mode]);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// ---- hardware scrolling ------------------------------------------------------------------
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Set up a continuous horizontal scroll, one column per step (start it with `scrollStart`). Do not call while scrolling.
|
|
368
|
+
* @param {boolean} right - True to scroll right.
|
|
369
|
+
* @param {number} startPage - 0..7.
|
|
370
|
+
* @param {number} endPage - startPage..7.
|
|
371
|
+
* @param {number} interval - Table index 0..7 = 5, 64, 128, 256, 3, 4, 25, 2 frames per step.
|
|
372
|
+
* @returns {Promise<void>}
|
|
373
|
+
*/
|
|
374
|
+
async setScrollHorizontal(right, startPage, endPage, interval) {
|
|
375
|
+
await this._ready;
|
|
376
|
+
await this._command(right ? 0x26 : 0x27, 0x00, startPage & 7, interval & 7, endPage & 7, 0x00, 0xFF);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Set up a continuous vertical + horizontal (diagonal) scroll (start it with `scrollStart`).
|
|
381
|
+
* @param {boolean} right - True to scroll right.
|
|
382
|
+
* @param {number} startPage - 0..7.
|
|
383
|
+
* @param {number} endPage - startPage..7.
|
|
384
|
+
* @param {number} interval - Table index 0..7.
|
|
385
|
+
* @param {number} rows - Vertical rows per step, 1..63.
|
|
386
|
+
* @returns {Promise<void>}
|
|
387
|
+
*/
|
|
388
|
+
async setScrollVertical(right, startPage, endPage, interval, rows) {
|
|
389
|
+
await this._ready;
|
|
390
|
+
await this._command(right ? 0x29 : 0x2A, 0x00, startPage & 7, interval & 7, endPage & 7, rows & 0x3F);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Set the vertical scroll area.
|
|
395
|
+
* @param {number} topFixed - Rows in the fixed top area, 0..63.
|
|
396
|
+
* @param {number} scrollRows - Rows in the scrolling area, 1..64.
|
|
397
|
+
* @returns {Promise<void>}
|
|
398
|
+
*/
|
|
399
|
+
async setScrollArea(topFixed, scrollRows) {
|
|
400
|
+
await this._ready;
|
|
401
|
+
await this._command(_CMD_SCROLL_AREA, topFixed & 0x3F, scrollRows & 0x7F);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** Activate the configured scroll (0x2F); `show()` / `showPage()` are refused until `scrollStop()`. @returns {Promise<void>} */
|
|
405
|
+
async scrollStart() {
|
|
406
|
+
await this._ready;
|
|
407
|
+
await this._command(0x2F);
|
|
408
|
+
this._scrolling = true;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** Deactivate scrolling (0x2E) and rewrite the RAM from the framebuffer, as the datasheet requires. @returns {Promise<void>} */
|
|
412
|
+
async scrollStop() {
|
|
413
|
+
await this._ready;
|
|
414
|
+
await this._command(0x2E);
|
|
415
|
+
this._scrolling = false;
|
|
416
|
+
await this._showAll();
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** Send raw bytes as one command stream. @param {...number} bytes @returns {Promise<void>} */
|
|
420
|
+
async sendCommand(...bytes) {
|
|
421
|
+
await this._ready;
|
|
422
|
+
await this._command(...bytes);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* SSD1306 over 4-wire SPI — minimal interface.
|
|
428
|
+
*
|
|
429
|
+
* Same framebuffer, drawing and initialization as SSD1306Minimal, driven through a display connection
|
|
430
|
+
* (CS, D/C, RES optional, no BUSY). The chip must be strapped for 4-wire SPI. SPI mode 0, up to 10 MHz
|
|
431
|
+
* (4 MHz recommended). Every command byte is sent with D/C low, RAM data with D/C high.
|
|
432
|
+
*
|
|
433
|
+
* @param {object} connection - DisplayConnection.
|
|
434
|
+
* @param {number} [width=128] - Visible columns, 1..128.
|
|
435
|
+
* @param {number} [height=64] - Rows, a multiple of 8, 16..64.
|
|
436
|
+
* @param {boolean} [externalVcc=false] - True when the board supplies VCC (charge pump off).
|
|
437
|
+
*/
|
|
438
|
+
class SSD1306SpiMinimal extends SSD1306Minimal {
|
|
439
|
+
constructor(connection, width = 128, height = 64, externalVcc = false) {
|
|
440
|
+
super(null, width, height, externalVcc, new SpiOledBus(connection));
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* SSD1306 over 4-wire SPI — full interface (see SSD1306Full).
|
|
446
|
+
*
|
|
447
|
+
* @param {object} connection - DisplayConnection.
|
|
448
|
+
* @param {number} [width=128] - Visible columns, 1..128.
|
|
449
|
+
* @param {number} [height=64] - Rows, a multiple of 8, 16..64.
|
|
450
|
+
* @param {boolean} [externalVcc=false] - True when the board supplies VCC (charge pump off).
|
|
451
|
+
*/
|
|
452
|
+
class SSD1306SpiFull extends SSD1306Full {
|
|
453
|
+
constructor(connection, width = 128, height = 64, externalVcc = false) {
|
|
454
|
+
super(null, width, height, externalVcc, new SpiOledBus(connection));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
module.exports = { SSD1306Minimal, SSD1306Full, SSD1306SpiMinimal, SSD1306SpiFull, WIDTH, HEIGHT, I2C_CHUNK, SPI_CHUNK };
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _FUNC_READ = 0x03;
|
|
4
|
+
const _FUNC_WRITE = 0x10;
|
|
5
|
+
const _MIN_INTERVAL_MS = 2000;
|
|
6
|
+
|
|
7
|
+
const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* CRC-16 (Modbus) used by the AM2315: init 0xFFFF, polynomial 0xA001 (reflected).
|
|
11
|
+
* @param {Buffer|number[]} data
|
|
12
|
+
* @returns {number}
|
|
13
|
+
*/
|
|
14
|
+
function crc16(data) {
|
|
15
|
+
let crc = 0xFFFF;
|
|
16
|
+
for (const byte of data) {
|
|
17
|
+
crc ^= byte;
|
|
18
|
+
for (let i = 0; i < 8; i++) crc = (crc & 1) ? (crc >> 1) ^ 0xA001 : crc >> 1;
|
|
19
|
+
}
|
|
20
|
+
return crc;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The AM2315 answered with an error response (function code with bit 7 set); `code` is 0x80-0x84. */
|
|
24
|
+
class AM2315Error extends Error {
|
|
25
|
+
constructor(code) {
|
|
26
|
+
super('AM2315 error response 0x' + code.toString(16).toUpperCase());
|
|
27
|
+
this.code = code;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function _toTemperature(raw) {
|
|
32
|
+
const t = (raw & 0x7FFF) / 10.0;
|
|
33
|
+
return (raw & 0x8000) ? -t : t;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* AM2315 humidity and temperature sensor — minimal interface.
|
|
38
|
+
*
|
|
39
|
+
* The sensor speaks a Modbus-style protocol: every read is a wake-up (a write the sensor does
|
|
40
|
+
* not acknowledge), a command write, a 2 ms wait and a read whose response carries a CRC-16.
|
|
41
|
+
* The sensor measures after each communication and returns that result on the next one, so
|
|
42
|
+
* `read()` returns the previous measurement; transactions are kept at least 2 s apart by
|
|
43
|
+
* sleeping the remainder.
|
|
44
|
+
*
|
|
45
|
+
* Default configuration: the constructor does not touch the bus; the first `read()` waits until
|
|
46
|
+
* 2 s after construction (power-up settling); one retry after a new wake on a CRC mismatch or
|
|
47
|
+
* bus error.
|
|
48
|
+
*/
|
|
49
|
+
class AM2315Minimal {
|
|
50
|
+
/**
|
|
51
|
+
* @param {import('../../connection/connection').Connection} connection - Configured I²C connection pointing at the device (address 0x5C, standard mode, at most 100 kHz).
|
|
52
|
+
*/
|
|
53
|
+
constructor(connection) {
|
|
54
|
+
this._conn = connection;
|
|
55
|
+
this._minIntervalMs = _MIN_INTERVAL_MS;
|
|
56
|
+
this._last = Date.now();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async _waitInterval() {
|
|
60
|
+
if (this._minIntervalMs <= 0) return;
|
|
61
|
+
const remaining = this._minIntervalMs - (Date.now() - this._last);
|
|
62
|
+
if (remaining > 0) await _sleep(remaining);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async _wake() {
|
|
66
|
+
try {
|
|
67
|
+
await this._conn.write(Buffer.from([0x00])); // the sleeping sensor NACKs this
|
|
68
|
+
} catch (e) { /* expected */ }
|
|
69
|
+
await _sleep(1);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async _exchange(frame, responseLen) {
|
|
73
|
+
await this._waitInterval();
|
|
74
|
+
await this._wake();
|
|
75
|
+
await this._conn.write(Buffer.from(frame));
|
|
76
|
+
await _sleep(2);
|
|
77
|
+
const data = Buffer.from(await this._conn.read(responseLen));
|
|
78
|
+
this._last = Date.now();
|
|
79
|
+
return data;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
_check(data, fn, responseLen) {
|
|
83
|
+
if (data.length >= 1 && (data[0] & 0x80)) throw new AM2315Error(data[0]);
|
|
84
|
+
if (data.length < responseLen) throw new Error('AM2315 short response');
|
|
85
|
+
if (data[0] !== fn) throw new Error('AM2315 unexpected function code');
|
|
86
|
+
const crc = data[responseLen - 2] | (data[responseLen - 1] << 8);
|
|
87
|
+
if (crc16(data.subarray(0, responseLen - 2)) !== crc) throw new Error('AM2315 CRC mismatch');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async _withRetry(fn) {
|
|
91
|
+
try {
|
|
92
|
+
return await fn();
|
|
93
|
+
} catch (e) {
|
|
94
|
+
if (e instanceof AM2315Error) throw e;
|
|
95
|
+
return await fn();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async _readRegisters(start, count) {
|
|
100
|
+
return this._withRetry(async () => {
|
|
101
|
+
const data = await this._exchange([_FUNC_READ, start, count], count + 4);
|
|
102
|
+
this._check(data, _FUNC_READ, count + 4);
|
|
103
|
+
if (data[1] !== count) throw new Error('AM2315 unexpected byte count');
|
|
104
|
+
return data.subarray(2, 2 + count);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Read temperature and humidity (registers 0x00-0x03). Returns the previous measurement;
|
|
110
|
+
* see `AM2315Full.readFresh()` for the real-time value.
|
|
111
|
+
* @returns {Promise<{temperature_c: number, humidity_pct: number}>} °C and %RH.
|
|
112
|
+
*/
|
|
113
|
+
async read() {
|
|
114
|
+
const d = await this._readRegisters(0x00, 4);
|
|
115
|
+
return { temperature_c: _toTemperature((d[2] << 8) | d[3]), humidity_pct: ((d[0] << 8) | d[1]) / 10.0 };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* AM2315 full interface — single values, raw words, fresh read, registers, user registers.
|
|
121
|
+
*
|
|
122
|
+
* Extends AM2315Minimal with temperature-only and humidity-only reads, raw words, the two-read
|
|
123
|
+
* real-time value, arbitrary register read/write (CRC verified), device information, the user
|
|
124
|
+
* registers and an explicit wake-up.
|
|
125
|
+
*/
|
|
126
|
+
class AM2315Full extends AM2315Minimal {
|
|
127
|
+
/**
|
|
128
|
+
* @param {import('../../connection/connection').Connection} connection - Configured I²C connection pointing at the device (address 0x5C).
|
|
129
|
+
*/
|
|
130
|
+
constructor(connection) {
|
|
131
|
+
super(connection);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Read the temperature only (registers 0x02-0x03).
|
|
136
|
+
* @returns {Promise<number>} °C.
|
|
137
|
+
*/
|
|
138
|
+
async readTemperature() {
|
|
139
|
+
const d = await this._readRegisters(0x02, 2);
|
|
140
|
+
return _toTemperature((d[0] << 8) | d[1]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Read the humidity only (registers 0x00-0x01).
|
|
145
|
+
* @returns {Promise<number>} %RH.
|
|
146
|
+
*/
|
|
147
|
+
async readHumidity() {
|
|
148
|
+
const d = await this._readRegisters(0x00, 2);
|
|
149
|
+
return ((d[0] << 8) | d[1]) / 10.0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Read the raw 16-bit words; the temperature word is sign + magnitude.
|
|
154
|
+
* @returns {Promise<number[]>} [rawHumidity, rawTemperature].
|
|
155
|
+
*/
|
|
156
|
+
async readRaw() {
|
|
157
|
+
const d = await this._readRegisters(0x00, 4);
|
|
158
|
+
return [(d[0] << 8) | d[1], (d[2] << 8) | d[3]];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Read twice (at least 2 s apart) and return the second, real-time result.
|
|
163
|
+
* @returns {Promise<{temperature_c: number, humidity_pct: number}>}
|
|
164
|
+
*/
|
|
165
|
+
async readFresh() {
|
|
166
|
+
await this.read();
|
|
167
|
+
return this.read();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Read `count` registers from `start` (function 0x03, CRC verified).
|
|
172
|
+
* @param {number} start - First register address (0x00-0x1F).
|
|
173
|
+
* @param {number} count - Number of registers, 1-10.
|
|
174
|
+
* @returns {Promise<Buffer>}
|
|
175
|
+
*/
|
|
176
|
+
async readRegisters(start, count) {
|
|
177
|
+
if (!(count >= 1 && count <= 10)) throw new RangeError('count must be 1-10');
|
|
178
|
+
if (!(start >= 0 && start <= 0x1F && start + count <= 0x20)) throw new RangeError('register range out of bounds');
|
|
179
|
+
return Buffer.from(await this._readRegisters(start, count));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Write the user registers 0x10-0x13 (function 0x10 with CRC).
|
|
184
|
+
* @param {number} start - First register address (0x10-0x13).
|
|
185
|
+
* @param {Buffer|number[]} data - 1-4 bytes; start + length must not pass 0x14.
|
|
186
|
+
* @returns {Promise<void>}
|
|
187
|
+
*/
|
|
188
|
+
async writeRegisters(start, data) {
|
|
189
|
+
const bytes = Buffer.from(data);
|
|
190
|
+
if (bytes.length < 1 || bytes.length > 4 || start < 0x10 || start + bytes.length > 0x14) {
|
|
191
|
+
throw new RangeError('only the user registers 0x10-0x13 may be written');
|
|
192
|
+
}
|
|
193
|
+
const body = Buffer.concat([Buffer.from([_FUNC_WRITE, start, bytes.length]), bytes]);
|
|
194
|
+
const crc = crc16(body);
|
|
195
|
+
const frame = Buffer.concat([body, Buffer.from([crc & 0xFF, crc >> 8])]);
|
|
196
|
+
await this._withRetry(async () => {
|
|
197
|
+
const resp = await this._exchange(frame, 5);
|
|
198
|
+
this._check(resp, _FUNC_WRITE, 5);
|
|
199
|
+
if (resp[1] !== start || resp[2] !== bytes.length) throw new Error('AM2315 unexpected write response');
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Read the device information (registers 0x08-0x0E).
|
|
205
|
+
* @returns {Promise<{model: number, version: number, device_id: number}>}
|
|
206
|
+
*/
|
|
207
|
+
async readDeviceInfo() {
|
|
208
|
+
const d = await this._readRegisters(0x08, 7);
|
|
209
|
+
return { model: (d[0] << 8) | d[1], version: d[2], device_id: d.readUInt32BE(3) };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Read the two 16-bit user registers (0x10-0x13).
|
|
214
|
+
* @returns {Promise<number[]>} [user1, user2].
|
|
215
|
+
*/
|
|
216
|
+
async readUserRegisters() {
|
|
217
|
+
const d = await this._readRegisters(0x10, 4);
|
|
218
|
+
return [(d[0] << 8) | d[1], (d[2] << 8) | d[3]];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Write the two 16-bit user registers (0x10-0x13).
|
|
223
|
+
* @param {number} user1 - 16-bit value for registers 0x10-0x11.
|
|
224
|
+
* @param {number} user2 - 16-bit value for registers 0x12-0x13.
|
|
225
|
+
* @returns {Promise<void>}
|
|
226
|
+
*/
|
|
227
|
+
async writeUserRegisters(user1, user2) {
|
|
228
|
+
await this.writeRegisters(0x10, [(user1 >> 8) & 0xFF, user1 & 0xFF, (user2 >> 8) & 0xFF, user2 & 0xFF]);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Wake the sensor: a dummy write (the NACK is ignored) and a 1 ms wait. */
|
|
232
|
+
async wake() {
|
|
233
|
+
await this._wake();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
module.exports = { AM2315Minimal, AM2315Full, AM2315Error, crc16 };
|