Hello!
Has someone a better way to read the GPIO state in Java?
I read in a loop:
String pfad = "/sys/class/gpio/";
FileInputStream in = null;
while (true) {
int value = -1;
try {
for (PinOut p : pins) {
in = new FileInputStream(pfad + "gpio" + p.pinMap
+ "/value");
value = in.read() - 48;
System.out.println("Read " + p.description + ": " + value);
switch (value) {
case 0:
p.previousState = false;
break;
case 1:
p.previousState = true;
break;
}
if (p.previousState != p.state) {
p.state = p.previousState;
System.out.println(p.state);
}
in.close();
}
Thread.sleep(40);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
I read every 40ms all GPIOs from my PinList.
Well, it works, but maybe there is a better way?
I think to made an own thread for any GPIO IN and maybe it can block until
the value has changed?
Thanks!
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.