Using
Sensor Channels APIs
The Sensor Channel establishes a data exchange connection between
the sensor framework and hardware using the sensor channel APIs.
Steps
Include the library SensrvClient.lib in
your .mmp file.
Include the following
header files, as they are required for accessing sensor channels regardless
of the channel type:
sensrvchannel.h
sensrvchannelinfo.h
sensrvtypes.h
sensrvchannelfinder.h
sensrvdatalistener.h
Retrieve details
about the required sensor channel. For details. see Querying
for Sensor Channels.
Connect to the sensor
by opening a connection with the sensor channel.
Create an instance
of CSensrvChannel
and specify the instance of TSensrvChannelInfo
returned
by CSensrvChannelFinder::FindChannelsL()
, as a parameter
in the NewL()
constructor.
CSensrvChannel* sensorChannel;
sensorChannel = CSensrvChannel::NewL(channelInfoList[0]);// channelInfoList is
// returned by the CSensrvChannelFinder::FindChannelsL()funtion
Open the sensor
channel using CSensrvChannel::OpenChannelL() function.
channel->OpenChannelL();
Perform any of the
following operations:
Close the channel.
channel->CloseChannel();
Important: A
channel must be closed when not required, as it reduces power consumption
of the Symbian device. An open sensor channel keeps the device processor active
each time data arrives. Therefore, the processor does not change to idle state
even when the device user is not performing any operations on the device.
- Querying
for Sensor Channels
You can retrieve a list of sensor channels that are available for
a particular sensor type. Once you get the list of sensor channels that are
active, you can perform any required operations such as configuring sensor
channel properties, controlling sensor channels and so on.
- Receiving
Data from Sensors
You can implement a data listener to receive data from the sensors.
Based on the data received, you can perform specific actions on the Symbian
device. For example, if you receive information from the sensor about the
distance between the device and the user then based on this information, you
can disable or enable the loudspeaker mode on the Symbian device.
- Retrieving
Channel Properties
A sensor channel is associated with properties such as channel
availability status, data transmission rate, data format and so on. Also,
each field in the data type supplied by a sensor channel can have its own
properties. The channel properties can be retrieved using the CSensrvChannel::GetPropertyL()
and CSensrvChannel::GetAllPropertiesL()
functions.
- Setting Channel Properties
The channel properties can be configured using the CSensrvChannel::SetProperty()
function.
- Listening
for Property Changes
The sensor channel APIs enable the client applications to be notified
about the changes to properties associated with a sensor channel.
- Listening
for Channel Changes
The sensor channel APIs enable you to receive notifications when
a sensor channel is added or removed. This ensures that you are informed of
changes to sensor channels whenever there is a change. For example, you can
receive notifications when a specific proximity sensor channel is added.
- Receiving
Channel Data based on Conditions
Conditional listening enables you to receive sensor data feeds
based on a specific condition. For example, you can choose to receive sensor
feeds that are only movement specific.