From: funman Date: Sat, 15 May 2010 15:20:45 +0000 (+0000) Subject: Fix alarmclock plugin time miscalculation X-Git-Url: https://repo.or.cz/w/kugel-rb.git/commitdiff_plain/84948d79aa139a25e8158f46daae9e0015b0dd3f Fix alarmclock plugin time miscalculation Author: Clément Pit-Claudel (CFP) Flyspray: FS#11110 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26056 a1c6a512-1295-4272-9138-f99709370657 --- diff --git a/apps/plugins/alarmclock.c b/apps/plugins/alarmclock.c index a691b6182..88e3e858c 100644 --- a/apps/plugins/alarmclock.c +++ b/apps/plugins/alarmclock.c @@ -28,7 +28,8 @@ const struct button_mapping *plugin_contexts[] = {generic_directions, generic_actions}; static int current = 0; -static int alarm[2] = {0, 0}, maxval[2] = {24, 60}; +static bool tomorrow = false; +static int alarm[2] = {0, 0}, maxval[2] = {24, 60}, prev_tick = 3600 * 24; static bool quit = false, usb = false, waiting = false, done = false; static inline int get_button(void) { @@ -36,9 +37,15 @@ static inline int get_button(void) { } int rem_seconds(void) { - return (((alarm[0] - rb->get_time()->tm_hour) * 3600) - +((alarm[1] - rb->get_time()->tm_min) * 60) - -(rb->get_time()->tm_sec)); + int seconds = (((alarm[0] - rb->get_time()->tm_hour) * 3600) + +((alarm[1] - rb->get_time()->tm_min) * 60) + -(rb->get_time()->tm_sec)); + + /* The tomorrow flag means that the alarm should ring on the next day */ + if (seconds > prev_tick) tomorrow = false; + prev_tick = seconds; + + return seconds + (tomorrow ? 24 * 3600 : 0); } void draw_centered_string(struct screen * display, char * string) { @@ -87,7 +94,7 @@ bool can_play(void) { else if (audio_status & AUDIO_STATUS_PAUSE) return true; - return false; + return false; } void play(void) { @@ -152,7 +159,7 @@ enum plugin_status plugin_start(const void* parameter) case PLA_FIRE: { if (rem_seconds() < 0) - alarm[0] += 24; + tomorrow = true; waiting = true; break;