Esempio n. 1
0
    def __init__(self):
        """Create library and ffi interfaces.
        """
        self.gpiod = libgpiod.libgpiod()
        self.lib = self.gpiod.lib
        self.ffi = self.gpiod.ffi

        # Inner Callback function
        @self.ffi.callback(
            "int (int evtype, unsigned int offset, const struct timespec *ts, void *data)"
        )
        def buttonCallback(evtype, offset, ts, data):
            # Use a try/except or an exception will cause an endless loop
            try:
                if evtype == self.lib.GPIOD_CTXLESS_EVENT_CB_TIMEOUT:
                    rc = self.lib.GPIOD_CTXLESS_EVENT_CB_RET_STOP
                    print("Timeout")
                else:
                    rc = self.lib.GPIOD_CTXLESS_EVENT_CB_RET_OK
                    if evtype == self.lib.GPIOD_CTXLESS_EVENT_CB_RISING_EDGE:
                        print("Rising  edge timestamp %s" % time.strftime(
                            '%m/%d/%Y %H:%M:%S', time.localtime(ts.tv_sec)))
                    else:
                        print("Falling edge timestamp %s" % time.strftime(
                            '%m/%d/%Y %H:%M:%S', time.localtime(ts.tv_sec)))
            except:
                rc = self.lib.GPIOD_CTXLESS_EVENT_CB_RET_ERR
                print("Unexpected error:", sys.exc_info()[0])
            return rc

        # Expose callback to object instance
        self.buttonCallback = buttonCallback
Esempio n. 2
0
 def __init__(self):
     """Create library interface.
     """    
     self.i2c = libperipheryi2c.libperipheryi2c()
     self.gpiod = libgpiod.libgpiod()
     self.lib = self.gpiod.lib
     self.ffi = self.gpiod.ffi        
Esempio n. 3
0
 def __init__(self):
     """Create library and ffi interfaces.
     """         
     self.gpiod = libgpiod.libgpiod()
     self.lib = self.gpiod.lib
     self.ffi = self.gpiod.ffi