diff -r 06b8e2af4411 -r 6fbed849b4f4 qtmobility/plugins/sensors/symbian/accelerometersym.cpp --- a/qtmobility/plugins/sensors/symbian/accelerometersym.cpp Fri Jun 11 14:26:25 2010 +0300 +++ b/qtmobility/plugins/sensors/symbian/accelerometersym.cpp Wed Jun 23 19:08:38 2010 +0300 @@ -48,7 +48,7 @@ /** * set the id of the accelerometer sensor */ -const char *CAccelerometerSensorSym::id("sym.accelerometer"); +char const * const CAccelerometerSensorSym::id("sym.accelerometer"); /** * Factory function, this is used to create the accelerometer object @@ -77,7 +77,7 @@ * Default constructor */ CAccelerometerSensorSym::CAccelerometerSensorSym(QSensor *sensor):CSensorBackendSym(sensor), - iScale(0), + iScaleRange(0), iUnit(0) { setReading(&iReading); @@ -86,6 +86,68 @@ SetListening(ETrue, EFalse); } +void CAccelerometerSensorSym::start() +{ + TSensrvProperty dataFormatProperty; + TInt err; + CSensorBackendSym::start(); + TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelDataFormat, ESensrvSingleProperty, dataFormatProperty)); + if(err == KErrNone) + { + TInt dataFormat; + dataFormatProperty.GetValue(dataFormat); + if(dataFormat == ESensrvChannelDataFormatScaled) + { + TSensrvProperty scaleRangeProperty; + TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdScaledRange, KSensrvItemIndexNone, scaleRangeProperty)); + if(err == KErrNone) + { + if(scaleRangeProperty.GetArrayIndex() == ESensrvSingleProperty) + { + if(scaleRangeProperty.PropertyType() == ESensrvIntProperty) + { + scaleRangeProperty.GetMaxValue(iScaleRange); + } + else if(scaleRangeProperty.PropertyType() == ESensrvRealProperty) + { + TReal realScale; + scaleRangeProperty.GetMaxValue(realScale); + iScaleRange = realScale; + } + } + else if(scaleRangeProperty.GetArrayIndex() == ESensrvArrayPropertyInfo) + { + TInt index; + if(scaleRangeProperty.PropertyType() == ESensrvIntProperty) + { + scaleRangeProperty.GetValue(index); + } + else if(scaleRangeProperty.PropertyType() == ESensrvRealProperty) + { + TReal realIndex; + scaleRangeProperty.GetValue(realIndex); + index = realIndex; + } + TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdScaledRange, KSensrvItemIndexNone, index, scaleRangeProperty)); + if(err == KErrNone) + { + if(scaleRangeProperty.PropertyType() == ESensrvIntProperty) + { + scaleRangeProperty.GetMaxValue(iScaleRange); + } + else if(scaleRangeProperty.PropertyType() == ESensrvRealProperty) + { + TReal realScaleRange; + scaleRangeProperty.GetMaxValue(realScaleRange); + iScaleRange = realScaleRange; + } + } + } + } + } + } +} + /* * RecvData is used to retrieve the sensor reading from sensor server * It is implemented here to handle accelerometer sensor specific @@ -104,13 +166,13 @@ TReal y = iData.iAxisY; TReal z = iData.iAxisZ; //Converting unit to m/s^2 - qoutputrangelist rangeList = sensor()->outputRanges(); - TReal maxValue = rangeList[sensor()->outputRange()].maximum; - if(iScale && iUnit == ESensevChannelUnitAcceleration) + if(iScaleRange && iUnit == ESensevChannelUnitAcceleration) { - x = (x/iScale) * maxValue; - y = (y/iScale) * maxValue; - z = (z/iScale) * maxValue; + qoutputrangelist rangeList = sensor()->outputRanges(); + TReal maxValue = rangeList[sensor()->outputRange()].maximum; + x = (x/iScaleRange) * maxValue; + y = (y/iScaleRange) * maxValue; + z = (z/iScaleRange) * maxValue; } else if(iUnit == ESensrvChannelUnitGravityConstant) { @@ -137,22 +199,12 @@ //Initialize the backend resources InitializeL(); + TInt err; TSensrvProperty unitProperty; - TRAPD(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelUnit, ESensrvSingleProperty, unitProperty)); + TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelUnit, ESensrvSingleProperty, unitProperty)); if(err == KErrNone) { unitProperty.GetValue(iUnit); } - - TSensrvProperty dataFormatProperty; - iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelDataFormat, ESensrvSingleProperty, dataFormatProperty); - TInt dataFormat; - dataFormatProperty.GetValue(dataFormat); - if(dataFormat == ESensrvChannelDataFormatScaled) - { - TSensrvProperty scaleRangeProperty; - TRAPD(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdScaledRange, ESensrvSingleProperty, scaleRangeProperty)); //Slight confusion - scaleRangeProperty.GetMaxValue(iScale); - } }