flexGUI and BME680
Rsadeika
Posts: 3,837
I am going to use the flexBASIC part of flexGUI, and I am considering trying to get the BME680 C code to work with, that is available form SimpleIDE.
Now the part that is a little confusing is how do I get the code that is in BME680.h to work with flexBASIC.
The BME680.h file has some 'typedef struct' that contain things like 'i2c *i2c_ptr', and spi. Now I am not sure how or where the i2c comes from or does flexBASIC have is own version of i2c/spi. I guess I need some guidance as to what the best approach for doin this, would be.
I will try to get this thing to run on the P1, and than hopefully transfer the code to the P2, to see hoe the P2 handles it.
Ray
Now the part that is a little confusing is how do I get the code that is in BME680.h to work with flexBASIC.
The BME680.h file has some 'typedef struct' that contain things like 'i2c *i2c_ptr', and spi. Now I am not sure how or where the i2c comes from or does flexBASIC have is own version of i2c/spi. I guess I need some guidance as to what the best approach for doin this, would be.
I will try to get this thing to run on the P1, and than hopefully transfer the code to the P2, to see hoe the P2 handles it.
Ray
Comments
Is there Spin code for driving the BME680? That would be the easiest to get working, I think, since fastspin's Spin support is pretty mature at this point. Also, both Spin and BASIC are case insensitive, which avoids some interoperability problems (it's very hard to call C functions with uppercase letters in them from BASIC).
Using Spin or C code from BASIC is generally pretty easy. The pseudo-code would look like:
I guess that leaves open either going with flexBASIC or flexC. If I am not mistaken, I think I read that flexC is not "fully" developed, not sure what the limitations are. I would hate to start in with flexC and find out that there are some important parts missing.
Ray
Simple little program: I get: error: syntax error, unexpected constant, for the 'usleep(200);'. Not sure what else is necessary for this to work.
Ray
That's not a legal C program. "usleep(200);" is a function call, which needs to be inside a function declaration. I'm guessing you wanted to put it inside of main().
I'm not sure why you said this is like learning to program in C again. PropGCC would have produced an error for the above program as well.
As for the learning C again, yes, I got used to cut and paste, plus having 'simpletools.h' that, I guess contains everything you need to use. I forgot that in order to use printf() you need to '#include <stdio.h>', that kind of stuff. You also presented waitcnt(), you think I remember how to use that. LOL
Ray
It really needs linking support in order to not be a giant pain in the &*#$^. I kind of gave up on it, waiting for a later time when more stuff was done. I also kind of stopped having free time as much.
Is the 'time' folder a library, just like 'stdio', if not, how do you make a library for use with flexC.
Ray
Header files like <time.h> and <stdio.h> are not libraries in traditional C. They just contain function declarations, the actual functions go elsewhere. That is, saying: Is exactly the same as just copying and pasting the contents of stdio.h at that point in the file. You'll notice that stdio.h doesn't actually have any function implementations in it.
In most C compilers the actual compiled functions are stored in a library called libc.a, but the math functions are in libm.a (and the in SimpleIDE the simple libraries are in other library files).
FlexC is a little different. You can link libc.a by putting it on the command line, but FlexC also has an extension which allows it to automatically link in the appropriate code for a header file. You do this by writing __fromfile("path/to/file.c") after the function declaration, e.g. you could write: The header file <compiler.h> has a macro _IMPL(x) which expands to __fromfile(x) in FlexC and an empty string in other compilers (like Catalina or PropGCC). So a slightly better way to do this is:
To recap:
(1) The .h file contains declarations, not code; things like #define, structure typedefs, and function prototypes.
(2) The .c file contains the implementation. Traditionally this gets compiled to an object file, .o and then placed into a library file (.a).
(3) In FlexC you can extend the function prototypes with a FlexC specific __fromfile() attribute which automatically will locate the code for the C function, without needing a .a file.