vsergeev / python-periphery

A pure Python 2/3 library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
MIT License
519 stars 139 forks source link

Do not write direction for SysfsGPIO if it is already set correctly #54

Closed fpracht closed 1 year ago

fpracht commented 2 years ago

I want to read the state of a GPIO pin which is already exported in sysfs. Because SysfsGPIO always writes the direction, the GPIO is reset and the value I want to read is gone.

The CdevGPIO implementation checks if the direction is already set correctly. The same should be done with the SysfsGPIO implementation.

vsergeev commented 1 year ago

I think this can be addressed by refactoring the export logic a little bit, and then only setting the direction if doesn't match the supplied initial direction.