Skip to content
Snippets Groups Projects
Commit 7c101d17 authored by Bryan Godbolt's avatar Bryan Godbolt
Browse files

filled in curve calibrator functions

parent 95011df1
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ float AbstractCalibrator::logAverage()
float total = 0;
for (int i=0; i<log->size(); ++i)
total += log->value(i);
return (total/log->size());
return floor(total/log->size());
}
float AbstractCalibrator::logExtrema()
......
......@@ -5,6 +5,8 @@
#include <QString>
#include <QLabel>
#include <math.h>
class AbstractCalibrator : public QWidget
{
Q_OBJECT
......
......@@ -2,9 +2,8 @@
CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) :
AbstractCalibrator(parent),
setpoints(QVector<double>(5)),
positions(QVector<double>())
setpoints(new QVector<double>(5)),
positions(new QVector<double>())
{
QGridLayout *grid = new QGridLayout(this);
QLabel *title = new QLabel(titleString);
......@@ -18,10 +17,10 @@ CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) :
grid->addLayout(pulseLayout, 1, 0, 1, 5, Qt::AlignHCenter);
for (int i=0; i<=100; i=i+100/4)
positions.append(static_cast<double>(i));
positions->append(static_cast<double>(i));
setpoints.fill(1500);
setpoints->fill(1500);
plot = new QwtPlot();
......@@ -29,13 +28,62 @@ CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) :
plot->setAxisScale(QwtPlot::yLeft, 1000, 2000, 200);
plot->setAxisScale(QwtPlot::xBottom, 0, 100, 25);
curve = new QwtPlotCurve();
curve->setData(positions, setpoints);
curve->setPen(QPen(QColor(QString("lime"))));
curve->setData(*positions, *setpoints);
curve->attach(plot);
plot->replot();
QPushButton *zero = new QPushButton(tr("0 %"));
QPushButton *twentyfive = new QPushButton(tr("25 %"));
QPushButton *fifty = new QPushButton(tr("50 %"));
QPushButton *seventyfive = new QPushButton(tr("75 %"));
QPushButton *hundred = new QPushButton(tr("100 %"));
grid->addWidget(zero, 3, 0);
grid->addWidget(twentyfive, 3, 1);
grid->addWidget(fifty, 3, 2);
grid->addWidget(seventyfive, 3, 3);
grid->addWidget(hundred, 3, 4);
this->setLayout(grid);
signalMapper = new QSignalMapper(this);
signalMapper->setMapping(zero, 0);
signalMapper->setMapping(twentyfive, 1);
signalMapper->setMapping(fifty, 2);
signalMapper->setMapping(seventyfive, 3);
signalMapper->setMapping(hundred, 4);
connect(zero, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(twentyfive, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(fifty, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(seventyfive, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(hundred, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(setSetpoint(int)));
}
CurveCalibrator::~CurveCalibrator()
{
delete setpoints;
delete positions;
}
void CurveCalibrator::setSetpoint(int setpoint)
{
if (setpoint == 0 || setpoint == 4)
{
setpoints->replace(setpoint, static_cast<double>(logExtrema()));
}
else
{
setpoints->replace(setpoint, static_cast<double>(logAverage()));
}
plot->replot();
emit setpointChanged(setpoint, static_cast<float>(setpoints->value(setpoint)));
}
......@@ -9,6 +9,11 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QPen>
#include <QColor>
#include <QString>
#include <QSignalMapper>
#include <QDebug>
#include "AbstractCalibrator.h"
......@@ -17,15 +22,20 @@ class CurveCalibrator : public AbstractCalibrator
Q_OBJECT
public:
explicit CurveCalibrator(QString title = QString(), QWidget *parent = 0);
~CurveCalibrator();
signals:
void setpointChanged(float[5]);
void setpointChanged(int setpoint, float raw);
protected slots:
void setSetpoint(int setpoint);
protected:
QVector<double> setpoints;
QVector<double> positions;
QVector<double> *setpoints;
QVector<double> *positions;
QwtPlot *plot;
QwtPlotCurve *curve;
QSignalMapper *signalMapper;
};
#endif // CURVECALIBRATOR_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment