×
Namespaces

Variants
Actions
Revision as of 06:13, 9 February 2012 by hamishwillee (Talk | contribs)

Archived:Using the PySymbian Sensor module

From Nokia Developer Wiki
Jump to: navigation, search

This code snippet shows how to use the PyS60 Sensor module in pys60 to access the Symbian rotation and accelaration sensors. Note that the sensor framework has not been implemented in PySymbian . This is for use with older devices.

Article Metadata
Tested with
Devices(s): Nokia N95, Nokia N93i , N82
Compatibility
Platform(s): S60 3rd Edition and FP1
Article
Keywords: Sensors
Created: anees042 (02 Jan 2009)
Last edited: hamishwillee (09 Feb 2012)

First of all import sensor and e32 module

import e32
import sensor

Now Lets see the available sensors

sensor.sensors()

To get the acceleration sensor

# if you wants to get Rotation sensor Change 'AccSensor' to 'RotSensor'
accsensor=sensor.get('AccSensor')

To get the id and category of acceleration sensor

id=accsensor.get('id')
cat=accsensor.get('cat')

Create a callback for sensor events

def printout(value):
print value

Now lets get the object of Acceleration Sensor

senobj=sensor.Sensor(id,cat)

lets set an event filter for the acceleration filter

#if you are working with rotation sensor then change sensor.OrientationEventFilter() to sensor.RotEventFilter()
# if you wants to get low level data then sensor.EventFilter() which is the base event filter class.
senobj.set_event_filter(sensor.OrientationEventFilter())

lets connect to the sensor

senobj.connect(printout)

wait for 15 seconds

e32.ao_sleep(15)

Disconnect from the sensor

senobj.disconnect()

Thats it for now. the complete code is listed below for Acceleration Sensor:

# __author__='Fayyaz Ali'
# version = '1.0 beta'
# license='GNU GPL'
import e32
import sensor
sensor.sensors()
accsensor=sensor.get('AccSensor')
id=accsensor.get('id')
cat=accsensor.get('cat')
def printout(value):
print value
senobj=sensor.Sensor(id,cat)
senobj.set_event_filter(sensor.OrientationEventFilter())
senobj.connect(printout)
e32.ao_sleep(15)
senobj.disconnect()

for Rotation Sensor:

# __author__='Fayyaz Ali'
# version = '1.0 beta'
# license='GNU GPL'
import e32
import sensor
sensor.sensors()
accsensor=sensor.get('RotSensor')
id=accsensor.get('id')
cat=accsensor.get('cat')
def printout(value):
print value
senobj=sensor.Sensor(id,cat)
senobj.set_event_filter(sensor.RotEventFilter())
senobj.connect(printout)
e32.ao_sleep(15)
senobj.disconnect()

Additional information

Above code is written by Fayyaz Ali and is Licensed under gnu gpl.

37 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.

×