Professional Documents
Culture Documents
2 (16) Python for s60 Sensor module S60 sensor framework support
TA !" #F $#%T"%TS
. (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+
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
] where channel_id- channel_type and channel_name w&ll ha)e the respe't&)e 'hannel;s )alues as str&n(s+
< (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
6 (16) Python for s60 Sensor module S60 sensor framework support
E (16) Python for s60 Sensor module S60 sensor framework support
F (16) Python for s60 Sensor module S60 sensor framework support
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+
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+
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
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
/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
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
/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
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
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
?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*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;