I decided to make this program public especially to help those who use the Arduino IDE and the SquarelineStudio program.
The final generated file has been tested with Arduino IDE 2.3.2, TFT_eSPI 2.5.43 and LVGL 9.1 (with 9.2 there are problems for now, so use 9.1) with ESP32-2432S028 ILI9341 screen 16 bit color touchscreen Chip is ESP32-D0WD-V3 (revision v3.1) also known as YELLOW, but it can also be used on other Arduino/ESP32 with touch connected by looking at both the pin configuration in the variable declaration, and in the User_Setup.h file contained in the main directory of the TFT_eSPI libraries and that I include in this compressed file (and you have to replace them with the original ones, perhaps renaming the old ones to not lose them)
Premise:
I don’t like object-oriented programming because I consider it too dispersive (even in other .Net projects that ask me), so I try to include everything in a single file and have everything under control.
Unfortunately, the projects generated by SquarelineStudio follow the object-oriented philosophy, and if I take the .ino file generated by SquarelineStudio it generates several errors during compilation with Arduino IDE (even if I follow the instructions and set the preferences file).
So I made this program that generates a single final .ino file both using the objects generated by SquarelineStudio and without.
The program displays 4 text windows where you can do a Copy/Paste with the classic CTRL+c and CTRL+v:
1 Include() where the references to the objects and variables are declared
2 Basic Handler() I only put the one related to the Touchscreen (then I open a clarification on those that can be included by importing them from the SquareLine project later)
3 Setup() which in Basic mode sets the rotation of the screen, the touch and the brightness of the screen
4 Loop() where you can insert for example a timer management and, at the end of the loop, all the settings of the various widgets imported from Squareline are inserted, including Screen1 (which you must keep with this name when you make the project in Squareline if you do not want to correct all the references to the screen)
The generated .ino file will follow this sequence of the 4 windows.
Using the program:
By default, once you have unzipped the entire archive where you prefer, the 4 windows start with a basic configuration where a screen1 with 2 color tones is generated and in the serial monitor you can check if the touchscreen coordinates correspond to where you press with the pen.
Therefore, to test if the basic routine works on your ESP32 Yellow and the coordinates on the screen correspond, just save the program in a directory of your choice using the ‘SAVE .INO FILE’ button (both the directory and the .ino file will be generated inside it).
The CHECK/UNCHECK button allows us to change the working mode between the 4 Basic windows or in other 4 windows in this way:
first click on CHECK/UNCHECK and the button that allows you to read the other 4 files will be enabled (contained in the program directory for example with the name Include.txt instead of BasicInclude.txt).
At this point press the corresponding button (‘Load Basic 4 Win’ or ‘Load Modified 4 Win’ to load the 4 windows)
The button to the right of them is used to save the 4 windows if you have made any changes (depending on what you selected before with CHECK/UNCHECK)
The 3 INCLUDE CHECK/UNCHECK only concern what we want to import from the Squareline project and do NOT concern the final .ino file which will however be composed by joining the 4 windows currently displayed.
When the program exits, the settings of the directories you have used, as well as the CHECK/UNCHECK, the INCLUDE and the REPLACE that we will talk about later and which concerns the Handlers are saved, so when the program is restarted you will find the same environment you left.
The archive also includes and zips these 8 default windows in 2 archives (Backup Basic 4 windows.zip for the Basic ones and Backup 4 window Squareline.zip for the other 4) in case you made mistakes in saving the windows and would like to return to the initial setting.
EVENTS
And finally let’s talk about the Handlers generated by Squareline:
By default, when you associate an EVENT to an object, Squareline generates an event of this type:
lv_obj_add_event_cb(ui_LuceOff, ui_event_LuceOff, LV_EVENT_ALL, NULL);
at the end of the object definition.
and it will generate an event of this type in the Ui.c file in FUNCTIONS:
void ui_event_LuceOff(lv_event_t * e){
lv_event_code_t event_code = lv_event_get_code(e);
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_CLICKED) {
_ui_basic_set_property(ui_LuceOff, _UI_BASIC_PROPERTY_POSITION_X, 0);
}
}
First of all, the line lv_event_code_t event_code = lv_event_get_code(e); generates an error at compile time
Then, in my opinion, it is not an optimized event management, because the definition
lv_obj_add_event_cb(ui_LuceOff, ui_event_LuceOff, LV_EVENT_ALL, NULL);
forces the program to examine all the possibilities that exist on an event (and there are many between clicks, gestures and various)
and then, inside the event you still find the condition if(event_code == LV_EVENT_CLICKED) { so it wastes further time
For this reason I put the CHECK/UNCHECK whether to include it or not in the Handlers and the possibility of replacing LV_EVENT_ALL with a single event of our choice between:
LV_EVENT_CLICKED
LV_EVENT_SHORT_CLICKED
LV_EVENT_PRESSED
LV_EVENT_LONG_PRESSED
LV_EVENT_LONG_PRESSED_REPEAT
LV_EVENT_GESTURE
So in my final code for a clock for the car based on GPS signals it is like this:
lv_obj_add_event_cb(ui_LuceOff, ui_event_LuceOff, LV_EVENT_CLICKED, NULL);
and in the events (FUNCTIONS) it is like this:
void ui_event_LuceOff(lv_event_t* e) {
SchermoOnOff -= IncrSchermo;
IncrSchermo++;
if (SchermoOnOff < 0) {
SchermoOnOff = 1;
IncrSchermo = 1;
}
ledcWrite(21, SchermoOnOff); // PWM 0-255
}
This is the handler for a button that is used to decrease the brightness of the screen.
Furthermore, in Squareline there is no possibility of inserting a custom routine like the one I put above (but I understand this because otherwise when you give RUN to the project in Squareline it would collide with these custom variables, even if the RUN could avoid taking these custom variables into consideration if put in a special container), and it could leave them in the final file of the project, so we already find them in place.
And below I attach the zipped file … and I hope it will be helpful to those who are approaching these libraries
And do not forget to replace the User_Setup.h file contained in the main directory of the TFT_eSPI libraries with the file I attached in the archive.
Bye
Squareline to ino.zip (65.6 KB)