current revision

This commit is contained in:
2016-09-28 12:16:45 +02:00
parent 075d8bb633
commit d47322e73b
90 changed files with 8228 additions and 606 deletions

View File

@@ -9,10 +9,15 @@
#include "PlotTurns.h"
#include "PlotWiFiScan.h"
#include "../Settings.h"
#include "../UIHelper.h"
template <typename Data> void removeOld(Data& data, const Timestamp limit) {
if (data.size() < 2) {return;}
while ( (data.back().key - data.front().key) > limit.ms()) {
/** helper method to remove old entries */
template <typename Data> void removeOld(Data& data, const Data& dataRef, const Timestamp limit) {
if (data.size() == 0) {return;}
if (dataRef.size() == 0) {return;}
while ( (dataRef.back().key - data.front().key) > limit.ms()) {
if (data.size() == 0) {return;}
data.remove(0);
}
}
@@ -41,7 +46,7 @@ public:
Timestamp lastRefresh;
bool needsRefresh(const Timestamp ts) {
const Timestamp diff = ts - lastRefresh;
return (diff > Timestamp::fromMS(100));
return (diff > Settings::SensorDebug::updateEvery);
}
@@ -68,7 +73,7 @@ public:
steps.setColor(colors[2]);
steps.setPointSize(8);
pc.addPlot(&steps);
const float s = 4.2;
const float s = 4.8;
const float ref = 9.81;
pc.setValRange(Range(ref-s, ref+s));
}
@@ -89,10 +94,10 @@ public:
void limit() {
const Timestamp limit = Timestamp::fromMS(3000);
removeOld(line[0].getData(), limit);
removeOld(line[1].getData(), limit);
removeOld(line[2].getData(), limit);
removeOld(steps.getData(), limit - Timestamp::fromMS(100)); // remove steps a little before. prevents errors
removeOld(line[0].getData(), line[0].getData(), limit);
removeOld(line[1].getData(), line[0].getData(), limit);
removeOld(line[2].getData(), line[0].getData(), limit);
removeOld( steps.getData(), line[0].getData(), limit); // remove steps a little before. prevents errors
}
};
@@ -102,7 +107,7 @@ class PlotGyro : public PlotXLines<3> {
public:
PlotGyro(QWidget* parent) : PlotXLines(parent) {
const float s = 1;
const float s = 1.5;
const float ref = 0;
pc.setValRange(Range(ref-s, ref+s));
}
@@ -119,14 +124,14 @@ public:
void limit() {
const Timestamp limit = Timestamp::fromMS(3000);
removeOld(line[0].getData(), limit);
removeOld(line[1].getData(), limit);
removeOld(line[2].getData(), limit);
removeOld(line[0].getData(), line[0].getData(), limit);
removeOld(line[1].getData(), line[0].getData(), limit);
removeOld(line[2].getData(), line[0].getData(), limit);
}
};
class PlotBaro : public PlotXLines<1> {
class PlotBaro : public PlotXLines<2> {
public:
@@ -135,55 +140,92 @@ public:
}
void add(const Timestamp ts, const BarometerData& data) {
static int skip = 0;
if ((++skip % 8) != 0) {return;}
addLineNode(ts, data.hPa, 0);
if (needsRefresh(ts)) {
limit();
refresh(ts);
}
const float s = 0.5;
const float s = 1.0;
const float ref = line[0].getData().front().val;
pc.setValRange(Range(ref-s, ref+s));
}
void add(const Timestamp ts, const ActivityData& data) {
static int skip = 0;
if ((++skip % 8) != 0) {return;}
float offset = 0;
switch(data.curActivity) {
case ActivityButterPressure::Activity::DOWN: offset = -0.5; break;
case ActivityButterPressure::Activity::UP: offset = +0.5; break;
case ActivityButterPressure::Activity::STAY: offset = +0.1; break;
}
addLineNode(ts, line[0].getData().front().val + offset, 1);
if (needsRefresh(ts)) {
limit();
refresh(ts);
}
}
void limit() {
removeOld(line[0].getData(), Timestamp::fromMS(8000));
// no limit!
//removeOld(line[0].getData(), Timestamp::fromMS(15000)); // 15 second values
}
};
class PlotTurn : public QWidget {
//class PlotTurn : public QWidget {
};
//};
SensorDataWidget::SensorDataWidget(QWidget* parent) : QWidget(parent) {
QGridLayout* lay = new QGridLayout(this);
plotGyro = new PlotGyro(this);
plotAcc = new PlotAcc(this);
plotBaro = new PlotBaro(this);
plotTurn = new PlotTurns(this);
plotWiFi = new PlotWiFiScan(this);
lay->addWidget(plotGyro, 0, 0, 1, 4, Qt::AlignTop);
lay->addWidget(plotAcc, 1, 0, 1, 4, Qt::AlignTop);
lay->addWidget(plotBaro, 2, 0, 1, 4, Qt::AlignTop);
lay->addWidget(plotTurn, 3, 0, 1, 1, Qt::AlignTop);
lay->addWidget(plotWiFi, 3, 1, 1, 3, Qt::AlignTop);
// layout setup
lay = new QGridLayout(this);
lay->addWidget(plotGyro, 0, 0, 1, 4);
lay->addWidget(plotAcc, 1, 0, 1, 4);
lay->addWidget(plotBaro, 2, 0, 1, 4);
lay->addWidget(plotTurn, 3, 0, 1, 1);
lay->addWidget(plotWiFi, 3, 1, 1, 3);
// lay->setRowStretch(0, 1);
// lay->setRowStretch(1, 1);
// lay->setRowStretch(2, 10);
// lay->setRowStretch(3, 10);
// lay->setVerticalSpacing(5);
// lay->setHorizontalSpacing(5);
// lay->setSizeConstraint(QGridLayout::SetDefaultConstraint);
// attach as listener to all sensors we want to debug
SensorFactory::get().getAccelerometer().addListener(this);
SensorFactory::get().getGyroscope().addListener(this);
SensorFactory::get().getBarometer().addListener(this);
SensorFactory::get().getSteps().addListener(this);
SensorFactory::get().getTurns().addListener(this);
SensorFactory::get().getWiFi().addListener(this);
//setAutoFillBackground(false);
SensorFactory::get().getActivity().addListener(this);
}
void SensorDataWidget::onSensorData(Sensor<AccelerometerData>* sensor, const Timestamp ts, const AccelerometerData& data) {
(void) sensor;
((PlotAcc*)plotAcc)->add(ts, data);
@@ -205,6 +247,11 @@ void SensorDataWidget::onSensorData(Sensor<BarometerData>* sensor, const Timesta
((PlotBaro*)plotBaro)->add(ts, data);
}
void SensorDataWidget::onSensorData(Sensor<ActivityData>* sensor, const Timestamp ts, const ActivityData& data) {
(void) sensor;
((PlotBaro*)plotBaro)->add(ts, data);
}
void SensorDataWidget::onSensorData(Sensor<TurnData>* sensor, const Timestamp ts, const TurnData& data) {
(void) sensor;
((PlotTurns*)plotTurn)->add(ts, data);
@@ -214,4 +261,3 @@ void SensorDataWidget::onSensorData(Sensor<WiFiMeasurements>* sensor, const Time
(void) sensor;
((PlotWiFiScan*)plotWiFi)->add(ts, data);
}