Initial copy from dali-adaptor repository
[platform/core/uifw/dali-adaptor-legacy.git] / dali / internal / sensor / ubuntu / tilt-sensor-impl-ubuntu.h
1 #ifndef DALI_SENSOR_UBUNTU_TILT_SENSOR_IMPL_UBUNTU_H
2 #define DALI_SENSOR_UBUNTU_TILT_SENSOR_IMPL_UBUNTU_H
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <deque>
23 #include <dali/public-api/object/base-object.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/internal/sensor/common/tilt-sensor-impl.h>
27 #include <dali/devel-api/adaptor-framework/tilt-sensor.h>
28 #include <dali/public-api/adaptor-framework/timer.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace Adaptor
37 {
38
39 /**
40  * TiltSensor provides pitch & roll values when the device is tilted.
41  */
42 class TiltSensorUbuntu : public Dali::Internal::Adaptor::TiltSensor
43 {
44 public:
45
46   typedef Dali::TiltSensor::TiltedSignalType TiltedSignalType;
47
48   /**
49  * Public constructor
50  * @return New instance of TiltSensorUbuntu
51  */
52   static TiltSensorUbuntu* New();
53
54   /**
55    * @copydoc Dali::TiltSensor::Start()
56    */
57   bool Start() override;
58
59   /**
60    * @copydoc Dali::TiltSensor::Stop()
61    */
62   void Stop() override;
63
64   /**
65    * @copydoc Dali::TiltSensor::IsStarted()
66    */
67   bool IsStarted() const override;
68
69   /**
70    * @copydoc Dali::TiltSensor::GetRoll()
71    */
72   float GetRoll() const override;
73
74   /**
75    * @copydoc Dali::TiltSensor::GetPitch()
76    */
77   float GetPitch() const override;
78
79   /**
80    * @copydoc Dali::TiltSensor::GetRotation()
81    */
82   Quaternion GetRotation() const override;
83
84   /**
85    * @copydoc Dali::TiltSensor::TiltedSignal()
86    */
87   TiltedSignalType& TiltedSignal() override;
88
89   /**
90    * @copydoc Dali::TiltSensor::SetUpdateFrequency()
91    */
92   void SetUpdateFrequency( float frequencyHertz ) override;
93
94   /**
95    * @copydoc Dali::TiltSensor::GetUpdateFrequency()
96    */
97   float GetUpdateFrequency() const override;
98
99   /**
100    * @copydoc Dali::TiltSensor::SetRotationThreshold()
101    */
102   void SetRotationThreshold(Radian rotationThreshold) override;
103
104   /**
105    * @copydoc Dali::TiltSensor::GetRotationThreshold()
106    */
107   Radian GetRotationThreshold() const override;
108
109   /**
110    * Connects a callback function with the object's signals.
111    * @param[in] object The object providing the signal.
112    * @param[in] tracker Used to disconnect the signal.
113    * @param[in] signalName The signal to connect to.
114    * @param[in] functor A newly allocated FunctorDelegate.
115    * @return True if the signal was connected.
116    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
117    */
118   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
119
120 private:
121
122   /**
123  * Private constructor; see also TiltSensor::New()
124  */
125   TiltSensorUbuntu();
126
127   /**
128    * Destructor
129    */
130   virtual ~TiltSensorUbuntu() override;
131
132   /**
133    * Timer callback to update the tilt values
134    */
135   bool Update();
136
137   // Undefined
138   TiltSensorUbuntu(const TiltSensorUbuntu&) = delete;
139
140   // Undefined
141   TiltSensorUbuntu& operator=(TiltSensorUbuntu&) = delete;
142
143 private:
144
145   float mFrequencyHertz;
146   Dali::Timer mTimer;
147   SlotDelegate< TiltSensorUbuntu > mTimerSlot;
148
149   int mSensorFrameworkHandle;
150
151   float mRoll;
152   float mPitch;
153   Quaternion mRotation;
154
155   Radian mRotationThreshold;
156
157   std::deque<float> mRollValues;
158   std::deque<float> mPitchValues;
159
160   TiltedSignalType mTiltedSignal;
161 };
162
163 } // namespace Adaptor
164
165 } // namespace Internal
166
167 } // namespace Dali
168
169 #endif // DALI_SENSOR_UBUNTU_TILT_SENSOR_IMPL_UBUNTU_H