AbstractSensorService.cpp Example File
bpstoqml/src/AbstractSensorService.cpp
#include "AbstractSensorService.hpp"
#include <QDateTime>
namespace bb {
namespace cascades {
namespace bps {
AbstractSensorService::AbstractSensorService(sensor_type_t sensorType,
QObject *parent)
: BlackBerryPlatformService(parent)
, m_sensorType(sensorType)
{
}
AbstractSensorService::~AbstractSensorService() {
}
bool AbstractSensorService::isSupported() {
return sensor_is_supported(m_sensorType);
}
void AbstractSensorService::setCalibrationEnabled(bool calibrationEnabled) {
m_calibrationEnabled = calibrationEnabled;
m_calibrationEnabledSet = true;
}
void AbstractSensorService::setEnableSkipDuplicates(bool enableSkipDuplicates) {
m_enableSkipDuplicates = enableSkipDuplicates;
m_enableSkipDuplicatesSet = true;
}
void AbstractSensorService::setEventRate(unsigned int rate) {
m_rate = rate;
m_rateSet = true;
}
void AbstractSensorService::setBackgroundEnabled(bool backgroundEnabled) {
m_backgroundEnabled = backgroundEnabled;
m_backgroundEnabledSet = true;
}
int AbstractSensorService::eventDomain() {
return sensor_get_domain();
}
void AbstractSensorService::requestEvents() {
if (m_calibrationEnabledSet)
sensor_set_calibration(m_sensorType, m_calibrationEnabled);
if (m_rateSet)
sensor_set_rate(m_sensorType, m_rate);
if (m_enableSkipDuplicatesSet)
sensor_set_skip_duplicates(m_sensorType, m_enableSkipDuplicates);
sensor_request_events(m_sensorType);
}
unsigned long long AbstractSensorService::getTimestamp(bps_event_t *event) {
unsigned long long timestamp = QDateTime::currentMSecsSinceEpoch();
return timestamp;
}
AbstractSensorService::SensorAccuracy AbstractSensorService::getAccuracy(
bps_event_t *event) {
SensorAccuracy accuracy = AccuracyUnreliable;
switch (sensor_event_get_accuracy(event)) {
case SENSOR_ACCURACY_UNRELIABLE:
accuracy = AccuracyUnreliable;
break;
case SENSOR_ACCURACY_LOW:
accuracy = AccuracyLow;
break;
case SENSOR_ACCURACY_MEDIUM:
accuracy = AccuracyMedium;
break;
case SENSOR_ACCURACY_HIGH:
accuracy = AccuracyHigh;
break;
}
return accuracy;
}
}
}
}