periph 1.1.0 → 1.2.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 (266) hide show
  1. package/README.md +61 -12
  2. package/examples/accelerometer/adxl345/complete.js +52 -0
  3. package/examples/accelerometer/adxl345/demo.js +34 -0
  4. package/examples/accelerometer/adxl345/minimal.js +18 -0
  5. package/examples/accelerometer/adxl362/complete.js +57 -0
  6. package/examples/accelerometer/adxl362/demo.js +51 -0
  7. package/examples/accelerometer/adxl362/minimal.js +21 -0
  8. package/examples/adc_dac/ad7705/complete.js +32 -0
  9. package/examples/adc_dac/ad7705/demo.js +42 -0
  10. package/examples/adc_dac/ad7705/minimal.js +16 -0
  11. package/examples/adc_dac/ad7706/complete.js +35 -0
  12. package/examples/adc_dac/ad7706/demo.js +44 -0
  13. package/examples/adc_dac/ad7706/minimal.js +16 -0
  14. package/examples/adc_dac/hx710a/complete.js +45 -0
  15. package/examples/adc_dac/hx710a/demo.js +52 -0
  16. package/examples/adc_dac/hx710a/minimal.js +16 -0
  17. package/examples/adc_dac/hx710b/complete.js +45 -0
  18. package/examples/adc_dac/hx710b/demo.js +64 -0
  19. package/examples/adc_dac/hx710b/minimal.js +16 -0
  20. package/examples/adc_dac/hx711/complete.js +7 -7
  21. package/examples/adc_dac/hx711/demo.js +6 -6
  22. package/examples/adc_dac/hx711/minimal.js +7 -7
  23. package/examples/adc_dac/mcp4725/complete.js +19 -17
  24. package/examples/adc_dac/mcp4725/demo.js +5 -5
  25. package/examples/adc_dac/mcp4725/minimal.js +8 -6
  26. package/examples/adc_dac/mcp4728/complete.js +24 -22
  27. package/examples/adc_dac/mcp4728/demo.js +22 -22
  28. package/examples/adc_dac/mcp4728/minimal.js +8 -6
  29. package/examples/adc_dac/pcf8591/complete.js +41 -0
  30. package/examples/adc_dac/pcf8591/demo.js +39 -0
  31. package/examples/adc_dac/pcf8591/minimal.js +19 -0
  32. package/examples/comms/mcp2515/complete.js +75 -0
  33. package/examples/comms/mcp2515/demo.js +66 -0
  34. package/examples/comms/mcp2515/minimal.js +27 -0
  35. package/examples/comms/rda5807m/complete.js +55 -0
  36. package/examples/comms/rda5807m/demo.js +68 -0
  37. package/examples/comms/rda5807m/minimal.js +15 -0
  38. package/examples/comms/rfm9x/complete.js +50 -0
  39. package/examples/comms/rfm9x/demo.js +55 -0
  40. package/examples/comms/rfm9x/minimal.js +20 -0
  41. package/examples/display/pcf8576/complete.js +18 -15
  42. package/examples/display/pcf8576/demo.js +6 -6
  43. package/examples/display/pcf8576/minimal.js +12 -10
  44. package/examples/environmental/aht21/complete.js +15 -13
  45. package/examples/environmental/aht21/demo.js +8 -6
  46. package/examples/environmental/aht21/minimal.js +5 -5
  47. package/examples/environmental/bme280/complete.js +23 -20
  48. package/examples/environmental/bme280/demo.js +14 -14
  49. package/examples/environmental/bme280/minimal.js +13 -11
  50. package/examples/environmental/bme680/complete.js +25 -22
  51. package/examples/environmental/bme680/demo.js +38 -36
  52. package/examples/environmental/bme680/minimal.js +14 -12
  53. package/examples/gas/ens160/complete.js +29 -27
  54. package/examples/gas/ens160/demo.js +39 -37
  55. package/examples/gas/ens160/minimal.js +17 -15
  56. package/examples/gnss/neo6/complete.js +49 -0
  57. package/examples/gnss/neo6/demo.js +54 -0
  58. package/examples/gnss/neo6/minimal.js +30 -0
  59. package/examples/gyroscope/l3g4200d/complete.js +56 -0
  60. package/examples/gyroscope/l3g4200d/demo.js +49 -0
  61. package/examples/gyroscope/l3g4200d/minimal.js +19 -0
  62. package/examples/gyroscope/l3gd20h/complete.js +42 -0
  63. package/examples/gyroscope/l3gd20h/demo.js +29 -0
  64. package/examples/gyroscope/l3gd20h/minimal.js +13 -0
  65. package/examples/humidity/dht11/complete.js +22 -0
  66. package/examples/humidity/dht11/demo.js +38 -0
  67. package/examples/humidity/dht11/minimal.js +18 -0
  68. package/examples/imu/mpu6050/complete.js +27 -25
  69. package/examples/imu/mpu6050/demo.js +29 -26
  70. package/examples/imu/mpu6050/minimal.js +6 -6
  71. package/examples/imu/mpu9250/complete.js +65 -0
  72. package/examples/imu/mpu9250/demo.js +53 -0
  73. package/examples/imu/mpu9250/minimal.js +21 -0
  74. package/examples/imu/mpu9255/complete.js +73 -0
  75. package/examples/imu/mpu9255/demo.js +73 -0
  76. package/examples/imu/mpu9255/minimal.js +21 -0
  77. package/examples/io_expander/mcp23017/complete.js +70 -77
  78. package/examples/io_expander/mcp23017/demo.js +37 -33
  79. package/examples/io_expander/mcp23017/minimal.js +15 -11
  80. package/examples/io_expander/pcf8574/complete.js +60 -65
  81. package/examples/io_expander/pcf8574/demo.js +30 -25
  82. package/examples/io_expander/pcf8574/minimal.js +15 -11
  83. package/examples/io_expander/pcf8575/complete.js +24 -20
  84. package/examples/io_expander/pcf8575/demo.js +27 -23
  85. package/examples/io_expander/pcf8575/minimal.js +16 -12
  86. package/examples/io_expander/tpic6b595/complete.js +57 -0
  87. package/examples/io_expander/tpic6b595/demo.js +75 -0
  88. package/examples/io_expander/tpic6b595/minimal.js +26 -0
  89. package/examples/led/apa102/complete.js +72 -0
  90. package/examples/led/apa102/demo.js +92 -0
  91. package/examples/led/apa102/minimal.js +21 -0
  92. package/examples/led/sk6812rgbw/complete.js +42 -40
  93. package/examples/led/sk6812rgbw/demo.js +16 -16
  94. package/examples/led/sk6812rgbw/minimal.js +15 -17
  95. package/examples/led/ws2812b/complete.js +40 -38
  96. package/examples/led/ws2812b/demo.js +16 -16
  97. package/examples/led/ws2812b/minimal.js +13 -14
  98. package/examples/led/ws2814/complete.js +71 -0
  99. package/examples/led/ws2814/demo.js +82 -0
  100. package/examples/led/ws2814/minimal.js +23 -0
  101. package/examples/light/apds-9930/complete.js +46 -0
  102. package/examples/light/apds-9930/demo.js +31 -0
  103. package/examples/light/apds-9930/minimal.js +20 -0
  104. package/examples/light/apds9960/complete.js +45 -43
  105. package/examples/light/apds9960/demo.js +11 -9
  106. package/examples/light/apds9960/minimal.js +5 -5
  107. package/examples/magnetometer/as5600/complete.js +31 -29
  108. package/examples/magnetometer/as5600/demo.js +35 -33
  109. package/examples/magnetometer/as5600/minimal.js +7 -7
  110. package/examples/magnetometer/hmc5883l/complete.js +47 -0
  111. package/examples/magnetometer/hmc5883l/demo.js +50 -0
  112. package/examples/magnetometer/hmc5883l/minimal.js +15 -0
  113. package/examples/memory/24aa02uid/complete.js +23 -21
  114. package/examples/memory/24aa02uid/demo.js +32 -30
  115. package/examples/memory/24aa02uid/minimal.js +5 -5
  116. package/examples/motor/drv8830/complete.js +50 -0
  117. package/examples/motor/drv8830/demo.js +57 -0
  118. package/examples/motor/drv8830/minimal.js +23 -0
  119. package/examples/other/mpr121/complete.js +50 -0
  120. package/examples/other/mpr121/demo.js +30 -0
  121. package/examples/other/mpr121/minimal.js +17 -0
  122. package/examples/power/ade7953/complete.js +44 -0
  123. package/examples/power/ade7953/demo.js +28 -0
  124. package/examples/power/ade7953/minimal.js +15 -0
  125. package/examples/power/ina219/complete.js +20 -18
  126. package/examples/power/ina219/demo.js +15 -13
  127. package/examples/power/ina219/minimal.js +8 -8
  128. package/examples/power/ina226/complete.js +24 -22
  129. package/examples/power/ina226/demo.js +22 -20
  130. package/examples/power/ina226/minimal.js +5 -5
  131. package/examples/power/ina3221/complete.js +51 -49
  132. package/examples/power/ina3221/demo.js +13 -13
  133. package/examples/power/ina3221/minimal.js +8 -8
  134. package/examples/pressure/bmp085/complete.js +29 -0
  135. package/examples/pressure/bmp085/demo.js +34 -0
  136. package/examples/pressure/bmp085/minimal.js +19 -0
  137. package/examples/pressure/bmp180/complete.js +20 -17
  138. package/examples/pressure/bmp180/demo.js +24 -22
  139. package/examples/pressure/bmp180/minimal.js +13 -11
  140. package/examples/pressure/bmp280/complete.js +23 -20
  141. package/examples/pressure/bmp280/demo.js +44 -41
  142. package/examples/pressure/bmp280/minimal.js +13 -11
  143. package/examples/pressure/bmp384/complete.js +29 -0
  144. package/examples/pressure/bmp384/demo.js +40 -0
  145. package/examples/pressure/bmp384/minimal.js +18 -0
  146. package/examples/pressure/bmp581/complete.js +34 -0
  147. package/examples/pressure/bmp581/demo.js +56 -0
  148. package/examples/pressure/bmp581/minimal.js +19 -0
  149. package/examples/pressure/lps22df/complete.js +50 -0
  150. package/examples/pressure/lps22df/demo.js +41 -0
  151. package/examples/pressure/lps22df/minimal.js +19 -0
  152. package/examples/pressure/lps28dfw/complete.js +37 -0
  153. package/examples/pressure/lps28dfw/demo.js +33 -0
  154. package/examples/pressure/lps28dfw/minimal.js +19 -0
  155. package/examples/pressure/lps33hw/complete.js +43 -0
  156. package/examples/pressure/lps33hw/demo.js +43 -0
  157. package/examples/pressure/lps33hw/minimal.js +19 -0
  158. package/examples/rfid/mfrc522/complete.js +44 -0
  159. package/examples/rfid/mfrc522/demo.js +70 -0
  160. package/examples/rfid/mfrc522/minimal.js +17 -0
  161. package/examples/rtc/ds3231/complete.js +77 -0
  162. package/examples/rtc/ds3231/demo.js +60 -0
  163. package/examples/rtc/ds3231/minimal.js +23 -0
  164. package/examples/rtc/pcf8523/complete.js +66 -0
  165. package/examples/rtc/pcf8523/demo.js +65 -0
  166. package/examples/rtc/pcf8523/minimal.js +20 -0
  167. package/examples/temperature/mcp9808/complete.js +89 -0
  168. package/examples/temperature/mcp9808/demo.js +62 -0
  169. package/examples/temperature/mcp9808/minimal.js +21 -0
  170. package/examples/temperature/tmp117/complete.js +90 -0
  171. package/examples/temperature/tmp117/demo.js +73 -0
  172. package/examples/temperature/tmp117/minimal.js +21 -0
  173. package/examples/tof/vl53l0x/complete.js +118 -0
  174. package/examples/tof/vl53l0x/demo.js +83 -0
  175. package/examples/tof/vl53l0x/minimal.js +25 -0
  176. package/examples/tof/vl53l1x/complete.js +151 -0
  177. package/examples/tof/vl53l1x/demo.js +100 -0
  178. package/examples/tof/vl53l1x/minimal.js +25 -0
  179. package/package.json +5 -1
  180. package/src/chips/accelerometer/adxl345.js +482 -0
  181. package/src/chips/accelerometer/adxl362.js +594 -0
  182. package/src/chips/adc_dac/ad7705.js +345 -0
  183. package/src/chips/adc_dac/ad7706.js +331 -0
  184. package/src/chips/adc_dac/hx710a.js +184 -0
  185. package/src/chips/adc_dac/hx710b.js +186 -0
  186. package/src/chips/adc_dac/hx711.js +15 -15
  187. package/src/chips/adc_dac/mcp4725.js +48 -40
  188. package/src/chips/adc_dac/mcp4728.js +57 -44
  189. package/src/chips/adc_dac/pcf8591.js +196 -0
  190. package/src/chips/comms/mcp2515.js +659 -0
  191. package/src/chips/comms/rda5807m.js +393 -0
  192. package/src/chips/comms/rfm9x.js +590 -0
  193. package/src/chips/display/pcf8576.js +42 -33
  194. package/src/chips/environmental/aht21.js +52 -37
  195. package/src/chips/environmental/bme280.js +85 -66
  196. package/src/chips/environmental/bme680.js +110 -87
  197. package/src/chips/gas/ens160.js +82 -64
  198. package/src/chips/gnss/neo6.js +438 -0
  199. package/src/chips/gyroscope/l3g4200d.js +366 -0
  200. package/src/chips/gyroscope/l3gd20h.js +314 -0
  201. package/src/chips/humidity/dht11.js +135 -0
  202. package/src/chips/imu/mpu6050.js +89 -66
  203. package/src/chips/imu/mpu9250.js +394 -0
  204. package/src/chips/imu/mpu9255.js +447 -0
  205. package/src/chips/io_expander/mcp23017.js +240 -157
  206. package/src/chips/io_expander/pcf8574.js +149 -124
  207. package/src/chips/io_expander/pcf8575.js +164 -135
  208. package/src/chips/io_expander/tpic6b595.js +242 -0
  209. package/src/chips/led/_NeoPixelRGBBase.js +204 -0
  210. package/src/chips/led/_NeoPixelRGBWBase.js +218 -0
  211. package/src/chips/led/apa102.js +236 -0
  212. package/src/chips/led/sk6812rgbw.js +15 -149
  213. package/src/chips/led/ws2812b.js +14 -139
  214. package/src/chips/led/ws2814.js +49 -0
  215. package/src/chips/light/apds-9930.js +342 -0
  216. package/src/chips/light/apds9960.js +158 -123
  217. package/src/chips/magnetometer/as5600.js +102 -82
  218. package/src/chips/magnetometer/hmc5883l.js +222 -0
  219. package/src/chips/memory/_24aa02uid.js +32 -29
  220. package/src/chips/motor/drv8830.js +239 -0
  221. package/src/chips/other/mpr121.js +375 -0
  222. package/src/chips/power/ade7953.js +427 -0
  223. package/src/chips/power/ina219.js +45 -40
  224. package/src/chips/power/ina226.js +50 -45
  225. package/src/chips/power/ina3221.js +95 -76
  226. package/src/chips/pressure/bmp085.js +251 -0
  227. package/src/chips/pressure/bmp180.js +54 -37
  228. package/src/chips/pressure/bmp280.js +72 -53
  229. package/src/chips/pressure/bmp384.js +410 -0
  230. package/src/chips/pressure/bmp581.js +489 -0
  231. package/src/chips/pressure/lps22df.js +341 -0
  232. package/src/chips/pressure/lps28dfw.js +314 -0
  233. package/src/chips/pressure/lps33hw.js +255 -0
  234. package/src/chips/rfid/mfrc522.js +674 -0
  235. package/src/chips/rtc/ds3231.js +504 -0
  236. package/src/chips/rtc/pcf8523.js +539 -0
  237. package/src/chips/temperature/mcp9808.js +488 -0
  238. package/src/chips/temperature/tmp117.js +471 -0
  239. package/src/chips/tof/_vl53_base.js +160 -0
  240. package/src/chips/tof/vl53l0x.js +816 -0
  241. package/src/chips/tof/vl53l1x.js +816 -0
  242. package/src/connection/connection.js +111 -0
  243. package/src/connection/dhtxx.js +138 -0
  244. package/src/connection/dhtxx_mock.js +39 -0
  245. package/src/{transport → connection}/hx711.js +49 -22
  246. package/src/connection/hx711_mock.js +52 -0
  247. package/src/{transport → connection}/i2c.js +13 -9
  248. package/src/connection/i2c_mock.js +91 -0
  249. package/src/connection/input_pin.js +156 -0
  250. package/src/connection/neo6_mock.js +45 -0
  251. package/src/{transport → connection}/neopixel.js +23 -4
  252. package/src/connection/output_pin.js +41 -0
  253. package/src/connection/sipo.js +159 -0
  254. package/src/{transport → connection}/smbus.js +14 -10
  255. package/src/{transport → connection}/spi.js +12 -8
  256. package/src/connection/spi_mock.js +151 -0
  257. package/src/{transport → connection}/uart.js +33 -26
  258. package/examples/gnss/.gitkeep +0 -0
  259. package/examples/humidity/.gitkeep +0 -0
  260. package/examples/motor/.gitkeep +0 -0
  261. package/examples/temperature/.gitkeep +0 -0
  262. package/examples/tof/.gitkeep +0 -0
  263. package/src/chips/gnss/.gitkeep +0 -0
  264. package/src/chips/motor/.gitkeep +0 -0
  265. package/src/chips/temperature/.gitkeep +0 -0
  266. package/src/chips/tof/.gitkeep +0 -0
