PIGPIO user permission patch
This commit is contained in:
@@ -89,13 +89,25 @@ PIString PIGPIO::GPIOName(int gpio_num) {
|
|||||||
|
|
||||||
void PIGPIO::exportGPIO(int gpio_num) {
|
void PIGPIO::exportGPIO(int gpio_num) {
|
||||||
#ifdef GPIO_SYS_CLASS
|
#ifdef GPIO_SYS_CLASS
|
||||||
int fd = ::open(("/sys/class/gpio/" + GPIOName(gpio_num) + "/value").dataAscii(), O_RDONLY);
|
PIString valfile = "/sys/class/gpio/" + GPIOName(gpio_num) + "/value";
|
||||||
|
int fd = ::open(valfile.dataAscii(), O_RDONLY);
|
||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
::close(fd);
|
::close(fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
ret = system(PIString("echo " + PIString::fromNumber(gpio_num) + " >> /sys/class/gpio/export").dataAscii());
|
ret = system(PIString("echo " + PIString::fromNumber(gpio_num) + " >> /sys/class/gpio/export").dataAscii());
|
||||||
|
if (ret == 0) {
|
||||||
|
PITimeMeasurer tm;
|
||||||
|
while (tm.elapsed_s() < 1.) {
|
||||||
|
fd = ::open(valfile.dataAscii(), O_RDWR);
|
||||||
|
if (fd != -1) {
|
||||||
|
::close(fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
piMSleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user