rpi-io 2.1.0 → 2.1.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/CHANGELOG.md +53 -0
- package/README.md +6 -304
- package/documentation/api.md +244 -0
- package/documentation/benchmark.md +22 -0
- package/documentation/examples.md +25 -0
- package/package.json +1 -1
- package/history.md +0 -48
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
## [2.1.2] - 2026-06-04
|
|
3
|
+
### Changed
|
|
4
|
+
- License MIT replaced by EUPL
|
|
5
|
+
|
|
6
|
+
## [2.1.1] - 2026-03-26
|
|
7
|
+
### Changed
|
|
8
|
+
- Updated doc organization and content
|
|
9
|
+
|
|
10
|
+
## [2.1.0] - 2026-03-26
|
|
11
|
+
### Added
|
|
12
|
+
- Default option in *constructor* method: `exporTime: -1` for automatic configuration of `exportTime` depending on device performance.
|
|
13
|
+
- Static method *Rio.model()* to return current RPi model.
|
|
14
|
+
|
|
15
|
+
## [2.0.11] - 2026-02-13
|
|
16
|
+
### Changed
|
|
17
|
+
- Minor updates in `README.md`:
|
|
18
|
+
* Typos in code examples, where imported class is *RIO*, not *Rio*.
|
|
19
|
+
* Details about Node.js pre-requisites.
|
|
20
|
+
|
|
21
|
+
## [2.0.9] - 2026-02-03
|
|
22
|
+
### Changed
|
|
23
|
+
- `package.json`: node-gyp version update to fix *tar* vulnerabilities
|
|
24
|
+
- `README.md`: Explanations for *tar* warnings.
|
|
25
|
+
|
|
26
|
+
## [2.0.5] - 2025-12-01
|
|
27
|
+
### Changed
|
|
28
|
+
- Typos
|
|
29
|
+
- Internal refactoring
|
|
30
|
+
|
|
31
|
+
## [2.0.0] - 2025-11-26
|
|
32
|
+
### Added
|
|
33
|
+
* Hybrid architecture Javascript + C addon to improve performances
|
|
34
|
+
* New API
|
|
35
|
+
|
|
36
|
+
## [1.2.2] - 2025-11-10
|
|
37
|
+
### Changed
|
|
38
|
+
* Utility API function name: `Rio.log` renamed to `Rio.logCfg`.
|
|
39
|
+
|
|
40
|
+
## [1.2.2] - 2025-11-07
|
|
41
|
+
### Added
|
|
42
|
+
* Option parameter for method `monitor` to take care of bias and bounces.
|
|
43
|
+
### Fixed
|
|
44
|
+
* Minor bugs and optimization
|
|
45
|
+
|
|
46
|
+
## [1.1.0] - 2025-10-31
|
|
47
|
+
### Added
|
|
48
|
+
* Support libgpiod 2.2.1
|
|
49
|
+
* Tested with *Trixie*
|
|
50
|
+
|
|
51
|
+
## [1.0.0] - 2025-10-23
|
|
52
|
+
### Added
|
|
53
|
+
Initial release: *Bookworm*, libgpiod 1.63
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# rpi-io
|
|
2
2
|
    
