Skip to content

Commit

Permalink
[sensorfw] Add real calibration level to hybris compass sensor.
Browse files Browse the repository at this point in the history
This makes the orientationfilter into a compassfilter, but not changing
the name. hybris calls it orientation sensor, even though it's
a calibrated compass.
  • Loading branch information
Lorn Potter committed Jul 23, 2014
1 parent 00975d9 commit b8832db
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
19 changes: 11 additions & 8 deletions adaptors/hybrisorientationadaptor/hybrisorientationadaptor.cpp
Expand Up @@ -43,7 +43,7 @@
HybrisOrientationAdaptor::HybrisOrientationAdaptor(const QString& id) :
HybrisAdaptor(id,SENSOR_TYPE_ORIENTATION)
{
buffer = new DeviceAdaptorRingBuffer<TimedXyzData>(1);
buffer = new DeviceAdaptorRingBuffer<CompassData>(1);
setAdaptedSensor("orientation", "Internal orientation coordinates", buffer);

setDescription("Hybris orientation");
Expand Down Expand Up @@ -72,15 +72,18 @@ void HybrisOrientationAdaptor::stopSensor()

void HybrisOrientationAdaptor::processSample(const sensors_event_t& data)
{
TimedXyzData *d = buffer->nextSlot();
CompassData *d = buffer->nextSlot();
d->timestamp_ = quint64(data.timestamp * .001);
// sensorfw wants milli-G'
d->x_ = data.data[0] * 1000; //azimuth
d->y_ = data.data[1] * 1000; //pitch
d->z_ = data.data[2] * 1000; //roll
d->degrees_ = data.data[0] * 1000; //azimuth
switch (data.orientation.status) {
case SENSOR_STATUS_UNRELIABLE:
d->level_ = 0;
break;
default:
d->level_ = data.orientation.status / 3;
break;
};

// qt's sensorfw plugin expects G == 9.81286, but it should be
//9.80665
buffer->commit();
buffer->wakeUpReaders();
}
Expand Down
Expand Up @@ -46,7 +46,7 @@ class HybrisOrientationAdaptor : public HybrisAdaptor
void init();

private:
DeviceAdaptorRingBuffer<TimedXyzData>* buffer;
DeviceAdaptorRingBuffer<CompassData>* buffer;
int sensorType;

};
Expand Down
2 changes: 1 addition & 1 deletion chains/compasschain/compasschain.cpp
Expand Up @@ -46,7 +46,7 @@ CompassChain::CompassChain(const QString& id) :
hasOrientationAdaptor = true;
setValid(orientAdaptor->isValid());
if (orientAdaptor->isValid())
orientationdataReader = new BufferReader<TimedXyzData>(1);
orientationdataReader = new BufferReader<CompassData>(1);

orientationFilter = sm.instantiateFilter("orientationfilter");
Q_ASSERT(orientationFilter);
Expand Down
2 changes: 1 addition & 1 deletion chains/compasschain/compasschain.h
Expand Up @@ -74,7 +74,7 @@ public Q_SLOTS:
BufferReader<CalibratedMagneticFieldData> *magReader;

DeviceAdaptor *orientAdaptor;
BufferReader<TimedXyzData> *orientationdataReader;
BufferReader<CompassData> *orientationdataReader;


FilterBase *compassFilter;
Expand Down
11 changes: 7 additions & 4 deletions chains/compasschain/orientationfilter.cpp
Expand Up @@ -24,17 +24,20 @@

OrientationFilter::OrientationFilter()
: orientDataSink(this, &OrientationFilter::orientDataAvailable),
level(3) //presume this is fully calibrated
level(0) //presume this is fully calibrated
{
addSink(&orientDataSink, "orientsink");
addSource(&magSource, "magnorthangle");
}

void OrientationFilter::orientDataAvailable(unsigned, const TimedXyzData *data)
void OrientationFilter::orientDataAvailable(unsigned, const CompassData *data)
{
CompassData compassData; //north angle
compassData.timestamp_ = data->timestamp_;
compassData.degrees_ = data->x_ * .001;
compassData.level_ = level;
compassData.degrees_ = data->degrees_ * .001;
if (data->level_ > 0 && data->level_ < 3.1)
compassData.level_ = data->level_;
else
compassData.level_ = level;
magSource.propagate(1, &compassData);
}
4 changes: 2 additions & 2 deletions chains/compasschain/orientationfilter.h
Expand Up @@ -43,8 +43,8 @@ class OrientationFilter : public QObject, public FilterBase
private:
Source<CompassData> magSource;

Sink<OrientationFilter, TimedXyzData> orientDataSink;
void orientDataAvailable(unsigned, const TimedXyzData*);
Sink<OrientationFilter, CompassData> orientDataSink;
void orientDataAvailable(unsigned, const CompassData*);
qreal level;
qreal oldHeading;
};
Expand Down

0 comments on commit b8832db

Please sign in to comment.