Gpio In Domapic
Handler to be used internally by Domapic Modules for controlling a gpio in "in" mode
Intro
This package provides a Domapic handler for controlling a gpio in "in" mode using the onoff library internally. Passing to it a Domapic module instance, it will retrieve the module instance configuration defined when started the service, and will configure the gpio based on it.
Just define which are your module "options keys" for configuring the gpio, and the handler will automatically load the configuration. Or you can also set the options with fixed values programatically.
Installation
npm i gpio-in-domapic -save
Usage
new Gpio(domapicModule, [options[, configurationKeys]])
options
<object>
Object containing default values for options. Will apply these values if no configuration keys are provided.debounceTimeout
<boolean>
Defines the debounce time for emitting gpio events.
configurationKeys
<object>
Object defining configuration keys from which the options will be loaded.gpio
<string>
Key defining the configuration property in which the gpio number is defined. Default isgpio
.debounceTimeout
<string>
Key defining the configuration property in which thedebounceTimeout
option for the gpio is defined.
Instance
gpio.init()
async method
. Initializes the gpio retrieving configuration, etc.gpio.status
getter
. Returns the current gpio status.gpio.events
getter
. Returns gpio eventEmitter object. Read the events chapter for further info.
Statics
eventNames
<object>
Object containing gpio event names.
Events
Gpio instances emit events through an eventEmitter
object exposed in the events
getter. Event names are exposed in the Gpio static object eventNames
. Available events are:
Gpio.eventNames.ON
. Emitted when gpio status change totrue
Gpio.eventNames.OFF
. Emitted when gpio status change tofalse
Gpio.eventNames.CHANGE
. Emitted whenever the gpio status changes. It sends the new status as first argument to subscribed listeners.Gpio.eventNames.ERROR
. Emitted whenever the gpio throws an error. It sends the error as first argument to subscribed listeners.
Example
In the next example, the gpio-in-domapic
package is used to create a Domapic Module having an state for returning a door status, and emitting an event when the door status changes. It also allow users to decide the debounce time when starting the module.
const path = const domapic = const gpioIn = domapic
Now, the module can be started using the debounce
option, which Gpio will use as debounceTimeout
:
node server.js --gpio=18 --debounce=1500