UNPKG

homebridge-gpio-sensor-door

Version:

Raspberry Pi GPIO Doorsensor plugin for Homebridge forked from homebridge-gpio-garagedoor-d

40 lines 1.13 kB
"use strict"; const Promise = require("bluebird"); const onoff = require("onoff"); var Gpio = onoff.Gpio; var gpioReadAsync = Promise.promisify(Gpio.prototype.read); var gpioWriteAsync = Promise.promisify(Gpio.prototype.write); (function (GPIOState) { GPIOState[GPIOState["On"] = 1] = "On"; GPIOState[GPIOState["Off"] = 0] = "Off"; })(exports.GPIOState || (exports.GPIOState = {})); var GPIOState = exports.GPIOState; class GPIOPort extends Gpio { constructor(gpio, direction, edge) { super(gpio, direction, edge); var self = this; process.on('SIGINT', function () { self.unexport(); }); } ; getState(retryCount) { retryCount = retryCount != null ? retryCount : 3; let val = 0; for (var i = 0; i < retryCount; i++) { val = this.readSync(); if (val == 1) { break; } } return val; } ; readAsync() { return gpioReadAsync.call(this); } writeAsync(state) { return gpioWriteAsync.call(this, state); } } exports.GPIOPort = GPIOPort;