Skip to content

Commit

Permalink
Accelerometer coordinate transformation matrix from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Rongas committed Jul 26, 2010
1 parent 5d69044 commit 175c185
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
37 changes: 34 additions & 3 deletions chains/accelerometerchain/accelerometerchain.cpp
Expand Up @@ -26,15 +26,18 @@

#include "accelerometerchain.h"
#include <QVariant>
#include <QStringList>
#include "sensord/sensormanager.h"
#include "sensord/bin.h"
#include "sensord/bufferreader.h"
#include "sensord/config.h"
#include "sensord/logging.h"

#include "filters/coordinatealignfilter/coordinatealignfilter.h"

double AccelerometerChain::aconv_[3][3] = { {-1.0, 0.0, 0.0},
{ 0.0,-1.0, 0.0},
{ 0.0, 0.0,-1.0} };
double AccelerometerChain::aconv_[3][3] = { { 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 } };

AccelerometerChain::AccelerometerChain(const QString& id) :
AbstractChain(id)
Expand All @@ -51,6 +54,18 @@ AccelerometerChain::AccelerometerChain(const QString& id) :

accelerometerReader_ = new BufferReader<AccelerationData>(1024);

// Get the transformation matrix from config file
QString aconvString = Config::configuration()->value("acc_trans_matrix", "").toString();
if (aconvString.size() > 0)
{
if (!setMatrixFromString(aconvString))
{
sensordLogW() << "Failed to parse 'acc_trans_matrix' configuration key. Coordinate alignment may be invalid";
}
} else {
sensordLogT() << "Key 'acc_trans_matrix' not found from configuration.";
}

accCoordinateAlignFilter_ = sm.instantiateFilter("coordinatealignfilter");
Q_ASSERT(accCoordinateAlignFilter_);
qRegisterMetaType<TMatrix>("TMatrix");
Expand Down Expand Up @@ -117,3 +132,19 @@ bool AccelerometerChain::stop()
}
return true;
}

bool AccelerometerChain::setMatrixFromString(const QString str)
{
QStringList strList = str.split(',');
if (strList.size() != 9) {
sensordLogW() << "Invalid cell count from matrix. Expected 9, got" << strList.size();
return false;
}

for (int i = 0; i < 9; i++)
{
aconv_[i/3][i%3] = strList.at(i).toInt();
}

return true;
}
3 changes: 3 additions & 0 deletions chains/accelerometerchain/accelerometerchain.h
Expand Up @@ -68,6 +68,9 @@ public Q_SLOTS:
~AccelerometerChain();

private:

bool setMatrixFromString(const QString str);

static double aconv_[3][3];
Bin* filterBin_;

Expand Down
3 changes: 3 additions & 0 deletions config/sensord.conf
Expand Up @@ -7,6 +7,9 @@ proximity_dev_path = /dev/bh1770glc_ps
# ALS adaptor
als_dev_path = /dev/bh1770glc_als

# Accelerometer coordinate transformation matrix
# (values separated by commas, concatenate rows from top to bottom)
acc_trans_matrix = "-1,0,0,0,-1,0,0,0,-1"

### Plugins
###
Expand Down

0 comments on commit 175c185

Please sign in to comment.