void CMagnetometer::DataReceived(CSensrvChannel& aChannel, TInt aCount, TInt aDataLost) { if (aChannel.GetChannelInfo().iChannelType == KSensrvChannelTypeIdMagnetometerXYZAxisData) { TPckgBuf<TSensrvMagnetometerAxisData> dataBuffer; TSensrvMagnetometerAxisData data; for (TInt i = 0; i < aCount; ++i) { aChannel.GetData(dataBuffer); data = dataBuffer(); // Do something with the date in data variable // data.iTimeStamp // Compensate axis for landscape mode TInt x = -data.iAxisYCalibrated; TInt y = data.iAxisXCalibrated; TInt z = data.iAxisZCalibrated; #if 0 TInt x = data.iAxisXCalibrated; TInt y = data.iAxisYCalibrated; TInt z = data.iAxisZCalibrated; #endif const TReal KPole = 0.85; iX = KPole * iX + (1.0 - KPole) * x; iY = KPole * iY + (1.0 - KPole) * y; iZ = KPole * iZ + (1.0 - KPole) * z; } } }
//----------------------------------------------------------------------------- // CSensorChannelDoubleTap::HandleDataReceivedL //----------------------------------------------------------------------------- // void CSensorChannelDoubleTap::HandleDataReceivedL( CSensrvChannel& aChannel, TInt aCount, TInt /*aDataLost*/ ) { FUNC_LOG; INFO_1( "Received double tapping data. Count: %d", aCount ); // Ensure that we actually have data if( aCount ) { TSensrvTappingData data; TPckg<TSensrvTappingData> dataBuf( data ); if( aChannel.GetData( dataBuf ) == KErrNone ) { // Define context iContext->SetSourceL( KSensorSource ); iContext->SetTypeL( KSensorSourceEventDoubleTap ); if( data.iDirection == ( KSensrvAccelerometerDirectionXplus | KSensrvAccelerometerDirectionXminus ) ) { // Tapping from X axel iContext->SetValueL( TPtrC( KSensorSourceEventDoubleTapValues[EDoubleTapX] ) ); } else if( data.iDirection == ( KSensrvAccelerometerDirectionYplus | KSensrvAccelerometerDirectionYminus ) ) { // Tapping from Y axel iContext->SetValueL( TPtrC( KSensorSourceEventDoubleTapValues[EDoubleTapY] ) ); } else { // Tapping from Z axel iContext->SetValueL( TPtrC( KSensorSourceEventDoubleTapValues[EDoubleTapZ] ) ); } INFO_1( "Double tap data from sensor. Direction: %x", data.iDirection ); // Publish context - use change detection RThread thread; iCF.PublishContext( *iContext, thread ); thread.Close(); } } }
Qt::Orientation HbSensorListener::orientationFromData(CSensrvChannel &aChannel, TInt aCount) { Qt::Orientation orientation = mOrientation; if (aChannel.GetChannelInfo().iChannelType == KSensrvChannelTypeIdOrientationData) { TSensrvOrientationData data; for (TInt i = 0; i < aCount; ++i) { TPckgBuf<TSensrvOrientationData> dataBuf; aChannel.GetData(dataBuf); data = dataBuf(); orientation = sensorOrientationToQtOrientation(data.iDeviceOrientation); } } return orientation; }
/* * RecvData is used to retrieve the sensor reading from sensor server * It is implemented here to handle proximity sensor specific * reading data and provides conversion and utility code */ void CProximitySensorSym::RecvData(CSensrvChannel &aChannel) { TPckg<TSensrvProximityData> proxpkg( iData ); TInt ret = aChannel.GetData( proxpkg ); if(KErrNone != ret) { // If there is no reading available, return without setting return; } // Get a lock on the reading data iBackendData.iReadingLock.Wait(); iReading.setClose(iData.iProximityState == TSensrvProximityData::EProximityDiscernible); // Set the timestamp iReading.setTimestamp(iData.iTimeStamp.Int64()); // Release the lock iBackendData.iReadingLock.Signal(); }
/* * RecvData is used to retrieve the sensor reading from sensor server * It is implemented here to handle accelerometer sensor specific * reading data and provides conversion and utility code */ void CAccelerometerSensorSym::RecvData(CSensrvChannel &aChannel) { TPckg<TSensrvAccelerometerAxisData> accelerometerpkg( iData ); TInt ret = aChannel.GetData( accelerometerpkg ); if(KErrNone != ret) { // If there is no reading available, return without setting return; } TReal x = iData.iAxisX; TReal y = iData.iAxisY; TReal z = iData.iAxisZ; //Converting unit to m/s^2 if(iScaleRange && iUnit == ESensevChannelUnitAcceleration) { qoutputrangelist rangeList = sensor()->outputRanges(); int outputRange = sensor()->outputRange(); if (outputRange == -1) outputRange = 0; TReal maxValue = rangeList[outputRange].maximum; x = (x/iScaleRange) * maxValue; y = (y/iScaleRange) * maxValue; z = (z/iScaleRange) * maxValue; } else if(iUnit == ESensrvChannelUnitGravityConstant) { //conversion is yet to done } // Get a lock on the reading data iBackendData.iReadingLock.Wait(); // Set qt mobility accelerometer reading with data from sensor server iReading.setX(x); iReading.setY(y); iReading.setZ(z); // Set the timestamp iReading.setTimestamp(iData.iTimeStamp.Int64()); // Release the lock iBackendData.iReadingLock.Signal(); }
/* * RecvData is used to retrieve the sensor reading from sensor server * It is implemented here to handle rotation sensor specific * reading data and provides conversion and utility code */ void CRotationSensorSym::RecvData(CSensrvChannel &aChannel) { TPckg<TSensrvRotationData> rotationpkg( iData ); TInt ret = aChannel.GetData( rotationpkg ); if(KErrNone != ret) { // If there is no reading available, return without setting return; } // Get a lock on the reading data iBackendData.iReadingLock.Wait(); // To Do verify with ds and ramsay // For x axis symbian provides reading from 0 to 359 range // This logic maps value to Qt range -90 to 90 if(iData.iDeviceRotationAboutXAxis >= 0 && iData.iDeviceRotationAboutXAxis <= 180) { iReading.setX(90 - iData.iDeviceRotationAboutXAxis); } else if(iData.iDeviceRotationAboutXAxis > 180 && iData.iDeviceRotationAboutXAxis <= 270) { iReading.setX(iData.iDeviceRotationAboutXAxis - 270); } else if(iData.iDeviceRotationAboutXAxis > 270 && iData.iDeviceRotationAboutXAxis < 360) { iReading.setX(iData.iDeviceRotationAboutXAxis - 270); } // For y axis symbian provides reading from 0 to 359 range // This logic maps value to Qt range -180 to 180 if(iData.iDeviceRotationAboutYAxis >= 0 && iData.iDeviceRotationAboutYAxis <= 180) { iReading.setY(iData.iDeviceRotationAboutYAxis); } else if(iData.iDeviceRotationAboutYAxis > 180 && iData.iDeviceRotationAboutYAxis < 360) { iReading.setY(iData.iDeviceRotationAboutYAxis - 360); } if(iData.iDeviceRotationAboutZAxis == TSensrvRotationData::KSensrvRotationUndefined) { sensor()->setProperty("hasZ", QVariant(FALSE)); } else { sensor()->setProperty("hasZ", QVariant(TRUE)); // For z axis symbian provides reading from 0 to 359 range // This logic maps value to Qt range -180 to 180 if(iData.iDeviceRotationAboutZAxis >= 0 && iData.iDeviceRotationAboutZAxis <= 180) { iReading.setZ(iData.iDeviceRotationAboutZAxis); } else if(iData.iDeviceRotationAboutZAxis > 180 && iData.iDeviceRotationAboutZAxis < 360) { iReading.setZ(iData.iDeviceRotationAboutZAxis - 360); } } // Set the timestamp iReading.setTimestamp(iData.iTimeStamp.Int64()); // Release the lock iBackendData.iReadingLock.Signal(); }