[844] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
| 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
| 6 | **
|
---|
| 7 | ** This file is part of the tools applications of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 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 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
| 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), m_channelOpen(false)
|
---|
| 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 | m_channelOpen = true;
|
---|
| 88 | break;
|
---|
| 89 | }
|
---|
| 90 | if (error) {
|
---|
| 91 | delete m_sensorChannel;
|
---|
| 92 | m_sensorChannel = 0;
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | channelInfoList.Close();
|
---|
| 97 | CleanupStack::Pop(&channelInfoList);
|
---|
| 98 | CleanupStack::PopAndDestroy(channelFinder);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | Orientation orientation() const
|
---|
| 102 | {
|
---|
| 103 | return m_current;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | void setOrientation(Orientation) { }
|
---|
| 107 |
|
---|
| 108 | private:
|
---|
| 109 | DeviceOrientation::Orientation m_current;
|
---|
| 110 | CSensrvChannel *m_sensorChannel;
|
---|
| 111 | bool m_channelOpen;
|
---|
| 112 | void pauseListening() {
|
---|
| 113 | if (m_sensorChannel && m_channelOpen) {
|
---|
| 114 | m_sensorChannel->StopDataListening();
|
---|
| 115 | m_sensorChannel->CloseChannel();
|
---|
| 116 | m_channelOpen = false;
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | void resumeListening() {
|
---|
| 121 | if (m_sensorChannel && !m_channelOpen) {
|
---|
| 122 | TRAPD(error, m_sensorChannel->OpenChannelL());
|
---|
| 123 | if (!error) {
|
---|
| 124 | TRAP(error, m_sensorChannel->StartDataListeningL(this, 1, 1, 0));
|
---|
| 125 | if (!error) {
|
---|
| 126 | m_channelOpen = true;
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 | if (error) {
|
---|
| 130 | delete m_sensorChannel;
|
---|
| 131 | m_sensorChannel = 0;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | void DataReceived(CSensrvChannel &channel, TInt count, TInt dataLost)
|
---|
| 137 | {
|
---|
| 138 | Q_UNUSED(dataLost)
|
---|
| 139 | if (channel.GetChannelInfo().iChannelType == KSensrvChannelTypeIdOrientationData) {
|
---|
| 140 | TSensrvOrientationData data;
|
---|
| 141 | for (int i = 0; i < count; ++i) {
|
---|
| 142 | TPckgBuf<TSensrvOrientationData> dataBuf;
|
---|
| 143 | channel.GetData(dataBuf);
|
---|
| 144 | data = dataBuf();
|
---|
| 145 | Orientation orientation = UnknownOrientation;
|
---|
| 146 | switch (data.iDeviceOrientation) {
|
---|
| 147 | case TSensrvOrientationData::EOrientationDisplayUp:
|
---|
| 148 | orientation = Portrait;
|
---|
| 149 | break;
|
---|
| 150 | case TSensrvOrientationData::EOrientationDisplayRightUp:
|
---|
| 151 | orientation = Landscape;
|
---|
| 152 | break;
|
---|
| 153 | case TSensrvOrientationData::EOrientationDisplayLeftUp:
|
---|
| 154 | orientation = LandscapeInverted;
|
---|
| 155 | break;
|
---|
| 156 | case TSensrvOrientationData::EOrientationDisplayDown:
|
---|
| 157 | orientation = PortraitInverted;
|
---|
| 158 | break;
|
---|
| 159 | case TSensrvOrientationData::EOrientationUndefined:
|
---|
| 160 | case TSensrvOrientationData::EOrientationDisplayUpwards:
|
---|
| 161 | case TSensrvOrientationData::EOrientationDisplayDownwards:
|
---|
| 162 | default:
|
---|
| 163 | break;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | if (m_current != orientation && orientation != UnknownOrientation) {
|
---|
| 167 | m_current = orientation;
|
---|
| 168 | emit orientationChanged();
|
---|
| 169 | }
|
---|
| 170 | }
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | void DataError(CSensrvChannel& /* channel */, TSensrvErrorSeverity /* error */)
|
---|
| 175 | {
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | void GetDataListenerInterfaceL(TUid /* interfaceUid */, TAny*& /* interface */)
|
---|
| 179 | {
|
---|
| 180 | }
|
---|
| 181 | };
|
---|
| 182 |
|
---|
| 183 |
|
---|
| 184 | DeviceOrientation* DeviceOrientation::instance()
|
---|
| 185 | {
|
---|
| 186 | static SymbianOrientation *o = 0;
|
---|
| 187 | if (!o)
|
---|
| 188 | o = new SymbianOrientation;
|
---|
| 189 | return o;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | #include "deviceorientation_symbian.moc"
|
---|