mistake from my side:
i dont need the makefile. I can compile the shown adc program in terminal with: gcc testADC.c -o testADC -lwiringPi
i compile the fltk App with: fltk-config --compile app.cxx
the problem is that i cant put the needed -lwiringPi in the compile line from the fltk
It probably is easier to do this with a Makefile - you will need to create one tailored to your project.
There are some notes you can follow:
Might be good places to start.
is it possible to put the ADC code from above in my fltk App code, and it should some how know the reference, so that it dousnt throw: undefined reference to wiringPiSetup ?
Yes, but it will need to be done via callbacks and so forth. GUI programming is event driven, in general, so the simple linear progression of the sample code you show will not work.
Take a look at the fltk test samples, see how their code works.
In my original reply, I thought you were trying to build an oscilloscope, but if you simply want to display values from the ADC in “real time” then a simpler timer based approach will probably work.
Build a simple fltk app that updates it’s display in response to a timer (see Fl::add_timeout) and in the timer callback call the ADC API there to read the latest value and then display that on your display widget.
Set the timer to repeat at every 0.1 seconds and that will work fine.
I’m not sure about the ADC that you are using but I’d assume you can probably poll it at 1kHz or so over the i2c bus. You can’t possibly display that many values though (your monitor will only be running at 60Hz, typically) and anyway humans can only parse values at about 10Hz, so refreshing the display any faster than that is just wasting pixels...
There are samples in the test and examples folder that demonstrate how to use the timers and how to make the callbacks, so you can easily start from there.
or do i have to start the ADC programm from my App with treads as you say before? If so, how i make my App knowing the ADC program to start it?
No, you can call the ADC API from your fltk program, in the timer callback if the update rate is low enough.
If you want to capture “all” the samples, you probably do need a separate thread to do that so that the ADC poll is independent of, and does not block, the GUI thread.
But do the timer approach first and once you understand how that works, head on to more challenging techniques!