rpi-io 2.0.3 → 2.0.4

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/binding.gyp CHANGED
@@ -19,6 +19,14 @@
19
19
  ],
20
20
  "defines": [
21
21
  "<!@(sh -c 'chmod +x script/detect-gpiod-version.sh 2>/dev/null; bash script/detect-gpiod-version.sh 2>/dev/null || echo LIBGPIOD_V2')"
22
+ ],
23
+ "conditions": [
24
+ ["OS=='linux'", {
25
+ "libraries": [
26
+ "-lgpiod",
27
+ "-lpthread"
28
+ ]
29
+ }]
22
30
  ]
23
31
  }
24
32
  ]
package/esm/ctl.mjs ADDED
@@ -0,0 +1,47 @@
1
+ // -------------------------------------------------------------------
2
+ // RPI-IO: Control utilities
3
+ // -------------------------------------------------------------------
4
+ import {log, warn} from "./log.mjs"
5
+
6
+ /** ------------------------------------------------------------------
7
+ * @function sleep
8
+ * @description Wait before continuing
9
+ * @param {Number} ms
10
+ * @param {Boolean} track
11
+ */
12
+ export const sleep = (ms, track = true) => {
13
+ track ? log("sleeping", ms, "ms") : false
14
+ return new Promise(resolve => setTimeout(resolve, ms));
15
+ }
16
+
17
+ /** ------------------------------------------------------------------
18
+ * @function ctrlC
19
+ * @description Intercept ctrl+c then exec callback
20
+ * @param {Function} callback
21
+ */
22
+ export const ctrlC = callback => {
23
+ process.on("SIGINT", () => {
24
+ log("ctrl+c pressed")
25
+ typeof callback === "function" ? callback() : false
26
+ process.exit(0)
27
+ })
28
+ }
29
+
30
+ /** ------------------------------------------------------------------
31
+ * @function lineNumber
32
+ * @description Return nth process argument and check it is a number
33
+ * @param {Number} nth
34
+ * @return {Number}
35
+ */
36
+ export const lineNumber = nth => {
37
+ const arg = parseInt(process.argv[nth])
38
+ if (typeof arg !== "number" || arg !== arg) {
39
+ warn("Line number expected as argument")
40
+ return -1
41
+ }
42
+ return arg
43
+ }
44
+
45
+ // -------------------------------------------------------------------
46
+ // EoF
47
+ // -------------------------------------------------------------------
package/esm/log.mjs ADDED
@@ -0,0 +1,58 @@
1
+ // -------------------------------------------------------------------
2
+ // RPI-IO: Custom console.log
3
+ // -------------------------------------------------------------------
4
+ let debug = {
5
+ trace: false,
6
+ warn: true
7
+ }
8
+
9
+ /** ------------------------------------------------------------------
10
+ * @function traceCfg
11
+ * @description Set log configuration
12
+ * @param {Number} level 0: no log, 1: warn only, 2: warn and log
13
+ */
14
+ export const traceCfg = level => {
15
+ debug = {
16
+ trace: false,
17
+ warn: false
18
+ }
19
+ level > 1 ? debug.trace = true : false
20
+ level > 0 ? debug.warn = true : false
21
+ }
22
+
23
+ /** ------------------------------------------------------------------
24
+ * @function nowStr
25
+ * @description Return timestamp as formatted string
26
+ * @return {String}
27
+ */
28
+ const nowStr = () => {
29
+ const date = new Date()
30
+ return date.toLocaleTimeString() + "." + date.getMilliseconds().toLocaleString('en', {
31
+ minimumIntegerDigits: 3,
32
+ minimumFractionDigits: 0,
33
+ useGrouping: false
34
+ })
35
+ }
36
+
37
+ /** ------------------------------------------------------------------
38
+ * @function log
39
+ * @description Global customized timestamped console.log
40
+ * Requires global variable 'debug'
41
+ */
42
+ export const log = function () {
43
+ if (debug.trace)
44
+ console.log.apply(console, Array.prototype.concat.apply([nowStr(), "🔎 "], arguments))
45
+ }
46
+
47
+ /** ------------------------------------------------------------------
48
+ * @function warn
49
+ * @description Colored log for error messages ⚠️ nodejs only ~ CSS color #F50
50
+ */
51
+ export const warn = function () {
52
+ if (debug.warn)
53
+ console.log.apply(console, Array.prototype.concat.apply([nowStr(), "⚠️", "\x1b[38;2;255;80;0m", ...arguments, "\x1b[0m"]))
54
+ }
55
+
56
+ // -------------------------------------------------------------------
57
+ // EoF
58
+ // -------------------------------------------------------------------
package/esm/main.mjs CHANGED
@@ -3,7 +3,9 @@
3
3
  // -------------------------------------------------------------------
