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

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

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

RadioCalibrationData::RadioCalibrationData(const RadioCalibrationData &other)
    :QObject()
{
33
    data = new QVector<QVector<uint16_t> >(*other.data);
34 35
}

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

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

    return NULL;
}

50
const QVector<uint16_t>& 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);
}