68519089d625cc1bf5a374ac56d4d510231bd17f
[platform/core/uifw/dali-adaptor.git] / adaptors / ubuntu / tilt-sensor-impl.h
1 #ifndef __DALI_INTERNAL_ADAPTOR_TILT_SENSOR_H__
2 #define __DALI_INTERNAL_ADAPTOR_TILT_SENSOR_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 <tilt-sensor.h>
27 #include <timer.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace Adaptor
36 {
37
38 /**
39  * TiltSensor provides pitch & roll values when the device is tilted.
40  */
41 class TiltSensor : public Dali::BaseObject
42 {
43 public:
44
45   typedef Dali::TiltSensor::TiltedSignalType TiltedSignalType;
46
47   /**
48    * Create a TiltSensor.
49    * This should only be called once by the Adaptor class.
50    * @return A newly allocated tilt-sensor.
51    */
52   static Dali::TiltSensor New();
53
54   /**
55    * @copydoc Dali::TiltSensor::Get()
56    */
57   static Dali::TiltSensor Get();
58
59   /**
60    * @copydoc Dali::TiltSensor::Start()
61    */
62   bool Start();
63
64   /**
65    * @copydoc Dali::TiltSensor::Stop()
66    */
67   void Stop();
68
69   /**
70    * @copydoc Dali::TiltSensor::IsStarted()
71    */
72   bool IsStarted() const;
73
74   /**
75    * @copydoc Dali::TiltSensor::GetRoll()
76    */
77   float GetRoll() const;
78
79   /**
80    * @copydoc Dali::TiltSensor::GetPitch()
81    */
82   float GetPitch() const;
83
84   /**
85    * @copydoc Dali::TiltSensor::GetRotation()
86    */
87   Quaternion GetRotation() const;
88
89   /**
90    * @copydoc Dali::TiltSensor::TiltedSignal()
91    */
92   TiltedSignalType& TiltedSignal();
93
94   /**
95    * @copydoc Dali::TiltSensor::SetUpdateFrequency()
96    */
97   void SetUpdateFrequency( float frequencyHertz );
98
99   /**
100    * @copydoc Dali::TiltSensor::GetUpdateFrequency()
101    */
102   float GetUpdateFrequency() const;
103
104   /**
105    * @copydoc Dali::TiltSensor::SetRotationThreshold()
106    */
107   void SetRotationThreshold(Radian rotationThreshold);
108
109   /**
110    * @copydoc Dali::TiltSensor::GetRotationThreshold()
111    */
112   Radian GetRotationThreshold() const;
113
114   /**
115    * Connects a callback function with the object's signals.
116    * @param[in] object The object providing the signal.
117    * @param[in] tracker Used to disconnect the signal.
118    * @param[in] signalName The signal to connect to.
119    * @param[in] functor A newly allocated FunctorDelegate.
120    * @return True if the signal was connected.
121    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
122    */
123   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
124
125 private:
126
127   /**
128    * Private constructor; see also TiltSensor::New()
129    */
130   TiltSensor();
131
132   /**
133    * Destructor
134    */
135   virtual ~TiltSensor();
136
137   /**
138    * Timer callback to update the tilt values
139    */
140   bool Update();
141
142   // Undefined
143   TiltSensor(const TiltSensor&);
144
145   // Undefined
146   TiltSensor& operator=(TiltSensor&);
147
148 private:
149
150   float mFrequencyHertz;
151   Dali::Timer mTimer;
152   SlotDelegate< TiltSensor > mTimerSlot;
153
154   int mSensorFrameworkHandle;
155
156   float mRoll;
157   float mPitch;
158   Quaternion mRotation;
159
160   Radian mRotationThreshold;
161
162   std::deque<float> mRollValues;
163   std::deque<float> mPitchValues;
164
165   TiltedSignalType mTiltedSignal;
166 };
167
168 } // namespace Adaptor
169
170 } // namespace Internal
171
172 // Helpers for public-api forwarding methods
173
174 inline Internal::Adaptor::TiltSensor& GetImplementation(Dali::TiltSensor& sensor)
175 {
176   DALI_ASSERT_ALWAYS( sensor && "TiltSensor handle is empty" );
177
178   BaseObject& handle = sensor.GetBaseObject();
179
180   return static_cast<Internal::Adaptor::TiltSensor&>(handle);
181 }
182
183 inline const Internal::Adaptor::TiltSensor& GetImplementation(const Dali::TiltSensor& sensor)
184 {
185   DALI_ASSERT_ALWAYS( sensor && "TiltSensor handle is empty" );
186
187   const BaseObject& handle = sensor.GetBaseObject();
188
189   return static_cast<const Internal::Adaptor::TiltSensor&>(handle);
190 }
191
192 } // namespace Dali
193
194 #endif // __DALI_INTERNAL_ADAPTOR_TILT_SENSOR_H__