qtmobility/plugins/sensors/symbian/accelerometersym.cpp
changeset 5 453da2cfceef
parent 4 90517678cc4f
child 11 06b8e2af4411
equal deleted inserted replaced
4:90517678cc4f 5:453da2cfceef
    39  **
    39  **
    40  ****************************************************************************/
    40  ****************************************************************************/
    41 
    41 
    42 // Internal Headers
    42 // Internal Headers
    43 #include "accelerometersym.h"
    43 #include "accelerometersym.h"
       
    44 #include <sensrvgeneralproperties.h>
       
    45 
       
    46 #define GRAVITATION_CONSTANT 9.812865328        //According to wikipedia link http://en.wikipedia.org/wiki/Standard_gravity
    44 
    47 
    45 /**
    48 /**
    46  * set the id of the accelerometer sensor
    49  * set the id of the accelerometer sensor
    47  */
    50  */
    48 const char *CAccelerometerSensorSym::id("sym.accelerometer");
    51 const char *CAccelerometerSensorSym::id("sym.accelerometer");
    71     }
    74     }
    72 
    75 
    73 /**
    76 /**
    74  * Default constructor
    77  * Default constructor
    75  */
    78  */
    76 CAccelerometerSensorSym::CAccelerometerSensorSym(QSensor *sensor):CSensorBackendSym(sensor)
    79 CAccelerometerSensorSym::CAccelerometerSensorSym(QSensor *sensor):CSensorBackendSym(sensor),
       
    80         iScale(0),
       
    81         iUnit(0)
    77         {
    82         {
    78         setReading<QAccelerometerReading>(&iReading);
    83         setReading<QAccelerometerReading>(&iReading);
    79         iBackendData.iSensorType = KSensrvChannelTypeIdAccelerometerXYZAxisData;    
    84         iBackendData.iSensorType = KSensrvChannelTypeIdAccelerometerXYZAxisData;    
    80         //Disable property listening
    85         //Disable property listening
    81         SetListening(ETrue, EFalse);
    86         SetListening(ETrue, EFalse);
    93     if(KErrNone != ret)
    98     if(KErrNone != ret)
    94         {
    99         {
    95         // If there is no reading available, return without setting
   100         // If there is no reading available, return without setting
    96         return;
   101         return;
    97         }
   102         }
       
   103     TReal x = iData.iAxisX;
       
   104     TReal y = iData.iAxisY;
       
   105     TReal z = iData.iAxisZ;
       
   106     //Converting unit to m/s^2
       
   107     qoutputrangelist rangeList = sensor()->outputRanges();
       
   108     TReal maxValue = rangeList[sensor()->outputRange()].maximum;
       
   109     if(iScale && iUnit == ESensevChannelUnitAcceleration)
       
   110         {
       
   111         x = (x/iScale) * maxValue;
       
   112         y = (y/iScale) * maxValue;
       
   113         z = (z/iScale) * maxValue;
       
   114         }
       
   115     else if(iUnit == ESensrvChannelUnitGravityConstant)
       
   116         {
       
   117         //conversion is yet to done
       
   118         }
    98     // Get a lock on the reading data
   119     // Get a lock on the reading data
    99     iBackendData.iReadingLock.Wait();
   120     iBackendData.iReadingLock.Wait();
   100     // Set qt mobility accelerometer reading with data from sensor server
   121     // Set qt mobility accelerometer reading with data from sensor server
   101     iReading.setX(iData.iAxisX);
   122     iReading.setX(x);
   102     iReading.setY(iData.iAxisY);
   123     iReading.setY(y);
   103     iReading.setZ(iData.iAxisZ);
   124     iReading.setZ(z);
   104     // Set the timestamp
   125     // Set the timestamp
   105     iReading.setTimestamp(iData.iTimeStamp.Int64());
   126     iReading.setTimestamp(iData.iTimeStamp.Int64());
   106     // Release the lock
   127     // Release the lock
   107     iBackendData.iReadingLock.Signal();
   128     iBackendData.iReadingLock.Signal();
   108     }
   129     }
   112  * Initialize the backend resources
   133  * Initialize the backend resources
   113  */
   134  */
   114 void CAccelerometerSensorSym::ConstructL()
   135 void CAccelerometerSensorSym::ConstructL()
   115     {
   136     {
   116     //Initialize the backend resources
   137     //Initialize the backend resources
   117     InitializeL();
   138     InitializeL(); 
       
   139     
       
   140     TSensrvProperty unitProperty;
       
   141     TRAPD(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelUnit, ESensrvSingleProperty, unitProperty));
       
   142     if(err == KErrNone)
       
   143         {
       
   144         unitProperty.GetValue(iUnit);
       
   145         }
       
   146     
       
   147     TSensrvProperty dataFormatProperty;
       
   148     iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelDataFormat, ESensrvSingleProperty, dataFormatProperty);
       
   149     TInt dataFormat;
       
   150     dataFormatProperty.GetValue(dataFormat);
       
   151     if(dataFormat == ESensrvChannelDataFormatScaled)
       
   152         {
       
   153         TSensrvProperty scaleRangeProperty;
       
   154         TRAPD(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdScaledRange, ESensrvSingleProperty, scaleRangeProperty));         //Slight confusion
       
   155         scaleRangeProperty.GetMaxValue(iScale);
       
   156         }
   118     }
   157     }
   119 
   158