|
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 tools applications of the Qt Toolkit. |
|
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 "deviceorientation.h" |
|
43 |
|
44 #include <e32base.h> |
|
45 #include <sensrvchannelfinder.h> |
|
46 #include <sensrvdatalistener.h> |
|
47 #include <sensrvchannel.h> |
|
48 #include <sensrvorientationsensor.h> |
|
49 |
|
50 class SymbianOrientation : public DeviceOrientation, public MSensrvDataListener |
|
51 { |
|
52 Q_OBJECT |
|
53 public: |
|
54 SymbianOrientation() |
|
55 : DeviceOrientation(), m_current(UnknownOrientation), m_sensorChannel(0) |
|
56 { |
|
57 TRAP_IGNORE(initL()); |
|
58 if (!m_sensorChannel) |
|
59 qWarning("No valid sensors found."); |
|
60 } |
|
61 |
|
62 ~SymbianOrientation() |
|
63 { |
|
64 if (m_sensorChannel) { |
|
65 m_sensorChannel->StopDataListening(); |
|
66 m_sensorChannel->CloseChannel(); |
|
67 delete m_sensorChannel; |
|
68 } |
|
69 } |
|
70 |
|
71 void initL() |
|
72 { |
|
73 CSensrvChannelFinder *channelFinder = CSensrvChannelFinder::NewLC(); |
|
74 RSensrvChannelInfoList channelInfoList; |
|
75 CleanupClosePushL(channelInfoList); |
|
76 |
|
77 TSensrvChannelInfo searchConditions; |
|
78 searchConditions.iChannelType = KSensrvChannelTypeIdOrientationData; |
|
79 channelFinder->FindChannelsL(channelInfoList, searchConditions); |
|
80 |
|
81 for (int i = 0; i < channelInfoList.Count(); ++i) { |
|
82 TRAPD(error, m_sensorChannel = CSensrvChannel::NewL(channelInfoList[i])); |
|
83 if (!error) |
|
84 TRAP(error, m_sensorChannel->OpenChannelL()); |
|
85 if (!error) { |
|
86 TRAP(error, m_sensorChannel->StartDataListeningL(this, 1, 1, 0)); |
|
87 break; |
|
88 } |
|
89 if (error) { |
|
90 delete m_sensorChannel; |
|
91 m_sensorChannel = 0; |
|
92 } |
|
93 } |
|
94 |
|
95 channelInfoList.Close(); |
|
96 CleanupStack::Pop(&channelInfoList); |
|
97 CleanupStack::PopAndDestroy(channelFinder); |
|
98 } |
|
99 |
|
100 Orientation orientation() const |
|
101 { |
|
102 return m_current; |
|
103 } |
|
104 |
|
105 void setOrientation(Orientation) { } |
|
106 |
|
107 private: |
|
108 DeviceOrientation::Orientation m_current; |
|
109 CSensrvChannel *m_sensorChannel; |
|
110 |
|
111 void DataReceived(CSensrvChannel &channel, TInt count, TInt dataLost) |
|
112 { |
|
113 if (channel.GetChannelInfo().iChannelType == KSensrvChannelTypeIdOrientationData) { |
|
114 TSensrvOrientationData data; |
|
115 for (int i = 0; i < count; ++i) { |
|
116 TPckgBuf<TSensrvOrientationData> dataBuf; |
|
117 channel.GetData(dataBuf); |
|
118 data = dataBuf(); |
|
119 Orientation o = UnknownOrientation; |
|
120 switch (data.iDeviceOrientation) { |
|
121 case TSensrvOrientationData::EOrientationDisplayUp: |
|
122 o = Portrait; |
|
123 break; |
|
124 case TSensrvOrientationData::EOrientationDisplayRightUp: |
|
125 o = Landscape; |
|
126 break; |
|
127 case TSensrvOrientationData::EOrientationDisplayLeftUp: |
|
128 case TSensrvOrientationData::EOrientationDisplayDown: |
|
129 case TSensrvOrientationData::EOrientationUndefined: |
|
130 case TSensrvOrientationData::EOrientationDisplayUpwards: |
|
131 case TSensrvOrientationData::EOrientationDisplayDownwards: |
|
132 default: |
|
133 break; |
|
134 } |
|
135 |
|
136 if (m_current != o && o != UnknownOrientation) { |
|
137 m_current = o; |
|
138 emit orientationChanged(); |
|
139 } |
|
140 } |
|
141 } |
|
142 } |
|
143 |
|
144 void DataError(CSensrvChannel& /* channel */, TSensrvErrorSeverity /* error */) |
|
145 { |
|
146 } |
|
147 |
|
148 void GetDataListenerInterfaceL(TUid /* interfaceUid */, TAny*& /* interface */) |
|
149 { |
|
150 } |
|
151 }; |
|
152 |
|
153 |
|
154 DeviceOrientation* DeviceOrientation::instance() |
|
155 { |
|
156 static SymbianOrientation *o = 0; |
|
157 if (!o) |
|
158 o = new SymbianOrientation; |
|
159 return o; |
|
160 } |
|
161 |
|
162 #include "deviceorientation_symbian.moc" |