|
|
@ -9,8 +9,10 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <sensormanagerinterface.h> |
|
|
|
#include <sensormanagerinterface.h> |
|
|
|
#include <orientationsensor_i.h> |
|
|
|
#include <orientationsensor_i.h> |
|
|
|
|
|
|
|
#include <accelerometersensor_i.h> |
|
|
|
|
|
|
|
|
|
|
|
static AbstractSensorChannelInterface *iface; |
|
|
|
static AbstractSensorChannelInterface *ifaceOrientation; |
|
|
|
|
|
|
|
static AbstractSensorChannelInterface *ifaceAccelerometer; |
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
|
@ -23,6 +25,36 @@ void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) |
|
|
|
registrar.RegisterMethodChannel("sensors_plus_aurora", |
|
|
|
registrar.RegisterMethodChannel("sensors_plus_aurora", |
|
|
|
MethodCodecType::Standard, |
|
|
|
MethodCodecType::Standard, |
|
|
|
[this](const MethodCall &call) { this->onMethodCall(call); }); |
|
|
|
[this](const MethodCall &call) { this->onMethodCall(call); }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
registrar.RegisterEventChannel( |
|
|
|
|
|
|
|
"sensors_aurora_orientation", |
|
|
|
|
|
|
|
MethodCodecType::Standard, |
|
|
|
|
|
|
|
[this](const Encodable &) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this->m_isSendSensorOrientation = true; |
|
|
|
|
|
|
|
onListenSensorOrientation(); |
|
|
|
|
|
|
|
return EventResponse(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
[this](const Encodable &) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this->m_isSendSensorOrientation = false; |
|
|
|
|
|
|
|
return EventResponse(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
registrar.RegisterEventChannel( |
|
|
|
|
|
|
|
"sensors_aurora_accelerometer", |
|
|
|
|
|
|
|
MethodCodecType::Standard, |
|
|
|
|
|
|
|
[this](const Encodable &) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this->m_isSendSensorAccelerometer = true; |
|
|
|
|
|
|
|
onListenSensorAccelerometer(); |
|
|
|
|
|
|
|
return EventResponse(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
[this](const Encodable &) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this->m_isSendSensorAccelerometer = false; |
|
|
|
|
|
|
|
return EventResponse(); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::onMethodCall(const MethodCall &call) |
|
|
|
void SensorsPlusAuroraPlugin::onMethodCall(const MethodCall &call) |
|
|
@ -30,17 +62,16 @@ void SensorsPlusAuroraPlugin::onMethodCall(const MethodCall &call) |
|
|
|
const auto &method = call.GetMethod(); |
|
|
|
const auto &method = call.GetMethod(); |
|
|
|
|
|
|
|
|
|
|
|
if (method == "listenSensor") { |
|
|
|
if (method == "listenSensor") { |
|
|
|
onListenSensor(call); |
|
|
|
// onListenSensor();
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unimplemented(call); |
|
|
|
unimplemented(call); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::onListenSensor(const MethodCall &call) |
|
|
|
void SensorsPlusAuroraPlugin::onListenSensorOrientation() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (iface != nullptr) { |
|
|
|
if (ifaceOrientation != nullptr) { |
|
|
|
unimplemented(call); |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -58,28 +89,80 @@ void SensorsPlusAuroraPlugin::onListenSensor(const MethodCall &call) |
|
|
|
|
|
|
|
|
|
|
|
sm.registerSensorInterface<OrientationSensorChannelInterface>("orientationsensor"); |
|
|
|
sm.registerSensorInterface<OrientationSensorChannelInterface>("orientationsensor"); |
|
|
|
|
|
|
|
|
|
|
|
iface = OrientationSensorChannelInterface::interface("orientationsensor"); |
|
|
|
ifaceOrientation = OrientationSensorChannelInterface::interface("orientationsensor"); |
|
|
|
qDebug() << "iface -> " << iface->thread(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!iface) { |
|
|
|
if (!ifaceOrientation) { |
|
|
|
qDebug() << "Cannot get OrientationSensorChannelInterface"; |
|
|
|
qDebug() << "Cannot get OrientationSensorChannelInterface"; |
|
|
|
exit(0); |
|
|
|
exit(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
connect(iface, SIGNAL(orientationChanged(const Unsigned&)), |
|
|
|
connect(ifaceOrientation, |
|
|
|
this, SLOT(receivedData(const Unsigned&))); |
|
|
|
SIGNAL(orientationChanged(const Unsigned&)), |
|
|
|
|
|
|
|
this, |
|
|
|
|
|
|
|
SLOT(eventSensorOrientation(const Unsigned&)) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
qDebug() << "Created sensor: " << iface->description(); |
|
|
|
ifaceOrientation->start(); |
|
|
|
iface->start(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
qDebug() << "Received data start"; |
|
|
|
void SensorsPlusAuroraPlugin::eventSensorOrientation(const Unsigned &data) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (this->m_isSendSensorOrientation) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
EventChannel("sensors_aurora_orientation", MethodCodecType::Standard) |
|
|
|
|
|
|
|
.SendEvent(data.x()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unimplemented(call); |
|
|
|
void SensorsPlusAuroraPlugin::onListenSensorAccelerometer() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (ifaceAccelerometer != nullptr) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SensorManagerInterface &sm = SensorManagerInterface::instance(); |
|
|
|
|
|
|
|
if (!sm.isValid()) { |
|
|
|
|
|
|
|
qDebug() << "Failed to create SensorManagerInterface"; |
|
|
|
|
|
|
|
exit(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QDBusReply<bool> reply(sm.loadPlugin("accelerometersensor")); |
|
|
|
|
|
|
|
if (!reply.isValid() || !reply.value()) { |
|
|
|
|
|
|
|
qDebug() << "Failed to load plugin"; |
|
|
|
|
|
|
|
exit(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sm.registerSensorInterface<AccelerometerSensorChannelInterface>("accelerometersensor"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ifaceAccelerometer = AccelerometerSensorChannelInterface::interface("accelerometersensor"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ifaceAccelerometer) { |
|
|
|
|
|
|
|
qDebug() << "Cannot get AccelerometerSensorChannelInterface"; |
|
|
|
|
|
|
|
exit(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(ifaceAccelerometer, |
|
|
|
|
|
|
|
SIGNAL(dataAvailable(const XYZ&)), |
|
|
|
|
|
|
|
this, |
|
|
|
|
|
|
|
SLOT(eventSensorAccelerometer(const XYZ&)) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ifaceAccelerometer->start(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::receivedData(const Unsigned &data) |
|
|
|
void SensorsPlusAuroraPlugin::eventSensorAccelerometer(const XYZ& data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
qDebug() << "receivedData: " << data.x(); |
|
|
|
if (this->m_isSendSensorAccelerometer) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::vector<Encodable> result; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.push_back(data.x()); |
|
|
|
|
|
|
|
result.push_back(data.y()); |
|
|
|
|
|
|
|
result.push_back(data.z()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EventChannel("sensors_aurora_accelerometer", MethodCodecType::Standard) |
|
|
|
|
|
|
|
.SendEvent(result); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::unimplemented(const MethodCall &call) |
|
|
|
void SensorsPlusAuroraPlugin::unimplemented(const MethodCall &call) |
|
|
|