@clysema/raspberry-gpio

[![npm (scoped)](https://img.shields.io/npm/v/@clysema/raspberry-gpio.svg)](https://www.npmjs.com/package/@clysema/raspberry-gpio) [![npm bundle size (minified)](https://img.shields.io/bundlephobia/min/@clysema/raspberry-gpio.svg)](https://www.npmjs.com/p

Usage no npm install needed!

<script type="module">
  import clysemaRaspberryGpio from 'https://cdn.skypack.dev/@clysema/raspberry-gpio';
</script>

README

@clysema/raspberry-gpio

npm (scoped) npm bundle size (minified)

Simple wrapper for the onoff package.

Install

$ npm install @clysema/raspberry-gpio

Config

config/raspberry-gpio.json

[
  {
    "name": "IN1",
    "gpio": 22,
    "type": "input",
    "edge": "falling",
    "debounceTimeout": 100
  },
  {
    "name": "IN2",
    "gpio": 23,
    "type": "input"
  },
  {
    "name": "OUT1",
    "gpio": 24,
    "type": "output",
    "init": 1
  }
]

Usage

Is an event emitter:

// subscribe to data
app.modules["raspberry-gpio"].emitter.on("data", (data) => {
  console.log(data);
  // { name: 'IN1', value: 1 }
});

// subscribe to errors
app.modules["raspberry-gpio"].emitter.on("error", (error) => {
  console.log(error);
});

Read/Write:

console.log(await app.modules["raspberry-gpio"].readOutputs());
await app.modules["raspberry-gpio"].setOutput("OUT1", 0);
console.log(await app.modules["raspberry-gpio"].readOutputs());