Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
fwatch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
fwatch
Commits
0843c772
Commit
0843c772
authored
May 23, 2015
by
Federico Vaga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fwatch: update example application
Signed-off-by:
Federico Vaga
<
federico.vaga@gmail.com
>
parent
21f76bb7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
30 deletions
+57
-30
example_app.c
sw/freewatch/src/apps/example_app.c
+57
-30
No files found.
sw/freewatch/src/apps/example_app.c
View file @
0843c772
...
...
@@ -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
),
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment