2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUixSensor_SensorUtil.cpp
20 * @brief This is the implementation file for the %_SensorUtil class.
22 * This files contains implementation of the %_SensorUtil class.
26 #include <FBaseSysLog.h>
28 #include <FApp_AppInfo.h>
30 #include "FUixSensor_SensorUtil.h"
31 #include "FUixSensor_ISensorCore.h"
33 using Tizen::App::_AppInfo;
35 namespace Tizen { namespace Uix { namespace Sensor
38 _SensorUtil::IsSensorTypeValid(SensorType sensorType)
40 return (sensorType > SENSOR_TYPE_NONE) && (sensorType < SENSOR_TYPE_MAX);
44 _SensorUtil::CheckSensorTypeValidation(SensorType sensorType)
46 if (_AppInfo::GetApiVersion() == Tizen::Base::_API_VERSION_2_0 && _AppInfo::IsOspCompat())
48 if (!IsSensorTypeValid(sensorType))
50 SetLastResult(E_DEVICE_UNAVAILABLE);
51 return E_DEVICE_UNAVAILABLE;
54 if (!_ISensorCore::IsSupported(sensorType))
56 SetLastResult(E_DEVICE_UNAVAILABLE);
57 return E_DEVICE_UNAVAILABLE;
62 SysTryReturn(NID_UIX, IsSensorTypeValid(sensorType), E_INVALID_ARG, E_INVALID_ARG, "Invalid SensorType [sensorType:%d]", sensorType);
64 bool isSupported = _ISensorCore::IsSupported(sensorType);
65 result r = GetLastResult();
67 SysTryReturn(NID_UIX, !IsFailed(r), E_OPERATION_FAILED, E_OPERATION_FAILED, "The operation has failed [sensorType:%d]", sensorType);
68 SysTryReturn(NID_UIX, isSupported, E_UNSUPPORTED_OPERATION, E_UNSUPPORTED_OPERATION, "Unsupported SensorType [sensorType:%d]", sensorType);
75 _SensorUtil::CheckIntervalValidation(SensorType sensorType, long interval)
79 result r = _ISensorCore::GetIntervalRange(sensorType, min, max);
85 SysTryReturn(NID_UIX, (min <= interval) && (max >= interval), E_INVALID_ARG, E_INVALID_ARG, "Invalid interval [sensorType:%d, min:%ld, max:%ld, interval:%ld]", sensorType, min, max, interval);
91 _SensorUtil::Atan2(double y, double x)
93 // reference: http://en.wikipedia.org/wiki/Atan2#Other_implementations.2Fcode_for_atan2
96 return Tizen::Base::Utility::Math::Atan(y / x);
99 if ((y >= 0.0) && (x < 0.0))
101 return Tizen::Base::Utility::Math::Atan(y / x) + PI;
104 if ((y < 0.0) && (x < 0.0))
106 return Tizen::Base::Utility::Math::Atan(y / x) - PI;
109 if ((y > 0.0) && IsEquals(x, 0.0))
114 if ((y < 0.0) && IsEquals(x, 0.0))
124 _SensorUtil::CutTimestamp(long long timestamp)
126 return (static_cast<unsigned long long>(timestamp) << BIT_FOR_TIMESTAMP_CUTTING) >> BIT_FOR_TIMESTAMP_CUTTING;
130 _SensorUtil::IsObjectDetected(float distance)
132 return _ISensorCore::IsObjectDetected(distance);
134 } } }// Tizen::Uix::Sensor