|
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 "dummycommon.h" |
|
43 |
|
44 #ifdef Q_OS_WINCE |
|
45 #include <windows.h> |
|
46 // WINCE has <time.h> but using clock() gives a link error because |
|
47 // the function isn't actually implemented. |
|
48 #else |
|
49 #include <time.h> |
|
50 #endif |
|
51 |
|
52 dummycommon::dummycommon(QSensor *sensor) |
|
53 : QSensorBackend(sensor) |
|
54 , m_timerid(0) |
|
55 { |
|
56 } |
|
57 |
|
58 void dummycommon::start() |
|
59 { |
|
60 if (m_timerid) |
|
61 return; |
|
62 |
|
63 int dataRate = sensor()->dataRate(); |
|
64 if (dataRate == 0) { |
|
65 if (sensor()->availableDataRates().count()) |
|
66 // Use the first available rate when -1 is chosen |
|
67 dataRate = sensor()->availableDataRates().first().first; |
|
68 else |
|
69 dataRate = 1; |
|
70 } |
|
71 |
|
72 int interval = 1000 / dataRate; |
|
73 |
|
74 if (interval) |
|
75 m_timerid = startTimer(interval); |
|
76 } |
|
77 |
|
78 void dummycommon::stop() |
|
79 { |
|
80 if (m_timerid) { |
|
81 killTimer(m_timerid); |
|
82 m_timerid = 0; |
|
83 } |
|
84 } |
|
85 |
|
86 void dummycommon::timerEvent(QTimerEvent * /*event*/) |
|
87 { |
|
88 poll(); |
|
89 } |
|
90 |
|
91 qtimestamp getTimestamp() |
|
92 { |
|
93 #ifdef Q_OS_WINCE |
|
94 // This implementation is based on code found here: |
|
95 // http://social.msdn.microsoft.com/Forums/en/vssmartdevicesnative/thread/74870c6c-76c5-454c-8533-812cfca585f8 |
|
96 HANDLE currentThread = GetCurrentThread(); |
|
97 FILETIME creationTime, exitTime, kernalTime, userTime; |
|
98 GetThreadTimes(currentThread, &creationTime, &exitTime, &kernalTime, &userTime); |
|
99 |
|
100 ULARGE_INTEGER uli; |
|
101 uli.LowPart = userTime.dwLowDateTime; |
|
102 uli.HighPart = userTime.dwHighDateTime; |
|
103 ULONGLONG systemTimeInMS = uli.QuadPart/10000; |
|
104 return static_cast<qtimestamp>(systemTimeInMS); |
|
105 #else |
|
106 return clock(); |
|
107 #endif |
|
108 } |
|
109 |