Vous êtes sur la page 1sur 16

1 (16) Python for s60 Sensor module S60 sensor framework support

Python for S60


Sensor module for S60 Sensor FW

2 (16) Python for s60 Sensor module S60 sensor framework support

TA !" #F $#%T"%TS

1. Introduction sensor -- Module to access the device sensors


Th&s PyS60 sensor module supports a''ess&n( the sensors on the de)&'es that ha)e S60 Sensor Framework l&*rar&es+ The S60 Sensor Framework was &ntrodu'ed &n S60 ,th "d&t&on- *ut &s also *a'kported to S60 .rd "d&t&on- Feature Pa'k 2 for some mo*&le de)&'es- as well as the %ok&a "66 de)&'e- wh&'h &s an S60 .rd "d&t&on- Feature Pa'k 1 de)&'e w&th sensor AP/s *ased on the S60 Sensor Framework+ The sensor module offers d&re't a''ess to a de)&'e0s phys&'al sensors+ The follow&n( sensor 'hannels are supported *y the sensor module- pro)&ded the de)&'e supports them1 A''elerometer 234 sensor 'hannel 5otat&on sensor 'hannel #r&entat&on sensor 'hannel A''elerometer dou*le6tap sensor 'hannel Pro7&m&ty mon&tor sensor 'hannel Am*&ent l&(ht sensor 'hannel 8a(net&' %orth sensor 'hannel

. (16) Python for s60 Sensor module S60 sensor framework support 8a(netometer 234 sensor 'hannel

The follow&n( ta*le l&sts the sensors a)a&la*le on d&fferent S60 de)&'es These sensors are mapped to a 'lass us&n( wh&'h the sensor 'hannel data 'an *e a''essed+ To a''ess a part&'ular sensor data an o*9e't of the respe't&)e 'lass has to *e 'reated f&rst+ Then the data 'all*a'k fun't&on 'an *e set us&n( the set_callback() method+ To start and stop re'e&)&n( updates the start_listening() and stop_listening() methods 'an *e used+ Note: Th&s module0s AP/ 'ompat&*&l&ty *etween 1+:+7 )ers&ons &sn0t (uaranteed unt&l 2+0+ /t won0t *e *roken w&thout (ood reason- *ut &t 'an happen+

2. Module Level Functions


2.1 List Channels
Fun't&on s&(nature 1 list_channels() Th&s returns a l&st of d&'t&onar&es 'onta&n&n( all the a)a&la*le sensors on the de)&'e+ The returned d&'t&onary has the follow&n( format1 [ {'id': channel id, 'type': channel type, 'name: channel name} {'id': channel id, 'type': channel type, 'name: channel name} .
Acceleromete r ou!le "a# Acceleromete r $%& 'rientation (otation Am!ient Light Magnetic North )ro*imity Monitor Magnetometer $%& +,#lat.orm

N/0 1,, N2, 130 ,320/-,21,31100

7 7 7 7 7 7 7 7

7 7 7 7 7 7 7 7 7

7 7 7 7 7 7 7 7

7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7

.rdFP2 .rdFP1 .rdFP2 .rdFP2 .rdFP2 ,th"d .rdFP2 .rdFP2 .rdFP2

] where channel_id- channel_type and channel_name w&ll ha)e the respe't&)e 'hannel;s )alues as str&n(s+

2.2 Query logical name:


Fun't&on s&(nature 1 get_logicalname(<DataLookupClass>, value)

< (16) Python for s60 Sensor module S60 sensor framework support Th&s fun't&on 'an *e used for =uery&n( the lo(&'al name *ased on )alue+ The f&le sensor_defs py has the mapp&n( of d&fferent sensor propert&es to the&r respe't&)e he7>de'&mal )alues+ Follow&n( ta*le 'onta&ns the sensor 'lasses- supported *y get_logicalname() and the respe't&)e data lookup 'lasses+ +ensor Class Pro7&m&ty8on&tor #r&entat&on?ata Am*&ent!&(ht?ata A''elerometer?ou*leTapp&n(?ata DataLookupClass TPro7&m&tyState TSensr)?e)&'e#r&entat&on TSensr)Am*&ent!&(ht?ata @Sensr)A''elerometer?&re't&on

, (16) Python for s60 Sensor module S60 sensor framework support

4. Classes 4.1 5ase class


The *ase 'lass to all types of sensor 'lass &s ASensor+ Th&s 'lass pro)&des the methods setA'all*a'kstartAl&sten&n( and stopAl&sten&n( wh&'h are 'ommon to all the sensor 'lass o*9e'ts+ The &nd&)&dual sensor 'lass o*9e'ts should *e used to use a spe'&f&' sensor+

4.1.1 '!6ect creation


Fun't&on s&(nature 1 AA&n&tAA(!data_filter"#one$) The dataAf&lter ar(ument &s only appl&'a*le for B234A7&s?ata and 5otat&on?ata sensor 'lasses+ Poss&*le Calues1 8ed&anF&lter()- !owPassF&lter() 6 /f noth&n( &s passed then the data &s left as6&s w&thout any f&lter&n( 6 8ed&anF&lter D !owPassF&lter are standard no&se f&lter&n( al(or&thms wh&'h pro)&de a smoother form of a s&(nal remo)&n( the short6term os'&llat&ons- lea)&n( only the lon(6term trend+

4.1.2 +et ata and 1rror Call!ac71


Fun't&on s&(nature 1 setA'all*a'k(dataA'all*a'k- !error_callback"#one$) Sets the data and error 'all*a'k fun't&on+ The error 'all*a'k fun't&on w&ll (et an ar(ument wh&'h w&ll 'onta&n a map w&th $hannel /? and error str&n(+ The data 'all*a'k fun't&on set w&ll not *e passed any ar(uments+

4.1.4 '#en and listen


Fun't&on s&(nature 1 startAl&sten&n(() #pens the sensor 'hannel and start l&sten&n(+ 5eturns True on su''ess and False on fa&lure+

4.1.8 +to# and close


Fun't&on s&(nature 1 stopAl&sten&n(() Stop l&sten&n( to the open 'hannel and 'lose the 'hannel+ To start re'e&)&n( updates a(a&n the startAl&sten&n( method 'an *e 'alled on the same sensor o*9e't+

6 (16) Python for s60 Sensor module S60 sensor framework support

4.1.0 +et9:et sensor channel #ro#erty


The 'urrent release of PyS60 sensor module does not support e&ther retr&e)&n( or mod&fy&n( all the sensor propert&es of a part&'ular 'hannel l&ke ?ata5ate- 8easure5an(e- S'aled5an(e et'+ Th&s feature w&ll *e pro)&ded &n the future dot releases+ 5efer the &nd&)&dual sensor 'lass des'r&pt&on for more deta&ls+

4.1., Class attri!utes


The sensor 'lasses ha)e one or more attr&*utes wh&'h w&ll 'onta&n the data returned *y the respe't&)e sensor+ These attr&*utes w&ll *e set *efore the re(&stered data 'all*a'k fun't&on &s 'alled and 'an *e a''essed us&n( the respe't&)e sensor 'lass o*9e't+

E (16) Python for s60 Sensor module S60 sensor framework support

4.2 class Accelerometer$%&A*is ata


?ete'ts mo)ement (estures- su'h as mo)&n( the de)&'e up or down /nher&ts from the ASensor *ase 'lass

Class attri!utes1 6 * 1 26a7&s )alue 6 y 1 36a7&s )alue 6 ; 1 46a7&s )alue


1*am#le: from sensor import * import e32 import time class Demo pp!": def ##init##!self": self.accelerometer $ % ccelerometer&'( )isData!data#filter$*o+,ass-ilter!"" self.accelerometer.set#call.ac/!data#call.ac/$self.my#call.ac/" self.co0nter $ 1 def my#call.ac/!self": 2 -or stream sensor data the call.ac/ is hit 33 times per sec!4n 2 3511". 6he de7ice cannot handle reso0rce h0n8ry operations li/e 2 print in the call.ac/ f0nction for s0ch hi8h fre90encies. 2 +or/aro0nd is to sample the data as demonstrated .elo+. if self.co0nter : 3 $$ 1: print ;&::s, '::s, (::s; : !self.accelerometer.), self.accelerometer.y, self.accelerometer.<" self.co0nter $ self.co0nter = > def r0n!self": self.accelerometer.start#listenin8!" if ##name## $$ '##main##': d $ Demo pp!" d.r0n!" e32.ao#sleep!>" d.accelerometer.stop#listenin8!" print ;?)itin8 ccelorometer;

F (16) Python for s60 Sensor module S60 sensor framework support

4.4 class Accelerometer ou!le"a##ing ata


?ete'ts a dou*le6tap on the de)&'e where the taps o''ur &n =u&'k su''ess&on and &n the same d&re't&on+ /nher&ts from the ASensor *ase 'lass

