2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include "mf-sensor.h"
22 static sensor_h g_sensor;
24 int mf_sensor_init(void)
26 int res = SENSOR_ERROR_NONE;
29 res = sensor_is_supported(SENSOR_MOTION_DOUBLETAP, &doubletap);
30 MF_CHECK_VAL(res == SENSOR_ERROR_NONE, res);
33 mf_error("sensor not supported. doubletap: %d", doubletap);
37 res = sensor_create(&g_sensor);
38 if(res != SENSOR_ERROR_NONE)
39 mf_error("Fail sensor_create");
42 mf_error("motion not supported");
47 int mf_sensor_finalize(void)
49 int res = SENSOR_ERROR_NONE;
50 MF_CHECK_VAL(g_sensor, -1);
51 res = sensor_destroy(g_sensor);
57 int mf_sensor_start(mf_motion_type type)
59 MF_CHECK_VAL(g_sensor, -1);
61 int res = SENSOR_ERROR_NONE;
64 case MF_MOTION_FACEDOWN:
65 res = sensor_start(g_sensor, SENSOR_MOTION_FACEDOWN);
67 case MF_MOTION_DOUBLETAP:
68 res = sensor_start(g_sensor, SENSOR_MOTION_DOUBLETAP);
71 mf_error("Invalid motion type: 0x%x", type);
74 if(res != SENSOR_ERROR_NONE)
75 mf_error("Fail sensor_start: type: %d ", type);
77 mf_debug("sensor started");
81 int mf_sensor_stop(mf_motion_type type)
83 MF_CHECK_VAL(g_sensor, -1);
85 int res = SENSOR_ERROR_NONE;
88 case MF_MOTION_FACEDOWN:
89 res = sensor_stop(g_sensor, SENSOR_MOTION_FACEDOWN);
91 case MF_MOTION_DOUBLETAP:
92 res = sensor_stop(g_sensor, SENSOR_MOTION_DOUBLETAP);
95 mf_error("Invalid motion type: 0x%x", type);
98 if(res != SENSOR_ERROR_NONE)
99 mf_error("Fail sensor_stop: type: %d ", type);
101 mf_debug("sensor stopped");
105 int mf_sensor_set_callback(mf_motion_type type, mf_sensor_cb callback, void *user_data)
107 MF_CHECK_VAL(g_sensor, -1);
109 int res = SENSOR_ERROR_NONE;
112 case MF_MOTION_FACEDOWN:
113 res = sensor_motion_facedown_set_cb(g_sensor, callback, user_data);
115 case MF_MOTION_DOUBLETAP:
116 res = sensor_motion_doubletap_set_cb(g_sensor, callback, user_data);
119 mf_error("Invalid motion type: 0x%x", type);
122 if(res != SENSOR_ERROR_NONE)
123 mf_error("Error: set sensor callback res = 0x%x");
127 int mf_sensor_unset_callback(mf_motion_type type)
129 MF_CHECK_VAL(g_sensor, -1);
131 int res = SENSOR_ERROR_NONE;
134 case MF_MOTION_FACEDOWN:
135 res = sensor_motion_facedown_unset_cb(g_sensor);
137 case MF_MOTION_DOUBLETAP:
138 res = sensor_motion_doubletap_unset_cb(g_sensor);
141 mf_error("Invalid motion type: 0x%x", type);
144 if(res != SENSOR_ERROR_NONE)
145 mf_error("Error: set sensor callback res = 0x%x");