@@ -1,40 +1,42 @@
1
1
  'use strict';
2
2
 
3
- const { I2CTransport } = require('../../../src/transport/i2c');
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
4
  const { EEPROM24AA02UIDFull } = require('../../../src/chips/memory/_24aa02uid');
5
5
 
6
- const transport = new I2CTransport(1, 0x50);
7
- const eeprom = new EEPROM24AA02UIDFull(transport); // Create 24AA02UID driver, (transport, addr=0x50) → void
6
+ const connection = new I2CConnection(1, 0x50);
7
+ const eeprom = new EEPROM24AA02UIDFull(connection); // Create 24AA02UID driver, (connection, addr=0x50) → void
8
8
 
9
- // --- Read the chip's factory-programmed 32-bit serial number ---
10
- // The UID at 0xFC-0xFF never changes and identifies the device
11
- // across the entire 256-byte address space.
12
- const uid = eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
9
+ (async () => {
10
+ // --- Read the chip's factory-programmed 32-bit serial number ---
11
+ // The UID at 0xFC-0xFF never changes and identifies the device
12
+ // across the entire 256-byte address space.
13
+ const uid = await eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
13
14
  // reads 4 bytes at 0xFC-0xFF
14
- console.log('Device UID: 0x' + uid.toString('hex').toUpperCase());
15
- console.log('Device UID int:', uid.readUInt32BE(0));
15
+ console.log('Device UID: 0x' + uid.toString('hex').toUpperCase());
16
+ console.log('Device UID int:', uid.readUInt32BE(0));
16
17
 
17
- // --- Maintain a 4-byte boot counter in user EEPROM at 0x00-0x03 ---
18
- // Read the existing value (or zero on a fresh chip), increment,
19
- // write back as 4 big-endian bytes. The user EEPROM is rewritable;
20
- // the UID region above 0x80 is not, so the two stay independent.
21
- const existing = eeprom.read(0x00, 4); // Sequential read, (address, length) → Buffer
18
+ // --- Maintain a 4-byte boot counter in user EEPROM at 0x00-0x03 ---
19
+ // Read the existing value (or zero on a fresh chip), increment,
20
+ // write back as 4 big-endian bytes. The user EEPROM is rewritable;
21
+ // the UID region above 0x80 is not, so the two stay independent.
22
+ const existing = await eeprom.read(0x00, 4); // Sequential read, (address, length) → Buffer
22
23
  // reads 4 bytes from user EEPROM
23
- let counter = existing.readUInt32BE(0);
24
- counter += 1;
25
- const updated = Buffer.alloc(4);
26
- updated.writeUInt32BE(counter, 0);
27
- eeprom.write(0x00, updated); // Arbitrary-length write, (address, data) → void
24
+ let counter = existing.readUInt32BE(0);
25
+ counter += 1;
26
+ const updated = Buffer.alloc(4);
27
+ updated.writeUInt32BE(counter, 0);
28
+ await eeprom.write(0x00, updated); // Arbitrary-length write, (address, data) → void
28
29
  // writes 4 bytes; ACK-polls when done
29
- console.log('Boot count:', counter);
30
+ console.log('Boot count:', counter);
30
31
 
31
- let n = 0;
32
- setInterval(() => {
33
- // --- Loop reading the UID only, showing it never changes ---
34
- // The two distinct areas of the chip (immutable identification
35
- // above 0x80, rewritable storage below 0x80) are exercised
36
- // independently.
37
- const uid = eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
38
- console.log('[' + n + '] UID: 0x' + uid.toString('hex').toUpperCase() + ' (counter at user EEPROM 0x00-0x03)');
39
- n++;
40
- }, 2000);
32
+ let n = 0;
33
+ setInterval(async () => {
34
+ // --- Loop reading the UID only, showing it never changes ---
35
+ // The two distinct areas of the chip (immutable identification
36
+ // above 0x80, rewritable storage below 0x80) are exercised
37
+ // independently.
38
+ const uid = await eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
39
+ console.log('[' + n + '] UID: 0x' + uid.toString('hex').toUpperCase() + ' (counter at user EEPROM 0x00-0x03)');
40
+ n++;
41
+ }, 2000);
42
+ })();
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- const { I2CTransport } = require('../../../src/transport/i2c');
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
4
  const { EEPROM24AA02UIDMinimal } = require('../../../src/chips/memory/_24aa02uid');
