1 #ifndef __DALI_TILT_SENSOR_H__
2 #define __DALI_TILT_SENSOR_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <boost/function.hpp>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/signals/dali-signal-v2.h>
27 namespace Dali DALI_IMPORT_API
30 namespace Internal DALI_INTERNAL
39 * TiltSensor provides pitch & roll values when the device is tilted.
40 * The basic usage is shown below:
46 * TiltSensor sensor = TiltSensor::Get();
48 * // Try to enable the sensor
49 * if ( sensor.Enable() )
51 * // Query the current values
52 * std::cout << "Roll = " << sensor.GetRoll() << ", Pitch = " << sensor.GetPitch() << std::endl;
54 * // Get notifications when the device is tilted
55 * sensor.SignalTilted().Connect( &OnTilted );
61 * // Query the new values
62 * std::cout << "Roll = " << sensor.GetRoll() << ", Pitch = " << sensor.GetPitch() << std::endl;
67 * While the tilt sensor is enabled, it will periodically poll for the latest pitch & roll values.
68 * For performance & power-saving, applications should disable this polling when no longer needed:
74 * // Disable the sensor when no longer needed
75 * TiltSensor::Get().Disable();
80 class TiltSensor : public BaseHandle
84 typedef SignalV2< void (const TiltSensor&) > TiltedSignalV2;
87 static const char* const SIGNAL_TILTED;
89 static const float DEFAULT_UPDATE_FREQUENCY; // 60 hertz
92 * Create an uninitialized handle.
93 * This can be initialized by calling TiltSensor::Get().
98 * Create an initialized handle to the TiltSensor.
99 * @return A handle to a newly allocated Dali resource.
101 static TiltSensor Get();
106 * This is non-virtual since derived Handle types must not contain data or virtual methods.
111 * Attempt to enable the tilt-sensor. This will fail if the underlying sensor hardware is powered-down,
112 * typically this occurs when the device is set to "sleep" mode.
113 * @return True if the tilt-sensor is enabled.
118 * Disable the tilt-sensor.
123 * Query whether the tilt-sensor is disabled.
124 * The sensor may be disabled automatically; typically this occurs when the device is set to "sleep" mode.
125 * @return True if the tilt-sensor is enabled.
127 bool IsEnabled() const;
130 * Query the roll value. This is in the range -1 to 1.
131 * When the device is lying face-up on a flat surface, this method will return a value close to zero.
132 * A value close to 1 indicates that the right-side of the device is pointing upwards.
133 * A value close to -1 indicates that the right-side of the device is pointing downwards.
134 * @pre The tilt-sensor is enabled.
135 * @return The roll value.
137 float GetRoll() const;
140 * Query the pitch value. This is in the range -1 to 1.
141 * When the device is lying face-up on a flat surface, this method will return a value close to zero.
142 * A value close to 1 indicates that the top of the device is pointing upwards.
143 * A value close to -1 indicates that the top of the device is pointing downwards.
144 * @pre The tilt-sensor is enabled.
145 * @return The pitch value.
147 float GetPitch() const;
150 * Retrieve the rotation of the device.
151 * When the device is lying face-up on a flat surface, the rotation angle will be approximately zero.
152 * The roll & pitch of the device is considered to be a rotation around the Y and X axes respectively.
153 * @pre The tilt-sensor is enabled.
154 * @return The rotation in quaternion format.
156 Quaternion GetRotation() const;
159 * This signal will be emitted when the device is tilted, if the tilt-sensor is enabled.
160 * The frequency of the signals can be controlled using SetUpdateFrequency().
161 * @return The signal to connect to.
163 TiltedSignalV2& TiltedSignal();
166 * Set the sensor update frequency.
167 * The default is TiltSensor::DEFAULT_UPDATE_FREQUENCY.
168 * @param[in] frequencyHertz The frequency in hertz.
170 void SetUpdateFrequency( float frequencyHertz );
173 * Query the sensor update frequency.
174 * @return The frequency in hertz.
176 float GetUpdateFrequency() const;
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.
184 void SetRotationThreshold( Radian rotationThreshold );
187 * Query the rotation threshold above which TiltedSignal will be emitted.
188 * @return The rotation degree threshold in Radians.
190 Radian GetRotationThreshold() const;
192 public: // Not intended for application developers
195 * This constructor is used by TiltSensor::Get().
196 * @param[in] sensor A pointer to the tilt sensor.
198 TiltSensor( Internal::Adaptor::TiltSensor* sensor );
203 #endif // __DALI_TILT_SENSOR_H__