I am in the process of making an event driven GUI in an embedded system. I just finished implementing the widget graphics and touchscreen functionality.
My question is how to / tips on implementing this in C and on an embedded system.
This is how I was thinking in VERY general "pseudo" code:
mainloop()
{
<All initializations etc.>
eventloop();
}
eventloop()
{
eventhandler();
sleep_low_power_uc_mode();
}
touchscreen_interrupt_service_routine()
{
int * x, *y;
eventtype event = TOUCHSCREEN_CLICK;
get_XY_coordinate(x, y);
post_event(*x, *y, event);
}
eventhandler()
{
int * x, *y;
eventtype * event;
static int current_state;
get_event(x, y, event);
if(event != NO_EVENT)
{
handle_events(*x, *y, *event, current_state);
}
}
handle_events(int x, int y, eventtype event, int * current_state)
{
int buttonID, i=0;
buttonID = check_if_button_pressed(x, y, current_state);
while(buttons[i].enabled != FALSE)
{
if(buttonID == buttons[i].ID)
{
call_buttons_respective_handler();
}
}
}
Here I assume that I have a touchscreen which will wake up my micro controller controlled device with a hardware interrupt. The eventloop() is a never ending event loop that will handle any events then go to sleep until next touchscreen interrupt. The touchscreen interrupt service routine will get the X and Y coordinate from the touchscreen and post an event with the post_event() function. The event_handler() function, which is a function within the eventloop() function, will get events (if any) and call the handle_events() function. The handle_events() function check if a button (for example) has been pressed with the given event, X and Y coordinates and return a non-zero buttonID if a button has been pressed. Then the next is to loop through the array of buttons and check of a identical buttonID and call that buttons handler.
Does what I have tried to describe make any sense in a event driven programming manner? Any thoughts are very welcome (and please bear with me as I am new to this).