'use strict';
'use warnings';

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _Options = _interopRequireDefault(require("./../../../Options"));

var _lodash = _interopRequireDefault(require("lodash"));

var _gpio = _interopRequireDefault(require("gpio"));

var _detectRpi = _interopRequireDefault(require("detect-rpi"));

var _child_process = require("child_process");

var index = /*#__PURE__*/function () {
  /**
   * @param {Object} config The Configuration Data Module Raspberry Pi
   * @param {boolean} config.enabled Disable The Module Raspberry Pi
   * @param {String} config.engine Engine Selection Prototype
   * @param {String} config.setDefaultLower Function For LowerState
   */
  function index(config) {
    var _this = this;

    (0, _classCallCheck2["default"])(this, index);
    (0, _defineProperty2["default"])(this, "pin", null);
    (0, _defineProperty2["default"])(this, "pinArray", []);
    (0, _defineProperty2["default"])(this, "config", {});
    (0, _defineProperty2["default"])(this, "exportInitialization", false);
    (0, _defineProperty2["default"])(this, "set", /*#__PURE__*/function () {
      var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(pin, State) {
        return _regenerator["default"].wrap(function _callee9$(_context9) {
          while (1) {
            switch (_context9.prev = _context9.next) {
              case 0:
                return _context9.abrupt("return", new Promise( /*#__PURE__*/function () {
                  var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(resolve, rejected) {
                    var mode;
                    return _regenerator["default"].wrap(function _callee8$(_context8) {
                      while (1) {
                        switch (_context8.prev = _context8.next) {
                          case 0:
                            if (!(0, _detectRpi["default"])()) {
                              _context8.next = 24;
                              break;
                            }

                            _context8.t0 = _this.config.engine;
                            _context8.next = _context8.t0 === _Options["default"].RASPBERRYPI_CORE_CLI ? 4 : _context8.t0 === _Options["default"].RASPBERRY_CORE_GPIO ? 8 : 22;
                            break;

                          case 4:
                            mode = State ? 1 : 0;
                            _context8.next = 7;
                            return new Promise( /*#__PURE__*/function () {
                              var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(SubResolve, Subrejected) {
                                return _regenerator["default"].wrap(function _callee2$(_context2) {
                                  while (1) {
                                    switch (_context2.prev = _context2.next) {
                                      case 0:
                                        _context2.next = 2;
                                        return (0, _child_process.exec)("gpio -g mode ".concat(pin, " ").concat(_this.config.direction), /*#__PURE__*/function () {
                                          var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(error, stdout, stderr) {
                                            return _regenerator["default"].wrap(function _callee$(_context) {
                                              while (1) {
                                                switch (_context.prev = _context.next) {
                                                  case 0:
                                                    if (error) {
                                                      _context.next = 5;
                                                      break;
                                                    }

                                                    _context.next = 3;
                                                    return SubResolve({
                                                      status: true
                                                    });

                                                  case 3:
                                                    _context.next = 6;
                                                    break;

                                                  case 5:
                                                    Subrejected({
                                                      status: false,
                                                      code: 500,
                                                      msg: "Error Open GPIO pin ".concat(pin, " to mode ").concat(_this.config.direction),
                                                      error: error
                                                    });

                                                  case 6:
                                                  case "end":
                                                    return _context.stop();
                                                }
                                              }
                                            }, _callee);
                                          }));

                                          return function (_x7, _x8, _x9) {
                                            return _ref4.apply(this, arguments);
                                          };
                                        }());

                                      case 2:
                                      case "end":
                                        return _context2.stop();
                                    }
                                  }
                                }, _callee2);
                              }));

                              return function (_x5, _x6) {
                                return _ref3.apply(this, arguments);
                              };
                            }()).then( /*#__PURE__*/function () {
                              var _ref5 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(res) {
                                var mReturn;
                                return _regenerator["default"].wrap(function _callee4$(_context4) {
                                  while (1) {
                                    switch (_context4.prev = _context4.next) {
                                      case 0:
                                        mReturn = {};
                                        _context4.next = 3;
                                        return (0, _child_process.exec)("gpio -g write ".concat(pin, " ").concat(mode), /*#__PURE__*/function () {
                                          var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(error, stdout, stderr) {
                                            return _regenerator["default"].wrap(function _callee3$(_context3) {
                                              while (1) {
                                                switch (_context3.prev = _context3.next) {
                                                  case 0:
                                                    mReturn = !error ? {
                                                      status: true
                                                    } : function (e) {
                                                      throw e;
                                                    }({
                                                      status: false,
                                                      code: 500,
                                                      msg: "cannot set pin ".concat(pin, " to ").concat(mode),
                                                      error: error
                                                    });

                                                  case 1:
                                                  case "end":
                                                    return _context3.stop();
                                                }
                                              }
                                            }, _callee3);
                                          }));

                                          return function (_x11, _x12, _x13) {
                                            return _ref6.apply(this, arguments);
                                          };
                                        }());

                                      case 3:
                                        return _context4.abrupt("return", mReturn);

                                      case 4:
                                      case "end":
                                        return _context4.stop();
                                    }
                                  }
                                }, _callee4);
                              }));

                              return function (_x10) {
                                return _ref5.apply(this, arguments);
                              };
                            }()).then( /*#__PURE__*/function () {
                              var _ref7 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(res) {
                                return _regenerator["default"].wrap(function _callee5$(_context5) {
                                  while (1) {
                                    switch (_context5.prev = _context5.next) {
                                      case 0:
                                        !res.status ? resolve({
                                          status: true,
                                          pin: "".concat(pin),
                                          state: State,
                                          mode: _this.config.direction
                                        }) : function (e) {
                                          throw e;
                                        }(res);

                                      case 1:
                                      case "end":
                                        return _context5.stop();
                                    }
                                  }
                                }, _callee5);
                              }));

                              return function (_x14) {
                                return _ref7.apply(this, arguments);
                              };
                            }())["catch"]( /*#__PURE__*/function () {
                              var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(err) {
                                return _regenerator["default"].wrap(function _callee6$(_context6) {
                                  while (1) {
                                    switch (_context6.prev = _context6.next) {
                                      case 0:
                                        _context6.next = 2;
                                        return rejected(err);

                                      case 2:
                                      case "end":
                                        return _context6.stop();
                                    }
                                  }
                                }, _callee6);
                              }));

                              return function (_x15) {
                                return _ref8.apply(this, arguments);
                              };
                            }());

                          case 7:
                            return _context8.abrupt("break", 22);

                          case 8:
                            if (_this.exportInitialization) {
                              _context8.next = 12;
                              break;
                            }

                            _context8.next = 11;
                            return _gpio["default"]["export"]("".concat(pin), {
                              direction: _this.config.direction,
                              ready: function () {
                                var _ready = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
                                  return _regenerator["default"].wrap(function _callee7$(_context7) {
                                    while (1) {
                                      switch (_context7.prev = _context7.next) {
                                        case 0:
                                          _this.exportInitialization = true;

                                        case 1:
                                        case "end":
                                          return _context7.stop();
                                      }
                                    }
                                  }, _callee7);
                                }));

                                function ready() {
                                  return _ready.apply(this, arguments);
                                }

                                return ready;
                              }()
                            });

                          case 11:
                            _this.pin = _context8.sent;

                          case 12:
                            _context8.next = 14;
                            return State;

                          case 14:
                            if (!_context8.sent) {
                              _context8.next = 18;
                              break;
                            }

                            _this.pin.set();

                            _context8.next = 19;
                            break;

                          case 18:
                            _this.pin.set(0);

                          case 19:
                            _context8.next = 21;
                            return resolve({
                              status: true,
                              code: 200,
                              msg: "Successfully to set pin ".concat(pin, " to ").concat(State)
                            });

                          case 21:
                            return _context8.abrupt("break", 22);

                          case 22:
                            _context8.next = 25;
                            break;

                          case 24:
                            rejected({
                              status: false,
                              code: 500,
                              msg: "This Device Not Raspbbery Pi Device"
                            });

                          case 25:
                          case "end":
                            return _context8.stop();
                        }
                      }
                    }, _callee8);
                  }));

                  return function (_x3, _x4) {
                    return _ref2.apply(this, arguments);
                  };
                }()));

              case 1:
              case "end":
                return _context9.stop();
            }
          }
        }, _callee9);
      }));

      return function (_x, _x2) {
        return _ref.apply(this, arguments);
      };
    }());
    (0, _defineProperty2["default"])(this, "toggle", /*#__PURE__*/function () {
      var _ref9 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee24(pin) {
        var lowerDefault,
            delay,
            _args24 = arguments;
        return _regenerator["default"].wrap(function _callee24$(_context24) {
          while (1) {
            switch (_context24.prev = _context24.next) {
              case 0:
                lowerDefault = _args24.length > 1 && _args24[1] !== undefined ? _args24[1] : _this.config.setDefaultLower;
                delay = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : 100;
                return _context24.abrupt("return", new Promise( /*#__PURE__*/function () {
                  var _ref10 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee23(resolve, rejected) {
                    return _regenerator["default"].wrap(function _callee23$(_context23) {
                      while (1) {
                        switch (_context23.prev = _context23.next) {
                          case 0:
                            if (!(0, _detectRpi["default"])()) {
                              _context23.next = 27;
                              break;
                            }

                            _context23.t0 = _this.config.engine;
                            _context23.next = _context23.t0 === _Options["default"].RASPBERRYPI_CORE_CLI ? 4 : _context23.t0 === _Options["default"].RASPBERRY_CORE_GPIO ? 11 : 25;
                            break;

                          case 4:
                            if (!(_this.config.direction.direction !== _Options["default"].GPIO_DIR_IN)) {
                              _context23.next = 9;
                              break;
                            }

                            _context23.next = 7;
                            return new Promise( /*#__PURE__*/function () {
                              var _ref11 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(Subresolve, Subrejected) {
                                return _regenerator["default"].wrap(function _callee11$(_context11) {
                                  while (1) {
                                    switch (_context11.prev = _context11.next) {
                                      case 0:
                                        _context11.next = 2;
                                        return (0, _child_process.exec)("gpio -g mode ".concat(pin, " ").concat(_this.config.direction), /*#__PURE__*/function () {
                                          var _ref12 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(error, stdout, stderr) {
                                            return _regenerator["default"].wrap(function _callee10$(_context10) {
                                              while (1) {
                                                switch (_context10.prev = _context10.next) {
                                                  case 0:
                                                    if (error) {
                                                      _context10.next = 5;
                                                      break;
                                                    }

                                                    _context10.next = 3;
                                                    return Subresolve({
                                                      status: true
                                                    });

                                                  case 3:
                                                    _context10.next = 6;
                                                    break;

                                                  case 5:
                                                    Subrejected({
                                                      status: false,
                                                      pin: pin,
                                                      code: 500,
                                                      msg: "Error Open GPIO pin ".concat(pin, " to mode ").concat(_this.config.direction),
                                                      error: error
                                                    });

                                                  case 6:
                                                  case "end":
                                                    return _context10.stop();
                                                }
                                              }
                                            }, _callee10);
                                          }));

                                          return function (_x21, _x22, _x23) {
                                            return _ref12.apply(this, arguments);
                                          };
                                        }());

                                      case 2:
                                      case "end":
                                        return _context11.stop();
                                    }
                                  }
                                }, _callee11);
                              }));

                              return function (_x19, _x20) {
                                return _ref11.apply(this, arguments);
                              };
                            }()).then( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee18() {
                              return _regenerator["default"].wrap(function _callee18$(_context18) {
                                while (1) {
                                  switch (_context18.prev = _context18.next) {
                                    case 0:
                                      _context18.next = 2;
                                      return lowerDefault;

                                    case 2:
                                      if (!_context18.sent) {
                                        _context18.next = 7;
                                        break;
                                      }

                                      _context18.next = 5;
                                      return (0, _child_process.exec)("gpio -g write ".concat(pin, " 0"), /*#__PURE__*/function () {
                                        var _ref14 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(error, stdout, stderr) {
                                          return _regenerator["default"].wrap(function _callee14$(_context14) {
                                            while (1) {
                                              switch (_context14.prev = _context14.next) {
                                                case 0:
                                                  if (error) {
                                                    _context14.next = 5;
                                                    break;
                                                  }

                                                  _context14.next = 3;
                                                  return setTimeout( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13() {
                                                    return _regenerator["default"].wrap(function _callee13$(_context13) {
                                                      while (1) {
                                                        switch (_context13.prev = _context13.next) {
                                                          case 0:
                                                            _context13.next = 2;
                                                            return (0, _child_process.exec)("gpio -g write ".concat(pin, " 1"), /*#__PURE__*/function () {
                                                              var _ref16 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(error, stdout, stderr) {
                                                                return _regenerator["default"].wrap(function _callee12$(_context12) {
                                                                  while (1) {
                                                                    switch (_context12.prev = _context12.next) {
                                                                      case 0:
                                                                        !error ? resolve({
                                                                          status: true,
                                                                          pin: "".concat(pin),
                                                                          toggle: true,
                                                                          mode: _this.config.direction
                                                                        }) : function (e) {
                                                                          throw e;
                                                                        }({
                                                                          status: false,
                                                                          code: 500,
                                                                          pin: pin,
                                                                          msg: "cannot set pin ".concat(pin, " to true"),
                                                                          error: error
                                                                        });

                                                                      case 1:
                                                                      case "end":
                                                                        return _context12.stop();
                                                                    }
                                                                  }
                                                                }, _callee12);
                                                              }));

                                                              return function (_x27, _x28, _x29) {
                                                                return _ref16.apply(this, arguments);
                                                              };
                                                            }());

                                                          case 2:
                                                          case "end":
                                                            return _context13.stop();
                                                        }
                                                      }
                                                    }, _callee13);
                                                  })), delay);

                                                case 3:
                                                  _context14.next = 6;
                                                  break;

                                                case 5:
                                                  (function (e) {
                                                    throw e;
                                                  })({
                                                    status: false,
                                                    code: 500,
                                                    pin: pin,
                                                    msg: "cannot set pin ".concat(pin, " to false"),
                                                    error: error
                                                  });

                                                case 6:
                                                case "end":
                                                  return _context14.stop();
                                              }
                                            }
                                          }, _callee14);
                                        }));

                                        return function (_x24, _x25, _x26) {
                                          return _ref14.apply(this, arguments);
                                        };
                                      }());

                                    case 5:
                                      _context18.next = 9;
                                      break;

                                    case 7:
                                      _context18.next = 9;
                                      return (0, _child_process.exec)("gpio -g write ".concat(pin, " 1"), /*#__PURE__*/function () {
                                        var _ref17 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17(error, stdout, stderr) {
                                          return _regenerator["default"].wrap(function _callee17$(_context17) {
                                            while (1) {
                                              switch (_context17.prev = _context17.next) {
                                                case 0:
                                                  if (error) {
                                                    _context17.next = 5;
                                                    break;
                                                  }

                                                  _context17.next = 3;
                                                  return setTimeout( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16() {
                                                    return _regenerator["default"].wrap(function _callee16$(_context16) {
                                                      while (1) {
                                                        switch (_context16.prev = _context16.next) {
                                                          case 0:
                                                            _context16.next = 2;
                                                            return (0, _child_process.exec)("gpio -g write ".concat(pin, " 0"), /*#__PURE__*/function () {
                                                              var _ref19 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15(error, stdout, stderr) {
                                                                return _regenerator["default"].wrap(function _callee15$(_context15) {
                                                                  while (1) {
                                                                    switch (_context15.prev = _context15.next) {
                                                                      case 0:
                                                                        !error ? resolve({
                                                                          status: true,
                                                                          pin: "".concat(pin),
                                                                          toggle: true,
                                                                          mode: _this.config.direction
                                                                        }) : function (e) {
                                                                          throw e;
                                                                        }({
                                                                          status: false,
                                                                          code: 500,
                                                                          pin: pin,
                                                                          msg: "cannot set pin ".concat(pin, " to false"),
                                                                          error: error
                                                                        });

                                                                      case 1:
                                                                      case "end":
                                                                        return _context15.stop();
                                                                    }
                                                                  }
                                                                }, _callee15);
                                                              }));

                                                              return function (_x33, _x34, _x35) {
                                                                return _ref19.apply(this, arguments);
                                                              };
                                                            }());

                                                          case 2:
                                                          case "end":
                                                            return _context16.stop();
                                                        }
                                                      }
                                                    }, _callee16);
                                                  })), delay);

                                                case 3:
                                                  _context17.next = 6;
                                                  break;

                                                case 5:
                                                  (function (e) {
                                                    throw e;
                                                  })({
                                                    status: false,
                                                    code: 500,
                                                    pin: pin,
                                                    msg: "cannot set pin ".concat(pin, " to true"),
                                                    error: error
                                                  });

                                                case 6:
                                                case "end":
                                                  return _context17.stop();
                                              }
                                            }
                                          }, _callee17);
                                        }));

                                        return function (_x30, _x31, _x32) {
                                          return _ref17.apply(this, arguments);
                                        };
                                      }());

                                    case 9:
                                    case "end":
                                      return _context18.stop();
                                  }
                                }
                              }, _callee18);
                            })))["catch"]( /*#__PURE__*/function () {
                              var _ref20 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee19(error) {
                                return _regenerator["default"].wrap(function _callee19$(_context19) {
                                  while (1) {
                                    switch (_context19.prev = _context19.next) {
                                      case 0:
                                        rejected(error);

                                      case 1:
                                      case "end":
                                        return _context19.stop();
                                    }
                                  }
                                }, _callee19);
                              }));

                              return function (_x36) {
                                return _ref20.apply(this, arguments);
                              };
                            }());

                          case 7:
                            _context23.next = 10;
                            break;

                          case 9:
                            rejected({
                              status: false,
                              code: 501,
                              msg: "This Pin not in direction Mode "
                            });

                          case 10:
                            return _context23.abrupt("break", 25);

                          case 11:
                            if (_this.exportInitialization) {
                              _context23.next = 15;
                              break;
                            }

                            _context23.next = 14;
                            return _gpio["default"]["export"]("".concat(pin), {
                              direction: _this.config.direction,
                              ready: function () {
                                var _ready2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee20() {
                                  return _regenerator["default"].wrap(function _callee20$(_context20) {
                                    while (1) {
                                      switch (_context20.prev = _context20.next) {
                                        case 0:
                                          _this.exportInitialization = true;

                                        case 1:
                                        case "end":
                                          return _context20.stop();
                                      }
                                    }
                                  }, _callee20);
                                }));

                                function ready() {
                                  return _ready2.apply(this, arguments);
                                }

                                return ready;
                              }()
                            });

                          case 14:
                            _this.pin = _context23.sent;

                          case 15:
                            if (!_this.config.setDefaultLower) {
                              _context23.next = 21;
                              break;
                            }

                            _context23.next = 18;
                            return _this.pin.set(0);

                          case 18:
                            setTimeout( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee21() {
                              return _regenerator["default"].wrap(function _callee21$(_context21) {
                                while (1) {
                                  switch (_context21.prev = _context21.next) {
                                    case 0:
                                      _context21.next = 2;
                                      return _this.pin.set();

                                    case 2:
                                      _context21.next = 4;
                                      return resolve({
                                        status: false,
                                        code: 200,
                                        msg: "Successfully Execute Command Set pin ".concat(pin)
                                      });

                                    case 4:
                                    case "end":
                                      return _context21.stop();
                                  }
                                }
                              }, _callee21);
                            })), delay);
                            _context23.next = 24;
                            break;

                          case 21:
                            _context23.next = 23;
                            return _this.pin.set();

                          case 23:
                            setTimeout( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee22() {
                              return _regenerator["default"].wrap(function _callee22$(_context22) {
                                while (1) {
                                  switch (_context22.prev = _context22.next) {
                                    case 0:
                                      _context22.next = 2;
                                      return _this.pin.set(0);

                                    case 2:
                                      _context22.next = 4;
                                      return resolve({
                                        status: false,
                                        code: 200,
                                        msg: "Successfully Execute Command Set pin ".concat(pin)
                                      });

                                    case 4:
                                    case "end":
                                      return _context22.stop();
                                  }
                                }
                              }, _callee22);
                            })), delay);

                          case 24:
                            return _context23.abrupt("break", 25);

                          case 25:
                            _context23.next = 28;
                            break;

                          case 27:
                            rejected({
                              status: false,
                              code: 500,
                              msg: "This Device Not Raspbbery Pi Device"
                            });

                          case 28:
                          case "end":
                            return _context23.stop();
                        }
                      }
                    }, _callee23);
                  }));

                  return function (_x17, _x18) {
                    return _ref10.apply(this, arguments);
                  };
                }()));

              case 3:
              case "end":
                return _context24.stop();
            }
          }
        }, _callee24);
      }));

      return function (_x16) {
        return _ref9.apply(this, arguments);
      };
    }());
    (0, _defineProperty2["default"])(this, "read", /*#__PURE__*/function () {
      var _ref23 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee26(pin, callback) {
        return _regenerator["default"].wrap(function _callee26$(_context26) {
          while (1) {
            switch (_context26.prev = _context26.next) {
              case 0:
                _context26.next = 2;
                return (0, _child_process.exec)("gpio -g read ".concat(pin), /*#__PURE__*/function () {
                  var _ref24 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee25(err, stdout, stderr) {
                    return _regenerator["default"].wrap(function _callee25$(_context25) {
                      while (1) {
                        switch (_context25.prev = _context25.next) {
                          case 0:
                            _context25.next = 2;
                            return callback(Number(stdout.replace(/\r?\n|\r/g, "")));

                          case 2:
                          case "end":
                            return _context25.stop();
                        }
                      }
                    }, _callee25);
                  }));

                  return function (_x39, _x40, _x41) {
                    return _ref24.apply(this, arguments);
                  };
                }());

              case 2:
              case "end":
                return _context26.stop();
            }
          }
        }, _callee26);
      }));

      return function (_x37, _x38) {
        return _ref23.apply(this, arguments);
      };
    }());
    (0, _defineProperty2["default"])(this, "event", /*#__PURE__*/function () {
      var _ref25 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee30(pin, callback) {
        var mode,
            _args30 = arguments;
        return _regenerator["default"].wrap(function _callee30$(_context30) {
          while (1) {
            switch (_context30.prev = _context30.next) {
              case 0:
                mode = _args30.length > 2 && _args30[2] !== undefined ? _args30[2] : index.GPIO_PULL_DOWN;
                return _context30.abrupt("return", new Promise( /*#__PURE__*/function () {
                  var _ref26 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee29(resolve, rejected) {
                    return _regenerator["default"].wrap(function _callee29$(_context29) {
                      while (1) {
                        switch (_context29.prev = _context29.next) {
                          case 0:
                            if (!(0, _detectRpi["default"])()) {
                              _context29.next = 11;
                              break;
                            }

                            console.log("Listening port ".concat(pin));
                            _context29.next = 4;
                            return (0, _child_process.execSync)("gpio -g mode ".concat(pin, " ").concat(_Options["default"].GPIO_DIR_IN));

                          case 4:
                            _context29.t0 = _this.config.engine;
                            _context29.next = _context29.t0 === _Options["default"].RASPBERRYPI_CORE_CLI ? 7 : 9;
                            break;

                          case 7:
                            setInterval( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee28() {
                              return _regenerator["default"].wrap(function _callee28$(_context28) {
                                while (1) {
                                  switch (_context28.prev = _context28.next) {
                                    case 0:
                                      _context28.next = 2;
                                      return (0, _child_process.execSync)("gpio -g wfi ".concat(pin, " ").concat(mode));

                                    case 2:
                                      _context28.next = 4;
                                      return (0, _child_process.exec)("gpio -g read ".concat(pin), /*#__PURE__*/function () {
                                        var _ref28 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee27(err, stdout, stderr) {
                                          var convertToInt;
                                          return _regenerator["default"].wrap(function _callee27$(_context27) {
                                            while (1) {
                                              switch (_context27.prev = _context27.next) {
                                                case 0:
                                                  convertToInt = Number(stdout.replace(/\r?\n|\r/g, ""));

                                                  if (!(convertToInt === 0)) {
                                                    _context27.next = 4;
                                                    break;
                                                  }

                                                  _context27.next = 4;
                                                  return callback();

                                                case 4:
                                                case "end":
                                                  return _context27.stop();
                                              }
                                            }
                                          }, _callee27);
                                        }));

                                        return function (_x46, _x47, _x48) {
                                          return _ref28.apply(this, arguments);
                                        };
                                      }());

                                    case 4:
                                    case "end":
                                      return _context28.stop();
                                  }
                                }
                              }, _callee28);
                            })), _this.config.interval);
                            return _context29.abrupt("break", 9);

                          case 9:
                            _context29.next = 12;
                            break;

                          case 11:
                            rejected({
                              status: false,
                              code: 500,
                              msg: "This Device Not Raspbbery Pi Device"
                            });

                          case 12:
                          case "end":
                            return _context29.stop();
                        }
                      }
                    }, _callee29);
                  }));

                  return function (_x44, _x45) {
                    return _ref26.apply(this, arguments);
                  };
                }()));

              case 2:
              case "end":
                return _context30.stop();
            }
          }
        }, _callee30);
      }));

      return function (_x42, _x43) {
        return _ref25.apply(this, arguments);
      };
    }());
    this.config = _lodash["default"].extend({
      enabled: true,
      engine: _Options["default"].RASPBERRYPI_CORE_CLI,
      setDefaultLower: false,
      interval: 200,
      direction: _Options["default"].GPIO_DIR_OUT
    }, config);
  }

  (0, _createClass2["default"])(index, null, [{
    key: "GPIO_DIR_OUT",
    get:
    /** The Declaration Of The Variable In The Class Data **/

    /** End The Declaration Of The Variable In The Class Data **/

    /** Static Variable For Settings **/
    function get() {
      return _Options["default"].GPIO_DIR_OUT;
    }
  }, {
    key: "GPIO_DIR_IN",
    get: function get() {
      return _Options["default"].GPIO_DIR_IN;
    }
  }, {
    key: "GPIO_EVENT_CHANGE",
    get: function get() {
      return _Options["default"].GPIO_EVENT_CHANGE;
    }
  }, {
    key: "GPIO_PULL_UP",
    get: function get() {
      return _Options["default"].GPIO_PULL_UP;
    }
  }, {
    key: "GPIO_PULL_DOWN",
    get: function get() {
      return _Options["default"].GPIO_PULL_DOWN;
    }
  }]);
  return index;
}();

var _default = index;
exports["default"] = _default;
//# sourceMappingURL=index.js.map