hb-rpi-tools 0.0.3 → 1.0.0

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/index.js CHANGED
@@ -4,6 +4,7 @@
4
4
  // Homebridge RPi Tools.
5
5
 
6
6
  /** Homebridge RPi Tools.
7
+ * see the {@tutorial hb-rpi-tools} tutorial.
7
8
  *
8
9
  * @module hb-rpi-tools
9
10
  */
@@ -1,4 +1,4 @@
1
- // hb-rpi-tools/lib/GpioDhtClient.js
1
+ // hb-rpi-tools/lib/DhtClient.js
2
2
  // Copyright © 2019-2026 Erik Baauw. All rights reserved.
3
3
  //
4
4
  // Homebridge RPi Tools.
@@ -7,9 +7,10 @@ import { EventEmitter, once } from 'node:events'
7
7
 
8
8
  /** Class to read a DHTxx sensor connected to a GPIO pin.
9
9
  *
10
+ * @class
10
11
  * @extends EventEmitter
11
12
  */
12
- class GpioDhtClient extends EventEmitter {
13
+ class DhtClient extends EventEmitter {
13
14
  constructor (parent, pi, gpio) {
14
15
  super()
15
16
  this.debug = parent.debug.bind(parent)
@@ -88,4 +89,4 @@ class GpioDhtClient extends EventEmitter {
88
89
  }
89
90
  }
90
91
 
91
- export { GpioDhtClient }
92
+ export { DhtClient }
@@ -1,4 +1,4 @@
1
- // hb-rpi-tools/lib/GpioClient/PigpioClient.js
1
+ // hb-rpi-tools/lib/GpioClient/Pigpio.js
2
2
  // Copyright © 2019-2026 Erik Baauw. All rights reserved.
3
3
  //
4
4
  // Homebridge RPi Tools.
@@ -328,9 +328,11 @@ const extCommands = [
328
328
 
329
329
  /** Client to pigpio's (remote) socket interface.
330
330
  *
331
+ * @class
331
332
  * @extends GpioClient
333
+ * @memberOf GpioClient
332
334
  */
333
- class PigpioClient extends GpioClient {
335
+ class Pigpio extends GpioClient {
334
336
  /** Create a new PigpioClient instance.
335
337
  *
336
338
  * @param {object} params - Parameters.
@@ -758,4 +760,4 @@ class PigpioClient extends GpioClient {
758
760
  }
759
761
  }
760
762
 
761
- GpioClient.Pigpio = PigpioClient
763
+ GpioClient.Pigpio = Pigpio
@@ -1,4 +1,4 @@
1
- // hb-rpi-tools/lib/GpioClient/RgpioClient.js
1
+ // hb-rpi-tools/lib/GpioClient/Rgpio.js
2
2
  // Copyright © 2019-2026 Erik Baauw. All rights reserved.
3
3
  //
4
4
  // Homebridge RPi Tools.
@@ -286,20 +286,22 @@ const pudValues = Object.freeze({
286
286
 
287
287
  /** Client to rgpio's (remote) socket interface.
288
288
  *
289
+ * @class
289
290
  * @extends GpioClient
291
+ * @memberOf GpioClient
290
292
  */
291
- class RgpioClient extends GpioClient {
293
+ class Rgpio extends GpioClient {
292
294
  /** Create a new RgpioClient instance.
293
295
  *
294
296
  * @param {object} params - Parameters.
295
297
  * @param {string} [params.host='localhost:8889'] - Hostname and port of
296
298
  * the rgpio server.<br>
297
299
  * Can also be specified through the environment variable LG_ADDR.
300
+ * @param {string} [params.user='homebridge-rpi'] - User name for rgpio server.<br>
301
+ * Can also be specified through the environment variable LG_USER.
298
302
  * @param {string} [params.password=''] - Password for rgpio server.<br>
299
303
  * Can also be specified through the environment variable LG_PASS.
300
304
  * @param {int} [timeout=15] - Timeout in seconds for socket operations.
301
- * @param {string} [params.user='homebridge-rpi'] - User name for rgpio server.<br>
302
- * Can also be specified through the environment variable LG_USER.
303
305
  */
304
306
  constructor (params = {}) {
305
307
  super()
@@ -769,4 +771,4 @@ class RgpioClient extends GpioClient {
769
771
  }
770
772
  }
771
773
 
772
- GpioClient.Rgpio = RgpioClient
774
+ GpioClient.Rgpio = Rgpio
package/lib/GpioClient.js CHANGED
@@ -8,6 +8,7 @@ import { createConnection } from 'node:net'
8
8
 
9
9
  /** Abstract superclass class for a client to a GPIO server.
10
10
  *
11
+ * @abstract
11
12
  * @extends EventEmitter
12
13
  * @hideconstructor
13
14
  */
@@ -94,9 +95,9 @@ class GpioClient extends EventEmitter {
94
95
  }
95
96
 
96
97
  /** Handle `data` events from the command socket.
97
- * @param {Buffer} data - The data.
98
- * @emits GpioClient#data
99
- */
98
+ * @param {Buffer} data - The data.
99
+ * @emits GpioClient#data
100
+ */
100
101
  #onCmdData (data) {
101
102
  /** Emitted when data from the pigpio socket has been received.
102
103
  * @event GpioClient#data
@@ -1,18 +1,20 @@
1
- // hb-rpi-tools/lib/GpioLedChain/Blinkt.js
1
+ // hb-rpi-tools/lib/LedChainClient/Blinkt.js
2
2
  // Copyright © 2019-2026 Erik Baauw. All rights reserved.
3
3
  //
4
4
  // Homebridge RPi Tools.
5
5
 
6
- import { GpioLedChain } from '../GpioLedChain.js'
6
+ import { LedChainClient } from '../LedChainClient.js'
7
7
 
8
8
  /** Class to control a Pimoroni Blinkt! (or similar devices, like the LED of
9
9
  * the Pimoroni FanShim).
10
10
  * @see https://shop.pimoroni.com/products/blinkt
11
11
  * @see https://shop.pimoroni.com/products/fan-shim
12
12
  *
13
- * @extends GpioLedChain
13
+ * @class
14
+ * @extends LedChainClient
15
+ * @memberOf LedChainClient
14
16
  */
15
- class Blinkt extends GpioLedChain {
17
+ class Blinkt extends LedChainClient {
16
18
  /** Encode LED state.
17
19
  * @param {int} [bri=0] - Brightness between 0 and 255.
18
20
  * @param {int} [r=0] - Red, between 0 and 255.
@@ -53,4 +55,4 @@ class Blinkt extends GpioLedChain {
53
55
  }
54
56
  }
55
57
 
56
- GpioLedChain.Blinkt = Blinkt
58
+ LedChainClient.Blinkt = Blinkt
@@ -3,7 +3,7 @@
3
3
  //
4
4
  // Homebridge RPi Tools.
5
5
 
6
- import { GpioLedChain } from '../GpioLedChain.js'
6
+ import { LedChainClient } from '../LedChainClient.js'
7
7
 
8
8
  function adjust (c, bri) {
9
9
  return (((c & 0xFF) * (bri & 0xFF)) / 0xFF) & 0xFF
@@ -11,9 +11,11 @@ function adjust (c, bri) {
11
11
  /** Class to control a chain of P9813-based LEDs, like the Grove Chainable LED.
12
12
  * @see https://github.com/Seeed-Studio/Grove_Chainable_RGB_LED
13
13
  *
14
- * @extends GpioLedChain
14
+ * @class
15
+ * @extends LedChainClient
16
+ * @memberOf LedChainClient
15
17
  */
16
- class P9813 extends GpioLedChain {
18
+ class P9813 extends LedChainClient {
17
19
  /** Encode LED state.
18
20
  * @param {int} [bri=0] - Brightness between 0 and 255.
19
21
  * @param {int} [r=0] - Red, between 0 and 255.
@@ -53,4 +55,4 @@ class P9813 extends GpioLedChain {
53
55
  }
54
56
  }
55
57
 
56
- GpioLedChain.P9813 = P9813
58
+ LedChainClient.P9813 = P9813
@@ -1,4 +1,4 @@
1
- // hb-rpi-tools/lib/GpioLedChain.js
1
+ // hb-rpi-tools/lib/LedChainClient.js
2
2
  // Copyright © 2019-2026 Erik Baauw. All rights reserved.
3
3
  //
4
4
  // Homebridge RPi Tools.
@@ -9,9 +9,11 @@ import { timeout } from 'hb-lib-tools'
9
9
 
10
10
  /** Abstract superclass to control a chain of LEDs using data and clock signals.
11
11
  *
12
+ * @class
13
+ * @abstract
12
14
  * @extends EventEmitter
13
15
  */
14
- class GpioLedChain extends EventEmitter {
16
+ class LedChainClient extends EventEmitter {
15
17
  /** Create a new socket to pigpiod for controlling the LED chain
16
18
  *
17
19
  * @param {GpioClient} pi - The Raspberry Pi with the LED chain.
@@ -261,4 +263,4 @@ class GpioLedChain extends EventEmitter {
261
263
  }
262
264
  }
263
265
 
264
- export { GpioLedChain }
266
+ export { LedChainClient }
package/lib/RpiTool.js CHANGED
@@ -23,7 +23,7 @@ const usage = {
23
23
  eventlog: `${b('eventlog')} [${b('-h')}] [${u('gpio')}...]`,
24
24
  gpio: `${b('gpio')} [${b('-h')}] ${u('gpio')} [${b('high')}|${b('low')}]`,
25
25
  dht: `${b('dht')} [${b('-h')}] ${u('gpio')}`,
26
- ledchain: `${b('ledchain')} [${b('-h')}] [${b('-B')}|${b('-P')}] [${b('-c')} ${u('gpio')} ${b('-d')} ${u('gpio')} ${b('-n')} ${u('nLeds')}] [${b('-b')} ${u('brightness')}] [${u('mode')}]`,
26
+ ledchain: `${b('ledchain')} [${b('-h')}] [${b('-B')}|${b('-F')}|${b('-P')}] [${b('-c')} ${u('gpio')} ${b('-d')} ${u('gpio')} ${b('-n')} ${u('nLeds')}] [${b('-b')} ${u('brightness')}] [${u('mode')}]`,
27
27
  pwm: `${b('pwm')} [${b('-h')}] ${u('gpio')} [${u('dutyCycle')}]`,
28
28
  servo: `${b('servo')} [${b('-h')}] ${u('gpio')} [${u('pulseWidth')}]`
29
29
  }
@@ -250,10 +250,14 @@ Parameters:
250
250
  Control Pimoroni Blinkt! LED chain (default).
251
251
  Sets clock to GPIO 24, data to GPIO 23, and number of LEDs to 8.
252
252
  You can change these with the ${b('-c')}, ${b('-d')}, and ${b('-n')} options.
253
- The Pimoroni FanShim uses GPIO 14 for clock, GPIO 15 for data, and has 1 LED.
253
+
254
+ ${b('-F')}, ${b('--fanshim')}
255
+ Control Pimoroni FanShim LED.
256
+ Sets clock to GPIO 14, data to GPIO 15, and number of LEDs to 1.
257
+ You can change these with the ${b('-c')}, ${b('-d')}, and ${b('-n')} options.
254
258
 
255
259
  ${b('-P')}, ${b('--p9813')}
256
- Use P9813-based LED chain.
260
+ Control P9813-based LED chain.
257
261
  Sets clock to GPIO 10, data to GPIO 11, and number of LEDs to 2.
258
262
  You can change these with the ${b('-c')}, ${b('-d')}, and ${b('-n')} options.
259
263
 
@@ -295,12 +299,12 @@ class RpiTool extends CommandLineTool {
295
299
  this._clargs = this.parseArguments()
296
300
  let Client
297
301
  if (this._clargs.port === 8888) {
298
- await import('../lib/GpioClient/PigpioClient.js')
302
+ await import('../lib/GpioClient/Pigpio.js')
299
303
  Client = GpioClient.Pigpio
300
304
  delete this._clargs.options.user
301
305
  delete this._clargs.options.password
302
306
  } else {
303
- await import('../lib/GpioClient/RgpioClient.js')
307
+ await import('../lib/GpioClient/Rgpio.js')
304
308
  Client = GpioClient.Rgpio
305
309
  }
306
310
  this.pi = new Client(this._clargs.options)
@@ -670,8 +674,8 @@ class RpiTool extends CommandLineTool {
670
674
  }
671
675
  this.pi
672
676
  .on('listen', (mask) => { this.debug('listening for %s', this.pi.vmap(mask)) })
673
- const { GpioDhtClient } = await import('../lib/GpioDhtClient.js')
674
- const dht = new GpioDhtClient(this, this.pi, clargs.gpio)
677
+ const { DhtClient } = await import('../lib/DhtClient.js')
678
+ const dht = new DhtClient(this, this.pi, clargs.gpio)
675
679
  this.pi.mask = 1 << clargs.gpio
676
680
  await this.pi.listen()
677
681
  const { temperature, humidity } = await dht.read()
@@ -701,6 +705,14 @@ class RpiTool extends CommandLineTool {
701
705
  nLeds: 8
702
706
  }
703
707
  })
708
+ .flag('F', 'fanshim', () => {
709
+ clargs.type = 'Blinkt'
710
+ clargs.config = {
711
+ gpioClock: 14,
712
+ gpioData: 15,
713
+ nLeds: 1
714
+ }
715
+ })
704
716
  .flag('P', 'p9813', () => {
705
717
  clargs.type = 'P9813'
706
718
  clargs.config = {
@@ -742,9 +754,9 @@ class RpiTool extends CommandLineTool {
742
754
  )
743
755
  }
744
756
 
745
- const { GpioLedChain } = await import('../lib/GpioLedChain.js')
746
- await import(`../lib/GpioLedChain/${clargs.type}.js`)
747
- this.ledChain = new GpioLedChain[clargs.type](this.pi, clargs.config)
757
+ const { LedChainClient } = await import('../lib/LedChainClient.js')
758
+ await import(`../lib/LedChainClient/${clargs.type}.js`)
759
+ this.ledChain = new LedChainClient[clargs.type](this.pi, clargs.config)
748
760
  this.ledChain
749
761
  .on('led', (id, led) => {
750
762
  this.vdebug('led %d: %j', id, led)
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": "0.0.3",
5
+ "version": "1.0.0",
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": "~2.2.16"
31
+ "hb-lib-tools": "~2.2.17"
32
32
  },
33
33
  "scripts": {
34
34
  "prepare": "standard && rm -rf out && jsdoc -c jsdoc.json",