/
sensorhandler_qtmob.cpp
174 lines (153 loc) · 5.35 KB
/
sensorhandler_qtmob.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
@file sensorhandler_qtmob.cpp
@brief sensor handler
<p>
Copyright (C) 2011 Nokia Corporation
@author Antti Virtanen <antti.i.virtanen@nokia.com>
@author Lihan Guo <ext-lihan.4.guo@nokia.com>
This file is part of Sensord.
Sensord is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License
version 2.1 as published by the Free Software Foundation.
Sensord is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Sensord. If not, see <http://www.gnu.org/licenses/>.
</p>
*/
#include "sensorhandler_qtmob.h"
#include "logging.h"
SensorHandler::SensorHandler(const QString& sensorName, QObject *parent) :
AbstractSensorHandler(sensorName, parent),
m_sensor(NULL)
{
if (sensorName_ == "compasssensor")
{
m_sensor = new QCompass();
connect(m_sensor, SIGNAL(readingChanged()),
this, SLOT(receivedCompassData()));
}
else if (sensorName_ == "magnetometersensor")
{
m_sensor = new QMagnetometer();
connect(m_sensor, SIGNAL(readingChanged()),
this, SLOT(receivedMagnetometerData()));
}
else if (sensorName_ == "orientationsensor")
{
m_sensor = new QOrientationSensor();
connect(m_sensor, SIGNAL(readingChanged()),
this, SLOT(receivedOrientationData()));
}
else if (sensorName_ == "accelerometersensor")
{
m_sensor = new QAccelerometer();
connect(m_sensor, SIGNAL(readingChanged()),
this, SLOT(receivedAccelerometerData()));
}
else if (sensorName_ == "alssensor")
{
m_sensor = new QAmbientLightSensor();
connect(m_sensor, SIGNAL(readingChanged()),
this, SLOT(receivedAlsData()));
}
else if (sensorName_ == "rotationsensor")
{
m_sensor = new QRotationSensor();
connect(m_sensor, SIGNAL(readingChanged()),
this, SLOT(receivedRotationData()));
}
else if (sensorName_ == "tapsensor")
{
m_sensor = new QTapSensor();
connect(m_sensor, SIGNAL(readingChanged()),
this, SLOT(receivedTapData()));
}
else if (sensorName_ == "proximitysensor")
{
m_sensor = new QProximitySensor();
connect(m_sensor, SIGNAL(readingChanged()),
this, SLOT(receivedProximityData()));
}
m_sensor->setProperty("alwaysOn", standbyoverride_);
m_sensor->setProperty("bufferSize", buffersize_);
m_sensor->setDataRate(interval_ ? 1000 / interval_ : 0);
}
SensorHandler::~SensorHandler()
{
delete m_sensor;
}
void SensorHandler::receivedAccelerometerData()
{
QAccelerometerReading* data = (QAccelerometerReading*) m_sensor->reading();
++dataCount_;
sensordLogT() << sensorName_ << " sample " << dataCount_ << ": "
<< "x " << data->x() << "y " << data->y() << "z " << data->z();
}
void SensorHandler::receivedCompassData()
{
QCompassReading* data = (QCompassReading*) m_sensor->reading();
++dataCount_;
sensordLogT() << sensorName_ << " sample " << dataCount_ << ": "
<< " azimuth: " << data->azimuth() << "calibrationLevel: " << data-> calibrationLevel();
}
void SensorHandler::receivedAlsData()
{
QAmbientLightReading* data = (QAmbientLightReading*) m_sensor->reading();
++dataCount_;
sensordLogT() << sensorName_ << " sample " << dataCount_ << ": "
<< "lightLevel " << data->lightLevel();
}
void SensorHandler::receivedMagnetometerData()
{
QMagnetometerReading* data = (QMagnetometerReading*) m_sensor->reading();
++dataCount_;
sensordLogT() << sensorName_ << " sample " << dataCount_ << ": "
<< "x " << data->x() << "y " << data->y() << "z " << data->z()
<< " calibrationLevel" << data->calibrationLevel();
}
void SensorHandler::receivedOrientationData()
{
QOrientationReading* data = (QOrientationReading*) m_sensor->reading();
++dataCount_;
sensordLogT() << sensorName_ << " sample " << dataCount_ << ": "
<< "orientation " << data->orientation();
}
void SensorHandler::receivedRotationData()
{
QRotationReading* data = (QRotationReading*) m_sensor->reading();
++dataCount_;
sensordLogT() << sensorName_ << " sample " << dataCount_ << ": "
<< "x " << data->x() << "y " << data->y() << "z " << data->z();
}
void SensorHandler::receivedTapData()
{
QTapReading* data = (QTapReading*) m_sensor->reading();
++dataCount_;
sensordLogT() << sensorName_ << " sample " << dataCount_ << ": "
<< "DoubleTap " << data->isDoubleTap();
}
void SensorHandler::receivedProximityData()
{
QProximityReading* data = (QProximityReading*) m_sensor->reading();
++dataCount_;
sensordLogT() << sensorName_ << " sample " << dataCount_ << ": "
<< "Close " << data->close();
}
bool SensorHandler::startClient()
{
if (m_sensor->start())
return true;
return false;
}
bool SensorHandler::init(const QStringList&)
{
return true;
}
bool SensorHandler::stopClient()
{
m_sensor->stop();
return true;
}