4
4
  import {createRequire} from "node:module"
5
5
  import {writeFileSync} from "node:fs"
6
- import {traceCfg, log, warn, sleep, ctrlC, lineConfig, lineNumber, wait} from "./_util.mjs"
6
+ import {traceCfg, log, warn} from "./log.mjs"
7
+ import {sleep, ctrlC,lineNumber} from "./ctl.mjs"
8
+ import {wait, lineConfig} from "./nut.mjs"
7
9
 
8
10
  export {traceCfg, log, warn, sleep, ctrlC, lineConfig, lineNumber}
9
11
  // -------------------------------------------------------------------
package/esm/nut.mjs ADDED
@@ -0,0 +1,30 @@
1
+ // -------------------------------------------------------------------
2
+ // RPI-IO: Nodejs utilities
3
+ // -------------------------------------------------------------------
4
+ import {execSync, spawnSync} from "node:child_process"
5
+ import {log} from "./log.mjs"
6
+ /** ------------------------------------------------------------------
7
+ * @function wait
8
+ * @description Wait before continuing (sync blocking mode)
9
+ * @param {Number} ms
10
+ */
11
+ export const wait = ms => {
12
+ log("waiting", ms, "ms")
13
+ spawnSync("sleep", [ms / 1000])
14
+ }
15
+
16
+ /** ------------------------------------------------------------------
17
+ * @function lineConfig
18
+ * @description Return line configuration
19
+ * @param {Number} line
20
+ * @return {String}
21
+ */
22
+ export const lineConfig = line => {
23
+ const stdout = execSync("pinctrl get " + line, {stdio: "pipe", encoding: "utf8"}).trim().split(/\s+/)
24
+ return stdout[stdout.length - 1].toLowerCase()
25
+ }
26
+
27
+
28
+ // -------------------------------------------------------------------
29
+ // EoF
30
+ // -------------------------------------------------------------------
package/history.md CHANGED
@@ -1,7 +1,7 @@
1
- 2.0.3 - Dec 1, 2025
1
+ 2.0.4 - Dec 1, 2025
2
2
  ===================
3
3
  * Typos
4
- * Less restrictive package.json and binding.gyp for dev purpose
4
+ * Internal refactoring
5
5
 
6
6
  2.0.0 - Nov 26, 2025
7
7
  ===================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rpi-io",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Nodejs module to control Raspberry Pi GPIO",
5
5
  "keywords": [
6
6
  "raspberry",
@@ -59,9 +59,7 @@
59
59
  "test-line": "node ./test/line-configuration.js"
60
60
  },
61
61
  "os": [
62
- "linux",
63
- "darwin",
64
- "win32"
62
+ "linux"
65
63
  ],
