Gpio Out Domapic
Handler to be used internally by Domapic Modules for controlling a gpio in "out" mode
Intro
This package provides a Domapic handler for controlling a relay using the onoff library internally. Passing 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 relay, and the handler will automatically load the configuration. Or you can also set the options with fixed values programatically.
Installation
npm i gpio-out-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.initialStatus
<boolean>
Defines the initial status of the gpio. Default isfalse
.rememberLastStatus
<boolean>
Defines if the Gpio will save status to storage in order to remember the last one when it is restarted. Default isfalse
.invert
<boolean>
If true, the values read from or written to the GPIO should be inverted. Equivalent to theactiveLow
option of the onoff library.
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
.initialStatus
<string>
Key defining the configuration property in which the initial status for the gpio is defined.rememberLastStatus
<string>
Key defining the configuration property in which the rememberLastStatus option is defined.invert
<string>
Key defining the configuration property in which the invert option is defined.
Instance
gpio.init()
async method
. Initializes the gpio retrieving configuration, etc.gpio.toggle()
async method
. Changes the relay status inverting the current value.gpio.setStatus(status)
async method
. Changes the relay status to the provided one.status
<boolean>
Defines the new status for the gpio.
gpio.status
getter
. Returns the current gpio status.
Example
In the next example, the gpio-out-domapic
package is used to create a Domapic Module that controls a relay that can be toogled using the built-in api:
const path = const domapic = const gpioOut = domapic
Now, the module can be started using the status
option, which Gpio will use as initialStatus
:
node server.js --status=true