2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "MsgCppTypes.h"
20 #include "MsgGconfWrapper.h"
21 #include "MsgSensorWrapper.h"
22 #include "MsgNotificationWrapper.h"
24 #ifndef MSG_WEARABLE_PROFILE
25 #include <gesture_recognition.h>
27 /*==================================================================================================
29 ==================================================================================================*/
31 gesture_h gestureHandler = NULL;
33 msg_sensor_cb SensorCBFunction = NULL;
35 #endif /* MSG_WEARABLE_PROFILE */
37 /*==================================================================================================
38 FUNCTION IMPLEMENTATION
39 ==================================================================================================*/
41 #ifndef MSG_WEARABLE_PROFILE
42 void MsgGestureCB(gesture_type_e gesture, const gesture_data_h data, double timestamp, gesture_error_e error, void *user_data)
44 if (error != GESTURE_ERROR_NONE) {
45 MSG_DEBUG("Gesture error = [%d]", error);
49 gesture_event_e event;
50 int ret = gesture_get_event(data, &event);
51 if (ret == GESTURE_ERROR_NONE && event == GESTURE_EVENT_DETECTED && \
52 gesture == GESTURE_TURN_FACE_DOWN) {
53 MSG_DEBUG("GESTURE_TURN_FACE_DOWN gesture detected.");
54 int motion_activation = 0;
55 int use_turn_over = 0;
57 if (MsgSettingGetInt(VCONFKEY_SETAPPL_MOTION_ACTIVATION, &motion_activation) != MSG_SUCCESS) {
58 MSG_INFO("MsgSettingGetInt() is failed");
61 if (MsgSettingGetInt(VCONFKEY_SETAPPL_USE_TURN_OVER, &use_turn_over) != MSG_SUCCESS) {
62 MSG_INFO("MsgSettingGetInt() is failed");
65 if (motion_activation && use_turn_over) {
72 void MsgSensorCBStop()
77 MsgDeleteNoti(MSG_NOTI_TYPE_ALL, -1);
78 MsgRefreshNotification(MSG_NOTI_TYPE_ALL, false, MSG_ACTIVE_NOTI_TYPE_NONE);
79 #ifndef MSG_NOTI_INTEGRATION
80 MsgRefreshNotification(MSG_NOTI_TYPE_SIM, false, MSG_ACTIVE_NOTI_TYPE_NONE);
85 #endif /* MSG_WEARABLE_PROFILE */
89 #ifndef MSG_WEARABLE_PROFILE
90 if (MsgSensorConnect() == MSG_SUCCESS) {
91 if (MsgRegSensorCB(&MsgSensorCBStop) != MSG_SUCCESS) {
92 MSG_DEBUG("Fail to MsgRegSensorCB.");
93 MsgSensorDisconnect();
96 MSG_DEBUG("Fail to MsgSensorConnect.");
98 #endif /* MSG_WEARABLE_PROFILE */
102 msg_error_t MsgSensorConnect()
104 #ifndef MSG_WEARABLE_PROFILE
105 bool supported = false;
106 int ret = gesture_is_supported(GESTURE_TURN_FACE_DOWN, &supported);
107 if (ret != GESTURE_ERROR_NONE) {
108 MSG_DEBUG("gesture_is_supported is failed [%d]", ret);
109 return MSG_ERR_UNKNOWN;
112 MSG_DEBUG("GESTURE_TURN_FACE_DOWN not supported in the current device.");
113 return MSG_ERR_UNKNOWN;
116 ret = gesture_create(&gestureHandler);
117 if (ret != GESTURE_ERROR_NONE) {
118 MSG_DEBUG("gesture_create is failed [%d]", ret);
119 return MSG_ERR_UNKNOWN;
121 #endif /* MSG_WEARABLE_PROFILE */
127 void MsgSensorDisconnect()
129 #ifndef MSG_WEARABLE_PROFILE
130 if (SensorCBFunction != NULL)
131 SensorCBFunction = NULL;
133 if (gestureHandler == NULL)
137 if(gesture_stop_recognition(gestureHandler)!= GESTURE_ERROR_NONE)
138 MSG_DEBUG("gesture_stop_recognition failed");
139 } catch(int exception) {
140 MSG_FATAL("gesture_stop_recognition error [%d]", exception);
143 gesture_release(gestureHandler);
144 gestureHandler = NULL;
145 #endif /* MSG_WEARABLE_PROFILE */
149 msg_error_t MsgRegSensorCB(msg_sensor_cb cb)
151 #ifndef MSG_WEARABLE_PROFILE
152 if (gestureHandler == NULL) {
153 MSG_DEBUG("Not connected to gesture FW.");
154 return MSG_ERR_UNKNOWN;
159 SensorCBFunction = cb;
161 MSG_DEBUG("cb is NULL.");
162 return MSG_ERR_UNKNOWN;
165 int ret = gesture_start_recognition(gestureHandler, GESTURE_TURN_FACE_DOWN, \
166 GESTURE_OPTION_DEFAULT, MsgGestureCB, NULL);
167 if (ret != GESTURE_ERROR_NONE) {
168 MSG_DEBUG("gesture_start_recognition failed");
169 return MSG_ERR_UNKNOWN;
171 #endif /* MSG_WEARABLE_PROFILE */