Page 1 of 1

Developing with C++ in Eclipse

Posted: Mon Mar 19, 2018 11:58 pm
by javaben
I'm new to Eclipse/ESP32, but not new to programming, although not too deep on C++; mostly C, and Java.

I decided a project I'm building would work better for me, from a design perspective, if I were to develop it in C++ instead of the Arduino IDE, so I downloaded, installed, and configured the Eclipse IDE, thanks to Kolban and pcbreflus' youtube videos. I've been able to compile and download some of the examples from those two gentlemen onto my ESP32, as well as Kolban's book.

So now I'm ready to turn my attention back to my project...

However, I'm still stuck, and as much research as I've been doing, I can't seem to understand what's going on if I want to code in C++.

For instance, I'm totally lost on the reason for, and use of, "app_main". It seems almost as though it is just thrown in there.

Any insight on actually using C++ for ESP32 on Eclipse IDE would be appreciated. I can find a ton of stuff on setup, and some example programs, but nothing that's actually showing me what's going on, and why.

Thanks,

JavaBen

Re: Developing with C++ in Eclipse

Posted: Tue Mar 20, 2018 4:49 am
by kolban
Howdy my friend,
The community will try and assist as best we can. However it is going to be best if we try and narrow our questions as best as possible. Lets take the app_main() story as a starting place.

When you write your application, you will need an entry point into your code. In a C/C++ application, this is usually a function called "main()". The designers of the ESP-IDF, decided that the entry point would be called "app_main()". In a C program, you may code:

Code: Select all

void app_main() {
   // do something
}
In a C++ program, it might be tempting to code the identical to the above. However, the ESP-IDF is written (primarily in C) and your user code is in C++. For the most part, this is transparent ... with one big exception ... C++ functions are "decorated" to include their signature. So coding "void app_main()" doesn't expose a function call "app_main", it exposes a function called app_main with no parameters and that returns void.

You can request in C++ that an application expose a function using simpler C constructs ... for example:

Code: Select all

extern "C" {
   void app_main();
}

void app_main() {
   // do something
}
should work.

Re: Developing with C++ in Eclipse

Posted: Tue Mar 20, 2018 8:21 pm
by javaben
"Howdy" - Kolban, are you going Big Texan on us? If so, then Howdy Tex!

Thanks for your insight. Doing a little bit of digging to understand.

Will be back soon, I expect!

The main thing is to keep the main thing the main thing, and the main thing is BBQ!

Re: Developing with C++ in Eclipse

Posted: Wed Mar 21, 2018 4:36 pm
by javaben
Digging in a little deeper meant a re-introduction to C++; the last time I had used it heavily was 1997! Searching google found a lot of hits, but they weren't really what I was looking for. Amazon seemed to have a lot of old books, many prior to C11 and that wasn't what I was looking for either.

Finally, I found this online book (doesn't appear to be a pirated copy), which is dated Feb 2018. I'm halfway through, and can say it is meeting my needs, so I'm recommending it to anyone that wants to get into C++: http://python.cs.southern.edu/cppbook/progcpp.pdf

Thanks,

JavaBen

Re: Developing with C++ in Eclipse

Posted: Thu Mar 22, 2018 2:33 pm
by javaben
Continuing with my efforts to utilize Eclipse for development; I've decided to document my "journey" in case it might help someone else.

My background: Extensive programming experience in Object Oriented design and programming (mostly Java; software architect for Verizon Wireless - retired), extensive C development, but very limited in C++. Extensive development of Arduino projects using Arduino IDE. Extensive electronic and process control background, analog and digital, at nuclear power plants.

My goal:
- Implement an Object Oriented design of a project in C++, using Eclipse for the development platform and the ESP32 for the target deployment uCU.
- Some things I intend to include: Integrated unit testing; MQTT; BLE

Some Resources:
- books, articles, youtube, comments from Kolban.
- articles, youtube, comments from 'pcbreflux'
- ESP32
- esp32.com
- http://esp-idf.readthedocs.io/en/latest/
- github.com (for coding examples)
- Eclipse (hope to grow this list):
-https://www.ibm.com/developerworks/libr ... se-stlcdt/
- C++
- a really good, free ebook posted online by the author (check out his other excellent free book on Python too!)
- http://python.cs.southern.edu/cppbook/progcpp.pdf

===
Progress
- Intensive studying of C++ using the book (link above) of progcpp.pdf
- Installed esp-idf and setup environment on Ubuntu 17.10.
- Developed some applications for ESP32 using Arduino IDE and deployed.
- Applications using MQTT, SMTP and Web Server.
- Installed Eclipse on Ubuntu 17.10. Did github.co clones of some example code; built and ran as test of environment.

Currently Concentrating on preparation activities:
- C++
- Eclipse for Object Oriented ESP32 programming

Future:
- Design of my ESP32 application using OO Design.
- Adding graphical interface for display of real-time data.

Re: Developing with C++ in Eclipse

Posted: Mon Mar 26, 2018 9:07 pm
by javaben
I've made a little bit of progress in my understanding.

- Using Kolban's video on youtube (referenced above), I built my Eclipse environment similar to the one specified in the video.

- Running Kolban's example (main_helloworld.cpp) created in the above video, I ran into problems, and finally had to post here for help. Kolban provided the insight needed. The issue was, I was taking literally the video regarding personal preferences regarding the setting of the log level. I didn't recognize the code was utilizing a logging feature call, ESP_LOGD(). Since I had selected a logging value above the Debug value, I wasn't seeing any output at all so I thought my environment was still bad. Going back through "make menuconfig" and setting to "verbose" cleared up this problem. I also added some <iostream> and "sdk::cout" commands to see how they would differ. This is a good feature (the ESP_LOGx()) to have built into the application.

- In other programs, I had seen some reference in selecting values, such as a GPIO pin during "make menuconfig", but I never saw this option available, until I notice Kconfig.projbuild in ~/esp/esp-idf/examples/get-started/blink/main/Kconfig.projbuild. Never having any need to build a kernel before, I was not familiar with this concept. In going through the .../get-started/blink program, and running "make menuconfig", I finally made the association between the code's #define BLINK_GPIO CONFIG_BLINK_GPIO and where it was originating in the Kconfig.projbuild. So I added one to a simple program I'm coding up called myBlink.

- So now I'm concentrating on how to write to a GPIO pin that has an LED attached, but from the direct use of the ESPRIFF API....and just getting started.

Thanks everyone, and especially Kolban, for the help so far in getting me going.