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
498ed818
Commit
498ed818
authored
Sep 17, 2014
by
=
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ui: Added 'set time' application.
parent
d3aacf9e
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
280 additions
and
30 deletions
+280
-30
ui.h
sw/common/gfx/ui.h
+2
-1
Makefile
sw/freertos/Makefile
+3
-0
app_list.h
sw/freertos/src/apps/app_list.h
+1
-0
clock.c
sw/freertos/src/apps/clock.c
+22
-6
clock.h
sw/freertos/src/apps/clock.h
+42
-0
menu_struct.c
sw/freertos/src/apps/menu_struct.c
+5
-23
set_time.c
sw/freertos/src/apps/settings/set_time.c
+169
-0
settings.h
sw/freertos/src/apps/settings/settings.h
+36
-0
No files found.
sw/common/gfx/ui.h
View file @
498ed818
/*
* Copyright (C) 2014 Julian Lewis
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
...
...
@@ -40,6 +40,7 @@ struct ui_widget {
struct
rect
pos
;
uint8_t
order
;
int
flags
;
void
*
data
;
struct
surface
dc
;
struct
ui_widget
*
next
;
...
...
sw/freertos/Makefile
View file @
498ed818
...
...
@@ -111,6 +111,7 @@ LIBS = -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group
INCLUDEPATHS
+=
\
-Isrc
\
-Isrc/apps
\
-IFreeRTOS/Source/include
\
-I../bitmaps
\
-I../common/CMSIS/Include
\
...
...
@@ -171,6 +172,8 @@ FreeRTOS/Source/list.c \
FreeRTOS/Source/croutine.c
\
FreeRTOS/Source/portable/MemMang/heap_1.c
\
FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
\
src/apps/settings/set_time.c
\
src/apps/widgets/spinbox.c
\
src/apps/widgets/status_bar.c
\
src/apps/application.c
\
src/apps/clock.c
\
...
...
sw/freertos/src/apps/app_list.h
View file @
498ed818
...
...
@@ -28,6 +28,7 @@
#define APP_LIST_H
#include "application.h"
#include "settings/settings.h"
extern
application
menu
;
extern
application
clock_app
;
...
...
sw/freertos/src/apps/clock.c
View file @
498ed818
...
...
@@ -25,6 +25,8 @@
* Clock application.
*/
#include "clock.h"
#include "application.h"
#include "widgets/status_bar.h"
#include <drivers/rtc.h>
...
...
@@ -35,13 +37,12 @@
static
struct
rtc_time
rtc
;
static
struct
tm
cur_time
;
static
void
digital_watch_redraw
(
struct
ui_widget
*
w
)
{
static
void
digital_watch_redraw
(
struct
ui_widget
*
w
)
{
char
buf
[
32
];
strftime
(
buf
,
sizeof
(
buf
),
"%H:%M"
,
&
cur_time
);
/*sprintf(buf,"%02d:%02d", cur_time.tm_hour, cur_time.tm_min);*/
gfx_clear
(
&
w
->
dc
,
0
);
strftime
(
buf
,
sizeof
(
buf
),
"%H:%M"
,
&
cur_time
);
gfx_text
(
&
w
->
dc
,
&
font_helv38b
,
4
,
0
,
buf
,
1
);
// sprintf must be used, so we can display msecs too
...
...
@@ -52,8 +53,7 @@ static void digital_watch_redraw(struct ui_widget *w)
gfx_centered_text
(
&
w
->
dc
,
&
font_helv17
,
40
,
buf
,
1
);
}
static
void
digital_watch_event
(
struct
ui_widget
*
w
,
const
struct
event
*
evt
)
{
static
void
digital_watch_event
(
struct
ui_widget
*
w
,
const
struct
event
*
evt
)
{
// Hour has changed, it is time to redraw the clock
if
(
evt
->
type
==
RTC_TICK
)
{
rtc
=
rtc_get_time
();
...
...
@@ -128,3 +128,19 @@ application clock_app = {
.
main
=
clock_main
};
// Settings
struct
tm
clock_get_time
(
void
)
{
rtc
=
rtc_get_time
();
localtime_r
((
time_t
*
)
&
rtc
.
epoch
,
&
cur_time
);
return
cur_time
;
}
void
clock_set_time
(
struct
tm
*
time
)
{
struct
rtc_time
r
;
r
.
msecs
=
0
;
r
.
epoch
=
mktime
(
time
);
rtc_set_time
(
r
);
}
sw/freertos/src/apps/clock.h
0 → 100644
View file @
498ed818
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* Clock application settings.
*/
#ifndef CLOCK_H
#define CLOCK_H
#include <stdbool.h>
/**
* TODO
*/
struct
tm
clock_get_time
(
void
);
/**
* TODO
*/
void
clock_set_time
(
struct
tm
*
time
);
#endif
/* CLOCK_H */
sw/freertos/src/apps/menu_struct.c
View file @
498ed818
...
...
@@ -37,13 +37,11 @@ int get_menu_size(const menu_list *menu) {
return
len
;
}
menu_list
s
ub
_menu
=
{
"S
ubmenu
"
,
menu_list
s
ettings
_menu
=
{
"S
ettings
"
,
{
{
APP
,
&
gps_receiving
,
{
.
app
=
&
clock_app
}
},
{
APP
,
&
battery
,
{
.
app
=
&
clock_app
}
},
{
APP
,
&
gps_disconnected
,
{
.
app
=
&
clock_app
}
},
{
END
,
&
gps_searching
,
{
NULL
}
}
{
APP
,
&
clock_icon
,
{
.
app
=
&
set_time
}
},
{
END
,
NULL
,
{
NULL
}
}
}
};
...
...
@@ -51,23 +49,7 @@ menu_list main_menu = {
"Main menu"
,
{
{
APP
,
&
example_icon
,
{
.
app
=
&
example
}
},
{
APP
,
&
gps_receiving
,
{
.
app
=
&
clock_app
}
},
{
APP
,
&
battery_charging
,
{
.
app
=
&
clock_app
}
},
{
SUBMENU
,
NULL
,
{
.
submenu
=
&
sub_menu
}
},
{
APP
,
&
battery
,
{
.
app
=
&
clock_app
}
},
{
APP
,
NULL
,
{
.
app
=
&
clock_app
}
},
{
APP
,
&
gps_disconnected
,
{
.
app
=
&
clock_app
}
},
{
APP
,
NULL
,
{
.
app
=
&
clock_app
}
},
{
SUBMENU
,
&
battery_charging
,
{
.
submenu
=
&
sub_menu
}
},
{
APP
,
NULL
,
{
.
app
=
&
clock_app
}
},
{
APP
,
NULL
,
{
.
app
=
&
clock_app
}
},
{
APP
,
NULL
,
{
.
app
=
&
clock_app
}
},
{
APP
,
NULL
,
{
.
app
=
&
clock_app
}
},
{
SUBMENU
,
NULL
,
{
.
submenu
=
&
sub_menu
}
},
{
SUBMENU
,
NULL
,
{
.
submenu
=
&
sub_menu
}
},
{
SUBMENU
,
NULL
,
{
.
submenu
=
&
sub_menu
}
},
{
APP
,
NULL
,
{
.
app
=
&
clock_app
}
},
{
APP
,
NULL
,
{
.
app
=
&
clock_app
}
},
{
SUBMENU
,
&
settings_icon
,
{
.
submenu
=
&
settings_menu
}
},
{
END
,
NULL
,
{
NULL
}
}
}
};
...
...
sw/freertos/src/apps/settings/set_time.c
0 → 100644
View file @
498ed818
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* Settings application.
*/
#include "application.h"
#include "widgets/status_bar.h"
#include "widgets/spinbox.h"
#include "clock.h"
#include <time.h>
static
const
int
DIST_X
=
24
;
static
const
int
POS_X
=
20
;
static
const
int
POS_Y
=
30
;
static
const
int
SIZE_X
=
16
;
static
const
int
SIZE_Y
=
38
;
static
void
set_time_redraw
(
struct
ui_widget
*
w
)
{
gfx_centered_text
(
&
w
->
dc
,
&
font_helv38b
,
POS_Y
,
":"
,
1
);
}
static
struct
ui_widget
set_time_screen
=
{
&
set_time_redraw
,
NULL
,
{
0
,
0
,
127
,
127
},
0
,
WF_ACTIVE
|
WF_VISIBLE
,
NULL
};
#define SPINBOX_NUMBER 4
enum
SPINBOX
{
H1
=
0
,
H2
,
M1
,
M2
};
// Spinboxes used for setting the hour & minute.
static
struct
spinbox
sb_time
[
SPINBOX_NUMBER
];
// Index that indicates the active spinbox
static
int
sb_index
;
static
inline
char
sb_digit
(
int
idx
)
{
// convert ascii character to a digit by subtracting 0x30 ('0')
return
spinbox_get_value
(
&
sb_time
[
idx
])
-
'0'
;
}
// Checks if spinboxes contain correct values
static
bool
is_valid
(
void
)
{
return
(
sb_digit
(
H1
)
<
3
&&
sb_digit
(
H2
)
<
5
&&
sb_digit
(
M1
)
<
6
);
}
// Sets the hour from spinboxes to clock
static
void
save
(
void
)
{
struct
tm
time
=
clock_get_time
();
time
.
tm_hour
=
sb_digit
(
H1
)
*
10
+
sb_digit
(
H2
);
time
.
tm_min
=
sb_digit
(
M1
)
*
10
+
sb_digit
(
M2
);
time
.
tm_sec
=
0
;
clock_set_time
(
&
time
);
}
// Sets the spinboxes to the current hour
static
void
load
(
void
)
{
struct
tm
time
=
clock_get_time
();
spinbox_set_value
(
&
sb_time
[
H1
],
(
time
.
tm_hour
/
10
)
+
'0'
);
spinbox_set_value
(
&
sb_time
[
H2
],
(
time
.
tm_hour
%
10
)
+
'0'
);
spinbox_set_value
(
&
sb_time
[
M1
],
(
time
.
tm_min
/
10
)
+
'0'
);
spinbox_set_value
(
&
sb_time
[
M2
],
(
time
.
tm_min
%
10
)
+
'0'
);
}
void
set_time_main
(
void
*
params
)
{
(
void
)(
params
);
// suppress unused parameter warning
struct
event
evt
;
int
i
;
// initialize user interface
ui_clear
();
// initialize widgets before adding them
for
(
i
=
0
;
i
<
4
;
++
i
)
{
struct
rect
pos
=
{
POS_X
+
i
*
DIST_X
,
POS_Y
,
POS_X
+
i
*
DIST_X
+
SIZE_X
,
POS_Y
+
SIZE_Y
};
spinbox_init_widget
(
&
sb_time
[
i
],
pos
,
char_digits
);
}
sb_index
=
H1
;
spinbox_set_active
(
&
sb_time
[
H1
],
true
);
ui_init_widget
(
&
set_time_screen
);
for
(
i
=
0
;
i
<
4
;
++
i
)
{
ui_add_widget
(
&
sb_time
[
i
].
widget
);
}
// widget belongs to the main screen
for
(
i
=
0
;
i
<
4
;
++
i
)
{
ui_add_child
(
&
set_time_screen
,
&
sb_time
[
i
].
widget
);
}
ui_add_widget
(
&
set_time_screen
);
ui_init_widget
(
&
status_bar
);
ui_add_widget
(
&
status_bar
);
load
();
ui_update
(
NULL
);
// event loop
while
(
1
)
{
if
(
xQueueReceive
(
appQueue
,
&
evt
,
0
))
{
switch
(
evt
.
type
)
{
case
BUTTON_PRESSED
:
if
(
evt
.
data
.
button
==
BUT_TL
)
{
return
;
// go back to the main menu
}
else
if
(
evt
.
data
.
button
==
BUT_TR
)
{
if
(
sb_index
<
SPINBOX_NUMBER
-
1
)
{
spinbox_set_active
(
&
sb_time
[
sb_index
],
false
);
spinbox_set_active
(
&
sb_time
[
++
sb_index
],
true
);
}
else
if
(
is_valid
())
{
save
();
return
;
}
else
{
// the set hour is invalid, start from the beginning
spinbox_set_active
(
&
sb_time
[
sb_index
],
false
);
sb_index
=
H1
;
spinbox_set_active
(
&
sb_time
[
H1
],
true
);
}
}
ui_update
(
&
evt
);
break
;
default:
// suppress warnings
break
;
}
}
}
}
application
set_time
=
{
.
name
=
"Set time"
,
// this will be shown in menu
.
main
=
set_time_main
};
sw/freertos/src/apps/settings/settings.h
0 → 100644
View file @
498ed818
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* List of settings subapps.
*/
#ifndef SETTINGS_H
#define SETTINGS_H
#include "application.h"
extern
application
set_time
;
#endif
/* SETTINGS_H */
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