hb-rpi-tools 1.0.0 → 1.0.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/lib/GpioClient/Pigpio.js +13 -8
- package/lib/GpioClient/Rgpio.js +13 -8
- package/lib/RpiTool.js +19 -11
- package/package.json +2 -2
package/lib/GpioClient/Pigpio.js
CHANGED
|
@@ -415,11 +415,17 @@ class Pigpio extends GpioClient {
|
|
|
415
415
|
* for sending commands and receiving responses.
|
|
416
416
|
* @throws `Error` - When connection fails.
|
|
417
417
|
* @emits connect
|
|
418
|
+
* @emits ready
|
|
418
419
|
*/
|
|
419
420
|
async connect () {
|
|
420
421
|
await super.connect()
|
|
421
422
|
await this.command(commands.HWVER)
|
|
422
423
|
this.emit('message', 'connected to pigpio')
|
|
424
|
+
|
|
425
|
+
/** Emitted when client is ready to use the pigpio socket.
|
|
426
|
+
* @event PigpioClient#ready
|
|
427
|
+
*/
|
|
428
|
+
this.emit('ready')
|
|
423
429
|
}
|
|
424
430
|
|
|
425
431
|
/** Subscribe to notifications for changed GPIO values.
|
|
@@ -689,14 +695,13 @@ class Pigpio extends GpioClient {
|
|
|
689
695
|
const status = (await this.command(
|
|
690
696
|
commands.SHELL, script.length, 0, script + '\0'
|
|
691
697
|
)).status
|
|
692
|
-
if (status
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
)
|
|
698
|
+
if (status !== 0) {
|
|
699
|
+
const message = status == null
|
|
700
|
+
? 'timeout'
|
|
701
|
+
: status === 32512
|
|
702
|
+
? 'script not found'
|
|
703
|
+
: `exit status ${status / 256}`
|
|
704
|
+
throw new Error(`${script}: ${message}`)
|
|
700
705
|
}
|
|
701
706
|
return status
|
|
702
707
|
}
|
package/lib/GpioClient/Rgpio.js
CHANGED
|
@@ -364,6 +364,7 @@ class Rgpio extends GpioClient {
|
|
|
364
364
|
* for sending commands and receiving responses.
|
|
365
365
|
* @throws `Error` - When connection fails.
|
|
366
366
|
* @emits connect
|
|
367
|
+
* @emits ready
|
|
367
368
|
*/
|
|
368
369
|
async connect () {
|
|
369
370
|
await super.connect()
|
|
@@ -396,6 +397,11 @@ class Rgpio extends GpioClient {
|
|
|
396
397
|
const result = await this.command(commands.GIC, { longs: [this.gpioChipHandle] })
|
|
397
398
|
this.emit('message', `${result.name}: ${result.label}`)
|
|
398
399
|
}
|
|
400
|
+
|
|
401
|
+
/** Emitted when client is ready to use the rgpio socket.
|
|
402
|
+
* @event RgpioClient#ready
|
|
403
|
+
*/
|
|
404
|
+
this.emit('ready')
|
|
399
405
|
}
|
|
400
406
|
|
|
401
407
|
/** Subscribe to notifications for changed GPIO values.
|
|
@@ -702,14 +708,13 @@ class Rgpio extends GpioClient {
|
|
|
702
708
|
const status = (await this.command(
|
|
703
709
|
commands.SHELL, { longs: [script.length + 1], string: script }
|
|
704
710
|
)).status
|
|
705
|
-
if (status
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
)
|
|
711
|
+
if (status !== 0) {
|
|
712
|
+
const message = status == null
|
|
713
|
+
? 'timeout'
|
|
714
|
+
: status === 32512
|
|
715
|
+
? 'script not found'
|
|
716
|
+
: `exit status ${status / 256}`
|
|
717
|
+
throw new Error(`${script}: ${message}`)
|
|
713
718
|
}
|
|
714
719
|
return status
|
|
715
720
|
}
|
package/lib/RpiTool.js
CHANGED
|
@@ -15,7 +15,7 @@ const { b, u } = CommandLineTool
|
|
|
15
15
|
const { UsageError } = CommandLineParser
|
|
16
16
|
|
|
17
17
|
const usage = {
|
|
18
|
-
rpi: `${b('rpi')} [${b('-hDV')}] [${b('-H')} ${u('hostname')}[${b(':')}${u('port')}]]] [${b('-U')} ${u('user')}] [${b('-P')} ${u('password')}] ${u('command')} [${u('argument')} ...]`,
|
|
18
|
+
rpi: `${b('rpi')} [${b('-hDV')}] [${b('-H')} ${u('hostname')}[${b(':')}${u('port')}]]] [${b('-U')} ${u('user')}] [${b('-P')} ${u('password')}] [${b('-t')} ${u('timeout')}] ${u('command')} [${u('argument')} ...]`,
|
|
19
19
|
info: `${b('info')} [${b('-hns')}]`,
|
|
20
20
|
state: `${b('state')} [${b('-hns')}]`,
|
|
21
21
|
test: `${b('test')} [${b('-hns')}]`,
|
|
@@ -76,6 +76,10 @@ Parameters:
|
|
|
76
76
|
Default is ${b('')} (empty).
|
|
77
77
|
The password can also be set through the environment variable ${b('LG_PASS')}.
|
|
78
78
|
|
|
79
|
+
${b('-t')} ${u('timeout')}, ${b('--timeout=')}${u('timeout')}
|
|
80
|
+
Set the command timeout in seconds.
|
|
81
|
+
Default is ${b('15')}.
|
|
82
|
+
|
|
79
83
|
Commands:
|
|
80
84
|
${usage.info}
|
|
81
85
|
${description.info}
|
|
@@ -352,7 +356,8 @@ class RpiTool extends CommandLineTool {
|
|
|
352
356
|
options: {
|
|
353
357
|
host: process.env.LG_ADDR || process.env.PIGPIO_ADDR || 'localhost',
|
|
354
358
|
user: process.env.LG_USER || 'homebridge-rpi',
|
|
355
|
-
password: process.env.LG_PASS || ''
|
|
359
|
+
password: process.env.LG_PASS || '',
|
|
360
|
+
timeout: 15
|
|
356
361
|
},
|
|
357
362
|
port: process.env.LG_ADDR == null && process.env.PIGPIO_ADDR != null ? 8888 : 8889
|
|
358
363
|
}
|
|
@@ -380,6 +385,9 @@ class RpiTool extends CommandLineTool {
|
|
|
380
385
|
.option('P', 'password', (value) => {
|
|
381
386
|
clargs.options.password = OptionParser.toString('password', value, true)
|
|
382
387
|
})
|
|
388
|
+
.option('t', 'timeout', (value) => {
|
|
389
|
+
clargs.options.timeout = OptionParser.toInt('timeout', value, 1, 60, true)
|
|
390
|
+
})
|
|
383
391
|
.parameter('command', (value) => {
|
|
384
392
|
if (usage[value] == null || typeof this[value] !== 'function') {
|
|
385
393
|
throw new UsageError(`${value}: unknown command`)
|
|
@@ -441,7 +449,7 @@ class RpiTool extends CommandLineTool {
|
|
|
441
449
|
return state
|
|
442
450
|
}
|
|
443
451
|
|
|
444
|
-
|
|
452
|
+
_parseCommandArgs (...args) {
|
|
445
453
|
const parser = new CommandLineParser(this.pkgJson)
|
|
446
454
|
const clargs = { options: {} }
|
|
447
455
|
parser
|
|
@@ -525,7 +533,7 @@ class RpiTool extends CommandLineTool {
|
|
|
525
533
|
.help('h', 'help', this.help)
|
|
526
534
|
.remaining((list) => {
|
|
527
535
|
for (const i in list) {
|
|
528
|
-
const gpio = OptionParser.toInt(`gpio[${i}]`, list[i])
|
|
536
|
+
const gpio = OptionParser.toInt(`gpio[${i}]`, list[i], 0, 31, true)
|
|
529
537
|
const bit = 1 << gpio
|
|
530
538
|
this.debug('gpio %d, bit %d', gpio, bit)
|
|
531
539
|
if ((bit & gpioMask) === 0) {
|
|
@@ -557,7 +565,7 @@ class RpiTool extends CommandLineTool {
|
|
|
557
565
|
parser
|
|
558
566
|
.help('h', 'help', this.help)
|
|
559
567
|
.parameter('gpio', (value) => {
|
|
560
|
-
clargs.gpio = OptionParser.toInt('gpio', value)
|
|
568
|
+
clargs.gpio = OptionParser.toInt('gpio', value, 0, 31, true)
|
|
561
569
|
})
|
|
562
570
|
.remaining((value) => {
|
|
563
571
|
if (value.length > 1) {
|
|
@@ -589,14 +597,14 @@ class RpiTool extends CommandLineTool {
|
|
|
589
597
|
parser
|
|
590
598
|
.help('h', 'help', this.help)
|
|
591
599
|
.parameter('gpio', (value) => {
|
|
592
|
-
clargs.gpio = OptionParser.toInt('gpio', value)
|
|
600
|
+
clargs.gpio = OptionParser.toInt('gpio', value, 0, 31, true)
|
|
593
601
|
})
|
|
594
602
|
.remaining((value) => {
|
|
595
603
|
if (value.length > 1) {
|
|
596
604
|
throw new UsageError('too many parameters')
|
|
597
605
|
}
|
|
598
606
|
if (value.length === 1) {
|
|
599
|
-
clargs.value = OptionParser.toInt('dutyCycle', value[0], 0, 100)
|
|
607
|
+
clargs.value = OptionParser.toInt('dutyCycle', value[0], 0, 100, true)
|
|
600
608
|
}
|
|
601
609
|
})
|
|
602
610
|
.parse(...args)
|
|
@@ -626,16 +634,16 @@ class RpiTool extends CommandLineTool {
|
|
|
626
634
|
parser
|
|
627
635
|
.help('h', 'help', this.help)
|
|
628
636
|
.parameter('gpio', (value) => {
|
|
629
|
-
clargs.gpio = OptionParser.toInt('gpio', value)
|
|
637
|
+
clargs.gpio = OptionParser.toInt('gpio', value, 0, 31, true)
|
|
630
638
|
})
|
|
631
639
|
.remaining((value) => {
|
|
632
640
|
if (value.length > 1) {
|
|
633
641
|
throw new UsageError('too many parameters')
|
|
634
642
|
}
|
|
635
643
|
if (value.length === 1) {
|
|
636
|
-
clargs.value = OptionParser.toInt('pulseWidth', value[0], 0)
|
|
644
|
+
clargs.value = OptionParser.toInt('pulseWidth', value[0], 0, 2500, true)
|
|
637
645
|
if (clargs.value !== 0) {
|
|
638
|
-
clargs.value = OptionParser.toInt('pulseWidth', value[0], 500, 2500)
|
|
646
|
+
clargs.value = OptionParser.toInt('pulseWidth', value[0], 500, 2500, true)
|
|
639
647
|
}
|
|
640
648
|
}
|
|
641
649
|
})
|
|
@@ -664,7 +672,7 @@ class RpiTool extends CommandLineTool {
|
|
|
664
672
|
parser
|
|
665
673
|
.help('h', 'help', this.help)
|
|
666
674
|
.parameter('gpio', (value) => {
|
|
667
|
-
clargs.gpio = OptionParser.toInt('gpio', value)
|
|
675
|
+
clargs.gpio = OptionParser.toInt('gpio', value, 0, 31, true)
|
|
668
676
|
})
|
|
669
677
|
.parse(...args)
|
|
670
678
|
const { gpioMask, model } = await this._getInfo()
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "hb-rpi-tools",
|
|
3
3
|
"description": "Homebridge RPi Tools",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.2",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"raspberrypi",
|
|
8
8
|
"raspberry",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"node": "^24||^22||^20"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"hb-lib-tools": "~
|
|
31
|
+
"hb-lib-tools": "~3.0.0"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"prepare": "standard && rm -rf out && jsdoc -c jsdoc.json",
|