|
|
3
3
|
|
|
4
|
-
Current version is 2.1.
|
|
4
|
+
Current version is 2.1.1. More details in [CHANGELOG.md](CHANGELOG.md).
|
|
5
5
|
|
|
6
6
|
**rpi-io** is a lite [ESM](https://nodejs.org/api/esm.html#modules-ecmascript-modules) module for **Node.js** to control **Raspberry Pi** GPIO: access (in, out), input event detection and [PWM](https://en.wikipedia.org/wiki/Pulse-width_modulation) peripheral control.
|
|
7
7
|
|
|
@@ -334,310 +334,12 @@ import {RIO, sleep, ctrlC, } from "rpi-io"
|
|
|
334
334
|
})()
|
|
335
335
|
```
|
|
336
336
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
```bash
|
|
342
|
-
# Simple write
|
|
343
|
-
node /your-project/node_modules/rpi-io/test/write.js
|
|
344
|
-
|
|
345
|
-
# Read and monitor
|
|
346
|
-
node /your-project/node_modules/rpi-io/test/read.js
|
|
347
|
-
|
|
348
|
-
# LED fade-in on PWM line
|
|
349
|
-
node /your-project/node_modules/rpi-io/test/pwm-led.js
|
|
350
|
-
|
|
351
|
-
# Servo-motor SG90 controlled by PWM
|
|
352
|
-
node /your-project/node_modules/rpi-io/test/pwm-motor.js
|
|
353
|
-
|
|
354
|
-
# Test duplicated instance error
|
|
355
|
-
node /your-project/node_modules/rpi-io/test/duplicate-error.js
|
|
356
|
-
|
|
357
|
-
# Test close of all instances
|
|
358
|
-
node /your-project/node_modules/rpi-io/test/close-all.js
|
|
359
|
-
|
|
360
|
-
# Test GPIO line configuration
|
|
361
|
-
node /your-project/node_modules/rpi-io/test/line-configuration.js
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
## API
|
|
367
|
-
|
|
368
|
-
The **rpi-io** API is based on the class `RIO` with instance methods.
|
|
369
|
-
|
|
370
|
-
### RIO class and methods
|
|
371
|
-
|
|
372
|
-
#### constructor RIO(line, mode, opt)
|
|
373
|
-
To create instance according to parameters.
|
|
374
|
-
##### Example
|
|
375
|
-
```javascript
|
|
376
|
-
import {RIO} from "rpi-io"
|
|
377
|
-
const myOutput = new RIO(17, "output")
|
|
378
|
-
```
|
|
379
|
-
##### Parameter(s)
|
|
380
|
-
- **line** *{Number}* Must be one of the GPIO number as defined in [pinout.xyz](https://pinout.xyz).
|
|
381
|
-
- **mode** *{String}* Must be one of the following values: "output", "input", "pwm".
|
|
382
|
-
- **opt** *{Object}* Various options depending on selected mode. See details and default values below.
|
|
383
|
-
|
|
384
|
-
```javascript
|
|
385
|
-
{
|
|
386
|
-
// For 'output' mode: Initial value {0,1}.
|
|
387
|
-
value: 0,
|
|
388
|
-
|
|
389
|
-
// For 'input' mode: Circuit bias {"disable", "pull-up", "pull-down"}.
|
|
390
|
-
bias: "disable",
|
|
391
|
-
|
|
392
|
-
// For 'pwm' mode: Delay (ms) required on instance creation
|
|
393
|
-
// to prevent failure due to device performance.
|
|
394
|
-
//
|
|
395
|
-
// Since v2.1.0 the default value is set to -1, which means auto delay.
|
|
396
|
-
// It is computed according to device model e.g. 50 ms for 5Pi or 1000 ms RPi Zero.
|
|
397
|
-
exportTime: -1,
|
|
398
|
-
|
|
399
|
-
// For 'pwm' mode: Period defined in μs. Default value is equivalent to 50 Hz.
|
|
400
|
-
period: 20000,
|
|
401
|
-
|
|
402
|
-
// For 'pwm' mode: dutyMin and dutyMax defines the duty cycle use range in µs
|
|
403
|
-
// especially for servo-motors (See their specs!).
|
|
404
|
-
dutyMin: 0,
|
|
405
|
-
dutyMax: 20000
|
|
406
|
-
}
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
##### Return
|
|
410
|
-
|
|
411
|
-
*{Object}* RIO instance
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
#### close()
|
|
416
|
-
To close instance i.e.
|
|
417
|
-
|
|
418
|
-
- to prevent future use of the line with the current instance
|
|
419
|
-
- to stop related monitoring process if any
|
|
420
|
-
- to free PWM resources if any
|
|
421
|
-
|
|
422
|
-
To reuse a line when closed, a new instance must be created.
|
|
423
|
-
|
|
424
|
-
##### Example
|
|
425
|
-
|
|
426
|
-
```javascript
|
|
427
|
-
import {RIO} from "rpi-io"
|
|
428
|
-
const myOutput = new RIO(17, "output")
|
|
429
|
-
myOutput.close()
|
|
430
|
-
```
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
#### write(value)
|
|
435
|
-
|
|
436
|
-
To write some value to "output" instance.
|
|
437
|
-
|
|
438
|
-
##### Example
|
|
439
|
-
|
|
440
|
-
```javascript
|
|
441
|
-
import {RIO} from "rpi-io"
|
|
442
|
-
const myOutput = new RIO(17, "output")
|
|
443
|
-
myOuput.write(1)
|
|
444
|
-
```
|
|
445
|
-
|
|
446
|
-
##### Parameter(s)
|
|
447
|
-
|
|
448
|
-
- **value** *{Number}* 0 or 1
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
#### read()
|
|
453
|
-
|
|
454
|
-
To read value from "input" instance.
|
|
455
|
-
|
|
456
|
-
##### Example
|
|
457
|
-
|
|
458
|
-
```javascript
|
|
459
|
-
import {RIO} from "rpi-io"
|
|
460
|
-
const myInput = new RIO(18, "input")
|
|
461
|
-
const result = myInput.read()
|
|
462
|
-
```
|
|
463
|
-
|
|
464
|
-
##### Return
|
|
465
|
-
|
|
466
|
-
*{Number}* 0 or 1
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
#### monitoringStart(callback, edge, bounce)
|
|
471
|
-
|
|
472
|
-
To start event monitoring of "input" instance.
|
|
473
|
-
|
|
474
|
-
##### Example
|
|
475
|
-
|
|
476
|
-
```javascript
|
|
477
|
-
import {RIO} from "rpi-io"
|
|
478
|
-
const myButton = new RIO(18, "input")
|
|
479
|
-
const callback = edge => {
|
|
480
|
-
console.log("edge:", edge)
|
|
481
|
-
}
|
|
482
|
-
myButton.monitoringStart(callback, "both", 30)
|
|
483
|
-
```
|
|
484
|
-
|
|
485
|
-
##### Parameter(s)
|
|
486
|
-
|
|
487
|
-
- **callback** *{Function}* Function triggered by input events where parameter is *edge* that can be either "rising" (input change from 0 to 1) or "falling" (input change from 1 to 0).
|
|
488
|
-
- **edge** *{String}* Filter of monitored events: "rising", "falling", "both" (default value).
|
|
489
|
-
- **bounce** *{Number}* Set threshold in ms to filter consecutive events of same type. Default value is 0.
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
#### monitoringStop()
|
|
494
|
-
|
|
495
|
-
To stop event monitoring of "input" instance.
|
|
496
|
-
|
|
497
|
-
##### Example
|
|
498
|
-
|
|
499
|
-
```javascript
|
|
500
|
-
import {RIO} from "rpi-io"
|
|
501
|
-
const myButton = new RIO(18, "input")
|
|
502
|
-
const callback =
|
|
503
|
-
myButton.monitoringStart(edge => {console.log("edge:", edge)})
|
|
504
|
-
// Stop monitoring after 10s
|
|
505
|
-
setTimeout(() => {
|
|
506
|
-
myButton.monitoringStop()
|
|
507
|
-
}, 10000)
|
|
508
|
-
```
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
#### pwmDuty(percent)
|
|
513
|
-
|
|
514
|
-
To change the *duty cycle* of a "pwm" instance. The parameter is defined as a percentage to compute a *duty cycle* based on the *dutyMin* and *dutyMax* values of instance definition.
|
|
515
|
-
|
|
516
|
-
##### Example
|
|
517
|
-
|
|
518
|
-
```javascript
|
|
519
|
-
import {RIO} from "rpi-io"
|
|
520
|
-
// Servo-motor instance
|
|
521
|
-
const servo = new RIO(13, "pwm", {
|
|
522
|
-
exportTime: 100,
|
|
523
|
-
period: 20000,
|
|
524
|
-
dutyMin: 500,
|
|
525
|
-
dutyMax: 2500})
|
|
526
|
-
|
|
527
|
-
// duty cycle = 50% between dutyMin and dutyMax
|
|
528
|
-
servo.pwmDuty(50)
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
##### Parameter(s)
|
|
532
|
-
|
|
533
|
-
- **percent** *{Number}* 0 ≤ percent ≤ 100
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
### Static functions
|
|
538
|
-
|
|
539
|
-
#### RIO.closeAll()
|
|
540
|
-
Function to close all instances
|
|
541
|
-
##### Example
|
|
542
|
-
```javascript
|
|
543
|
-
import {RIO} from "rpi-io"
|
|
544
|
-
const led = new RIO(17, "output", {value: 0})
|
|
545
|
-
const btn = new RIO(18, "input")
|
|
546
|
-
RIO.closeAll()
|
|
547
|
-
// led and btn are closed
|
|
548
|
-
```
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
#### RIO.model()
|
|
553
|
-
|
|
554
|
-
Function to return current model of RPi.
|
|
555
|
-
|
|
556
|
-
```javascript
|
|
557
|
-
import {RIO} from "rpi-io"
|
|
558
|
-
console.log("model:", RIO.model())
|
|
559
|
-
// Returns '5B', '4B', '3B', 'Zero2', 'Zero' or '' when unknown.
|
|
560
|
-
```
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
### Utilities
|
|
565
|
-
|
|
566
|
-
#### log(args)
|
|
567
|
-
|
|
568
|
-
Function similar to `console.log` but with timestamped prompt. Must be enabled or not by function `traceCfg` defined thereafter.
|
|
569
|
-
|
|
570
|
-
#### warn(args)
|
|
571
|
-
|
|
572
|
-
Function similar to `log` but colored and prefixed by sign ⚠️.
|
|
573
|
-
|
|
574
|
-
#### traceCfg(level)
|
|
575
|
-
|
|
576
|
-
Function to enable functions `log` and `warn`.
|
|
577
|
-
|
|
578
|
-
##### Example for log, warn and traceCfg
|
|
579
|
-
|
|
580
|
-
```javascript
|
|
581
|
-
import {traceCfg, log, warn} from "rpi-io"
|
|
582
|
-
// traceCfg(0) => warn and log are disabled
|
|
583
|
-
// traceCfg(1) => warn is enabled and log is disabled
|
|
584
|
-
// traceCfg(2) => warn and log are enabled
|
|
585
|
-
traceCfg(2)
|
|
586
|
-
warn("This is important info")
|
|
587
|
-
log("This is useful info")
|
|
588
|
-
```
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
#### sleep(time)
|
|
593
|
-
|
|
594
|
-
Similar to `setTimeout` but in async mode.
|
|
595
|
-
|
|
596
|
-
#### ctrlC(function)
|
|
597
|
-
|
|
598
|
-
To run a callback function on ctrl+c event.
|
|
599
|
-
|
|
600
|
-
##### Example for sleep and ctrlC
|
|
601
|
-
|
|
602
|
-
```javascript
|
|
603
|
-
import {sleep, ctrlC} from "rpi-io"
|
|
604
|
-
(async () => {
|
|
605
|
-
ctrlC(() => {
|
|
606
|
-
console.log("displayed on script interrupt")
|
|
607
|
-
})
|
|
608
|
-
await sleep(10000)
|
|
609
|
-
console.log("displayed after 10s")
|
|
610
|
-
})()
|
|
611
|
-
```
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
## Benchmark
|
|
617
|
-
|
|
618
|
-
The following tables summarize main operation times on various devices. Results are in micro-seconds (µs).
|
|
619
|
-
|
|
620
|
-
**PLEASE NOTE**: As PWM operations rely on files, performance of microSD cards installed on RPi may have a significant impact on results for `pwmDuty()`.
|
|
621
|
-
|
|
622
|
-
**OS Bookworm with libgpiod v1.6.3**
|
|
623
|
-
|
|
624
|
-
| | RPi 5B | RPi 4B | RPi Zero2 |
|
|
625
|
-
| --------------- | ------- | ------- | --------- |
|
|
626
|
-
| write | 0.72 µs | 1.30 µs | 2,37 µs |
|
|
627
|
-
| read | 1.32 µs | 1,09 µs | 1,90 µs |
|
|
628
|
-
| pwmDuty (1 KHz) | 15.6 µs | 25,6 µs | 48,4 µs |
|
|
629
|
-
|
|
630
|
-
**OS Trixie with libgpiod v2.2.1**
|
|
631
|
-
|
|
632
|
-
| | RPi 5B | RPi 4B | RPi Zero2 |
|
|
633
|
-
| --------------- | ------------ | ------- | ------------ |
|
|
634
|
-
| write | *not tested* | 1.20 µs | *not tested* |
|
|
635
|
-
| read | *not tested* | 1.37 µs | *not tested* |
|
|
636
|
-
| pwmDuty (1 KHz) | *not tested* | 24,9 µs | *not tested* |
|
|
637
|
-
|
|
638
|
-
|
|
337
|
+
## More documentation
|
|
338
|
+
- [Examples](documentation/examples.md)
|
|
339
|
+
- [API reference guide](documentation/api.md)
|
|
340
|
+
- [Benchmark](documentation/benchmark.md)
|
|
639
341
|
|
|
640
342
|
## Licence
|
|
641
343
|
|
|
642
|
-
|
|
344
|
+
[EUPL](https://interoperable-europe.ec.europa.eu/collection/eupl)
|
|
643
345
|
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# rpi-io API reference
|
|
2
|
+
The **rpi-io** API is based on the class `RIO` with instance methods and a few static functions and utilities
|
|
3
|
+
|
|
4
|
+
## RIO class and methods
|
|
5
|
+
|
|
6
|
+
### constructor RIO(line, mode, opt)
|
|
7
|
+
|
|
8
|
+
To create instance according to parameters.
|
|
9
|
+
#### Example
|
|
10
|
+
```javascript
|
|
11
|
+
import {RIO} from "rpi-io"
|
|
12
|
+
const myOutput = new RIO(17, "output")
|
|
13
|
+
```
|
|
14
|
+
#### Parameter(s)
|
|
15
|
+
- **line** *{Number}* Must be one of the GPIO number as defined in [pinout.xyz](https://pinout.xyz).
|
|
16
|
+
- **mode** *{String}* Must be one of the following values: "output", "input", "pwm".
|
|
17
|
+
- **opt** *{Object}* Various options depending on selected mode. See details and default values below.
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
{
|
|
21
|
+
// For 'output' mode: Initial value {0,1}.
|
|
22
|
+
value: 0,
|
|
23
|
+
|
|
24
|
+
// For 'input' mode: Circuit bias {"disable", "pull-up", "pull-down"}.
|
|
25
|
+
bias: "disable",
|
|
26
|
+
|
|
27
|
+
// For 'pwm' mode: Delay (ms) required on instance creation
|
|
28
|
+
// to prevent failure due to device performance.
|
|
29
|
+
//
|
|
30
|
+
// Since v2.1.0 the default value is set to -1, which means auto delay.
|
|
31
|
+
// It is computed according to device model e.g. 50 ms for 5Pi or 1000 ms RPi Zero.
|
|
32
|
+
exportTime: -1,
|
|
33
|
+
|
|
34
|
+
// For 'pwm' mode: Period defined in μs. Default value is equivalent to 50 Hz.
|
|
35
|
+
period: 20000,
|
|
36
|
+
|
|
37
|
+
// For 'pwm' mode: dutyMin and dutyMax defines the duty cycle use range in µs
|
|
38
|
+
// especially for servo-motors (See their specs!).
|
|
39
|
+
dutyMin: 0,
|
|
40
|
+
dutyMax: 20000
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### Return
|
|
45
|
+
|
|
46
|
+
*{Object}* RIO instance
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### close()
|
|
51
|
+
To close instance i.e.
|
|
52
|
+
|
|
53
|
+
- to prevent future use of the line with the current instance
|
|
54
|
+
- to stop related monitoring process if any
|
|
55
|
+
- to free PWM resources if any
|
|
56
|
+
|
|
57
|
+
To reuse a line when closed, a new instance must be created.
|
|
58
|
+
|
|
59
|
+
#### Example
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
import {RIO} from "rpi-io"
|
|
63
|
+
const myOutput = new RIO(17, "output")
|
|
64
|
+
myOutput.close()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
### write(value)
|
|
70
|
+
|
|
71
|
+
To write some value to "output" instance.
|
|
72
|
+
|
|
73
|
+
#### Example
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
import {RIO} from "rpi-io"
|
|
77
|
+
const myOutput = new RIO(17, "output")
|
|
78
|
+
myOuput.write(1)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### Parameter(s)
|
|
82
|
+
|
|
83
|
+
- **value** *{Number}* 0 or 1
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### read()
|
|
88
|
+
|
|
89
|
+
To read value from "input" instance.
|
|
90
|
+
|
|
91
|
+
#### Example
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
import {RIO} from "rpi-io"
|
|
95
|
+
const myInput = new RIO(18, "input")
|
|
96
|
+
const result = myInput.read()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### Return
|
|
100
|
+
|
|
101
|
+
*{Number}* 0 or 1
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
### monitoringStart(callback, edge, bounce)
|
|
106
|
+
|
|
107
|
+
To start event monitoring of "input" instance.
|
|
108
|
+
|
|
109
|
+
#### Example
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
import {RIO} from "rpi-io"
|
|
113
|
+
const myButton = new RIO(18, "input")
|
|
114
|
+
const callback = edge => {
|
|
115
|
+
console.log("edge:", edge)
|
|
116
|
+
}
|
|
117
|
+
myButton.monitoringStart(callback, "both", 30)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### Parameter(s)
|
|
121
|
+
|
|
122
|
+
- **callback** *{Function}* Function triggered by input events where parameter is *edge* that can be either "rising" (input change from 0 to 1) or "falling" (input change from 1 to 0).
|
|
123
|
+
- **edge** *{String}* Filter of monitored events: "rising", "falling", "both" (default value).
|
|
124
|
+
- **bounce** *{Number}* Set threshold in ms to filter consecutive events of same type. Default value is 0.
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
### monitoringStop()
|
|
129
|
+
|
|
130
|
+
To stop event monitoring of "input" instance.
|
|
131
|
+
|
|
132
|
+
#### Example
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
import {RIO} from "rpi-io"
|
|
136
|
+
const myButton = new RIO(18, "input")
|
|
137
|
+
const callback =
|
|
138
|
+
myButton.monitoringStart(edge => {console.log("edge:", edge)})
|
|
139
|
+
// Stop monitoring after 10s
|
|
140
|
+
setTimeout(() => {
|
|
141
|
+
myButton.monitoringStop()
|
|
142
|
+
}, 10000)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
### pwmDuty(percent)
|
|
148
|
+
|
|
149
|
+
To change the *duty cycle* of a "pwm" instance. The parameter is defined as a percentage to compute a *duty cycle* based on the *dutyMin* and *dutyMax* values of instance definition.
|
|
150
|
+
|
|
151
|
+
#### Example
|
|
152
|
+
|
|
153
|
+
```javascript
|
|
154
|
+
import {RIO} from "rpi-io"
|
|
155
|
+
// Servo-motor instance
|
|
156
|
+
const servo = new RIO(13, "pwm", {
|
|
157
|
+
exportTime: 100,
|
|
158
|
+
period: 20000,
|
|
159
|
+
dutyMin: 500,
|
|
160
|
+
dutyMax: 2500})
|
|
161
|
+
|
|
162
|
+
// duty cycle = 50% between dutyMin and dutyMax
|
|
163
|
+
servo.pwmDuty(50)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### Parameter(s)
|
|
167
|
+
|
|
168
|
+
- **percent** *{Number}* 0 ≤ percent ≤ 100
|
|
169
|
+
|
|
170
|
+
## Static functions
|
|
171
|
+
|
|
172
|
+
### RIO.closeAll()
|
|
173
|
+
Function to close all instances
|
|
174
|
+
#### Example
|
|
175
|
+
```javascript
|
|
176
|
+
import {RIO} from "rpi-io"
|
|
177
|
+
const led = new RIO(17, "output", {value: 0})
|
|
178
|
+
const btn = new RIO(18, "input")
|
|
179
|
+
RIO.closeAll()
|
|
180
|
+
// led and btn are closed
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
### RIO.model()
|
|
186
|
+
|
|
187
|
+
Function to return current model of RPi.
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
import {RIO} from "rpi-io"
|
|
191
|
+
console.log("model:", RIO.model())
|
|
192
|
+
// Returns '5B', '4B', '3B', 'Zero2', 'Zero' or '' when unknown.
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Utilities
|
|
196
|
+
|
|
197
|
+
### log(args)
|
|
198
|
+
|
|
199
|
+
Function similar to `console.log` but with timestamped prompt. Must be enabled or not by function `traceCfg` defined thereafter.
|
|
200
|
+
|
|
201
|
+
### warn(args)
|
|
202
|
+
|
|
203
|
+
Function similar to `log` but colored and prefixed by sign ⚠️.
|
|
204
|
+
|
|
205
|
+
### traceCfg(level)
|
|
206
|
+
|
|
207
|
+
Function to enable functions `log` and `warn`.
|
|
208
|
+
|
|
209
|
+
#### Example for log, warn and traceCfg
|
|
210
|
+
|
|
211
|
+
```javascript
|
|
212
|
+
import {traceCfg, log, warn} from "rpi-io"
|
|
213
|
+
// traceCfg(0) => warn and log are disabled
|
|
214
|
+
// traceCfg(1) => warn is enabled and log is disabled
|
|
215
|
+
// traceCfg(2) => warn and log are enabled
|
|
216
|
+
traceCfg(2)
|
|
217
|
+
warn("This is important info")
|
|
218
|
+
log("This is useful info")
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
### sleep(time)
|
|
224
|
+
|
|
225
|
+
Similar to `setTimeout` but in async mode.
|
|
226
|
+
|
|
227
|
+
### ctrlC(function)
|
|
228
|
+
|
|
229
|
+
To run a callback function on ctrl+c event.
|
|
230
|
+
|
|
231
|
+
#### Example for sleep and ctrlC
|
|
232
|
+
|
|
233
|
+
```javascript
|
|
234
|
+
import {sleep, ctrlC} from "rpi-io"
|
|
235
|
+
(async () => {
|
|
236
|
+
ctrlC(() => {
|
|
237
|
+
console.log("displayed on script interrupt")
|
|
238
|
+
})
|
|
239
|
+
await sleep(10000)
|
|
240
|
+
console.log("displayed after 10s")
|
|
241
|
+
})()
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
# End of File
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Benchmark
|
|
2
|
+
|
|
3
|
+
The following tables summarize main operation times on various devices. Results are in micro-seconds (µs).
|
|
4
|
+
|
|
5
|
+
**PLEASE NOTE**: As PWM operations rely on files, performance of microSD cards installed on RPi may have a significant impact on results for `pwmDuty()`.
|
|
6
|
+
|
|
7
|
+
**OS Bookworm with libgpiod v1.6.3**
|
|
8
|
+
|
|
9
|
+
| | RPi 5B | RPi 4B | RPi Zero2 |
|
|
10
|
+
| --------------- | ------- | ------- | --------- |
|
|
11
|
+
| write | 0.72 µs | 1.30 µs | 2,37 µs |
|
|
12
|
+
| read | 1.32 µs | 1,09 µs | 1,90 µs |
|
|
13
|
+
| pwmDuty (1 KHz) | 15.6 µs | 25,6 µs | 48,4 µs |
|
|
14
|
+
|
|
15
|
+
**OS Trixie with libgpiod v2.2.1**
|
|
16
|
+
|
|
17
|
+
| | RPi 5B | RPi 4B | RPi Zero2 |
|
|
18
|
+
| --------------- | ------------ | ------- | ------------ |
|
|
19
|
+
| write | *not tested* | 1.20 µs | *not tested* |
|
|
20
|
+
| read | *not tested* | 1.37 µs | *not tested* |
|
|
21
|
+
| pwmDuty (1 KHz) | *not tested* | 24,9 µs | *not tested* |
|
|
22
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
To get familiar with the **rpi-io**, you might have a glance on examples and play with them with the GPIO lines of your own electronic circuit.
|
|
3
|
+
|
|
4
|
+
```bash
|
|
5
|
+
# Simple write
|
|
6
|
+
node /your-project/node_modules/rpi-io/test/write.js
|
|
7
|
+
|
|
8
|
+
# Read and monitor
|
|
9
|
+
node /your-project/node_modules/rpi-io/test/read.js
|
|
10
|
+
|
|
11
|
+
# LED fade-in on PWM line
|
|
12
|
+
node /your-project/node_modules/rpi-io/test/pwm-led.js
|
|
13
|
+
|
|
14
|
+
# Servo-motor SG90 controlled by PWM
|
|
15
|
+
node /your-project/node_modules/rpi-io/test/pwm-motor.js
|
|
16
|
+
|
|
17
|
+
# Test duplicated instance error
|
|
18
|
+
node /your-project/node_modules/rpi-io/test/duplicate-error.js
|
|
19
|
+
|
|
20
|
+
# Test close of all instances
|
|
21
|
+
node /your-project/node_modules/rpi-io/test/close-all.js
|
|
22
|
+
|
|
23
|
+
# Test GPIO line configuration
|
|
24
|
+
node /your-project/node_modules/rpi-io/test/line-configuration.js
|
|
25
|
+
```
|
package/package.json
CHANGED
package/history.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
2.1.0 - March 26, 2026
|
|
2
|
-
===================
|
|
3
|
-
|
|
4
|
-
* New default option in *constructor* method: `exporTime: -1` for automatic configuration of `exportTime` depending on device performance.
|
|
5
|
-
* New static method *Rio.model()* to return current RPi model.
|
|
6
|
-
|
|
7
|
-
2.0.11 - Feb 13, 2026
|
|
8
|
-
===================
|
|
9
|
-
|
|
10
|
-
* Minor updates in `README.md`:
|
|
11
|
-
* Fixes in code examples, where imported class is *RIO*, not *Rio*.
|
|
12
|
-
* Details about Node.js pre-requisites.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
2.0.9 - Feb 03, 2026
|
|
16
|
-
===================
|
|
17
|
-
* `package.json`: node-gyp version update to fix *tar* vulnerabilities
|
|
18
|
-
* `README.md`: Explanations for *tar* warnings.
|
|
19
|
-
|
|
20
|
-
2.0.5 - Dec 01, 2025
|
|
21
|
-
===================
|
|
22
|
-
* Typos
|
|
23
|
-
* Internal refactoring
|
|
24
|
-
|
|
25
|
-
2.0.0 - Nov 26, 2025
|
|
26
|
-
===================
|
|
27
|
-
* New hybrid architecture Javascript + C addon to improve performances
|
|
28
|
-
* New API
|
|
29
|
-
* Fixes
|
|
30
|
-
|
|
31
|
-
1.2.2 - Nov 10, 2025
|
|
32
|
-
===================
|
|
33
|
-
* Change utility API function name from `Rio.log` to `Rio.logCfg`.
|
|
34
|
-
* Minor fixes
|
|
35
|
-
|
|
36
|
-
1.2.0 - Nov 07, 2025
|
|
37
|
-
===================
|
|
38
|
-
* New option parameter for method `monitor` to take care of bias and bounces.
|
|
39
|
-
* Fixes and optimization
|
|
40
|
-
|
|
41
|
-
1.1.0 - Oct 31, 2025
|
|
42
|
-
===================
|
|
43
|
-
* Added support libgpiod 2.2.1
|
|
44
|
-
* Tested with *Trixie*
|
|
45
|
-
|
|
46
|
-
1.0.0 - Oct 23, 2025
|
|
47
|
-
===================
|
|
48
|
-
Initial release: *Bookworm*, libgpiod 1.63
|