diff options
author | Robert Kukla <roolku@rockbox.org> | 2008-06-28 21:01:08 +0000 |
---|---|---|
committer | Robert Kukla <roolku@rockbox.org> | 2008-06-28 21:01:08 +0000 |
commit | 1f045bcb1e6b54de62c5dbca413c8a6192743fa9 (patch) | |
tree | 012d23657025b60b592f977b7184239cf734bc03 /apps | |
parent | 205f3df7816a1eea9c812ea285d74a4f8ecfad2a (diff) | |
download | rockbox-1f045bcb1e6b54de62c5dbca413c8a6192743fa9.tar.gz rockbox-1f045bcb1e6b54de62c5dbca413c8a6192743fa9.zip |
FS#9085 - Stopwatch: Retain stopwatch times after exit
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17858 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/stopwatch.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/apps/plugins/stopwatch.c b/apps/plugins/stopwatch.c index 2a5f97f93d..6bd6d2be2a 100644 --- a/apps/plugins/stopwatch.c +++ b/apps/plugins/stopwatch.c | |||
@@ -32,6 +32,8 @@ PLUGIN_HEADER | |||
32 | #define LAP_Y TIMER_Y+1 | 32 | #define LAP_Y TIMER_Y+1 |
33 | #define MAX_LAPS 64 | 33 | #define MAX_LAPS 64 |
34 | 34 | ||
35 | #define STOPWATCH_FILE ROCKBOX_DIR "/apps/stopwatch.dat" | ||
36 | |||
35 | /* variable button definitions */ | 37 | /* variable button definitions */ |
36 | #if CONFIG_KEYPAD == RECORDER_PAD | 38 | #if CONFIG_KEYPAD == RECORDER_PAD |
37 | #define STOPWATCH_QUIT BUTTON_OFF | 39 | #define STOPWATCH_QUIT BUTTON_OFF |
@@ -230,6 +232,75 @@ static void ticks_to_string(int ticks,int lap,int buflen, char * buf) | |||
230 | } | 232 | } |
231 | } | 233 | } |
232 | 234 | ||
235 | /* | ||
236 | * Load saved stopwatch state, if exists. | ||
237 | */ | ||
238 | void load_stopwatch(void) | ||
239 | { | ||
240 | int fd; | ||
241 | |||
242 | fd = rb->open(STOPWATCH_FILE, O_RDONLY); | ||
243 | |||
244 | if (fd < 0) | ||
245 | { | ||
246 | return; | ||
247 | } | ||
248 | |||
249 | /* variable stopwatch isn't saved/loaded, because it is only used | ||
250 | * temporarily in main loop | ||
251 | */ | ||
252 | |||
253 | rb->read(fd, &start_at, sizeof(start_at)); | ||
254 | rb->read(fd, &prev_total, sizeof(prev_total)); | ||
255 | rb->read(fd, &counting, sizeof(counting)); | ||
256 | rb->read(fd, &curr_lap, sizeof(curr_lap)); | ||
257 | rb->read(fd, &lap_scroll, sizeof(lap_scroll)); | ||
258 | rb->read(fd, &lap_start, sizeof(lap_start)); | ||
259 | rb->read(fd, lap_times, sizeof(lap_times)); | ||
260 | |||
261 | if (counting && start_at > *rb->current_tick) | ||
262 | { | ||
263 | /* Stopwatch started in the future? Unlikely; probably started on a | ||
264 | * previous session and powered off in-between. We'll keep | ||
265 | * everything intact (user can clear manually) but stop the | ||
266 | * stopwatch to avoid negative timing. | ||
267 | */ | ||
268 | start_at = 0; | ||
269 | counting = false; | ||
270 | } | ||
271 | |||
272 | rb->close(fd); | ||
273 | } | ||
274 | |||
275 | /* | ||
276 | * Save stopwatch state. | ||
277 | */ | ||
278 | void save_stopwatch(void) | ||
279 | { | ||
280 | int fd; | ||
281 | |||
282 | fd = rb->open(STOPWATCH_FILE, O_CREAT|O_WRONLY|O_TRUNC); | ||
283 | |||
284 | if (fd < 0) | ||
285 | { | ||
286 | return; | ||
287 | } | ||
288 | |||
289 | /* variable stopwatch isn't saved/loaded, because it is only used | ||
290 | * temporarily in main loop | ||
291 | */ | ||
292 | |||
293 | rb->write(fd, &start_at, sizeof(start_at)); | ||
294 | rb->write(fd, &prev_total, sizeof(prev_total)); | ||
295 | rb->write(fd, &counting, sizeof(counting)); | ||
296 | rb->write(fd, &curr_lap, sizeof(curr_lap)); | ||
297 | rb->write(fd, &lap_scroll, sizeof(lap_scroll)); | ||
298 | rb->write(fd, &lap_start, sizeof(lap_start)); | ||
299 | rb->write(fd, lap_times, sizeof(lap_times)); | ||
300 | |||
301 | rb->close(fd); | ||
302 | } | ||
303 | |||
233 | enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) | 304 | enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) |
234 | { | 305 | { |
235 | char buf[32]; | 306 | char buf[32]; |
@@ -251,6 +322,8 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* parame | |||
251 | lines = 1; | 322 | lines = 1; |
252 | #endif | 323 | #endif |
253 | 324 | ||
325 | load_stopwatch(); | ||
326 | |||
254 | rb->lcd_clear_display(); | 327 | rb->lcd_clear_display(); |
255 | 328 | ||
256 | while (!done) | 329 | while (!done) |
@@ -308,6 +381,7 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* parame | |||
308 | case STOPWATCH_RC_QUIT: | 381 | case STOPWATCH_RC_QUIT: |
309 | #endif | 382 | #endif |
310 | case STOPWATCH_QUIT: | 383 | case STOPWATCH_QUIT: |
384 | save_stopwatch(); | ||
311 | done = true; | 385 | done = true; |
312 | break; | 386 | break; |
313 | 387 | ||