以下 shell 命令可以很好地切换 Leopardboard gpio 31:
echo 31 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio31/direction
echo 0 > /sys/class/gpio/gpio31/value
echo 1 > /sys/class/gpio/gpio31/value
echo 0 > /sys/class/gpio/gpio31/value
这用作以下代码的示例。知道为什么以下 .vala 代码不会切换 gpio 31 吗?
public void sync () {
int fd = -1;
fd = open("/sys/class/gpio/export", O_WRONLY);
if (fd < 0) {
GLib.stdout.printf("Error sync export\n");
return;
}
write(fd, "31", 3);
close(fd);
fd = open("/sys/class/gpio/gpio31/direction", O_WRONLY);
if (fd < 0) {
GLib.stdout.printf("Error sync direction\n");
return;
}
write(fd, "out", 4);
close(fd);
fd = open("/sys/class/gpio/gpio31/value", O_WRONLY);
if (fd < 0) {
GLib.stdout.printf("Error sync value\n");
return;
}
write(fd, "0", 2);
write(fd, "1", 2);
Thread.usleep (1000); /* 1ms */
write(fd, "0", 2);
close(fd);
}