5
5
 
6
- const transport = new I2CTransport(1, 0x50);
7
- const eeprom = new EEPROM24AA02UIDMinimal(transport); // Create 24AA02UID driver, (transport, addr=0x50) → void
6
+ const connection = new I2CConnection(1, 0x50);
7
+ const eeprom = new EEPROM24AA02UIDMinimal(connection); // Create 24AA02UID driver, (connection, addr=0x50) → void
8
8
 
9
- setInterval(() => {
10
- const uid = eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
9
+ setInterval(async () => {
10
+ const uid = await eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
11
11
  console.log('UID:', uid.toString('hex').toUpperCase());
12
12
  }, 2000);
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { DRV8830Full } = require('periph/src/chips/motor/drv8830');
5
+
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ (async () => {
9
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
10
+ const connection = new I2CConnection(bus, DRV8830Full.I2C_ADDRESS);
11
+ const motor = new DRV8830Full(connection); // Create DRV8830 Full driver, (connection)
12
+ await motor.init(); // Confirm device presence, () → None
13
+ // plain CONTROL read; the chip has no identity register
14
+
15
+ await motor.drive(2.5); // Drive at regulated voltage, (voltage V, + = forward) → None
16
+ // maps 2.5 V to the nearest VSET code and sets IN1=1, IN2=0
17
+ await sleep(1000);
18
+ const out = await motor.readOutput(); // Read back CONTROL, () → {voltage V, direction}
19
+ // decodes VSET to volts and IN1/IN2 to a direction name
20
+ console.log(`commanded ${out.voltage.toFixed(2)} V ${out.direction}`);
21
+
22
+ await motor.drive(-1.5); // Drive at regulated voltage, (voltage V, - = reverse) → None
23
+ // a negative voltage sets IN1=0, IN2=1
24
+ await sleep(1000);
25
+
26
+ await motor.setOutput(37, true, false); // Write raw CONTROL fields, (vset 6–63, in1, in2) → None
27
+ // VSET 37 is ~2.97 V forward; codes 0–5 throw RangeError
28
+ await sleep(1000);
29
+
30
+ await motor.brake(); // Short-brake, () → None
31
+ // IN1=IN2=1 drives both outputs high
32
+ await sleep(500);
33
+ await motor.stop(); // Coast to standby, () → None
34
+ // IN1=IN2=0 leaves both outputs high-impedance
35
+
36
+ const fault = await motor.readFault(); // Read fault status, () → {fault, ocp, uvlo, ots, ilimit}
37
+ // does not clear — latched OCP/ILIMIT keep the bridge off
38
+ console.log('fault', fault);
39
+ await motor.clearFault(); // Clear fault bits, () → None
40
+ // writes CLEAR=1; re-enables a latched-off bridge
41
+
42
+ await motor.onInterrupt((status) => console.log('fault interrupt', status)); // Subscribe to FAULTn, (callback) → None
43
+ // falls back to 5 ms polling when no intPin is wired
44
+ const status = await motor.pollInterrupt(); // Poll fault status, () → {fault, ocp, uvlo, ots, ilimit}
45
+ // same as readFault(); never clears implicitly
46
+ await motor.offInterrupt(); // Unsubscribe, () → None
47
+ console.log('poll', status);
48
+
49
+ await connection.close();
50
+ })();
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ // Battery-powered toy motor controller: holds a regulated 3.0 V forward, then
4
+ // 2.0 V reverse, printing the commanded output every second — the DRV8830
5
+ // keeps that average voltage constant as the battery sags. Brakes, then
6
+ // coasts. After every drive() call the fault register is checked; a fault
7
+ // (e.g. a stalled motor tripping ILIMIT) stops the motor and clears it.
8
+
9
+ const { I2CConnection } = require('periph/src/connection/i2c');
10
+ const { DRV8830Full } = require('periph/src/chips/motor/drv8830');
11
+
12
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
13
+
14
+ (async () => {
15
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
16
+ const connection = new I2CConnection(bus, DRV8830Full.I2C_ADDRESS);
17
+ const motor = new DRV8830Full(connection); // Create DRV8830 Full driver, (connection)
18
+ await motor.init(); // Confirm device presence, () → None
19
+
20
+ async function checkFault() {
21
+ // --- Recover from a fault instead of leaving the bridge latched off ---
22
+ // OCP and ILIMIT disable the H-bridge until CLEAR is written; stop first
23
+ // so the motor does not lurch back to the old command on clear.
24
+ const f = await motor.readFault(); // Read fault status, () → {fault, ocp, uvlo, ots, ilimit}
25
+ if (f.fault) {
26
+ const names = ['ocp', 'uvlo', 'ots', 'ilimit'].filter((k) => f[k]).map((k) => k.toUpperCase());
27
+ console.log('fault:', names.join(', '));
28
+ await motor.stop(); // Coast to standby, () → None
29
+ await motor.clearFault(); // Clear fault bits, () → None
30
+ }
31
+ }
32
+
33
+ async function run(voltage, seconds) {
34
+ // --- Hold a regulated voltage and watch it stay put ---
35
+ // The chip PWM-regulates the bridge against VCC internally, so the
36
+ // commanded voltage (and motor speed) holds while the battery discharges.
37
+ await motor.drive(voltage); // Drive at regulated voltage, (voltage V, signed) → None
38
+ await checkFault();
39
+ for (let i = 0; i < seconds; i++) {
40
+ await sleep(1000);
41
+ const out = await motor.readOutput(); // Read back CONTROL, () → {voltage V, direction}
42
+ console.log(`${out.direction.padEnd(7)} ${out.voltage.toFixed(2)} V`);
43
+ }
44
+ }
45
+
46
+ await run(3.0, 5);
47
+ await run(-2.0, 5);
48
+
49
+ // --- Stop quickly, then release ---
50
+ // Braking shorts the winding for a fast stop; coasting afterwards removes
51
+ // the load so the motor does not sit shorted indefinitely.
52
+ await motor.brake(); // Short-brake, () → None
53
+ await sleep(500);
54
+ await motor.stop(); // Coast to standby, () → None
55
+
56
+ await connection.close();
57
+ })();
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { DRV8830Minimal } = require('periph/src/chips/motor/drv8830');
5
+
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ (async () => {
9
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
10
+ const connection = new I2CConnection(bus, DRV8830Minimal.I2C_ADDRESS);
11
+ const motor = new DRV8830Minimal(connection); // Create DRV8830 driver, (connection)
12
+ await motor.init(); // Confirm device presence, () → None
13
+
14
+ for (let i = 0; i < 5; i++) {
15
+ await motor.drive(3.0); // Drive at regulated voltage, (voltage V, + = forward) → None
16
+ await sleep(2000);
17
+ await motor.drive(-3.0); // Drive at regulated voltage, (voltage V, - = reverse) → None
18
+ await sleep(2000);
19
+ }
20
+
21
+ await motor.stop(); // Coast to standby, () → None
22
+ await connection.close();
23
+ })();
@@ -0,0 +1,50 @@
1
+ // Complete example for the MPR121 — exercises every Full-class method.
2
+
3
+ const { MPR121Full } = require('periph/src/chips/other/mpr121');
4
+ const { I2CConnection } = require('periph/src/connection/i2c_auto');
5
+
6
+ async function main() {
7
+ const connection = new I2CConnection(0x5A); // Create I2C connection, (addr=0x5A, bus=undefined) → I2CConnection
8
+ const mpr = new MPR121Full(connection); // Construct MPR121 Full, (connection) → MPR121Full
9
+ // runs Minimal init then exposes Full configuration methods
10
+
11
+ await mpr.stop(); // Enter Stop Mode, () → Promise<void>
12
+ // required before writing most config registers
13
+ await mpr.configureThresholds(0, 15, 8); // Set thresholds, (electrode=0, touch=15, release=8) → Promise<void>
14
+ // ELE0: touch at 15 LSBs below baseline, release at 8 LSBs
15
+ await mpr.configureAllThresholds(12, 6); // Apply thresholds to all, (touch=12, release=6) → Promise<void>
16
+ // ELE1..ELE11: same touch/release values
17
+ await mpr.configureProximityThresholds(8, 4); // Set ELEPROX thresholds, (touch=8, release=4) → Promise<void>
18
+ // ELEPROX touch at 8 LSBs, release at 4
19
+ await mpr.configureBaselineFilter(1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0); // Set baseline filter, (mhdr, nhdr, nclr, fdlr, mhdf, nhdf, nclf, fdlf, nhdt, nclt, fdlt) → Promise<void>
20
+ // baseline filter defaults; tracks capacitance drift only
21
+ await mpr.configureSampling(16, 1, 0, 0, 4); // Set AFE config, (cdc=16, cdt=1, ffi=0, sfi=0, esi=4) → Promise<void>
22
+ // 16 µA global CDC, 0.5 µs charge time, 16 ms sample interval
23
+ await mpr.configureDebounce(1, 1); // Set debounce, (touch=1, release=1) → Promise<void>
24
+ // one consecutive measurement to detect touch/release
25
+ await mpr.configureAutoconfig(3300, 0, false, true, true); // Configure autoconfig, (vdd_mv=3300, retry=0, scts=false, are=true, ace=true) → Promise<void>
26
+ // recompute USL/TL/LSL for 3.3 V supply
27
+ await mpr.start(12, 2, 0); // Enter Run Mode, (n_electrodes=12, cl=2, eleprox_en=0) → Promise<void>
28
+ // all 12 electrodes, baseline init from first measurement, proximity off
29
+
30
+ const f0 = await mpr.filtered(0); // Read ELE0 filtered, (electrode=0) → Promise<number> 0..1023
31
+ // raw 10-bit value, inversely proportional to capacitance
32
+ const b0 = await mpr.baseline(0); // Read ELE0 baseline, (electrode=0) → Promise<number> 0..1023
33
+ // 8 MSBs from baseline register, shifted left 2
34
+ const oor = await mpr.oorStatus(); // Read OOR bitmask, () → Promise<number> bitmask
35
+ // bits 0..11 = ELE0..11 out-of-range
36
+ const pt = await mpr.proximityTouched(); // Read proximity touched, () → Promise<boolean>
37
+ // False: ELEPROX not enabled in this example
38
+ console.log(`ELE0 filtered=${f0} baseline=${b0} OOR=0x${oor.toString(16).padStart(4, '0')} prox_touched=${pt}`);
39
+
40
+ await mpr.enableInterrupt(MPR121Full.SOURCE_OOR); // Enable interrupt source, (source=SOURCE_OOR) → Promise<void>
41
+ // OOR will now assert INT as well as touch/release
42
+ await mpr.disableInterrupt(MPR121Full.SOURCE_OOR); // Disable interrupt source, (source=SOURCE_OOR) → Promise<void>
43
+ // OOR no longer asserts INT
44
+ await mpr.clearOvercurrent(); // Clear OVCF, () → Promise<void>
45
+ // safe no-op when overcurrent has not occurred
46
+ await mpr.reset(); // Soft reset, () → Promise<void>
47
+ // reapplies Minimal defaults; device ready for fresh use
48
+ }
49
+
50
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,30 @@
1
+ // Demo for the MPR121 — 12-button musical keyboard with IRQ-driven detection.
2
+
3
+ const { MPR121Full } = require('periph/src/chips/other/mpr121');
4
+ const { I2CConnection } = require('periph/src/connection/i2c_auto');
5
+
6
+ const NOTES = ['C4', 'C#4', 'D4', 'D#4', 'E4', 'F4', 'F#4', 'G4', 'G#4', 'A4', 'A#4', 'B4'];
7
+
8
+ async function main() {
9
+ const connection = new I2CConnection(0x5A); // Create I2C connection, (addr=0x5A, bus=undefined) → I2CConnection
10
+ const mpr = new MPR121Full(connection); // Construct MPR121 Full, (connection) → MPR121Full
11
+ // defaults, all 12 electrodes enabled
12
+
13
+ let previous = 0;
14
+ setInterval(async () => {
15
+ const mask = await mpr.touched(); // Read 12-bit touch bitmask, () → Promise<number> bitmask
16
+ const newlyPressed = mask & ~previous;
17
+ const newlyReleased = (~mask) & previous;
18
+ for (let n = 0; n < 12; n++) {
19
+ if (newlyPressed & (1 << n)) {
20
+ console.log(`NOTE ON: ${NOTES[n]}`);
21
+ }
22
+ if (newlyReleased & (1 << n)) {
23
+ console.log(`NOTE OFF: ${NOTES[n]}`);
24
+ }
25
+ }
26
+ previous = mask;
27
+ }, 50);
28
+ }
29
+
30
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,17 @@
1
+ // Minimal example for the MPR121 capacitive touch controller.
2
+
3
+ const { MPR121Minimal } = require('periph/src/chips/other/mpr121');
4
+ const { I2CConnection } = require('periph/src/connection/i2c_auto');
5
+
6
+ async function main() {
7
+ const connection = new I2CConnection(0x5A); // Create I2C connection, (addr=0x5A, bus=undefined) → I2CConnection
8
+ const mpr = new MPR121Minimal(connection); // Construct MPR121 Minimal, (connection) → MPR121Minimal
9
+ // resets, applies default thresholds (T=12, R=6), enters Run Mode on all 12 electrodes
10
+ setInterval(async () => {
11
+ const t = await mpr.touched(); // Read 12-bit touch bitmask, () → Promise<number> bitmask
12
+ // bit n=1 means ELEn is currently touched
13
+ console.log(`touched=0x${t.toString(16).padStart(3, '0')}`);
14
+ }, 1000);
15
+ }
16
+
17
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ADE7953Full } = require('../../../src/chips/power/ade7953');
5
+
6
+ const connection = new I2CConnection(1, 0x38);
7
+ const ade = new ADE7953Full(connection, 251.0, 30.0); // Create ADE7953 driver, (connection, voltage_gain=V/V, current_gain=A/V, bus_type='i2c')
8
+
9
+ (async () => {
10
+ console.log('version:', (await ade.version()).toString(16)); // Read silicon version, () → int
11
+ console.log('V=', await ade.voltage()); // Read bus voltage, () → float V
12
+ // converts raw VRMS to volts using voltage_gain
13
+ console.log('I_a=', await ade.current()); // Read load current, () → float A
14
+ // converts raw IRMSA to amperes using current_gain
15
+ console.log('P_a=', await ade.activePower()); // Read active power, () → float W
16
+ // converts raw AWATT (instantaneous, 6.99 kHz) to watts
17
+ console.log('E_a=', await ade.activeEnergy()); // Read active energy, () → float Wh
18
+ // converts raw AENERGYA accumulated LSBs to watt-hours
19
+ console.log('PF=', await ade.powerFactor()); // Read power factor, () → float
20
+ // converts raw PFA (1 LSB = 2^-15) to a −1.0..+1.0 ratio
21
+ console.log('f=', await ade.lineFrequency()); // Read line frequency, () → float Hz
22
+
23
+ await ade.configureChannelB(30.0); // Set Channel B calibration, (current_gain_b) → None
24
+ console.log('I_b=', await ade.currentB()); // Read Current Channel B, () → float A
25
+
26
+ await ade.setPga('a', 1); // Write PGA Channel A, (channel, gain) → None
27
+ // gain 1..16 (+22 valid for Channel A only)
28
+ await ade.setPhaseCalibration('a', 0.0); // Write phase calibration A, (channel, delay_s) → None
29
+ // negative delay_s advances; range ±383 × 1.117 µs
30
+ await ade.setGainCalibration(0x282, 0x400000); // Write active-power gain A, (register, value) → None
31
+ // 0x400000 = unity; valid range 0x200000..0x600000
32
+ await ade.setOffsetCalibration(0x289, 0); // Write active-power offset A, (register, value) → None
33
+ // signed 24-bit offset
34
+ console.log('checksum:', (await ade.checksum()).toString(16)); // Read CRC/checksum, () → int
35
+ await ade.enableChecksum(true); // Enable CRC/checksum, (enabled) → None
36
+
37
+ await ade.configureOvervoltage(260.0); // Configure overvoltage, (threshold) → None
38
+ // threshold in volts (same scale as voltage())
39
+ await ade.configureOvercurrent(40.0); // Configure overcurrent, (threshold) → None
40
+ // threshold in amperes; applies to BOTH current channels
41
+
42
+ await ade.reset(); // Software reset, () → None
43
+ // waits 110 ms then re-runs the mandatory power-up sequence
44
+ })();
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ADE7953Full } = require('../../../src/chips/power/ade7953');
5
+
6
+ const connection = new I2CConnection(1, 0x38);
7
+ const ade = new ADE7953Full(connection, 251.0, 30.0); // Create ADE7953 driver, (connection, voltage_gain=V/V, current_gain=A/V, bus_type='i2c')
8
+
9
+ // --- Prepare the chip: enable overcurrent interrupt and pin it to IRQ ---
10
+ // The ADE7953 exposes power-quality events via the IRQ pin. Driving
11
+ // OIA through the chip's own alert output lets the host react without
12
+ // polling every reading every cycle.
13
+ ade.configureOvercurrent(40.0); // Configure overcurrent, (threshold) → None
14
+
15
+ // --- Sample at 1 Hz and emit one structured line per cycle ---
16
+ // The energy accumulator resets on read by default (RSTREAD = 1), so
17
+ // activeEnergy() returns watt-hours accumulated since the previous
18
+ // call. Callers wanting a running total accumulate the returned deltas
19
+ // themselves (or call setReadWithReset(false) and track the 24-bit
20
+ // register's own rollovers instead).
21
+ console.log('%-10s %-10s %-10s %-12s'.replace(/%-?\d+s/g, (m) => m.padEnd(12)));
22
+ setInterval(async () => {
23
+ const v = await ade.voltage(); // Read bus voltage, () → float V
24
+ const i = await ade.current(); // Read load current, () → float A
25
+ const p = await ade.activePower(); // Read active power, () → float W
26
+ const e = await ade.activeEnergy(); // Read active energy, () → float Wh
27
+ console.log(`${v.toFixed(2).padEnd(10)} ${i.toFixed(3).padEnd(10)} ${p.toFixed(2).padEnd(10)} ${e.toFixed(5).padEnd(12)}`);
28
+ }, 1000);
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ADE7953Minimal } = require('../../../src/chips/power/ade7953');
5
+
6
+ const connection = new I2CConnection(1, 0x38);
7
+ const ade = new ADE7953Minimal(connection, 251.0, 30.0); // Create ADE7953 driver, (connection, voltage_gain=V/V, current_gain=A/V, bus_type='i2c')
8
+
9
+ setInterval(async () => {
10
+ const v = await ade.voltage(); // Read bus voltage, () → float V
11
+ const i = await ade.current(); // Read load current, () → float A
12
+ const p = await ade.activePower(); // Read active power, () → float W
13
+ const e = await ade.activeEnergy(); // Read active energy, () → float Wh
14
+ console.log(`V=${v.toFixed(2)} I=${i.toFixed(3)} P=${p.toFixed(2)} E=${e.toFixed(4)}`);
15
+ }, 1000);
@@ -1,30 +1,32 @@
1
1
  'use strict';
