...
Code Block |
---|
#include "sensorunlinearitycorrection.h" SensorUnlinearityCorrection::SensorUnlinearityCorrection(QObject *parent) : QObject(parent) { //esimerkkina arvot kolmessa kohdassa mitta-aluetta CorrectVal.append(0.0); ValFromSensor.append(0.0); CorrectVal.append(50.0); ValFromSensor.append(52.0); CorrectVal.append(100.0); ValFromSensor.append(98.0); } void SensorUnlinearityCorrection::CalcCalibrationConstants() { int i; int length = CorrectVal.size(); a.empty(); b.empty(); for(i=0;i<length;i++) { b.append(CorrectVal[i]-ValFromSensor[i]); } for(i=0;i<(length-1);i++) { a.append((b[i+1]-b[i])/(CorrectVal[i+1]-CorrectVal[i])); } } double SensorUnlinearityCorrection::SensorErrorCorrection(double in) { int length = CorrectVal.size(); int i; double out; for(i=0;i<(length-1);i++) { if(in>=CorrectVal[i]&&in<=CorrectVal[i+1]) { out=in+(in-CorrectVal[i])*a[i]+b[i]; return out; } } out=in; return out; } |
Code Block |
---|
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include "sensorunlinearitycorrection.h"
namespace Ui {
class Dialog;
}
class Dialog : public QDialog {
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
SensorUnlinearityCorrection sensorUnlinearityCorrection;
protected:
void changeEvent(QEvent *e);
private:
Ui::Dialog *ui;
private slots:
void on_horizontalSlider_sliderMoved(int position);
};
#endif // DIALOG_H
|
Code Block |
---|
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
sensorUnlinearityCorrection.CalcCalibrationConstants();
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void Dialog::on_horizontalSlider_sliderMoved(int position)
{
double Arvo=sensorUnlinearityCorrection.SensorErrorCorrection((double)position);
ui->anturinAntamaArvo->setNum(Arvo);
ui->todellinenarvo->setNum(position);
}
|