periph 1.2.1 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const { toSigned } = require('../../connection/register');
4
+
3
5
  const _REG_INTERRUPT_CFG = 0x0B;
4
6
  const _REG_THS_P_L = 0x0C;
5
7
  const _REG_THS_P_H = 0x0D;
@@ -36,7 +38,7 @@ function _delay(ms) {
36
38
  * - ODR = 0100b (25 Hz)
37
39
  * - BDU = 1, EN_LPFP = 1, LFPF_CFG = 0 (ODR/4 bandwidth)
38
40
  *
39
- * @param {import('../../connection/connection').Connection} connection - Configured I²C connection.
41
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection.
40
42
  */
41
43
  class LPS28DFWMinimal {
42
44
  constructor(connection) {
@@ -51,13 +53,13 @@ class LPS28DFWMinimal {
51
53
  }
52
54
 
53
55
  async _init() {
56
+ _delay(_BOOT_WAIT_MS);
54
57
  const who = await this._readReg(_REG_WHO_AM_I, 1);
55
58
  if (who[0] !== _CHIP_ID) {
56
59
  throw new Error('LPS28DFW WHO_AM_I mismatch: expected 0x' +
57
60
  _CHIP_ID.toString(16).toUpperCase().padStart(2, '0') +
58
61
  ', got 0x' + who[0].toString(16).toUpperCase().padStart(2, '0'));
59
62
  }
60
- _delay(_BOOT_WAIT_MS);
61
63
  const ctrl2 = (this._fsMode << 6) | (this._lpfCfg << 5) | (this._lpfEn << 4) | (this._bdu << 3);
62
64
  await this._writeReg(_REG_CTRL_REG2, ctrl2);
63
65
  const ctrl1 = (this._odr << 3) | (this._avg & 0x07);
@@ -65,11 +67,11 @@ class LPS28DFWMinimal {
65
67
  }
66
68
 
67
69
  async _writeReg(reg, value) {
68
- await this._conn.write(Buffer.from([reg, value]));
70
+ await this._conn.writeReg(reg, value);
69
71
  }
70
72
 
71
73
  async _readReg(reg, n) {
72
- return this._conn.writeRead(Buffer.from([reg]), n);
74
+ return this._conn.readReg(reg, n);
73
75
  }
74
76
 
75
77
  /**
@@ -79,7 +81,7 @@ class LPS28DFWMinimal {
79
81
  async readPressure() {
80
82
  const raw = await this._readReg(_REG_PRESS_OUT_XL, 3);
81
83
  let v = (raw[2] << 16) | (raw[1] << 8) | raw[0];
82
- if (v & 0x800000) v |= 0xFF000000;
84
+ v = toSigned(v, 24);
83
85
  const sens = this._fsMode === 0 ? _SENSITIVITY_LSB_PER_HPA_MODE1 : _SENSITIVITY_LSB_PER_HPA_MODE2;
84
86
  return v / sens;
85
87
  }
@@ -90,7 +92,7 @@ class LPS28DFWMinimal {
90
92
  */
91
93
  async readTemperature() {
92
94
  const raw = await this._readReg(_REG_TEMP_OUT_L, 2);
93
- const v = raw.readInt16BE(0);
95
+ const v = raw.readInt16LE(0);
94
96
  return v / 100.0;
95
97
  }
96
98
  }
@@ -98,7 +100,7 @@ class LPS28DFWMinimal {
98
100
  /**
99
101
  * LPS28DFW full interface — extends LPS28DFWMinimal with full configuration.
100
102
  *
101
- * @param {import('../../connection/connection').Connection} connection - Configured I²C connection.
103
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection.
102
104
  */
103
105
  class LPS28DFWFull extends LPS28DFWMinimal {
104
106
  static ODR_POWER_DOWN = 0x00;
@@ -165,8 +167,8 @@ class LPS28DFWFull extends LPS28DFWMinimal {
165
167
  async read() {
166
168
  const raw = await this._readReg(_REG_PRESS_OUT_XL, 5);
167
169
  let p = (raw[2] << 16) | (raw[1] << 8) | raw[0];
168
- if (p & 0x800000) p |= 0xFF000000;
169
- const t = raw.readInt16BE(3);
170
+ p = toSigned(p, 24);
171
+ const t = raw.readInt16LE(3);
170
172
  const sens = this._fsMode === 0 ? _SENSITIVITY_LSB_PER_HPA_MODE1 : _SENSITIVITY_LSB_PER_HPA_MODE2;
171
173
  return { pressure: p / sens, temperature: t / 100.0 };
172
174
  }
@@ -231,9 +233,9 @@ class LPS28DFWFull extends LPS28DFWMinimal {
231
233
  * @returns {Promise<void>}
232
234
  */
233
235
  async fifoConfigure(mode, wtm, stopOnWtm) {
234
- if (mode === LPS28DFWFull.FIFO_BYPASS) {
235
- await this._writeReg(0x14, 0x00);
236
- }
236
+ // Always pass through Bypass first when switching FIFO modes (spec's
237
+ // "FIFO reset" procedure) -- not just when the target mode IS bypass.
238
+ await this._writeReg(0x14, 0x00);
237
239
  const trig = mode >= 4 ? 1 : 0;
238
240
  const fMode = mode & 0x03;
239
241
  const ctrl = (trig << 2) | ((stopOnWtm ? 1 : 0) << 3) | fMode;
@@ -255,7 +257,7 @@ class LPS28DFWFull extends LPS28DFWMinimal {
255
257
  for (let i = 0; i < count; i++) {
256
258
  const b = i * 3;
257
259
  let v = (raw[b + 2] << 16) | (raw[b + 1] << 8) | raw[b];
258
- if (v & 0x800000) v |= 0xFF000000;
260
+ v = toSigned(v, 24);
259
261
  out.push(v / sens);
260
262
  }
261
263
  return out;
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const { toSigned } = require('../../connection/register');
4
+
3
5
  const _REG_INTERRUPT_CFG = 0x0B;
4
6
  const _REG_THS_P_L = 0x0C;
5
7
  const _REG_THS_P_H = 0x0D;
@@ -29,8 +31,8 @@ function _delay(ms) {
29
31
  while (Date.now() - start < ms) {}
30
32
  }
31
33
 
32
- function _signExtend24(v) { return (v & 0x800000) ? (v | 0xFF000000) : v; }
33
- function _signExtend16(v) { return (v & 0x8000) ? (v | 0xFF00) : v; }
34
+ function _signExtend24(v) { return toSigned(v, 24); }
35
+ function _signExtend16(v) { return toSigned(v, 16); }
34
36
 
35
37
  /**
36
38
  * LPS33HW water-resistant MEMS absolute pressure sensor - minimal interface.
@@ -40,7 +42,7 @@ function _signExtend16(v) { return (v & 0x8000) ? (v | 0xFF00) : v; }
40
42
  *
41
43
  * Default: ODR=1 Hz, BDU=1, EN_LPFP=0, IF_ADD_INC=1.
42
44
  *
43
- * @param {import('../../connection/connection').Connection} connection - Configured I2C or SPI connection.
45
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection.
44
46
  */
45
47
  class LPS33HWMinimal {
46
48
  constructor(connection) {
@@ -64,11 +66,11 @@ class LPS33HWMinimal {
64
66
  }
65
67
 
66
68
  async _writeReg(reg, value) {
67
- await this._conn.write(Buffer.from([reg, value]));
69
+ await this._conn.writeReg(reg, value);
68
70
  }
69
71
 
70
72
  async _readReg(reg, n) {
71
- return this._conn.writeRead(Buffer.from([reg]), n);
73
+ return this._conn.readReg(reg, n);
72
74
  }
73
75
 
74
76
  async _waitStatus(mask) {
@@ -69,22 +69,22 @@ function _delayMs(ms) {
69
69
  */
70
70
  class DS3231Minimal {
71
71
  /**
72
- * @param {import('../../connection/connection').Connection} connection - Configured I²C connection at address 0x68.
72
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection at address 0x68.
73
73
  */
74
74
  constructor(connection) {
75
75
  this._conn = connection;
76
76
  }
77
77
 
78
78
  async _writeReg(reg, value) {
79
- await this._conn.write(Buffer.from([reg & 0xFF, value & 0xFF]));
79
+ await this._conn.writeReg(reg & 0xFF, value & 0xFF);
80
80
  }
81
81
 
82
82
  async _readReg(reg) {
83
- return (await this._conn.writeRead(Buffer.from([reg & 0xFF]), 1))[0];
83
+ return (await this._conn.readReg(reg & 0xFF, 1))[0];
84
84
  }
85
85
 
86
86
  async _readRegs(reg, n) {
87
- return this._conn.writeRead(Buffer.from([reg & 0xFF]), n);
87
+ return this._conn.readReg(reg & 0xFF, n);
88
88
  }
89
89
 
90
90
  /**
@@ -137,7 +137,7 @@ class DS3231Minimal {
137
137
  _intToBcd(month), // bit 7 (century) left at 0
138
138
  _intToBcd(year - 2000),
139
139
  ]);
140
- await this._conn.write(buf);
140
+ await this._conn.writeReg(buf[0], buf.subarray(1));
141
141
  const status = await this._readReg(_REG_CONTROL_STATUS);
142
142
  await this._writeReg(_REG_CONTROL_STATUS, status & ~_STATUS_OSF);
143
143
  }
@@ -170,7 +170,7 @@ class DS3231Minimal {
170
170
  */
171
171
  class DS3231Full extends DS3231Minimal {
172
172
  /**
173
- * @param {import('../../connection/connection').Connection} connection - Configured I²C connection at address 0x68.
173
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection at address 0x68.
174
174
  */
175
175
  constructor(connection) {
176
176
  super(connection);
@@ -235,7 +235,7 @@ class DS3231Full extends DS3231Minimal {
235
235
  (a1m3 << 7) | _intToBcd(hour),
236
236
  (a1m4 << 7) | (isDayOfWeek ? 0x40 : 0x00) | _intToBcd(dayOrDate),
237
237
  ]);
238
- await this._conn.write(buf);
238
+ await this._conn.writeReg(buf[0], buf.subarray(1));
239
239
  }
240
240
 
241
241
  /**
@@ -282,7 +282,7 @@ class DS3231Full extends DS3231Minimal {
282
282
  (a2m3 << 7) | _intToBcd(hour),
283
283
  (a2m4 << 7) | (isDayOfWeek ? 0x40 : 0x00) | _intToBcd(dayOrDate),
284
284
  ]);
285
- await this._conn.write(buf);
285
+ await this._conn.writeReg(buf[0], buf.subarray(1));
286
286
  }
287
287
 
288
288
  // -- Square wave / 32kHz --------------------------------------------
@@ -86,22 +86,22 @@ function _intToBcd(v) {
86
86
  */
87
87
  class PCF8523Minimal {
88
88
  /**
89
- * @param {import('../../connection/connection').Connection} connection - Configured I²C connection at address 0x68.
89
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection at address 0x68.
90
90
  */
91
91
  constructor(connection) {
92
92
  this._conn = connection;
93
93
  }
94
94
 
95
95
  async _writeReg(reg, value) {
96
- await this._conn.write(Buffer.from([reg & 0xFF, value & 0xFF]));
96
+ await this._conn.writeReg(reg & 0xFF, value & 0xFF);
97
97
  }
98
98
 
99
99
  async _readReg(reg) {
100
- return (await this._conn.writeRead(Buffer.from([reg & 0xFF]), 1))[0];
100
+ return (await this._conn.readReg(reg & 0xFF, 1))[0];
101
101
  }
102
102
 
103
103
  async _readRegs(reg, n) {
104
- return this._conn.writeRead(Buffer.from([reg & 0xFF]), n);
104
+ return this._conn.readReg(reg & 0xFF, n);
105
105
  }
106
106
 
107
107
  async _readControl1() {
@@ -156,16 +156,13 @@ class PCF8523Minimal {
156
156
  async setDatetime(year, month, day, weekday, hour, minute, second) {
157
157
  const ctrl1 = (await this._readControl1()) & ~_C1_12_24 & 0xFF;
158
158
  await this._writeReg(_REG_CONTROL_1, ctrl1 | _C1_STOP);
159
- await this._conn.write(Buffer.from([
160
- _REG_SECONDS,
161
- _intToBcd(second) & 0x7F, // OS = 0
159
+ await this._conn.writeReg(_REG_SECONDS, Buffer.from([_intToBcd(second) & 0x7F, // OS = 0
162
160
  _intToBcd(minute),
163
161
  _intToBcd(hour) & 0x3F,
164
162
  _intToBcd(day),
165
163
  weekday & 0x07,
166
164
  _intToBcd(month),
167
- _intToBcd(year - 2000),
168
- ]));
165
+ _intToBcd(year - 2000),]));
169
166
  await this._writeReg(_REG_CONTROL_1, ctrl1 & ~_C1_STOP & 0xFF);
170
167
  }
171
168
  }
@@ -229,13 +226,10 @@ class PCF8523Full extends PCF8523Minimal {
229
226
  * @returns {Promise<void>}
230
227
  */
231
228
  async setAlarm({ minute = null, hour = null, day = null, weekday = null } = {}) {
232
- await this._conn.write(Buffer.from([
233
- _REG_MINUTE_ALARM,
234
- minute == null ? 0x80 : _intToBcd(minute) & 0x7F,
229
+ await this._conn.writeReg(_REG_MINUTE_ALARM, Buffer.from([minute == null ? 0x80 : _intToBcd(minute) & 0x7F,
235
230
  hour == null ? 0x80 : _intToBcd(hour) & 0x3F,
236
231
  day == null ? 0x80 : _intToBcd(day) & 0x3F,
237
- weekday == null ? 0x80 : weekday & 0x07,
238
- ]));
232
+ weekday == null ? 0x80 : weekday & 0x07,]));
239
233
  }
240
234
 
241
235
  // -- Timers -----------------------------------------------------------
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const { toSigned } = require('../../connection/register');
4
+
3
5
  const _REG_CONFIG = 0x01;
4
6
  const _REG_TUPPER = 0x02;
5
7
  const _REG_TLOWER = 0x03;
@@ -34,7 +36,7 @@ const _HYSTERESES = [0, 1.5, 3.0, 6.0];
34
36
 
35
37
  function _decodeTemperature(raw16) {
36
38
  let raw = raw16 & 0x1FFF;
37
- if (raw & 0x1000) raw -= 0x2000;
39
+ raw = toSigned(raw, 13);
38
40
  return raw / 16;
39
41
  }
40
42
 
@@ -80,7 +82,7 @@ function _indexOfStep(table, value) {
80
82
  */
81
83
  class MCP9808Minimal {
82
84
  /**
83
- * @param {import('../../connection/connection').Connection} connection - Configured I²C connection (0x18–0x1F).
85
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection (0x18–0x1F).
84
86
  */
85
87
  constructor(connection) {
86
88
  this._conn = connection;
@@ -116,12 +118,12 @@ class MCP9808Minimal {
116
118
  }
117
119
 
118
120
  async _readReg(reg) {
119
- const buf = await this._conn.writeRead(Buffer.from([reg & 0xFF]), 2);
121
+ const buf = await this._conn.readReg(reg & 0xFF, 2);
120
122
  return buf.readUInt16BE(0);
121
123
  }
122
124
 
123
125
  async _writeReg(reg, value) {
124
- await this._conn.write(Buffer.from([reg & 0xFF, (value >> 8) & 0xFF, value & 0xFF]));
126
+ await this._conn.writeReg(reg & 0xFF, Buffer.from([(value >> 8) & 0xFF, value & 0xFF]));
125
127
  }
126
128
 
127
129
  /**
@@ -142,7 +144,7 @@ class MCP9808Minimal {
142
144
  */
143
145
  class MCP9808Full extends MCP9808Minimal {
144
146
  /**
145
- * @param {import('../../connection/connection').Connection} connection - Configured I²C connection (0x18–0x1F).
147
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection (0x18–0x1F).
146
148
  */
147
149
  constructor(connection) {
148
150
  super(connection);
@@ -172,7 +174,7 @@ class MCP9808Full extends MCP9808Minimal {
172
174
  const code = _indexOfStep(_RESOLUTIONS, celsius);
173
175
  if (code < 0) throw new RangeError('resolution must be one of 0.5, 0.25, 0.125, 0.0625');
174
176
  await this._ready;
175
- await this._conn.write(Buffer.from([_REG_RESOLUTION, code]));
177
+ await this._conn.writeReg(_REG_RESOLUTION, code);
176
178
  }
177
179
 
178
180
  /**
@@ -181,7 +183,7 @@ class MCP9808Full extends MCP9808Minimal {
181
183
  */
182
184
  async getResolution() {
183
185
  await this._ready;
184
- const buf = await this._conn.writeRead(Buffer.from([_REG_RESOLUTION]), 1);
186
+ const buf = await this._conn.readReg(_REG_RESOLUTION, 1);
185
187
  return _RESOLUTIONS[buf[0] & 0x03];
186
188
  }
187
189
 
@@ -79,7 +79,7 @@ function _encodeTemperature(celsius) {
79
79
  */
80
80
  class TMP117Minimal {
81
81
  /**
82
- * @param {import('../../connection/connection').Connection} connection - Configured I²C connection (0x48–0x4B).
82
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection (0x48–0x4B).
83
83
  */
84
84
  constructor(connection) {
85
85
  this._conn = connection;
@@ -110,12 +110,12 @@ class TMP117Minimal {
110
110
  }
111
111
 
112
112
  async _readReg(reg) {
113
- const buf = await this._conn.writeRead(Buffer.from([reg & 0xFF]), 2);
113
+ const buf = await this._conn.readReg(reg & 0xFF, 2);
114
114
  return buf.readUInt16BE(0);
115
115
  }
116
116
 
117
117
  async _writeReg(reg, value) {
118
- await this._conn.write(Buffer.from([reg & 0xFF, (value >> 8) & 0xFF, value & 0xFF]));
118
+ await this._conn.writeReg(reg & 0xFF, Buffer.from([(value >> 8) & 0xFF, value & 0xFF]));
119
119
  }
120
120
 
121
121
  /**
@@ -138,7 +138,7 @@ class TMP117Minimal {
138
138
  */
139
139
  class TMP117Full extends TMP117Minimal {
140
140
  /**
141
- * @param {import('../../connection/connection').Connection} connection - Configured I²C connection (0x48–0x4B).
141
+ * @param {import('../../connection/register_connection').RegisterConnection} connection - I²C or SMBus register connection (0x48–0x4B).
142
142
  */
143
143
  constructor(connection) {
144
144
  super(connection);
@@ -19,19 +19,21 @@ class Connection {
19
19
  /**
20
20
  * @param {InputPin|null} [intPin=null] - Optional InputPin for INT-line delivery.
21
21
  * @param {OutputPin|null} [enPin=null] - Optional OutputPin for hardware enable/power control.
22
+ * @param {boolean} [enActiveHigh=true] - True if the EN pin is active-high (default); false for active-low.
22
23
  */
23
- constructor(intPin = null, enPin = null) {
24
+ constructor(intPin = null, enPin = null, enActiveHigh = true) {
24
25
  this._intPin = intPin;
25
26
  this._enPin = enPin;
27
+ this._enActiveHigh = enActiveHigh;
26
28
  this._enabled = true;
27
29
  }
28
30
 
29
- /** Resume bus access; drives the hardware EN pin high if wired.
31
+ /** Resume bus access; asserts the hardware EN pin if wired.
30
32
  * @returns {Promise<void>}
31
33
  */
32
34
  async enable() {
33
35
  this._enabled = true;
34
- if (this._enPin) await this._enPin.set(true);
36
+ if (this._enPin) await this._enPin.set(this._enActiveHigh);
35
37
  }
36
38
 
37
39
  /**
@@ -42,7 +44,7 @@ class Connection {
42
44
  */
43
45
  async disable() {
44
46
  this._enabled = false;
45
- if (this._enPin) await this._enPin.set(false);
47
+ if (this._enPin) await this._enPin.set(!this._enActiveHigh);
46
48
  }
47
49
 
48
50
  /** @returns {boolean} The current software-gate state. */
@@ -36,10 +36,12 @@ class DHTxxConnection {
36
36
  /**
37
37
  * @param {number} dataPin - GPIO pin number for the DATA line.
38
38
  * @param {import('./output_pin').OutputPin|null} [enPin=null] - Optional EN-pin OutputPin.
39
+ * @param {boolean} [enActiveHigh=true] - True if the EN pin is active-high (default); false for active-low.
39
40
  */
40
- constructor(dataPin, enPin = null) {
41
+ constructor(dataPin, enPin = null, enActiveHigh = true) {
41
42
  this._pin = new Gpio(dataPin, 'in', 'both', { reconfigureDirection: true });
42
43
  this.enPin = enPin;
44
+ this.enActiveHigh = enActiveHigh;
43
45
  this._enabled = true;
44
46
  }
45
47
 
@@ -48,7 +50,7 @@ class DHTxxConnection {
48
50
  */
49
51
  async enable() {
50
52
  this._enabled = true;
51
- if (this.enPin) await this.enPin.set(true);
53
+ if (this.enPin) await this.enPin.set(this.enActiveHigh);
52
54
  }
53
55
 
54
56
  /** Gate read(); drives the hardware EN pin low if wired.
@@ -56,7 +58,7 @@ class DHTxxConnection {
56
58
  */
57
59
  async disable() {
58
60
  this._enabled = false;
59
- if (this.enPin) await this.enPin.set(false);
61
+ if (this.enPin) await this.enPin.set(!this.enActiveHigh);
60
62
  }
61
63
 
62
64
  /** @returns {boolean} The current software-gate state. */