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
Hide 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 @@
...
@@ -23,7 +23,7 @@
/**
/**
* Application template.
* Application template.
*/
*/
#include <libfwatch.h>
#include "application.h"
#include "application.h"
#include "widgets/status_bar.h"
#include "widgets/status_bar.h"
#include "drivers/backlight.h"
#include "drivers/backlight.h"
...
@@ -105,10 +105,13 @@ struct ui_widget example_screen = { // main screen, contains all widgets
...
@@ -105,10 +105,13 @@ struct ui_widget example_screen = { // main screen, contains all widgets
WF_ACTIVE
|
WF_VISIBLE
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
// this is a good place for hardware initialization
// (configure interrupts, backlight settings, etc.)
// (configure interrupts, backlight settings, etc.)
...
@@ -131,36 +134,60 @@ void example_main(void* params) {
...
@@ -131,36 +134,60 @@ void example_main(void* params) {
// draw the screen for the first time
// draw the screen for the first time
ui_update
(
NULL
);
ui_update
(
NULL
);
}
// event loop
/**
while
(
1
)
{
* It is the loop function that will be continously called until stopped
// "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
static
void
example_loop
(
struct
application
*
app
)
// for details, see below (else block)
{
if
(
xQueueReceive
(
appQueue
,
&
evt
,
portMAX_DELAY
))
{
struct
event
evt
;
switch
(
evt
.
type
)
{
int
ret
;
// decide which events are relevant and should be handled
// you may save some cycles if you list them here instead of
ret
=
xQueueReceive
(
appQueue
,
&
evt
,
portMAX_DELAY
);
// lazily handling all of them
if
(
ret
==
pdTRUE
)
{
case
BUTTON_PRESSED
:
// When there is a valid event, than process it
// current convention is to use the top left button to go back
fwatch_event_input_handler
(
app
,
&
evt
);
if
(
evt
.
data
.
button
==
BUT_TL
)
ui_update
(
&
evt
);
return
;
// go back to the main menu
}
else
{
// no break; fall through
// that part is executed if timeout occurs, so when there
// is not an event in the queue
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 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
=
{
application
example
=
{
.
name
=
"Example"
,
// this will be shown in menu
.
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