Exemplo n.º 1
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
Exemplo n.º 2
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