sensorservices/orientationssy/src/SsyOrientation.cpp
changeset 0 4e1aa6a622a0
child 59 0f7422b6b602
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Orientation class of Orientation SSY
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // Includes
       
    20 #include <e32math.h>
       
    21 #include <sensrvchannelfinder.h>
       
    22 #include <sensrvgeneralproperties.h>
       
    23 #include <sensrvaccelerometerproperties.h>
       
    24 #include <sensordatacompensator.h>
       
    25 #include <centralrepository.h>
       
    26 #include "SsyOrientation.h"
       
    27 #include "Ssyeventtimer.h"
       
    28 #include "SsyConfiguration.h"               // configuration
       
    29 #include "SsyTrace.h"
       
    30 #include "OrientationConfiguration.h"
       
    31 
       
    32 // Constants
       
    33 
       
    34 /**
       
    35  *  Constants for degrees
       
    36  */
       
    37 const TInt K45Degrees  = 45;
       
    38 const TInt K90Degrees  = 90;
       
    39 const TInt K135Degrees = 135;
       
    40 const TInt K180Degrees = 180;
       
    41 const TInt K225Degrees = 225;
       
    42 const TInt K270Degrees = 270;
       
    43 const TInt K315Degrees = 315;
       
    44 const TInt K360Degrees = 360;
       
    45 const TReal KRad2degrees = 57.3; // accurate enough for our purposes. 180° / pi
       
    46 const TReal KVariationFactor = 0.85;
       
    47 const TInt KOneSecond = 1;
       
    48 
       
    49 #ifdef _DEBUG
       
    50 // ----------------------------------------------------------------------------------
       
    51 // TraceOrientation()
       
    52 // Helper function for tracing orientation data.
       
    53 // ----------------------------------------------------------------------------------
       
    54 //
       
    55 void TraceOrientation( const TSensrvOrientationData::TSensrvDeviceOrientation aOrientation,
       
    56                                const TInt aXRotation,
       
    57                                const TInt aYRotation,
       
    58                                const TInt aZRotation )
       
    59     {
       
    60     switch ( aOrientation )
       
    61         {
       
    62         case TSensrvOrientationData::EOrientationDisplayUp:
       
    63             SSY_TRACE( EExtended, "ORIENTATIONSSY:EOrientationDisplayUp" );
       
    64             break;
       
    65         case TSensrvOrientationData::EOrientationDisplayDown:
       
    66             SSY_TRACE( EExtended, "ORIENTATIONSSY:EOrientationDisplayDown" );
       
    67             break;
       
    68         case TSensrvOrientationData::EOrientationDisplayLeftUp:
       
    69             SSY_TRACE( EExtended, "ORIENTATIONSSY:EOrientationDisplayLeftUp" );
       
    70             break;
       
    71         case TSensrvOrientationData::EOrientationDisplayRightUp:
       
    72             SSY_TRACE( EExtended, "ORIENTATIONSSY:EOrientationDisplayRightUp" );
       
    73             break;
       
    74         case TSensrvOrientationData::EOrientationDisplayUpwards:
       
    75             SSY_TRACE( EExtended, "ORIENTATIONSSY:EOrientationDisplayUpwards" );
       
    76             break;
       
    77         case TSensrvOrientationData::EOrientationDisplayDownwards:
       
    78             SSY_TRACE( EExtended, "ORIENTATIONSSY:EOrientationDisplayDownwards" );
       
    79             break;
       
    80         default:
       
    81             SSY_TRACE( EExtended, "ORIENTATIONSSY:EOrientationUndefined" );
       
    82             break;
       
    83         }
       
    84 
       
    85     SSY_TRACE( EExtended, "ORIENTATIONSSY:aXRotation=%d", aXRotation );
       
    86     SSY_TRACE( EExtended, "ORIENTATIONSSY:aYRotation=%d", aYRotation );
       
    87     SSY_TRACE( EExtended, "ORIENTATIONSSY:aZRotation=%d", aZRotation );
       
    88     }
       
    89 #endif
       
    90 
       
    91 // ----------------------------------------------------------------------------------
       
    92 // CSSYOrientation::CSSYOrientation()
       
    93 // ----------------------------------------------------------------------------------
       
    94 // 
       
    95 CSSYOrientation::CSSYOrientation( const TSensrvChannelTypeId aChannelType ) :
       
    96     iChannelType( aChannelType ),
       
    97     iChannel( NULL ),
       
    98     iChannelFinder( NULL ),
       
    99     iSensorChannel( NULL ),
       
   100     iEventTimer( NULL ),
       
   101     iFirstDataReceived( EFalse )
       
   102     {
       
   103     SSY_TRACE_IN();
       
   104     
       
   105     iConfigForCurrentState.iOrientationState = TSensrvOrientationData::EOrientationUndefined;
       
   106      
       
   107     iTimerState = CSSYOrientation::EUninitialized;
       
   108     
       
   109     iOrientationEvent.iDeviceOrientation = 
       
   110         TSensrvOrientationData::EOrientationUndefined;
       
   111         
       
   112     iCurrentOrientationState.iDeviceOrientation = 
       
   113         TSensrvOrientationData::EOrientationUndefined;
       
   114 
       
   115     iRotationEvent.iDeviceRotationAboutZAxis = 
       
   116         TSensrvRotationData::KSensrvRotationUndefined;
       
   117 
       
   118     iRotationEvent.iDeviceRotationAboutXAxis = 
       
   119         TSensrvRotationData::KSensrvRotationUndefined;
       
   120 
       
   121     iRotationEvent.iDeviceRotationAboutYAxis = 
       
   122         TSensrvRotationData::TSensrvRotationData::KSensrvRotationUndefined;
       
   123 
       
   124     iOrientationArray.Reset();
       
   125     
       
   126     SSY_TRACE_OUT();
       
   127     }
       
   128 
       
   129 // ----------------------------------------------------------------------------------
       
   130 // CSSYOrientation::~CSSYOrientation()
       
   131 // ----------------------------------------------------------------------------------
       
   132 // 
       
   133 CSSYOrientation::~CSSYOrientation()
       
   134     {
       
   135     SSY_TRACE_IN();
       
   136     
       
   137     if( iChannelFinder )
       
   138         {
       
   139         delete iChannelFinder;
       
   140         iChannelFinder = NULL;
       
   141         }
       
   142 
       
   143     if( iEventTimer )
       
   144         {
       
   145         delete iEventTimer;
       
   146         iEventTimer = NULL;
       
   147         }
       
   148 
       
   149     if( iSensorChannel )
       
   150         {
       
   151         delete iSensorChannel;
       
   152         iSensorChannel = NULL;
       
   153         }
       
   154 #ifdef AUTO_ORIENTAION_TEST
       
   155     if( iCRListener )
       
   156         {
       
   157         delete iCRListener;
       
   158         iCRListener = NULL;
       
   159         }
       
   160 #endif
       
   161     if( iRepository )
       
   162         {
       
   163         delete iRepository;
       
   164         iRepository = NULL;
       
   165         }
       
   166 
       
   167     delete iCompensator;
       
   168 
       
   169     iChannel = NULL;
       
   170 
       
   171     iChannelInfoList.Reset();
       
   172     iOrientationArray.Reset();
       
   173     iConfigArray.Reset();
       
   174 
       
   175     iChannelInfoList.Close();
       
   176     iOrientationArray.Close();
       
   177     iConfigArray.Close();
       
   178 
       
   179     SSY_TRACE_OUT();
       
   180     }
       
   181 
       
   182 //------------------------
       
   183 //
       
   184 //
       
   185 
       
   186 void CSSYOrientation::ConstructL()
       
   187     {
       
   188     iRepository = CRepository::NewL( KCRUidOrientationSsySettings );
       
   189     CreateConfigurations();
       
   190     
       
   191 #ifdef AUTO_ORIENTAION_TEST
       
   192     iCRListener = CSsyOrientationCRListener::NewL( *this, iRepository );
       
   193 #endif
       
   194     }
       
   195 
       
   196 // ----------------------------------------------------------------------------------
       
   197 // CSSYOrientation::DataReceived()
       
   198 // ----------------------------------------------------------------------------------
       
   199 //
       
   200 #ifdef _DEBUG
       
   201 void CSSYOrientation::DataReceived( CSensrvChannel& aChannel, 
       
   202                                     TInt aCount, 
       
   203                                     TInt aDataLost )
       
   204 #else
       
   205 // aCount and aDataLost are not used in UREL builds
       
   206 void CSSYOrientation::DataReceived( CSensrvChannel& aChannel, 
       
   207                                     TInt /*aCount*/, 
       
   208                                     TInt /*aDataLost*/ )
       
   209 #endif
       
   210     {
       
   211     SSY_TRACE_IN();
       
   212 
       
   213     SSY_TRACE( EExtended, "ORIENTATIONSSY:aChannel: %d", aChannel.GetChannelInfo().iChannelId );
       
   214     SSY_TRACE( EExtended, "ORIENTATIONSSY:aCount: %d", aCount );
       
   215     SSY_TRACE( EExtended, "ORIENTATIONSSY:aDataLost: %d", aDataLost );
       
   216 
       
   217     ASSERT_DEBUG_SSY( iSensorChannel == &aChannel );
       
   218 
       
   219     
       
   220     TBool rotationChanged( EFalse );
       
   221     
       
   222 	if ( !iFirstDataReceived )
       
   223 		{
       
   224         // No need to come here anymore
       
   225         iFirstDataReceived = ETrue;
       
   226         }
       
   227     TPckgBuf<TSensrvAccelerometerAxisData> dataBuf;
       
   228     TInt err = iSensorChannel->GetData( dataBuf );
       
   229 
       
   230     if ( KErrNone != err )
       
   231         {
       
   232         SSY_TRACE( EError, "ORIENTATIONSSY: GetData() failed: %d", err );
       
   233         return;
       
   234         }
       
   235         
       
   236     if ( !iCompensator )
       
   237         {        
       
   238         TSensrvChannelInfo channelInfo = iSensorChannel->GetChannelInfo();
       
   239         TSensrvChannelDataTypeId dataTypeId( channelInfo.iChannelDataTypeId );
       
   240         TRAP( err, iCompensator = CSensorDataCompensator::NewL( dataTypeId, 
       
   241                                         ESensorCompensateDeviceOrientation ) );
       
   242         if ( err != KErrNone )
       
   243             {
       
   244             SSY_TRACE( EError, "ORIENTATIONSSY: Unable to create compensator, data won't be compensated! err: %d", err );
       
   245             }
       
   246         }
       
   247 
       
   248     if ( iCompensator )
       
   249         {
       
   250         err = iCompensator->Compensate( dataBuf );
       
   251         if ( err != KErrNone )
       
   252             {
       
   253             SSY_TRACE( EError, "ORIENTATIONSSY: Data compensation failed! err: %d", err );
       
   254             }
       
   255         }
       
   256 
       
   257     TSensrvAccelerometerAxisData data = dataBuf();
       
   258     
       
   259     TInt zenith( 0 );
       
   260     TInt azimuth( 0 );
       
   261     err = CalculateSphericalPolarCoordinates(
       
   262          data.iAxisX,
       
   263          data.iAxisY,
       
   264          data.iAxisZ,
       
   265          zenith,
       
   266          azimuth );
       
   267     
       
   268     TSensrvOrientationData::TSensrvDeviceOrientation orientation = 
       
   269             CalculateDeviceOrientation( zenith, azimuth );
       
   270     
       
   271     // positive device rotation about the x-axis
       
   272     TInt xRotation = CalculateDeviceRotationInDegrees( 
       
   273         data.iAxisZ, data.iAxisY, ERotationAboutXaxis );
       
   274     
       
   275     // positive device rotation about the y-axis
       
   276     TInt yRotation = CalculateDeviceRotationInDegrees( 
       
   277         data.iAxisZ, data.iAxisX, ERotationAboutYaxis );
       
   278     
       
   279     // positive device rotation about the z-axis
       
   280     TInt zRotation = CalculateDeviceRotationInDegrees( 
       
   281         data.iAxisX, data.iAxisY, ERotationAboutZaxis );
       
   282     
       
   283     iOrientationEvent.iTimeStamp = data.iTimeStamp;
       
   284     iCurrentOrientationState.iTimeStamp = data.iTimeStamp;
       
   285     
       
   286     // In initial state do this
       
   287     if( ( iCurrentOrientationState.iDeviceOrientation == 
       
   288           TSensrvOrientationData::EOrientationUndefined )
       
   289      && ( iChannelType == KSensrvChannelTypeIdOrientationData ) 
       
   290      && ( iTimerState != CSSYOrientation::ERunning )
       
   291      && ( err == KErrNone ) )
       
   292         {
       
   293         GetConfigurationForState( orientation, iConfigForCurrentState );
       
   294         iOrientationEvent.iDeviceOrientation = orientation;
       
   295         iCurrentOrientationState.iDeviceOrientation = orientation;
       
   296         
       
   297         
       
   298         iOrientationEvent.iTimeStamp = data.iTimeStamp;
       
   299         iCurrentOrientationState.iTimeStamp = data.iTimeStamp;
       
   300         
       
   301         iRotationEvent.iTimeStamp = data.iTimeStamp;
       
   302         
       
   303         if ( iChannel && iChannel->AppendData( iOrientationEvent, iRotationEvent ) )
       
   304             {
       
   305             SSY_TRACE( EExtended, "ORIENTATIONSSY: First time data received, set first orientation=%d", orientation );
       
   306             iChannel->IssueRequest();
       
   307             iChannel = NULL;
       
   308             }
       
   309         }
       
   310     
       
   311     // Set rotation to rotation event
       
   312     if ( iChannelType == KSensrvChannelTypeIdRotationData )
       
   313         {
       
   314         if ( iRotationEvent.iDeviceRotationAboutXAxis != xRotation )
       
   315             {
       
   316             iRotationEvent.iDeviceRotationAboutXAxis = xRotation;
       
   317             rotationChanged = ETrue;
       
   318             }
       
   319 
       
   320         if ( iRotationEvent.iDeviceRotationAboutYAxis != yRotation )
       
   321             {
       
   322             iRotationEvent.iDeviceRotationAboutYAxis = yRotation;
       
   323             rotationChanged = ETrue;
       
   324             }
       
   325 
       
   326         if ( iRotationEvent.iDeviceRotationAboutZAxis != zRotation )
       
   327             {
       
   328             iRotationEvent.iDeviceRotationAboutZAxis = zRotation;
       
   329             rotationChanged = ETrue;
       
   330             }
       
   331         }
       
   332     
       
   333     if( ( iTimerState == CSSYOrientation::ERunning ) 
       
   334      && ( orientation != TSensrvOrientationData::EOrientationUndefined ) )
       
   335         {
       
   336         if( err == KErrNone )
       
   337             {
       
   338             TRAP_IGNORE( iOrientationArray.AppendL( (TInt)orientation ) );
       
   339             }
       
   340         }
       
   341     
       
   342     if( ( orientation != iCurrentOrientationState.iDeviceOrientation )
       
   343      && ( orientation != TSensrvOrientationData::EOrientationUndefined )
       
   344      && ( iTimerState != CSSYOrientation::ERunning )
       
   345      && ( err == KErrNone ) )
       
   346         {
       
   347         TInt timer = iConfigForCurrentState.GetTimerToOrientation( orientation );
       
   348         if( timer == 0 )
       
   349             {
       
   350             /**
       
   351             * Don't set timer to zero seconds, set it rather to one
       
   352             * milliseconds.
       
   353             */
       
   354             timer = KOneSecond;
       
   355             }
       
   356         SSY_TRACE( EExtended, "ORIENTATIONSSY:Set timer to %d ms", timer );
       
   357         TRAP_IGNORE( iOrientationArray.AppendL( (TInt)orientation ) );
       
   358         if( !iEventTimer )
       
   359             {
       
   360             TRAP_IGNORE( iEventTimer = CSsyOrientationEventTimer::NewL( timer, *this ) );
       
   361             }
       
   362         iTimerState = CSSYOrientation::ERunning;
       
   363         }
       
   364     
       
   365     // append only if somebody is listening
       
   366     if ( iChannel )
       
   367         {
       
   368 #ifdef _DEBUG
       
   369         SSY_TRACE( EExtended, "ORIENTATIONSSY:data.iAxisX=%d", data.iAxisX );
       
   370         SSY_TRACE( EExtended, "ORIENTATIONSSY:data.iAxisY=%d", data.iAxisY );
       
   371         SSY_TRACE( EExtended, "ORIENTATIONSSY:data.iAxisZ=%d", data.iAxisZ );        
       
   372 
       
   373         TraceOrientation( iOrientationEvent.iDeviceOrientation, 
       
   374                           iRotationEvent.iDeviceRotationAboutXAxis, 
       
   375                           iRotationEvent.iDeviceRotationAboutYAxis, 
       
   376                           iRotationEvent.iDeviceRotationAboutZAxis );
       
   377 #endif
       
   378         // If rotation channel is listened append data to rotation channel
       
   379         if ( ( iChannelType == KSensrvChannelTypeIdRotationData ) && rotationChanged )
       
   380             {
       
   381             iOrientationEvent.iTimeStamp = data.iTimeStamp;
       
   382             iRotationEvent.iTimeStamp = data.iTimeStamp;
       
   383             if ( iChannel->AppendData( iOrientationEvent, iRotationEvent ) )
       
   384                 {
       
   385                 iChannel->IssueRequest();
       
   386                 iChannel = NULL;
       
   387                 }
       
   388             }
       
   389         }
       
   390     
       
   391     SSY_TRACE_OUT();
       
   392     }
       
   393 
       
   394 // ----------------------------------------------------------------------------------
       
   395 // CSSYOrientation::CalculateDeviceRotationInDegrees()
       
   396 // ----------------------------------------------------------------------------------
       
   397 // 
       
   398 TInt CSSYOrientation::CalculateDeviceRotationInDegrees( 
       
   399     const TInt aAxis1, 
       
   400     const TInt aAxis2,
       
   401     const TRotation aRotation )
       
   402     {
       
   403     SSY_TRACE_IN();
       
   404 
       
   405     TInt devicetilt( TSensrvRotationData::KSensrvRotationUndefined );
       
   406     
       
   407     if ( aAxis2 != 0 )
       
   408         {
       
   409         TReal alpha    = 0;
       
   410         TReal relation = (TReal)Abs(aAxis1) / (TReal)Abs(aAxis2);
       
   411 
       
   412         // calculate the angle
       
   413         Math::ATan( alpha, relation );
       
   414 
       
   415         // change radians to degrees
       
   416         alpha = alpha * KRad2degrees;
       
   417 
       
   418         switch ( aRotation )
       
   419             {
       
   420             case ERotationAboutXaxis:
       
   421                 {
       
   422                 if ( aAxis1 > 0 && aAxis2 > 0 )
       
   423                     {
       
   424                     // 0-90
       
   425                     }
       
   426                 else if ( aAxis1 > 0 && aAxis2 < 0 )
       
   427                     {
       
   428                     // 90-180
       
   429                     alpha = K90Degrees + ( K90Degrees - alpha );
       
   430                     }
       
   431                 else if ( aAxis1 < 0 && aAxis2 < 0 )
       
   432                     {
       
   433                     // 180-270
       
   434                     alpha += K180Degrees;
       
   435                     }
       
   436                 else
       
   437                     {
       
   438                     // 270-360
       
   439                     alpha = K270Degrees + ( K90Degrees - alpha );
       
   440                     }
       
   441                 break;
       
   442                 }
       
   443 // positive device rotation about the x-axis
       
   444     
       
   445             case ERotationAboutYaxis:
       
   446                 {
       
   447                 if ( aAxis1 > 0 && aAxis2 > 0 )
       
   448                     {
       
   449                     // 90-180
       
   450                     alpha += K90Degrees;
       
   451                     }
       
   452                 else if ( aAxis1 > 0 && aAxis2 < 0 )
       
   453                     {
       
   454                     // 180-270
       
   455                     alpha = K270Degrees - alpha;
       
   456                     }
       
   457                 else if ( aAxis1 < 0 && aAxis2 < 0 )
       
   458                     {
       
   459                     // 270-360
       
   460                     alpha += K270Degrees;
       
   461                     }
       
   462                 else
       
   463                     {
       
   464                     // 0-90
       
   465                     alpha = K90Degrees - alpha;
       
   466                     }
       
   467                 break;
       
   468                 }
       
   469             case ERotationAboutZaxis:
       
   470                 {
       
   471                 if ( aAxis1 > 0 && aAxis2 > 0 )
       
   472                     {
       
   473                     // 270-360
       
   474                     alpha = K360Degrees - alpha;
       
   475                     }
       
   476                 else if ( aAxis1 > 0 && aAxis2 < 0 )
       
   477                     {
       
   478                     // 180-270
       
   479                     alpha += K180Degrees;
       
   480                     }
       
   481                 else if ( aAxis1 < 0 && aAxis2 < 0 )
       
   482                     {
       
   483                     // 90-180
       
   484                     alpha = K180Degrees - alpha;
       
   485                     }
       
   486                 else
       
   487                     {
       
   488                     // 0-90
       
   489                     }
       
   490                 break;
       
   491                 }
       
   492             default:
       
   493                 {
       
   494                 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Unknown rotation!" );
       
   495                 }
       
   496             }
       
   497 
       
   498         // truncate to integer
       
   499         devicetilt = (TInt)alpha;
       
   500 
       
   501         // round the result according to KRotationResolutionInDegrees
       
   502         devicetilt += ( KRotationResolutionInDegrees >> 1 );
       
   503         devicetilt /= KRotationResolutionInDegrees;
       
   504         devicetilt *= KRotationResolutionInDegrees;
       
   505         devicetilt %= K360Degrees;
       
   506         }
       
   507   
       
   508     SSY_TRACE_OUT();
       
   509 
       
   510     return devicetilt;
       
   511     }
       
   512   
       
   513 /**
       
   514 * New implementation
       
   515 */
       
   516 // ----------------------------------------------------------------------------------
       
   517 // CSSYOrientation::CalculateDeviceOrientation()
       
   518 // ----------------------------------------------------------------------------------
       
   519 // 
       
   520 TSensrvOrientationData::TSensrvDeviceOrientation CSSYOrientation::CalculateDeviceOrientation( 
       
   521     const TInt aZenithAngle,
       
   522     const TInt aAzimuthAngle )
       
   523     {
       
   524     SSY_TRACE_IN();
       
   525 
       
   526     TSensrvOrientationData::TSensrvDeviceOrientation orientation = 
       
   527                                 TSensrvOrientationData::EOrientationUndefined;
       
   528     
       
   529     /**
       
   530     * The corrections are to different states are gotten from configurations
       
   531     */
       
   532     TInt correctionDisplayUp( iConfigForCurrentState.iOrientationDisplayUp.iAngle );
       
   533     TInt correctionDisplayDown( iConfigForCurrentState.iOrientationDisplayDown.iAngle );
       
   534     TInt correctionDisplayDownwards( iConfigForCurrentState.iOrientationDisplayDownwards.iAngle );
       
   535     TInt correctionDisplayRightUp( iConfigForCurrentState.iOrientationDisplayRightUp.iAngle );
       
   536     TInt correctionDisplayUpwards( iConfigForCurrentState.iOrientationDisplayUpwards.iAngle );
       
   537     TInt correctionDisplayLeftUp( iConfigForCurrentState.iOrientationDisplayLeftUp.iAngle );
       
   538     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation iConfigForCurrentState.iOrientationDisplayUp.iConfigForCurrentState.iOrientationDisplayUp.iAngle=%d", iConfigForCurrentState.iOrientationDisplayUp.iAngle );
       
   539     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation iConfigForCurrentState.iOrientationDisplayUp.iConfigForCurrentState.iOrientationDisplayDown.iAngle=%d", iConfigForCurrentState.iOrientationDisplayDown.iAngle );
       
   540     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation iConfigForCurrentState.iOrientationDisplayUp.iConfigForCurrentState.iOrientationDisplayDownwards.iAngle=%d", iConfigForCurrentState.iOrientationDisplayDownwards.iAngle );
       
   541     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation iConfigForCurrentState.iOrientationDisplayUp.iConfigForCurrentState.iOrientationDisplayRightUp.iAngle=%d", iConfigForCurrentState.iOrientationDisplayRightUp.iAngle );
       
   542     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation iConfigForCurrentState.iOrientationDisplayUp.iConfigForCurrentState.iOrientationDisplayUpwards.iAngle=%d", iConfigForCurrentState.iOrientationDisplayUpwards.iAngle );
       
   543     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation iConfigForCurrentState.iOrientationDisplayUp.iConfigForCurrentState.iOrientationDisplayLeftUp.iAngle=%d", iConfigForCurrentState.iOrientationDisplayLeftUp.iAngle );
       
   544     
       
   545     /**
       
   546     * The current state needs to be compenstated in some cases.
       
   547     * This is done whenever the current state is diminished from 45 degrees.
       
   548     * This compenstation is saved to the correctionFromSelectedState.
       
   549     */
       
   550 
       
   551     
       
   552     /**
       
   553     * Total correction contains the compensation from the configurations
       
   554     */
       
   555     TInt totalCorrection( K45Degrees - correctionDisplayUpwards );
       
   556     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayUpwards totalCorrection=%d", totalCorrection );
       
   557     TInt totalCorrection1( 0 );
       
   558     TInt totalCorrection2( 0 );
       
   559     TInt totalCorrection3( 0 );
       
   560     
       
   561     /**
       
   562     * If the acceleration vector points upwards the zenith is smaller than
       
   563     * 45 + correction
       
   564     */
       
   565     if( aZenithAngle < totalCorrection )
       
   566         {
       
   567         orientation = TSensrvOrientationData::EOrientationDisplayUpwards;
       
   568         SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayUpwards=%d", orientation );
       
   569         }
       
   570     
       
   571     totalCorrection = K135Degrees + correctionDisplayDownwards;
       
   572     
       
   573 
       
   574     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation aZenithAngle=%d", aZenithAngle );
       
   575     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayDownwards totalCorrection=%d", totalCorrection );
       
   576     
       
   577     /**
       
   578     * If the acceleration vector points downwards the zenith angle is bigger
       
   579     * 135 + correction.
       
   580     */
       
   581     if( aZenithAngle > totalCorrection )
       
   582         {
       
   583         orientation = TSensrvOrientationData::EOrientationDisplayDownwards;
       
   584         SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayDownwards=%d", orientation );
       
   585         }
       
   586     
       
   587     if(iCurrentOrientationState.iDeviceOrientation
       
   588         == TSensrvOrientationData::EOrientationDisplayUpwards ||
       
   589         iCurrentOrientationState.iDeviceOrientation
       
   590                 == TSensrvOrientationData::EOrientationDisplayDownwards)
       
   591         {
       
   592         totalCorrection = K45Degrees - correctionDisplayRightUp;
       
   593         SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayRightUp totalCorrection=%d", totalCorrection );
       
   594         totalCorrection1 = K135Degrees + correctionDisplayRightUp;
       
   595         SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayRightUp totalCorrection1=%d", totalCorrection1 );
       
   596         }
       
   597     else
       
   598         {
       
   599         totalCorrection = K45Degrees - correctionDisplayUpwards;
       
   600         SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayRightUp totalCorrection=%d", totalCorrection );
       
   601         totalCorrection1 = K135Degrees + correctionDisplayDownwards;
       
   602         SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayRightUp totalCorrection1=%d", totalCorrection1 );
       
   603         }
       
   604     totalCorrection2 = K45Degrees - correctionDisplayRightUp;
       
   605     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayRightUp totalCorrection2=%d", totalCorrection2 );
       
   606     totalCorrection3 = K315Degrees + correctionDisplayRightUp;
       
   607     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayRightUp totalCorrection3=%d", totalCorrection3 );
       
   608     
       
   609     /**
       
   610     * If the acceleration vector points to the midlle the zenith is between
       
   611     * 45 and 135 degrees + correction and azimuth angle is between 45 and
       
   612     * 315 degrees + correction.
       
   613     */
       
   614     if( ( aZenithAngle >= totalCorrection )
       
   615      && ( aZenithAngle <= totalCorrection1 )
       
   616      && ( ( aAzimuthAngle <= totalCorrection2 ) || ( aAzimuthAngle >= totalCorrection3 ) ) )
       
   617         {
       
   618         // Azimuth 315 - 45
       
   619         orientation = TSensrvOrientationData::EOrientationDisplayRightUp;
       
   620         SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayRightUp=%d", orientation );
       
   621         }
       
   622     
       
   623     if(iCurrentOrientationState.iDeviceOrientation
       
   624         == TSensrvOrientationData::EOrientationDisplayUpwards ||
       
   625         iCurrentOrientationState.iDeviceOrientation
       
   626                 == TSensrvOrientationData::EOrientationDisplayDownwards)
       
   627         {
       
   628         totalCorrection = K45Degrees - correctionDisplayUp;
       
   629         totalCorrection1 = K135Degrees + correctionDisplayUp;
       
   630         }
       
   631     else
       
   632         {
       
   633         totalCorrection = K45Degrees - correctionDisplayUpwards;
       
   634         totalCorrection1 = K135Degrees + correctionDisplayDownwards;
       
   635         }
       
   636     totalCorrection2 = K45Degrees - correctionDisplayUp;
       
   637     totalCorrection3 = K135Degrees + correctionDisplayUp;
       
   638     /**
       
   639     * If the acceleration vector points to the midlle the zenith is between
       
   640     * 45 and 135 degrees + correction and azimuth angle is between 45 and
       
   641     * 135 degrees + correction.
       
   642     */
       
   643     if( IsOrientation( aZenithAngle, aAzimuthAngle, totalCorrection,
       
   644         totalCorrection1, totalCorrection2, totalCorrection3 ) )
       
   645         {
       
   646         // Azimuth 45 - 135
       
   647         orientation = TSensrvOrientationData::EOrientationDisplayUp;
       
   648         SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayUp=%d", orientation );
       
   649         }
       
   650 
       
   651     if(iCurrentOrientationState.iDeviceOrientation
       
   652         == TSensrvOrientationData::EOrientationDisplayUpwards ||
       
   653         iCurrentOrientationState.iDeviceOrientation
       
   654                 == TSensrvOrientationData::EOrientationDisplayDownwards)
       
   655         {
       
   656         totalCorrection = K45Degrees + correctionDisplayLeftUp;
       
   657         totalCorrection1 = K135Degrees - correctionDisplayLeftUp;
       
   658         }
       
   659     else
       
   660         {
       
   661         totalCorrection = K45Degrees - correctionDisplayUpwards;
       
   662         totalCorrection1 = K135Degrees + correctionDisplayDownwards;
       
   663         }
       
   664     totalCorrection2 = K135Degrees + correctionDisplayLeftUp;
       
   665     totalCorrection3 = K225Degrees - correctionDisplayLeftUp;
       
   666     /**
       
   667     * If the acceleration vector points to the midlle the zenith is between
       
   668     * 135 and 225 degrees + correction and azimuth angle is between 45 and
       
   669     * 135 degrees + correction.
       
   670     */
       
   671     if( IsOrientation( aZenithAngle, aAzimuthAngle, totalCorrection,
       
   672         totalCorrection1, totalCorrection2, totalCorrection3 ) )
       
   673         {
       
   674         // Azimuth 135 - 225
       
   675         orientation = TSensrvOrientationData::EOrientationDisplayLeftUp;
       
   676         SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayLeftUp=%d", orientation );
       
   677         }
       
   678     
       
   679     totalCorrection = K45Degrees - correctionDisplayUpwards;
       
   680     totalCorrection1 = K135Degrees + correctionDisplayDownwards;
       
   681     totalCorrection2 = K225Degrees + correctionDisplayDown;
       
   682     totalCorrection3 = K315Degrees - correctionDisplayDown;
       
   683     /**
       
   684     * If the acceleration vector points to the midlle the zenith is between
       
   685     * 225 and 315 degrees + correction and azimuth angle is between 45 and
       
   686     * 135 degrees + correction.
       
   687     */
       
   688     if( IsOrientation( aZenithAngle, aAzimuthAngle, totalCorrection,
       
   689         totalCorrection1, totalCorrection2, totalCorrection3 ) )
       
   690         {
       
   691         // Azimuth 225 - 315
       
   692         orientation = TSensrvOrientationData::EOrientationDisplayDown;
       
   693         SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation EOrientationDisplayDown=%d", orientation );
       
   694         }
       
   695     
       
   696     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation orientation=%d", orientation );
       
   697     
       
   698     SSY_TRACE_OUT();
       
   699 
       
   700     return orientation;
       
   701     }
       
   702 
       
   703 TBool CSSYOrientation::IsOrientation(
       
   704     const TInt aZenithAngle,
       
   705     const TInt aAzimuthAngle,
       
   706     TInt aCorrectionToState,
       
   707     TInt aCorrectionToState1,
       
   708     TInt aCorrectionToState2,
       
   709     TInt aCorrectionToState3 )
       
   710     {
       
   711     TBool retVal( EFalse );
       
   712     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation aZenithAngle=%d", aZenithAngle );
       
   713     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation aZenithAngle=%d", aAzimuthAngle );
       
   714     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation aZenithAngle=%d", aCorrectionToState );
       
   715     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation aZenithAngle=%d", aCorrectionToState1 );
       
   716     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation aZenithAngle=%d", aCorrectionToState2 );
       
   717     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateDeviceOrientation aZenithAngle=%d", aCorrectionToState3 );
       
   718     if( ( aZenithAngle > aCorrectionToState )
       
   719      && ( aZenithAngle < aCorrectionToState1 ) 
       
   720      && ( aAzimuthAngle > aCorrectionToState2 )
       
   721      && ( aAzimuthAngle < aCorrectionToState3 ) )
       
   722         {
       
   723         retVal = ETrue;
       
   724         }
       
   725     return retVal;
       
   726     }
       
   727 
       
   728 // ----------------------------------------------------------------------------------
       
   729 // CSSYOrientation::CalculateDeviceRotationInDegrees()
       
   730 // ----------------------------------------------------------------------------------
       
   731 // 
       
   732 TInt CSSYOrientation::CalculateSphericalPolarCoordinates( 
       
   733     const TInt aAxisX, 
       
   734     const TInt aAxisY,
       
   735     const TInt aAxisZ,
       
   736     TInt& aZenithAngle,
       
   737     TInt& aAzimuthAngle )
       
   738     {
       
   739     SSY_TRACE_IN();
       
   740     TInt retVal( KErrNone );
       
   741     
       
   742     // Calculate the spherial coordinates from carthesian vector coordinates
       
   743     // First take the length of the vector formed by x and y.
       
   744     TReal srcSqrtZenith = (TReal)( ( aAxisX * aAxisX ) + ( aAxisY * aAxisY ) );
       
   745     TReal srcZenith( 0 );
       
   746     Math::Sqrt( srcZenith, srcSqrtZenith );
       
   747     TReal axisZ( aAxisZ );
       
   748     // The zenith angle is arctan( ( x and y length ) / z )
       
   749     TReal trgZenith( 0 );
       
   750     if(aAxisZ != 0)
       
   751         {
       
   752         srcZenith = ( srcZenith / axisZ );
       
   753         Math::ATan( trgZenith, srcZenith );
       
   754         }
       
   755     
       
   756     TReal trgAzimuth( 0 );
       
   757     TReal srcAzimuth( 0 );
       
   758     TReal realAxisX( aAxisX );
       
   759     TReal realAxisY( aAxisY );
       
   760     if(aAxisX != 0 && aAxisY !=0)
       
   761         {
       
   762         srcAzimuth = ( realAxisY / realAxisX );
       
   763         // The azimuth angle is arctan( y / x )
       
   764         Math::ATan( trgAzimuth, srcAzimuth );
       
   765         }
       
   766     if(aAxisY ==0 && aAxisX != 0)
       
   767         trgAzimuth = 0;
       
   768 
       
   769     TReal zenithAngle = ( trgZenith * KRad2degrees );
       
   770     
       
   771     if( zenithAngle < 0 )
       
   772         {
       
   773         // Correct the zenith angle if the result is negative
       
   774         zenithAngle = K180Degrees + zenithAngle;
       
   775         }
       
   776     
       
   777     TReal azimuthAngle = ( trgAzimuth * KRad2degrees );
       
   778     
       
   779     if( ( aAxisX > 0 ) && ( aAxisY < 0 ) )
       
   780         {
       
   781         // Azimuth is negative, so basically this is minus
       
   782         azimuthAngle = azimuthAngle + K360Degrees;
       
   783         }
       
   784     if( ( aAxisX < 0 ) && ( aAxisY > 0 ) )
       
   785         {
       
   786         // Azimuth is negative, so basically this is minus
       
   787         azimuthAngle = K180Degrees + azimuthAngle;
       
   788         }
       
   789     if( ( aAxisX < 0 ) && ( aAxisY < 0 ) )
       
   790         {
       
   791         // This is plus
       
   792         azimuthAngle = azimuthAngle + K180Degrees;
       
   793         }
       
   794         
       
   795     TReal roundedAz( 0 );
       
   796     Math::Round( roundedAz, azimuthAngle, 0 );
       
   797     TReal roundedZen( 0 );
       
   798     Math::Round( roundedZen, zenithAngle, 0 );
       
   799     
       
   800     TInt32 valiAz( 0 );
       
   801     TInt32 valiZen( 0 );
       
   802     Math::Int( valiZen, roundedZen );
       
   803     Math::Int( valiAz, roundedAz );
       
   804     aZenithAngle = (TInt)valiZen;
       
   805     aAzimuthAngle = (TInt)valiAz;
       
   806 
       
   807     if(aAxisZ == 0)
       
   808         aZenithAngle = 90;
       
   809     if(aAxisX == 0 && aAxisY == 0)
       
   810         aAzimuthAngle = 90;
       
   811     if(aAxisX == 0 && aAxisY > 0)
       
   812         aAzimuthAngle = 90;
       
   813     if(aAxisX ==0 && aAxisY < 0)
       
   814         aAzimuthAngle = 270;
       
   815 
       
   816     // Check that calculated values are in range
       
   817     if( ( aZenithAngle > K180Degrees ) 
       
   818      || ( aAzimuthAngle > K360Degrees ) 
       
   819      || ( aZenithAngle < 0 ) 
       
   820      || ( aAzimuthAngle < 0 ) )
       
   821         {
       
   822         retVal = KErrArgument;
       
   823         SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateSphericalPolarCoordinates Could not calculate because some item was null err=%d", retVal );
       
   824         }
       
   825     
       
   826     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateSphericalPolarCoordinates aAzimuthAngle=%d", aAzimuthAngle );
       
   827     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateSphericalPolarCoordinates aZenithAngle=%d", aZenithAngle );
       
   828     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateSphericalPolarCoordinates aAxisX=%d", aAxisX );
       
   829     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateSphericalPolarCoordinates aAxisY=%d", aAxisY );
       
   830     SSY_TRACE( EExtended, "ORIENTATIONSSY:CalculateSphericalPolarCoordinates aAxisZ=%d", aAxisZ );
       
   831     
       
   832     SSY_TRACE_OUT();
       
   833     
       
   834     return retVal;
       
   835     }
       
   836 
       
   837 // ----------------------------------------------------------------------------------
       
   838 // CSSYOrientation::DataError()
       
   839 // ----------------------------------------------------------------------------------
       
   840 //
       
   841 #ifdef _DEBUG
       
   842 void CSSYOrientation::DataError( CSensrvChannel& aChannel, 
       
   843                                  TSensrvErrorSeverity aError )
       
   844 #else
       
   845 // aError is not used in UREL builds
       
   846 void CSSYOrientation::DataError( CSensrvChannel& aChannel, 
       
   847                                  TSensrvErrorSeverity /*aError*/ )
       
   848 #endif
       
   849     {
       
   850     SSY_TRACE_IN();
       
   851 
       
   852     ASSERT_DEBUG_SSY( iSensorChannel == &aChannel );
       
   853 
       
   854     SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: DataError %d for channelId %d", 
       
   855                aError, 
       
   856                aChannel.GetChannelInfo().iChannelId );
       
   857 
       
   858     if ( iSensorChannel != &aChannel )
       
   859         {
       
   860         SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Wrong channel!" );
       
   861         }
       
   862 
       
   863     SSY_TRACE_OUT();
       
   864     }
       
   865 
       
   866 // ----------------------------------------------------------------------------------
       
   867 // CSSYOrientation::OpenChannelL()
       
   868 // ----------------------------------------------------------------------------------
       
   869 //
       
   870 void CSSYOrientation::OpenChannelL()
       
   871     {
       
   872     SSY_TRACE_IN();
       
   873 
       
   874     // if we are opening the channel for the first time
       
   875     if ( !iSensorChannel )
       
   876         {
       
   877         TSensrvChannelInfo channelInfo;
       
   878         channelInfo.iChannelType = KSensrvChannelTypeIdAccelerometerXYZAxisData;
       
   879 
       
   880         // create channelfinder if it does not exist already
       
   881         if ( !iChannelFinder )
       
   882             {
       
   883             iChannelFinder = CSensrvChannelFinder::NewL();
       
   884             }
       
   885 
       
   886         iChannelInfoList.Reset();
       
   887 
       
   888         // find the accelerometer axis data channel
       
   889         iChannelFinder->FindChannelsL( iChannelInfoList, channelInfo );
       
   890 
       
   891         // we must find atleast one accelerometer axis channel
       
   892         if ( !iChannelInfoList.Count() )
       
   893             {
       
   894             SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: No KSensrvChannelTypeIdAccelerometerXYZAxisData found!" );
       
   895             User::Leave( KErrNotFound );
       
   896             }
       
   897 
       
   898         // create the actual channel
       
   899         iSensorChannel = CSensrvChannel::NewL( iChannelInfoList[0] );
       
   900         }
       
   901 
       
   902     // Reset orientation values
       
   903     
       
   904     iTimerState = CSSYOrientation::EUninitialized;
       
   905     
       
   906     // open the actual channel via sensor server
       
   907     iSensorChannel->OpenChannelL();
       
   908 
       
   909     SSY_TRACE_OUT();
       
   910     }
       
   911 
       
   912 // ----------------------------------------------------------------------------------
       
   913 // CSSYOrientation::CloseChannelL()
       
   914 // ----------------------------------------------------------------------------------
       
   915 //
       
   916 void CSSYOrientation::CloseChannelL()
       
   917     {
       
   918     SSY_TRACE_IN();
       
   919 
       
   920     if( !iSensorChannel )
       
   921         {
       
   922         User::Leave( KErrNotFound );
       
   923         }
       
   924 
       
   925     iSensorChannel->CloseChannel();
       
   926     iChannel = NULL;
       
   927 
       
   928     SSY_TRACE_OUT();
       
   929     }
       
   930 
       
   931 // ----------------------------------------------------------------------------------
       
   932 // CSSYOrientation::StartListeningL()
       
   933 // ----------------------------------------------------------------------------------
       
   934 //  
       
   935 void CSSYOrientation::StartListeningL()
       
   936     {
       
   937     SSY_TRACE_IN();
       
   938 
       
   939     if ( !iSensorChannel )
       
   940         {
       
   941         User::Leave( KErrNotFound );
       
   942         }
       
   943 
       
   944     TInt desiredCount( 1 );
       
   945     TInt maximumCount( 1 );
       
   946     TInt bufferingPeriod( 0 );
       
   947 
       
   948     iSensorChannel->StartDataListeningL( this, desiredCount, maximumCount, bufferingPeriod );
       
   949 
       
   950     SSY_TRACE_OUT();
       
   951     }
       
   952 
       
   953 // ----------------------------------------------------------------------------------
       
   954 // CSSYOrientation::StopListeningL()
       
   955 // ----------------------------------------------------------------------------------
       
   956 // 
       
   957 void CSSYOrientation::StopListeningL()
       
   958     {
       
   959     SSY_TRACE_IN();
       
   960 
       
   961     if ( !iSensorChannel )
       
   962         {
       
   963         User::Leave( KErrNotFound );
       
   964         }
       
   965 
       
   966     iSensorChannel->StopDataListening();
       
   967     iChannel = NULL;
       
   968 
       
   969     SSY_TRACE_OUT();
       
   970     }
       
   971 
       
   972 // ----------------------------------------------------------------------------------
       
   973 // CSSYOrientation::GetDataFromHardware()
       
   974 // ----------------------------------------------------------------------------------
       
   975 //  
       
   976 void CSSYOrientation::GetDataFromHardware( CSSYChannel* aChannel )
       
   977     {
       
   978     SSY_TRACE_IN();
       
   979     iChannel = aChannel;
       
   980     SSY_TRACE_OUT();
       
   981     }
       
   982 
       
   983 // ----------------------------------------------------------------------------------
       
   984 // CSSYOrientation::GetMaxDataRateL()
       
   985 // ----------------------------------------------------------------------------------
       
   986 //  
       
   987 void CSSYOrientation::GetMaxDataRateL( TSensrvProperty& aProperty )
       
   988     {
       
   989     SSY_TRACE_IN();
       
   990     // Get data rate property
       
   991     TSensrvProperty property;
       
   992     iSensorChannel->GetPropertyL( KSensrvPropIdDataRate, KSensrvItemIndexNone, property );
       
   993 
       
   994     // Check is it array type of property
       
   995     if( ESensrvArrayPropertyInfo == property.GetArrayIndex() )
       
   996         {
       
   997         // Array type of property, get max property
       
   998         TInt maxValueIndex( 0 );
       
   999         property.GetMaxValue( maxValueIndex );
       
  1000         iSensorChannel->GetPropertyL( KSensrvPropIdDataRate,
       
  1001             KSensrvItemIndexNone, maxValueIndex, property );
       
  1002         }
       
  1003     else
       
  1004         {
       
  1005         // Single property, use max value as value
       
  1006         TInt maxValue( 0 );
       
  1007         property.GetMaxValue( maxValue );
       
  1008         property.SetValue( maxValue );
       
  1009         }
       
  1010 
       
  1011     // Copy max data rate to reference parameter
       
  1012     aProperty = property;
       
  1013 
       
  1014     SSY_TRACE_OUT();
       
  1015     }
       
  1016 
       
  1017 // ----------------------------------------------------------------------------------
       
  1018 // CSSYOrientation::SendDataAfterTimer()
       
  1019 // ----------------------------------------------------------------------------------
       
  1020 //
       
  1021 void CSSYOrientation::SendDataAfterTimer()
       
  1022     {
       
  1023     SSY_TRACE_IN()
       
  1024     
       
  1025     // Timer has fired no send the data to channel if it is a valid state
       
  1026     iTimerState = CSSYOrientation::EStopped;
       
  1027     // Stop and delete timer
       
  1028     if( iEventTimer )
       
  1029         {
       
  1030         delete iEventTimer;
       
  1031         iEventTimer = NULL;
       
  1032         }
       
  1033     TInt amountOfOrientations = iOrientationArray.Count() - 1;
       
  1034     
       
  1035     // If there are no orientation events don't try counting anything
       
  1036     if( amountOfOrientations >= 0 )
       
  1037         {
       
  1038         TInt lastOrientationOfArray = iOrientationArray[ amountOfOrientations ];
       
  1039         TInt sumOfCorrectOrientations( 0 );
       
  1040         
       
  1041         // Check if the state should be changed to the state of the last orientation
       
  1042         for( TInt i = 0; iOrientationArray.Count() != i; i++ )
       
  1043             {
       
  1044             SSY_TRACE( EExtended, "ORIENTATIONSSY:SendDataAfterTimer::iOrientationArray[ i ]=%d", iOrientationArray[ i ] );
       
  1045             if( iOrientationArray[ i ] == lastOrientationOfArray )
       
  1046                 {
       
  1047                 sumOfCorrectOrientations++;
       
  1048                 }
       
  1049             }
       
  1050         TReal realCountOfArray = (TReal)( iOrientationArray.Count() );
       
  1051         TReal result = (TReal)(sumOfCorrectOrientations) / realCountOfArray;
       
  1052         
       
  1053         SSY_TRACE( EExtended, "ORIENTATIONSSY:SendDataAfterTimer::result=%f", result );
       
  1054         
       
  1055         // If variance of the last orientation is in range and current orientation is a new orientation, change the state
       
  1056         if( ( result > KVariationFactor ) &&
       
  1057             ( iCurrentOrientationState.iDeviceOrientation != 
       
  1058             (TSensrvOrientationData::TSensrvDeviceOrientation)lastOrientationOfArray ) )
       
  1059             {            
       
  1060             iOrientationEvent.iDeviceOrientation = 
       
  1061             (TSensrvOrientationData::TSensrvDeviceOrientation)lastOrientationOfArray;
       
  1062             
       
  1063             SSY_TRACE( EExtended, "ORIENTATIONSSY:SendDataAfterTimer::Orientation changed to=%d", lastOrientationOfArray );
       
  1064             iCurrentOrientationState.iDeviceOrientation = 
       
  1065             (TSensrvOrientationData::TSensrvDeviceOrientation)lastOrientationOfArray;
       
  1066             
       
  1067             // Get configurations for the new state
       
  1068             GetConfigurationForState( 
       
  1069                 iCurrentOrientationState.iDeviceOrientation,
       
  1070                 iConfigForCurrentState );
       
  1071         
       
  1072             if( iChannel )
       
  1073                 {
       
  1074                 if( ( iChannelType == KSensrvChannelTypeIdOrientationData )  &&
       
  1075                     ( iChannel->AppendData( iOrientationEvent, iRotationEvent ) ) )
       
  1076                     {
       
  1077                     iChannel->IssueRequest();
       
  1078                     iChannel = NULL;
       
  1079                     }
       
  1080                 }
       
  1081             }
       
  1082         
       
  1083         iOrientationArray.Reset();
       
  1084         }
       
  1085     
       
  1086     SSY_TRACE_OUT();
       
  1087     }
       
  1088 
       
  1089 // ----------------------------------------------------------------------------------
       
  1090 // CSSYOrientation::SetConfigurationForState()
       
  1091 // ----------------------------------------------------------------------------------
       
  1092 //
       
  1093 void CSSYOrientation::SetConfigurationForState(
       
  1094  const TOrientationConfiguration& aConfigurationForState )
       
  1095     {
       
  1096     SSY_TRACE_IN();
       
  1097     TBool wasFound( EFalse );
       
  1098     // Check if is in array
       
  1099     for( TInt i = 0; i != iConfigArray.Count(); i++ )
       
  1100         {
       
  1101         TOrientationConfiguration ori = iConfigArray[ i ];
       
  1102         if( aConfigurationForState.iOrientationState == iConfigArray[ i ].iOrientationState )
       
  1103             {
       
  1104             iConfigArray.Remove( i );
       
  1105             iConfigArray.Insert( aConfigurationForState, i );
       
  1106             wasFound = ETrue;
       
  1107             }
       
  1108         }
       
  1109     if( !wasFound )
       
  1110         {
       
  1111         iConfigArray.Append( aConfigurationForState );
       
  1112         }
       
  1113     SSY_TRACE_OUT();
       
  1114     }
       
  1115 
       
  1116 // ----------------------------------------------------------------------------------
       
  1117 // CSSYOrientation::GetConfigurationForState()
       
  1118 // ----------------------------------------------------------------------------------
       
  1119 //
       
  1120 void CSSYOrientation::GetConfigurationForState( 
       
  1121  const TSensrvOrientationData::TSensrvDeviceOrientation aOrientation,
       
  1122  TOrientationConfiguration& aConfigurationForState )
       
  1123     {
       
  1124     SSY_TRACE_IN();
       
  1125     SSY_TRACE( EExtended, "ORIENTATIONSSY: First time data received, set first orientation=%d", (TInt)aOrientation );
       
  1126     // Check if is in array
       
  1127     for( TInt i = 0; i != iConfigArray.Count(); i++ )
       
  1128         {
       
  1129         TOrientationConfiguration ori = iConfigArray[ i ];
       
  1130         if( aOrientation == iConfigArray[ i ].iOrientationState )
       
  1131             {
       
  1132             aConfigurationForState = iConfigArray[ i ];
       
  1133             }
       
  1134         }
       
  1135     SSY_TRACE_OUT();
       
  1136     }
       
  1137 
       
  1138 // ----------------------------------------------------------------------------------
       
  1139 // CSSYOrientation::CreteConfigurations()
       
  1140 // ----------------------------------------------------------------------------------
       
  1141 //
       
  1142 void CSSYOrientation::CreateConfigurations()
       
  1143     {
       
  1144     SSY_TRACE_IN();
       
  1145     
       
  1146     TInt repValue( 0 );
       
  1147     
       
  1148     // This is used in initialisation
       
  1149     if( iConfigForCurrentState.iOrientationState == TSensrvOrientationData::EOrientationUndefined )
       
  1150         {
       
  1151         iConfigForCurrentState.iOrientationDisplayUp.iAngle = 0;
       
  1152         iConfigForCurrentState.iOrientationDisplayUp.iTimerValueInMilSeconds = 0;
       
  1153         iConfigForCurrentState.iOrientationDisplayDown.iAngle = 0;
       
  1154         iConfigForCurrentState.iOrientationDisplayDown.iTimerValueInMilSeconds = 0;
       
  1155         iConfigForCurrentState.iOrientationDisplayLeftUp.iAngle = 0;
       
  1156         iConfigForCurrentState.iOrientationDisplayLeftUp.iTimerValueInMilSeconds = 0;
       
  1157         iConfigForCurrentState.iOrientationDisplayRightUp.iAngle = 0;
       
  1158         iConfigForCurrentState.iOrientationDisplayRightUp.iTimerValueInMilSeconds = 0;
       
  1159         iConfigForCurrentState.iOrientationDisplayUpwards.iAngle = 0;
       
  1160         iConfigForCurrentState.iOrientationDisplayUpwards.iTimerValueInMilSeconds = 0;
       
  1161         iConfigForCurrentState.iOrientationDisplayDownwards.iAngle = 0;
       
  1162         iConfigForCurrentState.iOrientationDisplayDownwards.iTimerValueInMilSeconds = 0;
       
  1163         }
       
  1164     
       
  1165     // Configuration for display up
       
  1166     TOrientationConfiguration configForDisplayUp;
       
  1167     configForDisplayUp.iOrientationState = TSensrvOrientationData::EOrientationDisplayUp;
       
  1168     configForDisplayUp.iOrientationDisplayUp.iAngle = 0;
       
  1169     configForDisplayUp.iOrientationDisplayUp.iTimerValueInMilSeconds = 0;
       
  1170     
       
  1171     iRepository->Get( KOriStateDisplayUpToDisplayDownKey, repValue );
       
  1172     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUp.iOrientationDisplayDown=%d", repValue );
       
  1173     configForDisplayUp.iOrientationDisplayDown.iAngle = repValue;
       
  1174     
       
  1175     iRepository->Get( KOriStateDisplayUpToDisplayDownTimerKey, repValue );
       
  1176     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUp.iOrientationDisplayDowniTimerValueInMilSeconds=%d", repValue );
       
  1177     configForDisplayUp.iOrientationDisplayDown.iTimerValueInMilSeconds = repValue;
       
  1178     
       
  1179     iRepository->Get( KOriStateDisplayUpToDisplayLeftUpKey, repValue );
       
  1180     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUp.iOrientationDisplayLeftUp=%d", repValue );
       
  1181     configForDisplayUp.iOrientationDisplayLeftUp.iAngle = repValue;
       
  1182     
       
  1183     iRepository->Get( KOriStateDisplayUpToDisplayLeftUpTimerKey, repValue );
       
  1184     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUp.iOrientationDisplayLeftUpiTimerValueInMilSeconds=%d", repValue );
       
  1185     configForDisplayUp.iOrientationDisplayLeftUp.iTimerValueInMilSeconds = repValue;
       
  1186     
       
  1187     iRepository->Get( KOriStateDisplayUpToDisplayRightUpKey, repValue );
       
  1188     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUp.iOrientationDisplayRightUp=%d", repValue );
       
  1189     configForDisplayUp.iOrientationDisplayRightUp.iAngle = repValue;
       
  1190     
       
  1191     iRepository->Get( KOriStateDisplayUpToDisplayRightUpTimerKey, repValue );
       
  1192     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUp.iOrientationDisplayRightUpiTimerValueInMilSeconds=%d", repValue );
       
  1193     configForDisplayUp.iOrientationDisplayRightUp.iTimerValueInMilSeconds = repValue;
       
  1194     
       
  1195     iRepository->Get( KOriStateDisplayUpToDisplayUpwardsKey, repValue );
       
  1196     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUp.iOrientationDisplayUpwards=%d", repValue );
       
  1197     configForDisplayUp.iOrientationDisplayUpwards.iAngle = repValue;
       
  1198     
       
  1199     iRepository->Get( KOriStateDisplayUpToDisplayUpwardsTimerKey, repValue );
       
  1200     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUp.iOrientationDisplayUpwards.iTimerValueInMilSeconds=%d", repValue );
       
  1201     configForDisplayUp.iOrientationDisplayUpwards.iTimerValueInMilSeconds = repValue;
       
  1202     
       
  1203     iRepository->Get( KOriStateDisplayUpToDisplayDownwardsKey, repValue );
       
  1204     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUp.iOrientationDisplayDownwards=%d", repValue );
       
  1205     configForDisplayUp.iOrientationDisplayDownwards.iAngle = repValue;
       
  1206     
       
  1207     iRepository->Get( KOriStateDisplayUpToDisplayDownwardsTimerKey, repValue );
       
  1208     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUp.iOrientationDisplayDownwards.iTimerValueInMilSeconds=%d", repValue );
       
  1209     configForDisplayUp.iOrientationDisplayDownwards.iTimerValueInMilSeconds = repValue;
       
  1210     
       
  1211     SetConfigurationForState( configForDisplayUp );
       
  1212     
       
  1213     // Configuration for display down
       
  1214     TOrientationConfiguration configForDisplayDown;
       
  1215     configForDisplayDown.iOrientationState = TSensrvOrientationData::EOrientationDisplayDown;
       
  1216     
       
  1217     iRepository->Get( KOriStateDisplayDownToDisplayUpKey, repValue );
       
  1218     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDown.iOrientationDisplayUp=%d", repValue );
       
  1219     configForDisplayDown.iOrientationDisplayUp.iAngle = repValue;
       
  1220     
       
  1221     iRepository->Get( KOriStateDisplayDownToDisplayUpTimerKey, repValue );
       
  1222     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDown.iOrientationDisplayUp.iTimerValueInMilSeconds=%d", repValue );
       
  1223     configForDisplayDown.iOrientationDisplayUp.iTimerValueInMilSeconds = repValue;
       
  1224     
       
  1225     configForDisplayDown.iOrientationDisplayDown.iAngle = 0;
       
  1226     configForDisplayDown.iOrientationDisplayDown.iTimerValueInMilSeconds = 0;
       
  1227     
       
  1228     iRepository->Get( KOriStateDisplayDownToDisplayLeftUpKey, repValue );
       
  1229     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDown.iOrientationDisplayLeftUp=%d", repValue );
       
  1230     configForDisplayDown.iOrientationDisplayLeftUp.iAngle = repValue;
       
  1231     
       
  1232     iRepository->Get( KOriStateDisplayDownToDisplayLeftUpTimerKey, repValue );
       
  1233     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDown.iOrientationDisplayLeftUp.iTimerValueInMilSeconds=%d", repValue );
       
  1234     configForDisplayDown.iOrientationDisplayLeftUp.iTimerValueInMilSeconds = repValue;
       
  1235     
       
  1236     iRepository->Get( KOriStateDisplayDownToDisplayRightUpKey, repValue );
       
  1237     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDown.iOrientationDisplayRightUp=%d", repValue );
       
  1238     configForDisplayDown.iOrientationDisplayRightUp.iAngle = repValue;
       
  1239     
       
  1240     iRepository->Get( KOriStateDisplayDownToDisplayRightUpTimerKey, repValue );
       
  1241     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDown.iOrientationDisplayRightUp.iTimerValueInMilSeconds=%d", repValue );
       
  1242     configForDisplayDown.iOrientationDisplayRightUp.iTimerValueInMilSeconds = repValue;
       
  1243     
       
  1244     iRepository->Get( KOriStateDisplayDownToDisplayUpwardsKey, repValue );
       
  1245     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDown.iOrientationDisplayUpwards=%d", repValue );
       
  1246     configForDisplayDown.iOrientationDisplayUpwards.iAngle = repValue;
       
  1247     
       
  1248     iRepository->Get( KOriStateDisplayDownToDisplayUpwardsTimerKey, repValue );
       
  1249     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDown.iOrientationDisplayUpwards.iTimerValueInMilSeconds=%d", repValue );
       
  1250     configForDisplayDown.iOrientationDisplayUpwards.iTimerValueInMilSeconds = repValue;
       
  1251     
       
  1252     iRepository->Get( KOriStateDisplayDownToDisplayDownwardsKey, repValue );
       
  1253     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDown.iOrientationDisplayDownwards=%d", repValue );
       
  1254     configForDisplayDown.iOrientationDisplayDownwards.iAngle = repValue;
       
  1255     
       
  1256     iRepository->Get( KOriStateDisplayDownToDisplayDownwardsTimerKey, repValue );
       
  1257     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDown.iOrientationDisplayDownwards.iTimerValueInMilSeconds=%d", repValue );
       
  1258     configForDisplayDown.iOrientationDisplayDownwards.iTimerValueInMilSeconds = repValue;
       
  1259     SetConfigurationForState( configForDisplayDown );
       
  1260     
       
  1261     // Configuration for left up
       
  1262     TOrientationConfiguration configForDisplayLeftUp;
       
  1263     configForDisplayLeftUp.iOrientationState = TSensrvOrientationData::EOrientationDisplayLeftUp;
       
  1264     
       
  1265     iRepository->Get( KOriStateDisplayLeftUpToDisplayUpKey, repValue );
       
  1266     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayLeftUp.iOrientationDisplayUp=%d", repValue );
       
  1267     configForDisplayLeftUp.iOrientationDisplayUp.iAngle = repValue;
       
  1268     
       
  1269     iRepository->Get( KOriStateDisplayLeftUpToDisplayUpTimerKey, repValue );
       
  1270     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayLeftUp.iOrientationDisplayUp.iTimerValueInMilSeconds=%d", repValue );
       
  1271     configForDisplayLeftUp.iOrientationDisplayUp.iTimerValueInMilSeconds = repValue;
       
  1272     
       
  1273     iRepository->Get( KOriStateDisplayLeftUpToDisplayDownKey, repValue );
       
  1274     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayLeftUp.iOrientationDisplayDown=%d", repValue );
       
  1275     configForDisplayLeftUp.iOrientationDisplayDown.iAngle = repValue;
       
  1276     
       
  1277     iRepository->Get( KOriStateDisplayLeftUpToDisplayDownTimerKey, repValue );
       
  1278     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayLeftUp.iOrientationDisplayDown.iTimerValueInMilSeconds=%d", repValue );
       
  1279     configForDisplayLeftUp.iOrientationDisplayDown.iTimerValueInMilSeconds = repValue;
       
  1280     
       
  1281     configForDisplayLeftUp.iOrientationDisplayLeftUp.iAngle = 0;
       
  1282     configForDisplayLeftUp.iOrientationDisplayLeftUp.iTimerValueInMilSeconds = 0;
       
  1283     
       
  1284     iRepository->Get( KOriStateDisplayLeftUpToDisplayRightUpKey, repValue );
       
  1285     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayLeftUp.iOrientationDisplayRightUp=%d", repValue );
       
  1286     configForDisplayLeftUp.iOrientationDisplayRightUp.iAngle = repValue;
       
  1287     
       
  1288     iRepository->Get( KOriStateDisplayLeftUpToDisplayRightUpTimerKey, repValue );
       
  1289     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayLeftUp.iOrientationDisplayRightUp.iTimerValueInMilSeconds=%d", repValue );
       
  1290     configForDisplayLeftUp.iOrientationDisplayRightUp.iTimerValueInMilSeconds = repValue;
       
  1291     
       
  1292     iRepository->Get( KOriStateDisplayLeftUpToDisplayUpwardsKey, repValue );
       
  1293     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayLeftUp.iOrientationDisplayUpwards=%d", repValue );
       
  1294     configForDisplayLeftUp.iOrientationDisplayUpwards.iAngle = repValue;
       
  1295     
       
  1296     iRepository->Get( KOriStateDisplayLeftUpToDisplayUpwardsTimerKey, repValue );
       
  1297     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayLeftUp.iOrientationDisplayUpwards.iTimerValueInMilSeconds=%d", repValue );
       
  1298     configForDisplayLeftUp.iOrientationDisplayUpwards.iTimerValueInMilSeconds = repValue;
       
  1299     
       
  1300     iRepository->Get( KOriStateDisplayLeftUpToDisplayDownwardsKey, repValue );
       
  1301     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayLeftUp.iOrientationDisplayDownwards=%d", repValue );
       
  1302     configForDisplayLeftUp.iOrientationDisplayDownwards.iAngle = repValue;
       
  1303     
       
  1304     iRepository->Get( KOriStateDisplayLeftUpToDisplayDownwardsTimerKey, repValue );
       
  1305     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayLeftUp.iOrientationDisplayDownwards.iTimerValueInMilSeconds=%d", repValue );
       
  1306     configForDisplayLeftUp.iOrientationDisplayDownwards.iTimerValueInMilSeconds = repValue;
       
  1307     SetConfigurationForState( configForDisplayLeftUp );
       
  1308     
       
  1309     // Configuration for right up
       
  1310     TOrientationConfiguration configForDisplayRightUp;
       
  1311     configForDisplayRightUp.iOrientationState = TSensrvOrientationData::EOrientationDisplayRightUp;
       
  1312     
       
  1313     iRepository->Get( KOriStateDisplayRightUpToDisplayUpKey, repValue );
       
  1314     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayRightUp.iOrientationDisplayUp=%d", repValue );
       
  1315     configForDisplayRightUp.iOrientationDisplayUp.iAngle = repValue;
       
  1316     
       
  1317     iRepository->Get( KOriStateDisplayRightUpToDisplayUpTimerKey, repValue );
       
  1318     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayRightUp.iOrientationDisplayUp.iTimerValueInMilSeconds=%d", repValue );
       
  1319     configForDisplayRightUp.iOrientationDisplayUp.iTimerValueInMilSeconds = repValue;
       
  1320     
       
  1321     iRepository->Get( KOriStateDisplayRightUpToDisplayDownKey, repValue );
       
  1322     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayRightUp.iOrientationDisplayDown=%d", repValue );
       
  1323     configForDisplayRightUp.iOrientationDisplayDown.iAngle = repValue;
       
  1324     
       
  1325     iRepository->Get( KOriStateDisplayRightUpToDisplayDownTimerKey, repValue );
       
  1326     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayRightUp.iOrientationDisplayDown.iTimerValueInMilSeconds=%d", repValue );
       
  1327     configForDisplayRightUp.iOrientationDisplayDown.iTimerValueInMilSeconds = repValue;
       
  1328     
       
  1329     iRepository->Get( KOriStateDisplayRightUpToDisplayLeftUpKey, repValue );
       
  1330     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayRightUp.iOrientationDisplayLeftUp=%d", repValue );
       
  1331     configForDisplayRightUp.iOrientationDisplayLeftUp.iAngle = repValue;
       
  1332     
       
  1333     iRepository->Get( KOriStateDisplayRightUpToDisplayLeftUpTimerKey, repValue );
       
  1334     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayRightUp.iOrientationDisplayLeftUp.iTimerValueInMilSeconds=%d", repValue );
       
  1335     configForDisplayRightUp.iOrientationDisplayLeftUp.iTimerValueInMilSeconds = repValue;
       
  1336     
       
  1337     configForDisplayRightUp.iOrientationDisplayRightUp.iAngle = 0;
       
  1338     configForDisplayRightUp.iOrientationDisplayRightUp.iTimerValueInMilSeconds = 0;
       
  1339     
       
  1340     iRepository->Get( KOriStateDisplayRightUpToDisplayUpwardsKey, repValue );
       
  1341     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayRightUp.iOrientationDisplayUpwards=%d", repValue );
       
  1342     configForDisplayRightUp.iOrientationDisplayUpwards.iAngle = repValue;
       
  1343     
       
  1344     iRepository->Get( KOriStateDisplayRightUpToDisplayUpwardsTimerKey, repValue );
       
  1345     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayRightUp.iOrientationDisplayUpwards.iTimerValueInMilSeconds=%d", repValue );
       
  1346     configForDisplayRightUp.iOrientationDisplayUpwards.iTimerValueInMilSeconds = repValue;
       
  1347     
       
  1348     iRepository->Get( KOriStateDisplayRightUpToDisplayDownwardsKey, repValue );
       
  1349     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayRightUp.iOrientationDisplayDownwards=%d", repValue );
       
  1350     configForDisplayRightUp.iOrientationDisplayDownwards.iAngle = repValue;
       
  1351     
       
  1352     iRepository->Get( KOriStateDisplayRightUpToDisplayDownwardsTimerKey, repValue );
       
  1353     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayRightUp.iOrientationDisplayDownwards.iTimerValueInMilSeconds=%d", repValue );
       
  1354     configForDisplayRightUp.iOrientationDisplayDownwards.iTimerValueInMilSeconds = repValue;
       
  1355     SetConfigurationForState( configForDisplayRightUp );
       
  1356     
       
  1357     // Configuration for upwards
       
  1358     TOrientationConfiguration configForDisplayUpwards;
       
  1359     configForDisplayUpwards.iOrientationState = TSensrvOrientationData::EOrientationDisplayUpwards;
       
  1360     
       
  1361     iRepository->Get( KOriStateDisplayUpwardsToDisplayUpKey, repValue );
       
  1362     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUpwards.iOrientationDisplayUp=%d", repValue );
       
  1363     configForDisplayUpwards.iOrientationDisplayUp.iAngle = repValue;
       
  1364     
       
  1365     iRepository->Get( KOriStateDisplayUpwardsToDisplayUpTimerKey, repValue );
       
  1366     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUpwards.iOrientationDisplayUp.iTimerValueInMilSeconds=%d", repValue );
       
  1367     configForDisplayUpwards.iOrientationDisplayUp.iTimerValueInMilSeconds = repValue;
       
  1368     
       
  1369     iRepository->Get( KOriStateDisplayUpwardsToDisplayDownKey, repValue );
       
  1370     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUpwards.iOrientationDisplayDown=%d", repValue );
       
  1371     configForDisplayUpwards.iOrientationDisplayDown.iAngle = repValue;
       
  1372     
       
  1373     iRepository->Get( KOriStateDisplayUpwardsToDisplayDownTimerKey, repValue );
       
  1374     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUpwards.iOrientationDisplayDown.iTimerValueInMilSeconds=%d", repValue );
       
  1375     configForDisplayUpwards.iOrientationDisplayDown.iTimerValueInMilSeconds = repValue;
       
  1376     
       
  1377     iRepository->Get( KOriStateDisplayUpwardsToDisplayLeftUpKey, repValue );
       
  1378     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUpwards.iOrientationDisplayLeftUp=%d", repValue );
       
  1379     configForDisplayUpwards.iOrientationDisplayLeftUp.iAngle = repValue;
       
  1380     
       
  1381     iRepository->Get( KOriStateDisplayUpwardsToDisplayLeftUpTimerKey, repValue );
       
  1382     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUpwards.iOrientationDisplayLeftUp.iTimerValueInMilSeconds=%d", repValue );
       
  1383     configForDisplayUpwards.iOrientationDisplayLeftUp.iTimerValueInMilSeconds = repValue;
       
  1384     
       
  1385     iRepository->Get( KOriStateDisplayUpwardsToDisplayRightUpKey, repValue );
       
  1386     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUpwards.iOrientationDisplayRightUp=%d", repValue );
       
  1387     configForDisplayUpwards.iOrientationDisplayRightUp.iAngle = repValue;
       
  1388     
       
  1389     iRepository->Get( KOriStateDisplayUpwardsToDisplayRightUpTimerKey, repValue );
       
  1390     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUpwards.iOrientationDisplayRightUp.iTimerValueInMilSeconds=%d", repValue );
       
  1391     configForDisplayUpwards.iOrientationDisplayRightUp.iTimerValueInMilSeconds = repValue;
       
  1392     
       
  1393     configForDisplayUpwards.iOrientationDisplayUpwards.iAngle = 0;
       
  1394     configForDisplayUpwards.iOrientationDisplayUpwards.iTimerValueInMilSeconds = 0;
       
  1395     
       
  1396     iRepository->Get( KOriStateDisplayUpwardsToDisplayDownwardsKey, repValue );
       
  1397     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUpwards.iOrientationDisplayDownwards=%d", repValue );
       
  1398     configForDisplayUpwards.iOrientationDisplayDownwards.iAngle = repValue;
       
  1399     
       
  1400     iRepository->Get( KOriStateDisplayUpwardsToDisplayDownwardsTimerKey, repValue );
       
  1401     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayUpwards.iOrientationDisplayDownwards.iTimerValueInMilSeconds=%d", repValue );
       
  1402     configForDisplayUpwards.iOrientationDisplayDownwards.iTimerValueInMilSeconds = repValue;
       
  1403     SetConfigurationForState( configForDisplayUpwards );
       
  1404     
       
  1405     // Configuration for downwards
       
  1406     TOrientationConfiguration configForDisplayDownwards;
       
  1407     configForDisplayDownwards.iOrientationState =
       
  1408          TSensrvOrientationData::EOrientationDisplayDownwards;
       
  1409     
       
  1410     iRepository->Get( KOriStateDisplayDownwardsToDisplayUpKey, repValue );
       
  1411     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDownwards.iOrientationDisplayUp=%d", repValue );
       
  1412     configForDisplayDownwards.iOrientationDisplayUp.iAngle = repValue;
       
  1413     
       
  1414     iRepository->Get( KOriStateDisplayDownwardsToDisplayUpTimerKey, repValue );
       
  1415     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDownwards.iOrientationDisplayUp.iTimerValueInMilSeconds=%d", repValue );
       
  1416     configForDisplayDownwards.iOrientationDisplayUp.iTimerValueInMilSeconds = repValue;
       
  1417     
       
  1418     iRepository->Get( KOriStateDisplayDownwardsToDisplayDownKey, repValue );
       
  1419     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDownwards.iOrientationDisplayDown=%d", repValue );
       
  1420     configForDisplayDownwards.iOrientationDisplayDown.iAngle = repValue;
       
  1421     
       
  1422     iRepository->Get( KOriStateDisplayDownwardsToDisplayDownTimerKey, repValue );
       
  1423     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDownwards.iOrientationDisplayDown.iTimerValueInMilSeconds=%d", repValue );
       
  1424     configForDisplayDownwards.iOrientationDisplayDown.iTimerValueInMilSeconds = repValue;
       
  1425     
       
  1426     iRepository->Get( KOriStateDisplayDownwardsToDisplayLeftUpKey, repValue );
       
  1427     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDownwards.iOrientationDisplayLeftUp=%d", repValue );
       
  1428     configForDisplayDownwards.iOrientationDisplayLeftUp.iAngle = repValue;
       
  1429     
       
  1430     iRepository->Get( KOriStateDisplayDownwardsToDisplayLeftUpTimerKey, repValue );
       
  1431     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDownwards.iOrientationDisplayLeftUp.iTimerValueInMilSeconds=%d", repValue );
       
  1432     configForDisplayDownwards.iOrientationDisplayLeftUp.iTimerValueInMilSeconds = repValue;
       
  1433     
       
  1434     iRepository->Get( KOriStateDisplayDownwardsToDisplayRightUpKey, repValue );
       
  1435     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDownwards.iOrientationDisplayRightUp=%d", repValue );
       
  1436     configForDisplayDownwards.iOrientationDisplayRightUp.iAngle = repValue;
       
  1437     
       
  1438     iRepository->Get( KOriStateDisplayDownwardsToDisplayRightUpTimerKey, repValue );
       
  1439     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDownwards.iOrientationDisplayRightUp.iTimerValueInMilSeconds=%d", repValue );
       
  1440     configForDisplayDownwards.iOrientationDisplayRightUp.iTimerValueInMilSeconds = repValue;
       
  1441     
       
  1442     iRepository->Get( KOriStateDisplayDownwardsToDisplayUpwardsKey, repValue );
       
  1443     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDownwards.iOrientationDisplayUpwards=%d", repValue );
       
  1444     configForDisplayDownwards.iOrientationDisplayUpwards.iAngle = repValue;
       
  1445     
       
  1446     iRepository->Get( KOriStateDisplayDownwardsToDisplayUpwardsTimerKey, repValue );
       
  1447     SSY_TRACE( EExtended, "ORIENTATIONSSY:CreteConfigurations::EOrientationDisplayDownwards.iOrientationDisplayUpwards.iTimerValueInMilSeconds=%d", repValue );
       
  1448     configForDisplayDownwards.iOrientationDisplayUpwards.iTimerValueInMilSeconds = repValue;
       
  1449     
       
  1450     configForDisplayDownwards.iOrientationDisplayDownwards.iAngle = 0;
       
  1451     configForDisplayDownwards.iOrientationDisplayDownwards.iTimerValueInMilSeconds = 0;
       
  1452     
       
  1453     SetConfigurationForState( configForDisplayDownwards );
       
  1454     
       
  1455     if( iConfigForCurrentState.iOrientationState != TSensrvOrientationData::EOrientationUndefined )
       
  1456         {
       
  1457         GetConfigurationForState(
       
  1458         iCurrentOrientationState.iDeviceOrientation, iConfigForCurrentState );
       
  1459         }
       
  1460     
       
  1461     SSY_TRACE_OUT();
       
  1462     }
       
  1463 
       
  1464 // ----------------------------------------------------------------------------------
       
  1465 // CSSYOrientation::GetDataListenerInterfaceL()
       
  1466 // ----------------------------------------------------------------------------------
       
  1467 //
       
  1468 void CSSYOrientation::GetDataListenerInterfaceL(
       
  1469     TUid /*aInterfaceUid*/, 
       
  1470     TAny*& aInterface )
       
  1471     {
       
  1472     aInterface = NULL;
       
  1473     }
       
  1474 
       
  1475 // End of File