2 * Copyright (c) 2011 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.
18 #include <dpl/log/log.h>
19 #include <Commons/Exception.h>
21 namespace WrtDeviceApis {
22 namespace Accelerometer {
24 Sensor& Sensor::getInstance()
26 static Sensor instance;
30 double Sensor::getX() const
33 memset(&data, 0, sizeof(sensor_data_t));
34 if ((sf_get_data(m_handle, ACCELEROMETER_BASE_DATA_SET, &data) < 0) ||
35 (data.values_num < 1))
37 Throw(Commons::PlatformException);
39 return data.values[0];
42 double Sensor::getY() const
45 memset(&data, 0, sizeof(sensor_data_t));
46 if ((sf_get_data(m_handle, ACCELEROMETER_BASE_DATA_SET, &data) < 0) ||
47 (data.values_num < 2))
49 Throw(Commons::PlatformException);
51 return data.values[1];
54 double Sensor::getZ() const
57 memset(&data, 0, sizeof(sensor_data_t));
58 if ((sf_get_data(m_handle, ACCELEROMETER_BASE_DATA_SET, &data) < 0) ||
59 (data.values_num < 3))
61 Throw(Commons::PlatformException);
63 return data.values[2];
68 m_handle = sf_connect(ACCELEROMETER_SENSOR);
70 LogError("Could not connect with accelerometer sensor.");
71 } else if (sf_start(m_handle, 0) < 0) {
72 LogError("Could not start communication with sensor.");
80 sf_disconnect(m_handle);