periph 1.1.0 → 1.2.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 (231) hide show
  1. package/README.md +54 -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/other/mpr121/complete.js +50 -0
  117. package/examples/other/mpr121/demo.js +30 -0
  118. package/examples/other/mpr121/minimal.js +17 -0
  119. package/examples/power/ade7953/complete.js +44 -0
  120. package/examples/power/ade7953/demo.js +28 -0
  121. package/examples/power/ade7953/minimal.js +15 -0
  122. package/examples/power/ina219/complete.js +20 -18
  123. package/examples/power/ina219/demo.js +15 -13
  124. package/examples/power/ina219/minimal.js +8 -8
  125. package/examples/power/ina226/complete.js +24 -22
  126. package/examples/power/ina226/demo.js +22 -20
  127. package/examples/power/ina226/minimal.js +5 -5
  128. package/examples/power/ina3221/complete.js +51 -49
  129. package/examples/power/ina3221/demo.js +13 -13
  130. package/examples/power/ina3221/minimal.js +8 -8
  131. package/examples/pressure/bmp085/complete.js +29 -0
  132. package/examples/pressure/bmp085/demo.js +34 -0
  133. package/examples/pressure/bmp085/minimal.js +19 -0
  134. package/examples/pressure/bmp180/complete.js +20 -17
  135. package/examples/pressure/bmp180/demo.js +24 -22
  136. package/examples/pressure/bmp180/minimal.js +13 -11
  137. package/examples/pressure/bmp280/complete.js +23 -20
  138. package/examples/pressure/bmp280/demo.js +44 -41
  139. package/examples/pressure/bmp280/minimal.js +13 -11
  140. package/examples/pressure/bmp384/complete.js +29 -0
  141. package/examples/pressure/bmp384/demo.js +40 -0
  142. package/examples/pressure/bmp384/minimal.js +18 -0
  143. package/examples/pressure/bmp581/complete.js +34 -0
  144. package/examples/pressure/bmp581/demo.js +56 -0
  145. package/examples/pressure/bmp581/minimal.js +19 -0
  146. package/examples/pressure/lps22df/complete.js +50 -0
  147. package/examples/pressure/lps22df/demo.js +41 -0
  148. package/examples/pressure/lps22df/minimal.js +19 -0
  149. package/examples/pressure/lps28dfw/complete.js +37 -0
  150. package/examples/pressure/lps28dfw/demo.js +33 -0
  151. package/examples/pressure/lps28dfw/minimal.js +19 -0
  152. package/examples/pressure/lps33hw/complete.js +43 -0
  153. package/examples/pressure/lps33hw/demo.js +43 -0
  154. package/examples/pressure/lps33hw/minimal.js +19 -0
  155. package/examples/rfid/mfrc522/complete.js +44 -0
  156. package/examples/rfid/mfrc522/demo.js +70 -0
  157. package/examples/rfid/mfrc522/minimal.js +17 -0
  158. package/package.json +5 -1
  159. package/src/chips/accelerometer/adxl345.js +482 -0
  160. package/src/chips/accelerometer/adxl362.js +594 -0
  161. package/src/chips/adc_dac/ad7705.js +345 -0
  162. package/src/chips/adc_dac/ad7706.js +331 -0
  163. package/src/chips/adc_dac/hx710a.js +184 -0
  164. package/src/chips/adc_dac/hx710b.js +186 -0
  165. package/src/chips/adc_dac/hx711.js +15 -15
  166. package/src/chips/adc_dac/mcp4725.js +48 -40
  167. package/src/chips/adc_dac/mcp4728.js +57 -44
  168. package/src/chips/adc_dac/pcf8591.js +196 -0
  169. package/src/chips/comms/mcp2515.js +659 -0
  170. package/src/chips/comms/rda5807m.js +393 -0
  171. package/src/chips/comms/rfm9x.js +590 -0
  172. package/src/chips/display/pcf8576.js +42 -33
  173. package/src/chips/environmental/aht21.js +52 -37
  174. package/src/chips/environmental/bme280.js +85 -66
  175. package/src/chips/environmental/bme680.js +110 -87
  176. package/src/chips/gas/ens160.js +82 -64
  177. package/src/chips/gnss/neo6.js +438 -0
  178. package/src/chips/gyroscope/l3g4200d.js +366 -0
  179. package/src/chips/gyroscope/l3gd20h.js +314 -0
  180. package/src/chips/humidity/dht11.js +135 -0
  181. package/src/chips/imu/mpu6050.js +89 -66
  182. package/src/chips/imu/mpu9250.js +394 -0
  183. package/src/chips/imu/mpu9255.js +447 -0
  184. package/src/chips/io_expander/mcp23017.js +240 -157
  185. package/src/chips/io_expander/pcf8574.js +149 -124
  186. package/src/chips/io_expander/pcf8575.js +164 -135
  187. package/src/chips/io_expander/tpic6b595.js +242 -0
  188. package/src/chips/led/_NeoPixelRGBBase.js +204 -0
  189. package/src/chips/led/_NeoPixelRGBWBase.js +218 -0
  190. package/src/chips/led/apa102.js +236 -0
  191. package/src/chips/led/sk6812rgbw.js +15 -149
  192. package/src/chips/led/ws2812b.js +14 -139
  193. package/src/chips/led/ws2814.js +49 -0
  194. package/src/chips/light/apds-9930.js +342 -0
  195. package/src/chips/light/apds9960.js +158 -123
  196. package/src/chips/magnetometer/as5600.js +102 -82
  197. package/src/chips/magnetometer/hmc5883l.js +222 -0
  198. package/src/chips/memory/_24aa02uid.js +32 -29
  199. package/src/chips/other/mpr121.js +375 -0
  200. package/src/chips/power/ade7953.js +427 -0
  201. package/src/chips/power/ina219.js +45 -40
  202. package/src/chips/power/ina226.js +50 -45
  203. package/src/chips/power/ina3221.js +95 -76
  204. package/src/chips/pressure/bmp085.js +251 -0
  205. package/src/chips/pressure/bmp180.js +54 -37
  206. package/src/chips/pressure/bmp280.js +72 -53
  207. package/src/chips/pressure/bmp384.js +410 -0
  208. package/src/chips/pressure/bmp581.js +489 -0
  209. package/src/chips/pressure/lps22df.js +341 -0
  210. package/src/chips/pressure/lps28dfw.js +314 -0
  211. package/src/chips/pressure/lps33hw.js +255 -0
  212. package/src/chips/rfid/mfrc522.js +674 -0
  213. package/src/connection/connection.js +111 -0
  214. package/src/connection/dhtxx.js +138 -0
  215. package/src/connection/dhtxx_mock.js +39 -0
  216. package/src/{transport → connection}/hx711.js +49 -22
  217. package/src/connection/hx711_mock.js +52 -0
  218. package/src/{transport → connection}/i2c.js +13 -9
  219. package/src/connection/i2c_mock.js +91 -0
  220. package/src/connection/input_pin.js +156 -0
  221. package/src/connection/neo6_mock.js +45 -0
  222. package/src/{transport → connection}/neopixel.js +23 -4
  223. package/src/connection/output_pin.js +41 -0
  224. package/src/connection/sipo.js +159 -0
  225. package/src/{transport → connection}/smbus.js +14 -10
  226. package/src/{transport → connection}/spi.js +12 -8
  227. package/src/connection/spi_mock.js +151 -0
  228. package/src/{transport → connection}/uart.js +33 -26
  229. package/examples/gnss/.gitkeep +0 -0
  230. package/examples/humidity/.gitkeep +0 -0
  231. package/src/chips/gnss/.gitkeep +0 -0
