periph 1.0.0 → 1.1.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 +49 -0
- package/examples/adc_dac/hx711/complete.js +42 -0
- package/examples/adc_dac/hx711/demo.js +35 -0
- package/examples/adc_dac/hx711/minimal.js +16 -0
- package/examples/adc_dac/mcp4728/complete.js +41 -0
- package/examples/adc_dac/mcp4728/demo.js +41 -0
- package/examples/adc_dac/mcp4728/minimal.js +11 -0
- package/examples/display/pcf8576/complete.js +32 -0
- package/examples/display/pcf8576/demo.js +48 -0
- package/examples/display/pcf8576/minimal.js +18 -0
- package/examples/environmental/aht21/complete.js +30 -0
- package/examples/environmental/aht21/demo.js +44 -0
- package/examples/environmental/aht21/minimal.js +12 -0
- package/examples/environmental/bme280/complete.js +34 -0
- package/examples/environmental/bme280/demo.js +67 -0
- package/examples/environmental/bme280/minimal.js +18 -0
- package/examples/environmental/bme680/complete.js +37 -0
- package/examples/environmental/bme680/demo.js +52 -0
- package/examples/environmental/bme680/minimal.js +19 -0
- package/examples/gas/ens160/complete.js +52 -0
- package/examples/gas/ens160/demo.js +52 -0
- package/examples/gas/ens160/minimal.js +27 -0
- package/examples/imu/mpu6050/complete.js +56 -0
- package/examples/imu/mpu6050/demo.js +34 -0
- package/examples/imu/mpu6050/minimal.js +14 -0
- package/examples/light/apds9960/complete.js +62 -0
- package/examples/light/apds9960/demo.js +32 -0
- package/examples/light/apds9960/minimal.js +12 -0
- package/examples/memory/24aa02uid/complete.js +40 -0
- package/examples/memory/24aa02uid/demo.js +40 -0
- package/examples/memory/24aa02uid/minimal.js +12 -0
- package/examples/pressure/bmp280/complete.js +22 -18
- package/examples/pressure/bmp280/demo.js +34 -18
- package/examples/pressure/bmp280/minimal.js +4 -4
- package/package.json +1 -1
- package/src/chips/adc_dac/hx711.js +165 -0
- package/src/chips/adc_dac/mcp4728.js +284 -0
- package/src/chips/display/pcf8576.js +223 -0
- package/src/chips/environmental/aht21.js +170 -0
- package/src/chips/environmental/bme280.js +366 -0
- package/src/chips/environmental/bme680.js +489 -0
- package/src/chips/gas/ens160.js +280 -0
- package/src/chips/imu/mpu6050.js +266 -0
- package/src/chips/light/apds9960.js +464 -0
- package/src/chips/memory/_24aa02uid.js +179 -0
- package/src/chips/pressure/bmp280.js +154 -191
- package/src/transport/hx711.js +105 -0
- package/examples/display/.gitkeep +0 -0
- package/examples/environmental/.gitkeep +0 -0
- package/examples/imu/.gitkeep +0 -0
- package/examples/light/.gitkeep +0 -0
- package/examples/pressure/.gitkeep +0 -0
- package/src/chips/display/.gitkeep +0 -0
- package/src/chips/environmental/.gitkeep +0 -0
- package/src/chips/imu/.gitkeep +0 -0
- package/src/chips/light/.gitkeep +0 -0
- package/src/chips/pressure/.gitkeep +0 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ADDR_SA0_LOW = 0x38;
|
|
4
|
+
const _ADDR_SA0_HIGH = 0x39;
|
|
5
|
+
|
|
6
|
+
const _CMD_MODE_SET = 0x40;
|
|
7
|
+
const _CMD_LOAD_PTR = 0x00;
|
|
8
|
+
const _CMD_DEVICE_SELECT = 0x60;
|
|
9
|
+
const _CMD_BANK_SELECT = 0x78;
|
|
10
|
+
const _CMD_BLINK_SELECT = 0x70;
|
|
11
|
+
|
|
12
|
+
const _MODE_1_4 = 0x00;
|
|
13
|
+
const _MODE_STATIC = 0x01;
|
|
14
|
+
const _MODE_1_2 = 0x02;
|
|
15
|
+
const _MODE_1_3 = 0x03;
|
|
16
|
+
|
|
17
|
+
const _BIAS_1_3 = 0x00;
|
|
18
|
+
const _BIAS_1_2 = 0x04;
|
|
19
|
+
|
|
20
|
+
const _DISPLAY_OFF = 0x00;
|
|
21
|
+
const _DISPLAY_ON = 0x08;
|
|
22
|
+
|
|
23
|
+
const _SEVEN_SEG = [
|
|
24
|
+
0xED, 0x60, 0xA7, 0xE3, 0x6A,
|
|
25
|
+
0xCB, 0xCF, 0xE0, 0xEF, 0xEB,
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* PCF8576 40x4 universal LCD segment driver — minimal interface.
|
|
30
|
+
*
|
|
31
|
+
* Drives a single 7-segment LCD display (static or 1:4 multiplex) out of
|
|
32
|
+
* the box. The chip is write-only — the host never reads back. I2C address
|
|
33
|
+
* is 0x38 (SA0 = VSS) or 0x39 (SA0 = VDD).
|
|
34
|
+
*
|
|
35
|
+
* Default: 1:4 multiplex drive mode, 1/3 bias, display enabled, and a
|
|
36
|
+
* 7-segment digit lookup table for the default multiplex mode.
|
|
37
|
+
*
|
|
38
|
+
* @param {object} transport - Configured I2C transport pointing at the device.
|
|
39
|
+
*/
|
|
40
|
+
class PCF8576Minimal {
|
|
41
|
+
constructor(transport) {
|
|
42
|
+
this._transport = transport;
|
|
43
|
+
this._backplanes = 4;
|
|
44
|
+
this._clear();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
_cmdMode(enable, bias, mode) {
|
|
48
|
+
return _CMD_MODE_SET | (enable ? _DISPLAY_ON : _DISPLAY_OFF) | bias | mode;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_sendCommands(cmds) {
|
|
52
|
+
const out = [];
|
|
53
|
+
for (let i = 0; i < cmds.length - 1; i++) {
|
|
54
|
+
out.push(0x80 | (cmds[i] & 0x7F));
|
|
55
|
+
}
|
|
56
|
+
out.push(cmds[cmds.length - 1] & 0x7F);
|
|
57
|
+
this._transport.write(Buffer.from(out));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
_sendCommandsWithData(cmd, data) {
|
|
61
|
+
const out = [cmd & 0x7F, ...data];
|
|
62
|
+
this._transport.write(Buffer.from(out));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
_clear() {
|
|
66
|
+
this._sendCommands([this._cmdMode(true, _BIAS_1_3, _MODE_1_4)]);
|
|
67
|
+
const zeros = new Array(20).fill(0);
|
|
68
|
+
this._sendCommandsWithData(_CMD_LOAD_PTR, zeros);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Zero all 40 columns of display RAM; all segments off.
|
|
73
|
+
*/
|
|
74
|
+
clear() {
|
|
75
|
+
this._clear();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Set the data pointer to {@param address} and write raw data bytes.
|
|
80
|
+
*
|
|
81
|
+
* @param {number} address - RAM column address, 0-39.
|
|
82
|
+
* @param {Buffer|Uint8Array|number[]} data - Bytes to write to display RAM.
|
|
83
|
+
*/
|
|
84
|
+
writeRaw(address, data) {
|
|
85
|
+
if (address < 0 || address > 39) {
|
|
86
|
+
throw new RangeError('address must be in 0..39');
|
|
87
|
+
}
|
|
88
|
+
if (!data || data.length === 0) return;
|
|
89
|
+
this._sendCommandsWithData(_CMD_LOAD_PTR | (address & 0x3F), Array.from(data));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Write one 7-segment byte at column {@param position} * 2.
|
|
94
|
+
*
|
|
95
|
+
* @param {number} position - Digit index, 0-19. Maps to RAM address position * 2.
|
|
96
|
+
* @param {number} segments - 7-segment byte (a/c/b/DP/f/e/g/d packed, MSB-first).
|
|
97
|
+
* Add 0x10 to set the decimal point.
|
|
98
|
+
*/
|
|
99
|
+
setDigit7seg(position, segments) {
|
|
100
|
+
if (position < 0 || position > 19) {
|
|
101
|
+
throw new RangeError('position must be in 0..19');
|
|
102
|
+
}
|
|
103
|
+
this.writeRaw(position * 2, [segments & 0xFF]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* PCF8576 full interface — extends PCF8576Minimal with drive mode, bias, and blink control.
|
|
109
|
+
*
|
|
110
|
+
* Adds the ability to switch drive modes (static, 1:2, 1:3, 1:4 multiplex),
|
|
111
|
+
* change bias (1:2 or 1/3), configure blinking, select RAM banks for
|
|
112
|
+
* static and 1:2 multiplex use, and change the device subaddress counter
|
|
113
|
+
* for cascaded displays.
|
|
114
|
+
*
|
|
115
|
+
* @param {object} transport - Configured I2C transport pointing at the device.
|
|
116
|
+
*/
|
|
117
|
+
class PCF8576Full extends PCF8576Minimal {
|
|
118
|
+
static BLINK_OFF = 0;
|
|
119
|
+
static BLINK_2_HZ = 1;
|
|
120
|
+
static BLINK_1_HZ = 2;
|
|
121
|
+
static BLINK_0_5_HZ = 3;
|
|
122
|
+
|
|
123
|
+
static BIAS_1_3 = 0;
|
|
124
|
+
static BIAS_1_2 = 1;
|
|
125
|
+
|
|
126
|
+
static BACKPLANES_1 = 1;
|
|
127
|
+
static BACKPLANES_2 = 2;
|
|
128
|
+
static BACKPLANES_3 = 3;
|
|
129
|
+
static BACKPLANES_4 = 4;
|
|
130
|
+
|
|
131
|
+
static BANK_0 = 0;
|
|
132
|
+
static BANK_1 = 1;
|
|
133
|
+
|
|
134
|
+
constructor(transport) {
|
|
135
|
+
super(transport);
|
|
136
|
+
this._enabled = true;
|
|
137
|
+
this._bias = PCF8576Full.BIAS_1_3;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
_modeCode(backplanes) {
|
|
141
|
+
switch (backplanes) {
|
|
142
|
+
case PCF8576Full.BACKPLANES_1: return _MODE_STATIC;
|
|
143
|
+
case PCF8576Full.BACKPLANES_2: return _MODE_1_2;
|
|
144
|
+
case PCF8576Full.BACKPLANES_3: return _MODE_1_3;
|
|
145
|
+
case PCF8576Full.BACKPLANES_4: return _MODE_1_4;
|
|
146
|
+
default: return _MODE_1_4;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
_applyMode() {
|
|
151
|
+
const biasBits = (this._bias === PCF8576Full.BIAS_1_2) ? _BIAS_1_2 : _BIAS_1_3;
|
|
152
|
+
this._sendCommands([this._cmdMode(this._enabled, biasBits, this._modeCode(this._backplanes))]);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Turn the display on (E = 1). RAM contents are preserved.
|
|
157
|
+
*/
|
|
158
|
+
enable() {
|
|
159
|
+
this._enabled = true;
|
|
160
|
+
this._applyMode();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Blank the display output (E = 0). RAM contents are preserved.
|
|
165
|
+
*/
|
|
166
|
+
disable() {
|
|
167
|
+
this._enabled = false;
|
|
168
|
+
this._applyMode();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Reconfigure drive mode and bias at runtime.
|
|
173
|
+
*
|
|
174
|
+
* @param {number} backplanes - Number of backplanes: 1 (static), 2 (1:2), 3 (1:3), 4 (1:4).
|
|
175
|
+
* @param {number} [bias=0] - 0 = 1/3 bias, 1 = 1/2 bias.
|
|
176
|
+
*/
|
|
177
|
+
setMode(backplanes, bias = 0) {
|
|
178
|
+
this._backplanes = backplanes;
|
|
179
|
+
this._bias = bias;
|
|
180
|
+
this._applyMode();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Set the blink frequency.
|
|
185
|
+
*
|
|
186
|
+
* @param {number} frequency - 0 = off, 1 = ~2 Hz, 2 = ~1 Hz, 3 = ~0.5 Hz.
|
|
187
|
+
* @param {boolean} [alternateBank=false] - Alternate-RAM-bank blinking (static/1:2 only).
|
|
188
|
+
*/
|
|
189
|
+
setBlink(frequency, alternateBank = false) {
|
|
190
|
+
if (frequency < 0 || frequency > 3) {
|
|
191
|
+
throw new RangeError('frequency must be in 0..3');
|
|
192
|
+
}
|
|
193
|
+
const ab = alternateBank ? 0x04 : 0x00;
|
|
194
|
+
this._sendCommands([_CMD_BLINK_SELECT | ab | (frequency & 0x03)]);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Select the active RAM bank.
|
|
199
|
+
*
|
|
200
|
+
* @param {number} inputBank - 0 (rows 0-1) or 1 (rows 2-3).
|
|
201
|
+
* @param {number} outputBank - 0 (rows 0-1) or 1 (rows 2-3).
|
|
202
|
+
*/
|
|
203
|
+
setBank(inputBank, outputBank) {
|
|
204
|
+
this._sendCommands([_CMD_BANK_SELECT | ((inputBank & 1) << 1) | (outputBank & 1)]);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Change the subaddress counter for cascaded displays.
|
|
209
|
+
*
|
|
210
|
+
* @param {number} subaddress - 0-7; must match the A0/A1/A2 pin state.
|
|
211
|
+
*/
|
|
212
|
+
deviceSelect(subaddress) {
|
|
213
|
+
if (subaddress < 0 || subaddress > 7) {
|
|
214
|
+
throw new RangeError('subaddress must be in 0..7');
|
|
215
|
+
}
|
|
216
|
+
this._sendCommands([_CMD_DEVICE_SELECT | (subaddress & 0x07)]);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
PCF8576Minimal.SEVEN_SEG = _SEVEN_SEG;
|
|
221
|
+
PCF8576Full.SEVEN_SEG = _SEVEN_SEG;
|
|
222
|
+
|
|
223
|
+
module.exports = { PCF8576Minimal, PCF8576Full };
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _CMD_TRIGGER = Buffer.from([0xAC, 0x33, 0x00]);
|
|
4
|
+
const _CMD_SOFT_RESET = Buffer.from([0xBA]);
|
|
5
|
+
const _CMD_CAL_INIT_1 = Buffer.from([0x1B, 0x00, 0x00]);
|
|
6
|
+
const _CMD_CAL_INIT_2 = Buffer.from([0x1C, 0x00, 0x00]);
|
|
7
|
+
const _CMD_CAL_INIT_3 = Buffer.from([0x1E, 0x00, 0x00]);
|
|
8
|
+
|
|
9
|
+
const _STATUS_BUSY = 0x80;
|
|
10
|
+
const _STATUS_CAL = 0x08;
|
|
11
|
+
|
|
12
|
+
function _sleep(ms) {
|
|
13
|
+
const end = Date.now() + ms;
|
|
14
|
+
while (Date.now() < end) {}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* AHT21 temperature and humidity sensor — minimal interface.
|
|
19
|
+
*
|
|
20
|
+
* Provides temperature and humidity readings with no configuration beyond
|
|
21
|
+
* the transport. Handles power-on initialization, calibration check, and
|
|
22
|
+
* measurement triggering automatically.
|
|
23
|
+
*
|
|
24
|
+
* Default configuration (baked in at construction):
|
|
25
|
+
* - Measurement triggered on every read() call (no continuous mode)
|
|
26
|
+
* - 80 ms fixed wait after trigger (no busy-polling)
|
|
27
|
+
* - No CRC verification (reduces complexity; CRC check is Full-only)
|
|
28
|
+
*/
|
|
29
|
+
class AHT21Minimal {
|
|
30
|
+
/**
|
|
31
|
+
* @param {object} transport - Configured I²C transport pointing at the device (address 0x38).
|
|
32
|
+
*/
|
|
33
|
+
constructor(transport) {
|
|
34
|
+
this._transport = transport;
|
|
35
|
+
_sleep(100);
|
|
36
|
+
let status = this._readStatus();
|
|
37
|
+
if ((status & 0x18) !== 0x18) {
|
|
38
|
+
this._transport.write(_CMD_SOFT_RESET);
|
|
39
|
+
_sleep(20);
|
|
40
|
+
status = this._readStatus();
|
|
41
|
+
if ((status & 0x18) !== 0x18) {
|
|
42
|
+
this._transport.write(_CMD_CAL_INIT_1);
|
|
43
|
+
_sleep(10);
|
|
44
|
+
this._transport.write(_CMD_CAL_INIT_2);
|
|
45
|
+
_sleep(10);
|
|
46
|
+
this._transport.write(_CMD_CAL_INIT_3);
|
|
47
|
+
_sleep(10);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_readStatus() {
|
|
53
|
+
return this._transport.read(1)[0];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Trigger a measurement and return temperature and humidity.
|
|
58
|
+
*
|
|
59
|
+
* Sends the trigger command, waits 80 ms, reads 6 bytes, and decodes
|
|
60
|
+
* the raw 20-bit values into physical units.
|
|
61
|
+
*
|
|
62
|
+
* @returns {{ temperature_c: number, humidity_pct: number }}
|
|
63
|
+
* temperature_c: Temperature in degrees Celsius (-50 to 150 °C).
|
|
64
|
+
* humidity_pct: Relative humidity in percent (0 to 100 %RH).
|
|
65
|
+
*/
|
|
66
|
+
read() {
|
|
67
|
+
this._transport.write(_CMD_TRIGGER);
|
|
68
|
+
_sleep(80);
|
|
69
|
+
const data = this._transport.read(6);
|
|
70
|
+
const rawRh = (data[1] << 12) | (data[2] << 4) | (data[3] >> 4);
|
|
71
|
+
const rawT = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5];
|
|
72
|
+
const humidityPct = (rawRh / 1048576.0) * 100.0;
|
|
73
|
+
const temperatureC = (rawT / 1048576.0) * 200.0 - 50.0;
|
|
74
|
+
return { temperature_c: temperatureC, humidity_pct: humidityPct };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* AHT21 full interface — extends AHT21Minimal with CRC and status support.
|
|
80
|
+
*
|
|
81
|
+
* Adds CRC-8 verification, explicit soft reset, calibration status inspection,
|
|
82
|
+
* and individual temperature/humidity readings.
|
|
83
|
+
*/
|
|
84
|
+
class AHT21Full extends AHT21Minimal {
|
|
85
|
+
/**
|
|
86
|
+
* @param {object} transport - Configured I²C transport pointing at the device (address 0x38).
|
|
87
|
+
*/
|
|
88
|
+
constructor(transport) {
|
|
89
|
+
super(transport);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Trigger a measurement and return temperature only.
|
|
94
|
+
* @returns {number} Temperature in degrees Celsius (-50 to 150 °C).
|
|
95
|
+
*/
|
|
96
|
+
readTemperature() {
|
|
97
|
+
return this.read().temperature_c;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Trigger a measurement and return humidity only.
|
|
102
|
+
* @returns {number} Relative humidity in percent (0 to 100 %RH).
|
|
103
|
+
*/
|
|
104
|
+
readHumidity() {
|
|
105
|
+
return this.read().humidity_pct;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Trigger a measurement, read 7 bytes, and verify CRC-8.
|
|
110
|
+
*
|
|
111
|
+
* Uses polynomial x^8 + x^5 + x^4 + 1 (0x31) with initial value 0xFF
|
|
112
|
+
* to verify the CRC byte against bytes 0–5 of the response.
|
|
113
|
+
*
|
|
114
|
+
* @returns {{ temperature_c: number, humidity_pct: number, crc_ok: boolean }}
|
|
115
|
+
* temperature_c: Temperature in degrees Celsius.
|
|
116
|
+
* humidity_pct: Relative humidity in percent.
|
|
117
|
+
* crc_ok: True if CRC-8 verification passed.
|
|
118
|
+
*/
|
|
119
|
+
readWithCrc() {
|
|
120
|
+
this._transport.write(_CMD_TRIGGER);
|
|
121
|
+
_sleep(80);
|
|
122
|
+
const data = this._transport.read(7);
|
|
123
|
+
const rawRh = (data[1] << 12) | (data[2] << 4) | (data[3] >> 4);
|
|
124
|
+
const rawT = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5];
|
|
125
|
+
const humidityPct = (rawRh / 1048576.0) * 100.0;
|
|
126
|
+
const temperatureC = (rawT / 1048576.0) * 200.0 - 50.0;
|
|
127
|
+
const crcOk = this._crc8(data.slice(0, 6)) === data[6];
|
|
128
|
+
return { temperature_c: temperatureC, humidity_pct: humidityPct, crc_ok: crcOk };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Send the soft reset command and wait 20 ms for recovery.
|
|
133
|
+
*/
|
|
134
|
+
softReset() {
|
|
135
|
+
this._transport.write(_CMD_SOFT_RESET);
|
|
136
|
+
_sleep(20);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Check if the calibration bit is set in the status byte.
|
|
141
|
+
* @returns {boolean} True if the sensor reports calibration enabled.
|
|
142
|
+
*/
|
|
143
|
+
isCalibrated() {
|
|
144
|
+
return !!(this._readStatus() & _STATUS_CAL);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Check if the busy bit is set in the status byte.
|
|
149
|
+
* @returns {boolean} True if a measurement is in progress.
|
|
150
|
+
*/
|
|
151
|
+
isBusy() {
|
|
152
|
+
return !!(this._readStatus() & _STATUS_BUSY);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_crc8(data) {
|
|
156
|
+
let crc = 0xFF;
|
|
157
|
+
for (let i = 0; i < data.length; i++) {
|
|
158
|
+
crc ^= data[i];
|
|
159
|
+
for (let j = 0; j < 8; j++) {
|
|
160
|
+
if (crc & 0x80)
|
|
161
|
+
crc = ((crc << 1) ^ 0x31) & 0xFF;
|
|
162
|
+
else
|
|
163
|
+
crc = (crc << 1) & 0xFF;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return crc;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
module.exports = { AHT21Minimal, AHT21Full };
|