2
2
 
3
- const { I2CTransport } = require('../../../src/transport/i2c');
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
4
  const { INA219Full } = require('../../../src/chips/power/ina219');
5
5
 
6
6
  const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
7
  const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
8
8
 
9
- const transport = new I2CTransport(I2C_BUS, I2C_ADDR);
10
- const ina = new INA219Full(transport);
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ const ina = new INA219Full(connection);
11
11
 
12
- console.log(ina.voltage()); // Read bus voltage, () → float V
13
- console.log(ina.shuntVoltage()); // Read shunt voltage, () → float V
14
- console.log(ina.current()); // Read load current, () → float A
15
- console.log(ina.power()); // Read power, () → float W
16
- console.log(ina.conversionReady()); // Check conversion done, () → bool
17
- console.log(ina.overflow()); // Check math overflow, () → bool
12
+ (async () => {
13
+ console.log(await ina.voltage()); // Read bus voltage, () → float V
14
+ console.log(await ina.shuntVoltage()); // Read shunt voltage, () → float V
15
+ console.log(await ina.current()); // Read load current, () → float A
16
+ console.log(await ina.power()); // Read power, () → float W
17
+ console.log(await ina.conversionReady()); // Check conversion done, () → bool
18
+ console.log(await ina.overflow()); // Check math overflow, () → bool
18
19
 
19
- ina.configure(1, 3, 0x03, 0x03, 7);
20
- // Configure ADC, (brng 0–1, pga 0–3, badc 0x0F, sadc 0x0F, mode 0–7) → None
21
- // sets bus range, PGA gain, ADC resolution, and operating mode
20
+ await ina.configure(1, 3, 0x03, 0x03, 7);
21
+ // Configure ADC, (brng 0–1, pga 0–3, badc 0x0F, sadc 0x0F, mode 0–7) → None
22
+ // sets bus range, PGA gain, ADC resolution, and operating mode
22
23
 
23
- ina.shutdown(); // Put chip into power-down mode, () → None
24
- const end = Date.now() + 1;
25
- while (Date.now() < end) {}
26
- ina.wake(); // Restore previous operating mode, () → None
24
+ await ina.shutdown(); // Put chip into power-down mode, () → None
25
+ const end = Date.now() + 1;
26
+ while (Date.now() < end) {}
27
+ await ina.wake(); // Restore previous operating mode, () → None
27
28
 
28
- ina.reset(); // Reset all registers and re-write calibration, () → None
29
+ await ina.reset(); // Reset all registers and re-write calibration, () → None
29
30
 
30
- transport.close();
31
+ await connection.close();
32
+ })();
@@ -1,26 +1,28 @@
1
1
  'use strict';
