|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "tapsensorsym.h" |
|
43 /** |
|
44 * set the id of the Tap sensor |
|
45 */ |
|
46 char const * const CTapSensorSym::id("sym.tap"); |
|
47 |
|
48 /** |
|
49 * Factory function, this is used to create the tap sensor object |
|
50 * @return CTapSensorSym if successful, leaves on failure |
|
51 */ |
|
52 CTapSensorSym* CTapSensorSym::NewL(QSensor *sensor) |
|
53 { |
|
54 CTapSensorSym* self = new (ELeave) CTapSensorSym(sensor); |
|
55 CleanupStack::PushL(self); |
|
56 self->ConstructL(); |
|
57 CleanupStack::Pop(); |
|
58 return self; |
|
59 } |
|
60 |
|
61 /** |
|
62 * Destructor |
|
63 * Closes the backend resources |
|
64 */ |
|
65 CTapSensorSym::~CTapSensorSym() |
|
66 { |
|
67 Close(); |
|
68 } |
|
69 |
|
70 /** |
|
71 * Default constructor |
|
72 */ |
|
73 CTapSensorSym::CTapSensorSym(QSensor *sensor):CSensorBackendSym(sensor) |
|
74 { |
|
75 setReading<QTapReading>(&iReading); |
|
76 iBackendData.iSensorType = KSensrvChannelTypeIdAccelerometerDoubleTappingData; |
|
77 } |
|
78 /* |
|
79 * RecvData is used to retrieve the sensor reading from sensor server |
|
80 * It is implemented here to handle tap sensor specific |
|
81 * reading data and provides conversion and utility code |
|
82 */ |
|
83 void CTapSensorSym::RecvData(CSensrvChannel &aChannel) |
|
84 { |
|
85 TPckg<TSensrvTappingData> tappkg( iData ); |
|
86 TInt ret = aChannel.GetData( tappkg ); |
|
87 if(KErrNone != ret) |
|
88 { |
|
89 // If there is no reading available, return without setting |
|
90 return; |
|
91 } |
|
92 // Get a lock on the reading data |
|
93 iBackendData.iReadingLock.Wait(); |
|
94 //Mapping device tap sensor enum values to Qt tap sensor enum values |
|
95 switch (iData.iDirection) |
|
96 { |
|
97 // Indicates a tap on positive X axis |
|
98 case KSensrvAccelerometerDirectionXplus: |
|
99 { |
|
100 iReading.setTapDirection(QTapReading::X_Pos); |
|
101 } |
|
102 break; |
|
103 // Indicates a tap on negative X axis |
|
104 case KSensrvAccelerometerDirectionXminus: |
|
105 { |
|
106 iReading.setTapDirection(QTapReading::X_Neg); |
|
107 } |
|
108 break; |
|
109 // Indicates a tap on positive Y axis |
|
110 case KSensrvAccelerometerDirectionYplus: |
|
111 { |
|
112 iReading.setTapDirection(QTapReading::Y_Pos); |
|
113 } |
|
114 break; |
|
115 // Indicates a tap on negative Y axis |
|
116 case KSensrvAccelerometerDirectionYminus: |
|
117 { |
|
118 iReading.setTapDirection(QTapReading::Y_Neg); |
|
119 } |
|
120 break; |
|
121 // Indicates a tap on positive Z axis |
|
122 case KSensrvAccelerometerDirectionZplus: |
|
123 { |
|
124 iReading.setTapDirection(QTapReading::Z_Pos); |
|
125 } |
|
126 break; |
|
127 // Indicates a tap on negative Z axis |
|
128 case KSensrvAccelerometerDirectionZminus: |
|
129 { |
|
130 iReading.setTapDirection(QTapReading::Z_Neg); |
|
131 } |
|
132 break; |
|
133 default: |
|
134 { |
|
135 // Indicates a tap on X axis |
|
136 if(iData.iDirection==KSensrvAccelerometerDirectionXplus|KSensrvAccelerometerDirectionXminus) |
|
137 { |
|
138 iReading.setTapDirection(QTapReading::X); |
|
139 } |
|
140 // Indicates a tap on Y axis |
|
141 else if(iData.iDirection==KSensrvAccelerometerDirectionYplus|KSensrvAccelerometerDirectionYminus) |
|
142 { |
|
143 iReading.setTapDirection(QTapReading::Y); |
|
144 } |
|
145 // Indicates a tap on Z axis |
|
146 else if(iData.iDirection==KSensrvAccelerometerDirectionZplus|KSensrvAccelerometerDirectionZminus) |
|
147 { |
|
148 iReading.setTapDirection(QTapReading::Z); |
|
149 } |
|
150 // Undefined value |
|
151 else |
|
152 { |
|
153 iReading.setTapDirection(QTapReading::Undefined); |
|
154 } |
|
155 } |
|
156 } |
|
157 //Set the type of tap to be double tap |
|
158 iReading.setDoubleTap(true); |
|
159 iReading.setTimestamp(iData.iTimeStamp.Int64()); |
|
160 // Release the lock |
|
161 iBackendData.iReadingLock.Signal(); |
|
162 } |
|
163 /** |
|
164 * Second phase constructor |
|
165 * Initialize the backend resources |
|
166 */ |
|
167 void CTapSensorSym::ConstructL() |
|
168 { |
|
169 InitializeL(); |
|
170 } |
|
171 |