Ejemplo n.º 1
0
 def cb_validate_init_parameters(self, pin_id, direction_mode, blocking_mode):
     '''
         Check parameters are valid. Raise exception if they are not.
         Base implementation checks pin_id is not already exported.
         Sub-classes should override, add additional checks and call
         this super class implementation. Note that basic parameter
         checks are performed before _validate_init_parameters is called
         by converting parameters to instances of their specific,
         validated, handling types: PinId, DirectionMode and BlockMode.
     '''
     # Raise a PinInUseError if pin is currently exported
     if os.path.exists(sysfs_pin_path(pin_id)):
         raise PinInUseError
Ejemplo n.º 2
0
 def close(self):
     '''
         Closes the pin. Can be called repeatedly safely on the same
         object. Closes pin's sys filesystem value file and unexports
         the pin from the sys filesystem.
     '''
     if ( not self.closed() ):
         self.__value_file.close()
         self.__value_file = None
         # Unexport if exported (should be unless somone sneaking around
         # behind our backs!)
         if os.path.exists(sysfs_pin_path( self.__pin_id )):
             with open(sysfs_unexport_path(), 'w') as unexport_file:
                 unexport_file.write( str(self.__pin_id) )
         self.__pin_id = None
Ejemplo n.º 3
0
def force_free_pin( pin_id ):
    '''
        Will 'free' a pin by unexporting it from the sys filesystem if it
        is exported. Intended to be used in cases where some failure has
        left pins exported which should not have been. It is considered
        preferable to have GPIO pin IO classes back off if a pin they are
        asked to use is already exported so as not to trample on other
        users' toes as it were. However this leaves the possibility that
        pins are accidentally left exported due to bad process termination.

        pin_id is the raw GPIO pin id to free.

        Returns None if the pin was not exported or the pin_id value if it
        was and had to be unexported.
        
        Throws a pin.PinIdInvalidError if the pin_id is invalid
    '''
    unexported = None
    if os.path.exists(sysfs_pin_path( pin_id )):
        unexported = pin_id
        with open(sysfs_unexport_path(), 'w') as unexport_file:
            unexport_file.write( str(pin_id) )
    return unexported