2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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.
18 #include "GestureSensor.h"
20 using namespace gesture;
23 GestureSensor::GestureSensor() :
24 __gestureType(static_cast<gesture_type_e>(UNDEFINED)),
31 GestureSensor::~GestureSensor()
35 bool GestureSensor::setGesture(gesture_type_e type)
37 sensor_type_t sensor = __toSensor(type);
38 IF_FAIL_RETURN(sensor != UNKNOWN_SENSOR, false);
41 __sensorAdapter.setSensor(sensor);
45 void GestureSensor::setPowerSave(bool ps)
47 __sensorAdapter.setPowerSave(ps);
50 void GestureSensor::setCallback(gesture_recognition_cb cb)
55 void GestureSensor::setUserData(void* data)
60 bool GestureSensor::start()
62 return __sensorAdapter.start();
65 bool GestureSensor::stop()
67 return __sensorAdapter.stop();
70 bool GestureSensor::isSupported(gesture_type_e type)
72 sensor_type_t sensor = __toSensor(type);
73 IF_FAIL_RETURN(sensor != UNKNOWN_SENSOR, false);
75 return SensorAdapter::isSupported(sensor);
78 void GestureSensor::onEvent(double timestamp, float* values, int accuracy)
81 data.gesture = __gestureType;
83 /* TODO: This is the default form.
84 For each sensor, this part needs to adapt accordingly */
85 data.event = static_cast<int>(values[0]);
87 __callback(__gestureType, &data, timestamp, static_cast<gesture_error_e>(ERR_NONE), __userData);
90 sensor_type_t GestureSensor::__toSensor(gesture_type_e type)
94 return GESTURE_MOVEMENT_SENSOR;
95 case GESTURE_WRIST_UP:
96 return GESTURE_WRIST_UP_SENSOR;
98 return UNKNOWN_SENSOR;