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
9e16582c
Commit
9e16582c
authored
Aug 26, 2014
by
Projects
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apps: The clock is ticking!
parent
40d8fac0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
14 deletions
+40
-14
clock.c
sw/freertos/src/apps/clock.c
+40
-14
No files found.
sw/freertos/src/apps/clock.c
View file @
9e16582c
...
...
@@ -27,33 +27,46 @@
#include "clock.h"
#include "widgets/status_bar.h"
#include <drivers/rtc.h>
#include <stdio.h>
static
unsigned
int
hour
,
mins
,
secs
,
msecs
;
static
void
digital_watch_redraw
(
struct
ui_widget
*
w
)
{
int
h
,
m
,
c
;
// TODO sys_get_time(&h, &m, &c);
h
=
16
;
m
=
20
;
c
=
0
;
char
buf
[
20
];
sprintf
(
buf
,
"%02d:%02d"
,
h
,
m
);
sprintf
(
buf
,
"%02d:%02d"
,
h
our
,
mins
);
gfx_clear
(
&
w
->
dc
,
0
);
gfx_text
(
&
w
->
dc
,
&
font_helv38b
,
0
,
0
,
buf
,
1
);
sprintf
(
buf
,
"%02d.%01d"
,
c
*
12
/
10
,
(
c
*
12
)
%
1
0
);
sprintf
(
buf
,
"%02d.%01d"
,
secs
,
msecs
/
10
0
);
gfx_text
(
&
w
->
dc
,
&
font_helv22b
,
84
,
14
,
buf
,
1
);
}
static
void
digital_watch_event
(
struct
ui_widget
*
w
,
const
struct
event
*
evt
)
{
// TODO if hour has changed, mark widget as dirty
(
void
)(
w
);
(
void
)(
evt
);
// Hour has changed, it is time to redraw the clock
if
(
evt
->
type
==
RTC_TICK
)
{
msecs
+=
200
;
if
(
1000
==
msecs
)
{
++
secs
;
msecs
=
0
;
}
++
secs
;
if
(
60
==
secs
)
{
++
mins
;
secs
=
0
;
if
(
60
==
mins
)
{
++
hour
;
mins
=
0
;
if
(
24
==
hour
)
hour
=
0
;
// TODO 12/24 hour format
}
}
w
->
flags
|=
WF_DIRTY
;
}
}
struct
ui_widget
digital_watch
=
{
...
...
@@ -76,6 +89,16 @@ void clock_main(void* params) {
(
void
)(
params
);
// suppress unused parameter warning
struct
event
evt
;
// Restore clock
struct
rtc_time
time
=
rtc_get_time
();
msecs
=
time
.
msecs
;
secs
=
time
.
epoch
;
mins
=
secs
/
60
;
hour
=
mins
/
60
;
secs
%=
60
;
mins
%=
60
;
hour
%=
24
;
// Initialize user interface
ui_clear
();
...
...
@@ -99,12 +122,15 @@ void clock_main(void* params) {
case
BUTTON_PRESSED
:
if
(
evt
.
data
.
button
==
BUT_TR
)
return
;
// go back to the main menu
break
;
// no break; fall through
default:
case
RTC_TICK
:
// and BUTTON_PRESSED
ui_update
(
&
evt
);
// forward event to widgets
default:
// suppress warnings
break
;
}
}
}
}
...
...
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