AbstractCalibrator.cc 1.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include "AbstractCalibrator.h"

AbstractCalibrator::AbstractCalibrator(QWidget *parent) :
    QWidget(parent),
    pulseWidth(new QLabel()),
    log(new QVector<float>())
{
}

AbstractCalibrator::~AbstractCalibrator()
{
    delete log;
}

float AbstractCalibrator::logAverage()
{
    float total = 0;
    for (int i=0; i<log->size(); ++i)
        total += log->value(i);
20
    return floor(total/log->size());
21 22 23 24 25
}

float AbstractCalibrator::logExtrema()
{
    float extrema = logAverage();
26 27
    if (logAverage() < 1500) {
        for (int i=0; i<log->size(); ++i) {
28 29 30
            if (log->value(i) < extrema)
                extrema = log->value(i);
        }
31
        extrema -= 5; // add 5us to prevent integer overflow
32 33
    } else {
        for (int i=0; i<log->size(); ++i) {
34 35 36
            if (log->value(i) > extrema)
                extrema = log->value(i);
        }
37
        extrema += 5; // subtact 5us to prevent integer overflow
38 39 40 41 42 43 44 45 46 47 48 49
    }

    return extrema;
}

void AbstractCalibrator::channelChanged(float raw)
{
    pulseWidth->setText(QString::number(static_cast<double>(raw)));
    if (log->size() == 5)
        log->pop_front();
    log->push_back(raw);
}