Class attri!ute: direction 1 Ge7 )alue &nd&'at&n( the tap d&re't&on+ Hs&n( (etAlo(&'alname AP/ and 'lassname as
@Sensr)A''elerometer?&re't&on the d&re't&on 'an *e determ&ned &n human reada*le form+

4.4.1 +et9:et #ro#erty


Th&s sensor 'lass pro)&des add&t&onal fun't&ons wh&'h 'an *e used to set>(et some of the propert&es spe'&f&' to th&s sensor+ N'"11 set>(et sensor property AP/ &s not 'omplete yet and &s not supported for all sensors or all types of propert&es+ These AP/s m&(ht 'han(e &n the future dot releases+

get<a*is<active=> 5eturns 7- y- I )alues1 1 &f a7&s &s a't&)e else 0+ set<a*is<active=[x=None, y=None, z=None]> Sets one or more a7&s as a't&)e+ Pass 1 to set the
a7&s and 0 to d&sa*le &t+

get<#ro#erties=> 5eturns TapThresholdCalue- Tap?urat&onCalue- Tap!aten'yCalueTap/nter)alCalue

set<#ro#erties=[DblTapThresholdValue = None, DblTapDurationValue = None, DblTapLatencyValue = None, DblTapInter alValue = None] > Sets the tap related propert&es
1*am#le: from sensor import * import e32 class Demo pp!": def ##init##!self": self.do0.letap $ ccelerometerDo0.le6appin8Data!" self.do0.letap.set#a)is#acti7e!)$1, y$>, <$>" print ; cti7e )is are: ;, self.do0.letap.8et#a)is#acti7e!" self.do0.letap.set#call.ac/!data#call.ac/$self.my#call.ac/" def my#call.ac/!self": print ;@a+ Direction 7al0e;, self.do0.letap.direction print ;Direction: ;, 8et#lo8icalname!ABensr7 ccelerometerDirection, self.do0.letap.direction" def r0n!self":

: (16) Python for s60 Sensor module S60 sensor framework support self.do0.letap.start#listenin8!" if ##name## $$ '##main##': d $ Demo pp!" d.r0n!" e32.ao#sleep!>3" d.do0.letap.stop#listenin8!" print ;?)itin8 Do0.le 6ap;

10 (16) Python for s60 Sensor module S60 sensor framework support

4.8 class Magnetometer$%&A*is ata


/nd&'ates the stren(th of the (eoma(net&' flu7 dens&ty &n the 2- 3 and 4 a7es+ #nly 'al&*rated a7&s data &s e7posed r&(ht now and not raw data+ /nher&ts from the ASensor *ase 'lass

Class attri!utes:
6 6 6 6

* 1 26a7&s )alue y 1 36a7&s )alue ; 1 46a7&s )alue cali!<level: /nd&'ates the 'al&*rat&on le)el+ o )ossi!le values:
0 6 %ot 'al&*rated 1 6 !ow 'al&*rat&on+ 2 6 8ed&um 'al&*rat&on . 6 G&(h a''ura'y

1*am#le: from sensor import * import e32 class Demo pp!": def ##init##!self": self.ma8netometer $ % Ca8netometer&'( )isData!data#filter$*o+,ass-ilter!"" self.ma8netometer.set#call.ac/!data#call.ac/$self.my#call.ac/" self.co0nter $ 1 def my#call.ac/!self": 2 -or stream sensor data the call.ac/ is hit 33 times per sec!4n 2 3511". 6he de7ice cannot handle reso0rce h0n8ry operations li/e 2 print in the call.ac/ f0nction for s0ch hi8h fre90encies. 2 +or/aro0nd is to sample the data as demonstrated .elo+. if self.co0nter : 3 $$ 1: print ;Dali.:;, self.ma8netometer.cali.#le7el print ;&::s, '::s, (::s; : !self.ma8netometer.), self.ma8netometer.y, self.ma8netometer.<" self.co0nter $ self.co0nter = > def r0n!self": self.ma8netometer.start#listenin8!"

11 (16) Python for s60 Sensor module S60 sensor framework support if ##name## $$ '##main##': d $ Demo pp!" d.r0n!" e32.ao#sleep!3" d.ma8netometer.stop#listenin8!" print ;?)itin8 Ca8netometer )is;

12 (16) Python for s60 Sensor module S60 sensor framework support

4.0 class MagneticNorth ata


