Add set tick frequncy feature 28/93228/8
authorHyunho Kang <hhstark.kang@samsung.com>
Fri, 21 Oct 2016 06:47:08 +0000 (15:47 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Wed, 2 Nov 2016 09:45:22 +0000 (18:45 +0900)
- APIs for tick resolution setting
- watch_app_set_tick_frequency
- watch_app_get_tick_frequency

Change-Id: I80aede5d3e8741abf959ce0fc9b7f4424ff9b981
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
include/appcore-watch.h
include/watch_app.h
src/appcore-watch.c
src/watch_app_main.c

index 9c274fa..2b4645b 100755 (executable)
@@ -73,6 +73,8 @@ void watch_core_get_timeinfo(struct watch_time_s *timeinfo);
 bool watch_core_get_24h_mode(void);
 int watch_core_set_ambient_tick_type(watch_app_ambient_tick_type_e type);
 int watch_core_get_ambient_tick_type(watch_app_ambient_tick_type_e *type);
+int watch_core_set_time_tick_frequency(int ticks, watch_app_time_tick_resolution_e type);
+int watch_core_get_time_tick_frequency(int *ticks, watch_app_time_tick_resolution_e *type);
 
 #ifdef __cplusplus
 }
index 4f1a73b..608a028 100755 (executable)
@@ -114,7 +114,8 @@ typedef void (*watch_app_resume_cb) (void *user_data);
 typedef void (*watch_app_terminate_cb) (void *user_data);
 
 /**
- * @brief Called at each second. This callback is not called while the app is paused or the device is in ambient mode.
+ * @brief Called with the frequency set with watch_app_set_time_tick_frequency().
+ * @details This callback is not called while the app is paused or the device is in ambient mode.
  * @since_tizen 2.3.1
  *
  * @param[in] watch_time The watch time handle. watch_time will not be available after returning this callback. It will be freed by the framework.
@@ -123,7 +124,7 @@ typedef void (*watch_app_terminate_cb) (void *user_data);
 typedef void (*watch_app_time_tick_cb) (watch_time_h watch_time, void *user_data);
 
 /**
- * @brief Called at each minute when the device in the ambient mode.
+ * @brief Called with the frequency set with watch_app_set_ambient_tick_type(), if the device is in the ambient mode.
  * @since_tizen 2.3.1
  *
  * @remarks You should not do a job that takes long time in this callback. You should update the UI as fast as possible in this callback. The platform might make the device to sleep in short time after the ambient tick expires. Since 2.3.2, you can control when this callback is called by watch_app_set_ambient_tick_type()
@@ -254,6 +255,53 @@ int watch_app_main(int argc, char **argv, watch_app_lifecycle_callback_s *callba
 void watch_app_exit(void);
 
 /**
+ * @brief Enumeration for tick resolution type.
+ * @details It is one of the input parameters of the watch_app_set_time_tick_frequency() and watch_app_get_time_tick_frequency() functions.
+ * @since_tizen 3.0
+ *
+ * @see watch_app_set_time_tick_frequency()
+ * @see watch_app_get_time_tick_frequency()
+ */
+typedef enum {
+       WATCH_APP_TIME_TICKS_PER_SECOND, /**< 1 ~ 60 ticks per second */
+       WATCH_APP_TIME_TICKS_PER_MINUTE, /**< 1 ~ 60 ticks per minute */
+       WATCH_APP_TIME_TICKS_PER_HOUR, /**< 1 ~ 60 ticks per hour */
+} watch_app_time_tick_resolution_e;
+
+/**
+ * @brief Sets the frequency of watch_app_time_tick_cb() calls.
+ * @details If watch_app_set_time_tick_frequency() is not called, watch_app_time_tick_cb() will be called every second.
+ * @since_tizen 3.0
+ *
+ * @param[in] ticks The number of ticks per given resolution type
+ * @param[in] type The resolution type
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ *
+ * @see watch_app_time_tick_resolution_e
+ * @see watch_app_get_time_tick_frequency()
+ */
+int watch_app_set_time_tick_frequency(int ticks, watch_app_time_tick_resolution_e type);
+
+/**
+ * @brief Gets the frequency of watch_app_time_tick_cb() calls.
+ * @since_tizen 3.0
+ *
+ * @param[out] ticks The number of ticks per given resolution type
+ * @param[out] type The resolution type
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ *
+ * @see watch_app_time_tick_resolution_e
+ * @see watch_app_set_time_tick_frequency()
+ */
+int watch_app_get_time_tick_frequency(int *ticks, watch_app_time_tick_resolution_e *type);
+
+/**
  * @brief Enumeration for periodic ambient tick type.
  * @since_tizen 2.3.2
  */
