4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 #include "appcore-internal.h"
32 #define LCD_TYPE_KEY "memory/sensor/lcd_type"
36 int (*callback) (enum appcore_rm, void *);
43 static struct rot_s rot;
46 enum accelerometer_rotate_state re;
50 static struct rot_evt re_to_rm[] = {
53 APPCORE_RM_PORTRAIT_NORMAL,
57 APPCORE_RM_LANDSCAPE_NORMAL,
61 APPCORE_RM_PORTRAIT_REVERSE,
65 APPCORE_RM_LANDSCAPE_REVERSE,
69 static enum appcore_rm __get_mode(int event_data)
74 m = APPCORE_RM_UNKNOWN;
76 for (i = 0; i < sizeof(re_to_rm) / sizeof(re_to_rm[0]); i++) {
77 if (re_to_rm[i].re == event_data) {
86 static void __changed_cb(unsigned int event_type, sensor_event_data_t *event,
95 if (event_type != ACCELEROMETER_EVENT_ROTATION_CHECK) {
100 cb_event_data = (int *)(event->event_data);
102 m = __get_mode(*cb_event_data);
104 _DBG("[APP %d] Rotation: %d -> %d", getpid(), rot.mode, m);
107 if (rot.cb_set && rot.mode != m) {
108 rot.callback(m, data);
114 static void __lock_cb(keynode_t *node, void *data)
119 rot.lock = vconf_keynode_get_bool(node);
122 _DBG("[APP %d] Rotation locked", getpid());
126 _DBG("[APP %d] Rotation unlocked", getpid());
129 r = appcore_get_rotation_state(&m);
130 _DBG("[APP %d] Rotmode prev %d -> curr %d", getpid(),
132 if (!r && rot.mode != m) {
133 rot.callback(m, data);
140 static void __add_rotlock(void *data)
146 r = vconf_get_bool(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, &lock);
148 _DBG("[APP %d] Rotation vconf get bool failed", getpid());
153 vconf_notify_key_changed(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, __lock_cb,
157 static void __del_rotlock(void)
159 vconf_ignore_key_changed(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, __lock_cb);
163 EXPORT_API int appcore_set_rotation_cb(int (*cb) (enum appcore_rm, void *),
174 if (rot.callback != NULL) {
179 handle = sf_connect(ACCELEROMETER_SENSOR);
181 _ERR("sf_connect failed: %d", handle);
185 r = sf_register_event(handle, ACCELEROMETER_EVENT_ROTATION_CHECK,
186 NULL, __changed_cb, data);
188 _ERR("sf_register_event failed: %d", r);
189 sf_disconnect(handle);
197 r = sf_start(handle, 0);
199 _ERR("sf_start failed: %d", r);
200 sf_unregister_event(handle, ACCELEROMETER_EVENT_ROTATION_CHECK);
205 sf_disconnect(handle);
216 EXPORT_API int appcore_unset_rotation_cb(void)
220 _retv_if(rot.callback == NULL, 0);
225 r = sf_unregister_event(rot.handle,
226 ACCELEROMETER_EVENT_ROTATION_CHECK);
228 _ERR("sf_unregister_event failed: %d", r);
236 if (rot.sf_started == 1) {
237 r = sf_stop(rot.handle);
239 _ERR("sf_stop failed: %d", r);
245 r = sf_disconnect(rot.handle);
247 _ERR("sf_disconnect failed: %d", r);
255 EXPORT_API int appcore_get_rotation_state(enum appcore_rm *curr)
265 r = sf_check_rotation(&event);
267 _ERR("sf_check_rotation failed: %d", r);
268 *curr = APPCORE_RM_UNKNOWN;
272 *curr = __get_mode(event);
277 EXPORT_API int appcore_pause_rotation_cb(void)
281 _retv_if(rot.callback == NULL, 0);
282 _DBG("[APP %d] appcore_pause_rotation_cb is called", getpid());
287 r = sf_unregister_event(rot.handle,
288 ACCELEROMETER_EVENT_ROTATION_CHECK);
290 _ERR("sf_unregister_event in appcore_internal_sf_stop failed: %d", r);
296 if (rot.sf_started == 1) {
297 r = sf_stop(rot.handle);
299 _ERR("sf_stop in appcore_internal_sf_stop failed: %d",
309 EXPORT_API int appcore_resume_rotation_cb(void)
314 _retv_if(rot.callback == NULL, 0);
315 _DBG("[APP %d] appcore_resume_rotation_cb is called", getpid());
317 if (rot.cb_set == 0) {
318 r = sf_register_event(rot.handle,
319 ACCELEROMETER_EVENT_ROTATION_CHECK, NULL,
320 __changed_cb, rot.cbdata);
322 _ERR("sf_register_event in appcore_internal_sf_start failed: %d", r);
328 if (rot.sf_started == 0) {
329 r = sf_start(rot.handle, 0);
331 _ERR("sf_start in appcore_internal_sf_start failed: %d",
333 sf_unregister_event(rot.handle,
334 ACCELEROMETER_EVENT_ROTATION_CHECK);
341 __add_rotlock(rot.cbdata);
343 r = appcore_get_rotation_state(&m);
344 _DBG("[APP %d] Rotmode prev %d -> curr %d", getpid(), rot.mode, m);
345 if (!r && rot.mode != m && rot.lock == 0) {
346 rot.callback(m, rot.cbdata);