RadioCalibrationData.cc 1.94 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 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
}

RadioCalibrationData::RadioCalibrationData(const QVector<float> &aileron,
                                                                   const QVector<float> &elevator,
                                                                   const QVector<float> &rudder,
                                                                   const QVector<float> &gyro,
                                                                   const QVector<float> &pitch,
                                                                   const QVector<float> &throttle)
{
    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 43 44 45 46 47 48 49 50
const float* RadioCalibrationData::operator [](int i) const
{
    if (i < data->size())
    {
        return (*data)[i].constData();
    }

    return NULL;
}

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

58
    throw std::out_of_range("Invalid channel index");
59
}
60 61 62 63 64 65 66 67 68 69

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