index 95a1946..8fa1c6b 100755 (executable)
@@ -69,6 +69,9 @@ static alarm_id_t alarm_id = 0;
 static watch_app_ambient_tick_type_e ambient_tick_type
                                        = WATCH_APP_AMBIENT_TICK_EVERY_MINUTE;
 
+static watch_app_time_tick_resolution_e app_tick_type = WATCH_APP_TIME_TICKS_PER_SECOND;
+static int app_tick_resolution = 1;
+
 /**
  * Appcore internal system event
  */
@@ -896,6 +899,34 @@ static void __watch_core_time_tick_cancel(void)
        }
 }
 
+static double __get_next_tick_sec()
+{
+       double cur_time_in_milli;
+       double term = 1.0;
+       double sec = 1.0;
+       int idx;
+       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;
+
+       if (app_tick_type == WATCH_APP_TIME_TICKS_PER_SECOND) {
+               term = (double)ONE_SECOND / (double)app_tick_resolution;
+       } else if (app_tick_type == WATCH_APP_TIME_TICKS_PER_MINUTE) {
+               term = (double)ONE_MINUTE_IN_SEC / (double)app_tick_resolution;
+               term *= 1000;
+       } else if (app_tick_type == WATCH_APP_TIME_TICKS_PER_HOUR) {
+               term = (double)ONE_HOUR_IN_SEC / (double)app_tick_resolution;
+               term *= 1000;
+       }
+
+       idx = cur_time_in_milli / term;
+       sec = (((idx + 1) * term) - cur_time_in_milli) / 1000.0;
+
+       return sec;
+}
+
 static Eina_Bool __watch_core_time_tick(void *data)
 {
        struct watch_time_s timeinfo;
@@ -907,10 +938,10 @@ static Eina_Bool __watch_core_time_tick(void *data)
                __get_timeinfo(&timeinfo);
 
                /* Set a next timer */
-               sec = (ONE_SECOND - timeinfo.millisecond) / 1000.0;
+               sec = __get_next_tick_sec();
                watch_tick = ecore_timer_add(sec, __watch_core_time_tick, NULL);
 
-               _D("next time tick: %f", sec);
+               _D("next time tick: %f, type %d, ticks %d", sec, app_tick_resolution, app_tick_type);
                priv.ops->time_tick(&timeinfo, priv.ops->data);
        }
 
@@ -1254,3 +1285,37 @@ EXPORT_API int watch_core_get_ambient_tick_type(watch_app_ambient_tick_type_e *t
        *type = ambient_tick_type;
        return 0;
 }
+
+EXPORT_API int watch_core_set_time_tick_frequency(int ticks, watch_app_time_tick_resolution_e type)
+{
+       double sec = 1.0;
+       struct watch_time_s timeinfo;
+
+       _D("ticks: %d, type: %d", ticks, type);
+       ecore_timer_precision_set(0.0000001);
+       __watch_core_time_tick_cancel();
+
+       app_tick_type = type;
+       app_tick_resolution = ticks;
+
+       sec = __get_next_tick_sec();
+       /* Set a next timer */
+       watch_tick = ecore_timer_add(sec, __watch_core_time_tick, NULL);
+       _D("next time tick: %f", sec);
+
+       if (priv.ops && priv.ops->time_tick && priv.state != WS_PAUSED) {
+               __get_timeinfo(&timeinfo);
+               priv.ops->time_tick(&timeinfo, priv.ops->data);
+       }
+
+       return 0;
+}
+
+EXPORT_API int watch_core_get_time_tick_frequency(int *ticks, watch_app_time_tick_resolution_e *type)
+{
+       *ticks = app_tick_resolution;
+       *type = app_tick_type;
+       return 0;
+}
+
+
index 4fc3351..95fe6f7 100755 (executable)
@@ -708,4 +708,18 @@ EXPORT_API int watch_app_get_ambient_tick_type(watch_app_ambient_tick_type_e *ty
        if (type == NULL)
                return APP_ERROR_INVALID_PARAMETER;
        return watch_core_get_ambient_tick_type(type);
+}
+
+EXPORT_API int watch_app_set_time_tick_frequency(int ticks, watch_app_time_tick_resolution_e type)
+{
+       if (type < WATCH_APP_TIME_TICKS_PER_SECOND || type > WATCH_APP_TIME_TICKS_PER_HOUR)
+               return APP_ERROR_INVALID_PARAMETER;
+       return watch_core_set_time_tick_frequency(ticks, type);
+}
+
+EXPORT_API int watch_app_get_time_tick_frequency(int *ticks, watch_app_time_tick_resolution_e *type)
+{
+       if (type == NULL || ticks == NULL)
+               return APP_ERROR_INVALID_PARAMETER;
+       return watch_core_get_time_tick_frequency(ticks, type);
 }
\ No newline at end of file