Event Based Programming (GUI) in C for Embedded System

I am running an event driven GUI on an embedded system. I just finished implementing the widget and touchscreen graphics.

My question is how to do this / tips for implementing this in C and embedded system.

This is how I thought 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 am assuming I have a touchscreen that will wake up my microcontroller controlled device with a hardware interrupt. Eventloop () is an infinite event loop that will process any events and then go to sleep until the next touch interrupt. The touchscreen interrupt service routine will receive the X and Y coordinates from the touchscreen and dispatch an event with the post_event () function. The event_handler () function, which is a function inside the eventloop () function, will receive events (if any) and call the handle_events () function. The handle_events () function checks if a button is pressed (for example) with the given event, X and Y coordinates, and returns a nonzero buttonID if the button is pressed. Then the next one is to loop through an array of buttons and check for an identical buttonID and call that button handler.

Does what I was trying to describe make sense in event-driven programming? Any thoughts are greatly appreciated (and please bear with me as I am new to this).

+3


source to share


1 answer


The answer will depend on which platform you are running on. The embedded RTOS for the Microchip controller will have one set of limitations, while the RTOS for the ARM solution will be completely different. You should clarify what kind of hardware, or at least the microcontroller for which you are designing.



0


source







All Articles