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
}
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.
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()
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
*/
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
*/
}
}
+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;
__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);
}
*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;
+}
+
+
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