void initFan(bool init) { if (init) { exportGpio(true); sleep(1); setDirection(true); changeFanState(ENUM_FAN_STATUS_OFF); } else { changeFanState(ENUM_FAN_STATUS_OFF); exportGpio(false); } }
void attach(const char *pin) { this->pin = pin; exportGpio(pin); //muxPin(pin, 0x37); digitalMode(pin, OUTPUT); mode = OUTPUT; }
static int GPIO_init(GPIO *self, PyObject *args, PyObject *kwds) { int fd = -1; int gpio = -1; PyObject * direction = NULL; PyObject * trigger = NULL; PyObject * tmp = NULL; static char *kwlist[] = { "gpio", "direction", "trigger", NULL }; if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|OO:__init__", kwlist, &gpio, &direction, &trigger ) ) return -1; if (gpio < 0) return -1; self->gpio = gpio; GPIO_VALUE( gpio, self->v_path ); if ( ( fd = open( self->v_path, O_RDWR, 0 ) ) == -1 ) { // try to get gpio exported: if ( exportGpio( gpio ) == 0 ) { // check if export was (really) successful if ( ( fd = open( self->v_path, O_RDWR ) ) == -1) { // export failed PyErr_SetFromErrno( PyExc_IOError ); return -1; } } else { PyErr_SetString( PyExc_StandardError, "Export failed." ); return -1; } } GPIO_EDGE(gpio, self->e_path); GPIO_DIREC(gpio, self->d_path); self->fd_val = fd; if ( ( self->fd_dir = open( self->d_path, O_RDWR ) ) == -1 ) { return -1; } if ( ( self->fd_edge = open( self->e_path, O_RDWR ) ) == -1 ) { return -1; } if (direction) { setDirection( self, direction ); tmp = self->direction; Py_INCREF(direction); self->direction = direction; Py_XDECREF(tmp); } else { // no direction requested, use current Py_XDECREF(self->direction); self->direction = getDirection( self ); Py_INCREF(self->direction); } if (trigger) { setTrigger( self, trigger ); tmp = self->trigger; Py_INCREF(trigger); self->trigger = trigger; Py_XDECREF(tmp); } else { // no trigger requested, use current Py_XDECREF(self->trigger); self->trigger = getTrigger( self ); Py_INCREF(self->trigger); } return 0; }