camerauis/cameraxui/cxengine/src/sensor/xqaccsensor_p.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 23 61bc0f252b2b
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 #include "xqaccsensor_p.h"
       
    18 #include "xqaccsensor.h"
       
    19 #include <sensrvaccelerometersensor.h>
       
    20 #include <sensrvchannel.h>
       
    21 
       
    22 XQAccelerationSensorPrivate::XQAccelerationSensorPrivate(XQSensor& qq) :
       
    23     XQSensorPrivate(qq)
       
    24 {
       
    25 }
       
    26 
       
    27 XQAccelerationSensorPrivate::~XQAccelerationSensorPrivate()
       
    28 {
       
    29     close();
       
    30     delete iXyzAxisChannel;
       
    31 }
       
    32 
       
    33 void XQAccelerationSensorPrivate::open()
       
    34 {
       
    35     TRAP(iError,
       
    36         if(!iXyzAxisChannel) {
       
    37             iXyzAxisChannel = CreateChannelL(KSensrvChannelTypeIdAccelerometerXYZAxisData);
       
    38         }
       
    39         iXyzAxisChannel->OpenChannelL();
       
    40     )
       
    41 }
       
    42 
       
    43 void XQAccelerationSensorPrivate::close()
       
    44 {
       
    45     if (iXyzAxisChannel) {
       
    46         iXyzAxisChannel->CloseChannel();
       
    47     }
       
    48 }
       
    49 
       
    50 void XQAccelerationSensorPrivate::startReceiving()
       
    51 {
       
    52     if (iXyzAxisChannel) {
       
    53         TRAP(iError,
       
    54             iXyzAxisChannel->StartDataListeningL(this, 1, 16, 0);
       
    55         )
       
    56     } else {
       
    57         iError = KErrNotReady;
       
    58     }
       
    59 }
       
    60 
       
    61 void XQAccelerationSensorPrivate::stopReceiving()
       
    62 {
       
    63     if (iXyzAxisChannel) {
       
    64         iXyzAxisChannel->StopDataListening();
       
    65     }
       
    66 }
       
    67 
       
    68 void XQAccelerationSensorPrivate::DataReceived(CSensrvChannel& aChannel,
       
    69     TInt aCount, TInt aDataLost)
       
    70 {
       
    71     TSensrvChannelTypeId typeId = aChannel.GetChannelInfo().iChannelType;
       
    72     if (typeId == KSensrvChannelTypeIdAccelerometerXYZAxisData) {
       
    73         HandleXyzAxisData(aChannel, aCount, aDataLost);
       
    74     }
       
    75 }
       
    76 
       
    77 void XQAccelerationSensorPrivate::HandleXyzAxisData(CSensrvChannel& aChannel, TInt aCount, TInt /*aDataLost*/)
       
    78 {
       
    79     for(TInt i = 0; i < aCount; i++) {
       
    80         TPckgBuf<TSensrvAccelerometerAxisData> dataBuf;
       
    81         if (aChannel.GetData(dataBuf) == KErrNone) {
       
    82             TSensrvAccelerometerAxisData data = dataBuf();
       
    83             for (int i = iFilters.size() - 1; i >= 0; --i) {
       
    84                 XQAbstractAccelerationSensorFilter* filter = iFilters.at(i);
       
    85                 if (filter->filter(data.iAxisX, data.iAxisY, data.iAxisZ))
       
    86                     break;
       
    87             }
       
    88             iXAcceleration = data.iAxisX;
       
    89             iYAcceleration = data.iAxisY;
       
    90             iZAcceleration = data.iAxisZ;
       
    91         }
       
    92     }
       
    93 }
       
    94 
       
    95 XQSensor::Error XQAccelerationSensorPrivate::error() const
       
    96 {
       
    97     switch (iError) {
       
    98         case KErrNone:
       
    99             return XQSensor::NoError;
       
   100         case KErrNoMemory:
       
   101             return XQSensor::OutOfMemoryError;
       
   102         case KErrNotFound:
       
   103             return XQSensor::NotFoundError;
       
   104         default:
       
   105             return XQSensor::UnknownError;
       
   106     }
       
   107 }
       
   108 
       
   109 void XQAccelerationSensorPrivate::addFilter(XQAbstractAccelerationSensorFilter& filter)
       
   110 {
       
   111     iFilters.append(&filter);
       
   112 }
       
   113 
       
   114 QList<XQAbstractAccelerationSensorFilter*>& XQAccelerationSensorPrivate::filters()
       
   115 {
       
   116     return iFilters;
       
   117 }
       
   118 
       
   119 int XQAccelerationSensorPrivate::xAcceleration() const
       
   120 {
       
   121     return iXAcceleration;
       
   122 }
       
   123 
       
   124 int XQAccelerationSensorPrivate::yAcceleration() const
       
   125 {
       
   126     return iYAcceleration;
       
   127 }
       
   128 
       
   129 int XQAccelerationSensorPrivate::zAcceleration() const
       
   130 {
       
   131     return iZAcceleration;
       
   132 }
       
   133 
       
   134 bool XQAccelerationDataPostFilter::filter(int& xAcceleration, int& yAcceleration, int& zAcceleration)
       
   135 {
       
   136     const int maxAcceleration = 127;    //for framework
       
   137     xAcceleration = xAcceleration * 100 / maxAcceleration;
       
   138     yAcceleration = yAcceleration * 100 / maxAcceleration;
       
   139     zAcceleration = zAcceleration * 100 / maxAcceleration;
       
   140     return false;
       
   141 }
       
   142 
       
   143 XQAccelerationDataPostFilter::XQAccelerationDataPostFilter()
       
   144 {
       
   145 }
       
   146 
       
   147 // End of file