This page was last modified 07:34, 22 April 2008.
CS000913 - Listening for rotation sensor data events
From Forum Nokia Wiki
| ID | CS000913 | Creation date | April 22, 2008 |
| Platform | S60 3rd Edition, MR | Tested on devices | Nokia N95 8GB |
| Category | Symbian C++ | Subcategory | Hardware, Sensor |
| Keywords (APIs, classes, methods, functions): CRRSensorApi, TRRSensorInfo, CRRSensorApi::NewL(), CRRSensorApi::AddDataListener(), CRRSensorApi::RemoveDataListener(), MRRSensorDataListener::HandleDataEventL() |
Overview
This code snippet demonstrates how to listen for data events produced by the rotation 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>
// Rotation sensor UID const TInt KRotationSensorUID = 0x303E;
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 the rotation sensor listener. */ void RegisterSensors(); /** * Unregisters the rotation sensor listener. */ void UnregisterSensors(); private: // Data CRRSensorApi* iRotationSensor; }
Source file
#include <RRSensorApi.h>
void CMyControl::ConstructL(const TRect& aRect) { // ... // Initialize and register the rotation sensor listener RegisterSensors(); // ... }
CMyControl::~CMyControl() { // ... // Unregister the rotation sensor listener UnregisterSensors(); // ... }
/** * Initializes and registers the rotation sensor listener. */ 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 rotation sensor now if (sensorList[i].iSensorId == KRotationSensorUID) { iRotationSensor = CRRSensorApi::NewL(sensorList[i]); // Register this control as rotation data listener iRotationSensor->AddDataListener(this); break; } } CleanupStack::PopAndDestroy(); // sensorList }
/** * Unregisters the rotation sensor listener. */ void CMyControl::UnregisterSensors() { // Unregister rotation data listener iRotationSensor->RemoveDataListener(); delete iRotationSensor; iRotationSensor = 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, the CMyControl::HandleDataEventL() function is called.
See also
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Web application freezes key events processing | ten0s | General Symbian C++ | 0 | 2007-04-03 17:22 |
| access problem | nimrot | Python | 3 | 2008-05-09 11:09 |
| Debug mode that allows for viewing/capturing all events? | kirason | Carbide.c++ and CodeWarrior Tools | 3 | 2006-04-18 06:11 |
| 3rd Edition application development | liuxg | Symbian | 76 | 2008-05-12 02:45 |
| Port for Picture Message | Nokia_Archive | Smart Messaging | 4 | 2002-07-18 05:13 |

