Fix tick per sec/min bug 82/125182/1
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 05:29:18 +0000 (14:29 +0900)
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/appcore-watch.c

index 9b704da..ba11925 100755 (executable)
@@ -176,6 +176,7 @@ struct watch_core {
 };
 
 static struct watch_core core;
+static double __prev_target_tick = -1;
 
 static int __sys_lowmem_post(void *data, void *evt);
 static int __sys_lowmem(void *data, void *evt);
@@ -898,6 +899,7 @@ static void __watch_core_time_tick_cancel(void)
        if (watch_tick) {
                ecore_timer_del(watch_tick);
                watch_tick = NULL;
+               __prev_target_tick = -1;
        }
 }
 
@@ -907,11 +909,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;
@@ -924,7 +928,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;
 }