|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 "ambientlightsensorsym.h" |
|
43 |
|
44 /** |
|
45 * set the id of the ambient light sensor |
|
46 */ |
|
47 const char *CAmbientLightSensorSym::id("sym.ambientlight"); |
|
48 |
|
49 /** |
|
50 * Factory function, this is used to create the ambient light sensor object |
|
51 * @return CAmbientLightSensorSym if successful, leaves on failure |
|
52 */ |
|
53 CAmbientLightSensorSym* CAmbientLightSensorSym::NewL(QSensor *sensor) |
|
54 { |
|
55 CAmbientLightSensorSym* self = new (ELeave) CAmbientLightSensorSym(sensor); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 /** |
|
63 * Destructor |
|
64 * Closes the backend resources |
|
65 */ |
|
66 CAmbientLightSensorSym::~CAmbientLightSensorSym() |
|
67 { |
|
68 // Release the backend resources |
|
69 Close(); |
|
70 } |
|
71 |
|
72 /** |
|
73 * Default constructor |
|
74 */ |
|
75 CAmbientLightSensorSym::CAmbientLightSensorSym(QSensor *sensor):CSensorBackendSym(sensor) |
|
76 { |
|
77 setReading<QAmbientLightReading>(&iReading); |
|
78 iBackendData.iSensorType = KSensrvChannelTypeIdAmbientLightData; |
|
79 } |
|
80 |
|
81 /* |
|
82 * RecvData is used to retrieve the sensor reading from sensor server |
|
83 * It is implemented here to handle ambient light sensor specific |
|
84 * reading data and provides conversion and utility code |
|
85 */ |
|
86 void CAmbientLightSensorSym::RecvData(CSensrvChannel &aChannel) |
|
87 { |
|
88 TPckg<TSensrvAmbientLightData> lightpkg( iData ); |
|
89 TInt ret = aChannel.GetData( lightpkg ); |
|
90 if(KErrNone != ret) |
|
91 { |
|
92 // If there is no reading available, return without setting |
|
93 return; |
|
94 } |
|
95 // Get a lock on the reading data |
|
96 iBackendData.iReadingLock.Wait(); |
|
97 switch (iData.iAmbientLight) |
|
98 { |
|
99 case TSensrvAmbientLightData::KAmbientLightVeryDark: |
|
100 case TSensrvAmbientLightData::KAmbientLightDark: |
|
101 { |
|
102 iReading.setLightLevel(QAmbientLightReading::Dark); |
|
103 } |
|
104 break; |
|
105 |
|
106 case TSensrvAmbientLightData::KAmbientLightTwilight: |
|
107 { |
|
108 iReading.setLightLevel(QAmbientLightReading::Twilight); |
|
109 } |
|
110 break; |
|
111 |
|
112 case TSensrvAmbientLightData::KAmbientLightLight: |
|
113 { |
|
114 iReading.setLightLevel(QAmbientLightReading::Light); |
|
115 } |
|
116 break; |
|
117 |
|
118 case TSensrvAmbientLightData::KAmbientLightBright: |
|
119 { |
|
120 iReading.setLightLevel(QAmbientLightReading::Bright); |
|
121 } |
|
122 break; |
|
123 |
|
124 case TSensrvAmbientLightData::KAmbientLightSunny: |
|
125 { |
|
126 iReading.setLightLevel(QAmbientLightReading::Sunny); |
|
127 } |
|
128 break; |
|
129 |
|
130 default: |
|
131 { |
|
132 iReading.setLightLevel(QAmbientLightReading::Undefined); |
|
133 } |
|
134 } |
|
135 // Set the timestamp |
|
136 iReading.setTimestamp(iData.iTimeStamp.Int64()); |
|
137 // Release the lock |
|
138 iBackendData.iReadingLock.Signal(); |
|
139 } |
|
140 |
|
141 /** |
|
142 * Second phase constructor |
|
143 * Initialize the backend resources |
|
144 */ |
|
145 void CAmbientLightSensorSym::ConstructL() |
|
146 { |
|
147 //Initialize the backend resources |
|
148 InitializeL(); |
|
149 } |
|
150 |