periph 1.5.0 → 1.5.2
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 +19 -0
- package/examples/color/as7262/complete.js +60 -0
- package/examples/color/as7262/demo.js +65 -0
- package/examples/color/as7262/minimal.js +23 -0
- package/examples/environmental/aht10/complete.js +37 -0
- package/examples/environmental/aht10/demo.js +43 -0
- package/examples/environmental/aht10/minimal.js +12 -0
- package/examples/environmental/aht20/complete.js +41 -0
- package/examples/environmental/aht20/demo.js +49 -0
- package/examples/environmental/aht20/minimal.js +12 -0
- package/examples/environmental/am2320/complete.js +34 -0
- package/examples/environmental/am2320/demo.js +46 -0
- package/examples/environmental/am2320/minimal.js +21 -0
- package/examples/humidity/hdc1008/complete.js +39 -0
- package/examples/humidity/hdc1008/demo.js +46 -0
- package/examples/humidity/hdc1008/minimal.js +22 -0
- package/examples/humidity/hdc1080/complete.js +34 -0
- package/examples/humidity/hdc1080/demo.js +46 -0
- package/examples/humidity/hdc1080/minimal.js +22 -0
- package/examples/humidity/hs30xx/complete.js +43 -0
- package/examples/humidity/hs30xx/demo.js +40 -0
- package/examples/humidity/hs30xx/minimal.js +21 -0
- package/examples/humidity/hs40xx/complete.js +54 -0
- package/examples/humidity/hs40xx/demo.js +38 -0
- package/examples/humidity/hs40xx/minimal.js +21 -0
- package/examples/io_expander/tca9554/complete.js +63 -0
- package/examples/io_expander/tca9554/demo.js +58 -0
- package/examples/io_expander/tca9554/minimal.js +20 -0
- package/examples/led/ht16k33/complete.js +45 -0
- package/examples/led/ht16k33/demo.js +54 -0
- package/examples/led/ht16k33/minimal.js +24 -0
- package/examples/led/is31fl3731/complete.js +60 -0
- package/examples/led/is31fl3731/demo.js +72 -0
- package/examples/led/is31fl3731/minimal.js +26 -0
- package/examples/led/pca9685/complete.js +43 -0
- package/examples/led/pca9685/demo.js +77 -0
- package/examples/led/pca9685/minimal.js +24 -0
- package/examples/power/ina260/complete.js +38 -0
- package/examples/power/ina260/demo.js +32 -0
- package/examples/power/ina260/minimal.js +11 -0
- package/examples/power/lc709203f/complete.js +57 -0
- package/examples/power/lc709203f/demo.js +34 -0
- package/examples/power/lc709203f/minimal.js +11 -0
- package/examples/power/lm25066/complete.js +54 -0
- package/examples/power/lm25066/demo.js +41 -0
- package/examples/power/lm25066/minimal.js +12 -0
- package/examples/power/ltc4151/complete.js +40 -0
- package/examples/power/ltc4151/demo.js +49 -0
- package/examples/power/ltc4151/minimal.js +11 -0
- package/examples/power/max17048/complete.js +68 -0
- package/examples/power/max17048/demo.js +56 -0
- package/examples/power/max17048/minimal.js +19 -0
- package/examples/pressure/lps22hb/complete.js +43 -0
- package/examples/pressure/lps22hb/demo.js +43 -0
- package/examples/pressure/lps22hb/minimal.js +19 -0
- package/examples/pressure/mpl115a2/complete.js +25 -0
- package/examples/pressure/mpl115a2/demo.js +30 -0
- package/examples/pressure/mpl115a2/minimal.js +20 -0
- package/package.json +1 -1
- package/src/chips/color/as7262.js +419 -0
- package/src/chips/environmental/aht10.js +186 -0
- package/src/chips/environmental/aht20.js +226 -0
- package/src/chips/environmental/am2320.js +237 -0
- package/src/chips/humidity/hdc1008.js +262 -0
- package/src/chips/humidity/hdc1080.js +208 -0
- package/src/chips/humidity/hs30xx.js +254 -0
- package/src/chips/humidity/hs40xx.js +382 -0
- package/src/chips/io_expander/tca9554.js +407 -0
- package/src/chips/led/ht16k33.js +273 -0
- package/src/chips/led/is31fl3731.js +501 -0
- package/src/chips/led/pca9685.js +350 -0
- package/src/chips/power/ina260.js +229 -0
- package/src/chips/power/lc709203f.js +376 -0
- package/src/chips/power/lm25066.js +370 -0
- package/src/chips/power/ltc4151.js +297 -0
- package/src/chips/power/max17048.js +302 -0
- package/src/chips/pressure/lps22hb.js +257 -0
- package/src/chips/pressure/mpl115a2.js +171 -0
- package/src/discovery/registry.js +56 -14
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { IS31FL3731Full } = require('../../../src/chips/led/is31fl3731');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x74', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
|
|
10
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
const matrix = new IS31FL3731Full(connection); // Create IS31FL3731 driver, (connection)
|
|
14
|
+
await matrix.ready;
|
|
15
|
+
|
|
16
|
+
await matrix.clear(); // Switch all LEDs of the drawing frame off, () → void
|
|
17
|
+
await matrix.setPixel(2, 5, 200); // Set one LED's PWM brightness, (row 0–8, col 0–15, brightness 0–255) → void
|
|
18
|
+
console.log(matrix.getPixel(2, 5)); // Read a pixel from the shadow copy, (row, col) → number 0–255
|
|
19
|
+
await matrix.setPixels(Buffer.from(Array.from({ length: 144 }, (_, i) => i))); // Write a whole frame, (data 144 bytes, row-major) → void
|
|
20
|
+
await matrix.fill(40); // Set every LED's PWM brightness, (brightness 0–255) → void
|
|
21
|
+
await matrix.setLedEnabled(0, 0, false); // LED-control (on/off) bit, (row, col, on) → void
|
|
22
|
+
await matrix.setLedEnabled(0, 0, true);
|
|
23
|
+
await matrix.setBlink(1, 1, true); // Blink-enable bit of one LED, (row, col, on) → void
|
|
24
|
+
await matrix.setBlinkAll(false); // Blink-enable bit of every LED, (on) → void
|
|
25
|
+
await matrix.enableBlink(true, 2); // Blink on, (enabled, period 0–7 × 0.27 s) → void
|
|
26
|
+
// 0.54 s period, 50 % duty
|
|
27
|
+
await sleep(2000);
|
|
28
|
+
await matrix.enableBlink(false);
|
|
29
|
+
await matrix.selectFrame(1); // Frame subsequent drawing writes to, (frame 0–7) → void
|
|
30
|
+
await matrix.fill(100);
|
|
31
|
+
await matrix.copyFrame(1, 2); // Copy PWM values between frames, (src, dst) → void
|
|
32
|
+
await matrix.clearFrame(2); // Re-initialise one frame, (frame 0–7) → void
|
|
33
|
+
await matrix.clearAllFrames(); // Re-initialise all eight frames, () → void
|
|
34
|
+
await matrix.selectFrame(0);
|
|
35
|
+
await matrix.showFrame(0); // Display a frame in Picture mode, (frame 0–7) → void
|
|
36
|
+
await matrix.setPictureMode(); // Picture mode, () → void
|
|
37
|
+
await matrix.startAutoPlay(2, 1, 110, 0); // Auto Frame Play, (frames 0–7, loops 0–7, delayMs, startFrame) → void
|
|
38
|
+
// frames/loops 0 = all/endless; plays 2 frames once
|
|
39
|
+
await sleep(1000);
|
|
40
|
+
console.log(await matrix.frameState()); // Read FRAME_STATE, () → number
|
|
41
|
+
console.log(await matrix.currentFrame()); // Frame being displayed, () → number 0–7
|
|
42
|
+
console.log(await matrix.movieFinished()); // Movie-finished flag (clears it), () → boolean
|
|
43
|
+
await matrix.stopAutoPlay(); // Back to Picture mode on the current frame, () → void
|
|
44
|
+
await matrix.setBreath(true, 3, 3, 2); // Breath function, (enabled, fadeIn, fadeOut, extinguish 0–7) → void
|
|
45
|
+
await sleep(3000);
|
|
46
|
+
await matrix.setBreath(false);
|
|
47
|
+
await matrix.setIntensityControl(false); // Share frame 1's PWM with all frames, (useFrame1) → void
|
|
48
|
+
await matrix.setAudioGain(6, true, false); // Audio gain, (gainDb 0–21 step 3, agc, fast) → void
|
|
49
|
+
await matrix.setAudioRate(10); // Audio ADC interval, (a 0–255, × 46 µs) → void
|
|
50
|
+
await matrix.setAudioSync(false); // Audio intensity modulation, (enabled) → void
|
|
51
|
+
await matrix.setAudioMode(false); // Audio Frame Play on/off, (enabled) → void
|
|
52
|
+
console.log(await matrix.readFunctionRegister(0x03)); // Raw function-page read, (reg 0–0x0C) → number
|
|
53
|
+
await matrix.writeFunctionRegister(0x03, 0x0B); // Raw function-page write, (reg, value) → void
|
|
54
|
+
console.log(await matrix.pollInterrupt()); // FRAME_STATE, clears INT, () → number
|
|
55
|
+
await matrix.shutdown(); // Software shutdown, (on = true) → void
|
|
56
|
+
await matrix.shutdown(false); // Back to normal operation
|
|
57
|
+
|
|
58
|
+
await connection.close();
|
|
59
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
60
|
+
})();
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { IS31FL3731Full } = require('../../../src/chips/led/is31fl3731');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x74', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
|
|
10
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
// --- Animated matrix: auto-play movie, blinking checkerboard, breath, gamma fade ---
|
|
14
|
+
// A diagonal moves across frames 1-8 and is played by the chip itself, then a
|
|
15
|
+
// blinking checkerboard is shown in Picture mode, a filled frame breathes, the
|
|
16
|
+
// matrix fades through the 64-step gamma table, a finite 2-loop movie ends with
|
|
17
|
+
// an interrupt, and the display is shut down.
|
|
18
|
+
const matrix = new IS31FL3731Full(connection); // Create IS31FL3731 driver, (connection)
|
|
19
|
+
await matrix.ready;
|
|
20
|
+
await matrix.clearAllFrames(); // Initialise all eight frames, () → void
|
|
21
|
+
|
|
22
|
+
for (let f = 0; f < 8; f++) {
|
|
23
|
+
await matrix.selectFrame(f); // Draw on frame f, (frame 0–7) → void
|
|
24
|
+
for (let r = 0; r < 9; r++) {
|
|
25
|
+
await matrix.setPixel(r, (f + r) % 16, 255); // One diagonal LED per row, (row, col, brightness) → void
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
await matrix.selectFrame(0);
|
|
29
|
+
|
|
30
|
+
await matrix.startAutoPlay(0, 0, 100, 0); // Endless 8-frame movie, (frames, loops, delayMs, startFrame) → void
|
|
31
|
+
for (let i = 0; i < 6; i++) {
|
|
32
|
+
console.log('frame', await matrix.currentFrame()); // Frame being displayed, () → number
|
|
33
|
+
await sleep(500);
|
|
34
|
+
}
|
|
35
|
+
await matrix.stopAutoPlay(); // Picture mode, current frame kept, () → void
|
|
36
|
+
|
|
37
|
+
await matrix.selectFrame(0);
|
|
38
|
+
await matrix.clear(); // Blank the drawing frame, () → void
|
|
39
|
+
const pixels = Buffer.alloc(144);
|
|
40
|
+
for (let r = 0; r < 9; r++) for (let c = 0; c < 16; c++) pixels[r * 16 + c] = (r + c) % 2 === 0 ? 255 : 0;
|
|
41
|
+
await matrix.setPixels(pixels); // Checkerboard, (data 144 bytes) → void
|
|
42
|
+
await matrix.setBlinkAll(true); // Every LED blinks, (on) → void
|
|
43
|
+
await matrix.enableBlink(true, 2); // Blink period 2 × 0.27 s, (enabled, period) → void
|
|
44
|
+
await matrix.showFrame(0); // Show frame 1 in Picture mode, (frame) → void
|
|
45
|
+
await sleep(3000);
|
|
46
|
+
await matrix.enableBlink(false);
|
|
47
|
+
await matrix.setBlinkAll(false);
|
|
48
|
+
|
|
49
|
+
await matrix.fill(255); // Full brightness, (brightness) → void
|
|
50
|
+
await matrix.setBreath(true, 4, 4, 2); // Breathing, (enabled, fadeIn, fadeOut, extinguish) → void
|
|
51
|
+
await sleep(5000);
|
|
52
|
+
await matrix.setBreath(false);
|
|
53
|
+
|
|
54
|
+
for (const level of IS31FL3731Full.GAMMA_64) {
|
|
55
|
+
await matrix.fill(level); // Gamma-corrected fade, (brightness) → void
|
|
56
|
+
await sleep(30);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await matrix.onInterrupt((status) => { // Callback when a movie ends, (callback, options) → void
|
|
60
|
+
console.log('movie finished at frame', status & 0x07);
|
|
61
|
+
});
|
|
62
|
+
await matrix.setPictureMode(); // Picture mode, () → void
|
|
63
|
+
await matrix.startAutoPlay(0, 2, 100, 0); // Two loops, (frames, loops, delayMs, startFrame) → void
|
|
64
|
+
await sleep(3000);
|
|
65
|
+
await matrix.offInterrupt(); // Unsubscribe, () → void
|
|
66
|
+
|
|
67
|
+
await matrix.clearAllFrames();
|
|
68
|
+
await matrix.shutdown(); // Display off, (on = true) → void
|
|
69
|
+
|
|
70
|
+
await connection.close();
|
|
71
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
72
|
+
})();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { IS31FL3731Minimal } = require('../../../src/chips/led/is31fl3731');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x74', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
|
|
10
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
const matrix = new IS31FL3731Minimal(connection); // Create IS31FL3731 driver, (connection)
|
|
14
|
+
await matrix.ready;
|
|
15
|
+
|
|
16
|
+
for (let col = 0; col < IS31FL3731Minimal.COLS; col++) {
|
|
17
|
+
await matrix.setPixel(0, col, 128); // Set one LED's PWM brightness, (row 0–8, col 0–15, brightness 0–255) → void
|
|
18
|
+
}
|
|
19
|
+
await sleep(1000);
|
|
20
|
+
await matrix.fill(32); // Set every LED's PWM brightness, (brightness 0–255) → void
|
|
21
|
+
await sleep(1000);
|
|
22
|
+
await matrix.clear(); // Switch all LEDs off, () → void
|
|
23
|
+
|
|
24
|
+
await connection.close();
|
|
25
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
26
|
+
})();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { PCA9685Full } = require('../../../src/chips/led/pca9685');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
|
|
10
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
const pwm = new PCA9685Full(connection); // Create PCA9685 driver, (connection)
|
|
14
|
+
await pwm.ready;
|
|
15
|
+
await pwm.setDuty(0, 0.25); // Set one channel's duty cycle, (channel 0–15, duty 0.0–1.0) → void
|
|
16
|
+
await pwm.setPwm(1, 409, 1228); // Phase-shifted PWM, (channel, on 0–4095, off 0–4095) → void
|
|
17
|
+
// 10 % delay, 20 % duty
|
|
18
|
+
console.log(await pwm.getPwm(1)); // Read the ON/OFF counts, (channel) → {on, off}
|
|
19
|
+
await pwm.setFullOn(2); // Hold a channel high, (channel) → void
|
|
20
|
+
await pwm.setFullOff(2); // Hold a channel low, (channel) → void
|
|
21
|
+
await pwm.setAllDuty(0.1); // Same duty on all 16 channels, (duty 0.0–1.0) → void
|
|
22
|
+
await pwm.setAllPwm(0, 2048); // Same ON/OFF counts on all channels, (on, off) → void
|
|
23
|
+
await pwm.setAllDuty(0.0);
|
|
24
|
+
await pwm.setFrequency(50); // PWM frequency, (hz 24–1526, oscHz = 25 MHz) → void
|
|
25
|
+
console.log(await pwm.getFrequency()); // Programmed PWM frequency, (oscHz = 25 MHz) → number Hz
|
|
26
|
+
await pwm.setPulseWidth(15, 0.0015); // Servo pulse width, (channel, seconds) → void
|
|
27
|
+
// 1.5 ms at 50 Hz = servo centre
|
|
28
|
+
await sleep(1000);
|
|
29
|
+
await pwm.sleep(); // Low-power mode, outputs stop, () → void
|
|
30
|
+
await pwm.wake(); // Wake and restart running channels, () → void
|
|
31
|
+
await pwm.restart(); // Datasheet restart sequence, () → void
|
|
32
|
+
await pwm.setOutputMode(false, false, PCA9685Full.OFF_LOW); // MODE2 output driver, (openDrain, invert, offState OFF_LOW/OFF_HIGH_OR_HIGHZ/OFF_HIGHZ) → void
|
|
33
|
+
await pwm.setUpdateOnAck(false); // Outputs change on STOP (false) or ACK (true), (enabled) → void
|
|
34
|
+
await pwm.setAllcall(false, 0x70); // LED All Call address, (enabled, address) → void
|
|
35
|
+
await pwm.setSubaddress(1, 0x71, false); // LED Sub Call address, (index 1–3, address, enabled) → void
|
|
36
|
+
console.log(await pwm.readMode()); // Raw MODE1/MODE2, () → {mode1, mode2}
|
|
37
|
+
// await pwm.useExternalClock(); // Sticky EXTCLK switch, () → void (needs a clock on EXTCLK)
|
|
38
|
+
// await PCA9685Full.softwareReset(generalCall); // Reset every PCA9685 on the bus, (Connection at address 0x00) → void
|
|
39
|
+
await pwm.reset(); // Write power-on defaults, () → void
|
|
40
|
+
|
|
41
|
+
await connection.close();
|
|
42
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
43
|
+
})();
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { PCA9685Full } = require('../../../src/chips/led/pca9685');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
|
|
10
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
11
|
+
|
|
12
|
+
// --- LED fader and servo sweep ---
|
|
13
|
+
// Fade channel 0 at 1 kHz, show a phase-shifted pair, run a 16-channel chase,
|
|
14
|
+
// switch to 50 Hz and sweep a servo on channel 15 from 1 ms to 2 ms, then show
|
|
15
|
+
// all-channel writes, full ON/OFF, output modes, sleep/wake/restart with the
|
|
16
|
+
// outputs preserved, the all-call and sub addresses, and finish with a reset.
|
|
17
|
+
(async () => {
|
|
18
|
+
const pwm = new PCA9685Full(connection); // Create PCA9685 driver, (connection)
|
|
19
|
+
await pwm.ready;
|
|
20
|
+
await pwm.setFrequency(1000); // 1 kHz PWM for LEDs, (hz) → void
|
|
21
|
+
|
|
22
|
+
for (let i = 0; i <= 100; i++) {
|
|
23
|
+
await pwm.setDuty(0, 0.5 - 0.5 * Math.cos(Math.PI * i / 50)); // Fade up and down, (channel, duty) → void
|
|
24
|
+
await sleep(20);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
await pwm.setPwm(1, 0, 1024); // 25 % duty, no delay, (channel, on, off) → void
|
|
28
|
+
await pwm.setPwm(2, 2048, 3072); // same duty, shifted by half a period
|
|
29
|
+
console.log(await pwm.getPwm(2)); // Read back the counts, (channel) → {on, off}
|
|
30
|
+
await sleep(1000);
|
|
31
|
+
|
|
32
|
+
for (let ch = 0; ch < 16; ch++) {
|
|
33
|
+
await pwm.setDuty(ch, 1.0); // Chase across all channels, (channel, duty) → void
|
|
34
|
+
await sleep(50);
|
|
35
|
+
await pwm.setDuty(ch, 0.0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await pwm.setAllDuty(0.2); // All channels together, (duty) → void
|
|
39
|
+
await sleep(500);
|
|
40
|
+
await pwm.setAllPwm(0, 3072); // 75 % on all channels, (on, off) → void
|
|
41
|
+
await sleep(500);
|
|
42
|
+
await pwm.setAllDuty(0.0);
|
|
43
|
+
await pwm.setFullOn(3); // Constant high, (channel) → void
|
|
44
|
+
await sleep(500);
|
|
45
|
+
await pwm.setFullOff(3); // Constant low, (channel) → void
|
|
46
|
+
|
|
47
|
+
await pwm.setFrequency(50); // Servo frequency, (hz) → void
|
|
48
|
+
for (let us = 1000; us <= 2000; us += 50) {
|
|
49
|
+
await pwm.setPulseWidth(15, us / 1e6); // Servo pulse 1–2 ms, (channel, seconds) → void
|
|
50
|
+
await sleep(50);
|
|
51
|
+
}
|
|
52
|
+
console.log(await pwm.getFrequency()); // () → number Hz
|
|
53
|
+
|
|
54
|
+
await pwm.setFrequency(1000);
|
|
55
|
+
await pwm.setDuty(4, 0.5);
|
|
56
|
+
await pwm.setOutputMode(false, true, PCA9685Full.OFF_LOW); // Inverted output, (openDrain, invert, offState) → void
|
|
57
|
+
await sleep(500);
|
|
58
|
+
await pwm.setOutputMode(true, false, PCA9685Full.OFF_HIGHZ); // Open-drain, high-Z when OE = 1
|
|
59
|
+
await sleep(500);
|
|
60
|
+
await pwm.setOutputMode(); // Back to totem-pole, not inverted
|
|
61
|
+
await pwm.setUpdateOnAck(true); // Update on ACK, (enabled) → void
|
|
62
|
+
await pwm.setUpdateOnAck(false);
|
|
63
|
+
|
|
64
|
+
await pwm.sleep(); // Outputs pause, PWM registers kept, () → void
|
|
65
|
+
await sleep(500);
|
|
66
|
+
await pwm.wake(); // Outputs resume, () → void
|
|
67
|
+
await pwm.restart(); // Restart sequence, () → void
|
|
68
|
+
await pwm.setAllcall(true, 0x70); // Respond to all-call, (enabled, address) → void
|
|
69
|
+
await pwm.setAllcall(false);
|
|
70
|
+
await pwm.setSubaddress(1, 0x71, true); // Respond to sub address 1, (index, address, enabled) → void
|
|
71
|
+
await pwm.setSubaddress(1, 0x71, false);
|
|
72
|
+
console.log(await pwm.readMode()); // () → {mode1, mode2}
|
|
73
|
+
await pwm.reset(); // Back to power-on state, () → void
|
|
74
|
+
|
|
75
|
+
await connection.close();
|
|
76
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
77
|
+
})();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { PCA9685Minimal } = require('../../../src/chips/led/pca9685');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
|
|
10
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
const pwm = new PCA9685Minimal(connection); // Create PCA9685 driver at 1 kHz, (connection)
|
|
14
|
+
await pwm.ready;
|
|
15
|
+
|
|
16
|
+
for (let step = 0; step <= 10; step++) {
|
|
17
|
+
await pwm.setDuty(0, step / 10); // Set one channel's duty cycle, (channel 0–15, duty 0.0–1.0) → void
|
|
18
|
+
await sleep(200);
|
|
19
|
+
}
|
|
20
|
+
await pwm.setDuty(0, 0.0);
|
|
21
|
+
|
|
22
|
+
await connection.close();
|
|
23
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
24
|
+
})();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { INA260Full } = require('../../../src/chips/power/ina260');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x40);
|
|
7
|
+
const ina = new INA260Full(connection);
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
console.log('0x' + (await ina.manufacturerId()).toString(16));
|
|
11
|
+
console.log('0x' + (await ina.dieId()).toString(16));
|
|
12
|
+
|
|
13
|
+
console.log(await ina.voltage());
|
|
14
|
+
console.log(await ina.current());
|
|
15
|
+
console.log(await ina.power());
|
|
16
|
+
console.log(await ina.conversionReady());
|
|
17
|
+
console.log(await ina.overflow());
|
|
18
|
+
|
|
19
|
+
await ina.configure(INA260Full.AVG_64, INA260Full.CT_1100US, INA260Full.CT_1100US, INA260Full.MODE_SHUNT_BUS_CONT);
|
|
20
|
+
|
|
21
|
+
await ina.setAlert(INA260Full.POL, 1.0, false, true);
|
|
22
|
+
console.log('0x' + (await ina.alertFlags()).toString(16));
|
|
23
|
+
|
|
24
|
+
await ina.setAlert(INA260Full.BOL, 5.5);
|
|
25
|
+
await ina.setAlert(INA260Full.BUL, 4.5);
|
|
26
|
+
await ina.setAlert(INA260Full.OCL, 5.0);
|
|
27
|
+
await ina.setAlert(INA260Full.CNVR);
|
|
28
|
+
await ina.clearAlert();
|
|
29
|
+
|
|
30
|
+
await ina.trigger(INA260Full.MODE_SHUNT_BUS_TRIGGERED);
|
|
31
|
+
while (!(await ina.conversionReady())) {}
|
|
32
|
+
|
|
33
|
+
await ina.shutdown();
|
|
34
|
+
await ina.wake();
|
|
35
|
+
await ina.reset();
|
|
36
|
+
|
|
37
|
+
await connection.close();
|
|
38
|
+
})();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { INA260Full } = require('../../../src/chips/power/ina260');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x40);
|
|
7
|
+
const ina = new INA260Full(connection);
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
// 64-sample averaging smooths out switching noise from DC/DC converters
|
|
11
|
+
await ina.configure(INA260Full.AVG_64, INA260Full.CT_1100US, INA260Full.CT_1100US, INA260Full.MODE_SHUNT_BUS_CONT);
|
|
12
|
+
|
|
13
|
+
// latch the alert so a brief spike is not missed between loop iterations
|
|
14
|
+
await ina.setAlert(INA260Full.POL, 1.0, false, true);
|
|
15
|
+
|
|
16
|
+
console.log('V A W');
|
|
17
|
+
|
|
18
|
+
setInterval(async () => {
|
|
19
|
+
// wait for a fresh conversion to avoid reading stale register values
|
|
20
|
+
while (!(await ina.conversionReady())) {}
|
|
21
|
+
|
|
22
|
+
const v = await ina.voltage();
|
|
23
|
+
const i = await ina.current();
|
|
24
|
+
const p = await ina.power();
|
|
25
|
+
console.log(v.toFixed(3) + 'V ' + i.toFixed(4) + 'A ' + p.toFixed(4) + 'W');
|
|
26
|
+
|
|
27
|
+
// reading alertFlags clears the latch — do this after printing measurements
|
|
28
|
+
if ((await ina.alertFlags()) & INA260Full.AFF) {
|
|
29
|
+
console.log('ALERT: power limit exceeded');
|
|
30
|
+
}
|
|
31
|
+
}, 1000);
|
|
32
|
+
})();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { INA260Minimal } = require('../../../src/chips/power/ina260');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x40);
|
|
7
|
+
const ina = new INA260Minimal(connection);
|
|
8
|
+
|
|
9
|
+
setInterval(async () => {
|
|
10
|
+
console.log(await ina.voltage(), await ina.current(), await ina.power());
|
|
11
|
+
}, 1000);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { LC709203FFull } = require('../../../src/chips/power/lc709203f');
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
const connection = new I2CConnection(1, 0x0B); // Create I²C connection, (bus, addr=0x0B) → Connection
|
|
8
|
+
const gauge = new LC709203FFull(connection, 1000, 1); // Create LC709203F driver, (connection, capacityMah, profile)
|
|
9
|
+
await gauge.ready; // Wait for the starting flow, () → Promise<void>
|
|
10
|
+
|
|
11
|
+
console.log(await gauge.voltage()); // Cell voltage, () → number V
|
|
12
|
+
console.log(await gauge.percent()); // State of charge (ITE), () → number %
|
|
13
|
+
console.log(await gauge.temperature()); // Cell temperature, () → number °C
|
|
14
|
+
await gauge.setTemperature(25.0); // Host temperature (I²C mode), (celsius) → Promise<void>
|
|
15
|
+
// clamped to -20...+60 °C
|
|
16
|
+
|
|
17
|
+
console.log(await gauge.rsoc()); // RSOC register, () → number % (0-100)
|
|
18
|
+
await gauge.setRsoc(50); // Force RSOC, (percent) → Promise<void>
|
|
19
|
+
await gauge.initRsoc(); // Initial RSOC from present voltage, () → Promise<void>
|
|
20
|
+
await gauge.beforeRsoc(); // RSOC from max voltage since reset, () → Promise<void>
|
|
21
|
+
|
|
22
|
+
await gauge.useThermistor(3380); // Thermistor mode, (bConstant) → Promise<void>
|
|
23
|
+
console.log(await gauge.isThermistorMode()); // Temperature source, () → boolean
|
|
24
|
+
console.log(await gauge.getBConstant()); // Thermistor B constant, () → number K
|
|
25
|
+
await gauge.useI2cTemperature(25.0); // Back to I²C temperature mode, (celsius) → Promise<void>
|
|
26
|
+
|
|
27
|
+
await gauge.setApa(0x19); // Adjustment Pack Application, (value) → Promise<void>
|
|
28
|
+
console.log(await gauge.getApa()); // () → number
|
|
29
|
+
await gauge.setApt(0x1E); // Adjustment Pack Thermistor, (value) → Promise<void>
|
|
30
|
+
console.log(await gauge.getApt()); // () → number
|
|
31
|
+
|
|
32
|
+
await gauge.setCurrentDirection(LC709203FFull.DIRECTION_AUTO); // Current direction, (mode) → Promise<void>
|
|
33
|
+
// DIRECTION_AUTO / _CHARGE / _DISCHARGE
|
|
34
|
+
console.log(await gauge.getCurrentDirection()); // () → number
|
|
35
|
+
await gauge.setProfile(1); // Battery profile 0/1, (profile) → Promise<void>
|
|
36
|
+
// re-initializes the chip (90 ms)
|
|
37
|
+
console.log(await gauge.getProfile()); // () → number
|
|
38
|
+
console.log((await gauge.profileId()).toString(16)); // Number of the parameter, () → number
|
|
39
|
+
console.log((await gauge.icVersion()).toString(16)); // IC version, () → number
|
|
40
|
+
|
|
41
|
+
await gauge.setAlarmRsoc(20); // Low-RSOC alarm, (percent) → Promise<void>; 0 = off
|
|
42
|
+
console.log(await gauge.getAlarmRsoc()); // () → number %
|
|
43
|
+
await gauge.setAlarmVoltage(3.5); // Low-voltage alarm, (volts) → Promise<void>; 0 = off
|
|
44
|
+
console.log(await gauge.getAlarmVoltage()); // () → number V
|
|
45
|
+
console.log(await gauge.pollInterrupt()); // Alarm bitmask, () → number
|
|
46
|
+
// ALARM_RSOC = 1, ALARM_VOLTAGE = 2
|
|
47
|
+
await gauge.onInterrupt((status) => console.log('alarm', status)); // Subscribe to ALARMB, (callback, {intPin}) → Promise<void>
|
|
48
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
49
|
+
await gauge.offInterrupt(); // Unsubscribe, () → Promise<void>
|
|
50
|
+
|
|
51
|
+
await gauge.sleep(); // Sleep mode, () → Promise<void>
|
|
52
|
+
await gauge.wake(); // Wake up, () → Promise<void>
|
|
53
|
+
console.log(await gauge.isSleeping()); // Power mode, () → boolean
|
|
54
|
+
await connection.close();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
main();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { LC709203FFull } = require('../../../src/chips/power/lc709203f');
|
|
5
|
+
|
|
6
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
const connection = new I2CConnection(1, 0x0B); // Create I²C connection, (bus, addr=0x0B) → Connection
|
|
10
|
+
const gauge = new LC709203FFull(connection, 1000, 1); // Create LC709203F driver, 1000 mAh 3.7 V LiPo
|
|
11
|
+
await gauge.ready;
|
|
12
|
+
|
|
13
|
+
console.log(`IC version 0x${(await gauge.icVersion()).toString(16)}, profile id 0x${(await gauge.profileId()).toString(16)}, RSOC ${await gauge.rsoc()} %`);
|
|
14
|
+
|
|
15
|
+
await gauge.setAlarmRsoc(20); // Alarm at 20 % RSOC, (percent) → Promise<void>
|
|
16
|
+
await gauge.setAlarmVoltage(3.5); // Alarm at 3.5 V, (volts) → Promise<void>
|
|
17
|
+
|
|
18
|
+
// Battery monitor: one line per 5 s for a minute, host temperature fixed at 25 °C
|
|
19
|
+
for (let n = 0; n < 12; n++) {
|
|
20
|
+
await gauge.setTemperature(25.0);
|
|
21
|
+
const v = await gauge.voltage();
|
|
22
|
+
const p = await gauge.percent();
|
|
23
|
+
const t = await gauge.temperature();
|
|
24
|
+
console.log(`${v.toFixed(3)} V ${p.toFixed(1)} % ${t.toFixed(1)} °C alarm=${await gauge.pollInterrupt()}`);
|
|
25
|
+
await sleep(5000);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
await gauge.sleep(); // Sleep mode, () → Promise<void>
|
|
29
|
+
await gauge.wake(); // Wake up, () → Promise<void>
|
|
30
|
+
console.log('sleeping:', await gauge.isSleeping());
|
|
31
|
+
await connection.close();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
main();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { LC709203FMinimal } = require('../../../src/chips/power/lc709203f');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x0B); // Create I²C connection, (bus, addr=0x0B) → Connection
|
|
7
|
+
const gauge = new LC709203FMinimal(connection, 1000, 1); // Create LC709203F driver, (connection, capacityMah, profile)
|
|
8
|
+
|
|
9
|
+
setInterval(async () => {
|
|
10
|
+
console.log(await gauge.voltage(), await gauge.percent(), await gauge.temperature()); // Read V / % / °C, () → Promise<number> each
|
|
11
|
+
}, 5000);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { LM25066Full } = require('../../../src/chips/power/lm25066');
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
const connection = new I2CConnection(1, 0x40); // Create I²C connection, (bus, addr=0x40) → Connection
|
|
8
|
+
const hotswap = new LM25066Full(connection, 1.0, false); // Create LM25066 driver, (connection, rSenseMohm, currentLimitHigh)
|
|
9
|
+
|
|
10
|
+
console.log(await hotswap.voltageIn()); // Input voltage, () → number V
|
|
11
|
+
console.log(await hotswap.voltageOut()); // Output voltage, () → number V
|
|
12
|
+
console.log(await hotswap.current()); // Input current, () → number A
|
|
13
|
+
console.log(await hotswap.power()); // Input power, () → number W
|
|
14
|
+
console.log(await hotswap.temperature()); // MOSFET temperature, () → number °C
|
|
15
|
+
console.log(await hotswap.voltageAux()); // VAUX pin voltage, () → number V (0 ... 1.16)
|
|
16
|
+
console.log(await hotswap.readBlock()); // Time-aligned BLOCK_READ, () → {diagnostic, current, voltageOut, voltageIn, power, temperature}
|
|
17
|
+
console.log(await hotswap.readAverage()); // AVG_BLOCK_READ, () → object
|
|
18
|
+
console.log(await hotswap.blackBox()); // Snapshot at first SMBA, () → object
|
|
19
|
+
console.log(await hotswap.voltageInAvg(), await hotswap.voltageOutAvg()); // Averaged VIN / VOUT, () → number V each
|
|
20
|
+
console.log(await hotswap.currentAvg(), await hotswap.powerAvg()); // Averaged IIN / PIN, () → number each
|
|
21
|
+
console.log(await hotswap.powerPeak()); // Peak input power, () → number W
|
|
22
|
+
await hotswap.clearPowerPeak(); // Reset the peak register, () → Promise<void>
|
|
23
|
+
await hotswap.setAveraging(6); // Average 2^6 samples, (exponent 0-12) → Promise<void>
|
|
24
|
+
console.log(await hotswap.getAveraging()); // () → number
|
|
25
|
+
await hotswap.setVinUvWarn(10.0); // VIN under-voltage warning, (volts | null) → Promise<void>
|
|
26
|
+
await hotswap.setVinOvWarn(15.0); // VIN over-voltage warning, (volts | null) → Promise<void>
|
|
27
|
+
await hotswap.setVoutUvWarn(9.0); // VOUT under-voltage warning, (volts | null) → Promise<void>
|
|
28
|
+
await hotswap.setOtWarn(100.0); // Over-temperature warning, (celsius | null) → Promise<void>
|
|
29
|
+
await hotswap.setOtFault(125.0); // Over-temperature fault, (celsius | null) → Promise<void>
|
|
30
|
+
await hotswap.setIinWarn(20.0); // Input over-current warning, (amps | null) → Promise<void>
|
|
31
|
+
await hotswap.setPinWarn(200.0); // Input over-power warning, (watts | null) → Promise<void>
|
|
32
|
+
console.log(await hotswap.getLimits()); // All thresholds, () → object (null = disabled)
|
|
33
|
+
console.log(await hotswap.statusByte(), await hotswap.statusWord()); // STATUS_BYTE / STATUS_WORD, () → number each
|
|
34
|
+
console.log(await hotswap.statusVout(), await hotswap.statusInput()); // Per-group status bytes, () → number each
|
|
35
|
+
console.log(await hotswap.statusTemperature(), await hotswap.statusCml(), await hotswap.statusMfr()); // STATUS_TEMPERATURE / _CML / _MFR_SPECIFIC
|
|
36
|
+
console.log(await hotswap.diagnosticWord()); // READ_DIAGNOSTIC_WORD, () → number
|
|
37
|
+
await hotswap.clearFaults(); // CLEAR_FAULTS (does not turn the MOSFET on), () → Promise<void>
|
|
38
|
+
console.log(await hotswap.isOn()); // MOSFET on, () → boolean
|
|
39
|
+
// await hotswap.operationOff(); // CUTS THE LOAD RAIL, () → Promise<void>
|
|
40
|
+
// await hotswap.operationOn(); // Switch the MOSFET on, () → Promise<void>
|
|
41
|
+
console.log(await hotswap.deviceSetup()); // DEVICE_SETUP, () → number
|
|
42
|
+
// await hotswap.configureDevice({ retryCode: 7, currentLimitHigh: false }); // Override RETRY/CL/CB pins, ({retryCode, currentLimitHigh, cbRatioHigh})
|
|
43
|
+
// await hotswap.setGateMask(0x04); // DANGEROUS: disable fault shut-off, (mask bits 5/4/2) → Promise<void>
|
|
44
|
+
console.log(await hotswap.getGateMask(), await hotswap.capability()); // GATE_MASK / CAPABILITY, () → number each
|
|
45
|
+
console.log(await hotswap.manufacturerId(), await hotswap.model(), await hotswap.revision()); // MFR_ID / MFR_MODEL / MFR_REVISION, () → string each
|
|
46
|
+
await hotswap.enableInterrupt(LM25066Full.SOURCE_VIN_UV_WARN); // Unmask an alert source, (source) → Promise<void>
|
|
47
|
+
await hotswap.disableInterrupt(LM25066Full.SOURCE_VIN_UV_WARN); // Mask an alert source, (source) → Promise<void>
|
|
48
|
+
console.log(await hotswap.pollInterrupt()); // Diagnostic word, () → number
|
|
49
|
+
await hotswap.onInterrupt((diag) => console.log("alert", diag)); // Subscribe to SMBA, (callback, {intPin}) → Promise<void>
|
|
50
|
+
await hotswap.offInterrupt(); // Unsubscribe, () → Promise<void>
|
|
51
|
+
await connection.close();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
main();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { LM25066Full } = require('../../../src/chips/power/lm25066');
|
|
5
|
+
|
|
6
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
const connection = new I2CConnection(1, 0x40); // Create I²C connection, (bus, addr=0x40) → Connection
|
|
10
|
+
const hotswap = new LM25066Full(connection, 1.0, false); // Create LM25066 driver, 12 V rail with 1 mΩ sense resistor
|
|
11
|
+
|
|
12
|
+
console.log(await hotswap.manufacturerId(), await hotswap.model(), await hotswap.revision()); // Identify the chip, () → string each
|
|
13
|
+
await hotswap.clearFaults(); // Release SMBA after power-up, () → Promise<void>
|
|
14
|
+
|
|
15
|
+
// Hot-swap rail monitor: one line per second for a minute
|
|
16
|
+
for (let i = 0; i < 60; i++) {
|
|
17
|
+
if (i === 30) {
|
|
18
|
+
await hotswap.setAveraging(6); // 64-sample averaging, (exponent) → Promise<void>
|
|
19
|
+
await hotswap.setVinUvWarn(10.0); // VIN under-voltage warning at 10 V, (volts) → Promise<void>
|
|
20
|
+
await hotswap.setIinWarn(20.0); // Input over-current warning at 20 A, (amps) → Promise<void>
|
|
21
|
+
await hotswap.enableInterrupt(LM25066Full.SOURCE_VIN_UV_WARN | LM25066Full.SOURCE_IIN_WARN); // Unmask both alerts, (source)
|
|
22
|
+
}
|
|
23
|
+
console.log(`VIN ${(await hotswap.voltageIn()).toFixed(2)} V VOUT ${(await hotswap.voltageOut()).toFixed(2)} V ` +
|
|
24
|
+
`IIN ${(await hotswap.current()).toFixed(3)} A (avg ${(await hotswap.currentAvg()).toFixed(3)}) ` +
|
|
25
|
+
`PIN ${(await hotswap.power()).toFixed(2)} W T ${(await hotswap.temperature()).toFixed(1)} C`);
|
|
26
|
+
await sleep(1000);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
console.log(`peak power ${(await hotswap.powerPeak()).toFixed(2)} W`); // Peak input power, () → number W
|
|
30
|
+
console.log('diagnostic 0x' + (await hotswap.pollInterrupt()).toString(16)); // Alert flags, () → number
|
|
31
|
+
await hotswap.clearFaults(); // Finish servicing, () → Promise<void>
|
|
32
|
+
|
|
33
|
+
if (process.argv.includes('--control')) {
|
|
34
|
+
await hotswap.operationOff(); // CUTS THE LOAD RAIL, () → Promise<void>
|
|
35
|
+
await sleep(1000);
|
|
36
|
+
await hotswap.operationOn(); // Switch the MOSFET back on, () → Promise<void>
|
|
37
|
+
}
|
|
38
|
+
await connection.close();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
main();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { LM25066Minimal } = require('../../../src/chips/power/lm25066');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x40); // Create I²C connection, (bus, addr=0x40) → Connection
|
|
7
|
+
const hotswap = new LM25066Minimal(connection, 1.0, false); // Create LM25066 driver, (connection, rSenseMohm, currentLimitHigh)
|
|
8
|
+
|
|
9
|
+
setInterval(async () => {
|
|
10
|
+
console.log(await hotswap.voltageIn(), await hotswap.voltageOut()); // Read VIN / VOUT, () → Promise<number> V each
|
|
11
|
+
console.log(await hotswap.current(), await hotswap.power(), await hotswap.temperature()); // Read A / W / MOSFET °C, () → Promise<number> each
|
|
12
|
+
}, 1000);
|