SwitchCalibrator.cc 1.89 KB
Newer Older
1 2 3
#include "SwitchCalibrator.h"

SwitchCalibrator::SwitchCalibrator(QString titleString, QWidget *parent) :
4 5 6
    AbstractCalibrator(parent),    
    defaultPulseWidth(new QLabel()),
    toggledPulseWidth(new QLabel())
7 8 9 10 11 12 13
{
    /* Add title label*/
    QLabel *title = new QLabel(titleString);
    QGridLayout *grid = new QGridLayout();
    grid->addWidget(title, 0, 0, 1, 3);

    /* Add current Pulse Width Display */
14
    QLabel *pulseWidthTitle = new QLabel(tr("Pulse Width (us)"));    
15 16 17 18 19
    QHBoxLayout *pulseLayout = new QHBoxLayout();
    pulseLayout->addWidget(pulseWidthTitle);
    pulseLayout->addWidget(pulseWidth);
    grid->addLayout(pulseLayout, 1, 0, 1, 3);

20 21 22 23 24 25 26 27 28 29 30 31
    QLabel *defaultPulseString = new QLabel(tr("Default Position"));
    QPushButton *defaultButton = new QPushButton(tr("Set"));
    grid->addWidget(defaultPulseString, 2, 0);
    grid->addWidget(defaultPulseWidth, 2, 1);
    grid->addWidget(defaultButton, 2, 2);

    QLabel *toggledPulseString = new QLabel(tr("Toggled Position"));
    QPushButton *toggledButton = new QPushButton(tr("Set"));
    grid->addWidget(toggledPulseString, 3, 0);
    grid->addWidget(toggledPulseWidth, 3, 1);
    grid->addWidget(toggledButton, 3, 2);

32
    this->setLayout(grid);
33 34 35 36 37 38 39 40 41

    connect(defaultButton, SIGNAL(clicked()), this, SLOT(setDefault()));
    connect(toggledButton, SIGNAL(clicked()), this, SLOT(setToggled()));
}


void SwitchCalibrator::setDefault()
{
    defaultPulseWidth->setText(QString::number(static_cast<double>(logExtrema())));
42
    emit setpointChanged(0, logExtrema());
43 44
}

45
void SwitchCalibrator::setToggled()
46
{
47
    toggledPulseWidth->setText(QString::number(static_cast<double>(logExtrema())));
48
    emit setpointChanged(1, logExtrema());
49
}
50 51 52 53 54 55 56 57 58

void SwitchCalibrator::set(const QVector<float> &data)
{
    if (data.size() == 2)
    {
        defaultPulseWidth->setText(QString::number(data[0]));
        toggledPulseWidth->setText(QString::number(data[1]));
    }
}