Purge underscored header file barriers
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / tilt-sensor.h
1 #ifndef DALI_TILT_SENSOR_H
2 #define DALI_TILT_SENSOR_H
3
4 /*
5  * Copyright (c) 2019 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 <dali/public-api/object/base-handle.h>
23 #include <dali/public-api/signals/dali-signal.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/dali-adaptor-common.h>
27
28 namespace Dali
29 {
30
31 namespace Internal DALI_INTERNAL
32 {
33 namespace Adaptor
34 {
35 class TiltSensor;
36 }
37 }
38
39 /**
40  * TiltSensor provides pitch & roll values when the device is tilted.
41  * The basic usage is shown below:
42  *
43  * @code
44  *
45  *  void Example()
46  *  {
47  *    TiltSensor sensor = TiltSensor::Get();
48  *
49  *    // Try to start the tilt sensor
50  *    if ( sensor.Start() )
51  *    {
52  *      // Query the current values
53  *      std::cout << "Roll = " << sensor.GetRoll() << ", Pitch = " << sensor.GetPitch() << std::endl;
54  *
55  *      // Get notifications when the device is tilted
56  *      sensor.TiltedSignal().Connect( &OnTilted );
57  *    }
58  *  }
59  *
60  *  void OnTilted( const TiltSensor& sensor )
61  *  {
62  *    // Query the new values
63  *    std::cout << "Roll = " << sensor.GetRoll() << ", Pitch = " << sensor.GetPitch() << std::endl;
64  *  }
65  *
66  * @endcode
67  *
68  * While the tilt sensor is started, it will periodically poll for the latest pitch & roll values.
69  * For performance & power-saving, applications should disable this polling when no longer needed:
70  *
71  * @code
72  *
73  *  void EndExample()
74  *  {
75  *    // Stop the sensor when no longer needed
76  *    TiltSensor::Get().Stop();
77  *  }
78  *
79  * @endcode
80  */
81 class DALI_ADAPTOR_API TiltSensor : public BaseHandle
82 {
83 public:
84
85   typedef Signal< void (const TiltSensor&) > TiltedSignalType;
86
87   static const float DEFAULT_UPDATE_FREQUENCY; // 60 hertz
88
89   /**
90    * Create an uninitialized handle.
91    * This can be initialized by calling TiltSensor::Get().
92    */
93   TiltSensor();
94
95   /**
96    * Create an initialized handle to the TiltSensor.
97    * @return A handle to a newly allocated Dali resource.
98    */
99   static TiltSensor Get();
100
101   /**
102    * @brief Destructor
103    *
104    * This is non-virtual since derived Handle types must not contain data or virtual methods.
105    */
106   ~TiltSensor();
107
108   /**
109    * Attempt to start the tilt-sensor. This will fail if the underlying sensor hardware is powered-down,
110    * typically this occurs when the device is set to "sleep" mode.
111    * @return True if the tilt-sensor is started.
112    */
113   bool Start();
114
115   /**
116    * Stop the tilt-sensor.
117    */
118   void Stop();
119
120   /**
121    * Query whether the tilt-sensor is started.
122    * The sensor may be disabled automatically; typically this occurs when the device is set to "sleep" mode.
123    * @return True if the tilt-sensor is started.
124    */
125   bool IsStarted() const;
126
127   /**
128    * Query the roll value. This is in the range -1 to 1.
129    * When the device is lying face-up on a flat surface, this method will return a value close to zero.
130    * A value close to 1 indicates that the right-side of the device is pointing upwards.
131    * A value close to -1 indicates that the right-side of the device is pointing downwards.
132    * @pre The tilt-sensor is started.
133    * @return The roll value.
134    */
135   float GetRoll() const;
136
137   /**
138    * Query the pitch value. This is in the range -1 to 1.
139    * When the device is lying face-up on a flat surface, this method will return a value close to zero.
140    * A value close to 1 indicates that the top of the device is pointing upwards.
141    * A value close to -1 indicates that the top of the device is pointing downwards.
142    * @pre The tilt-sensor is started.
143    * @return The pitch value.
144    */
145   float GetPitch() const;
146
147   /**
148    * Retrieve the rotation of the device.
149    * When the device is lying face-up on a flat surface, the rotation angle will be approximately zero.
150    * The roll & pitch of the device is considered to be a rotation around the Y and X axes respectively.
151    * @pre The tilt-sensor is started.
152    * @return The rotation in quaternion format.
153    */
154   Quaternion GetRotation() const;
155
156   /**
157    * This signal will be emitted when the device is tilted, if the tilt-sensor is started.
158    * The frequency of the signals can be controlled using SetUpdateFrequency().
159    * @return The signal to connect to.
160    *
161    * @note The signal name is "tilted" if using BaseHandle::ConnectSignal()
162    */
163   TiltedSignalType& TiltedSignal();
164
165   /**
166    * Set the sensor update frequency.
167    * The default is TiltSensor::DEFAULT_UPDATE_FREQUENCY.
168    * @param[in] frequencyHertz The frequency in hertz.
169    */
170   void SetUpdateFrequency( float frequencyHertz );
171
172   /**
173    * Query the sensor update frequency.
174    * @return The frequency in hertz.
175    */
176   float GetUpdateFrequency() const;
177
178   /**
179    * Set the threshold value for rotation in Radians, above which TiltedSignal should be emitted.
180    * The default is 0.0f in Radians (i.e) it will be emitted always at the frequency set.
181    * Example tiltSensor.SetRotationThreshold( Radian(Degree(10) ) // A rotation threshold of 10 degrees
182    * @param[in] rotationThreshold The threshold value for rotation.
183    */
184   void SetRotationThreshold( Radian rotationThreshold );
185
186   /**
187    * Query the rotation threshold above which TiltedSignal will be emitted.
188    * @return The rotation degree threshold in Radians.
189    */
190   Radian GetRotationThreshold() const;
191
192 public: // Not intended for application developers
193
194   /**
195    * This constructor is used by TiltSensor::Get().
196    * @param[in] sensor A pointer to the tilt sensor.
197    */
198   explicit DALI_INTERNAL TiltSensor( Internal::Adaptor::TiltSensor* sensor );
199 };
200
201 } // namespace Dali
202
203 #endif // DALI_TILT_SENSOR_H