4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.tizenopensource.org/license
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <sensor_internal.h>
22 #include <vconf-keys.h>
27 #include <Elementary.h>
29 #include <ui-gadget-module.h>
31 #include "wfd_motion_control.h"
32 #include "wfd_ug_view.h"
33 #include "wfd_client.h"
36 static int motion_handle = -1;
38 static TARGET_VIEW_FOCUS __motion_target_view_focus_get(void *data)
40 struct ug_data *ugd = (struct ug_data *)data;
42 if ((ugd == NULL) || (ugd->naviframe == NULL))
43 return MOTION_TARGET_VIEW_FOCUS_OFF;
45 if (elm_object_focus_get(ugd->naviframe))
46 return MOTION_TARGET_VIEW_FOCUS_ON;
48 return MOTION_TARGET_VIEW_FOCUS_OFF;
52 static void __motion_shake_cb(unsigned int event_type, sensor_event_data_t *event_data, void *data)
56 gboolean motion_activated = FALSE;
57 struct ug_data *ugd = (struct ug_data *) data;
59 DBG(LOG_ERROR, "NULL pointer!");
62 TARGET_VIEW_FOCUS focus_state = __motion_target_view_focus_get(ugd);
64 DBG(LOG_DEBUG, "event type: %d, focus state: %d\n", event_type, focus_state);
66 if (focus_state != MOTION_TARGET_VIEW_FOCUS_ON)
69 if (vconf_get_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION,
70 (void *)&motion_activated)) {
71 DBG(LOG_ERROR, "Get motion activation status fail");
75 if (FALSE == motion_activated) {
76 DBG(LOG_INFO, "Motion value is false");
80 if (vconf_get_bool(VCONFKEY_SETAPPL_USE_SHAKE,
81 (void *)&motion_activated)) {
82 DBG(LOG_ERROR, "Get use shake status fail");
86 if (FALSE == motion_activated) {
87 DBG(LOG_INFO, "Shake status is false");
92 const char *btn_text = NULL;
94 wfd_refresh_wifi_direct_state(ugd);
96 if (NULL == ugd->scan_toolbar) {
97 DBG(LOG_ERROR, "NULL == ugd->scan_toolbar\n");
101 btn_text = elm_object_part_text_get(ugd->scan_toolbar, "default");
102 if (NULL == btn_text) {
103 DBG(LOG_ERROR, "Incorrect button text(NULL)\n");
107 GList *iterator = NULL;
109 if (0 == strcmp(btn_text, D_("IDS_WIFI_SK4_SCAN"))) {
110 if (WIFI_DIRECT_STATE_CONNECTED == ugd->wfd_status) {
111 ret = wfd_client_disconnect(NULL);
112 if (ret != WIFI_DIRECT_ERROR_NONE) {
113 DBG(LOG_ERROR, "Failed wfd_client_disconnect() [%d]\n", ret);
118 if (ugd->multi_connect_mode != WFD_MULTI_CONNECT_MODE_NONE) {
119 wfd_free_multi_selected_peers(ugd);
121 /* update the connecting icon */
122 for (iterator = ugd->raw_discovered_peer_list; iterator; iterator = iterator->next) {
123 ((device_type_s *)iterator->data)->conn_status = PEER_CONN_STATUS_DISCONNECTED;
124 wfd_ug_view_refresh_glitem(((device_type_s *)iterator->data)->gl_item);
127 } else if (WIFI_DIRECT_STATE_DEACTIVATED == ugd->wfd_status) {
128 wfd_client_switch_on(ugd);
129 } else if ((WIFI_DIRECT_STATE_DISCOVERING == ugd->wfd_status) || (WIFI_DIRECT_STATE_ACTIVATED == ugd->wfd_status)) {
130 ugd->wfd_discovery_status = WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL_START;
131 ret = wifi_direct_start_discovery_specific_channel(false, 1, WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL);
132 if (ret != WIFI_DIRECT_ERROR_NONE) {
133 ugd->wfd_discovery_status = WIFI_DIRECT_DISCOVERY_NONE;
134 DBG(LOG_ERROR, "Failed to start discovery. [%d]\n", ret);
135 wifi_direct_cancel_discovery();
143 void motion_create(struct ug_data *ugd)
147 motion_handle = sf_connect(MOTION_SENSOR);
148 if (motion_handle < 0) {
149 DBG(LOG_ERROR, "Failed Operation sf_connect.\n");
152 ret = sf_register_event(motion_handle, MOTION_ENGINE_EVENT_SHAKE, NULL,
153 __motion_shake_cb, ugd);
155 DBG(LOG_ERROR, "Failed Operation sf_register_event. [%d]\n", ret);
158 ret = sf_start(motion_handle, 0);
160 DBG(LOG_ERROR, "Failed Operation sf_start. [%d]\n", ret);
164 DBG(LOG_INFO, "Successfully, Init Sensor Handle\n");
168 ret = sf_disconnect(motion_handle);
170 DBG(LOG_ERROR, "Failed Operation sf_disconnect. [%d]\n", ret);
173 void motion_destroy(void)
177 if (motion_handle < 0) {
178 DBG(LOG_ERROR, "Motion Handle Not valid !!!");
182 ret = sf_stop(motion_handle);
184 DBG(LOG_ERROR, "Failed Operation sf_stop. [%d]\n", ret);
186 ret = sf_unregister_event(motion_handle, MOTION_ENGINE_EVENT_SHAKE);
188 DBG(LOG_ERROR, "Failed Operation sf_unregister_event. [%d]\n", ret);
190 ret = sf_disconnect(motion_handle);
192 DBG(LOG_ERROR, "Failed Operation sf_disconnect. [%d]\n", ret);