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.
- 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 +42 -0
- package/examples/adc_dac/hx711/demo.js +35 -0
- package/examples/adc_dac/hx711/minimal.js +16 -0
- 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 +43 -0
- package/examples/adc_dac/mcp4728/demo.js +41 -0
- package/examples/adc_dac/mcp4728/minimal.js +13 -0
- 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 +35 -0
- package/examples/display/pcf8576/demo.js +48 -0
- package/examples/display/pcf8576/minimal.js +20 -0
- package/examples/environmental/aht21/complete.js +32 -0
- package/examples/environmental/aht21/demo.js +46 -0
- package/examples/environmental/aht21/minimal.js +12 -0
- package/examples/environmental/bme280/complete.js +37 -0
- package/examples/environmental/bme280/demo.js +67 -0
- package/examples/environmental/bme280/minimal.js +20 -0
- package/examples/environmental/bme680/complete.js +40 -0
- package/examples/environmental/bme680/demo.js +54 -0
- package/examples/environmental/bme680/minimal.js +21 -0
- package/examples/gas/ens160/complete.js +54 -0
- package/examples/gas/ens160/demo.js +54 -0
- package/examples/gas/ens160/minimal.js +29 -0
- 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 +58 -0
- package/examples/imu/mpu6050/demo.js +37 -0
- package/examples/imu/mpu6050/minimal.js +14 -0
- 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 +64 -0
- package/examples/light/apds9960/demo.js +34 -0
- package/examples/light/apds9960/minimal.js +12 -0
- 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 +42 -0
- package/examples/memory/24aa02uid/demo.js +42 -0
- package/examples/memory/24aa02uid/minimal.js +12 -0
- 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 +29 -22
- package/examples/pressure/bmp280/demo.js +42 -23
- 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 +165 -0
- package/src/chips/adc_dac/mcp4725.js +48 -40
- package/src/chips/adc_dac/mcp4728.js +297 -0
- 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 +232 -0
- package/src/chips/environmental/aht21.js +185 -0
- package/src/chips/environmental/bme280.js +385 -0
- package/src/chips/environmental/bme680.js +512 -0
- package/src/chips/gas/ens160.js +298 -0
- 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 +289 -0
- 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 +499 -0
- package/src/chips/magnetometer/as5600.js +102 -82
- package/src/chips/magnetometer/hmc5883l.js +222 -0
- package/src/chips/memory/_24aa02uid.js +182 -0
- 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 +188 -206
- 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/connection/hx711.js +132 -0
- 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/display/.gitkeep +0 -0
- package/examples/environmental/.gitkeep +0 -0
- package/examples/gnss/.gitkeep +0 -0
- package/examples/humidity/.gitkeep +0 -0
- package/examples/imu/.gitkeep +0 -0
- package/examples/light/.gitkeep +0 -0
- package/examples/pressure/.gitkeep +0 -0
- package/src/chips/display/.gitkeep +0 -0
- package/src/chips/environmental/.gitkeep +0 -0
- package/src/chips/gnss/.gitkeep +0 -0
- package/src/chips/imu/.gitkeep +0 -0
- package/src/chips/light/.gitkeep +0 -0
- package/src/chips/pressure/.gitkeep +0 -0
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {
|
|
2
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
3
3
|
const { Pcf8574Minimal } = require('periph/src/chips/io_expander/pcf8574');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const
|
|
5
|
+
async function main() {
|
|
6
|
+
const connection = new I2CConnection(1, 0x20); // Create I2C connection, (bus, addr=0x20)
|
|
7
|
+
const chip = new Pcf8574Minimal(connection); // Create PCF8574 driver, (connection, addr=0x20)
|
|
7
8
|
|
|
8
|
-
const p0 = chip.pin(0, 'out'); // Get pin proxy, (n, direction='out') → Pin
|
|
9
|
-
const p4 = chip.pin(4, 'in'); // Get pin proxy, (n, direction='in') → Pin
|
|
9
|
+
const p0 = chip.pin(0, 'out'); // Get pin proxy, (n, direction='out') → Pin
|
|
10
|
+
const p4 = chip.pin(4, 'in'); // Get pin proxy, (n, direction='in') → Pin
|
|
10
11
|
|
|
11
|
-
setInterval(() => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}, 200);
|
|
12
|
+
setInterval(async () => {
|
|
13
|
+
const port = await chip.readPort(); // Read all 8 pins, (port=0) → Promise<int bitmask>
|
|
14
|
+
const btn = (port >> 4) & 1;
|
|
15
|
+
await p0.write(btn ? 1 : 0); // Write pin, (value=0|1) → Promise<void>
|
|
16
|
+
console.log('port=0x' + port.toString(16).padStart(2, '0'));
|
|
17
|
+
}, 200);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
main();
|
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const { Pcf8575Minimal, Pcf8575Full } = require('../../src/chips/io_expander/pcf8575');
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
write
|
|
6
|
-
read
|
|
4
|
+
const connection = {
|
|
5
|
+
async write(buf) { console.log('write', buf); },
|
|
6
|
+
async read(len) { return Buffer.from([0xFF, 0xFF]); }
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
async function main() {
|
|
10
|
+
const chip = new Pcf8575Full(connection, 0x20); // Create PCF8575 full driver, (connection, addr=0x20)
|
|
10
11
|
|
|
11
|
-
const p0 = chip.pin(0);
|
|
12
|
-
p0.
|
|
13
|
-
p0.
|
|
14
|
-
const v = p0.
|
|
12
|
+
const p0 = chip.pin(0); // Get pin proxy, (n=0) → Pin
|
|
13
|
+
await p0.write(0); // Write pin, (value=0|1) → Promise<void>
|
|
14
|
+
await p0.write(1); // Write pin, (value=0|1) → Promise<void>
|
|
15
|
+
const v = await p0.read(); // Read pin, () → Promise<0|1>
|
|
15
16
|
|
|
16
|
-
const port0 = chip.readPort(0);
|
|
17
|
-
const port1 = chip.readPort(1);
|
|
17
|
+
const port0 = await chip.readPort(0); // Read Port 0, (port=0) → Promise<int bitmask>
|
|
18
|
+
const port1 = await chip.readPort(1); // Read Port 1, (port=1) → Promise<int bitmask>
|
|
18
19
|
|
|
19
|
-
chip.writePort(0, 0b00001111);
|
|
20
|
-
chip.writePort(1, 0b00001111);
|
|
20
|
+
await chip.writePort(0, 0b00001111); // Write Port 0, (port=0, mask=int) → Promise<void>
|
|
21
|
+
await chip.writePort(1, 0b00001111); // Write Port 1, (port=1, mask=int) → Promise<void>
|
|
21
22
|
|
|
22
|
-
const p8 = chip.pin(8);
|
|
23
|
-
p8.setDirection('in');
|
|
24
|
-
const state = p8.
|
|
23
|
+
const p8 = chip.pin(8); // Get pin proxy, (n=8) → Pin
|
|
24
|
+
await p8.setDirection('in'); // Set direction, (direction='in'|'out') → Promise<void>
|
|
25
|
+
const state = await p8.read(); // Read pin, () → Promise<0|1>
|
|
25
26
|
|
|
26
|
-
chip.
|
|
27
|
-
|
|
28
|
-
});
|
|
27
|
+
await chip.onInterrupt((changed) => { // Subscribe to INT line, (callback, options) → Promise<void>
|
|
28
|
+
console.log('changed:', changed);
|
|
29
|
+
});
|
|
29
30
|
|
|
30
|
-
const changed = chip.
|
|
31
|
-
console.log('v:', v, 'port0:', port0, 'port1:', port1, 'state:', state, 'changed:', changed);
|
|
31
|
+
const changed = await chip.pollInterrupt(); // Read port and return 16-bit changed bitmask, () → Promise<int>
|
|
32
|
+
console.log('v:', v, 'port0:', port0, 'port1:', port1, 'state:', state, 'changed:', changed);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
main();
|
|
@@ -1,33 +1,37 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const { Pcf8575Full } = require('../../src/chips/io_expander/pcf8575');
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
write
|
|
6
|
-
read
|
|
4
|
+
const connection = {
|
|
5
|
+
async write(buf) { /* LED write */ },
|
|
6
|
+
async read(len) { return Buffer.from([0xFF, 0xFF]); }
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
|
|
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);
|
|
12
|
-
chip.writePort(1, 0xFF);
|
|
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.
|
|
15
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
5
|
-
write
|
|
6
|
-
read
|
|
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
|
-
|
|
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);
|
|
12
|
-
const p8 = chip.pin(8);
|
|
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.
|
|
15
|
-
const v = p0.
|
|
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);
|
|
19
|
-
const port1 = chip.readPort(1);
|
|
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
|
+
})();
|