in status_led_pkg/status_led_pkg/gpio_module.py [0:0]
def enable(self):
"""Enable the GPIO port by exporting the control of a GPIO to userspace and
set the direction attribute.
Returns:
bool: True if successful else False.
"""
try:
if(not os.path.isdir(self.root_path)):
with open(f"{self.base_path}/export", "w") as export:
export.write(str(self.gpio))
except Exception as ex:
self.logger.error(f"Error while writing to export for the GPIO port {self.gpio}: {ex}")
return False
try:
with open(f"{self.root_path}/direction", "w") as direction:
direction.write(self.direction)
except Exception as ex:
self.logger.error(f"Error while writing direction for the GPIO port {self.gpio}: {ex}")
return False
try:
os.chmod(self.value_path, 766)
except Exception as ex:
self.logger.error("Error while changing access permissions of value file for the GPIO port"
f"{self.gpio}: {ex}")
return False
return True