From 1b97f1d16a2b22c4c23a0c4898f26404b3760fc8 Mon Sep 17 00:00:00 2001 From: taeyoon Date: Thu, 6 Aug 2015 13:41:24 +0900 Subject: [PATCH] Replaced internal sensor api or deprecated api - Modification of adaptors/tizen/tilt-sensor-impl* by SinJae Lee - Add some modification according to latest dali Conflicts: build/tizen/adaptor/Makefile.am build/tizen/configure.ac Change-Id: Ib3c401448af337a780ebf2233a4ce597177777b4 --- adaptors/tizen/tilt-sensor-impl-tizen.cpp | 306 ++++++++++++++------- adaptors/tizen/tilt-sensor-impl.h | 61 +++- .../src/dali-adaptor-internal/CMakeLists.txt | 1 - build/tizen/adaptor-uv/Makefile.am | 4 +- build/tizen/adaptor-uv/configure.ac | 2 +- build/tizen/adaptor/Makefile.am | 2 + build/tizen/adaptor/configure.ac | 7 +- build/tizen/configure.ac | 1 + packaging/dali-adaptor.spec | 2 +- 9 files changed, 272 insertions(+), 114 deletions(-) diff --git a/adaptors/tizen/tilt-sensor-impl-tizen.cpp b/adaptors/tizen/tilt-sensor-impl-tizen.cpp index 058abf4..b21e518 100644 --- a/adaptors/tizen/tilt-sensor-impl-tizen.cpp +++ b/adaptors/tizen/tilt-sensor-impl-tizen.cpp @@ -16,14 +16,10 @@ */ // CLASS HEADER -#include "tilt-sensor-impl.h" +#include // EXTERNAL INCLUDES #include -#ifdef SENSOR_ENABLED -#include -#endif - #include #include @@ -32,20 +28,19 @@ namespace // unnamed namespace { - const char* const SIGNAL_TILTED = "tilted"; -const int NUMBER_OF_SAMPLES = 10; - -const float MAX_ACCELEROMETER_XY_VALUE = 9.8f; +const float MAX_ORIENTATION_ROLL_VALUE = 90.f; +const float MAX_ORIENTATION_PITCH_VALUE = 180.f; +const float MAX_ACCELEROMETER_VALUE = 9.8f; // Type Registration -Dali::BaseHandle GetInstance() +Dali::BaseHandle Create() { return Dali::Internal::Adaptor::TiltSensor::Get(); } -Dali::TypeRegistration typeRegistration( typeid(Dali::TiltSensor), typeid(Dali::BaseHandle), GetInstance ); +Dali::TypeRegistration typeRegistration( typeid(Dali::TiltSensor), typeid(Dali::BaseHandle), Create ); Dali::SignalConnectorType signalConnector1( typeRegistration, SIGNAL_TILTED, Dali::Internal::Adaptor::TiltSensor::DoConnectSignal ); @@ -60,6 +55,52 @@ namespace Internal namespace Adaptor { +#ifdef SENSOR_ENABLED +static void sensor_changed_cb (sensor_h sensor, sensor_event_s *event, void *user_data) +{ + TiltSensor* tiltSensor = (TiltSensor*)user_data; + + if(tiltSensor) + { + tiltSensor->Update(event); + } + + return; +} + +static std::string get_sensor_error_string(int errorValue) +{ + std::string ret; + + switch(errorValue) + { + case SENSOR_ERROR_IO_ERROR: + ret = "SENSOR_ERROR_IO_ERROR"; + break; + case SENSOR_ERROR_INVALID_PARAMETER: + ret = "SENSOR_ERROR_INVALID_PARAMETER"; + break; + case SENSOR_ERROR_NOT_SUPPORTED: + ret = "SENSOR_ERROR_NOT_SUPPORTED"; + break; + case SENSOR_ERROR_PERMISSION_DENIED: + ret = "SENSOR_ERROR_PERMISSION_DENIED"; + break; + case SENSOR_ERROR_OUT_OF_MEMORY: + ret = "SENSOR_ERROR_OUT_OF_MEMORY"; + break; + case SENSOR_ERROR_NOT_NEED_CALIBRATION: + ret = "SENSOR_ERROR_NOT_NEED_CALIBRATION"; + break; + case SENSOR_ERROR_OPERATION_FAILED: + ret = "SENSOR_ERROR_OPERATION_FAILED"; + break; + } + + return ret; +} +#endif + Dali::TiltSensor TiltSensor::New() { Dali::TiltSensor sensor = Dali::TiltSensor(new TiltSensor()); @@ -72,6 +113,7 @@ Dali::TiltSensor TiltSensor::Get() Dali::TiltSensor sensor; Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the keyboard focus manager is already created @@ -95,44 +137,151 @@ Dali::TiltSensor TiltSensor::Get() TiltSensor::~TiltSensor() { - Disable(); + Disconnect(); } -bool TiltSensor::Enable() +bool TiltSensor::Connect() { - // Make sure sensor API is responding - bool success = Update(); +#ifdef SENSOR_ENABLED + if(mState != DISCONNECTED) + { + Stop(); + Disconnect(); + } + + const int interval = 1000/mFrequencyHertz; + + int ret = 0; + bool isSupported = false; + + // try to use Orientation sensor at first for less power consumption. + ret = sensor_is_supported(SENSOR_ORIENTATION, &isSupported); + + if(ret < 0) + { + DALI_LOG_ERROR("sensor_is_supported() failed : %s\n", get_sensor_error_string(ret).c_str()); + return false; + } + + if(isSupported == true) + { + mSensorType = SENSOR_ORIENTATION; + } + else + { + DALI_LOG_ERROR("sensor does not support SENSOR_ORIENTATION\n"); + + sensor_is_supported(SENSOR_ACCELEROMETER, &isSupported); + + if(isSupported == false) + { + DALI_LOG_ERROR("sensor does not support both SENSOR_ORIENTATION and SENSOR_ACCELEROMETER\n"); + return false; + } + + mSensorType = SENSOR_ACCELEROMETER; + } + + ret = sensor_get_default_sensor(mSensorType, &mSensor); /* mSensor should not be deleted */ + + if(ret < 0) + { + DALI_LOG_ERROR("sensor_get_default_sensor() failed : %s\n", get_sensor_error_string(ret).c_str()); + return false; + } + + sensor_create_listener(mSensor, &mSensorListener); + sensor_listener_set_event_cb(mSensorListener, interval, sensor_changed_cb, this); + sensor_listener_set_interval(mSensorListener, interval); + + sensor_listener_set_option(mSensorListener, SENSOR_OPTION_DEFAULT /* Not receive data when LCD is off and in power save mode */); + + mState = CONNECTED; + + return true; +#endif + + return false; +} - if ( success ) +void TiltSensor::Disconnect() +{ + if(mSensorListener) { - if ( !mTimer ) + if(mState == STARTED) { - mTimer = Dali::Timer::New( 1000.0f / mFrequencyHertz ); - mTimer.TickSignal().Connect( mTimerSlot, &TiltSensor::Update ); + Stop(); } - if ( mTimer && - !mTimer.IsRunning() ) + if(mState == STOPPED || mState == CONNECTED) { - mTimer.Start(); +#ifdef SENSOR_ENABLED + sensor_listener_unset_event_cb(mSensorListener); + sensor_listener_stop(mSensorListener); + sensor_destroy_listener(mSensorListener); +#endif + mSensor = NULL; + mSensorListener = NULL; + mState = DISCONNECTED; } } +} - return success; +bool TiltSensor::Start() +{ + if(mSensorListener && mState == CONNECTED) + { +#ifdef SENSOR_ENABLED + int ret = 0; + ret = sensor_listener_start(mSensorListener); + if(ret != SENSOR_ERROR_NONE) + { + DALI_LOG_ERROR("sensor_listener_start() failed : %s\n", get_sensor_error_string(ret).c_str()); + Disconnect(); + return false; + } + + mState = STARTED; + return true; +#endif + } + else + { + if(mState != CONNECTED) + { + DALI_LOG_ERROR("Wrong state [%d]\n", mState); + } + return false; + } + return false; } -void TiltSensor::Disable() +void TiltSensor::Stop() { - if ( mTimer ) +#ifdef SENSOR_ENABLED + if(mSensorListener && mState == STARTED) { - mTimer.Stop(); - mTimer.Reset(); + sensor_listener_stop( mSensorListener ); + mState = STOPPED; } +#endif +} + +bool TiltSensor::Enable() +{ + // start sensor callback + return Start(); +} + +void TiltSensor::Disable() +{ + // stop sensor callback + Stop(); } bool TiltSensor::IsEnabled() const { - return ( mTimer && mTimer.IsRunning() ); + return ( mSensorListener && mState == STARTED ); } float TiltSensor::GetRoll() const @@ -163,10 +312,13 @@ void TiltSensor::SetUpdateFrequency( float frequencyHertz ) { mFrequencyHertz = frequencyHertz; - if ( mTimer ) +#ifdef SENSOR_ENABLED + if(mSensorListener) { - mTimer.SetInterval( 1000.0f / mFrequencyHertz ); + const int interval = 1000/mFrequencyHertz; + sensor_listener_set_interval(mSensorListener, interval); } +#endif } } @@ -190,7 +342,7 @@ bool TiltSensor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface bool connected( true ); TiltSensor* sensor = dynamic_cast( object ); - if( sensor && ( SIGNAL_TILTED == signalName ) ) + if( sensor && SIGNAL_TILTED == signalName ) { sensor->TiltedSignal().Connect( tracker, functor ); } @@ -204,103 +356,63 @@ bool TiltSensor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface } TiltSensor::TiltSensor() -: mFrequencyHertz( Dali::TiltSensor::DEFAULT_UPDATE_FREQUENCY ), - mTimerSlot( this ), - mSensorFrameworkHandle( -1 ), +: mState(DISCONNECTED), + mFrequencyHertz( Dali::TiltSensor::DEFAULT_UPDATE_FREQUENCY ), + mSensor( NULL ), + mSensorListener( NULL ), mRoll( 0.0f ), mPitch( 0.0f ), - mRotation( Radian( 0.0f), Vector3::YAXIS ), + mRotation( Radian(0.0f), Vector3::YAXIS ), mRotationThreshold( 0.0f ) { - mRollValues.resize( NUMBER_OF_SAMPLES, 0.0f ); - mPitchValues.resize( NUMBER_OF_SAMPLES, 0.0f ); + // connect sensor + Connect(); } -bool TiltSensor::Update() +#ifdef SENSOR_ENABLED +void TiltSensor::Update(sensor_event_s *event) { - float newRoll = 0.0f; - float newPitch = 0.0f; + Radian newRoll( 0.0f ); + Radian newPitch( 0.0f ); Quaternion newRotation; -#ifdef SENSOR_ENABLED - - // Read accelerometer data - - mSensorFrameworkHandle = sf_connect( ACCELEROMETER_SENSOR ); - if ( mSensorFrameworkHandle < 0 ) - { - DALI_LOG_ERROR( "Failed to connect to sensor framework" ); - return false; - } - - if ( sf_start(mSensorFrameworkHandle, 0) < 0 ) - { - DALI_LOG_ERROR( "Failed to start sensor" ); - sf_disconnect(mSensorFrameworkHandle); - return false; - } - - sensor_data_t* base_data_values = (sensor_data_t*)malloc(sizeof(sensor_data_t)); - int dataErr = sf_get_data(mSensorFrameworkHandle, ACCELEROMETER_BASE_DATA_SET, base_data_values); - if ( dataErr < 0 ) + if(mSensorType == SENSOR_ORIENTATION) { - DALI_LOG_ERROR( "Failed to retrieve sensor data" ); - free(base_data_values); - sf_stop(mSensorFrameworkHandle); - sf_disconnect(mSensorFrameworkHandle); - return false; + newRoll = Clamp( float(event->values[2] / MAX_ORIENTATION_ROLL_VALUE) /* -90 < roll < 90 */, -1.0f/*min*/, 1.0f/*max*/ ); + newPitch = Clamp( float(event->values[1] / MAX_ORIENTATION_PITCH_VALUE) /* -180 < pitch < 180 */, -1.0f/*min*/, 1.0f/*max*/ ); } - - sf_stop(mSensorFrameworkHandle); - sf_disconnect(mSensorFrameworkHandle); - - mRollValues.push_back( base_data_values->values[0] ); - mRollValues.pop_front(); - - mPitchValues.push_back( base_data_values->values[1] ); - mPitchValues.pop_front(); - - free(base_data_values); - base_data_values = NULL; - - float averageRoll( 0.0f ); - for ( std::deque::const_iterator iter = mRollValues.begin(); mRollValues.end() != iter; ++iter ) + else if(mSensorType == SENSOR_ACCELEROMETER) { - averageRoll += *iter; + newRoll = Clamp( float(event->values[0] / MAX_ACCELEROMETER_VALUE), -1.0f/*min*/, 1.0f/*max*/ ); + newPitch = Clamp( float(event->values[1] / MAX_ACCELEROMETER_VALUE), -1.0f/*min*/, 1.0f/*max*/ ); } - averageRoll /= mRollValues.size(); - - float averagePitch( 0.0f ); - for ( std::deque::const_iterator iter = mPitchValues.begin(); mPitchValues.end() != iter; ++iter ) + else { - averagePitch += *iter; + DALI_LOG_ERROR("Invalid sensor type"); + return; } - averagePitch /= mPitchValues.size(); - - newRoll = Clamp( float(averageRoll / MAX_ACCELEROMETER_XY_VALUE), -1.0f/*min*/, 1.0f/*max*/ ); - newPitch = Clamp( float(averagePitch / MAX_ACCELEROMETER_XY_VALUE), -1.0f/*min*/, 1.0f/*max*/ ); - newRotation = Quaternion( Radian( newRoll * Math::PI * -0.5f ), Vector3::YAXIS ) * - Quaternion( Radian( newPitch * Math::PI * -0.5f ), Vector3::XAXIS ); -#endif // SENSOR_ENABLED + newRotation = Quaternion( Radian( newRoll * Math::PI * -0.5f ), Vector3::YAXIS ) * + Quaternion( Radian( newPitch * Math::PI * -0.5f ), Vector3::XAXIS ); Radian angle(Quaternion::AngleBetween(newRotation, mRotation)); + // If the change in value is more than the threshold then emit tilted signal. - if( angle > mRotationThreshold ) + if( angle >= mRotationThreshold ) { mRoll = newRoll; mPitch = newPitch; mRotation = newRotation; + // emit signal if ( !mTiltedSignal.Empty() ) { Dali::TiltSensor handle( this ); mTiltedSignal.Emit( handle ); } } - - return true; } +#endif // SENSOR_ENABLED } // namespace Adaptor diff --git a/adaptors/tizen/tilt-sensor-impl.h b/adaptors/tizen/tilt-sensor-impl.h index 4f864ad..18b6acb 100644 --- a/adaptors/tizen/tilt-sensor-impl.h +++ b/adaptors/tizen/tilt-sensor-impl.h @@ -19,12 +19,18 @@ */ // EXTERNAL INCLUDES +#ifdef CAPI_SYSTEM_SENSOR_SUPPORT +#include + +#define SENSOR_ENABLED +#endif + #include #include // INTERNAL INCLUDES -#include -#include +#include +#include namespace Dali { @@ -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,22 @@ private: virtual ~TiltSensor(); /** - * Timer callback to update the tilt values + * Connect sensor device + */ + bool Connect(); + /** + * Disconnect sensor device */ - bool Update(); + void Disconnect(); + + /** + * Start sensor operation + */ + bool Start(); + /** + * Stop sensor operation + */ + void Stop(); // Undefined TiltSensor(const TiltSensor&); @@ -146,12 +182,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 +201,6 @@ private: Radian mRotationThreshold; - std::deque mRollValues; - std::deque mPitchValues; - TiltedSignalType mTiltedSignal; }; diff --git a/automated-tests/src/dali-adaptor-internal/CMakeLists.txt b/automated-tests/src/dali-adaptor-internal/CMakeLists.txt index 5951df1..0a5b4d2 100644 --- a/automated-tests/src/dali-adaptor-internal/CMakeLists.txt +++ b/automated-tests/src/dali-adaptor-internal/CMakeLists.txt @@ -35,7 +35,6 @@ PKG_CHECK_MODULES(${CAPI_LIB} REQUIRED dali-adaptor ecore ) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -ggdb --coverage -Wall -Werror" ) # Shouldn't have to do this! diff --git a/build/tizen/adaptor-uv/Makefile.am b/build/tizen/adaptor-uv/Makefile.am index 60bd418..b6c5d52 100644 --- a/build/tizen/adaptor-uv/Makefile.am +++ b/build/tizen/adaptor-uv/Makefile.am @@ -405,13 +405,13 @@ libdali_adaptor_uv_la_CXXFLAGS += $(CAPI_APPFW_APPLICATION_CFLAGS) \ $(CAPI_SYSTEM_SYSTEM_SETTINGS_CFLAGS) \ $(CAPI_SYSTEM_INFO_CFLAGS) \ $(TTS_CFLAGS) \ - $(SENSOR_CFLAGS) + $(CAPI_SYSTEM_SENSOR_CFLAGS) libdali_adaptor_uv_la_LIBADD += $(CAPI_APPFW_APPLICATION_LIBS) \ $(CAPI_SYSTEM_SYSTEM_SETTINGS_LIBS) \ $(CAPI_SYSTEM_INFO_LIBS) \ $(TTS_LIBS) \ - $(SENSOR_LIBS) + $(CAPI_SYSTEM_SENSOR_LIBS) endif if WAYLAND diff --git a/build/tizen/adaptor-uv/configure.ac b/build/tizen/adaptor-uv/configure.ac index 1b22417..e1919d1 100644 --- a/build/tizen/adaptor-uv/configure.ac +++ b/build/tizen/adaptor-uv/configure.ac @@ -249,13 +249,13 @@ else PKG_CHECK_MODULES(DLOG, dlog) -PKG_CHECK_MODULES(SENSOR, sensor) PKG_CHECK_MODULES(TTS, tts) PKG_CHECK_MODULES(VCONF, vconf) if test "x$enable_efl" = "xyes"; then if test "x$with_tizen_2_2_compatibility" = "xno"; then PKG_CHECK_MODULES(CAPI_SYSTEM_INFO, capi-system-info) +PKG_CHECK_MODULES(CAPI_SYSTEM_SENSOR, capi-system-sensor) fi fi diff --git a/build/tizen/adaptor/Makefile.am b/build/tizen/adaptor/Makefile.am index 9ae51dd..6bca851 100644 --- a/build/tizen/adaptor/Makefile.am +++ b/build/tizen/adaptor/Makefile.am @@ -346,6 +346,7 @@ libdali_adaptor_la_CXXFLAGS = \ $(EXIF_CFLAGS) \ $(MMFSOUND_CFLAGS) \ $(TTS_CFLAGS) \ + $(CAPI_SYSTEM_SENSOR_CFLAGS) \ $(LIBDRM_CFLAGS) \ $(LIBEXIF_CFLAGS) \ $(LIBCURL_CFLAGS) \ @@ -369,6 +370,7 @@ libdali_adaptor_la_LIBADD = \ $(VCONF_LIBS) \ $(EXIF_LIBS) \ $(TTS_LIBS) \ + $(CAPI_SYSTEM_SENSOR_LIBS) \ $(LIBDRM_LIBS) \ $(LIBEXIF_LIBS) \ $(LIBCURL_LIBS) \ diff --git a/build/tizen/adaptor/configure.ac b/build/tizen/adaptor/configure.ac index 940c6e7..7fee548 100644 --- a/build/tizen/adaptor/configure.ac +++ b/build/tizen/adaptor/configure.ac @@ -232,13 +232,18 @@ else PKG_CHECK_MODULES(DLOG, dlog) -PKG_CHECK_MODULES(SENSOR, sensor) PKG_CHECK_MODULES(TTS, tts) PKG_CHECK_MODULES(VCONF, vconf) if test "x$enable_efl" = "xyes"; then if test "x$with_tizen_2_2_compatibility" = "xno"; then PKG_CHECK_MODULES(CAPI_SYSTEM_INFO, capi-system-info) +PKG_CHECK_MODULES(CAPI_SYSTEM_SENSOR, capi-system-sensor, [ capi_system_sensor_support=yes ], [ capi_system_sensor_support=no ] ) + +if test "x$capi_system_sensor_support" = "xyes"; then + DALI_ADAPTOR_CFLAGS="$DALI_ADAPTOR_CFLAGS -DCAPI_SYSTEM_SENSOR_SUPPORT" +fi + fi fi diff --git a/build/tizen/configure.ac b/build/tizen/configure.ac index 76b59f1..a4b137e 100644 --- a/build/tizen/configure.ac +++ b/build/tizen/configure.ac @@ -36,6 +36,7 @@ if test "x$with_libuv" != "xno"; then # build dali-adaptor & dali-adaptor-uv AC_CONFIG_SUBDIRS(adaptor-uv) fi + if test "x$enable_feedback" = "xyes"; then # build dali-adaptor & dali-adaptor-uv & plugins AC_CONFIG_SUBDIRS(plugins) diff --git a/packaging/dali-adaptor.spec b/packaging/dali-adaptor.spec index c8ebe6e..71d74f8 100644 --- a/packaging/dali-adaptor.spec +++ b/packaging/dali-adaptor.spec @@ -69,7 +69,6 @@ BuildRequires: pkgconfig(glesv2) BuildRequires: pkgconfig BuildRequires: gawk -BuildRequires: pkgconfig(sensor) BuildRequires: pkgconfig(aul) BuildRequires: giflib-devel BuildRequires: pkgconfig(fontconfig) @@ -89,6 +88,7 @@ BuildRequires: fribidi-devel %if 0%{?tizen_2_2_compatibility} != 1 BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(capi-system-sensor) %endif # Tizen currently does not have libuv as a separate libuv package -- 2.7.4