periph 1.1.0 → 1.2.1
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 +61 -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/motor/drv8830/complete.js +50 -0
- package/examples/motor/drv8830/demo.js +57 -0
- package/examples/motor/drv8830/minimal.js +23 -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 +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/examples/rtc/ds3231/complete.js +77 -0
- package/examples/rtc/ds3231/demo.js +60 -0
- package/examples/rtc/ds3231/minimal.js +23 -0
- package/examples/rtc/pcf8523/complete.js +66 -0
- package/examples/rtc/pcf8523/demo.js +65 -0
- package/examples/rtc/pcf8523/minimal.js +20 -0
- package/examples/temperature/mcp9808/complete.js +89 -0
- package/examples/temperature/mcp9808/demo.js +62 -0
- package/examples/temperature/mcp9808/minimal.js +21 -0
- package/examples/temperature/tmp117/complete.js +90 -0
- package/examples/temperature/tmp117/demo.js +73 -0
- package/examples/temperature/tmp117/minimal.js +21 -0
- package/examples/tof/vl53l0x/complete.js +118 -0
- package/examples/tof/vl53l0x/demo.js +83 -0
- package/examples/tof/vl53l0x/minimal.js +25 -0
- package/examples/tof/vl53l1x/complete.js +151 -0
- package/examples/tof/vl53l1x/demo.js +100 -0
- package/examples/tof/vl53l1x/minimal.js +25 -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/motor/drv8830.js +239 -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 +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/chips/rtc/ds3231.js +504 -0
- package/src/chips/rtc/pcf8523.js +539 -0
- package/src/chips/temperature/mcp9808.js +488 -0
- package/src/chips/temperature/tmp117.js +471 -0
- package/src/chips/tof/_vl53_base.js +160 -0
- package/src/chips/tof/vl53l0x.js +816 -0
- package/src/chips/tof/vl53l1x.js +816 -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/examples/motor/.gitkeep +0 -0
- package/examples/temperature/.gitkeep +0 -0
- package/examples/tof/.gitkeep +0 -0
- package/src/chips/gnss/.gitkeep +0 -0
- package/src/chips/motor/.gitkeep +0 -0
- package/src/chips/temperature/.gitkeep +0 -0
- package/src/chips/tof/.gitkeep +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { PCF8591Full } = require('../../../src/chips/adc_dac/pcf8591');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x48', 16);
|
|
8
|
+
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
10
|
+
const adc = new PCF8591Full(connection);
|
|
11
|
+
|
|
12
|
+
const VREF = 3.3;
|
|
13
|
+
const VAGND = 0.0;
|
|
14
|
+
|
|
15
|
+
function delay(ms) {
|
|
16
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function run_feedback() {
|
|
20
|
+
// --- Wire a potentiometer across VAGND–VREF with the wiper to AIN0 ---
|
|
21
|
+
// Connect an LED (with series resistor) to AOUT. In a loop, read AIN0, map
|
|
22
|
+
// the 0–255 value to a DAC output value, and write it to AOUT — the LED
|
|
23
|
+
// brightness tracks the potentiometer. This demonstrates the ADC→DAC
|
|
24
|
+
// feedback path inside a single chip.
|
|
25
|
+
await adc.configure(PCF8591Full.MODE_4_SINGLE_ENDED, false, true); // Configure input mode, (input_mode=0–3, auto_increment=bool, dac_enabled=bool) → None
|
|
26
|
+
// single-ended mode with DAC output enabled
|
|
27
|
+
for (let n = 0; n < 20; n++) {
|
|
28
|
+
const raw = await adc.read_channel(0); // Read single channel, (channel=0–3) → number
|
|
29
|
+
const vin = VAGND + raw * (VREF - VAGND) / 256.0;
|
|
30
|
+
await adc.set_dac(raw); // Enable DAC and set raw value, (value=0–255) → None
|
|
31
|
+
const vout = VAGND + raw * (VREF - VAGND) / 256.0;
|
|
32
|
+
console.log(`n=${String(n).padStart(2)} raw=${String(raw).padStart(3)} vin=${vin.toFixed(3)}V vout=${vout.toFixed(3)}V`);
|
|
33
|
+
await delay(200);
|
|
34
|
+
}
|
|
35
|
+
console.log('Demo complete');
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
run_feedback();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { PCF8591Minimal } = require('../../../src/chips/adc_dac/pcf8591');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x48', 16);
|
|
8
|
+
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
10
|
+
const adc = new PCF8591Minimal(connection);
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
const ch0 = await adc.read_channel(0); // Read single channel, (channel=0–3) → number
|
|
14
|
+
const allRaw = await adc.read_all(); // Read all four channels, () → number[]
|
|
15
|
+
|
|
16
|
+
console.log('ch0=' + ch0);
|
|
17
|
+
console.log('all=' + JSON.stringify(allRaw));
|
|
18
|
+
console.log('PCF8591 minimal running');
|
|
19
|
+
})();
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { SPIConnection } = require('../../../src/connection/spi');
|
|
4
|
+
const { MCP2515Full } = require('../../../src/chips/comms/mcp2515');
|
|
5
|
+
|
|
6
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
7
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
8
|
+
const BITRATE = parseInt(process.env.MCP2515_BITRATE || '125', 10);
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: 0, maxSpeedHz: 10_000_000 }); // open SPI bus, (busNumber, deviceNumber, mode=0, maxSpeedHz=10e6) → SPIConnection
|
|
12
|
+
const chip = new MCP2515Full(connection, BITRATE); // create MCP2515 full driver, (connection, bitrateKbps=125, oscMhz=8) → MCP2515Full
|
|
13
|
+
|
|
14
|
+
const mode = await chip.getMode(); // read current operating mode, () → Promise<string>
|
|
15
|
+
// 'normal' after the constructor's init sequence
|
|
16
|
+
console.log('mode:', mode);
|
|
17
|
+
|
|
18
|
+
await chip.setFilter(0, 0x123, false); // configure filter 0, (filterNum=0, id=0x123, extended=false) → Promise<void>
|
|
19
|
+
// matches standard ID 0x123 only (when used with the right mask)
|
|
20
|
+
await chip.setMask(0, 0x7FF, false); // configure mask 0, (maskNum=0, mask=0x7FF, extended=false) → Promise<void>
|
|
21
|
+
// forces exact match on the 11-bit standard ID
|
|
22
|
+
await chip.setRxMode(0, 0); // set RX buffer 0 filter mode, (buf=0, mode=0) → Promise<void>
|
|
23
|
+
// 0 = accept standard IDs through filters/masks; 3 would accept-all
|
|
24
|
+
|
|
25
|
+
const data = Buffer.from([0xAA, 0xBB, 0xCC, 0xDD]);
|
|
26
|
+
await chip.sendBuffered(0x123, data, false, 0); // send on TX buffer 0, (id=0x123, data=4 B, extended=false, buf=0) → Promise<void>
|
|
27
|
+
// explicit buffer; 0/1/2 selectable; 0 wins ties at equal priority
|
|
28
|
+
await chip.send(0x456, Buffer.from([0x01, 0x02]), false); // send on next free buffer, (id=0x456, data=2 B, extended=false) → Promise<void>
|
|
29
|
+
// defaults to the first free of TXB0/TXB1/TXB2
|
|
30
|
+
|
|
31
|
+
await chip.send(0x18FF1234, Buffer.from([0x10, 0x20, 0x30, 0x40]), true); // send extended frame, (id=0x18FF1234 29-bit, data=4 B, extended=true) → Promise<void>
|
|
32
|
+
// EXIDE bit set in TXBnSIDL; full 29-bit identifier
|
|
33
|
+
|
|
34
|
+
const extendedFilterId = 0x18FF1234;
|
|
35
|
+
await chip.setFilter(2, extendedFilterId, true); // configure filter 2, (filterNum=2, id=0x18FF1234, extended=true) → Promise<void>
|
|
36
|
+
// matches the 29-bit extended ID exactly
|
|
37
|
+
await chip.setMask(1, 0x1FFFFFFF, true); // configure mask 1, (maskNum=1, mask=0x1FFFFFFF, extended=true) → Promise<void>
|
|
38
|
+
// requires all 29 extended-ID bits to match
|
|
39
|
+
await chip.setRxMode(1, 1); // set RX buffer 1 filter mode, (buf=1, mode=1) → Promise<void>
|
|
40
|
+
// 1 = accept extended IDs through filters/masks
|
|
41
|
+
|
|
42
|
+
await chip.setOneShot(true); // enable one-shot mode, (enable=true) → Promise<void>
|
|
43
|
+
// OSM in CANCTRL set; no retransmit on error or arbitration loss
|
|
44
|
+
await chip.setOneShot(false); // disable one-shot mode, (enable=false) → Promise<void>
|
|
45
|
+
// OSM cleared; default retransmit behaviour
|
|
46
|
+
|
|
47
|
+
await chip.setMode('loopback'); // switch to loopback mode, (mode='loopback') → Promise<void>
|
|
48
|
+
// TX frames are internally routed to RX; useful for self-test without a bus
|
|
49
|
+
|
|
50
|
+
const loopbackFrame = await chip.recv(1000); // receive one CAN frame, (timeoutMs=1000) → Promise<CanFrame | null>
|
|
51
|
+
if (loopbackFrame) {
|
|
52
|
+
console.log('loopback:', loopbackFrame);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await chip.setMode('normal'); // switch to normal mode, (mode='normal') → Promise<void>
|
|
56
|
+
// required for actual bus participation
|
|
57
|
+
|
|
58
|
+
const errors = await chip.readErrors(); // read error counters, () → Promise<{tec,rec,eflg}>
|
|
59
|
+
// tec/rec are TX/RX error counters; eflg is the EFLG register
|
|
60
|
+
console.log('errors:', errors);
|
|
61
|
+
|
|
62
|
+
const frame = await chip.recv(500); // receive one CAN frame, (timeoutMs=500) → Promise<CanFrame | null>
|
|
63
|
+
if (frame) {
|
|
64
|
+
console.log('received', frame);
|
|
65
|
+
await chip.clearOverflow(0); // clear RX0 overflow flag, (buf=0) → Promise<void>
|
|
66
|
+
// only relevant if the previous RX triggered RX0OVR
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
await chip.abortTx(); // abort all pending TX, () → Promise<void>
|
|
70
|
+
// sets ABAT in CANCTRL; waits for it to clear (max 500 ms)
|
|
71
|
+
await chip.reset(); // issue SPI RESET, () → Promise<void>
|
|
72
|
+
// all registers return to POR defaults; run init() again
|
|
73
|
+
|
|
74
|
+
await connection.close();
|
|
75
|
+
})();
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/* MCP2515 demo — heartbeat loopback round-trip on the CAN bus.
|
|
2
|
+
*
|
|
3
|
+
* Hardware: a single MCP2515 wired up (e.g. paired with an MCP2551
|
|
4
|
+
* transceiver on a real bus, or a second MCP2515 in loopback for
|
|
5
|
+
* desk-top testing). The demo configures loopback mode so the chip
|
|
6
|
+
* internally routes transmitted frames straight back into its own RX
|
|
7
|
+
* buffers — no external CAN transceiver required for the round-trip
|
|
8
|
+
* to succeed.
|
|
9
|
+
*
|
|
10
|
+
* Runs 10 TX/RX iterations: transmits a 4-byte uptime counter once
|
|
11
|
+
* per second, immediately waits up to 1 s for the chip's own RX path
|
|
12
|
+
* to deliver the frame back, and prints the received ID, DLC, and
|
|
13
|
+
* data bytes (hex). Reports total successful round trips.
|
|
14
|
+
*/
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const { SPIConnection } = require('../../../src/connection/spi');
|
|
18
|
+
const { MCP2515Full } = require('../../../src/chips/comms/mcp2515');
|
|
19
|
+
|
|
20
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
21
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
22
|
+
|
|
23
|
+
(async () => {
|
|
24
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: 0, maxSpeedHz: 10_000_000 });
|
|
25
|
+
const chip = new MCP2515Full(connection, 125); // create MCP2515 full driver, (connection, bitrateKbps=125, oscMhz=8) → MCP2515Full
|
|
26
|
+
|
|
27
|
+
// --- Configure for single-node loopback heartbeat ---
|
|
28
|
+
// Loopback mode bypasses the physical CAN bus — the chip's TX path is
|
|
29
|
+
// internally routed to RX, so a single MCP2515 can demonstrate the full
|
|
30
|
+
// TX → RX round trip without an external transceiver. This is the same
|
|
31
|
+
// mode the datasheet recommends for self-test / bench validation.
|
|
32
|
+
await chip.setMode('loopback'); // switch to loopback mode, (mode='loopback') → Promise<void>
|
|
33
|
+
// CANCTRL REQOP=010; chip stays on the bus but routes TX frames to its own RX
|
|
34
|
+
|
|
35
|
+
let ok = 0;
|
|
36
|
+
const total = 10;
|
|
37
|
+
for (let n = 0; n < total; n++) {
|
|
38
|
+
const tx = Buffer.alloc(4);
|
|
39
|
+
tx.writeUInt32BE(n, 0);
|
|
40
|
+
await chip.send(0x001, tx, false); // send heartbeat frame, (id=0x001 std, data=4 B, extended=false) → Promise<void>
|
|
41
|
+
// filled with the iteration counter, big-endian
|
|
42
|
+
|
|
43
|
+
const frame = await chip.recv(1000); // receive one CAN frame, (timeoutMs=1000) → Promise<CanFrame | null>
|
|
44
|
+
if (frame && frame.id === 0x001 && frame.data.equals(tx)) {
|
|
45
|
+
const hexId = '0x' + frame.id.toString(16).padStart(3, '0');
|
|
46
|
+
const hexDlc = frame.data.length;
|
|
47
|
+
const hexData = frame.data.toString('hex');
|
|
48
|
+
const kind = frame.extended ? 'EXT' : (frame.rtr ? 'RTR' : 'STD');
|
|
49
|
+
console.log(`[${n}] got ${kind} id=${hexId} dlc=${hexDlc} data=${hexData}`);
|
|
50
|
+
ok++;
|
|
51
|
+
} else {
|
|
52
|
+
console.log(`[${n}] no round-trip got=${frame ? frame.id : 'null'}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// --- Return to Normal mode before exit ---
|
|
59
|
+
// Leaving the chip in loopback would surprise the next user; switch
|
|
60
|
+
// back to Normal so the bus is in a known state when this program ends.
|
|
61
|
+
await chip.setMode('normal'); // switch to normal mode, (mode='normal') → Promise<void>
|
|
62
|
+
|
|
63
|
+
console.log(`done — ${ok}/${total} round trips successful`);
|
|
64
|
+
|
|
65
|
+
await connection.close();
|
|
66
|
+
})();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { SPIConnection } = require('../../../src/connection/spi');
|
|
4
|
+
const { MCP2515Minimal } = require('../../../src/chips/comms/mcp2515');
|
|
5
|
+
|
|
6
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
7
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
8
|
+
const BITRATE = parseInt(process.env.MCP2515_BITRATE || '125', 10);
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: 0, maxSpeedHz: 10_000_000 }); // open SPI bus, (busNumber, deviceNumber, mode=0, maxSpeedHz=10e6) → SPIConnection
|
|
12
|
+
const chip = new MCP2515Minimal(connection, BITRATE); // create MCP2515 driver, (connection, bitrateKbps=125, oscMhz=8) → MCP2515Minimal
|
|
13
|
+
// runs the chip's full init at construction (125 kbit/s @ 8 MHz, polled, accept-all)
|
|
14
|
+
|
|
15
|
+
const data = Buffer.from([0x01, 0x02, 0x03, 0x04]);
|
|
16
|
+
await chip.send(0x123, data); // send CAN frame, (id=0x123 standard, data=4 B, extended=false) → Promise<void>
|
|
17
|
+
console.log('sent id=0x123 data=' + data.toString('hex'));
|
|
18
|
+
|
|
19
|
+
const frame = await chip.recv(1000); // receive one CAN frame, (timeoutMs=1000) → Promise<CanFrame | null>
|
|
20
|
+
if (frame) {
|
|
21
|
+
console.log('received', frame);
|
|
22
|
+
} else {
|
|
23
|
+
console.log('no frame within 1000 ms');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
await connection.close();
|
|
27
|
+
})();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { RDA5807MFull } = require('../../../src/chips/comms/rda5807m');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x10', 16);
|
|
8
|
+
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
10
|
+
const fm = new RDA5807MFull(connection, 100.0, 8); // Create RDA5807M driver, (connection, frequencyMhz=100.0, volume=8)
|
|
11
|
+
// runs the init sequence and tunes to the initial frequency
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
await fm.setFrequency(97.5); // Tune to frequency, (frequencyMhz) → undefined
|
|
15
|
+
// computes CHAN from the current band/spacing and blocks until STC
|
|
16
|
+
console.log(await fm.frequency()); // Read tuned frequency, () → number MHz
|
|
17
|
+
// converts READCHAN back to MHz
|
|
18
|
+
|
|
19
|
+
await fm.setVolume(10); // Set volume, (level 0–15) → undefined
|
|
20
|
+
await fm.mute(false); // Mute/unmute, (enable) → undefined
|
|
21
|
+
// enable=true mutes; here we ensure audio is audible
|
|
22
|
+
|
|
23
|
+
const freq = await fm.seek(true); // Seek next station, (up=true) → number|null
|
|
24
|
+
// blocks until STC; returns null if SF (seek fail) is set
|
|
25
|
+
console.log(freq);
|
|
26
|
+
|
|
27
|
+
await fm.configure({ // Configure tuner, ({band, space, deEmphasis, seekThreshold, seekMode, clkMode, afcDisable, eastEurope50m}) → undefined
|
|
28
|
+
band: RDA5807MFull.BAND_WORLD, // re-tunes to the current frequency if band or space changed
|
|
29
|
+
space: RDA5807MFull.SPACE_100K,
|
|
30
|
+
deEmphasis: true,
|
|
31
|
+
seekThreshold: 8,
|
|
32
|
+
seekMode: true
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
await fm.setBassBoost(true); // Enable bass boost, (enable) → undefined
|
|
36
|
+
await fm.setMono(false); // Force mono/allow stereo, (enable) → undefined
|
|
37
|
+
await fm.setSoftmute(true); // Enable soft mute, (enable) → undefined
|
|
38
|
+
|
|
39
|
+
await fm.enableRds(true); // Enable RDS/RBDS, (enable) → undefined
|
|
40
|
+
setTimeout(async () => {
|
|
41
|
+
console.log(await fm.rdsReady()); // Check RDS group ready, () → bool
|
|
42
|
+
console.log(await fm.readRdsGroup()); // Read raw RDS blocks, () → number[]|null
|
|
43
|
+
|
|
44
|
+
console.log(await fm.isStereo()); // Check stereo indicator, () → bool
|
|
45
|
+
console.log(await fm.isStation()); // Check real station, () → bool
|
|
46
|
+
console.log(await fm.isReady()); // Check tuner ready, () → bool
|
|
47
|
+
console.log(await fm.signalStrength()); // Read RSSI, () → number 0–127
|
|
48
|
+
|
|
49
|
+
await fm.standby(true); // Power down/up, (enable) → undefined
|
|
50
|
+
setTimeout(async () => {
|
|
51
|
+
await fm.standby(false);
|
|
52
|
+
await fm.softReset(); // Pulse soft reset, () → undefined
|
|
53
|
+
}, 10);
|
|
54
|
+
}, 1000);
|
|
55
|
+
})();
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { RDA5807MFull } = require('../../../src/chips/comms/rda5807m');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x10', 16);
|
|
8
|
+
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
10
|
+
const fm = new RDA5807MFull(connection, 87.5, 10);
|
|
11
|
+
|
|
12
|
+
function sleep(ms) {
|
|
13
|
+
const end = Date.now() + ms;
|
|
14
|
+
while (Date.now() < end) {}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// --- FM band scanner ---
|
|
18
|
+
// Start at the bottom of the world-wide band and repeatedly seek upward with
|
|
19
|
+
// SKMODE=1 (stop at band limit, the Minimal/Full default) so a seek that
|
|
20
|
+
// returns null means the top of the band has been reached and the scan is done.
|
|
21
|
+
(async () => {
|
|
22
|
+
await fm.enableRds(true);
|
|
23
|
+
|
|
24
|
+
const stations = [];
|
|
25
|
+
while (true) {
|
|
26
|
+
const freq = await fm.seek(true);
|
|
27
|
+
if (freq === null) break;
|
|
28
|
+
if (!(await fm.isStation())) continue;
|
|
29
|
+
|
|
30
|
+
const rssi = await fm.signalStrength();
|
|
31
|
+
const stereo = (await fm.isStereo()) ? 'stereo' : 'mono';
|
|
32
|
+
let name = null;
|
|
33
|
+
|
|
34
|
+
// --- Try to read the Program Service (station) name via RDS ---
|
|
35
|
+
// Group types 0A/0B carry the 8-character PS name, four segments of two
|
|
36
|
+
// characters each, addressed by block B bits 1:0. Give the decoder up to
|
|
37
|
+
// 2 seconds to assemble a full name before moving on to the next station.
|
|
38
|
+
const psChars = new Array(8).fill(null);
|
|
39
|
+
const deadline = Date.now() + 2000;
|
|
40
|
+
while (Date.now() < deadline) {
|
|
41
|
+
if (await fm.rdsReady()) {
|
|
42
|
+
const group = await fm.readRdsGroup();
|
|
43
|
+
if (group !== null) {
|
|
44
|
+
const [, blockB, , blockD] = group;
|
|
45
|
+
const groupType = blockB >> 12;
|
|
46
|
+
const isBVariant = (blockB >> 11) & 1;
|
|
47
|
+
if (groupType === 0 && isBVariant === 0) {
|
|
48
|
+
const segment = blockB & 0x03;
|
|
49
|
+
psChars[segment * 2] = String.fromCharCode(blockD >> 8);
|
|
50
|
+
psChars[segment * 2 + 1] = String.fromCharCode(blockD & 0xFF);
|
|
51
|
+
if (!psChars.includes(null)) {
|
|
52
|
+
name = psChars.join('');
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
sleep(40);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const label = name ? name.trim() : '(no RDS name)';
|
|
62
|
+
console.log(`${freq.toFixed(2)} MHz RSSI=${rssi} ${stereo} ${label}`);
|
|
63
|
+
stations.push({ freq, rssi, stereo, label });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log();
|
|
67
|
+
console.log(`Scan complete: ${stations.length} station(s) found`);
|
|
68
|
+
})();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { RDA5807MMinimal } = require('../../../src/chips/comms/rda5807m');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x10', 16);
|
|
8
|
+
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
10
|
+
const fm = new RDA5807MMinimal(connection, 100.0, 8); // Create RDA5807M driver, (connection, frequencyMhz=100.0, volume=8)
|
|
11
|
+
|
|
12
|
+
setInterval(async () => {
|
|
13
|
+
const freq = await fm.seek(true); // Seek to next station, (up=true) → number|null
|
|
14
|
+
if (freq !== null) console.log(`${freq} MHz`);
|
|
15
|
+
}, 3000);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { SPIConnection } = require('../../../src/connection/spi');
|
|
4
|
+
const { RFM95Full } = require('../../../src/chips/comms/rfm9x');
|
|
5
|
+
|
|
6
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
7
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
8
|
+
const FREQ_HZ = parseInt(process.env.RFM9X_FREQ || '868000000', 10);
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: 0, maxSpeedHz: 5_000_000 }); // open SPI bus, (busNumber, deviceNumber, options) → SPIConnection
|
|
12
|
+
const radio = new RFM95Full(connection, FREQ_HZ); // create RFM95W full driver, (connection, frequencyHz=868e6) → RFM95Full
|
|
13
|
+
await radio.init();
|
|
14
|
+
|
|
15
|
+
const ver = await radio.version(); // read silicon version, () → Promise<number>
|
|
16
|
+
// expect 0x12 (SX1276)
|
|
17
|
+
console.log('version:', '0x' + ver.toString(16));
|
|
18
|
+
|
|
19
|
+
await radio.configure(7, 125.0, 5); // configure LoRa modem, (sf=6–12, bandwidthKhz=7.8–500, codingRate=5–8, crc=true) → Promise<void>
|
|
20
|
+
// sets SF=7, BW=125 kHz, CR 4/5
|
|
21
|
+
await radio.setTxPower(17, true); // set TX power, (powerDbm=2–20, usePaBoost=true) → Promise<void>
|
|
22
|
+
// PA_BOOST pin, +17 dBm
|
|
23
|
+
|
|
24
|
+
await radio.setFrequency(FREQ_HZ); // change carrier frequency, (frequencyHz=862e6–1020e6) → Promise<void>
|
|
25
|
+
await radio.standby(); // enter STDBY mode, () → Promise<void>
|
|
26
|
+
|
|
27
|
+
await radio.send(Buffer.from('hello world')); // send packet, (data=Buffer ≤255 B) → Promise<void>
|
|
28
|
+
// STDBY → fill FIFO → TX → poll TxDone → STDBY
|
|
29
|
+
|
|
30
|
+
const pkt = await radio.receive(2000); // receive single packet, (timeoutMs=2000) → Promise<Buffer | null>
|
|
31
|
+
// RXSINGLE → poll RxDone/RxTimeout → read FIFO
|
|
32
|
+
if (pkt) {
|
|
33
|
+
const rssi = await radio.lastPacketRssi(); // last packet RSSI, () → Promise<number> dBm
|
|
34
|
+
const snr = await radio.lastPacketSnr(); // last packet SNR, () → Promise<number> dB
|
|
35
|
+
console.log('packet:', pkt.toString('hex'), 'rssi=', rssi, 'snr=', snr);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await radio.receiveContinuous(); // enter continuous RX, () → Promise<void>
|
|
39
|
+
const buf = await radio.readPacket(); // read buffered packet, () → Promise<Buffer | null>
|
|
40
|
+
// drains FIFO when RxDone fires
|
|
41
|
+
if (buf) console.log('rx:', buf);
|
|
42
|
+
await radio.stopReceive(); // return to STDBY from RX_CONT, () → Promise<void>
|
|
43
|
+
|
|
44
|
+
await radio.sleep(); // enter SLEEP mode, () → Promise<void>
|
|
45
|
+
// lowest power; FIFO inaccessible
|
|
46
|
+
await new Promise(r => setTimeout(r, 250));
|
|
47
|
+
await radio.standby();
|
|
48
|
+
|
|
49
|
+
await connection.close();
|
|
50
|
+
})();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* RFM95W demo — two-node round-trip link test.
|
|
2
|
+
*
|
|
3
|
+
* Hardware: two RFM95W modules wired back-to-back (or two boards running
|
|
4
|
+
* the same code). Both configured for 868 MHz, SF=7, BW=125 kHz, CR 4/5.
|
|
5
|
+
*
|
|
6
|
+
* Runs 10 TX/RX iterations: transmits an incrementing 4-byte counter, then
|
|
7
|
+
* immediately waits up to 1 s for the peer to echo it back. Prints the
|
|
8
|
+
* round-trip time and per-packet RSSI/SNR on success, then reports the
|
|
9
|
+
* total packet loss.
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const { SPIConnection } = require('../../../src/connection/spi');
|
|
14
|
+
const { RFM95Full } = require('../../../src/chips/comms/rfm9x');
|
|
15
|
+
|
|
16
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
17
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
18
|
+
const FREQ_HZ = parseInt(process.env.RFM9X_FREQ || '868000000', 10);
|
|
19
|
+
|
|
20
|
+
(async () => {
|
|
21
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: 0, maxSpeedHz: 5_000_000 });
|
|
22
|
+
const radio = new RFM95Full(connection, FREQ_HZ); // create RFM95W driver, (connection, frequencyHz=868e6) → RFM95Full
|
|
23
|
+
await radio.init();
|
|
24
|
+
|
|
25
|
+
// --- Configure for short-range link test ---
|
|
26
|
+
// SF7 / 125 kHz / 4/5 keeps airtime low so the round-trip fits in a 1 s window;
|
|
27
|
+
// +17 dBm on PA_BOOST gives enough link margin for desk-top loop-back.
|
|
28
|
+
await radio.configure(7, 125.0, 5); // configure LoRa modem, (sf=7, bandwidthKhz=125.0, codingRate=5) → Promise<void>
|
|
29
|
+
await radio.setTxPower(17, true); // set TX power, (powerDbm=17, usePaBoost=true) → Promise<void>
|
|
30
|
+
|
|
31
|
+
let loss = 0;
|
|
32
|
+
const total = 10;
|
|
33
|
+
for (let n = 0; n < total; n++) {
|
|
34
|
+
const tx = Buffer.alloc(4);
|
|
35
|
+
tx.writeUInt32BE(n, 0);
|
|
36
|
+
const t0 = Date.now();
|
|
37
|
+
await radio.send(tx); // send packet, (data=Buffer ≤255 B) → Promise<void>
|
|
38
|
+
|
|
39
|
+
const rx = await radio.receive(1000); // receive single packet, (timeoutMs=1000) → Promise<Buffer | null>
|
|
40
|
+
const t1 = Date.now();
|
|
41
|
+
|
|
42
|
+
if (rx && rx.equals(tx)) {
|
|
43
|
+
const rssi = await radio.lastPacketRssi(); // last packet RSSI, () → Promise<number> dBm
|
|
44
|
+
const snr = await radio.lastPacketSnr(); // last packet SNR, () → Promise<number> dB
|
|
45
|
+
console.log(`[${n}] echo rtt=${t1 - t0} ms rssi=${rssi.toFixed(1)} snr=${snr.toFixed(1)}`);
|
|
46
|
+
} else {
|
|
47
|
+
loss++;
|
|
48
|
+
console.log(`[${n}] no echo pkt=${rx && rx.toString('hex')}`);
|
|
49
|
+
}
|
|
50
|
+
await new Promise(r => setTimeout(r, 200));
|
|
51
|
+
}
|
|
52
|
+
console.log(`done — ${total - loss}/${total} successful, ${loss} lost`);
|
|
53
|
+
|
|
54
|
+
await connection.close();
|
|
55
|
+
})();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { SPIConnection } = require('../../../src/connection/spi');
|
|
4
|
+
const { RFM95Minimal } = require('../../../src/chips/comms/rfm9x');
|
|
5
|
+
|
|
6
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
7
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
8
|
+
const FREQ_HZ = parseInt(process.env.RFM9X_FREQ || '868000000', 10);
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: 0, maxSpeedHz: 5_000_000 }); // open SPI bus, (busNumber, deviceNumber, options) → SPIConnection
|
|
12
|
+
const radio = new RFM95Minimal(connection, FREQ_HZ); // create RFM95W driver, (connection, frequencyHz=868e6) → RFM95Minimal
|
|
13
|
+
await radio.init(); // initialise the chip, () → Promise<void>
|
|
14
|
+
// FSK SLEEP → LoRa SLEEP → STDBY; resets FIFO bases + modem defaults
|
|
15
|
+
|
|
16
|
+
await radio.send(Buffer.from('hello')); // send packet, (data=Buffer ≤255 B) → Promise<void>
|
|
17
|
+
console.log('sent');
|
|
18
|
+
|
|
19
|
+
await connection.close();
|
|
20
|
+
})();
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
3
|
const { PCF8576Full } = require('../../../src/chips/display/pcf8576');
|
|
4
4
|
|
|
5
5
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x38', 16);
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const lcd = new PCF8576Full(
|
|
10
|
-
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const lcd = new PCF8576Full(connection); // Create PCF8576 driver, (connection)
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
await lcd.clear(); // Blank the display, () → void
|
|
11
13
|
// zeros all 40 columns of display RAM
|
|
12
|
-
lcd.deviceSelect(0);
|
|
14
|
+
await lcd.deviceSelect(0); // Select device on the bus, (subaddress 0–7) → void
|
|
13
15
|
// sets the subaddress counter for cascaded use
|
|
14
|
-
lcd.setMode(PCF8576Full.BACKPLANES_4, PCF8576Full.BIAS_1_3); // Set drive mode, (backplanes 1–4, bias 0/1) → void
|
|
16
|
+
await lcd.setMode(PCF8576Full.BACKPLANES_4, PCF8576Full.BIAS_1_3); // Set drive mode, (backplanes 1–4, bias 0/1) → void
|
|
15
17
|
// configures 1:4 multiplex with 1/3 bias
|
|
16
|
-
lcd.setBlink(PCF8576Full.BLINK_2_HZ);
|
|
18
|
+
await lcd.setBlink(PCF8576Full.BLINK_2_HZ); // Set blink frequency, (frequency 0–3) → void
|
|
17
19
|
// ~2 Hz blink for visual attention
|
|
18
|
-
lcd.setBank(PCF8576Full.BANK_0, PCF8576Full.BANK_0);
|
|
20
|
+
await lcd.setBank(PCF8576Full.BANK_0, PCF8576Full.BANK_0); // Select RAM bank, (input_bank 0/1, output_bank 0/1) → void
|
|
19
21
|
// selects rows 0-1 for both input and output
|
|
20
22
|
|
|
21
|
-
const digits = [5, 6, 7, 8];
|
|
22
|
-
const out = digits.map(d => PCF8576Full.SEVEN_SEG[d]);
|
|
23
|
-
lcd.writeRaw(0, out);
|
|
23
|
+
const digits = [5, 6, 7, 8];
|
|
24
|
+
const out = digits.map(d => PCF8576Full.SEVEN_SEG[d]); // Encode 7-segment digit, (digit 0–9) → number
|
|
25
|
+
await lcd.writeRaw(0, out); // Write raw bytes, (address 0–39, data) → void
|
|
24
26
|
// sets data pointer to 0 and writes all four digits
|
|
25
27
|
|
|
26
|
-
lcd.disable();
|
|
28
|
+
await lcd.disable(); // Disable display output, () → void
|
|
27
29
|
// blanks the panel while keeping RAM contents
|
|
28
|
-
lcd.enable();
|
|
30
|
+
await lcd.enable(); // Enable display output, () → void
|
|
29
31
|
// resumes output from RAM with the prior configuration
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
console.log('===DONE: 0 passed, 0 failed===');
|
|
33
|
+
await connection.close();
|
|
34
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
35
|
+
})();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
3
|
const { PCF8576Full } = require('../../../src/chips/display/pcf8576');
|
|
4
4
|
|
|
5
5
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x38', 16);
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
9
|
|
|
10
10
|
async function sleep(ms) {
|
|
11
11
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
@@ -17,7 +17,7 @@ async function sleep(ms) {
|
|
|
17
17
|
// encodes each digit using the chip's 1:4 multiplex bit layout (a/c/b/DP/f/e/g/d)
|
|
18
18
|
// and writes all four with one writeRaw() call. The countdown runs once per
|
|
19
19
|
// second and the terminal mirrors the value sent to the display.
|
|
20
|
-
const lcd = new PCF8576Full(
|
|
20
|
+
const lcd = new PCF8576Full(connection); // Create PCF8576 driver, (connection)
|
|
21
21
|
|
|
22
22
|
for (let n = 9999; n >= 0; n--) {
|
|
23
23
|
const d0 = Math.floor(n / 1000) % 10;
|
|
@@ -30,7 +30,7 @@ async function sleep(ms) {
|
|
|
30
30
|
PCF8576Full.SEVEN_SEG[d2], // Encode 7-segment digit, (digit 0–9) → number
|
|
31
31
|
PCF8576Full.SEVEN_SEG[d3], // Encode 7-segment digit, (digit 0–9) → number
|
|
32
32
|
];
|
|
33
|
-
lcd.writeRaw(0, out);
|
|
33
|
+
await lcd.writeRaw(0, out); // Write all four digits, (address 0, 4 bytes) → void
|
|
34
34
|
console.log(`countdown: ${String(n).padStart(4, '0')}`);
|
|
35
35
|
await sleep(1000);
|
|
36
36
|
}
|
|
@@ -40,9 +40,9 @@ async function sleep(ms) {
|
|
|
40
40
|
// signal that the demo has finished. Each digit's g segment is bit 1, so a
|
|
41
41
|
// 0x02 byte lights just the bar across the middle.
|
|
42
42
|
const dash = [0x02, 0x02, 0x02, 0x02];
|
|
43
|
-
lcd.writeRaw(0, dash);
|
|
43
|
+
await lcd.writeRaw(0, dash); // Write dash pattern, (address 0, 4 bytes) → void
|
|
44
44
|
console.log('countdown complete');
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
await connection.close();
|
|
47
47
|
console.log('===DONE: 0 passed, 0 failed===');
|
|
48
48
|
})();
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
3
|
const { PCF8576Minimal } = require('../../../src/chips/display/pcf8576');
|
|
4
4
|
|
|
5
5
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x38', 16);
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const lcd = new PCF8576Minimal(
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const lcd = new PCF8576Minimal(connection); // Create PCF8576 driver, (connection)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
(async () => {
|
|
12
|
+
const digits = [1, 2, 3, 4];
|
|
13
|
+
for (let i = 0; i < digits.length; i++) {
|
|
14
|
+
const seg = PCF8576Minimal.SEVEN_SEG[digits[i]]; // Encode 7-segment digit, (digit 0–9) → number
|
|
15
|
+
await lcd.setDigit7seg(i, seg); // Write one digit, (position 0–19, segments 0–255) → void
|
|
16
|
+
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
console.log('===DONE: 0 passed, 0 failed===');
|
|
18
|
+
await connection.close();
|
|
19
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
20
|
+
})();
|