Commit 0843c772 authored by Federico Vaga's avatar Federico Vaga

fwatch: update example application

Signed-off-by: 's avatarFederico Vaga <federico.vaga@gmail.com>
parent 21f76bb7
......@@ -23,7 +23,7 @@
/**
* Application template.
*/
#include <libfwatch.h>
#include "application.h"
#include "widgets/status_bar.h"
#include "drivers/backlight.h"
......@@ -105,10 +105,13 @@ struct ui_widget example_screen = { // main screen, contains all widgets
WF_ACTIVE | WF_VISIBLE
};
void example_main(void* params) {
(void)(params); // suppress unused parameter warning
struct event evt;
/**
* It is the setup function that will be called only one time when
* you lanch the application
*/
static int example_setup(struct application *app)
{
// this is a good place for hardware initialization
// (configure interrupts, backlight settings, etc.)
......@@ -131,36 +134,60 @@ void example_main(void* params) {
// draw the screen for the first time
ui_update(NULL);
}
// event loop
while(1) {
// "0" in the line below, if you set it to a positive value then
// you may have a block of code that is executed when no event arrives
// for details, see below (else block)
if(xQueueReceive(appQueue, &evt, portMAX_DELAY)) {
switch(evt.type) {
// decide which events are relevant and should be handled
// you may save some cycles if you list them here instead of
// lazily handling all of them
case BUTTON_PRESSED:
// current convention is to use the top left button to go back
if(evt.data.button == BUT_TL)
return; // go back to the main menu
// no break; fall through
default: // suppress warnings
// ignore events that were not mentioned above
ui_update(&evt); // forward event to widgets
break;
}
}
else {
// that part is executed if timeout occurs
}
/**
* It is the loop function that will be continously called until stopped
*/
static void example_loop(struct application *app)
{
struct event evt;
int ret;
ret = xQueueReceive(appQueue, &evt, portMAX_DELAY);
if(ret == pdTRUE) {
// When there is a valid event, than process it
fwatch_event_input_handler(app, &evt);
ui_update(&evt);
} else {
// that part is executed if timeout occurs, so when there
// is not an event in the queue
}
}
/**
* It is the end of the application. Here you can do whatever it needs to
* properly close the application.
*/
static void example_quit(struct application *app)
{
// DO something
}
static int example_event_button(struct application *app, struct event *evt)
{
if (evt->data.button == BUT_TL)
fwatch_application_stop(app);
return 0;
}
/*
* decide which events are relevant and should be handled
* you may save some cycles if you list them here instead of
* lazily handling all of them
*/
static struct app_evt_callback evt_call[] = {
{
.type = BUTTON_PRESSED,
.callback = example_event_button,
},
};
application example = {
.name = "Example", // this will be shown in menu
.main = example_main
.setup = example_setup,
.loop = example_loop,
.quit = example_quit,
.event_handlers = evt_call,
.event_handlers_n = ARRAY_SIZE(evt_call),
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment