Nokia N97 SDK
Example Applications Guide

Sensor API example

1. About this Example
2. Architecture
3. Design and Implementation


1. About this Example

Sensorexample is an example application that demonstrates Sensor API functionality. Sensor API provides clients the access to the data provided by various sensors of the device.

1.1 APIs demonstrated

Sensor API

1.2 Prerequisites

The user should be familiar with standard Symbian OS application architecture employing the Application, Document, UI, and View classes. The user should be aware of basic Symbian OS concepts.

Behavior of sensor channels in emulator environment is configured to SsyReferenceConfig.xml file.


2. Architecture

This example exists as a complete application and has the standard Symbian OS application architecture employing the Application, Document, UI, and View classes.


3. Design and Implementation

3.1 Capabilities

ECapabilityReadDeviceData capability is needed to run this application. To be able to set a property, ECapabilityWriteDeviceData capability is needed.

3.2 Opening sensor channels

This section explains the sequence of opening sensor channels during the application startup.

openChannel.PNG

1. The framework completes the construction of the AppUI object by calling its ConstructL method (CSensorExampleAppUi::ConstructL).
2. AppUI object tries to open three sensor channels (accelerometer, double tapping and orientation). Channels are opened by calling three times CSensorExampleAppUi::OpenChannelL method.
3. A channel finder object is created.
4. A channel is searched by calling FindChannelsL method with a channel type id as a parameter.
5. If a searched channel is found a sensor channel object is created.
6. A Found channel is opened.
7. Channel data listening is started.

3.3 Receiving sensor data

This section explains the sequence of receiving data from sensor channel.

receiveData.PNG

1. The sensor channel calls DataReceived call-back method when new data is available.
2. Data listener object reads new data with GetData method.
3. Received data is passed to AppView object.
4. AppView object draws screen showing the current sensor data. A smiley is drawn to the screen as shown in screenshot below. Sensor data affects to smiley in three different ways:

basicView.PNG

3.4 Handling properties

This section explains the sequence of getting and setting sensor channel properties.

property.PNG

1. Whenever the user selects a menu option, CSensorExampleAppUi::HandleCommandL is called by the framework. Available property related commands are shown in figure below.

showPropertySelected.PNG
2. The AppUI calls internal method HandleQueryL for property related commands.
3. A channel finder object is created.
4. All available channels are searched by calling FindChannelsL.
5. ShowQueryDialogL method shows all available channels on device in query dialog where user can select one as shown in figure below.
accelerometerSelected.PNG
6. After user has selected one channel, a new channel object is created.
7. User selected channel is opened.
8. All properties of the opened channel are queried.
9. ShowQueryDialogL method shows all available properties of the opened channel. User can select one property as shown in figure below.
scaledRangeSelected.PNG
10. Depending on user selection in phase one the result is following:

© Nokia 2009

Back to top