RadioCalibrationData.cc 1.64 KB
Newer Older
1 2 3 4
#include "RadioCalibrationData.h"

RadioCalibrationData::RadioCalibrationData()
{
5 6 7 8 9 10 11
    data = new QVector<QVector<float> >(6);
    (*data).insert(AILERON, QVector<float>(3));
    (*data).insert(ELEVATOR, QVector<float>(3));
    (*data).insert(RUDDER, QVector<float>(3));
    (*data).insert(GYRO, QVector<float>(2));
    (*data).insert(PITCH, QVector<float>(5));
    (*data).insert(THROTTLE, QVector<float>(5));
12 13 14
}

RadioCalibrationData::RadioCalibrationData(const QVector<float> &aileron,
15 16 17 18 19
        const QVector<float> &elevator,
        const QVector<float> &rudder,
        const QVector<float> &gyro,
        const QVector<float> &pitch,
        const QVector<float> &throttle)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
{
    data = new QVector<QVector<float> >();
    (*data) << aileron
            << elevator
            << rudder
            << gyro
            << pitch
            << throttle;
}

RadioCalibrationData::RadioCalibrationData(const RadioCalibrationData &other)
    :QObject()
{
    data = new QVector<QVector<float> >(*other.data);
}

36 37 38 39 40
RadioCalibrationData::~RadioCalibrationData()
{
    delete data;
}

41 42
const float* RadioCalibrationData::operator [](int i) const
{
43
    if (i < data->size()) {
44 45 46 47 48 49
        return (*data)[i].constData();
    }

    return NULL;
}

50
const QVector<float>& RadioCalibrationData::operator ()(const int i) const throw(std::out_of_range)
51
{
52
    if ((i < data->size()) && (i >=0)) {
53 54 55
        return (*data)[i];
    }

56
    throw std::out_of_range("Invalid channel index");
57
}
58 59 60 61

QString RadioCalibrationData::toString(RadioElement element) const
{
    QString s;
62
    foreach (float f, (*data)[element]) {
63 64 65 66
        s += QString::number(f) + ", ";
    }
    return s.mid(0, s.length()-2);
}