periph 1.0.1 → 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 (241) 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 +42 -0
  21. package/examples/adc_dac/hx711/demo.js +35 -0
  22. package/examples/adc_dac/hx711/minimal.js +16 -0
  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 +43 -0
  27. package/examples/adc_dac/mcp4728/demo.js +41 -0
  28. package/examples/adc_dac/mcp4728/minimal.js +13 -0
  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 +35 -0
  42. package/examples/display/pcf8576/demo.js +48 -0
  43. package/examples/display/pcf8576/minimal.js +20 -0
  44. package/examples/environmental/aht21/complete.js +32 -0
  45. package/examples/environmental/aht21/demo.js +46 -0
  46. package/examples/environmental/aht21/minimal.js +12 -0
  47. package/examples/environmental/bme280/complete.js +37 -0
  48. package/examples/environmental/bme280/demo.js +67 -0
  49. package/examples/environmental/bme280/minimal.js +20 -0
  50. package/examples/environmental/bme680/complete.js +40 -0
  51. package/examples/environmental/bme680/demo.js +54 -0
  52. package/examples/environmental/bme680/minimal.js +21 -0
  53. package/examples/gas/ens160/complete.js +54 -0
  54. package/examples/gas/ens160/demo.js +54 -0
  55. package/examples/gas/ens160/minimal.js +29 -0
  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 +58 -0
  69. package/examples/imu/mpu6050/demo.js +37 -0
  70. package/examples/imu/mpu6050/minimal.js +14 -0
  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 +64 -0
  105. package/examples/light/apds9960/demo.js +34 -0
  106. package/examples/light/apds9960/minimal.js +12 -0
  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 +42 -0
  114. package/examples/memory/24aa02uid/demo.js +42 -0
  115. package/examples/memory/24aa02uid/minimal.js +12 -0
  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 +29 -22
  138. package/examples/pressure/bmp280/demo.js +42 -23
  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 +165 -0
  166. package/src/chips/adc_dac/mcp4725.js +48 -40
  167. package/src/chips/adc_dac/mcp4728.js +297 -0
  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 +232 -0
  173. package/src/chips/environmental/aht21.js +185 -0
  174. package/src/chips/environmental/bme280.js +385 -0
  175. package/src/chips/environmental/bme680.js +512 -0
  176. package/src/chips/gas/ens160.js +298 -0
  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 +289 -0
  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 +499 -0
  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 +182 -0
  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 +188 -206
  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/connection/hx711.js +132 -0
  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/display/.gitkeep +0 -0
  230. package/examples/environmental/.gitkeep +0 -0
  231. package/examples/gnss/.gitkeep +0 -0
  232. package/examples/humidity/.gitkeep +0 -0
  233. package/examples/imu/.gitkeep +0 -0
  234. package/examples/light/.gitkeep +0 -0
  235. package/examples/pressure/.gitkeep +0 -0
  236. package/src/chips/display/.gitkeep +0 -0
  237. package/src/chips/environmental/.gitkeep +0 -0
  238. package/src/chips/gnss/.gitkeep +0 -0
  239. package/src/chips/imu/.gitkeep +0 -0
  240. package/src/chips/light/.gitkeep +0 -0
  241. package/src/chips/pressure/.gitkeep +0 -0
@@ -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
+ })();
@@ -1,6 +1,6 @@
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);
@@ -12,8 +12,8 @@ const RAINBOW_MS = 10000;
12
12
  const WARM_MS = 2000;
13
13
  const WARM_HALF = 100;
14
14
 
15
- const transport = new NeoPixelTransport(SPI_BUS, SPI_DEVICE); // Create NeoPixel transport, (busNumber, deviceNumber)
16
- const strip = new SK6812RGBWFull(transport, N_PIXELS); // Create SK6812RGBW full driver, (transport, n=N_PIXELS pixels)
15
+ const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
16
+ const strip = new SK6812RGBWFull(connection, N_PIXELS); // Create SK6812RGBW full driver, (connection, n=N_PIXELS pixels)
17
17
  strip.brightness = 180; // Set global brightness, (value=0–255)
18
18
 
19
19
  const { _hsvToRgb } = require('../../../src/chips/led/_color');
@@ -24,13 +24,13 @@ const { _hsvToRgb } = require('../../../src/chips/led/_color');
24
24
  let hueOffset = 0;
25
25
  let lastPrint = Date.now();
26
26
 
