|
|
|
@ -10,164 +10,515 @@
|
|
|
|
|
#include <sensormanagerinterface.h> |
|
|
|
|
#include <orientationsensor_i.h> |
|
|
|
|
#include <accelerometersensor_i.h> |
|
|
|
|
#include <compasssensor_i.h> |
|
|
|
|
#include <tapsensor_i.h> |
|
|
|
|
#include <alssensor_i.h> |
|
|
|
|
#include <proximitysensor_i.h> |
|
|
|
|
#include <rotationsensor_i.h> |
|
|
|
|
#include <magnetometersensor_i.h> |
|
|
|
|
|
|
|
|
|
namespace KeyChannel |
|
|
|
|
{ |
|
|
|
|
constexpr auto Orientation = "sensors_plus_aurora_orientationsensor"; |
|
|
|
|
constexpr auto Accelerometer = "sensors_plus_aurora_accelerometersensor"; |
|
|
|
|
constexpr auto Compass = "sensors_plus_aurora_compasssensor"; |
|
|
|
|
constexpr auto Tap = "sensors_plus_aurora_tapsensor"; |
|
|
|
|
constexpr auto ALS = "sensors_plus_aurora_alssensor"; |
|
|
|
|
constexpr auto Proximity = "sensors_plus_aurora_proximitysensor"; |
|
|
|
|
constexpr auto Rotation = "sensors_plus_aurora_rotationsensor"; |
|
|
|
|
constexpr auto Magnetometer = "sensors_plus_aurora_magnetometersensor"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static AbstractSensorChannelInterface *ifaceOrientation; |
|
|
|
|
static AbstractSensorChannelInterface *ifaceAccelerometer; |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
constexpr auto METHOD_LISTEN_SENSOR = "listenSensor"; |
|
|
|
|
|
|
|
|
|
namespace KeySensor |
|
|
|
|
{ |
|
|
|
|
constexpr auto Orientation = "orientationsensor"; |
|
|
|
|
constexpr auto Accelerometer = "accelerometersensor"; |
|
|
|
|
constexpr auto Compass = "compasssensor"; |
|
|
|
|
constexpr auto Tap = "tapsensor"; |
|
|
|
|
constexpr auto ALS = "alssensor"; |
|
|
|
|
constexpr auto Proximity = "proximitysensor"; |
|
|
|
|
constexpr auto Rotation = "rotationsensor"; |
|
|
|
|
constexpr auto Magnetometer = "magnetometersensor"; |
|
|
|
|
} /* namespace */ |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) |
|
|
|
|
{ |
|
|
|
|
registrar.RegisterMethodChannel("sensors_plus_aurora", |
|
|
|
|
MethodCodecType::Standard, |
|
|
|
|
[this](const MethodCall &call) { this->onMethodCall(call); }); |
|
|
|
|
registrar.RegisterEventChannel( |
|
|
|
|
KeyChannel::Orientation, MethodCodecType::Standard, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ EnableSensorOrientation(); return EventResponse(); }, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ DisableSensorOrientation(); return EventResponse(); }); |
|
|
|
|
|
|
|
|
|
registrar.RegisterEventChannel( |
|
|
|
|
"sensors_aurora_orientation", |
|
|
|
|
MethodCodecType::Standard, |
|
|
|
|
KeyChannel::Accelerometer, MethodCodecType::Standard, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ |
|
|
|
|
this->m_isSendSensorOrientation = true; |
|
|
|
|
onListenSensorOrientation(); |
|
|
|
|
return EventResponse(); |
|
|
|
|
}, |
|
|
|
|
{ EnableSensorAccelerometer(); return EventResponse(); }, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ |
|
|
|
|
this->m_isSendSensorOrientation = false; |
|
|
|
|
return EventResponse(); |
|
|
|
|
}); |
|
|
|
|
{ DisableSensorAccelerometer(); return EventResponse(); }); |
|
|
|
|
|
|
|
|
|
registrar.RegisterEventChannel( |
|
|
|
|
"sensors_aurora_accelerometer", |
|
|
|
|
MethodCodecType::Standard, |
|
|
|
|
KeyChannel::Compass, MethodCodecType::Standard, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ |
|
|
|
|
this->m_isSendSensorAccelerometer = true; |
|
|
|
|
onListenSensorAccelerometer(); |
|
|
|
|
return EventResponse(); |
|
|
|
|
}, |
|
|
|
|
{ EnableSensorCompass(); return EventResponse(); }, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ DisableSensorCompass(); return EventResponse(); }); |
|
|
|
|
|
|
|
|
|
registrar.RegisterEventChannel( |
|
|
|
|
KeyChannel::Tap, MethodCodecType::Standard, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ EnableSensorTap(); return EventResponse(); }, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ DisableSensorTap(); return EventResponse(); }); |
|
|
|
|
|
|
|
|
|
registrar.RegisterEventChannel( |
|
|
|
|
KeyChannel::ALS, MethodCodecType::Standard, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ EnableSensorALS(); return EventResponse(); }, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ DisableSensorALS(); return EventResponse(); }); |
|
|
|
|
|
|
|
|
|
registrar.RegisterEventChannel( |
|
|
|
|
KeyChannel::Proximity, MethodCodecType::Standard, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ EnableSensorProximity(); return EventResponse(); }, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ DisableSensorProximity(); return EventResponse(); }); |
|
|
|
|
|
|
|
|
|
registrar.RegisterEventChannel( |
|
|
|
|
KeyChannel::Rotation, MethodCodecType::Standard, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ EnableSensorRotation(); return EventResponse(); }, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ DisableSensorRotation(); return EventResponse(); }); |
|
|
|
|
|
|
|
|
|
registrar.RegisterEventChannel( |
|
|
|
|
KeyChannel::Magnetometer, MethodCodecType::Standard, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ EnableSensorMagnetometer(); return EventResponse(); }, |
|
|
|
|
[this](const Encodable &) |
|
|
|
|
{ DisableSensorMagnetometer(); return EventResponse(); }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
bool SensorsPlusAuroraPlugin::RegisterSensorInterface(QString sensor) |
|
|
|
|
{ |
|
|
|
|
SensorManagerInterface &sm = SensorManagerInterface::instance(); |
|
|
|
|
if (!sm.isValid()) |
|
|
|
|
{ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QDBusReply<bool> reply(sm.loadPlugin(sensor)); |
|
|
|
|
if (!reply.isValid() || !reply.value()) |
|
|
|
|
{ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sm.registerSensorInterface<T>(sensor); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::EventChannelNull(std::string channel) |
|
|
|
|
{ |
|
|
|
|
this->m_isSendSensorAccelerometer = false; |
|
|
|
|
return EventResponse(); |
|
|
|
|
}); |
|
|
|
|
EventChannel(channel, MethodCodecType::Standard).SendEvent(nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::onMethodCall(const MethodCall &call) |
|
|
|
|
void SensorsPlusAuroraPlugin::EventChannelData(std::string channel, std::vector<Encodable> result) |
|
|
|
|
{ |
|
|
|
|
const auto &method = call.GetMethod(); |
|
|
|
|
EventChannel(channel, MethodCodecType::Standard).SendEvent(result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (method == "listenSensor") { |
|
|
|
|
// onListenSensor();
|
|
|
|
|
/**
|
|
|
|
|
* Orientation |
|
|
|
|
*/ |
|
|
|
|
void SensorsPlusAuroraPlugin::EnableSensorOrientation() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceOrientation == nullptr) |
|
|
|
|
{ |
|
|
|
|
if (!RegisterSensorInterface<OrientationSensorChannelInterface>(KeySensor::Orientation)) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Orientation); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unimplemented(call); |
|
|
|
|
m_ifaceOrientation = OrientationSensorChannelInterface::interface(KeySensor::Orientation); |
|
|
|
|
|
|
|
|
|
if (!m_ifaceOrientation) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Orientation); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
connect(m_ifaceOrientation, |
|
|
|
|
SIGNAL(orientationChanged(const Unsigned &)), |
|
|
|
|
this, |
|
|
|
|
SLOT(EventSensorOrientation(const Unsigned &))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceOrientation->start(); |
|
|
|
|
EventSensorOrientation(m_ifaceOrientation->orientation()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::onListenSensorOrientation() |
|
|
|
|
void SensorsPlusAuroraPlugin::DisableSensorOrientation() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceOrientation == nullptr) |
|
|
|
|
{ |
|
|
|
|
if (ifaceOrientation != nullptr) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SensorManagerInterface &sm = SensorManagerInterface::instance(); |
|
|
|
|
if (!sm.isValid()) { |
|
|
|
|
qDebug() << "Failed to create SensorManagerInterface"; |
|
|
|
|
exit(0); |
|
|
|
|
m_ifaceOrientation->stop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QDBusReply<bool> reply(sm.loadPlugin("orientationsensor")); |
|
|
|
|
if (!reply.isValid() || !reply.value()) { |
|
|
|
|
qDebug() << "Failed to load plugin"; |
|
|
|
|
exit(0); |
|
|
|
|
void SensorsPlusAuroraPlugin::EventSensorOrientation(const Unsigned &data) |
|
|
|
|
{ |
|
|
|
|
std::vector<Encodable> result; |
|
|
|
|
result.push_back(data.x()); |
|
|
|
|
EventChannelData(KeyChannel::Orientation, result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sm.registerSensorInterface<OrientationSensorChannelInterface>("orientationsensor"); |
|
|
|
|
/**
|
|
|
|
|
* Accelerometer |
|
|
|
|
*/ |
|
|
|
|
void SensorsPlusAuroraPlugin::EnableSensorAccelerometer() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceAccelerometer == nullptr) |
|
|
|
|
{ |
|
|
|
|
if (!RegisterSensorInterface<AccelerometerSensorChannelInterface>(KeySensor::Accelerometer)) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Accelerometer); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ifaceOrientation = OrientationSensorChannelInterface::interface("orientationsensor"); |
|
|
|
|
m_ifaceAccelerometer = AccelerometerSensorChannelInterface::interface(KeySensor::Accelerometer); |
|
|
|
|
|
|
|
|
|
if (!ifaceOrientation) { |
|
|
|
|
qDebug() << "Cannot get OrientationSensorChannelInterface"; |
|
|
|
|
exit(0); |
|
|
|
|
if (!m_ifaceAccelerometer) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Accelerometer); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
connect(ifaceOrientation, |
|
|
|
|
SIGNAL(orientationChanged(const Unsigned&)), |
|
|
|
|
connect(m_ifaceAccelerometer, |
|
|
|
|
SIGNAL(dataAvailable(const XYZ &)), |
|
|
|
|
this, |
|
|
|
|
SLOT(eventSensorOrientation(const Unsigned&)) |
|
|
|
|
); |
|
|
|
|
SLOT(EventSensorAccelerometer(const XYZ &))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceAccelerometer->start(); |
|
|
|
|
EventSensorAccelerometer(m_ifaceAccelerometer->get()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ifaceOrientation->start(); |
|
|
|
|
void SensorsPlusAuroraPlugin::DisableSensorAccelerometer() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceAccelerometer == nullptr) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceAccelerometer->stop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::EventSensorAccelerometer(const XYZ &data) |
|
|
|
|
{ |
|
|
|
|
std::vector<Encodable> result; |
|
|
|
|
result.push_back(data.x()); |
|
|
|
|
result.push_back(data.y()); |
|
|
|
|
result.push_back(data.z()); |
|
|
|
|
EventChannelData(KeyChannel::Accelerometer, result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::eventSensorOrientation(const Unsigned &data) |
|
|
|
|
/**
|
|
|
|
|
* Compass |
|
|
|
|
*/ |
|
|
|
|
void SensorsPlusAuroraPlugin::EnableSensorCompass() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceCompass == nullptr) |
|
|
|
|
{ |
|
|
|
|
if (this->m_isSendSensorOrientation) |
|
|
|
|
if (!RegisterSensorInterface<CompassSensorChannelInterface>(KeySensor::Compass)) |
|
|
|
|
{ |
|
|
|
|
EventChannel("sensors_aurora_orientation", MethodCodecType::Standard) |
|
|
|
|
.SendEvent(data.x()); |
|
|
|
|
EventChannelNull(KeyChannel::Compass); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceCompass = CompassSensorChannelInterface::interface(KeySensor::Compass); |
|
|
|
|
|
|
|
|
|
if (!m_ifaceCompass) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Compass); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
connect(m_ifaceCompass, |
|
|
|
|
SIGNAL(dataAvailable(const Compass &)), |
|
|
|
|
this, |
|
|
|
|
SLOT(EventSensorCompass(const Compass &))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::onListenSensorAccelerometer() |
|
|
|
|
m_ifaceCompass->start(); |
|
|
|
|
EventSensorCompass(m_ifaceCompass->get()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::DisableSensorCompass() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceCompass == nullptr) |
|
|
|
|
{ |
|
|
|
|
if (ifaceAccelerometer != nullptr) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SensorManagerInterface &sm = SensorManagerInterface::instance(); |
|
|
|
|
if (!sm.isValid()) { |
|
|
|
|
qDebug() << "Failed to create SensorManagerInterface"; |
|
|
|
|
exit(0); |
|
|
|
|
m_ifaceCompass->stop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QDBusReply<bool> reply(sm.loadPlugin("accelerometersensor")); |
|
|
|
|
if (!reply.isValid() || !reply.value()) { |
|
|
|
|
qDebug() << "Failed to load plugin"; |
|
|
|
|
exit(0); |
|
|
|
|
void SensorsPlusAuroraPlugin::EventSensorCompass(const Compass &data) |
|
|
|
|
{ |
|
|
|
|
std::vector<Encodable> result; |
|
|
|
|
result.push_back(data.degrees()); |
|
|
|
|
result.push_back(data.level()); |
|
|
|
|
EventChannelData(KeyChannel::Compass, result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sm.registerSensorInterface<AccelerometerSensorChannelInterface>("accelerometersensor"); |
|
|
|
|
/**
|
|
|
|
|
* Tap |
|
|
|
|
*/ |
|
|
|
|
void SensorsPlusAuroraPlugin::EnableSensorTap() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceTap == nullptr) |
|
|
|
|
{ |
|
|
|
|
if (!RegisterSensorInterface<TapSensorChannelInterface>(KeySensor::Tap)) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Tap); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ifaceAccelerometer = AccelerometerSensorChannelInterface::interface("accelerometersensor"); |
|
|
|
|
m_ifaceTap = TapSensorChannelInterface::interface(KeySensor::Tap); |
|
|
|
|
|
|
|
|
|
if (!ifaceAccelerometer) { |
|
|
|
|
qDebug() << "Cannot get AccelerometerSensorChannelInterface"; |
|
|
|
|
exit(0); |
|
|
|
|
if (!m_ifaceTap) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Tap); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
connect(ifaceAccelerometer, |
|
|
|
|
SIGNAL(dataAvailable(const XYZ&)), |
|
|
|
|
connect(m_ifaceTap, |
|
|
|
|
SIGNAL(dataAvailable(const Tap &)), |
|
|
|
|
this, |
|
|
|
|
SLOT(EventSensorTap(const Tap &))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceTap->start(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::DisableSensorTap() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceTap == nullptr) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceTap->stop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::EventSensorTap(const Tap &data) |
|
|
|
|
{ |
|
|
|
|
std::vector<Encodable> result; |
|
|
|
|
result.push_back(static_cast<int>(data.direction())); |
|
|
|
|
result.push_back(static_cast<int>(data.type())); |
|
|
|
|
EventChannelData(KeyChannel::Tap, result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ALS |
|
|
|
|
*/ |
|
|
|
|
void SensorsPlusAuroraPlugin::EnableSensorALS() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceALS == nullptr) |
|
|
|
|
{ |
|
|
|
|
if (!RegisterSensorInterface<ALSSensorChannelInterface>(KeySensor::ALS)) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::ALS); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceALS = ALSSensorChannelInterface::interface(KeySensor::ALS); |
|
|
|
|
|
|
|
|
|
if (!m_ifaceALS) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::ALS); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
connect(m_ifaceALS, |
|
|
|
|
SIGNAL(ALSChanged(const Unsigned &)), |
|
|
|
|
this, |
|
|
|
|
SLOT(EventSensorALS(const Unsigned &))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceALS->start(); |
|
|
|
|
EventSensorALS(m_ifaceALS->lux()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::DisableSensorALS() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceALS == nullptr) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceALS->stop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::EventSensorALS(const Unsigned &data) |
|
|
|
|
{ |
|
|
|
|
std::vector<Encodable> result; |
|
|
|
|
result.push_back(data.x()); |
|
|
|
|
EventChannelData(KeyChannel::ALS, result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Proximity |
|
|
|
|
*/ |
|
|
|
|
void SensorsPlusAuroraPlugin::EnableSensorProximity() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceProximity == nullptr) |
|
|
|
|
{ |
|
|
|
|
if (!RegisterSensorInterface<ProximitySensorChannelInterface>(KeySensor::Proximity)) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Proximity); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceProximity = ProximitySensorChannelInterface::interface(KeySensor::Proximity); |
|
|
|
|
|
|
|
|
|
if (!m_ifaceProximity) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Proximity); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
connect(m_ifaceProximity, |
|
|
|
|
SIGNAL(reflectanceDataAvailable(const Proximity &)), |
|
|
|
|
this, |
|
|
|
|
SLOT(eventSensorAccelerometer(const XYZ&)) |
|
|
|
|
); |
|
|
|
|
SLOT(EventSensorProximity(const Proximity &))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ifaceAccelerometer->start(); |
|
|
|
|
m_ifaceProximity->start(); |
|
|
|
|
EventSensorProximity(m_ifaceProximity->proximityReflectance()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::eventSensorAccelerometer(const XYZ& data) |
|
|
|
|
void SensorsPlusAuroraPlugin::DisableSensorProximity() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceProximity == nullptr) |
|
|
|
|
{ |
|
|
|
|
if (this->m_isSendSensorAccelerometer) |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceProximity->stop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::EventSensorProximity(const Proximity &data) |
|
|
|
|
{ |
|
|
|
|
std::vector<Encodable> result; |
|
|
|
|
result.push_back(data.withinProximity() ? 1 : 0); |
|
|
|
|
EventChannelData(KeyChannel::Proximity, result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Rotation |
|
|
|
|
*/ |
|
|
|
|
void SensorsPlusAuroraPlugin::EnableSensorRotation() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceRotation == nullptr) |
|
|
|
|
{ |
|
|
|
|
if (!RegisterSensorInterface<RotationSensorChannelInterface>(KeySensor::Rotation)) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Rotation); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceRotation = RotationSensorChannelInterface::interface(KeySensor::Rotation); |
|
|
|
|
|
|
|
|
|
if (!m_ifaceRotation) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Rotation); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
connect(m_ifaceRotation, |
|
|
|
|
SIGNAL(dataAvailable(const XYZ &)), |
|
|
|
|
this, |
|
|
|
|
SLOT(EventSensorRotation(const XYZ &))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceRotation->start(); |
|
|
|
|
EventSensorRotation(m_ifaceRotation->rotation()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::DisableSensorRotation() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceRotation == nullptr) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceRotation->stop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::EventSensorRotation(const XYZ &data) |
|
|
|
|
{ |
|
|
|
|
std::vector<Encodable> result; |
|
|
|
|
result.push_back(data.x()); |
|
|
|
|
result.push_back(data.y()); |
|
|
|
|
result.push_back(data.z()); |
|
|
|
|
EventChannelData(KeyChannel::Rotation, result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Magnetometer |
|
|
|
|
*/ |
|
|
|
|
void SensorsPlusAuroraPlugin::EnableSensorMagnetometer() |
|
|
|
|
{ |
|
|
|
|
if (m_ifaceMagnetometer == nullptr) |
|
|
|
|
{ |
|
|
|
|
if (!RegisterSensorInterface<MagnetometerSensorChannelInterface>(KeySensor::Magnetometer)) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Magnetometer); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceMagnetometer = MagnetometerSensorChannelInterface::interface(KeySensor::Magnetometer); |
|
|
|
|
|
|
|
|
|
if (!m_ifaceMagnetometer) |
|
|
|
|
{ |
|
|
|
|
EventChannelNull(KeyChannel::Magnetometer); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
EventChannel("sensors_aurora_accelerometer", MethodCodecType::Standard) |
|
|
|
|
.SendEvent(result); |
|
|
|
|
connect(m_ifaceMagnetometer, |
|
|
|
|
SIGNAL(dataAvailable(const MagneticField &)), |
|
|
|
|
this, |
|
|
|
|
SLOT(EventSensorMagnetometer(const MagneticField &))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceMagnetometer->start(); |
|
|
|
|
EventSensorMagnetometer(m_ifaceMagnetometer->magneticField()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::unimplemented(const MethodCall &call) |
|
|
|
|
void SensorsPlusAuroraPlugin::DisableSensorMagnetometer() |
|
|
|
|
{ |
|
|
|
|
call.SendSuccessResponse(nullptr); |
|
|
|
|
if (m_ifaceMagnetometer == nullptr) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_ifaceMagnetometer->stop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SensorsPlusAuroraPlugin::EventSensorMagnetometer(const MagneticField &data) |
|
|
|
|
{ |
|
|
|
|
std::vector<Encodable> result; |
|
|
|
|
result.push_back(data.x()); |
|
|
|
|
result.push_back(data.y()); |
|
|
|
|
result.push_back(data.z()); |
|
|
|
|
EventChannelData(KeyChannel::Magnetometer, result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#include "moc_sensors_plus_aurora_plugin.cpp" |
|
|
|
|