periph 1.5.3 → 1.6.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 (79) hide show
  1. package/README.md +18 -0
  2. package/examples/color/isl29125/complete.js +57 -0
  3. package/examples/color/isl29125/demo.js +77 -0
  4. package/examples/color/isl29125/minimal.js +23 -0
  5. package/examples/environmental/bme688/complete.js +48 -0
  6. package/examples/environmental/bme688/demo.js +47 -0
  7. package/examples/environmental/bme688/minimal.js +21 -0
  8. package/examples/gas/ccs811/complete.js +87 -0
  9. package/examples/gas/ccs811/demo.js +108 -0
  10. package/examples/gas/ccs811/minimal.js +20 -0
  11. package/examples/gas/rrh46410/complete.js +78 -0
  12. package/examples/gas/rrh46410/demo.js +86 -0
  13. package/examples/gas/rrh46410/minimal.js +21 -0
  14. package/examples/humidity/hts221/complete.js +83 -0
  15. package/examples/humidity/hts221/demo.js +94 -0
  16. package/examples/humidity/hts221/minimal.js +22 -0
  17. package/examples/humidity/htu31d/complete.js +50 -0
  18. package/examples/humidity/htu31d/demo.js +65 -0
  19. package/examples/humidity/htu31d/minimal.js +22 -0
  20. package/examples/humidity/shtc3/complete.js +48 -0
  21. package/examples/humidity/shtc3/demo.js +45 -0
  22. package/examples/humidity/shtc3/minimal.js +22 -0
  23. package/examples/led/saa1064/complete.js +51 -0
  24. package/examples/led/saa1064/demo.js +54 -0
  25. package/examples/led/saa1064/minimal.js +23 -0
  26. package/examples/light/apds9250/complete.js +71 -0
  27. package/examples/light/apds9250/demo.js +79 -0
  28. package/examples/light/apds9250/minimal.js +23 -0
  29. package/examples/light/bh1750/complete.js +46 -0
  30. package/examples/light/bh1750/demo.js +52 -0
  31. package/examples/light/bh1750/minimal.js +22 -0
  32. package/examples/light/si1132/complete.js +70 -0
  33. package/examples/light/si1132/demo.js +73 -0
  34. package/examples/light/si1132/minimal.js +22 -0
  35. package/examples/light/si1133/complete.js +89 -0
  36. package/examples/light/si1133/demo.js +93 -0
  37. package/examples/light/si1133/minimal.js +22 -0
  38. package/examples/light/si1145/complete.js +93 -0
  39. package/examples/light/si1145/demo.js +98 -0
  40. package/examples/light/si1145/minimal.js +22 -0
  41. package/examples/pressure/mpl3115a2/complete.js +49 -0
  42. package/examples/pressure/mpl3115a2/demo.js +48 -0
  43. package/examples/pressure/mpl3115a2/minimal.js +22 -0
  44. package/examples/pressure/ms5607/complete.js +49 -0
  45. package/examples/pressure/ms5607/demo.js +65 -0
  46. package/examples/pressure/ms5607/minimal.js +22 -0
  47. package/examples/pressure/ms5611/complete.js +49 -0
  48. package/examples/pressure/ms5611/demo.js +65 -0
  49. package/examples/pressure/ms5611/minimal.js +22 -0
  50. package/examples/pressure/spl06/complete.js +81 -0
  51. package/examples/pressure/spl06/demo.js +106 -0
  52. package/examples/pressure/spl06/minimal.js +22 -0
  53. package/examples/rfid/pn532/complete.js +99 -0
  54. package/examples/rfid/pn532/demo.js +121 -0
  55. package/examples/rfid/pn532/minimal.js +22 -0
  56. package/package.json +1 -1
  57. package/src/chips/color/isl29125.js +379 -0
  58. package/src/chips/environmental/bme688.js +573 -0
  59. package/src/chips/gas/ccs811.js +400 -0
  60. package/src/chips/gas/rrh46410.js +534 -0
  61. package/src/chips/humidity/hts221.js +369 -0
  62. package/src/chips/humidity/htu31d.js +242 -0
  63. package/src/chips/humidity/shtc3.js +239 -0
  64. package/src/chips/led/saa1064.js +241 -0
  65. package/src/chips/light/apds9250.js +431 -0
  66. package/src/chips/light/bh1750.js +196 -0
  67. package/src/chips/light/si1132.js +416 -0
  68. package/src/chips/light/si1133.js +583 -0
  69. package/src/chips/light/si1145.js +630 -0
  70. package/src/chips/pressure/mpl3115a2.js +459 -0
  71. package/src/chips/pressure/ms5607.js +290 -0
  72. package/src/chips/pressure/ms5611.js +290 -0
  73. package/src/chips/pressure/spl06.js +461 -0
  74. package/src/chips/rfid/pn532.js +513 -0
  75. package/src/connection/i2c.js +46 -13
  76. package/src/connection/smbus.js +21 -8
  77. package/src/discovery/registry.js +18 -18
  78. package/examples/gpio/.gitkeep +0 -0
  79. package/src/chips/gpio/.gitkeep +0 -0