27
- function rainbowFrame() {
27
+ async function rainbowFrame() {
28
28
  for (let i = 0; i < N_PIXELS; i++) {
29
29
  const h = (hueOffset + i / N_PIXELS) % 1.0;
30
30
  const [r, g, b] = _hsvToRgb(h, 1.0, 1.0);
31
31
  strip.set_pixel(i, r, g, b, 0); // Set pixel i to rainbow hue (w=0), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
32
32
  }
33
- strip.show(); // Transmit buffer to strip, () → void
33
+ await strip.show(); // Transmit buffer to strip, () → void
34
34
  hueOffset = (hueOffset + 1.0 / (N_PIXELS * 2)) % 1.0;
35
35
  const now = Date.now();
36
36
  if (now - lastPrint >= 1000) {
@@ -40,8 +40,8 @@ function rainbowFrame() {
40
40
  }
41
41
 
42
42
  const rainbowStart = Date.now();
43
- const rainbowTimer = setInterval(() => {
44
- rainbowFrame();
43
+ const rainbowTimer = setInterval(async () => {
44
+ await rainbowFrame();
45
45
  if (Date.now() - rainbowStart >= RAINBOW_MS) {
46
46
  clearInterval(rainbowTimer);
47
47
  startWarm();
@@ -52,14 +52,14 @@ const rainbowTimer = setInterval(() => {
52
52
  // All four channels active (r=255, g=200, b=150, w=255) gives a warm,
53
53
  // high-CRI white; toggling at 5 Hz for 2 seconds draws the eye to the
54
54
  // difference between mixed-RGB white and the native W element. ---
55
- function startWarm() {
55
+ async function startWarm() {
56
56
  strip.brightness = 255; // Set global brightness, (value=0–255)
57
- strip.fill(255, 200, 150, 255); // Pre-load warm white (RGB+W) into buffer, (r=0–255, g=0–255, b=0–255, w=0–255) → void
57
+ await strip.fill(255, 200, 150, 255); // Pre-load warm white (RGB+W) into buffer, (r=0–255, g=0–255, b=0–255, w=0–255) → void
58
58
  let state = true;
59
59
  const warmStart = Date.now();
60
- const warmTimer = setInterval(() => {
60
+ const warmTimer = setInterval(async () => {
61
61
  strip.brightness = state ? 255 : 0; // Toggle brightness on/off, (value=0–255)
62
- strip.show(); // Transmit buffer to strip, () → void
62
+ await strip.show(); // Transmit buffer to strip, () → void
63
63
  state = !state;
64
64
  if (Date.now() - warmStart >= WARM_MS) {
65
65
  clearInterval(warmTimer);
@@ -73,13 +73,13 @@ function startRainbowContinuous() {
73
73
  strip.brightness = 180; // Set global brightness, (value=0–255)
74
74
  hueOffset = 0;
75
75
  lastPrint = Date.now();
76
- setInterval(() => {
77
- rainbowFrame();
76
+ setInterval(async () => {
77
+ await rainbowFrame();
78
78
  }, FRAME_MS);
79
79
  }
80
80
 
81
- process.on('SIGINT', () => {
82
- strip.off();
83
- transport.close();
81
+ process.on('SIGINT', async () => {
82
+ await strip.off();
83
+ await connection.close();
84
84
  process.exit(0);
85
85
  });
@@ -1,25 +1,23 @@
1
1
  'use strict';
2
2
 
3
- const { NeoPixelTransport } = require('../../../src/transport/neopixel');
3
+ const { NeoPixelConnection } = require('../../../src/connection/neopixel');
4
4
  const { SK6812RGBWMinimal } = 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 SK6812RGBWMinimal(transport, 30); // Create SK6812RGBW driver, (transport, n=30 pixels)
9
+ const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
10
+ const strip = new SK6812RGBWMinimal(connection, 30); // Create SK6812RGBW driver, (connection, n=30 pixels)
11
11
 
12
- strip.fill(255, 0, 0); // Fill all pixels red, (r=0–255, g=0–255, b=0–255, w=0–255) → void
13
- setTimeout(() => {
14
- strip.fill(0, 255, 0); // Fill all pixels green, (r=0–255, g=0–255, b=0–255, w=0–255) → void
15
- setTimeout(() => {
16
- strip.fill(0, 0, 255); // Fill all pixels blue, (r=0–255, g=0–255, b=0–255, w=0–255) → void
17
- setTimeout(() => {
18
- strip.fill(0, 0, 0, 255); // Fill all pixels white (W channel), (r=0–255, g=0–255, b=0–255, w=0–255) → void
19
- setTimeout(() => {
20
- strip.off(); // Turn off all pixels, () → void
21
- transport.close();
22
- }, 1000);
23
- }, 1000);
24
- }, 1000);
25
- }, 1000);
12
+ (async () => {
13
+ await strip.fill(255, 0, 0); // Fill all pixels red, (r=0–255, g=0–255, b=0–255, w=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, w=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, w=0–255) → void
18
+ await new Promise(r => setTimeout(r, 1000));
19
+ await strip.fill(0, 0, 0, 255); // Fill all pixels white (W channel), (r=0–255, g=0–255, b=0–255, w=0–255) → void
20
+ await new Promise(r => setTimeout(r, 1000));
21
+ await strip.off(); // Turn off all pixels, () → void
22
+ await connection.close();
23
+ })();
@@ -1,64 +1,66 @@
1
1
  'use strict';
2
2
 
3
- const { NeoPixelTransport } = require('../../../src/transport/neopixel');
3
+ const { NeoPixelConnection } = require('../../../src/connection/neopixel');
4
4
  const { WS2812BFull } = require('../../../src/chips/led/ws2812b');
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 WS2812BFull(transport, 8); // Create WS2812B full driver, (transport, n=8 pixels)
9
+ const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
10
+ const strip = new WS2812BFull(connection, 8); // Create WS2812B 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) → void
14
- // stores GRB 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) → void
15
+ // stores GRB in buffer and calls connection.write()
15
16
 
16
- // set individual pixels then show
17
- 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) → void
17
+ // set individual pixels then show
18
+ 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) → void
18
19
  // writes G,R,B bytes into internal buffer at position index*3
19
- 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) → void
20
+ 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) → void
20
21
  // writes G,R,B bytes into internal buffer at position index*3
21
- 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) → void
22
+ 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) → void
22
23
  // writes G,R,B bytes into internal buffer at position index*3
23
- strip.show(); // Transmit buffer to strip, () → void
24
- // applies brightness scaling then calls transport.write()
24
+ await strip.show(); // Transmit buffer to strip, () → void
25
+ // applies brightness scaling then calls connection.write()
25
26
 
26
- // set_pixels — write multiple pixels at once
27
- strip.set_pixels([[255,0,0],[0,255,0],[0,0,255], // Set pixels from array of [r,g,b], (colors=Array<[r,g,b]>) → void
28
- [255,255,0],[0,255,255],[255,0,255],
29
- [128,128,128],[255,255,255]]);
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], (colors=Array<[r,g,b]>) → void
29
+ [255,255,0],[0,255,255],[255,0,255],
30
+ [128,128,128],[255,255,255]]);
30
31
  // writes entries sequentially from pixel 0; ignores extras beyond strip length
31
- strip.show(); // Transmit buffer to strip, () → void
32
- // applies brightness scaling then calls transport.write()
32
+ await strip.show(); // Transmit buffer to strip, () → void
33
+ // applies brightness scaling then calls connection.write()
33
34
 
34
- // brightness — global scale applied at show() time
35
- strip.brightness = 64; // Set global brightness, (value=0–255)
35
+ // brightness — global scale applied at show() time
36
+ strip.brightness = 64; // Set global brightness, (value=0–255)
36
37
  // stored value is scaled: sent = stored * brightness / 255
37
- strip.show(); // Transmit buffer to strip, () → void
38
- // applies brightness scaling then calls transport.write()
39
- strip.brightness = 255; // Set global brightness, (value=0–255)
38
+ await strip.show(); // Transmit buffer to strip, () → void
39
+ // applies brightness scaling then calls connection.write()
40
+ strip.brightness = 255; // Set global brightness, (value=0–255)
40
41
  // stored value is scaled: sent = stored * brightness / 255
41
42
 
42
- // fill_hsv — fill all pixels from HSV colour
43
- 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
43
+ // fill_hsv — fill all pixels from HSV colour
44
+ 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
44
45
  // converts HSV to RGB then calls fill(); hue 0.0 = red
45
- 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
46
+ 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
46
47
  // converts HSV to RGB then calls fill(); hue 0.333 = green
47
- 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
48
+ 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
48
49
  // converts HSV to RGB then calls fill(); hue 0.667 = blue
49
50
 
50
- // rotate — shift pixel buffer left, then show
51
- 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
51
+ // rotate — shift pixel buffer left, then show
52
+ 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
52
53
  // writes entries sequentially from pixel 0; ignores extras beyond strip length
53
- strip.show(); // Transmit buffer to strip, () → void
54
- // applies brightness scaling then calls transport.write()
55
- for (let i = 0; i < 7; i++) {
56
- strip.rotate(1); // Rotate pixel buffer left, (steps=1) → void
54
+ await strip.show(); // Transmit buffer to strip, () → void
55
+ // applies brightness scaling then calls connection.write()
56
+ for (let i = 0; i < 7; i++) {
57
+ strip.rotate(1); // Rotate pixel buffer left, (steps=1) → void
57
58
  // shifts buffer by steps pixel positions; wraps around; does not send
58
- strip.show(); // Transmit buffer to strip, () → void
59
- // applies brightness scaling then calls transport.write()
60
- }
59
+ await strip.show(); // Transmit buffer to strip, () → void
60
+ // applies brightness scaling then calls connection.write()
61
+ }
61
62
 
62
- strip.off(); // Turn off all pixels, () → void
63
+ await strip.off(); // Turn off all pixels, () → void
63
64
  // equivalent to fill(0, 0, 0)
64
- transport.close();
65
+ await connection.close();
66
+ })();
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const { NeoPixelTransport } = require('../../../src/transport/neopixel');
3
+ const { NeoPixelConnection } = require('../../../src/connection/neopixel');
4
4
  const { WS2812BFull } = require('../../../src/chips/led/ws2812b');
5
5
 
6
6
  const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
@@ -12,8 +12,8 @@ const RAINBOW_DURATION = 10000;
12
12
  const STROBE_DURATION = 2000;
13
13
  const STROBE_HALF = 50;
14
14
 
15
- const transport = new NeoPixelTransport(SPI_BUS, SPI_DEVICE); // Create NeoPixel transport, (busNumber, deviceNumber)
16
- const strip = new WS2812BFull(transport, N_PIXELS); // Create WS2812B full driver, (transport, n=N_PIXELS pixels)
15
+ const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
16
+ const strip = new WS2812BFull(connection, N_PIXELS); // Create WS2812B full driver, (connection, n=N_PIXELS pixels)
17
17
  strip.brightness = 180; // Set global brightness, (value=0–255)
18
18
 
19
19
  function hsvToRgb(h, s, v) {
@@ -40,13 +40,13 @@ function hsvToRgb(h, s, v) {
40
40
  let hueOffset = 0;
41
41
  let lastPrint = Date.now();
42
42
 
43
- function rainbowFrame() {
43
+ async function rainbowFrame() {
44
44
  for (let i = 0; i < N_PIXELS; i++) {
45
45
  const h = (hueOffset + i / N_PIXELS) % 1.0;
46
46
  const [r, g, b] = hsvToRgb(h, 1.0, 1.0);
47
47
  strip.set_pixel(i, r, g, b); // Set pixel i to rainbow hue, (index=0–n-1, r=0–255, g=0–255, b=0–255) → void
48
48
  }
49
- strip.show(); // Transmit buffer to strip, () → void
49
+ await strip.show(); // Transmit buffer to strip, () → void
50
50
  hueOffset = (hueOffset + 1.0 / (N_PIXELS * 2)) % 1.0;
51
51
  const now = Date.now();
52
52
  if (now - lastPrint >= 1000) {
@@ -56,8 +56,8 @@ function rainbowFrame() {
56
56
  }
57
57
 
58
58
  const rainbowStart = Date.now();
59
- const rainbowTimer = setInterval(() => {
60
- rainbowFrame();
59
+ const rainbowTimer = setInterval(async () => {
60
+ await rainbowFrame();
61
61
  if (Date.now() - rainbowStart >= RAINBOW_DURATION) {
62
62
  clearInterval(rainbowTimer);
63
63
  startStrobe();
@@ -68,14 +68,14 @@ const rainbowTimer = setInterval(() => {
68
68
  // Uses brightness=255 for maximum intensity then brightness=0 for off,
69
69
  // demonstrating non-destructive brightness scaling — pixel values in the
70
70
  // buffer are never zeroed. ---
71
- function startStrobe() {
71
+ async function startStrobe() {
72
72
  strip.brightness = 255; // Set global brightness, (value=0–255)
73
- strip.fill(255, 255, 255); // Pre-load white into buffer, (r=0–255, g=0–255, b=0–255) → void
73
+ await strip.fill(255, 255, 255); // Pre-load white into buffer, (r=0–255, g=0–255, b=0–255) → void
74
74
  let state = true;
75
75
  const strobeStart = Date.now();
76
- const strobeTimer = setInterval(() => {
76
+ const strobeTimer = setInterval(async () => {
77
77
  strip.brightness = state ? 255 : 0; // Set global brightness, (value=0–255)
78
- strip.show(); // Transmit buffer to strip, () → void
78
+ await strip.show(); // Transmit buffer to strip, () → void
79
79
  state = !state;
80
80
  if (Date.now() - strobeStart >= STROBE_DURATION) {
81
81
  clearInterval(strobeTimer);
@@ -89,13 +89,13 @@ function startRainbowContinuous() {
89
89
  strip.brightness = 180; // Set global brightness, (value=0–255)
90
90
  hueOffset = 0;
91
91
  lastPrint = Date.now();
92
- setInterval(() => {
93
- rainbowFrame();
92
+ setInterval(async () => {
93
+ await rainbowFrame();
94
94
  }, FRAME_MS);
95
95
  }
96
96
 
97
- process.on('SIGINT', () => {
98
- strip.off();
99
- transport.close();
97
+ process.on('SIGINT', async () => {
98
+ await strip.off();
99
+ await connection.close();
100
100
  process.exit(0);
101
101
  });
@@ -1,22 +1,21 @@
1
1
  'use strict';
2
2
 
3
- const { NeoPixelTransport } = require('../../../src/transport/neopixel');
3
+ const { NeoPixelConnection } = require('../../../src/connection/neopixel');
4
4
  const { WS2812BMinimal } = require('../../../src/chips/led/ws2812b');
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 WS2812BMinimal(transport, 30); // Create WS2812B driver, (transport, n=30 pixels)
9
+ const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
10
+ const strip = new WS2812BMinimal(connection, 30); // Create WS2812B driver, (connection, n=30 pixels)
11
11
 
12
- strip.fill(255, 0, 0); // Fill all pixels red, (r=0–255, g=0–255, b=0–255) → void
13
- setTimeout(() => {
14
- strip.fill(0, 255, 0); // Fill all pixels green, (r=0–255, g=0–255, b=0–255) → void
15
- setTimeout(() => {
16
- strip.fill(0, 0, 255); // Fill all pixels blue, (r=0–255, g=0–255, b=0–255) → void
17
- setTimeout(() => {
18
- strip.off(); // Turn off all pixels, () → void
19
- transport.close();
20
- }, 1000);
21
- }, 1000);
22
- }, 1000);
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
+ })();
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ const { NeoPixelConnection } = require('../../../src/connection/neopixel');
4
+ const { WS2814Full } = require('../../../src/chips/led/ws2814');
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 NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
10
+ const strip = new WS2814Full(connection, 8); // Create WS2814 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, w=0–255) → void
15
+ // stores RGBW in buffer (identity order) and calls connection.write()
16
+
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
19
+ // w=255 activates dedicated white LED element; RGB channels stay dark
20
+
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
23
+ // writes R,G,B,W bytes into internal buffer at position index*4
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
25
+ // writes R,G,B,W bytes into internal buffer at position index*4
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
27
+ // writes R,G,B,W bytes into internal buffer at position index*4
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
29
+ // w=255 lights the dedicated white element; RGB remain off
30
+ await strip.show(); // Transmit buffer to strip, () → void
31
+ // applies brightness scaling then calls connection.write()
32
+
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]]);
36
+ // handles 3- or 4-element tuples; writes entries sequentially from pixel 0
37
+ await strip.show(); // Transmit buffer to strip, () → void
38
+ // applies brightness scaling then calls connection.write()
39
+
40
+ // brightness — global scale applied at show() time
41
+ strip.brightness = 64; // Set global brightness, (value=0–255)
42
+ // stored value is scaled: sent = stored * brightness / 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)
46
+ // stored value is scaled: sent = stored * brightness / 255
47
+
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
50
+ // converts HSV to RGB (w=0) then calls fill(); hue 0.0 = red
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
52
+ // converts HSV to RGB (w=0) then calls fill(); hue 0.333 = green
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
54
+ // converts HSV to RGB (w=0) then calls fill(); hue 0.667 = blue
55
+
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
58
+ // handles 3- or 4-element tuples; writes entries sequentially from pixel 0
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
63
+ // shifts buffer by steps pixel positions; wraps around; does not send
64
+ await strip.show(); // Transmit buffer to strip, () → void
65
+ // applies brightness scaling then calls connection.write()
66
+ }
67
+
68
+ await strip.off(); // Turn off all pixels, () → void
69
+ // equivalent to fill(0, 0, 0, 0)
70
+ await connection.close();
71
+ })();