RadioCalibrationData.cc 1.96 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 51 52 53 54 55 56 57 58
const float* RadioCalibrationData::operator [](int i) const
{
    if (i < data->size())
    {
        return (*data)[i].constData();
    }

    return NULL;
}

const QVector<float>& RadioCalibrationData::operator ()(int i) const
{
    if (i < data->size())
    {
        return (*data)[i];
    }

    // This is not good.  If it is ever used after being returned it will cause a crash
59
//    return QVector<float>();
60
}
61 62 63 64 65 66 67 68 69 70

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