qtmobility/plugins/sensors/symbian/accelerometersym.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
    46 #define GRAVITATION_CONSTANT 9.812865328        //According to wikipedia link http://en.wikipedia.org/wiki/Standard_gravity
    46 #define GRAVITATION_CONSTANT 9.812865328        //According to wikipedia link http://en.wikipedia.org/wiki/Standard_gravity
    47 
    47 
    48 /**
    48 /**
    49  * set the id of the accelerometer sensor
    49  * set the id of the accelerometer sensor
    50  */
    50  */
    51 const char *CAccelerometerSensorSym::id("sym.accelerometer");
    51 char const * const CAccelerometerSensorSym::id("sym.accelerometer");
    52 
    52 
    53 /**
    53 /**
    54  * Factory function, this is used to create the accelerometer object
    54  * Factory function, this is used to create the accelerometer object
    55  * @return CAccelerometerSensorSym if successful, leaves on failure
    55  * @return CAccelerometerSensorSym if successful, leaves on failure
    56  */
    56  */
    75 
    75 
    76 /**
    76 /**
    77  * Default constructor
    77  * Default constructor
    78  */
    78  */
    79 CAccelerometerSensorSym::CAccelerometerSensorSym(QSensor *sensor):CSensorBackendSym(sensor),
    79 CAccelerometerSensorSym::CAccelerometerSensorSym(QSensor *sensor):CSensorBackendSym(sensor),
    80         iScale(0),
    80         iScaleRange(0),
    81         iUnit(0)
    81         iUnit(0)
    82         {
    82         {
    83         setReading<QAccelerometerReading>(&iReading);
    83         setReading<QAccelerometerReading>(&iReading);
    84         iBackendData.iSensorType = KSensrvChannelTypeIdAccelerometerXYZAxisData;    
    84         iBackendData.iSensorType = KSensrvChannelTypeIdAccelerometerXYZAxisData;    
    85         //Disable property listening
    85         //Disable property listening
    86         SetListening(ETrue, EFalse);
    86         SetListening(ETrue, EFalse);
    87         }
    87         }
    88 
    88 
       
    89 void CAccelerometerSensorSym::start()
       
    90 {
       
    91     TSensrvProperty dataFormatProperty;
       
    92     TInt err;
       
    93     CSensorBackendSym::start();
       
    94     TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelDataFormat, ESensrvSingleProperty, dataFormatProperty));
       
    95     if(err == KErrNone)
       
    96         {
       
    97         TInt dataFormat;
       
    98         dataFormatProperty.GetValue(dataFormat);
       
    99         if(dataFormat == ESensrvChannelDataFormatScaled)
       
   100             {
       
   101             TSensrvProperty scaleRangeProperty;
       
   102             TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdScaledRange, KSensrvItemIndexNone, scaleRangeProperty)); 
       
   103             if(err == KErrNone)
       
   104                 {
       
   105                 if(scaleRangeProperty.GetArrayIndex() == ESensrvSingleProperty)
       
   106                     {
       
   107                     if(scaleRangeProperty.PropertyType() == ESensrvIntProperty)
       
   108                         {
       
   109                         scaleRangeProperty.GetMaxValue(iScaleRange);
       
   110                         }
       
   111                     else if(scaleRangeProperty.PropertyType() == ESensrvRealProperty)
       
   112                         {
       
   113                         TReal realScale;
       
   114                         scaleRangeProperty.GetMaxValue(realScale);
       
   115                         iScaleRange = realScale;
       
   116                         }
       
   117                     }
       
   118                 else if(scaleRangeProperty.GetArrayIndex() == ESensrvArrayPropertyInfo)
       
   119                     {
       
   120                     TInt index;
       
   121                     if(scaleRangeProperty.PropertyType() == ESensrvIntProperty)
       
   122                         {               
       
   123                         scaleRangeProperty.GetValue(index);
       
   124                         }
       
   125                     else if(scaleRangeProperty.PropertyType() == ESensrvRealProperty)
       
   126                         {
       
   127                         TReal realIndex;           
       
   128                         scaleRangeProperty.GetValue(realIndex);
       
   129                         index = realIndex;
       
   130                         }
       
   131                     TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdScaledRange, KSensrvItemIndexNone, index, scaleRangeProperty));
       
   132                     if(err == KErrNone)
       
   133                         {
       
   134                         if(scaleRangeProperty.PropertyType() == ESensrvIntProperty)
       
   135                             {
       
   136                             scaleRangeProperty.GetMaxValue(iScaleRange);
       
   137                             }
       
   138                         else if(scaleRangeProperty.PropertyType() == ESensrvRealProperty)
       
   139                             {
       
   140                             TReal realScaleRange;
       
   141                             scaleRangeProperty.GetMaxValue(realScaleRange);
       
   142                             iScaleRange = realScaleRange;
       
   143                             }
       
   144                         }
       
   145                     }
       
   146                 }
       
   147             }
       
   148         }
       
   149 }
       
   150 
    89 /*
   151 /*
    90  * RecvData is used to retrieve the sensor reading from sensor server
   152  * RecvData is used to retrieve the sensor reading from sensor server
    91  * It is implemented here to handle accelerometer sensor specific
   153  * It is implemented here to handle accelerometer sensor specific
    92  * reading data and provides conversion and utility code
   154  * reading data and provides conversion and utility code
    93  */
   155  */
   102         }
   164         }
   103     TReal x = iData.iAxisX;
   165     TReal x = iData.iAxisX;
   104     TReal y = iData.iAxisY;
   166     TReal y = iData.iAxisY;
   105     TReal z = iData.iAxisZ;
   167     TReal z = iData.iAxisZ;
   106     //Converting unit to m/s^2
   168     //Converting unit to m/s^2
   107     qoutputrangelist rangeList = sensor()->outputRanges();
   169     if(iScaleRange && iUnit == ESensevChannelUnitAcceleration)
   108     TReal maxValue = rangeList[sensor()->outputRange()].maximum;
   170         {
   109     if(iScale && iUnit == ESensevChannelUnitAcceleration)
   171 	qoutputrangelist rangeList = sensor()->outputRanges();
   110         {
   172 	TReal maxValue = rangeList[sensor()->outputRange()].maximum;
   111         x = (x/iScale) * maxValue;
   173         x = (x/iScaleRange) * maxValue;
   112         y = (y/iScale) * maxValue;
   174         y = (y/iScaleRange) * maxValue;
   113         z = (z/iScale) * maxValue;
   175         z = (z/iScaleRange) * maxValue;        
   114         }
   176         }
   115     else if(iUnit == ESensrvChannelUnitGravityConstant)
   177     else if(iUnit == ESensrvChannelUnitGravityConstant)
   116         {
   178         {
   117         //conversion is yet to done
   179         //conversion is yet to done
   118         }
   180         }
   135 void CAccelerometerSensorSym::ConstructL()
   197 void CAccelerometerSensorSym::ConstructL()
   136     {
   198     {
   137     //Initialize the backend resources
   199     //Initialize the backend resources
   138     InitializeL(); 
   200     InitializeL(); 
   139     
   201     
       
   202     TInt err;
   140     TSensrvProperty unitProperty;
   203     TSensrvProperty unitProperty;
   141     TRAPD(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelUnit, ESensrvSingleProperty, unitProperty));
   204     TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelUnit, ESensrvSingleProperty, unitProperty));
   142     if(err == KErrNone)
   205     if(err == KErrNone)
   143         {
   206         {
   144         unitProperty.GetValue(iUnit);
   207         unitProperty.GetValue(iUnit);
   145         }
   208         }
   146     
   209     }
   147     TSensrvProperty dataFormatProperty;
   210 
   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         }
       
   157     }
       
   158