/nd&'ates the num*er of de(rees *etween the de)&'e and ma(net&' north /nher&ts from the ASensor *ase 'lass

Class attri!ute:
6

a;imuth : 0 to .,: 'lo'kw&se de(rees from ma(net&' north

1*am#le: from sensor import * import e32 class Demo pp!": def ##init##!self": self.ma8netic#north $ Ca8neticEorthData!" self.ma8netic#north.set#call.ac/!data#call.ac/$self.my#call.ac/" def my#call.ac/!self": if self.ma8netic#north.cali.#le7el F 1: a<im0th $ str!self.ma8netic#north.a<im0th" print ;cali.ration le7el;, self.ma8netic#north.cali.#le7el print ;a<im0th;, a<im0th def r0n!self": self.ma8netic#north.start#listenin8!" if ##name## $$ '##main##': d $ Demo pp!" d.r0n!" e32.ao#sleep!3" d.ma8netic#north.stop#listenin8!" print ;?)itin8 Ca8neticEorth;

1. (16) Python for s60 Sensor module S60 sensor framework support

4., class Am!ientLight ata


/nd&'ates the 'urrent l&(ht le)el /nher&ts from the ASensor *ase 'lass

Class attri!ute: - am!ient<light : 0 to 100 per'ent l&(ht+ Hse (etAlo(&'alname AP/ w&th 'lassname as
TSensr)Am*&ent!&(ht?ata to (et the lo(&'al names+

1*am#le: from sensor import * import e32 class Demo pp!": def ##init##!self": self. *B $ m.ient*i8htData!" self. *B.set#call.ac/!data#call.ac/$self.my#call.ac/" def my#call.ac/!self": print ' *B : ', 8et#lo8icalname!6Bensr7 m.ient*i8htData, self. *B.am.ient#li8ht" def r0n!self": self. *B.start#listenin8!" if ##name## $$ '##main##': d $ Demo pp!" d.r0n!" e32.ao#sleep!31" d. *B.stop#listenin8!" print ;?)itin8 m.ient *i8ht;

1< (16) Python for s60 Sensor module S60 sensor framework support

4.3 class )ro*imityMonitor


/nd&'ates how 'lose the de)&'e &s to- for e7ample- the user0s hand or ear /nher&ts from the ASensor *ase 'lass

Class attri!ute: - #ro*imity<state : The poss&*le )alues are 0- 1 and 2+ Hse (etAlo(&'alname AP/ w&th
TPro7&m&tyState as the 'lass name to (et the lo(&'al names of these )alues+ 1*am#le: from sensor import * import e32 class Demo pp!": def ##init##!self": self.pro)i $ ,ro)imityConitor!" self.pro)i.set#call.ac/!data#call.ac/$self.my#call.ac/" def my#call.ac/!self": print 'pro)i : ', 8et#lo8icalname!6,ro)imityBtate, self.pro)i.pro)imity#state" def r0n!self": self.pro)i.start#listenin8!" if ##name## $$ '##main##': d $ Demo pp!" d.r0n!" e32.ao#sleep!>1" d.pro)i.stop#listenin8!" print ; fter Btop *istenin8; e32.ao#sleep!3" print ;?)itin8 ,ro)imity;

1, (16) Python for s60 Sensor module S60 sensor framework support

4./ class 'rientation ata


/nd&'ates the or&entat&on of the de)&'e- for e7ample1 d&splay up or d&splay down /nher&ts from the ASensor *ase 'lass

Class attri!ute: - device<orientation : Calues ran(e from 61 to 6+ To determ&ne the lo(&'al names of these )alues
(etAlo(&'alname AP/ 'an *e used w&th 'lassname as TSensr)?e)&'e#r&entat&on+ 1*am#le: from sensor import * import e32 class Demo pp!": def ##init##!self": self.orientation $ 4rientationData!" self.orientation.set#call.ac/!data#call.ac/$self.my#call.ac/" def my#call.ac/!self": print 'orientation : ', 8et#lo8icalname!6Bensr7De7ice4rientation, self.orientation.de7ice#orientation" def r0n!self": self.orientation.start#listenin8!" if ##name## $$ '##main##': d $ Demo pp!" d.r0n!" e32.ao#sleep!>1" d.orientation.stop#listenin8!" print ;?)itin8 4rientation;

16 (16) Python for s60 Sensor module S60 sensor framework support

4.2 class (otation ata


?ete'ts the rotat&on of the de)&'e a*out ea'h a7&s /nher&ts from the ASensor *ase 'lass

Class attri!utes:
6 6 6

* 1 26a7&s )alue y 1 36a7&s )alue ; 1 46a7&s )alue

1*am#le:
from sensor import * import e32 class Demo pp!": def ##init##!self": self.rotation $ @otationData!" self.rotation.set#call.ac/!data#call.ac/$self.my#call.ac/" self.co0nter $ 1 def my#call.ac/!self": 2 -or stream sensor data the call.ac/ is hit appro)imately 21 2 times per sec!4n 3511". 6he de7ice cannot handle reso0rce 2 h0n8ry operations li/e print in the call.ac/ f0nction for s0ch 2 hi8h fre90encies. +or/aro0nd is to sample the data as 2 demonstrated .elo+. if self.co0nter : 3 $$ 1: print ;&::s, '::s, (::s; : !self.rotation.), self.rotation.y, self.rotation.<" self.co0nter $ self.co0nter = > def r0n!self": self.rotation.start#listenin8!" if ##name## $$ '##main##': d $ Demo pp!" d.r0n!" e32.ao#sleep!3" d.rotation.stop#listenin8!" print ;?)itin8 @otation;