I just reimplemented the whole GUI abstraction layer.
Before it was like this: You call guiInit(); which does continiously read out the touchpad coordinates. Then, when you call guiDrawButton(), a new thread is created which does read the variables provided by the GUI main thread. If these coordinates are inside the button's area, the variable you specified is set to 1, otherwise to 0.
The problem is that this does need a massive amount of memory and CPU resources. If you have 10 buttons, you have 11 threads, each with its own working area!
The current implemenetation works as following: You call guiInit(); once. As a parameter, you give it an update interval in milliseconds. Then, whenever you can guiDrawButton(), the button is inserted into a linked list. The GUI thread created when calling guiInit() does now walk through the linked list. It first checks if the button is set to active. If not, it ignores it and goes to the next linked list entry. Otherwise, it will look if the coordinates read out from the touchpad are inside the button area and does set the given variable to 1, otherwise to 0. Between taking the next list element, the thread sleeps for the amount of milliseconds you specified with the interval parameter from guiInit().
Here's the guiDrawButton Prototype:
Code: Select all
uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *active, uint8_t *state)
And here some simple usage example:
Code: Select all
uint8_t setActive, setState, clearActive, clearState;
setActive = active;
clearActive = active;
//setActive = inactive;
//clearActive = inactive;
guiInit(10);
guiDrawButton(10, 10, 60, 60, "Set", Black, Yellow, &setActive, &setState);
guiDrawButton(70, 10, 120, 60, "Clear", Black, Red, &clearActive, &clearState);
while (TRUE) {
if(setState)
palSetPad(GPIOD, GPIOD_LED3);
if(clearState)
palClearPad(GPIOD, GPIOD_LED3);
chThdSleepMilliseconds(200);
}
I am open for any ideas, improvements, critics or something else
~ Tectu