This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

gpio-out-domapic

1.0.0 • Public • Published

Gpio Out Domapic

Handler to be used internally by Domapic Modules for controlling a gpio in "out" mode

Build status Coverage Status Quality Gate js-standard-style

NPM dependencies Last commit Last release

NPM downloads License


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 is false.
    • rememberLastStatus <boolean> Defines if the Gpio will save status to storage in order to remember the last one when it is restarted. Default is false.
    • invert <boolean> If true, the values read from or written to the GPIO should be inverted. Equivalent to the activeLow 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 is gpio.
    • 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 = require('path')
 
const domapic = require('domapic-service')
const gpioOut = require('gpio-out-domapic')
 
domapic.createModule({
  packagePath: path.resolve(__dirname),
  customConfig: {
    status: {
      type: 'boolean',
      describe: 'Set initial status of the relay when module is started',
      default: false
    }
  }
}).then(async dmpcModule => {
  const relay = new gpioOut.Gpio(dmpcModule, {
    rememberLastStatus: true
  }, {
    initialStatus: 'status'
  })
 
  await dmpcModule.register({
    toggle: {
      description: 'Toggle relay',
      action: {
        description: 'Toggle the relay status',
        handler: async () => {
          await relay.toggle()
          return Promise.resolve()
        }
      }
    }
  })
 
  await relay.init()
  return dmpcModule.start()
})

Now, the module can be started using the status option, which Gpio will use as initialStatus:

node server.js --status=true

Package Sidebar

Install

npm i gpio-out-domapic

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

12.2 kB

Total Files

10

Last publish

Collaborators

  • javierbrea