2
2
 
3
- const { I2CTransport } = require('../../../src/transport/i2c');
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
4
  const { INA219Full } = require('../../../src/chips/power/ina219');
5
5
 
6
6
  const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
7
  const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
8
8
 
9
- const transport = new I2CTransport(I2C_BUS, I2C_ADDR);
10
- const ina = new INA219Full(transport);
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ const ina = new INA219Full(connection);
11
11
 
12
12
  // --- Configure for noise-sensitive power rail monitoring ---
13
13
  // 128-sample averaging suppresses switching noise on a noisy 5 V rail;
14
14
  // continuous mode avoids re-triggering overhead between measurements.
15
- ina.configure(1, 3, 0x0F, 0x0F, 7);
16
- // Configure ADC, (brng 0–1, pga 0–3, badc 0x0F, sadc 0x0F, mode 0–7) → None
15
+ (async () => {
16
+ await ina.configure(1, 3, 0x0F, 0x0F, 7);
17
+ // Configure ADC, (brng 0–1, pga 0–3, badc 0x0F, sadc 0x0F, mode 0–7) → None
17
18
 
18
- console.log('V A W');
19
+ console.log('V A W');
19
20
 
20
- setInterval(() => {
21
- while (!ina.conversionReady()) {} // Check conversion done, () → bool
22
- const v = ina.voltage(); // Read bus voltage, () → float V
23
- const i = ina.current(); // Read load current, () → float A
24
- const p = ina.power(); // Read power, () → float W
25
- console.log(`${v.toFixed(3)} V ${i.toFixed(4)} A ${p.toFixed(4)} W`);
26
- }, 1000);
21
+ setInterval(async () => {
22
+ while (!(await ina.conversionReady())) {} // Check conversion done, () → bool
23
+ const v = await ina.voltage(); // Read bus voltage, () → float V
24
+ const i = await ina.current(); // Read load current, () → float A
25
+ const p = await ina.power(); // Read power, () → float W
26
+ console.log(`${v.toFixed(3)} V ${i.toFixed(4)} A ${p.toFixed(4)} W`);
27
+ }, 1000);
28
+ })();
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
- const { I2CTransport } = require('../../../src/transport/i2c');
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
4
  const { INA219Minimal } = require('../../../src/chips/power/ina219');