@@ -1,33 +1,37 @@
1
1
  'use strict';
2
2
  const { Pcf8575Full } = require('../../src/chips/io_expander/pcf8575');
3
3
 
4
- const transport = {
5
- write: (buf) => { /* LED write */ },
6
- read: (len) => { return Buffer.from([0xFF, 0xFF]); }
4
+ const connection = {
5
+ async write(buf) { /* LED write */ },
6
+ async read(len) { return Buffer.from([0xFF, 0xFF]); }
7
7
  };
8
8
 
9
- const chip = new Pcf8575Full(transport, 0x20); // Create PCF8575 full driver, (transport, addr=0x20)
9
+ async function main() {
10
+ const chip = new Pcf8575Full(connection, 0x20); // Create PCF8575 full driver, (connection, addr=0x20)
10
11
 
11
- chip.writePort(0, 0xFF); // Write Port 0, (port=0, mask=int) → void
12
- chip.writePort(1, 0xFF); // Write Port 1, (port=1, mask=int) → void
12
+ await chip.writePort(0, 0xFF); // Write Port 0, (port=0, mask=int) → Promise<void>
13
+ await chip.writePort(1, 0xFF); // Write Port 1, (port=1, mask=int) → Promise<void>
13
14
 
14
- chip.configureInterrupt(null, (changed) => { // Attach interrupt, (int_gpio_path|null, callback) → void
15
- console.log('changed:', changed);
16
- });
15
+ await chip.onInterrupt((changed) => { // Subscribe to INT line, (callback, options) → Promise<void>
16
+ console.log('changed:', changed);
17
+ });
17
18
 
18
- console.log('Running — buttons on P10–P17 mirror to LEDs on P00–P07');
19
- setInterval(() => {
20
- const port0 = chip.readPort(0); // Read Port 0, (port=0) → int bitmask
21
- const port1 = chip.readPort(1); // Read Port 1, (port=1) → int bitmask
19
+ console.log('Running — buttons on P10–P17 mirror to LEDs on P00–P07');
20
+ setInterval(async () => {
21
+ const port0 = await chip.readPort(0); // Read Port 0, (port=0) → Promise<int bitmask>
22
+ const port1 = await chip.readPort(1); // Read Port 1, (port=1) → Promise<int bitmask>
22
23
 
23
- const buttons = port1 & 0xFF; // P10–P17 (pressed = 0)
24
- const led_bits = (~buttons) & 0xFF; // invert: pressed → LED on (0)
25
- chip.writePort(0, led_bits); // Write Port 0, (port=0, mask=int) → void
24
+ const buttons = port1 & 0xFF; // P10–P17 (pressed = 0)
25
+ const led_bits = (~buttons) & 0xFF; // invert: pressed → LED on (0)
26
+ await chip.writePort(0, led_bits); // Write Port 0, (port=0, mask=int) → Promise<void>
26
27
 
27
- console.log(
28
- 'P0=0x' + port0.toString(16).padStart(2, '0') +
29
- ' P1=0x' + port1.toString(16).padStart(2, '0') +
30
- ' buttons=' + Array.from({length: 8}, (_, i) => (buttons >> (7 - i)) & 1 ? '.' : 'X').join('') +
31
- ' LEDs=' + Array.from({length: 8}, (_, i) => (led_bits >> (7 - i)) & 1 ? ' ' : '*').join('')
32
- );
33
- }, 200);
28
+ console.log(
29
+ 'P0=0x' + port0.toString(16).padStart(2, '0') +
30
+ ' P1=0x' + port1.toString(16).padStart(2, '0') +
31
+ ' buttons=' + Array.from({length: 8}, (_, i) => (buttons >> (7 - i)) & 1 ? '.' : 'X').join('') +
32
+ ' LEDs=' + Array.from({length: 8}, (_, i) => (led_bits >> (7 - i)) & 1 ? ' ' : '*').join('')
33
+ );
34
+ }, 200);
35
+ }
36
+
37
+ main();
@@ -1,20 +1,24 @@
1
1
  'use strict';
2
2
  const { Pcf8575Minimal } = require('../../src/chips/io_expander/pcf8575');
3
3
 
4
- const transport = { // Mock transport for example
5
- write: (buf) => { console.log('write', buf); },
6
- read: (len) => { return Buffer.from([0xFF, 0xFF]); }
4
+ const connection = { // Mock connection for example
5
+ async write(buf) { console.log('write', buf); },
6
+ async read(len) { return Buffer.from([0xFF, 0xFF]); }
7
7
  };
8
8
 
9
- const chip = new Pcf8575Minimal(transport, 0x20); // Create PCF8575 driver, (transport, addr=0x20)
9
+ async function main() {
10
+ const chip = new Pcf8575Minimal(connection, 0x20); // Create PCF8575 driver, (connection, addr=0x20)
10
11
 
11
- const p0 = chip.pin(0); // Get pin proxy, (n=0) → Pin
12
- const p8 = chip.pin(8); // Get pin proxy, (n=8) → Pin
12
+ const p0 = chip.pin(0); // Get pin proxy, (n=0) → Pin
13
+ const p8 = chip.pin(8); // Get pin proxy, (n=8) → Pin
13
14
 
14
- p0.writeSync(0); // Write pin, (value=0|1) → void
15
- const v = p0.readSync(); // Read pin, () → 0|1
16
- console.log('pin0 value:', v);
15
+ await p0.write(0); // Write pin, (value=0|1) → Promise<void>
16
+ const v = await p0.read(); // Read pin, () → Promise<0|1>
17
+ console.log('pin0 value:', v);
17
18
 
18
- const port0 = chip.readPort(0); // Read Port 0, (port=0) → int bitmask
19
- const port1 = chip.readPort(1); // Read Port 1, (port=1) → int bitmask
20
- console.log('port0:', port0, 'port1:', port1);
19
+ const port0 = await chip.readPort(0); // Read Port 0, (port=0) → Promise<int bitmask>
20
+ const port1 = await chip.readPort(1); // Read Port 1, (port=1) → Promise<int bitmask>
21
+ console.log('port0:', port0, 'port1:', port1);
22
+ }
23
+
24
+ main();
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ const opengpio = require('opengpio');
4
+ const { SiPoConnection } = require('../../../src/connection/sipo');
5
+ const { Tpic6b595Minimal, Tpic6b595Full } = require('../../../src/chips/io_expander/tpic6b595');
6
+
7
+ async function main() {
8
+ const rck = new opengpio.Output(17); // Open RCK GPIO, (line=17)
9
+ const srclr = new opengpio.Output(16); // Open SRCLR GPIO, (line=16)
10
+ const g = new opengpio.Output(15); // Open G GPIO, (line=15)
11
+ const connection = new SiPoConnection(rck, { srclr, g }); // Create SiPo connection, (rck, srclr, g)
12
+ const chip = new Tpic6b595Full(connection, 2); // Create TPIC6B595 full driver, (connection, numDevices=2)
13
+ // two cascaded devices — 16 outputs total (DRAIN0..DRAIN15)
14
+
15
+ // --- Pin-level control ---
16
+ const p0 = chip.pin(0); // Get pin proxy for DRAIN0 of device 0, (n=0) → Pin
17
+ await p0.on(); // Set DRAIN0 ON, () → Promise<void>
18
+ // sets shadow[0] bit 0, reverses the cascade, shifts out and pulses RCK
19
+ await p0.off(); // Set DRAIN0 OFF, () → Promise<void>
20
+ // clears shadow[0] bit 0, retransmits and latches
21
+ await p0.toggle(); // Invert shadow bit, () → Promise<void>
22
+
23
+ const state = await p0.read(); // Read pin state, () → Promise<number>
24
+ // returns the shadow bit (no bus read — SiPo is write-only)
25
+ await p0.write(1); // Write pin high, (value=1) → Promise<void>
26
+ // equivalent to on(); updates shadow, retransmits, latches
27
+ await p0.set(true); // OutputPin set, (high=true) → Promise<void>
28
+ // same path as on()/write(1), but matches the OutputPin contract
29
+
30
+ // --- Port-level bulk write ---
31
+ await chip.writePort(0, 0xAA); // Write device 0 outputs, (port=0, mask=0xAA) → Promise<void>
32
+ // sets DRAIN{1,3,5,7} ON, DRAIN{0,2,4,6} OFF; preserves device 1
33
+ await chip.writePort(1, 0x55); // Write device 1 outputs, (port=1, mask=0x55) → Promise<void>
34
+
35
+ // --- Bulk fill / off ---
36
+ await chip.fill(true); // Set every output ON, (value=true) → Promise<void>
37
+ // fills every shadow byte with 0xFF and retransmits — fast "all on" path
38
+ await chip.fill(false); // Set every output OFF, (value=false) → Promise<void>
39
+ // fills every shadow byte with 0x00 and retransmits — fast "all off" path
40
+ await chip.off(); // Turn every output off, () → Promise<void>
41
+ // shorthand for fill(false); the safe initial state
42
+
43
+ // --- Multi-device bulk write ---
44
+ await chip.writeAll([0x01, 0x80]); // Write all device bytes, (values=[0x01, 0x80]) → void
45
+ // updates both shadow bytes and performs one transmit + latch
46
+
47
+ // --- Hardware features (Full only) ---
48
+ chip.clear(); // Pulse SRCLR, () → void
49
+ // clears the shift register only; outputs unaffected until next RCK pulse
50
+ chip.setOutputEnable(false); // Force every output off via G, (enabled=false) → void
51
+ // drives G HIGH, blanking outputs without disturbing the shadow register
52
+ await new Promise(r => setTimeout(r, 100));
53
+ chip.setOutputEnable(true); // Re-enable outputs, (enabled=true) → void
54
+ // drives G LOW; outputs resume from the previously-latched state
55
+ }
56
+
57
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,75 @@
1
+ // TPIC6B595 demo — "knight rider" chase pattern across two cascaded devices.
2
+ //
3
+ // Hardware:
4
+ // Two cascaded TPIC6B595s driving 16 LEDs as an automotive-cluster-style
5
+ // indicator bank (DRAIN0..DRAIN7 on each device). Each LED's anode goes to
6
+ // the supply through a series resistor and its cathode to a DRAIN pin;
7
+ // writing 1 turns the LED on (active-low via the DMOS sink).
8
+ //
9
+ // The demo walks a single lit LED back and forth across all 16 outputs and,
10
+ // every few sweeps, blanks every output for half a second via
11
+ // setOutputEnable(false) to demonstrate glitch-free global blanking. The
12
+ // shadow register is untouched across the blank, so the chase pattern resumes
13
+ // exactly where it left off.
14
+ 'use strict';
15
+
16
+ const opengpio = require('opengpio');
17
+ const { SiPoConnection } = require('../../../src/connection/sipo');
18
+ const { Tpic6b595Full } = require('../../../src/chips/io_expander/tpic6b595');
19
+
20
+ const NUM_DEVICES = 2;
21
+ const NUM_OUTPUTS = NUM_DEVICES * 8;
22
+
23
+ async function main() {
24
+ const rck = new opengpio.Output(17); // Open RCK GPIO, (line=17)
25
+ const srclr = new opengpio.Output(16); // Open SRCLR GPIO, (line=16)
26
+ const g = new opengpio.Output(15); // Open G GPIO, (line=15)
27
+ const connection = new SiPoConnection(rck, { srclr, g }); // Create SiPo connection, (rck, srclr, g)
28
+ const chip = new Tpic6b595Full(connection, NUM_DEVICES); // Create TPIC6B595 full driver, (connection, numDevices=2)
29
+ // two cascaded devices — 16 outputs total; outputs start OFF
30
+
31
+ let position = 0;
32
+ let direction = 1;
33
+ let sweepCount = 0;
34
+ const BLANK_EVERY = 3;
35
+ const BLANK_MS = 500;
36
+
37
+ while (true) {
38
+ // --- Walk a single lit LED across all 16 outputs and back ---
39
+ // Use writeAll() each step so both cascaded devices latch together —
40
+ // there is no way to update just one downstream device without re-sending
41
+ // the whole chain's data.
42
+ const bytes = new Uint8Array(NUM_DEVICES);
43
+ const port = Math.floor(position / 8);
44
+ const bit = position % 8;
45
+ bytes[port] = 1 << bit;
46
+ chip.writeAll(bytes); // Write all device bytes, (values=[0x01, 0x80]) → void
47
+
48
+ console.log(`position=${position} device=${port} bit=${bit} bytes=[0x${bytes[0].toString(16).padStart(2, '0')}, 0x${bytes[1].toString(16).padStart(2, '0')}]`);
49
+
50
+ // --- Periodically blank every output via G, then resume ---
51
+ // setOutputEnable(false) drives G HIGH, forcing every DMOS off without
52
+ // touching the shadow register — the LEDs simply resume exactly where they
53
+ // left off when G is re-enabled.
54
+ sweepCount++;
55
+ if (sweepCount % BLANK_EVERY === 0) {
56
+ chip.setOutputEnable(false); // Force every output off via G, (enabled=false) → void
57
+ // the chase pattern's shadow state is preserved
58
+ console.log(` blanked via G for ${BLANK_MS} ms`);
59
+ await new Promise(r => setTimeout(r, BLANK_MS));
60
+ chip.setOutputEnable(true); // Re-enable outputs, (enabled=true) → void
61
+ // LEDs resume from the previously-latched state
62
+ }
63
+
64
+ // Bounce the chase position at both ends of the strip
65
+ position += direction;
66
+ if (position >= NUM_OUTPUTS - 1 || position <= 0) {
67
+ direction = -direction;
68
+ await new Promise(r => setTimeout(r, 100));
69
+ } else {
70
+ await new Promise(r => setTimeout(r, 80));
71
+ }
72
+ }
73
+ }
74
+
75
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ const opengpio = require('opengpio');
4
+ const { SiPoConnection } = require('../../../src/connection/sipo');
5
+ const { Tpic6b595Minimal } = require('../../../src/chips/io_expander/tpic6b595');
6
+
7
+ async function main() {
8
+ const rck = new opengpio.Output(17); // Open RCK GPIO, (line=17)
9
+ const connection = new SiPoConnection(rck); // Create SiPo connection, (rck, srclr=null, g=null)
10
+ const chip = new Tpic6b595Minimal(connection, 1); // Create TPIC6B595 driver, (connection, numDevices=1)
11
+ // initialises every output to OFF (shadow zeroed, latched once)
12
+
13
+ const p0 = chip.pin(0); // Get pin proxy, (n=0) → Pin
14
+ const p7 = chip.pin(7); // Get pin proxy, (n=7) → Pin
15
+
16
+ while (true) {
17
+ await p0.on(); // Set DMOS output ON, () → Promise<void>
18
+ await p7.off(); // Set DMOS output OFF, () → Promise<void>
19
+ await new Promise(r => setTimeout(r, 500));
20
+ await p0.off(); // Set DMOS output OFF, () → Promise<void>
21
+ await p7.on(); // Set DMOS output ON, () → Promise<void>
22
+ await new Promise(r => setTimeout(r, 500));
23
+ }
24
+ }
25
+
26
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ const { SPIConnection } = require('../../../src/connection/spi');
4
+ const { APA102Full } = require('../../../src/chips/led/apa102');
5
+
6
+ const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
7
+ const SPI_DEVICE = parseInt(process.env.SPI_DEVICE || '0', 10);
8
+
9
+ const connection = new SPIConnection(SPI_BUS, SPI_DEVICE, { mode: 0, maxSpeedHz: 1_000_000 }); // Create SPI connection, (busNumber, deviceNumber, mode=0, 1MHz)
10
+ const strip = new APA102Full(connection, 8); // Create APA102 full driver, (connection, n=8 pixels)
11
+
12
+ (async () => {
13
+ // fill — set all pixels and send immediately
14
+ await strip.fill(255, 0, 0); // Fill all pixels with one colour, (r=0–255, g=0–255, b=0–255) → void
15
+ // stores brightness/B/G/R in buffer and calls connection.write()
16
+
17
+ // set individual pixels then show
18
+ strip.set_pixel(0, 255, 0, 0); // Set pixel 0 to red (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, pixel_brightness=0–31) → void
19
+ // writes brightness, B, G, R bytes into internal buffer at position index*4
20
+ strip.set_pixel(1, 0, 255, 0); // Set pixel 1 to green (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, pixel_brightness=0–31) → void
21
+ // writes brightness, B, G, R bytes into internal buffer at position index*4
22
+ strip.set_pixel(2, 0, 0, 255); // Set pixel 2 to blue (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, pixel_brightness=0–31) → void
23
+ // writes brightness, B, G, R bytes into internal buffer at position index*4
24
+ await strip.show(); // Transmit buffer to strip, () → void
25
+ // applies software brightness scaling then calls connection.write()
26
+
27
+ // set_pixels — write multiple pixels at once
28
+ strip.set_pixels([[255,0,0],[0,255,0],[0,0,255], // Set pixels from array of [r,g,b] or [r,g,b,brightness], (colors=Array<[r,g,b]|[r,g,b,brightness]>) → void
29
+ [255,255,0],[0,255,255],[255,0,255],
30
+ [128,128,128],[255,255,255]]);
31
+ // writes entries sequentially from pixel 0; ignores extras beyond strip length
32
+ await strip.show(); // Transmit buffer to strip, () → void
33
+ // applies software brightness scaling then calls connection.write()
34
+
35
+ // set_pixels with per-pixel hardware brightness
36
+ strip.set_pixels([[255,0,0,31],[255,0,0,16],[255,0,0,8],[255,0,0,4], // Set pixels with varying hardware brightness, (colors=Array<[r,g,b,brightness]>) → void
37
+ [0,255,0,31],[0,255,0,16],[0,255,0,8],[0,255,0,4]]);
38
+ await strip.show(); // Transmit buffer to strip, () → void
39
+ // applies software brightness scaling then calls connection.write()
40
+
41
+ // brightness — global software scale applied at show() time
42
+ strip.brightness = 64; // Set global software brightness, (value=0–255)
43
+ // stored RGB value is scaled: sent = stored * brightness / 255; hardware brightness byte unchanged
44
+ await strip.show(); // Transmit buffer to strip, () → void
45
+ // applies software brightness scaling then calls connection.write()
46
+ strip.brightness = 255; // Set global software brightness, (value=0–255)
47
+ // stored RGB value is scaled: sent = stored * brightness / 255; hardware brightness byte unchanged
48
+
49
+ // fill_hsv — fill all pixels from HSV colour
50
+ await strip.fill_hsv(0.0, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
51
+ // converts HSV to RGB then calls fill(); hue 0.0 = red
52
+ await strip.fill_hsv(0.333, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
53
+ // converts HSV to RGB then calls fill(); hue 0.333 = green
54
+ await strip.fill_hsv(0.667, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
55
+ // converts HSV to RGB then calls fill(); hue 0.667 = blue
56
+
57
+ // rotate — shift pixel buffer left, then show
58
+ strip.set_pixels([[255, 0, 0], ...Array(7).fill([0, 0, 0])]); // Set pixels from array of [r,g,b], (colors=Array<[r,g,b]>) → void
59
+ // writes entries sequentially from pixel 0; ignores extras beyond strip length
60
+ await strip.show(); // Transmit buffer to strip, () → void
61
+ // applies software brightness scaling then calls connection.write()
62
+ for (let i = 0; i < 7; i++) {
63
+ strip.rotate(1); // Rotate pixel buffer left, (steps=1) → void
64
+ // shifts buffer by steps pixel positions; wraps around; does not send
65
+ await strip.show(); // Transmit buffer to strip, () → void
66
+ // applies software brightness scaling then calls connection.write()
67
+ }
68
+
69
+ await strip.off(); // Turn off all pixels, () → void
70
+ // equivalent to fill(0, 0, 0)
71
+ await connection.close();
72
+ })();
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+
3
+ const { SPIConnection } = require('../../../src/connection/spi');
4
+ const { APA102Full } = require('../../../src/chips/led/apa102');
5
+
6
+ const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
7
+ const SPI_DEVICE = parseInt(process.env.SPI_DEVICE || '0', 10);
8
+ const N_PIXELS = parseInt(process.env.N_PIXELS || '30', 10);
9
+ const FRAME_MS = 16; // ~60 fps
10
+ const RAINBOW_MS = 10000;
11
+
12
+ const connection = new SPIConnection(SPI_BUS, SPI_DEVICE, { mode: 0, maxSpeedHz: 1_000_000 }); // Create SPI connection, (busNumber, deviceNumber, mode=0, 1MHz)
13
+ const strip = new APA102Full(connection, N_PIXELS); // Create APA102 full driver, (connection, n=N_PIXELS pixels)
14
+
15
+ function hsvToRgb(h, s, v) {
16
+ if (s === 0) { const c = Math.round(v * 255); return [c, c, c]; }
17
+ const i = Math.floor(h * 6);
18
+ const f = h * 6 - i;
19
+ const p = Math.round(v * (1 - s) * 255);
20
+ const q = Math.round(v * (1 - s * f) * 255);
21
+ const t = Math.round(v * (1 - s * (1 - f)) * 255);
22
+ const vv = Math.round(v * 255);
23
+ switch (i % 6) {
24
+ case 0: return [vv, t, p];
25
+ case 1: return [q, vv, p];
26
+ case 2: return [p, vv, t];
27
+ case 3: return [p, q, vv];
28
+ case 4: return [t, p, vv];
29
+ default: return [vv, p, q];
30
+ }
31
+ }
32
+
33
+ // --- 13-bit effective color depth demonstration ---
34
+ // First pass: full hardware brightness (31) for maximum drive current
35
+ // Second pass: hardware brightness 1 (1/31 current) to show hardware vs software dimming
36
+
37
+ let hueOffset = 0;
38
+ let lastPrint = Date.now();
39
+
40
+ async function rainbowFrame(hwBrightness, label) {
41
+ for (let i = 0; i < N_PIXELS; i++) {
42
+ const h = (hueOffset + i / N_PIXELS) % 1.0;
43
+ const [r, g, b] = hsvToRgb(h, 1.0, 1.0);
44
+ strip.set_pixel(i, r, g, b, hwBrightness); // Set pixel i to rainbow hue at hw brightness, (index=0–n-1, r=0–255, g=0–255, b=0–255, pixel_brightness=0–31) → void
45
+ }
46
+ await strip.show(); // Transmit buffer to strip, () → void
47
+ // applies software brightness scaling then calls connection.write()
48
+ hueOffset = (hueOffset + 1.0 / (N_PIXELS * 2)) % 1.0;
49
+ const now = Date.now();
50
+ if (now - lastPrint >= 1000) {
51
+ console.log(label + ' hue_offset=' + hueOffset.toFixed(3));
52
+ lastPrint = now;
53
+ }
54
+ }
55
+
56
+ // --- Pass 1: Full hardware brightness (31) ---
57
+ // Rainbow sweep at hardware brightness 31 uses full 8-bit PWM channels + 5-bit
58
+ // hardware current control = 13-bit effective depth per channel.
59
+ strip.brightness = 255; // Set global software brightness, (value=0–255)
60
+ const rainbowStart1 = Date.now();
61
+ const rainbowTimer1 = setInterval(async () => {
62
+ await rainbowFrame(31, 'rainbow hw_brightness=31');
63
+ if (Date.now() - rainbowStart1 >= RAINBOW_MS) {
64
+ clearInterval(rainbowTimer1);
65
+ startPass2();
66
+ }
67
+ }, FRAME_MS);
68
+
69
+ // --- Pass 2: Low hardware brightness (1) ---
70
+ // Same 8-bit RGB values but hardware brightness=1 (1/31 drive current).
71
+ // Demonstrates hardware current control vs software brightness scaling.
72
+ async function startPass2() {
73
+ strip.brightness = 255; // Set global software brightness, (value=0–255)
74
+ hueOffset = 0;
75
+ lastPrint = Date.now();
76
+ const rainbowStart2 = Date.now();
77
+ const rainbowTimer2 = setInterval(async () => {
78
+ await rainbowFrame(1, 'rainbow hw_brightness=1');
79
+ if (Date.now() - rainbowStart2 >= RAINBOW_MS) {
80
+ clearInterval(rainbowTimer2);
81
+ await strip.off(); // Turn off all pixels, () → void
82
+ await connection.close();
83
+ process.exit(0);
84
+ }
85
+ }, FRAME_MS);
86
+ }
87
+
88
+ process.on('SIGINT', async () => {
89
+ await strip.off();
90
+ await connection.close();
91
+ process.exit(0);
92
+ });
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ const { SPIConnection } = require('../../../src/connection/spi');
4
+ const { APA102Minimal } = require('../../../src/chips/led/apa102');
5
+
6
+ const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
7
+ const SPI_DEVICE = parseInt(process.env.SPI_DEVICE || '0', 10);
8
+
9
+ const connection = new SPIConnection(SPI_BUS, SPI_DEVICE, { mode: 0, maxSpeedHz: 1_000_000 }); // Create SPI connection, (busNumber, deviceNumber, mode=0, 1MHz)
10
+ const strip = new APA102Minimal(connection, 30); // Create APA102 driver, (connection, n=30 pixels)
11
+
12
+ (async () => {
13
+ await strip.fill(255, 0, 0); // Fill all pixels red, (r=0–255, g=0–255, b=0–255) → void
14
+ await new Promise(r => setTimeout(r, 1000));
15
+ await strip.fill(0, 255, 0); // Fill all pixels green, (r=0–255, g=0–255, b=0–255) → void
16
+ await new Promise(r => setTimeout(r, 1000));
17
+ await strip.fill(0, 0, 255); // Fill all pixels blue, (r=0–255, g=0–255, b=0–255) → void
18
+ await new Promise(r => setTimeout(r, 1000));
19
+ await strip.off(); // Turn off all pixels, () → void
20
+ await connection.close();
21
+ })();
@@ -1,69 +1,71 @@
1
1
  'use strict';
2
2
 
3
- const { NeoPixelTransport } = require('../../../src/transport/neopixel');
3
+ const { NeoPixelConnection } = require('../../../src/connection/neopixel');
4
4
  const { SK6812RGBWFull } = require('../../../src/chips/led/sk6812rgbw');
5
5
 
6
6
  const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
7
7
  const SPI_DEVICE = parseInt(process.env.SPI_DEVICE || '0', 10);
8
8
 
9
- const transport = new NeoPixelTransport(SPI_BUS, SPI_DEVICE); // Create NeoPixel transport, (busNumber, deviceNumber)
10
- const strip = new SK6812RGBWFull(transport, 8); // Create SK6812RGBW full driver, (transport, n=8 pixels)
9
+ const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
10
+ const strip = new SK6812RGBWFull(connection, 8); // Create SK6812RGBW full driver, (connection, n=8 pixels)
11
11
 
12
- // fill — set all pixels and send immediately
13
- strip.fill(255, 0, 0); // Fill all pixels with one colour, (r=0–255, g=0–255, b=0–255, w=0–255) → void
14
- // stores GRBW in buffer and calls transport.write()
12
+ (async () => {
13
+ // fill — set all pixels and send immediately
14
+ await strip.fill(255, 0, 0); // Fill all pixels with one colour, (r=0–255, g=0–255, b=0–255, w=0–255) → void
15
+ // stores GRBW in buffer and calls connection.write()
15
16
 
16
- // fill with white channel
17
- strip.fill(0, 0, 0, 255); // Fill all pixels using W channel, (r=0–255, g=0–255, b=0–255, w=0–255) → void
17
+ // fill with white channel
18
+ await strip.fill(0, 0, 0, 255); // Fill all pixels using W channel, (r=0–255, g=0–255, b=0–255, w=0–255) → void
18
19
  // w=255 activates dedicated white LED element; RGB channels stay dark
19
20
 
20
- // set individual pixels then show
21
- strip.set_pixel(0, 255, 0, 0); // Set pixel 0 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
21
+ // set individual pixels then show
22
+ strip.set_pixel(0, 255, 0, 0); // Set pixel 0 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
22
23
  // writes G,R,B,W bytes into internal buffer at position index*4
23
- strip.set_pixel(1, 0, 255, 0); // Set pixel 1 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
24
+ strip.set_pixel(1, 0, 255, 0); // Set pixel 1 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
24
25
  // writes G,R,B,W bytes into internal buffer at position index*4
25
- strip.set_pixel(2, 0, 0, 255); // Set pixel 2 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
26
+ strip.set_pixel(2, 0, 0, 255); // Set pixel 2 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
26
27
  // writes G,R,B,W bytes into internal buffer at position index*4
27
- strip.set_pixel(3, 0, 0, 0, 255); // Set pixel 3 to white in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
28
+ strip.set_pixel(3, 0, 0, 0, 255); // Set pixel 3 to white in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
28
29
  // w=255 lights the dedicated white element; RGB remain off
29
- strip.show(); // Transmit buffer to strip, () → void
30
- // applies brightness scaling then calls transport.write()
30
+ await strip.show(); // Transmit buffer to strip, () → void
31
+ // applies brightness scaling then calls connection.write()
31
32
 
32
- // set_pixels — write multiple pixels at once
33
- strip.set_pixels([[255,0,0,0],[0,255,0,0],[0,0,255,0], // Set pixels from array of [r,g,b,w], (colors=Array<[r,g,b,w?]>) → void
34
- [0,0,0,255],[255,200,150,255]]);
33
+ // set_pixels — write multiple pixels at once
34
+ strip.set_pixels([[255,0,0,0],[0,255,0,0],[0,0,255,0], // Set pixels from array of [r,g,b,w], (colors=Array<[r,g,b,w?]>) → void
35
+ [0,0,0,255],[255,200,150,255]]);
35
36
  // handles 3- or 4-element tuples; writes entries sequentially from pixel 0
36
- strip.show(); // Transmit buffer to strip, () → void
37
- // applies brightness scaling then calls transport.write()
37
+ await strip.show(); // Transmit buffer to strip, () → void
38
+ // applies brightness scaling then calls connection.write()
38
39
 
39
- // brightness — global scale applied at show() time
40
- strip.brightness = 64; // Set global brightness, (value=0–255)
40
+ // brightness — global scale applied at show() time
41
+ strip.brightness = 64; // Set global brightness, (value=0–255)
41
42
  // stored value is scaled: sent = stored * brightness / 255
42
- strip.show(); // Transmit buffer to strip, () → void
43
- // applies brightness scaling then calls transport.write()
44
- strip.brightness = 255; // Set global brightness, (value=0–255)
43
+ await strip.show(); // Transmit buffer to strip, () → void
44
+ // applies brightness scaling then calls connection.write()
45
+ strip.brightness = 255; // Set global brightness, (value=0–255)
45
46
  // stored value is scaled: sent = stored * brightness / 255
46
47
 
47
- // fill_hsv — fill all pixels from HSV colour (white=0)
48
- strip.fill_hsv(0.0, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
48
+ // fill_hsv — fill all pixels from HSV colour (white=0)
49
+ await strip.fill_hsv(0.0, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
49
50
  // converts HSV to RGB (w=0) then calls fill(); hue 0.0 = red
50
- strip.fill_hsv(0.333, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
51
+ await strip.fill_hsv(0.333, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
51
52
  // converts HSV to RGB (w=0) then calls fill(); hue 0.333 = green
52
- strip.fill_hsv(0.667, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
53
+ await strip.fill_hsv(0.667, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
53
54
  // converts HSV to RGB (w=0) then calls fill(); hue 0.667 = blue
54
55
 
55
- // rotate — shift pixel buffer left, then show
56
- strip.set_pixels([[255,0,0,0], ...Array(7).fill([0,0,0,0])]); // Set pixels from array of [r,g,b,w], (colors=Array<[r,g,b,w?]>) → void
56
+ // rotate — shift pixel buffer left, then show
57
+ strip.set_pixels([[255,0,0,0], ...Array(7).fill([0,0,0,0])]); // Set pixels from array of [r,g,b,w], (colors=Array<[r,g,b,w?]>) → void
57
58
  // handles 3- or 4-element tuples; writes entries sequentially from pixel 0
58
- strip.show(); // Transmit buffer to strip, () → void
59
- // applies brightness scaling then calls transport.write()
60
- for (let i = 0; i < 7; i++) {
61
- strip.rotate(1); // Rotate pixel buffer left, (steps=1) → void
59
+ await strip.show(); // Transmit buffer to strip, () → void
60
+ // applies brightness scaling then calls connection.write()
61
+ for (let i = 0; i < 7; i++) {
62
+ strip.rotate(1); // Rotate pixel buffer left, (steps=1) → void
62
63
  // shifts buffer by steps pixel positions; wraps around; does not send
63
- strip.show(); // Transmit buffer to strip, () → void
64
- // applies brightness scaling then calls transport.write()
65
- }
64
+ await strip.show(); // Transmit buffer to strip, () → void
65
+ // applies brightness scaling then calls connection.write()
66
+ }
66
67
 
67
- strip.off(); // Turn off all pixels, () → void
68
+ await strip.off(); // Turn off all pixels, () → void
68
69
  // equivalent to fill(0, 0, 0, 0)
69
- transport.close();
70
+ await connection.close();
71
+ })();