×
Namespaces

Variants
Actions

Archived:Using the PySymbian Sensor module

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

This code snippet shows how to use the PySymbian 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 (08 May 2013)

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.

This page was last modified on 8 May 2013, at 09:24.
33 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.

×