5
5
 
6
6
  const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
7
  const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
8
8
 
9
- const transport = new I2CTransport(I2C_BUS, I2C_ADDR);
10
- const ina = new INA219Minimal(transport);
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ const ina = new INA219Minimal(connection);
11
11
 
12
- setInterval(() => {
13
- const v = ina.voltage(); // Read bus voltage, () → float V
14
- const i = ina.current(); // Read load current, () → float A
15
- const p = ina.power(); // Read power, () → float W
12
+ setInterval(async () => {
13
+ const v = await ina.voltage(); // Read bus voltage, () → float V
14
+ const i = await ina.current(); // Read load current, () → float A
15
+ const p = await ina.power(); // Read power, () → float W
16
16
  console.log(`${v.toFixed(3)} V ${i.toFixed(4)} A ${p.toFixed(4)} W`);
17
- }, 1000);
17
+ }, 1000);
@@ -1,33 +1,35 @@
1
1
  'use strict';
2
2
 
3
- const { I2CTransport } = require('../../../src/transport/i2c');
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
4
  const { INA226Full } = require('../../../src/chips/power/ina226');
5
5
 
6
- const transport = new I2CTransport(1, 0x40);
7
- const ina = new INA226Full(transport);
6
+ const connection = new I2CConnection(1, 0x40);
7
+ const ina = new INA226Full(connection);
8
8
 
