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.
- package/README.md +54 -12
- package/examples/accelerometer/adxl345/complete.js +52 -0
- package/examples/accelerometer/adxl345/demo.js +34 -0
- package/examples/accelerometer/adxl345/minimal.js +18 -0
- package/examples/accelerometer/adxl362/complete.js +57 -0
- package/examples/accelerometer/adxl362/demo.js +51 -0
- package/examples/accelerometer/adxl362/minimal.js +21 -0
- package/examples/adc_dac/ad7705/complete.js +32 -0
- package/examples/adc_dac/ad7705/demo.js +42 -0
- package/examples/adc_dac/ad7705/minimal.js +16 -0
- package/examples/adc_dac/ad7706/complete.js +35 -0
- package/examples/adc_dac/ad7706/demo.js +44 -0
- package/examples/adc_dac/ad7706/minimal.js +16 -0
- package/examples/adc_dac/hx710a/complete.js +45 -0
- package/examples/adc_dac/hx710a/demo.js +52 -0
- package/examples/adc_dac/hx710a/minimal.js +16 -0
- package/examples/adc_dac/hx710b/complete.js +45 -0
- package/examples/adc_dac/hx710b/demo.js +64 -0
- package/examples/adc_dac/hx710b/minimal.js +16 -0
- package/examples/adc_dac/hx711/complete.js +7 -7
- package/examples/adc_dac/hx711/demo.js +6 -6
- package/examples/adc_dac/hx711/minimal.js +7 -7
- package/examples/adc_dac/mcp4725/complete.js +19 -17
- package/examples/adc_dac/mcp4725/demo.js +5 -5
- package/examples/adc_dac/mcp4725/minimal.js +8 -6
- package/examples/adc_dac/mcp4728/complete.js +24 -22
- package/examples/adc_dac/mcp4728/demo.js +22 -22
- package/examples/adc_dac/mcp4728/minimal.js +8 -6
- package/examples/adc_dac/pcf8591/complete.js +41 -0
- package/examples/adc_dac/pcf8591/demo.js +39 -0
- package/examples/adc_dac/pcf8591/minimal.js +19 -0
- package/examples/comms/mcp2515/complete.js +75 -0
- package/examples/comms/mcp2515/demo.js +66 -0
- package/examples/comms/mcp2515/minimal.js +27 -0
- package/examples/comms/rda5807m/complete.js +55 -0
- package/examples/comms/rda5807m/demo.js +68 -0
- package/examples/comms/rda5807m/minimal.js +15 -0
- package/examples/comms/rfm9x/complete.js +50 -0
- package/examples/comms/rfm9x/demo.js +55 -0
- package/examples/comms/rfm9x/minimal.js +20 -0
- package/examples/display/pcf8576/complete.js +18 -15
- package/examples/display/pcf8576/demo.js +6 -6
- package/examples/display/pcf8576/minimal.js +12 -10
- package/examples/environmental/aht21/complete.js +15 -13
- package/examples/environmental/aht21/demo.js +8 -6
- package/examples/environmental/aht21/minimal.js +5 -5
- package/examples/environmental/bme280/complete.js +23 -20
- package/examples/environmental/bme280/demo.js +14 -14
- package/examples/environmental/bme280/minimal.js +13 -11
- package/examples/environmental/bme680/complete.js +25 -22
- package/examples/environmental/bme680/demo.js +38 -36
- package/examples/environmental/bme680/minimal.js +14 -12
- package/examples/gas/ens160/complete.js +29 -27
- package/examples/gas/ens160/demo.js +39 -37
- package/examples/gas/ens160/minimal.js +17 -15
- package/examples/gnss/neo6/complete.js +49 -0
- package/examples/gnss/neo6/demo.js +54 -0
- package/examples/gnss/neo6/minimal.js +30 -0
- package/examples/gyroscope/l3g4200d/complete.js +56 -0
- package/examples/gyroscope/l3g4200d/demo.js +49 -0
- package/examples/gyroscope/l3g4200d/minimal.js +19 -0
- package/examples/gyroscope/l3gd20h/complete.js +42 -0
- package/examples/gyroscope/l3gd20h/demo.js +29 -0
- package/examples/gyroscope/l3gd20h/minimal.js +13 -0
- package/examples/humidity/dht11/complete.js +22 -0
- package/examples/humidity/dht11/demo.js +38 -0
- package/examples/humidity/dht11/minimal.js +18 -0
- package/examples/imu/mpu6050/complete.js +27 -25
- package/examples/imu/mpu6050/demo.js +29 -26
- package/examples/imu/mpu6050/minimal.js +6 -6
- package/examples/imu/mpu9250/complete.js +65 -0
- package/examples/imu/mpu9250/demo.js +53 -0
- package/examples/imu/mpu9250/minimal.js +21 -0
- package/examples/imu/mpu9255/complete.js +73 -0
- package/examples/imu/mpu9255/demo.js +73 -0
- package/examples/imu/mpu9255/minimal.js +21 -0
- package/examples/io_expander/mcp23017/complete.js +70 -77
- package/examples/io_expander/mcp23017/demo.js +37 -33
- package/examples/io_expander/mcp23017/minimal.js +15 -11
- package/examples/io_expander/pcf8574/complete.js +60 -65
- package/examples/io_expander/pcf8574/demo.js +30 -25
- package/examples/io_expander/pcf8574/minimal.js +15 -11
- package/examples/io_expander/pcf8575/complete.js +24 -20
- package/examples/io_expander/pcf8575/demo.js +27 -23
- package/examples/io_expander/pcf8575/minimal.js +16 -12
- package/examples/io_expander/tpic6b595/complete.js +57 -0
- package/examples/io_expander/tpic6b595/demo.js +75 -0
- package/examples/io_expander/tpic6b595/minimal.js +26 -0
- package/examples/led/apa102/complete.js +72 -0
- package/examples/led/apa102/demo.js +92 -0
- package/examples/led/apa102/minimal.js +21 -0
- package/examples/led/sk6812rgbw/complete.js +42 -40
- package/examples/led/sk6812rgbw/demo.js +16 -16
- package/examples/led/sk6812rgbw/minimal.js +15 -17
- package/examples/led/ws2812b/complete.js +40 -38
- package/examples/led/ws2812b/demo.js +16 -16
- package/examples/led/ws2812b/minimal.js +13 -14
- package/examples/led/ws2814/complete.js +71 -0
- package/examples/led/ws2814/demo.js +82 -0
- package/examples/led/ws2814/minimal.js +23 -0
- package/examples/light/apds-9930/complete.js +46 -0
- package/examples/light/apds-9930/demo.js +31 -0
- package/examples/light/apds-9930/minimal.js +20 -0
- package/examples/light/apds9960/complete.js +45 -43
- package/examples/light/apds9960/demo.js +11 -9
- package/examples/light/apds9960/minimal.js +5 -5
- package/examples/magnetometer/as5600/complete.js +31 -29
- package/examples/magnetometer/as5600/demo.js +35 -33
- package/examples/magnetometer/as5600/minimal.js +7 -7
- package/examples/magnetometer/hmc5883l/complete.js +47 -0
- package/examples/magnetometer/hmc5883l/demo.js +50 -0
- package/examples/magnetometer/hmc5883l/minimal.js +15 -0
- package/examples/memory/24aa02uid/complete.js +23 -21
- package/examples/memory/24aa02uid/demo.js +32 -30
- package/examples/memory/24aa02uid/minimal.js +5 -5
- package/examples/other/mpr121/complete.js +50 -0
- package/examples/other/mpr121/demo.js +30 -0
- package/examples/other/mpr121/minimal.js +17 -0
- package/examples/power/ade7953/complete.js +44 -0
- package/examples/power/ade7953/demo.js +28 -0
- package/examples/power/ade7953/minimal.js +15 -0
- package/examples/power/ina219/complete.js +20 -18
- package/examples/power/ina219/demo.js +15 -13
- package/examples/power/ina219/minimal.js +8 -8
- package/examples/power/ina226/complete.js +24 -22
- package/examples/power/ina226/demo.js +22 -20
- package/examples/power/ina226/minimal.js +5 -5
- package/examples/power/ina3221/complete.js +51 -49
- package/examples/power/ina3221/demo.js +13 -13
- package/examples/power/ina3221/minimal.js +8 -8
- package/examples/pressure/bmp085/complete.js +29 -0
- package/examples/pressure/bmp085/demo.js +34 -0
- package/examples/pressure/bmp085/minimal.js +19 -0
- package/examples/pressure/bmp180/complete.js +20 -17
- package/examples/pressure/bmp180/demo.js +24 -22
- package/examples/pressure/bmp180/minimal.js +13 -11
- package/examples/pressure/bmp280/complete.js +23 -20
- package/examples/pressure/bmp280/demo.js +44 -41
- package/examples/pressure/bmp280/minimal.js +13 -11
- package/examples/pressure/bmp384/complete.js +29 -0
- package/examples/pressure/bmp384/demo.js +40 -0
- package/examples/pressure/bmp384/minimal.js +18 -0
- package/examples/pressure/bmp581/complete.js +34 -0
- package/examples/pressure/bmp581/demo.js +56 -0
- package/examples/pressure/bmp581/minimal.js +19 -0
- package/examples/pressure/lps22df/complete.js +50 -0
- package/examples/pressure/lps22df/demo.js +41 -0
- package/examples/pressure/lps22df/minimal.js +19 -0
- package/examples/pressure/lps28dfw/complete.js +37 -0
- package/examples/pressure/lps28dfw/demo.js +33 -0
- package/examples/pressure/lps28dfw/minimal.js +19 -0
- package/examples/pressure/lps33hw/complete.js +43 -0
- package/examples/pressure/lps33hw/demo.js +43 -0
- package/examples/pressure/lps33hw/minimal.js +19 -0
- package/examples/rfid/mfrc522/complete.js +44 -0
- package/examples/rfid/mfrc522/demo.js +70 -0
- package/examples/rfid/mfrc522/minimal.js +17 -0
- package/package.json +5 -1
- package/src/chips/accelerometer/adxl345.js +482 -0
- package/src/chips/accelerometer/adxl362.js +594 -0
- package/src/chips/adc_dac/ad7705.js +345 -0
- package/src/chips/adc_dac/ad7706.js +331 -0
- package/src/chips/adc_dac/hx710a.js +184 -0
- package/src/chips/adc_dac/hx710b.js +186 -0
- package/src/chips/adc_dac/hx711.js +15 -15
- package/src/chips/adc_dac/mcp4725.js +48 -40
- package/src/chips/adc_dac/mcp4728.js +57 -44
- package/src/chips/adc_dac/pcf8591.js +196 -0
- package/src/chips/comms/mcp2515.js +659 -0
- package/src/chips/comms/rda5807m.js +393 -0
- package/src/chips/comms/rfm9x.js +590 -0
- package/src/chips/display/pcf8576.js +42 -33
- package/src/chips/environmental/aht21.js +52 -37
- package/src/chips/environmental/bme280.js +85 -66
- package/src/chips/environmental/bme680.js +110 -87
- package/src/chips/gas/ens160.js +82 -64
- package/src/chips/gnss/neo6.js +438 -0
- package/src/chips/gyroscope/l3g4200d.js +366 -0
- package/src/chips/gyroscope/l3gd20h.js +314 -0
- package/src/chips/humidity/dht11.js +135 -0
- package/src/chips/imu/mpu6050.js +89 -66
- package/src/chips/imu/mpu9250.js +394 -0
- package/src/chips/imu/mpu9255.js +447 -0
- package/src/chips/io_expander/mcp23017.js +240 -157
- package/src/chips/io_expander/pcf8574.js +149 -124
- package/src/chips/io_expander/pcf8575.js +164 -135
- package/src/chips/io_expander/tpic6b595.js +242 -0
- package/src/chips/led/_NeoPixelRGBBase.js +204 -0
- package/src/chips/led/_NeoPixelRGBWBase.js +218 -0
- package/src/chips/led/apa102.js +236 -0
- package/src/chips/led/sk6812rgbw.js +15 -149
- package/src/chips/led/ws2812b.js +14 -139
- package/src/chips/led/ws2814.js +49 -0
- package/src/chips/light/apds-9930.js +342 -0
- package/src/chips/light/apds9960.js +158 -123
- package/src/chips/magnetometer/as5600.js +102 -82
- package/src/chips/magnetometer/hmc5883l.js +222 -0
- package/src/chips/memory/_24aa02uid.js +32 -29
- package/src/chips/other/mpr121.js +375 -0
- package/src/chips/power/ade7953.js +427 -0
- package/src/chips/power/ina219.js +45 -40
- package/src/chips/power/ina226.js +50 -45
- package/src/chips/power/ina3221.js +95 -76
- package/src/chips/pressure/bmp085.js +251 -0
- package/src/chips/pressure/bmp180.js +54 -37
- package/src/chips/pressure/bmp280.js +72 -53
- package/src/chips/pressure/bmp384.js +410 -0
- package/src/chips/pressure/bmp581.js +489 -0
- package/src/chips/pressure/lps22df.js +341 -0
- package/src/chips/pressure/lps28dfw.js +314 -0
- package/src/chips/pressure/lps33hw.js +255 -0
- package/src/chips/rfid/mfrc522.js +674 -0
- package/src/connection/connection.js +111 -0
- package/src/connection/dhtxx.js +138 -0
- package/src/connection/dhtxx_mock.js +39 -0
- package/src/{transport → connection}/hx711.js +49 -22
- package/src/connection/hx711_mock.js +52 -0
- package/src/{transport → connection}/i2c.js +13 -9
- package/src/connection/i2c_mock.js +91 -0
- package/src/connection/input_pin.js +156 -0
- package/src/connection/neo6_mock.js +45 -0
- package/src/{transport → connection}/neopixel.js +23 -4
- package/src/connection/output_pin.js +41 -0
- package/src/connection/sipo.js +159 -0
- package/src/{transport → connection}/smbus.js +14 -10
- package/src/{transport → connection}/spi.js +12 -8
- package/src/connection/spi_mock.js +151 -0
- package/src/{transport → connection}/uart.js +33 -26
- package/examples/gnss/.gitkeep +0 -0
- package/examples/humidity/.gitkeep +0 -0
- package/src/chips/gnss/.gitkeep +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
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
|
|
16
|
-
const strip = new SK6812RGBWFull(
|
|
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();
|
|
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);
|
|
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();
|
|
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
|
-
|
|
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 {
|
|
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
|
|
10
|
-
const strip = new SK6812RGBWMinimal(
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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 {
|
|
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
|
|
10
|
-
const strip = new WS2812BFull(
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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);
|
|
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);
|
|
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);
|
|
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();
|
|
24
|
-
// applies brightness scaling then calls
|
|
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],
|
|
28
|
-
|
|
29
|
-
|
|
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();
|
|
32
|
-
// applies brightness scaling then calls
|
|
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;
|
|
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();
|
|
38
|
-
// applies brightness scaling then calls
|
|
39
|
-
strip.brightness = 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);
|
|
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);
|
|
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);
|
|
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();
|
|
54
|
-
// applies brightness scaling then calls
|
|
55
|
-
for (let i = 0; i < 7; i++) {
|
|
56
|
-
|
|
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
|
-
|
|
59
|
-
// applies brightness scaling then calls
|
|
60
|
-
}
|
|
59
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
60
|
+
// applies brightness scaling then calls connection.write()
|
|
61
|
+
}
|
|
61
62
|
|
|
62
|
-
strip.off();
|
|
63
|
+
await strip.off(); // Turn off all pixels, () → void
|
|
63
64
|
// equivalent to fill(0, 0, 0)
|
|
64
|
-
|
|
65
|
+
await connection.close();
|
|
66
|
+
})();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
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
|
|
16
|
-
const strip = new WS2812BFull(
|
|
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();
|
|
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);
|
|
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();
|
|
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
|
-
|
|
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 {
|
|
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
|
|
10
|
-
const strip = new WS2812BMinimal(
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
+
})();
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { NeoPixelConnection } = require('../../../src/connection/neopixel');
|
|
4
|
+
const { WS2814Full } = require('../../../src/chips/led/ws2814');
|
|
5
|
+
const { _hsvToRgb } = require('../../../src/chips/led/_color');
|
|
6
|
+
|
|
7
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
8
|
+
const SPI_DEVICE = parseInt(process.env.SPI_DEVICE || '0', 10);
|
|
9
|
+
const N_PIXELS = parseInt(process.env.N_PIXELS || '30', 10);
|
|
10
|
+
|
|
11
|
+
const FRAME_MS = 33; // ~30 fps
|
|
12
|
+
const RAINBOW_MS = 5000;
|
|
13
|
+
const FLASH_MS = 2000;
|
|
14
|
+
const DIM_MS = 2000;
|
|
15
|
+
|
|
16
|
+
const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
|
|
17
|
+
const strip = new WS2814Full(connection, N_PIXELS); // Create WS2814 full driver, (connection, n=N_PIXELS pixels)
|
|
18
|
+
|
|
19
|
+
function sleep(ms) {
|
|
20
|
+
return new Promise(r => setTimeout(r, ms));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function main() {
|
|
24
|
+
// --- Rainbow rotation using RGB channels (white=0). Each pixel is
|
|
25
|
+
// assigned a hue offset by its position; the offset advances each
|
|
26
|
+
// frame so the rainbow rotates continuously around the strip.
|
|
27
|
+
// Demonstrates that WS2814's RGBW wire order is identity (R, G, B, W
|
|
28
|
+
// with no reorder), unlike the SK6812RGBW's GRBW order. Runs at
|
|
29
|
+
// ~30 fps for 5 seconds. ---
|
|
30
|
+
let hueOffset = 0;
|
|
31
|
+
const rainbowStart = Date.now();
|
|
32
|
+
let lastPrint = rainbowStart;
|
|
33
|
+
while (Date.now() - rainbowStart < RAINBOW_MS) {
|
|
34
|
+
for (let i = 0; i < N_PIXELS; i++) {
|
|
35
|
+
const h = (hueOffset + i / N_PIXELS) % 1.0;
|
|
36
|
+
const [r, g, b] = _hsvToRgb(h, 1.0, 1.0);
|
|
37
|
+
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
|
|
38
|
+
}
|
|
39
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
40
|
+
hueOffset = (hueOffset + 1.0 / (N_PIXELS * 2)) % 1.0;
|
|
41
|
+
const now = Date.now();
|
|
42
|
+
if (now - lastPrint >= 1000) {
|
|
43
|
+
console.log(`mode=rainbow brightness=${strip.brightness}`);
|
|
44
|
+
lastPrint = now;
|
|
45
|
+
}
|
|
46
|
+
await sleep(FRAME_MS);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// --- Warm white at full brightness for 2 seconds. r=255, g=200, b=150,
|
|
50
|
+
// w=255 blends the dedicated white element with amber-tinted RGB,
|
|
51
|
+
// exercising the white channel and the 32-bit RGBW pixel word at
|
|
52
|
+
// full brightness. ---
|
|
53
|
+
await strip.fill(255, 200, 150, 255); // Fill all pixels warm white, (r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
54
|
+
const flashStart = Date.now();
|
|
55
|
+
while (Date.now() - flashStart < FLASH_MS) {
|
|
56
|
+
console.log(`mode=warm-white brightness=${strip.brightness}`);
|
|
57
|
+
await sleep(100);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// --- Dim warm white to 50% using the brightness property and hold for
|
|
61
|
+
// 2 seconds. Demonstrates that brightness scaling is non-destructive:
|
|
62
|
+
// the stored RGBW values are unchanged, only the scale factor applied
|
|
63
|
+
// at show() time changes. ---
|
|
64
|
+
strip.brightness = 128; // Set global brightness, (value=0–255)
|
|
65
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
66
|
+
const dimStart = Date.now();
|
|
67
|
+
while (Date.now() - dimStart < DIM_MS) {
|
|
68
|
+
console.log(`mode=warm-white-dimmed brightness=${strip.brightness}`);
|
|
69
|
+
await sleep(100);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// --- Cycle to cool white at full brightness. r=200, g=210, b=255,
|
|
73
|
+
// w=255 shifts the blend toward blue, showcasing the dedicated
|
|
74
|
+
// white element paired with a cool-tinted RGB base. ---
|
|
75
|
+
strip.brightness = 255; // Set global brightness, (value=0–255)
|
|
76
|
+
await strip.fill(200, 210, 255, 255); // Fill all pixels cool white, (r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
77
|
+
console.log(`mode=cool-white brightness=${strip.brightness}`);
|
|
78
|
+
|
|
79
|
+
await connection.close();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
main();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { NeoPixelConnection } = require('../../../src/connection/neopixel');
|
|
4
|
+
const { WS2814Minimal } = 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 WS2814Minimal(connection, 30); // Create WS2814 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, 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
|
+
})();
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Complete example for the APDS-9930 — exercises every Full-class method.
|
|
2
|
+
|
|
3
|
+
const { APDS9930Full } = require('periph/src/chips/light/apds-9930');
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c_auto');
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
const connection = new I2CConnection(0x39); // Create I2C connection, (addr=0x39, bus=undefined) → I2CConnection
|
|
8
|
+
const apds = new APDS9930Full(connection); // Construct APDS-9930 Full, (connection) → APDS9930Full
|
|
9
|
+
// exposes ALS and proximity configuration methods
|
|
10
|
+
|
|
11
|
+
await new Promise(r => setTimeout(r, 110));
|
|
12
|
+
|
|
13
|
+
await apds.configureAls(0xDB, 0, false); // Configure ALS, (atime=0xDB, again=0, agl=false) → Promise<void>
|
|
14
|
+
// sets ALS integration time to 101 ms with 1x gain
|
|
15
|
+
await apds.configureProximity(8, 0, 0, false, 0xFF); // Configure proximity, (ppulse=8, pgain=0, pdrive=0, pdl=false, ptime=0xFF) → Promise<void>
|
|
16
|
+
// 8 LED pulses at 100 mA, 1x gain, no reduced drive
|
|
17
|
+
await apds.disableWait(); // Disable wait timer, () → Promise<void>
|
|
18
|
+
// clears WEN in ENABLE
|
|
19
|
+
await apds.setAlsThresholds(100, 60000, 1); // Set ALS thresholds, (low=100, high=60000, persistence=1) → Promise<void>
|
|
20
|
+
// fires after 1 consecutive out-of-range Ch0 count
|
|
21
|
+
await apds.setProximityThresholds(10, 200, 1); // Set proximity thresholds, (low=10, high=200, persistence=1) → Promise<void>
|
|
22
|
+
// fires on a single proximity reading outside [10, 200]
|
|
23
|
+
await apds.setProximityOffset(0); // Set proximity offset, (offset=0) → Promise<void>
|
|
24
|
+
// clears any prior offset
|
|
25
|
+
await apds.sleepAfterInterrupt(false); // Configure SAI, (enable=false) → Promise<void>
|
|
26
|
+
// chip stays in normal operation after an interrupt
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < 10; i++) {
|
|
29
|
+
await new Promise(r => setTimeout(r, 110));
|
|
30
|
+
const lx = await apds.lux(); // Read ambient illuminance, () → Promise<number> lx
|
|
31
|
+
// combines Ch0 and Ch1 with IR-compensation coefficients
|
|
32
|
+
const p = await apds.proximity(); // Read proximity count, () → Promise<number> count
|
|
33
|
+
// 16-bit ADC value
|
|
34
|
+
const c0 = await apds.ch0(); // Read Ch0 raw, () → Promise<number> count
|
|
35
|
+
// 16-bit ADC value of visible + IR channel
|
|
36
|
+
const c1 = await apds.ch1(); // Read Ch1 raw, () → Promise<number> count
|
|
37
|
+
// 16-bit ADC value of IR-only channel
|
|
38
|
+
const st = await apds.status(); // Read STATUS decoded, () → Promise<object>
|
|
39
|
+
// {avalid, pvalid, psat, aint, pint} booleans
|
|
40
|
+
console.log(`lux=${lx.toFixed(1)} prox=${p} ch0=${c0} ch1=${c1} status=${JSON.stringify(st)}`);
|
|
41
|
+
}
|
|
42
|
+
await apds.clearInterrupt('both'); // Clear interrupts, (channel='both') → Promise<void>
|
|
43
|
+
// issues special-function command 0xE7 to clear both ALS and proximity INT flags
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Demo for the APDS-9930 — adaptive backlight + screen-lock scenario.
|
|
2
|
+
|
|
3
|
+
const { APDS9930Full } = require('periph/src/chips/light/apds-9930');
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c_auto');
|
|
5
|
+
|
|
6
|
+
const DIM_LUX_THRESHOLD = 10.0;
|
|
7
|
+
const PROX_SCREEN_OFF = 400;
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
// --- Configure for adaptive backlight + screen-lock monitoring ---
|
|
11
|
+
// Defaults (ATIME=0xDB, 1x AGAIN, 8-pulse proximity, 100 mA drive)
|
|
12
|
+
// already give stable readings; we just print lux and proximity.
|
|
13
|
+
const connection = new I2CConnection(0x39); // Create I2C connection, (addr=0x39, bus=undefined) → I2CConnection
|
|
14
|
+
const apds = new APDS9930Full(connection); // Construct APDS-9930 Full, (connection) → APDS9930Full
|
|
15
|
+
// default 101 ms ALS integration, 8-pulse proximity, 100 mA drive
|
|
16
|
+
|
|
17
|
+
await new Promise(r => setTimeout(r, 110));
|
|
18
|
+
// --- Sample lux and proximity once per second for 30 cycles ---
|
|
19
|
+
for (let i = 0; i < 30; i++) {
|
|
20
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
21
|
+
const lx = await apds.lux(); // Read ambient illuminance, () → Promise<number> lx
|
|
22
|
+
// IR-compensated lux via Ch0/Ch1 difference
|
|
23
|
+
const p = await apds.proximity(); // Read proximity count, () → Promise<number> count
|
|
24
|
+
// 16-bit ADC value; higher = closer
|
|
25
|
+
console.log(`lux=${lx.toFixed(1)} lx proximity=${p}`);
|
|
26
|
+
if (lx < DIM_LUX_THRESHOLD) console.log(' -> dim backlight');
|
|
27
|
+
if (p > PROX_SCREEN_OFF) console.log(' -> disable screen');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
main().catch(err => { console.error(err); process.exit(1); });
|