current revision
This commit is contained in:
67
ui/debug/InfoWidget.cpp
Normal file
67
ui/debug/InfoWidget.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "InfoWidget.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QGridLayout>
|
||||
|
||||
#include <Indoor/Assertions.h>
|
||||
|
||||
InfoWidget::InfoWidget(QWidget *parent) : QWidget(parent) {
|
||||
|
||||
//setMinimumHeight(32);
|
||||
//setMaximumHeight(32);
|
||||
|
||||
QGridLayout* lay = new QGridLayout(this);
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
|
||||
lblActivity = new QLabel();
|
||||
lblActivity->setText("-");
|
||||
//lblActivity->setStyleSheet("QLabel { color : white; }");
|
||||
//lblActivity->setFont(QFont("courier", 9));
|
||||
lay->addWidget(lblActivity, row, col, 1,1,Qt::AlignLeft); ++row;
|
||||
lblActivity->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
|
||||
lblFilterTime = new QLabel();
|
||||
lblFilterTime->setText("-");
|
||||
//lblFilterTime->setStyleSheet("QLabel { color : white; }");
|
||||
//lblFilterTime->setFont(QFont("courier", 9));
|
||||
lay->addWidget(lblFilterTime, row, col, 1,1,Qt::AlignLeft); ++row;
|
||||
lblFilterTime->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
|
||||
// lblMapViewTime = new QLabel();
|
||||
// lblMapViewTime->setText("-");
|
||||
// //lblMapViewTime->setStyleSheet("QLabel { color : white; }");
|
||||
// //lblMapViewTime->setFont(QFont("courier", 9));
|
||||
// lay->addWidget(lblMapViewTime, row, col, 1,1,Qt::AlignLeft); ++row;
|
||||
// lblMapViewTime->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
|
||||
col = 1;
|
||||
row = 0;
|
||||
|
||||
lblLog = new QLabel(this);
|
||||
lblLog->setText("-");
|
||||
//lblLog->setStyleSheet("QLabel { color : white; }");
|
||||
lblLog->setFont(QFont("Arial", 8));
|
||||
lay->addWidget(lblLog, row, col, 3, 1);
|
||||
lblLog->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void InfoWidget::showActivity(const QString& act) {
|
||||
lblActivity->setText("Activity: " + act);
|
||||
}
|
||||
|
||||
void InfoWidget::showFilterTime(const QString& act) {
|
||||
lblFilterTime->setText("Filtering: " + act);
|
||||
}
|
||||
|
||||
void InfoWidget::showMapViewTime(const QString& act) {
|
||||
lblMapViewTime->setText("MapView: " + act);
|
||||
}
|
||||
|
||||
void InfoWidget::showLog(const QString& info) {
|
||||
lblLog->setText(info);
|
||||
}
|
||||
|
||||
35
ui/debug/InfoWidget.h
Normal file
35
ui/debug/InfoWidget.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef INFOWIDGET_H
|
||||
#define INFOWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QLabel;
|
||||
|
||||
class InfoWidget : public QWidget {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
||||
QLabel* lblActivity;
|
||||
QLabel* lblFilterTime;
|
||||
QLabel* lblMapViewTime;
|
||||
QLabel* lblLog;
|
||||
|
||||
public:
|
||||
|
||||
explicit InfoWidget(QWidget *parent = 0);
|
||||
|
||||
Q_INVOKABLE void showActivity(const QString& act);
|
||||
Q_INVOKABLE void showFilterTime(const QString& act);
|
||||
Q_INVOKABLE void showMapViewTime(const QString& act);
|
||||
Q_INVOKABLE void showLog(const QString& info);
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // INFOWIDGET_H
|
||||
@@ -6,7 +6,9 @@ PlotTurns::PlotTurns(QWidget *parent) : QWidget(parent) {
|
||||
setMinimumWidth(96);
|
||||
setMinimumHeight(96);
|
||||
|
||||
resize(96, 96);
|
||||
//setSizeIncrement(QSize(1,1));
|
||||
//setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding));
|
||||
// resize(96, 96);
|
||||
|
||||
// setMaximumWidth(64);
|
||||
// setMaximumHeight(64);
|
||||
|
||||
@@ -19,6 +19,8 @@ public:
|
||||
|
||||
void add(const Timestamp ts, const TurnData& data);
|
||||
|
||||
//QSize sizeHint() const {return QSize(96, 96);}
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -3,12 +3,18 @@
|
||||
|
||||
#include <QPainter>
|
||||
#include <QStaticText>
|
||||
#include "../UIHelper.h"
|
||||
|
||||
PlotWiFiScan::PlotWiFiScan(QWidget *parent) : QWidget(parent) {
|
||||
|
||||
setMinimumWidth(96);
|
||||
setMinimumHeight(96);
|
||||
|
||||
|
||||
//setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
// setMaximumHeight(300);
|
||||
// sets
|
||||
//setAutoFillBackground(false);
|
||||
|
||||
}
|
||||
@@ -24,13 +30,15 @@ void PlotWiFiScan::paintEvent(QPaintEvent* evt) {
|
||||
(void) evt;
|
||||
QPainter p(this);
|
||||
|
||||
const int x0 = 4; const int xw = 150;
|
||||
const int x0 = 4; const int xw = UIHelper::getWifiLabelDistX(this->parent());
|
||||
const int y0 = 3;
|
||||
const int lh = 13;
|
||||
const int lh = UIHelper::getWifiLabelDistY(this->parent());
|
||||
|
||||
int x = x0;
|
||||
int y = y0;
|
||||
|
||||
int w = width();
|
||||
int h = height();
|
||||
|
||||
p.fillRect(0,0,width(),height(),QColor(255,255,255,192));
|
||||
p.setPen(Qt::black);
|
||||
@@ -45,7 +53,7 @@ void PlotWiFiScan::paintEvent(QPaintEvent* evt) {
|
||||
std::string str = mac + ": " + std::to_string((int)m.getRSSI());
|
||||
p.drawStaticText(x, y, QStaticText(str.c_str()));
|
||||
y += lh;
|
||||
if (y > 90) {y = y0; x += xw;}
|
||||
if (y > this->height()-10) {y = y0; x += xw;}
|
||||
}
|
||||
|
||||
p.end();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,10 @@
|
||||
#include "../sensors/StepSensor.h"
|
||||
#include "../sensors/TurnSensor.h"
|
||||
#include "../sensors/WiFiSensor.h"
|
||||
#include "../sensors/ActivitySensor.h"
|
||||
|
||||
class PlotWidget;
|
||||
class QGridLayout;
|
||||
|
||||
/** debug display for sensor data */
|
||||
class SensorDataWidget :
|
||||
@@ -21,6 +23,7 @@ class SensorDataWidget :
|
||||
public SensorListener<AccelerometerData>,
|
||||
public SensorListener<GyroscopeData>,
|
||||
public SensorListener<BarometerData>,
|
||||
public SensorListener<ActivityData>,
|
||||
public SensorListener<StepData>,
|
||||
public SensorListener<TurnData>,
|
||||
public SensorListener<WiFiMeasurements> {
|
||||
@@ -28,6 +31,7 @@ class SensorDataWidget :
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
|
||||
SensorDataWidget(QWidget* parent);
|
||||
@@ -38,6 +42,7 @@ public:
|
||||
void onSensorData(Sensor<StepData>* sensor, const Timestamp ts, const StepData& data) override;
|
||||
void onSensorData(Sensor<TurnData>* sensor, const Timestamp ts, const TurnData& data) override;
|
||||
void onSensorData(Sensor<WiFiMeasurements>* sensor, const Timestamp ts, const WiFiMeasurements& data) override;
|
||||
void onSensorData(Sensor<ActivityData>* sensor, const Timestamp ts, const ActivityData& data) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -47,6 +52,8 @@ private:
|
||||
QWidget* plotTurn;
|
||||
QWidget* plotWiFi;
|
||||
|
||||
QGridLayout* lay;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user