UNPKG

@raiden733/homebridge-gpio-garagedoor

Version:

Raspberry Pi GPIO based Garage Door plugin for Homebridge

43 lines (42 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GPIOPort = exports.GPIOState = void 0; 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); var GPIOState; (function (GPIOState) { GPIOState[GPIOState["On"] = 1] = "On"; GPIOState[GPIOState["Off"] = 0] = "Off"; })(GPIOState || (exports.GPIOState = GPIOState = {})); class GPIOPort extends Gpio { constructor(gpio, direction, edge, options) { super(gpio, direction, edge, options); 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;