javaextensions/sensor/src.s60/cacceleratorsensor.cpp
changeset 21 2a9601315dfc
child 25 9ac0a0a7da70
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Accelerometer sensor implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INTERNAL INCLUDES
       
    20 #include "cacceleratorsensor.h"
       
    21 #include "csensorproperties.h"
       
    22 #include "sensorlistener.h"
       
    23 #include "sensornativeconstants.h"
       
    24 #include "logger.h"
       
    25 
       
    26 #include <e32debug.h>
       
    27 
       
    28 #include <sensrvtypes.h>
       
    29 
       
    30 
       
    31 _LIT(KSeparator, "#");
       
    32 _LIT(KDescription, "description=");
       
    33 _LIT(KModel, "#model=Nokia#");
       
    34 _LIT(KConnectionTypeNotSpecified, "connectiontype=0");
       
    35 _LIT(KContextTypeUser, "user#");
       
    36 _LIT(KDataTypeDouble, "1#");
       
    37 _LIT(KValueScale, "0#");
       
    38 
       
    39 _LIT(KMeasureRangeCount, "1#");
       
    40 _LIT(KChannelTerminator, "#@ch_end#");
       
    41 
       
    42 const TInt KChannels = 3;
       
    43 
       
    44 const TInt KDataListening = 1;
       
    45 const TInt KConditionListening = 2;
       
    46 const TInt KGetDataListening = 4;
       
    47 const TReal KStandardGravityValue = 9.812865328; // in m/s^2
       
    48 
       
    49 CAcceleratorSensor::CAcceleratorSensor(const TSensrvChannelInfo& aChannelInfo) :
       
    50         iChannelInfo(aChannelInfo), iStartTime(KErrNotFound)
       
    51 {
       
    52     JELOG2(ESensor);
       
    53     // No implementation needed
       
    54 }
       
    55 
       
    56 CAcceleratorSensor::~CAcceleratorSensor()
       
    57 {
       
    58     JELOG2(ESensor);
       
    59     if (iChannel)
       
    60     {
       
    61         iChannel->StopDataListening();
       
    62         iChannel->CloseChannel();
       
    63     }
       
    64     delete iChannel;
       
    65 }
       
    66 
       
    67 CAcceleratorSensor* CAcceleratorSensor::NewLC(const TSensrvChannelInfo& aChannelInfo)
       
    68 {
       
    69     JELOG2(ESensor);
       
    70     CAcceleratorSensor* self = new(ELeave) CAcceleratorSensor(aChannelInfo);
       
    71     CleanupStack::PushL(self);
       
    72     self->ConstructL();
       
    73     return self;
       
    74 }
       
    75 
       
    76 CAcceleratorSensor* CAcceleratorSensor::NewL(const TSensrvChannelInfo& aChannelInfo)
       
    77 {
       
    78     JELOG2(ESensor);
       
    79     CAcceleratorSensor* self = CAcceleratorSensor::NewLC(aChannelInfo);
       
    80     CleanupStack::Pop(); // self;
       
    81     return self;
       
    82 }
       
    83 
       
    84 void CAcceleratorSensor::ConstructL()
       
    85 {
       
    86     JELOG2(ESensor);
       
    87     CSensorBase::ConstructL();
       
    88     iChannel = CSensrvChannel::NewL(iChannelInfo);
       
    89 }
       
    90 
       
    91 void CAcceleratorSensor::GetProperty(const RSensrvPropertyList aList,
       
    92                                      const TSensrvPropertyId aPropertyId,
       
    93                                      const TInt aItemIndex,
       
    94                                      TSensrvProperty& aProperty)
       
    95 {
       
    96     JELOG2(ESensor);
       
    97     TInt propCount = aList.Count();
       
    98     for (int i = 0; i < propCount; i++)
       
    99     {
       
   100         aProperty = aList[i];
       
   101         if (aProperty.GetPropertyId() == aPropertyId &&
       
   102                 aProperty.PropertyItemIndex() == aItemIndex)
       
   103         {
       
   104             return;
       
   105         }
       
   106     }
       
   107     TSensrvProperty prop;
       
   108     aProperty = prop;
       
   109 }
       
   110 // newcode for querying for the property using arrayindex also
       
   111 void CAcceleratorSensor::GetProperty(const RSensrvPropertyList aList,
       
   112                                      const TSensrvPropertyId aPropertyId,
       
   113                                      const TInt aItemIndex,
       
   114                                      const TInt aArrayIndex,
       
   115                                      TSensrvProperty& aProperty)
       
   116 {
       
   117     JELOG2(ESensor);
       
   118     TInt propCount = aList.Count();
       
   119     for (int i = 0; i < propCount; i++)
       
   120     {
       
   121         aProperty = aList[i];
       
   122         if (aProperty.GetPropertyId() == aPropertyId &&
       
   123                 aProperty.PropertyItemIndex() == aItemIndex&&
       
   124                 aProperty.GetArrayIndex()==aArrayIndex)
       
   125 
       
   126         {
       
   127             return;
       
   128         }
       
   129     }
       
   130     TSensrvProperty prop;
       
   131     aProperty = prop;
       
   132 }
       
   133 
       
   134 HBufC* CAcceleratorSensor::CreateDescriptionLC()
       
   135 {
       
   136     JELOG2(ESensor);
       
   137     HBufC* description = HBufC::NewLC(KMaxSensorDescriptionLength);
       
   138     TPtr desPtr = description->Des();
       
   139 
       
   140     CSensrvChannel* channel = CSensrvChannel::NewL(iChannelInfo);
       
   141     CleanupStack::PushL(channel);
       
   142     channel->OpenChannelL();
       
   143 
       
   144     RSensrvPropertyList propList;
       
   145     CleanupClosePushL(propList);
       
   146     channel->GetAllPropertiesL(propList);
       
   147     channel->CloseChannel();
       
   148 
       
   149     // Quantity
       
   150     desPtr.Append(SensorProperties::GetPropertyString(
       
   151                       KQuantity, iChannelInfo.iQuantity));
       
   152     desPtr.Append(KSeparator);
       
   153 
       
   154     // ContextType
       
   155     desPtr.Append(KContextTypeUser);
       
   156 
       
   157     // Location
       
   158     TBuf<KSensrvLocationLength> location;
       
   159     location.Copy(iChannelInfo.iLocation);
       
   160     desPtr.Append(location);
       
   161     desPtr.Append(KSeparator);
       
   162 
       
   163     // Vendor
       
   164     TBuf<KSensrvVendorIdLength> vendor;
       
   165     vendor.Copy(iChannelInfo.iVendorId);
       
   166     desPtr.Append(vendor);
       
   167     desPtr.Append(KSeparator);
       
   168 
       
   169     // Description and Model
       
   170     desPtr.Append(KDescription);
       
   171 
       
   172     desPtr.Append(SensorProperties::GetPropertyString(KSensorDescription,
       
   173                   SensorDescriptionId()));
       
   174 
       
   175     Model(&desPtr);
       
   176 
       
   177     TSensrvProperty property;
       
   178     TInt intValue(0);
       
   179 
       
   180     // Connection type
       
   181     GetProperty(propList, KSensrvSensorConnectionType,    KSensrvItemIndexNone,
       
   182                 property);
       
   183     if (property.PropertyType() == ESensrvIntProperty)
       
   184     {
       
   185         property.GetValue(intValue);
       
   186         desPtr.Append(SensorProperties::GetPropertyString(
       
   187                           KConnectionType, intValue));
       
   188     }
       
   189     else
       
   190     {
       
   191         desPtr.Append(KConnectionTypeNotSpecified);
       
   192     }
       
   193     desPtr.Append(KSeparator);
       
   194 
       
   195     // Availability
       
   196     GetProperty(propList, KSensrvPropIdAvailability, KSensrvItemIndexNone,
       
   197                 property);
       
   198     if (property.PropertyType() == ESensrvIntProperty)
       
   199     {
       
   200         property.GetValue(intValue);
       
   201         desPtr.AppendNum(intValue);
       
   202     }
       
   203     else
       
   204     {
       
   205         desPtr.AppendNum(0);
       
   206     }
       
   207     desPtr.Append(KSeparator);
       
   208 
       
   209     //number of channels
       
   210     desPtr.AppendNum(KChannels);
       
   211     desPtr.Append(KSeparator);
       
   212     DescriptorAppendChannel(&desPtr, propList,
       
   213                             TSensrvAccelerometerAxisData::EAxisX);
       
   214     DescriptorAppendChannel(&desPtr, propList,
       
   215                             TSensrvAccelerometerAxisData::EAxisY);
       
   216     DescriptorAppendChannel(&desPtr, propList,
       
   217                             TSensrvAccelerometerAxisData::EAxisZ);
       
   218 
       
   219     CleanupStack::PopAndDestroy();
       
   220     CleanupStack::PopAndDestroy(channel);
       
   221     return description;
       
   222 }
       
   223 
       
   224 void CAcceleratorSensor::DescriptorAppendChannel(TPtr* aPtr,
       
   225         const RSensrvPropertyList aList,
       
   226         TInt aItemIndex)
       
   227 {
       
   228     JELOG2(ESensor);
       
   229     TRealFormat realFormat;
       
   230     realFormat.iTriLen = 0;
       
   231     realFormat.iPoint = '.';
       
   232     TSensrvProperty property;
       
   233     TReal realValue(0);
       
   234 
       
   235     // name
       
   236     aPtr->Append(SensorProperties::GetPropertyString(
       
   237                      KAcceleratorChannelName, aItemIndex));
       
   238     aPtr->Append(KSeparator);
       
   239 
       
   240     // accuracy
       
   241     GetProperty(aList, KSensrvPropIdChannelAccuracy,
       
   242                 KSensrvItemIndexNone, property);
       
   243     if (property.PropertyType() == ESensrvRealProperty)
       
   244     {
       
   245         property.GetValue(realValue);
       
   246         aPtr->AppendNum(realValue / 100, realFormat);
       
   247     }
       
   248     // the checking for int property was introduced for 9.2
       
   249     else if (property.PropertyType() == ESensrvIntProperty)
       
   250     {
       
   251         TInt intValue(0);
       
   252         property.GetValue(intValue);
       
   253         aPtr->AppendNum(intValue, realFormat);
       
   254     }
       
   255     else
       
   256     {
       
   257         aPtr->AppendNum(-1);
       
   258     }
       
   259 
       
   260     aPtr->Append(KSeparator);
       
   261 
       
   262     // data type
       
   263     DataType(aPtr);
       
   264 
       
   265     // scale
       
   266     aPtr->Append(KValueScale);
       
   267 
       
   268     // data unit
       
   269     DataUnit(aList, aPtr);
       
   270     aPtr->Append(KSeparator);
       
   271 
       
   272     // range count and range
       
   273     DataRange(aList, aPtr);
       
   274     aPtr->Append(KChannelTerminator);
       
   275 }
       
   276 
       
   277 
       
   278 CSensorBase* CAcceleratorSensor::DuplicateL()
       
   279 {
       
   280     JELOG2(ESensor);
       
   281     return NewL(iChannelInfo);
       
   282 }
       
   283 
       
   284 TReal CAcceleratorSensor::InterpretValue(TReal aValue)
       
   285 {
       
   286     JELOG2(ESensor);
       
   287     return iScaleFactor * aValue;
       
   288 }
       
   289 
       
   290 int CAcceleratorSensor::OpenChannel(SensorListener *aListener)
       
   291 {
       
   292     JELOG2(ESensor);
       
   293     iSensorListener = aListener;
       
   294     TRAPD(err, OpenChannelL(););
       
   295     return err==KErrNotFound? KErrNone : err;
       
   296 }
       
   297 
       
   298 void CAcceleratorSensor::OpenChannelL()
       
   299 {
       
   300     JELOG2(ESensor);
       
   301     LOG(ESensor,EInfo,"Creating Open Channel");
       
   302     iChannel->OpenChannelL();
       
   303     LOG(ESensor,EInfo,"Channel Created");
       
   304     // Check if the sensor data is scaled and set the scale factor
       
   305     iScaleFactor = 1;
       
   306     TInt format(ESensrvChannelDataFormatAbsolute);
       
   307     TSensrvProperty property;
       
   308     TRAPD(err1,iChannel->GetPropertyL(KSensrvPropIdChannelDataFormat, KSensrvItemIndexNone,
       
   309                                       property););
       
   310     LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::GetPropertyL() One = %d",err1);
       
   311     if (property.PropertyType() == ESensrvIntProperty)
       
   312     {
       
   313         property.GetValue(format);
       
   314         LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::GetValue()::KSensrvPropIdChannelDataFormat format = %d",format);
       
   315     }
       
   316     else
       
   317     {
       
   318         LOG(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::KSensrvPropIdChannelDataFormat::Propety Type must be Integer");
       
   319         //KSensrvPropIdChannelDataFormat::Propety Type must be Integer
       
   320         __ASSERT_DEBUG(EFalse,User::Invariant());
       
   321     }
       
   322 
       
   323     if (format == ESensrvChannelDataFormatScaled)
       
   324     {
       
   325         LOG(ESensor,EInfo," format is equal to ESensrvChannelDataFormatScaled");
       
   326         // Scaled value maximum
       
   327         TSensrvProperty property_scaled;
       
   328         TInt maxScaled(0);
       
   329         TRAPD(err2,iChannel->GetPropertyL(KSensrvPropIdScaledRange, KSensrvItemIndexNone,
       
   330                                           property_scaled););
       
   331         LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::GetPropertyL() Two = %d",err2);
       
   332 
       
   333         if (property_scaled.GetArrayIndex() == ESensrvArrayPropertyInfo)
       
   334         {
       
   335             LOG(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::If");
       
   336             //for 2G Accelerometer Sensor index value is 0.
       
   337             TInt rangeIndex(0);
       
   338             TRAPD(err3,iChannel->GetPropertyL(KSensrvPropIdScaledRange, KSensrvItemIndexNone,
       
   339                                               rangeIndex, property_scaled););
       
   340             LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::GetPropertyL() Three = %d",err3);
       
   341 
       
   342             property_scaled.GetMaxValue(maxScaled);
       
   343 
       
   344             LOG1(ESensor,EInfo,"property_scaled::maxValue = %d",maxScaled);
       
   345         }
       
   346         else
       
   347         {
       
   348             LOG(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::else");
       
   349             property_scaled.GetMaxValue(maxScaled);
       
   350             LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::maxScaled = %d",maxScaled);
       
   351         }
       
   352         // MeasureRange can be an array property
       
   353         TReal maxMeasure;
       
   354         TSensrvProperty property_Measured;
       
   355         TRAPD(err4,iChannel->GetPropertyL(KSensrvPropIdMeasureRange, KSensrvItemIndexNone,
       
   356                                           property_Measured););
       
   357         LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::GetPropertyL() Four = %d",err4);
       
   358 
       
   359         if (err4 == KErrNone)
       
   360         {
       
   361             TInt arrayIndex = property_Measured.GetArrayIndex();
       
   362             LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::KSensrvPropIdMeasureRange::arrayIndex = %d",arrayIndex);
       
   363 
       
   364             if (property_Measured.GetArrayIndex() == ESensrvArrayPropertyInfo)
       
   365             {
       
   366                 LOG(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::If");
       
   367 
       
   368                 TInt index2g = 0;
       
   369                 LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::Getting RangeIndex = %f",index2g);
       
   370                 //We need to TypeCast variable rangeIndex to TInt for
       
   371                 TRAPD(err5,iChannel->GetPropertyL(KSensrvPropIdMeasureRange, KSensrvItemIndexNone,
       
   372                                                   index2g, property_Measured););
       
   373                 LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::GetPropertyL() Five = %d",err5);
       
   374                 property_Measured.GetMaxValue(maxMeasure);
       
   375             }
       
   376             else
       
   377             {
       
   378                 LOG(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::else");
       
   379                 property_Measured.GetMaxValue(maxMeasure);
       
   380             }
       
   381 
       
   382         }
       
   383         iScaleFactor = maxMeasure / maxScaled ;
       
   384         LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::iScaleFactor = %f",iScaleFactor);
       
   385     }
       
   386     // this checking was introduced for 9.2
       
   387     else if (format == ESensrvChannelDataFormatAbsolute)
       
   388     {
       
   389         iScaleFactor = 2 * KStandardGravityValue / 127;
       
   390         // no need to calculate the scale factor
       
   391     }
       
   392 }
       
   393 void CAcceleratorSensor::CloseChannelL()
       
   394 {
       
   395     JELOG2(ESensor);
       
   396     TInt err = iChannel->CloseChannel();
       
   397 }
       
   398 
       
   399 void CAcceleratorSensor::StartDataListeningL()
       
   400 {
       
   401     JELOG2(ESensor);
       
   402     if (iStartTime == KErrNotFound)
       
   403     {
       
   404         iStartTime.UniversalTime();
       
   405     }
       
   406     iChannelXData = iData[ 0 ];
       
   407     iChannelYData = iData[ 1 ];
       
   408     iChannelZData = iData[ 2 ];
       
   409     if (!iListeningType)
       
   410     {
       
   411         iChannel->StartDataListeningL(this, iBufferSize, iBufferSize,
       
   412                                       iBufferingPeriod/1000);
       
   413     }
       
   414     if (iIsOneShot)
       
   415     {
       
   416         iListeningType = iListeningType | KGetDataListening;
       
   417     }
       
   418     else
       
   419     {
       
   420         iListeningType = iListeningType | KDataListening;
       
   421     }
       
   422 }
       
   423 
       
   424 
       
   425 void CAcceleratorSensor::CancelDataListeningL()
       
   426 {
       
   427     JELOG2(ESensor);
       
   428     if (iListeningType & KDataListening)
       
   429     {
       
   430         iListeningType = iListeningType ^ KDataListening;
       
   431     }
       
   432     if (!iListeningType)
       
   433     {
       
   434         User::LeaveIfError(iChannel->StopDataListening());
       
   435     }
       
   436 }
       
   437 
       
   438 
       
   439 void CAcceleratorSensor::StopConditionListeningL()
       
   440 {
       
   441     JELOG2(ESensor);
       
   442     if (iListeningType & KConditionListening)
       
   443     {
       
   444         iListeningType = iListeningType ^ KConditionListening;
       
   445         User::LeaveIfError(iChannel->StopDataListening());
       
   446         if (iListeningType)
       
   447         {
       
   448             iChannel->StartDataListeningL(this, iBufferSize, iBufferSize,
       
   449                                           iBufferingPeriod/1000);
       
   450         }
       
   451     }
       
   452 }
       
   453 
       
   454 
       
   455 void CAcceleratorSensor::StartConditionListeningL()
       
   456 {
       
   457     JELOG2(ESensor);
       
   458     if (iListeningType & (KDataListening | KGetDataListening))
       
   459     {
       
   460         iChannel->StopDataListening();
       
   461     }
       
   462     if (!(iListeningType & KConditionListening))
       
   463     {
       
   464 
       
   465         // changing -1 to 0 for buffering period since -1 throws KErrArgument in 9.2
       
   466         iChannel->StartDataListeningL(this, 1, 1 /* listen every value*/, 0);
       
   467     }
       
   468     iListeningType = iListeningType | KConditionListening;
       
   469 }
       
   470 
       
   471 void CAcceleratorSensor::DataReceived(CSensrvChannel& aChannel,
       
   472                                       TInt aCount,
       
   473                                       TInt aDataLost)
       
   474 {
       
   475     JELOG2(ESensor);
       
   476     TSensrvAccelerometerAxisData data;
       
   477     TPckgBuf<TSensrvAccelerometerAxisData> dataBuf;
       
   478     TBool dataFetched = EFalse;
       
   479     TTime currentTime;
       
   480     currentTime.UniversalTime();
       
   481     // no need for data preparation if only listening conditions
       
   482     if (iListeningType & (KDataListening | KGetDataListening))
       
   483     {
       
   484         // Do not go over buffer count
       
   485         if (iChannelXData->iNumOfValues + aCount > iBufferSize)
       
   486         {
       
   487             aCount = iBufferSize - iChannelXData->iNumOfValues;
       
   488         }
       
   489 
       
   490         // Prepare own data
       
   491         for (TInt i = iChannelXData->iNumOfValues; i < aCount + iChannelXData->iNumOfValues; i++)
       
   492         {
       
   493             aChannel.GetData(dataBuf);
       
   494             data = dataBuf();
       
   495             dataFetched = ETrue;
       
   496             CopyData(data, i);
       
   497             // add timestamps, if needed
       
   498             if (iChannelXData->iTimeStampsIncluded)
       
   499             {
       
   500                 // Sensrv api returns timestams in localtime java requires UTC
       
   501                 iChannelXData->iTimeStamps[ i ] = TimeStamp(currentTime);
       
   502                 iChannelYData->iTimeStamps[ i ] = TimeStamp(currentTime);
       
   503                 iChannelZData->iTimeStamps[ i ] = TimeStamp(currentTime);
       
   504             }
       
   505         }
       
   506         iChannelXData->iNumOfValues += aCount;
       
   507         iChannelYData->iNumOfValues += aCount;
       
   508         iChannelZData->iNumOfValues += aCount;
       
   509 
       
   510         if (iChannelXData->iNumOfValues == iBufferSize || iBufferingPeriod > 0
       
   511                 || (iListeningType & KConditionListening
       
   512                     && currentTime.MicroSecondsFrom(iStartTime)
       
   513                     >= iBufferingPeriod))
       
   514         {
       
   515             if (iListeningType & KGetDataListening)
       
   516             {
       
   517                 iListeningType = iListeningType ^ KGetDataListening;
       
   518                 if (!(iListeningType & KConditionListening))
       
   519                 {
       
   520                     iChannel->StopDataListening();
       
   521                 }
       
   522             }
       
   523             // callback
       
   524             iSensorListener->DataReceived(iData, aDataLost > 0);
       
   525             iChannelXData->iNumOfValues = 0;
       
   526             iChannelYData->iNumOfValues = 0;
       
   527             iChannelZData->iNumOfValues = 0;
       
   528             iStartTime = KErrNotFound;
       
   529         }
       
   530     }
       
   531     // evaluate conditions if condition listening is on
       
   532     if (iListeningType & KConditionListening)
       
   533     {
       
   534         // get data if not done already by datalistening routine
       
   535         if (!dataFetched)
       
   536         {
       
   537             aChannel.GetData(dataBuf);
       
   538             data = dataBuf();
       
   539         }
       
   540         EvaluateConditions(data.iAxisX, 0);
       
   541         EvaluateConditions(data.iAxisY, 1);
       
   542         EvaluateConditions(data.iAxisZ, 2);
       
   543         if (!iJavaConditionEval && iConditions.Count() == 0)
       
   544         {
       
   545             TRAP_IGNORE(StopConditionListeningL());
       
   546         }
       
   547     }
       
   548 }
       
   549 
       
   550 void CAcceleratorSensor::DataError(CSensrvChannel& /*aChannel*/,
       
   551                                    TSensrvErrorSeverity /*aError*/)
       
   552 {
       
   553     JELOG2(ESensor);
       
   554     // Currently we don't care wether error is minor or fatal
       
   555     if (!(iListeningType ^ KGetDataListening))
       
   556     {
       
   557         iChannel->StopDataListening();
       
   558     }
       
   559     TSensrvAccelerometerAxisData data;
       
   560     for (TInt i = iChannelXData->iNumOfValues; i < iBufferSize; i++)
       
   561     {
       
   562         data.iAxisX = 0;
       
   563         data.iAxisY = 0;
       
   564         data.iAxisZ = 0;
       
   565         CopyData(data, i);
       
   566         if (iValiditiesIncluded)
       
   567         {
       
   568             iChannelXData->iValidities[i] = EFalse;
       
   569             iChannelYData->iValidities[i] = EFalse;
       
   570             iChannelZData->iValidities[i] = EFalse;
       
   571         }
       
   572     }
       
   573     iSensorListener->DataReceived(iData, ETrue);
       
   574     iChannelXData->iNumOfValues = 0;
       
   575     iChannelYData->iNumOfValues = 0;
       
   576     iChannelZData->iNumOfValues = 0;
       
   577     iStartTime = KErrNotFound;
       
   578 }
       
   579 
       
   580 void CAcceleratorSensor::GetDataListenerInterfaceL(TUid /*aInterfaceUid*/,
       
   581         TAny*& aInterface)
       
   582 {
       
   583     JELOG2(ESensor);
       
   584     aInterface = NULL;
       
   585     // For future extension, implement when needed
       
   586 }
       
   587 
       
   588 void CAcceleratorSensor::Model(TPtr* aPtr)
       
   589 {
       
   590     JELOG2(ESensor);
       
   591     aPtr->Append(KModel);
       
   592 }
       
   593 
       
   594 void CAcceleratorSensor::DataType(TPtr* aPtr)
       
   595 {
       
   596     JELOG2(ESensor);
       
   597     aPtr->Append(KDataTypeDouble);
       
   598 }
       
   599 
       
   600 void CAcceleratorSensor::DataUnit(const RSensrvPropertyList aList, TPtr* aPtr)
       
   601 {
       
   602     JELOG2(ESensor);
       
   603     TSensrvProperty property;
       
   604     TInt intValue(0);
       
   605     GetProperty(aList, KSensrvPropIdChannelUnit, KSensrvItemIndexNone, property);
       
   606     if (property.PropertyType() == ESensrvIntProperty)
       
   607     {
       
   608         property.GetValue(intValue);
       
   609         aPtr->Append(SensorProperties::GetPropertyString(KChannelUnit, intValue));
       
   610     }
       
   611     else
       
   612     {
       
   613         aPtr->Append(SensorProperties::GetPropertyString(KChannelUnit,
       
   614                      ESensrvChannelUnitNotDefined));
       
   615     }
       
   616 }
       
   617 
       
   618 void CAcceleratorSensor::DataRange(const RSensrvPropertyList aList,
       
   619                                    TPtr* aPtr)
       
   620 {
       
   621     JELOG2(ESensor);
       
   622     TRealFormat realFormat;
       
   623     realFormat.iTriLen = 0;
       
   624     realFormat.iPoint = '.';
       
   625     realFormat.iPlaces = 2;
       
   626     TSensrvProperty property;
       
   627     TReal realValue(0);
       
   628     GetProperty(aList, KSensrvPropIdMeasureRange,KSensrvItemIndexNone, property);
       
   629 
       
   630     // the extra checking for arraypropertyindex was introduced for 9.2 driver changes
       
   631     // for 5.0 and 9.2 both the platforms first and second IF blocks should be executed
       
   632     if ((property.GetArrayIndex() == ESensrvArrayPropertyInfo)&&
       
   633             (property.PropertyType() == ESensrvRealProperty))
       
   634     {
       
   635         LOG(ESensor,EInfo,"CAcceleratorSensor::DataRange()::KSensrvPropIdMeasureRange is ESensrvArrayPropertyInfo and ESensrvRealProperty::first IF");
       
   636         // Read index
       
   637         TInt index2g = 0;
       
   638         // Read actual property data from array
       
   639         GetProperty(aList, KSensrvPropIdMeasureRange,
       
   640                     KSensrvItemIndexNone, index2g, property);
       
   641         LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::DataRange() index = %f",index);
       
   642     }
       
   643 
       
   644     if (property.PropertyType() == ESensrvRealProperty)
       
   645     {
       
   646         LOG(ESensor,EInfo,"CAcceleratorSensor::DataRange()::KSensrvPropIdMeasureRange ESensrvRealProperty::second IF");
       
   647         aPtr->Append(KMeasureRangeCount);
       
   648         property.GetMinValue(realValue);   // min
       
   649         LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::DataRange() min = %f",realValue);
       
   650         aPtr->AppendNum(realValue, realFormat);
       
   651         aPtr->Append(KSeparator);
       
   652         property.GetMaxValue(realValue);   // max
       
   653         LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::DataRange() max = %f",realValue);
       
   654         aPtr->AppendNum(realValue, realFormat);
       
   655         aPtr->Append(KSeparator);
       
   656         property.GetValue(realValue);   // resolution
       
   657         //resolution is minimum difference between the data values
       
   658         TReal resolution = realValue /127 ;
       
   659         LOG1(ESensor,EInfo,"CAcceleratorSensor::OpenChannelL()::DataRange() val = %f",resolution);
       
   660         aPtr->AppendNum(resolution, realFormat);
       
   661     }
       
   662     // the extra checking for ESensrvIntProperty was introduced for 9.2 driver changes
       
   663     else if (property.PropertyType() == ESensrvIntProperty)
       
   664     {
       
   665         //This condition is an extra check and not supposed to be entered.
       
   666         LOG(ESensor,EInfo,"CAcceleratorSensor::DataRange()::KSensrvPropIdMeasureRange ESensrvIntProperty::ELSE IF");
       
   667         TReal min,max,resolution;
       
   668         // Read TInt values
       
   669         TInt minInt,maxInt,resolutionInt;
       
   670         property.GetMinValue(minInt);
       
   671         property.GetMaxValue(maxInt);
       
   672         property.GetValue(resolutionInt);
       
   673 
       
   674         // Convert integers to TReal
       
   675         min=-((resolutionInt * KStandardGravityValue)/1000);
       
   676         max=((resolutionInt * KStandardGravityValue)/1000);
       
   677         // Resolution is minimum value difference which can be caught.
       
   678         // for ex. in case of raw data(-128 -to- 127) the resolution is 1
       
   679         resolution=(resolutionInt* KStandardGravityValue)/(1000 * 127);
       
   680         aPtr->Append(KMeasureRangeCount);
       
   681         aPtr->AppendNum(min, realFormat);
       
   682         aPtr->Append(KSeparator);
       
   683         aPtr->AppendNum(max, realFormat);
       
   684         aPtr->Append(KSeparator);
       
   685         aPtr->AppendNum(resolution, realFormat);
       
   686 
       
   687     }
       
   688     else
       
   689     {
       
   690         aPtr->AppendNum(0);
       
   691     }
       
   692 }
       
   693 void CAcceleratorSensor::CopyData(const TSensrvAccelerometerAxisData aData, TInt aIndex)
       
   694 {
       
   695     JELOG2(ESensor);
       
   696     iChannelXData->iDoubleValues[ aIndex ] = aData.iAxisX * iScaleFactor;
       
   697     iChannelYData->iDoubleValues[ aIndex ] = aData.iAxisY * iScaleFactor;
       
   698     iChannelZData->iDoubleValues[ aIndex ] = aData.iAxisZ * iScaleFactor;
       
   699 }
       
   700 
       
   701 TInt CAcceleratorSensor::SensorDescriptionId()
       
   702 {
       
   703     JELOG2(ESensor);
       
   704     return EAccelerometerSensor;
       
   705 }