@@ -0,0 +1,239 @@
1
+ 'use strict';
2
+
3
+ const _CMD_SLEEP = 0xB098;
4
+ const _CMD_WAKE = 0x3517;
5
+ const _CMD_RESET = 0x805D;
6
+ const _CMD_READ_ID = 0xEFC8;
7
+ // measurement commands [lowPower][clockStretching], temperature first
8
+ const _CMD_MEASURE = [[0x7866, 0x7CA2], [0x609C, 0x6458]];
9
+ const _ID_MASK = 0x083F;
10
+ const _ID_VALUE = 0x0807;
11
+
12
+ const _sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
13
+
14
+ /**
15
+ * CRC-8 used by the SHTC3: polynomial 0x31 (x^8 + x^5 + x^4 + 1), init 0xFF, no final XOR.
16
+ * @param {Buffer|number[]} data
17
+ * @returns {number}
18
+ */
19
+ function crc8(data) {
20
+ let crc = 0xFF;
21
+ for (const byte of data) {
22
+ crc ^= byte;
23
+ for (let i = 0; i < 8; i++) crc = (crc & 0x80) ? ((crc << 1) ^ 0x31) & 0xFF : (crc << 1) & 0xFF;
24
+ }
25
+ return crc;
26
+ }
27
+
28
+ function _toHumidity(code) {
29
+ return Math.min(100.0, Math.max(0.0, 100.0 * code / 65536.0));
30
+ }
31
+
32
+ function _toTemperature(code) {
33
+ return -45.0 + 175.0 * code / 65536.0;
34
+ }
35
+
36
+ function _word(data, offset) {
37
+ const chunk = data.subarray(offset, offset + 3);
38
+ if (crc8(chunk.subarray(0, 2)) !== chunk[2]) throw new Error('SHTC3 CRC mismatch');
39
+ return (chunk[0] << 8) | chunk[1];
40
+ }
41
+
42
+ /**
43
+ * SHTC3 humidity and temperature sensor — minimal interface.
44
+ *
45
+ * Each `read()` runs a full measurement cycle: wake-up (0x3517), a normal-mode
46
+ * temperature-first measurement without clock stretching (0x7866), a 13 ms wait,
47
+ * a 6-byte read with both CRC-8 bytes verified, and the sleep command (0xB098).
48
+ * A bad CRC is retried once before an error is thrown.
49
+ *
50
+ * The device is command driven (no register pointer), so a plain I²C connection is used.
51
+ * The constructor does not touch the bus; `init()` performs the soft reset and the ID check.
52
+ */
53
+ class SHTC3Minimal {
54
+ /**
55
+ * @param {import('../../connection/connection').Connection} connection - Configured I²C connection pointing at the device (address 0x70).
56
+ */
57
+ constructor(connection) {
58
+ this._conn = connection;
59
+ this._lowPower = false;
60
+ this._stretching = false;
61
+ this._sleepBetween = true;
62
+ this._asleep = false;
63
+ }
64
+
65
+ async _command(code) {
66
+ await this._conn.write(Buffer.from([(code >> 8) & 0xFF, code & 0xFF]));
67
+ }
68
+
69
+ async _wake() {
70
+ if (this._asleep) {
71
+ await this._command(_CMD_WAKE);
72
+ await _sleep(1);
73
+ this._asleep = false;
74
+ }
75
+ }
76
+
77
+ async _sleepCmd() {
78
+ await this._command(_CMD_SLEEP);
79
+ this._asleep = true;
80
+ }
81
+
82
+ async _measure() {
83
+ await this._wake();
84
+ try {
85
+ for (let attempt = 0; ; attempt++) {
86
+ await this._command(_CMD_MEASURE[this._lowPower ? 1 : 0][this._stretching ? 1 : 0]);
87
+ if (!this._stretching) await _sleep(this._lowPower ? 1 : 13);
88
+ const data = Buffer.from(await this._conn.read(6));
89
+ try {
90
+ return [_word(data, 0), _word(data, 3)];
91
+ } catch (e) {
92
+ if (attempt) throw e;
93
+ }
94
+ }
95
+ } finally {
96
+ if (this._sleepBetween) await this._sleepCmd();
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Wake, soft reset (0x805D), check the product ID, then sleep.
102
+ * @throws {Error} If the ID word fails its CRC or is not an SHTC3.
103
+ */
104
+ async init() {
105
+ this._asleep = true;
106
+ await this._wake();
107
+ await this._command(_CMD_RESET);
108
+ await _sleep(1);
109
+ await this._command(_CMD_READ_ID);
110
+ const data = Buffer.from(await this._conn.read(3));
111
+ let id;
112
+ try {
113
+ id = _word(data, 0);
114
+ } finally {
115
+ await this._sleepCmd();
116
+ }
117
+ if ((id & _ID_MASK) !== _ID_VALUE) throw new Error('not an SHTC3 (ID 0x' + id.toString(16) + ')');
118
+ }
119
+
120
+ /**
121
+ * Measure temperature and humidity.
122
+ * @returns {Promise<{temperature_c: number, humidity_pct: number}>} °C and %RH (0-100)
123
+ */
124
+ async read() {
125
+ const [t, rh] = await this._measure();
126
+ return { temperature_c: _toTemperature(t), humidity_pct: _toHumidity(rh) };
127
+ }
128
+ }
129
+
130
+ /**
131
+ * SHTC3 full interface — single values, raw codes, low-power mode, clock stretching, sleep control, ID, dew point.
132
+ *
133
+ * Extends SHTC3Minimal with single values, raw codes, the low-power measurement mode,
134
+ * the clock-stretching command set, sleep control, soft reset, the product ID and the dew point.
135
+ */
136
+ class SHTC3Full extends SHTC3Minimal {
137
+ /**
138
+ * @param {import('../../connection/connection').Connection} connection - Configured I²C connection pointing at the device (address 0x70).
139
+ */
140
+ constructor(connection) {
141
+ super(connection);
142
+ }
143
+
144
+ /**
145
+ * Run one measurement cycle and return the temperature.
146
+ * @returns {Promise<number>} Temperature in °C.
147
+ */
148
+ async readTemperature() {
149
+ return _toTemperature((await this._measure())[0]);
150
+ }
151
+
152
+ /**
153
+ * Run one measurement cycle and return the humidity.
154
+ * @returns {Promise<number>} Relative humidity in %RH, clamped to 0-100.
155
+ */
156
+ async readHumidity() {
157
+ return _toHumidity((await this._measure())[1]);
158
+ }
159
+
160
+ /**
161
+ * Run one measurement cycle and return the raw codes.
162
+ * @returns {Promise<[number, number]>} [raw_temperature, raw_humidity], both 16-bit unsigned.
163
+ */
164
+ async readRaw() {
165
+ return this._measure();
166
+ }
167
+
168
+ /**
169
+ * Use the low-power (0.7 ms) or the normal (10.8 ms) measurement commands.
170
+ * @param {boolean} on - True for low-power mode (waits 1 ms), false for normal mode (13 ms).
171
+ */
172
+ setLowPower(on) {
173
+ this._lowPower = Boolean(on);
174
+ }
175
+
176
+ /**
177
+ * Use the clock-stretching command set; the fixed wait is skipped.
178
+ * Requires an I²C controller that tolerates a slave holding SCL low.
179
+ * @param {boolean} on
180
+ */
181
+ setClockStretching(on) {
182
+ this._stretching = Boolean(on);
183
+ }
184
+
185
+ /**
186
+ * Choose whether a read ends with the sleep command (default on).
187
+ * @param {boolean} on
188
+ */
189
+ setSleepBetween(on) {
190
+ this._sleepBetween = Boolean(on);
191
+ }
192
+
193
+ /** Send the wake-up command (0x3517) and wait 1 ms. */
194
+ async wake() {
195
+ await this._command(_CMD_WAKE);
196
+ await _sleep(1);
197
+ this._asleep = false;
198
+ }
199
+
200
+ /** Send the sleep command (0xB098). */
201
+ async sleep() {
202
+ await this._sleepCmd();
203
+ }
204
+
205
+ /** Soft reset (0x805D), 1 ms wait; leaves the sensor idle. */
206
+ async softReset() {
207
+ await this._wake();
208
+ await this._command(_CMD_RESET);
209
+ await _sleep(1);
210
+ }
211
+
212
+ /**
213
+ * Read the 16-bit ID word (command 0xEFC8, CRC verified). A sleeping sensor is woken
214
+ * for the read and put back to sleep.
215
+ * @returns {Promise<number>} ID word; (id & 0x083F) === 0x0807 for the SHTC3.
216
+ */
217
+ async readId() {
218
+ const wasAsleep = this._asleep;
219
+ await this._wake();
220
+ await this._command(_CMD_READ_ID);
221
+ const data = Buffer.from(await this._conn.read(3));
222
+ if (wasAsleep) await this._sleepCmd();
223
+ return _word(data, 0);
224
+ }
225
+
226
+ /**
227
+ * Run one measurement and compute the dew point (Magnus formula over water).
228
+ * @returns {Promise<number>} Dew point in °C.
229
+ */
230
+ async dewPoint() {
231
+ const m = await this.read();
232
+ const t = m.temperature_c;
233
+ const rh = m.humidity_pct <= 0.0 ? 0.01 : m.humidity_pct;
234
+ const g = Math.log(rh / 100.0) + 17.62 * t / (243.12 + t);
235
+ return 243.12 * g / (17.62 - g);
236
+ }
237
+ }
238
+
239
+ module.exports = { SHTC3Minimal, SHTC3Full, crc8 };
@@ -0,0 +1,241 @@
1
+ 'use strict';
2
+
3
+ const _SEGMENTS = {
4
+ 0: 'abcdef', 1: 'bc', 2: 'abdeg', 3: 'abcdg', 4: 'bcfg',
5
+ 5: 'acdfg', 6: 'acdefg', 7: 'abc', 8: 'abcdefg', 9: 'abcdfg',
6
+ };
7
+ const _KEYS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'dp'];
8
+ const _DEFAULT_MAP = { a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, dp: 7 };
9
+
10
+ const _SUB_CONTROL = 0x00;
11
+ const _C_DYNAMIC = 0x01;
12
+ const _C_UNBLANK_13 = 0x02;
13
+ const _C_UNBLANK_24 = 0x04;
14
+ const _C_TEST = 0x08;
15
+ const _C_CURRENT = 0x70;
16
+
17
+ /**
18
+ * SAA1064 4-digit LED driver — minimal interface.
19
+ *
20
+ * Drives four 7-segment digits (multiplexed in pairs, dynamic mode) with
21
+ * decimal points. I2C address 0x38-0x3B selected by the voltage on the ADR
22
+ * pin. The constructor starts the initialization (control byte 0x47: dynamic
23
+ * mode, all digits unblanked, 12 mA; digits blanked); every bus method waits
24
+ * for it, and `ready` exposes it.
25
+ *
26
+ * @param {import('../../connection/connection').Connection} connection - Configured I2C connection pointing at the device.
27
+ */
28
+ class SAA1064Minimal {
29
+ constructor(connection) {
30
+ this._conn = connection;
31
+ this._control = 0x47;
32
+ this._patterns = [0, 0, 0, 0];
33
+ this._map = Object.assign({}, _DEFAULT_MAP);
34
+ this._glyphs = {};
35
+ this._rebuildGlyphs();
36
+ this._ready = this._conn.write(Buffer.from([_SUB_CONTROL, this._control, 0, 0, 0, 0]));
37
+ }
38
+
39
+ /** Wait for the init sequence started by the constructor. @returns {Promise<void>} */
40
+ get ready() { return this._ready; }
41
+
42
+ _rebuildGlyphs() {
43
+ this._glyphs = {};
44
+ for (const value of Object.keys(_SEGMENTS)) {
45
+ let pattern = 0;
46
+ for (const s of _SEGMENTS[value]) pattern |= 1 << this._map[s];
47
+ this._glyphs[value] = pattern;
48
+ }
49
+ }
50
+
51
+ _pattern(value) {
52
+ if (value === null || value === undefined) return 0;
53
+ if (!Number.isInteger(value) || value < 0 || value > 9) throw new RangeError('digit must be 0-9 or null');
54
+ return this._glyphs[value];
55
+ }
56
+
57
+ async _writeDigits(first) {
58
+ await this._ready;
59
+ await this._conn.write(Buffer.from([first].concat(this._patterns.slice(first - 1))));
60
+ }
61
+
62
+ /**
63
+ * Show four digits using the segment mapping.
64
+ * @param {Array<number|null>} digits - Four values, each 0-9 or null (blank).
65
+ * @returns {Promise<void>}
66
+ */
67
+ async showDigits(digits) {
68
+ if (digits.length !== 4) throw new RangeError('digits must have 4 values');
69
+ this._patterns = digits.map((d) => this._pattern(d));
70
+ await this._writeDigits(1);
71
+ }
72
+
73
+ /**
74
+ * Show a right-aligned decimal number with leading zeros blanked.
75
+ * @param {number} value - Integer 0-9999.
76
+ * @returns {Promise<void>}
77
+ */
78
+ async showNumber(value) {
79
+ if (!Number.isInteger(value) || value < 0 || value > 9999) throw new RangeError('value must be in 0..9999');
80
+ const digits = [null, null, null, value % 10];
81
+ let v = Math.floor(value / 10);
82
+ for (const i of [2, 1, 0]) {
83
+ if (v > 0) { digits[i] = v % 10; v = Math.floor(v / 10); }
84
+ }
85
+ await this.showDigits(digits);
86
+ }
87
+
88
+ /** Blank all four digits. @returns {Promise<void>} */
89
+ async clear() {
90
+ this._patterns = [0, 0, 0, 0];
91
+ await this._writeDigits(1);
92
+ }
93
+
94
+ /**
95
+ * Write raw segment bytes starting at a digit.
96
+ * @param {number[]} patterns - 1-4 segment bytes (bit 0 = P1/P9 ... bit 7 = P8/P16).
97
+ * @param {number} [firstDigit=1] - First digit to write, 1-4.
98
+ * @returns {Promise<void>}
99
+ */
100
+ async writeRaw(patterns, firstDigit = 1) {
101
+ patterns = Array.from(patterns);
102
+ if (!Number.isInteger(firstDigit) || firstDigit < 1 || firstDigit > 4) throw new RangeError('firstDigit must be in 1..4');
103
+ if (patterns.length < 1 || firstDigit - 1 + patterns.length > 4) throw new RangeError('patterns must fit within digits 1..4');
104
+ for (const p of patterns) {
105
+ if (!Number.isInteger(p) || p < 0 || p > 255) throw new RangeError('pattern must be 0..255');
106
+ }
107
+ for (let i = 0; i < patterns.length; i++) this._patterns[firstDigit - 1 + i] = patterns[i];
108
+ await this._ready;
109
+ await this._conn.write(Buffer.from([firstDigit].concat(patterns)));
110
+ }
111
+ }
112
+
113
+ /**
114
+ * SAA1064 full interface — mode, blanking, current, test, segment map, status.
115
+ *
116
+ * @param {import('../../connection/connection').Connection} connection - Configured I2C connection pointing at the device.
117
+ */
118
+ class SAA1064Full extends SAA1064Minimal {
119
+ async _writeControl() {
120
+ await this._ready;
121
+ await this._conn.write(Buffer.from([_SUB_CONTROL, this._control]));
122
+ }
123
+
124
+ async _setBit(mask, on) {
125
+ if (on) this._control |= mask;
126
+ else this._control &= ~mask & 0x7F;
127
+ await this._writeControl();
128
+ }
129
+
130
+ /**
131
+ * Select dynamic (all four digits) or static (digits 1 and 2) mode.
132
+ * @param {boolean} dynamic - true for dynamic mode.
133
+ * @returns {Promise<void>}
134
+ */
135
+ async setMode(dynamic) { await this._setBit(_C_DYNAMIC, dynamic); }
136
+
137
+ /**
138
+ * Blank digit pairs.
139
+ * @param {boolean} digits13 - true to blank digits 1 and 3.
140
+ * @param {boolean} digits24 - true to blank digits 2 and 4.
141
+ * @returns {Promise<void>}
142
+ */
143
+ async blank(digits13, digits24) {
144
+ this._control = digits13 ? this._control & ~_C_UNBLANK_13 & 0x7F : this._control | _C_UNBLANK_13;
145
+ this._control = digits24 ? this._control & ~_C_UNBLANK_24 & 0x7F : this._control | _C_UNBLANK_24;
146
+ await this._writeControl();
147
+ }
148
+
149
+ /**
150
+ * Set the segment output current.
151
+ * @param {number} ma - 0, 3, 6, 9, 12, 15, 18 or 21 (mA).
152
+ * @returns {Promise<void>}
153
+ */
154
+ async setCurrent(ma) {
155
+ if (![0, 3, 6, 9, 12, 15, 18, 21].includes(ma)) throw new RangeError('ma must be one of 0, 3, 6, 9, 12, 15, 18, 21');
156
+ this._control = (this._control & ~_C_CURRENT & 0x7F) | ((ma / 3) << 4);
157
+ await this._writeControl();
158
+ }
159
+
160
+ /**
161
+ * Switch all segment outputs on (segment test).
162
+ * @param {boolean} on - true to start the test.
163
+ * @returns {Promise<void>}
164
+ */
165
+ async segmentTest(on) { await this._setBit(_C_TEST, on); }
166
+
167
+ /**
168
+ * Remap the helper's segment bits to the module wiring.
169
+ * @param {{a:number,b:number,c:number,d:number,e:number,f:number,g:number,dp:number}} mapping - bit numbers 0-7.
170
+ */
171
+ setSegmentMap(mapping) {
172
+ for (const k of _KEYS) {
173
+ if (!(k in mapping)) throw new RangeError('mapping needs keys a-g and dp');
174
+ if (!Number.isInteger(mapping[k]) || mapping[k] < 0 || mapping[k] > 7) throw new RangeError('bit numbers must be in 0..7');
175
+ }
176
+ this._map = {};
177
+ for (const k of _KEYS) this._map[k] = mapping[k];
178
+ this._rebuildGlyphs();
179
+ }
180
+
181
+ /**
182
+ * Show one digit with an optional decimal point.
183
+ * @param {number} position - Digit 1-4.
184
+ * @param {number|null} value - 0-9 or null (blank).
185
+ * @param {boolean} [dp=false] - true to light the decimal point.
186
+ * @returns {Promise<void>}
187
+ */
188
+ async showDigit(position, value, dp = false) {
189
+ if (!Number.isInteger(position) || position < 1 || position > 4) throw new RangeError('position must be in 1..4');
190
+ let pattern = this._pattern(value);
191
+ if (dp) pattern |= 1 << this._map.dp;
192
+ this._patterns[position - 1] = pattern;
193
+ await this._ready;
194
+ await this._conn.write(Buffer.from([position, pattern]));
195
+ }
196
+
197
+ /**
198
+ * Switch a decimal point, keeping the cached segments.
199
+ * @param {number} position - Digit 1-4.
200
+ * @param {boolean} on - true to light the decimal point.
201
+ * @returns {Promise<void>}
202
+ */
203
+ async setDecimalPoint(position, on) {
204
+ if (!Number.isInteger(position) || position < 1 || position > 4) throw new RangeError('position must be in 1..4');
205
+ const bit = 1 << this._map.dp;
206
+ if (on) this._patterns[position - 1] |= bit;
207
+ else this._patterns[position - 1] &= ~bit & 0xFF;
208
+ await this._ready;
209
+ await this._conn.write(Buffer.from([position, this._patterns[position - 1]]));
210
+ }
211
+
212
+ /**
213
+ * Read the status byte (bit 7 = PR power-reset flag, cleared by the read).
214
+ * @returns {Promise<number>} Status byte, 0-255.
215
+ */
216
+ async readStatus() {
217
+ await this._ready;
218
+ const data = await this._conn.read(1);
219
+ return data[0];
220
+ }
221
+
222
+ /** Read the status byte and return its PR flag. @returns {Promise<boolean>} */
223
+ async powerResetFlag() {
224
+ return ((await this.readStatus()) & 0x80) !== 0;
225
+ }
226
+
227
+ /**
228
+ * Write a raw control byte (bit 7 forced to 0).
229
+ * @param {number} value - Control byte 0-127.
230
+ * @returns {Promise<void>}
231
+ */
232
+ async writeControl(value) {
233
+ this._control = value & 0x7F;
234
+ await this._writeControl();
235
+ }
236
+ }
237
+
238
+ SAA1064Minimal.DIGITS = 4;
239
+ SAA1064Full.DIGITS = 4;
240
+
241
+ module.exports = { SAA1064Minimal, SAA1064Full };