Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:Listening for accelerometer sensor data events on Symbian

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Tested with
Devices(s): Nokia N95 8GB
Compatibility
Platform(s): S60 3rd Edition, FP1
S60 3rd Edition FP1
Article
Keywords: CRRSensorApi, TRRSensorInfo, CRRSensorApi::NewL(), CRRSensorApi::AddDataListener(), CRRSensorApi::RemoveDataListener(), MRRSensorDataListener::HandleDataEventL()
Created: tapiolaitinen (02 Apr 2008)
Last edited: lpvalente (05 Aug 2012)

Contents

Overview

This snippet demonstrates how to listen for data events produced by the accelerometer sensor of the device.

In practice, the control implements the MRRSensorDataListener interface which enables it to listen to the data events. Whenever a data event occurs, the MRRSensorDataListener::HandleDataEventL() function is called.

Note: In order to use the code, you need to install the sensor plug-in for your SDK.

This snippet can be self-signed.

MMP file

The following libraries are required:

LIBRARY RRSensorApi.lib

Header file

#include <RRSensorApi.h>
// Accelerometer sensor UID
const TInt KAccelerometerSensorUID = 0x10273024;
class CMyControl : public CCoeControl, public MRRSensorDataListener
{
// ...
 
private: // Functions from base classes
/**
* From MRRSensorDataListener.
* Callback function for receiving sensor data events.
*
* @param aSensor identifies the sensor that created the event.
* @param aEvent contains data about created event.
*/

void HandleDataEventL(TRRSensorInfo aSensor, TRRSensorEvent aEvent);
 
private:
/**
* Initializes and registers accelerometer sensors.
*/

void RegisterSensors();
 
/**
* Unregisters accelerometer sensors.
*/

void UnregisterSensors();
 
private: // Data
CRRSensorApi* iAccelerometerSensor;
}

Source file

#include <RRSensorApi.h>
void CMyControl::ConstructL(const TRect& aRect)
{
// ...
 
// Initialize and register accelerometer sensors
RegisterSensors();
 
// ...
}
CMyControl::~CMyControl()
{
// ...
 
// Unregister accelerometer sensors
UnregisterSensors();
 
// ...
}
/**
* Initializes and registers accelerometer sensors.
*/

void CMyControl::RegisterSensors()
{
RArray<TRRSensorInfo> sensorList;
CleanupClosePushL(sensorList);
 
// Retrieve list of available sensors
CRRSensorApi::FindSensorsL(sensorList);
 
// Get number of sensors available
TInt sensorCount = sensorList.Count();
 
for (TInt i = 0; i < sensorCount; i++)
{
// We are interested only in the accelerometer sensor now
if (sensorList[i].iSensorId == KAccelerometerSensorUID)
{
iAccelerometerSensor = CRRSensorApi::NewL(sensorList[i]);
 
// Register this control as accelerometer data listener
iAccelerometerSensor->AddDataListener(this);
 
break;
}
}
 
CleanupStack::PopAndDestroy(); // sensorList
}
/**
* Unregisters accelerometer sensors.
*/

void CMyControl::UnregisterSensors()
{
// Unregister accelerometer data listener
iAccelerometerSensor->RemoveDataListener();
delete iAccelerometerSensor;
iAccelerometerSensor = NULL;
}
/**
* Gets called whenever a data event occurs.
*/

void CMyControl::HandleDataEventL(TRRSensorInfo aSensor, TRRSensorEvent aEvent)
{
// A data event occurred. Handle it.
// ...
}

Postconditions

Whenever a data event occurs, CMyControl::HandleDataEventL() function is called.

This page was last modified on 5 August 2012, at 18:18.
51 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×