Merge branch 'devel/master' into tizen_4.0
[platform/core/uifw/dali-adaptor.git] / adaptors / tizen / tilt-sensor-impl.h
index 599b169..f4d81d2 100644 (file)
  */
 
 // EXTERNAL INCLUDES
+#ifdef CAPI_SYSTEM_SENSOR_SUPPORT
+#include <sensor/sensor.h>
+
+#define SENSOR_ENABLED
+#endif
+
 #include <deque>
 #include <dali/public-api/object/base-object.h>
-#include <timer.h>
 
 // INTERNAL INCLUDES
-#include <tilt-sensor.h>
+#include <public-api/adaptor-framework/timer.h>
+#include <devel-api/adaptor-framework/tilt-sensor.h>
 
 namespace Dali
 {
@@ -57,19 +63,19 @@ public:
   static Dali::TiltSensor Get();
 
   /**
-   * @copydoc Dali::TiltSensor::Enable()
+   * @copydoc Dali::TiltSensor::Start()
    */
-  bool Enable();
+  bool Start();
 
   /**
-   * @copydoc Dali::TiltSensor::Disable()
+   * @copydoc Dali::TiltSensor::Stop()
    */
-  void Disable();
+  void Stop();
 
   /**
-   * @copydoc Dali::TiltSensor::IsEnabled()
+   * @copydoc Dali::TiltSensor::IsStarted()
    */
-  bool IsEnabled() const;
+  bool IsStarted() const;
 
   /**
    * @copydoc Dali::TiltSensor::GetRoll()
@@ -122,8 +128,25 @@ public:
    */
   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
 
+  /**
+   * Update sensor data
+   * @note This is called by static sensor callback function
+   * @param[in] event sensor event data
+   */
+#ifdef SENSOR_ENABLED
+  void Update(sensor_event_s *event);
+#endif
+
 private:
 
+  enum State
+  {
+    DISCONNECTED,
+    CONNECTED,
+    STARTED,
+    STOPPED
+  };
+
   /**
    * Private constructor; see also TiltSensor::New()
    */
@@ -135,9 +158,13 @@ private:
   virtual ~TiltSensor();
 
   /**
-   * Timer callback to update the tilt values
+   * Connect sensor device
+   */
+  bool Connect();
+  /**
+   * Disconnect sensor device
    */
-  bool Update();
+  void Disconnect();
 
   // Undefined
   TiltSensor(const TiltSensor&);
@@ -146,12 +173,18 @@ private:
   TiltSensor& operator=(TiltSensor&);
 
 private:
-
+  State mState;
   float mFrequencyHertz;
-  Dali::Timer mTimer;
-  SlotDelegate< TiltSensor > mTimerSlot;
 
-  int mSensorFrameworkHandle;
+#ifdef SENSOR_ENABLED
+  sensor_type_e mSensorType;
+  sensor_h mSensor;
+  sensor_listener_h mSensorListener;
+#else
+  int mSensorType;
+  int* mSensor;
+  int* mSensorListener;
+#endif
 
   float mRoll;
   float mPitch;
@@ -159,9 +192,6 @@ private:
 
   Radian mRotationThreshold;
 
-  std::deque<float> mRollValues;
-  std::deque<float> mPitchValues;
-
   TiltedSignalType mTiltedSignal;
 };