4#include <QGuiApplication>
9#include "tools/SO3Util.h"
10#include <scolPlugin.h>
15# if defined(APPLE_IOS)
16Q_IMPORT_PLUGIN(IOSSensorPlugin)
17# elif defined(LINUX) || defined(RPI)
18Q_IMPORT_PLUGIN(LinuxSensorPlugin)
20Q_IMPORT_PLUGIN(genericSensorPlugin)
32SQSensor::SQSensor() : QObject(QCoreApplication::instance()),
SSensor()
37SQSensor::SQSensor(SSensorType type) : QObject(QCoreApplication::instance()),
SSensor(type)
41 case SSensorType::SSENSOR_TYPE_ACCELEROMETER:
43 mQSensor =
new QAccelerometer(
this);
48 case SSensorType::SSENSOR_TYPE_GYROSCOPE:
50 mQSensor =
new QGyroscope(
this);
54 case SSensorType::SSENSOR_TYPE_MAGNETIC_FIELD:
56 mQSensor =
new QMagnetometer(
this);
60 case SSensorType::SSENSOR_TYPE_LIGHT:
62 mQSensor =
new QLightSensor(
this);
66 case SSensorType::SSENSOR_TYPE_PROXIMITY:
68 mQSensor =
new QProximitySensor(
this);
78 connect(mQSensor, SIGNAL(readingChanged()),
this, SLOT(updateData()));
79 mQSensor->connectToBackend();
88 SAFE_DELETE(mQSensor);
92void SQSensor::updateData()
94 if (mEnabled && mQSensor->isActive())
97 memset(&formatedData, 0,
sizeof(formatedData));
100 QSensorReading* reading = mQSensor->reading();
101 formatedData.delta = GetElapsedTime(reading->timestamp());
105 case SSensorType::SSENSOR_TYPE_ACCELEROMETER:
107 QAccelerometerReading* reading =
static_cast<QAccelerometerReading*
>(reading);
108 formatedData.vec3.x = reading->x();
109 formatedData.vec3.y = reading->y();
110 formatedData.vec3.z = reading->z();
112 CallSensorCb(formatedData);
113 if (manager->IsEnabled(SSENSOR_TYPE_ORIENTATION))
117 orientationTracker->processAcceleration(formatedData.vec3, GetTickCountNano());
122 case SSensorType::SSENSOR_TYPE_GYROSCOPE:
124 QGyroscopeReading* reading =
static_cast<QGyroscopeReading*
>(reading);
126 formatedData.vec3.x = reading->x() * DEG_TO_RAD;
127 formatedData.vec3.y = reading->y() * DEG_TO_RAD;
128 formatedData.vec3.z = reading->z() * DEG_TO_RAD;
130 CallSensorCb(formatedData);
132 if (manager->IsEnabled(SSENSOR_TYPE_ORIENTATION))
136 orientationTracker->processGyro(formatedData.vec3, GetTickCountNano());
141 case SSensorType::SSENSOR_TYPE_MAGNETIC_FIELD:
143 QMagnetometerReading* reading =
static_cast<QMagnetometerReading*
>(reading);
144 formatedData.vec3.x = reading->x();
145 formatedData.vec3.y = reading->y();
146 formatedData.vec3.z = reading->z();
148 CallSensorCb(formatedData);
158 case SSensorType::SSENSOR_TYPE_LIGHT:
160 QLightReading* reading =
static_cast<QLightReading*
>(reading);
161 formatedData.fval = reading->lux();
163 CallSensorCb(formatedData);
166 case SSensorType::SSENSOR_TYPE_PROXIMITY:
168 QProximityReading* reading =
static_cast<QProximityReading*
>(reading);
169 formatedData.fval = (reading->close()) ? 1.0f : 0.0f;
171 CallSensorCb(formatedData);
179 SetData(formatedData);
193QSensor* SQSensor::GetQSensor()
198void SQSensor::SetQSensor(QSensor* aSensor)
208 mSensorList = std::set<SSensor*>();
209 QList<QByteArray> sensorTypes = QSensor::sensorTypes();
211 if (sensorTypes.contains(QAccelerometer::type))
213 MMechostr(MSKDEBUG,
"SSensorManager() : an accelerometer has been found\n");
215 mSensorList.insert(sensor);
218 if (sensorTypes.contains(QGyroscope::type))
220 MMechostr(MSKDEBUG,
"SSensorManager() : a gyrometer has been found\n");
222 mSensorList.insert(sensor);
225 if (sensorTypes.contains(QMagnetometer::type))
227 MMechostr(MSKDEBUG,
"SSensorManager() : a magnetometer has been found\n");
229 mSensorList.insert(sensor);
232 if (sensorTypes.contains(QLightSensor::type))
234 MMechostr(MSKDEBUG,
"SSensorManager() : a light sensor has been found\n");
236 mSensorList.insert(sensor);
239 if (sensorTypes.contains(QIRProximitySensor::type))
241 MMechostr(MSKDEBUG,
"SSensorManager() : a proximity sensor has been found\n");
243 mSensorList.insert(sensor);
247SQSensorManager::~SQSensorManager()
249 for (std::set<SSensor*>::iterator it = mSensorList.begin(); it != mSensorList.end(); ++it)
255 mSingletonInstance = NULL;
258int SQSensorManager::SetSensorEnable(SSensorType sensorType,
bool state)
260 boost::shared_lock< boost::shared_mutex > lock(mGlobalMutex);
262 if (sensorType == SSENSOR_TYPE_ORIENTATION && IsAvailable(SSENSOR_TYPE_ORIENTATION))
266 int orient = ROTATION_0;
267 Qt::ScreenOrientation qrot = QGuiApplication::primaryScreen()->primaryOrientation();
270 case Qt::LandscapeOrientation:
271 orient = ROTATION_90;
274 case Qt::InvertedPortraitOrientation:
275 orient = ROTATION_180;
278 case Qt::InvertedLandscapeOrientation:
279 orient = ROTATION_270;
286 GetOrientationTracker()->startTracking((DeviceOrientation)orient);
289 GetOrientationTracker()->stopTracking();
291 SetSensorEnable(SSENSOR_TYPE_MAGNETIC_FIELD, state);
292 return SetSensorEnable(SSENSOR_TYPE_ACCELEROMETER, state) + SetSensorEnable(SSENSOR_TYPE_GYROSCOPE, state);
297 SSensor* sensor = GetSensorByType(sensorType);
300 QSensor* aSensor = ((
SQSensor*) sensor)->GetQSensor();
303 sensor->SetEnabled(state);
306 aSensor->setDataRate(100);
329void SQSensorManager::Vibrate(
long millis)
333void SQSensorManager::StartVibration()
337void SQSensorManager::VibratePattern(std::vector<int> pattern,
bool loop)
343void SQSensorManager::StopVibration()
347void SQSensorManager::StartLocationService()
352void SQSensorManager::StopLocationService()
357bool SQSensorManager::GetLocation(
float &longitude,
float &latitude,
float &altitude)