66
64
  "cpu": [
67
65
  "arm",
package/esm/_util.mjs DELETED
@@ -1,122 +0,0 @@
1
- // -------------------------------------------------------------------
2
- // RPI-IO: Nodejs tools and utilities
3
- // -------------------------------------------------------------------
4
- import {execSync} from "child_process"
5
- import {spawnSync} from "node:child_process"
6
-
7
- // -------------------------------------------------------------------
8
- // DEV UTILITIES
9
- // -------------------------------------------------------------------
10
- let debug = {
11
- trace: false,
12
- warn: true
13
- }
14
- /** ------------------------------------------------------------------
15
- * @function traceCfg
16
- * @description Set log configuration
17
- * @param {Number} level 0: no log, 1: warn only, 2: warn and log
18
- */
19
- export const traceCfg = level => {
20
- debug = {
21
- trace: false,
22
- warn: false
23
- }
24
- level > 1 ? debug.trace = true : false
25
- level > 0 ? debug.warn = true : false
26
- }
27
-
28
- /** ------------------------------------------------------------------
29
- * @function nowStr
30
- * @description Return timestamp as formatted string
31
- * @return {String}
32
- */
33
- const nowStr = () => {
34
- const date = new Date()
35
- return date.toLocaleTimeString() + "." + date.getMilliseconds().toLocaleString('en', {
36
- minimumIntegerDigits: 3,
37
- minimumFractionDigits: 0,
38
- useGrouping: false
39
- })
40
- }
41
-
42
- /** ------------------------------------------------------------------
43
- * @function log
44
- * @description Global customized timestamped console.log
45
- * Requires global variable 'debug'
46
- */
47
- export const log = function () {
48
- if (debug.trace)
49
- console.log.apply(console, Array.prototype.concat.apply([nowStr(), "🔎 "], arguments))
50
- }
51
-
52
- /** ------------------------------------------------------------------
53
- * @function warn
54
- * @description Colored log for error messages ⚠️ nodejs only ~ CSS color #F50
55
- */
56
- export const warn = function () {
57
- if (debug.warn)
58
- console.log.apply(console, Array.prototype.concat.apply([nowStr(), "⚠️", "\x1b[38;2;255;80;0m", ...arguments, "\x1b[0m"]))
59
- }
60
-
61
- /** ------------------------------------------------------------------
62
- * @function sleep
63
- * @description Wait before continuing
64
- * @param {Number} ms
65
- * @param {Boolean} track
66
- */
67
- export const sleep = (ms, track = true) => {
68
- track ? log("sleeping", ms, "ms") : false
69
- return new Promise(resolve => setTimeout(resolve, ms));
70
- }
71
-
72
- /** ------------------------------------------------------------------
73
- * @function wait
74
- * @description Wait before continuing (sync blocking mode)
75
- * @param {Number} ms
76
- */
77
- export const wait = ms => {
78
- log("waiting", ms, "ms")
79
- spawnSync("sleep", [ms / 1000])
80
- }
81
-
82
- /** ------------------------------------------------------------------
83
- * @function ctrlC
84
- * @description Intercept ctrl+c then exec callback
85
- * @param {Function} callback
86
- */
87
- export const ctrlC = callback => {
88
- process.on("SIGINT", () => {
89
- log("ctrl+c pressed")
90
- typeof callback === "function" ? callback() : false
91
- process.exit(0)
92
- })
93
- }
94
-
95
- /** ------------------------------------------------------------------
96
- * @function lineConfig
97
- * @description Return line configuration
98
- * @param {Number} line
99
- * @return {String}
100
- */
101
- export const lineConfig = line => {
102
- const stdout = execSync("pinctrl get " + line, {stdio: "pipe", encoding: "utf8"}).trim().split(/\s+/)
103
- return stdout[stdout.length - 1].toLowerCase()
104
- }
105
-
106
- /** ------------------------------------------------------------------
107
- * @function lineNumber
108
- * @param {Number} nth
109
- * @return {Number}
110
- */
111
- export const lineNumber = nth => {
112
- const arg = parseInt(process.argv[nth])
113
- if (typeof arg !== "number" || arg !== arg) {
114
- warn("Line number expected as argument")
115
- return -1
116
- }
117
- return arg
118
- }
119
-
120
- // -------------------------------------------------------------------
121
- // EoF
122
- // -------------------------------------------------------------------