systemswstubs/tiltcompensationstub/src/tiltcompensation/tiltcompensation.cpp
changeset 43 e71858845f73
parent 40 b7e5ed8c1342
child 46 e1758cbb96ac
equal deleted inserted replaced
40:b7e5ed8c1342 43:e71858845f73
     1 /*
       
     2 * Copyright (c) 2007 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:  Compensate function definition.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32math.h>
       
    20 #include "tiltcompensation.h"
       
    21 
       
    22 //-----------------------------------------------------------------------------
       
    23 // Direction6D
       
    24 //-----------------------------------------------------------------------------
       
    25 //
       
    26 EXPORT_C TInt Compensate(
       
    27     const TTiltCompensationInput& aInput,
       
    28     TTiltCompensationOutput& aOutput,
       
    29      )
       
    30     {
       
    31     TReal target;
       
    32     TReal source( 0 );
       
    33     TReal inputY( aInput.iMagneticVector.iY );
       
    34     TReal inputZ( aInput.iMagneticVector.iZ );
       
    35     
       
    36     if( aInput.iMagneticVector.iY > 0 && aInput.iMagneticVector.iZ > 0 )
       
    37     // 0 - 90 degrees
       
    38         {
       
    39         source = inputY / inputZ;
       
    40         }
       
    41     if( aInput.iMagneticVector.iY > 0 && aInput.iMagneticVector.iZ < 0 )
       
    42     // 90 - 180 degrees
       
    43         {
       
    44         source = inputZ / inputY * -1;
       
    45         }
       
    46     if( aInput.iMagneticVector.iY < 0 && aInput.iMagneticVector.iZ < 0 )
       
    47     // 180 - 270 degrees
       
    48         {
       
    49         source = inputY / inputZ;
       
    50         }
       
    51     if( aInput.iMagneticVector.iY < 0 && aInput.iMagneticVector.iZ > 0 )
       
    52     // 270 - 360 degrees
       
    53         {
       
    54         source = inputZ / inputY * -1;
       
    55         }
       
    56     
       
    57     Math::ATan( target, source );
       
    58     TInt16 declination( ( target * 180 ) / 3.14 );
       
    59     
       
    60     if( aInput.iMagneticVector.iY > 0 && aInput.iMagneticVector.iZ > 0 )
       
    61     // 0 - 90 degrees
       
    62         {
       
    63         }
       
    64     if( aInput.iMagneticVector.iY > 0 && aInput.iMagneticVector.iZ < 0 )
       
    65     // 90 - 180 degrees
       
    66         {
       
    67         declination = declination + 90;
       
    68         }
       
    69     if( aInput.iMagneticVector.iY < 0 && aInput.iMagneticVector.iZ < 0 )
       
    70     // 180 - 270 degrees
       
    71         {
       
    72         declination = declination + 180;
       
    73         }
       
    74     if( aInput.iMagneticVector.iY < 0 && aInput.iMagneticVector.iZ > 0 )
       
    75     // 270 - 360 degrees
       
    76         {
       
    77         declination = declination + 270;
       
    78         }
       
    79     
       
    80     if( inputY == 0 && inputZ > 0 )
       
    81         {
       
    82         declination = 0;
       
    83         }
       
    84     if( inputY > 0 && inputZ == 0 )
       
    85         {
       
    86         declination = 90;
       
    87         }
       
    88     if( inputY == 0 && inputZ < 0 )
       
    89         {
       
    90         declination = 180;
       
    91         }
       
    92     if( inputY < 0 && inputZ == 0 )
       
    93         {
       
    94         declination = 270;
       
    95         }
       
    96     
       
    97     aOutput.iTheta = declination;
       
    98     return KErrNone;
       
    99     }
       
   100     
       
   101 //-----------------------------------------------------------------------------
       
   102 // Direction6D
       
   103 //-----------------------------------------------------------------------------
       
   104 //
       
   105 EXPORT_C TInt Compensate(
       
   106     const TTiltCompensationInput& aInput,
       
   107     TTiltCompensationOutput& aOutput,
       
   108     const RParamsArray& aParamsArray )
       
   109     {
       
   110     TReal target;
       
   111     TReal source( 0 );
       
   112     TReal inputY( aInput.iMagneticVector.iY );
       
   113     TReal inputZ( aInput.iMagneticVector.iZ );
       
   114     
       
   115     // Get parameters
       
   116     for( TInt i = 0; i != aParamsArray.Count(); i++ )
       
   117         {
       
   118         TInt parameter = aParamsArray[ i ];
       
   119         }
       
   120     
       
   121     if( aInput.iMagneticVector.iY > 0 && aInput.iMagneticVector.iZ > 0 )
       
   122     // 0 - 90 degrees
       
   123         {
       
   124         source = inputY / inputZ;
       
   125         }
       
   126     if( aInput.iMagneticVector.iY > 0 && aInput.iMagneticVector.iZ < 0 )
       
   127     // 90 - 180 degrees
       
   128         {
       
   129         source = inputZ / inputY * -1;
       
   130         }
       
   131     if( aInput.iMagneticVector.iY < 0 && aInput.iMagneticVector.iZ < 0 )
       
   132     // 180 - 270 degrees
       
   133         {
       
   134         source = inputY / inputZ;
       
   135         }
       
   136     if( aInput.iMagneticVector.iY < 0 && aInput.iMagneticVector.iZ > 0 )
       
   137     // 270 - 360 degrees
       
   138         {
       
   139         source = inputZ / inputY * -1;
       
   140         }
       
   141     
       
   142     Math::ATan( target, source );
       
   143     TInt16 declination( ( target * 180 ) / 3.14 );
       
   144     
       
   145     if( aInput.iMagneticVector.iY > 0 && aInput.iMagneticVector.iZ > 0 )
       
   146     // 0 - 90 degrees
       
   147         {
       
   148         }
       
   149     if( aInput.iMagneticVector.iY > 0 && aInput.iMagneticVector.iZ < 0 )
       
   150     // 90 - 180 degrees
       
   151         {
       
   152         declination = declination + 90;
       
   153         }
       
   154     if( aInput.iMagneticVector.iY < 0 && aInput.iMagneticVector.iZ < 0 )
       
   155     // 180 - 270 degrees
       
   156         {
       
   157         declination = declination + 180;
       
   158         }
       
   159     if( aInput.iMagneticVector.iY < 0 && aInput.iMagneticVector.iZ > 0 )
       
   160     // 270 - 360 degrees
       
   161         {
       
   162         declination = declination + 270;
       
   163         }
       
   164     
       
   165     if( inputY == 0 && inputZ > 0 )
       
   166         {
       
   167         declination = 0;
       
   168         }
       
   169     if( inputY > 0 && inputZ == 0 )
       
   170         {
       
   171         declination = 90;
       
   172         }
       
   173     if( inputY == 0 && inputZ < 0 )
       
   174         {
       
   175         declination = 180;
       
   176         }
       
   177     if( inputY < 0 && inputZ == 0 )
       
   178         {
       
   179         declination = 270;
       
   180         }
       
   181     
       
   182     aOutput.iTheta = declination;
       
   183     return KErrNone;
       
   184     }    
       
   185 
       
   186 // End of File