Fix tick per sec/min bug 62/125062/6
authorHyunho Kang <hhstark.kang@samsung.com>
Thu, 13 Apr 2017 12:51:13 +0000 (21:51 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Fri, 14 Apr 2017 04:10:14 +0000 (21:10 -0700)
When a time tick was set with a long term like 30 seconds,
the tick was not called at the correct time with a very small error,
so the next time tick was set equal to the previous target tick time.
This causes an unintended callback called.
To solve this problem, it store the next time tick before set the timer,
and when the tick callback is called, if the current time's next tick is
same as the stored time, set the timer by calculating the stored
time's next tick.

Change-Id: Ib22470c5810818ab4871abcd3a31ce9278c5008e
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
src/watch_app_main.c

index 375a611..1bade82 100755 (executable)
@@ -150,6 +150,7 @@ static int __app_event_converter[APPCORE_BASE_EVENT_MAX] = {
 };
 
 struct watch_app_context __context;
+static double __prev_target_tick = -1;
 
 static void __on_ambient_tick(void *watchtime, void *data);
 static void __on_ambient_changed(int ambient, void *data);
@@ -234,11 +235,13 @@ static double __get_next_tick_sec()
        double term = 1.0;
        double sec = 1.0;
        int idx;
+       double target;
+
        struct _watch_time_s timeinfo;
 
        __get_timeinfo(&timeinfo);
        cur_time_in_milli = timeinfo.hour24 * 60 * 60 * 1000 + timeinfo.minute * 60 * 1000 +
-                       timeinfo.minute * 60 * 1000 + timeinfo.second * 1000 + timeinfo.millisecond;
+                       timeinfo.second * 1000 + timeinfo.millisecond;
 
        if (app_tick_type == WATCH_APP_TIME_TICKS_PER_SECOND) {
                term = (double)ONE_SECOND / (double)app_tick_resolution;
@@ -251,7 +254,13 @@ static double __get_next_tick_sec()
        }
 
        idx = cur_time_in_milli / term;
-       sec = (((idx + 1) * term) - cur_time_in_milli) / 1000.0;
+       target = (idx + 1) * term;
+
+       if (__prev_target_tick == target)
+               target = __prev_target_tick + term;
+
+       sec = (target - cur_time_in_milli) / 1000.0;
+       __prev_target_tick = target;
 
        return sec;
 }
@@ -390,6 +399,7 @@ static void __time_tick_cancel(void)
        if (watch_tick) {
                ecore_timer_del(watch_tick);
                watch_tick = NULL;
+               __prev_target_tick = -1;
        }
 }