is there a way to return a boolean from fast-gpio read?
-
I'm trying to get a usable output (boolean) from "fast-gpio read", but it only gives output of the form > Read GPIOxx: 1. is there an easy way to get a boolean from this?
-
@tacowilson43 Well, you could e.g. use something along the lines of
fast-gpio-read 1|sed 's/1/True/;s/0/False/'
orfast-gpio-read 1|sed 's/^[^01]*//;/1/True/;s/0/False/'
Or you could modify the sources for fast-gpio and make it spit out whatever you like.
-
Thanks I appreciate the help, this is my first experience with linux, could you explain the code you posted? I have Java and python experience, I see that you are piping the output of fast-gpio to sed, but idk what sed or the funtion after is
-
@tacowilson43 sed is a command that modifies any text that is piped to it, or it can read the text to be modified from a file. How it actually modifies the text is defined by the odd-looking string I'm supplying to it, or, again, this string can be supplied from a file instead.
-
Thanks, sorry to be a pain but can you explain the string as well?
-
@tacowilson43 A sed-command s is a command for replacing text with something else and the forward slash is a separator between the arguments to it and semicolon is a separator between commands, so it basically reads replace "1" with "True", followed by another command, replace "0" with "False". If you want to know more, you should google a sed-tutorial. They can explain this stuff much better than I can, and going through all the different things you can do with sed could fill a whole book, so this forum isn't probably the best place for that.
-
That's great thanks a lot
-
@tacowilson43 said in is there a way to return a boolean from fast-gpio read?:
I have Java and python experience
As a programmer of such languages, you surely must be familiar with the logistics to call C Language functions and use libraries. Check this library from Kit Bishop:
https://github.com/KitBishop/Omega-GPIO-I2C-Arduino/blob/master/libnewgpio/src/GPIOAccess.cppOnce you've get the thing working, let us know how you use the library from your favorite programming language. This is just out of curiosity for me, but I'm sure it will help many others.
-
@fossette Further to this, if it is of any interest to people, I will soon be publishing Java wrapper code to enable the C++ code in all parts of https://github.com/KitBishop/Omega-GPIO-I2C-Arduino to be called from Java code.
The source code can be built into a .jar file that can then be executed on the Omega using the Jamvm Java Virtual Machine