9
- console.log('0x' + ina.manufacturerId().toString(16));
10
- console.log('0x' + ina.dieId().toString(16));
9
+ (async () => {
10
+ console.log('0x' + (await ina.manufacturerId()).toString(16));
11
+ console.log('0x' + (await ina.dieId()).toString(16));
11
12
 
12
- console.log(ina.voltage());
13
- console.log(ina.shuntVoltage());
14
- console.log(ina.current());
15
- console.log(ina.power());
16
- console.log(ina.conversionReady());
17
- console.log(ina.overflow());
13
+ console.log(await ina.voltage());
14
+ console.log(await ina.shuntVoltage());
15
+ console.log(await ina.current());
16
+ console.log(await ina.power());
17
+ console.log(await ina.conversionReady());
18
+ console.log(await ina.overflow());
18
19
 
19
- ina.configure(3, 4, 4, 7);
20
+ await ina.configure(3, 4, 4, 7);
20
21
 
21
- ina.setAlert(INA226Full.POL, 1.0, false, true);
22
- console.log('0x' + ina.alertFlags().toString(16));
22
+ await ina.setAlert(INA226Full.POL, 1.0, false, true);
23
+ console.log('0x' + (await ina.alertFlags()).toString(16));
23
24
 
24
- ina.setAlert(INA226Full.BOL, 5.5);
25
- ina.setAlert(INA226Full.BUL, 4.5);
26
- ina.setAlert(INA226Full.SOL, 0.05);
27
- ina.setAlert(INA226Full.CNVR);
25
+ await ina.setAlert(INA226Full.BOL, 5.5);
26
+ await ina.setAlert(INA226Full.BUL, 4.5);
27
+ await ina.setAlert(INA226Full.SOL, 0.05);
28
+ await ina.setAlert(INA226Full.CNVR);
28
29
 
29
- ina.shutdown();
30
- ina.wake();
31
- ina.reset();
30
+ await ina.shutdown();
31
+ await ina.wake();
32
+ await ina.reset();
32
33
 
33
- transport.close();
34
+ await connection.close();
35
+ })();