AbstractCalibrator.h 2.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief Common aspects of radio calibration widgets
 *   @author Bryan Godbolt <godbolt@ualberta.ca>
 */

30 31 32 33 34 35
#ifndef ABSTRACTCALIBRATOR_H
#define ABSTRACTCALIBRATOR_H

#include <QWidget>
#include <QString>
#include <QLabel>
36
#include <QVector>
37

38
#include <math.h>
39
#include <stdint.h>
40

41 42 43 44 45
/**
  @brief Holds the code which is common to all the radio calibration widgets.

  @author Bryan Godbolt <godbolt@ece.ualberta.ca>
  */
46 47
class AbstractCalibrator : public QWidget
{
48
    Q_OBJECT
49 50 51 52
public:
    explicit AbstractCalibrator(QWidget *parent = 0);
    ~AbstractCalibrator();

53 54 55 56
    /** Change the setpoints of the widget.  Used when
      changing the display from an external source (file/uav).
      @param data QVector of setpoints
      */
57
    virtual void set(const QVector<uint16_t>& data)=0;
58
signals:
59 60 61 62
    /** Announce a setpoint change.
      @param index setpoint number - 0 based in the current implementation
      @param value new value
      */
63
    void setpointChanged(int index, uint16_t value);
64

65
public slots:
66 67 68
    /** Slot to call when the relevant channel is updated
     @param raw current channel value
     */
69
    void channelChanged(uint16_t raw);
70 71

protected:
72
    /** Display the current pulse width */
73 74
    QLabel *pulseWidth;

75
    /** Log of the past few samples for use in averaging and finding extrema */
76
    QVector<uint16_t> *log;
77
    /** Find the maximum or minimum of the data log */
78
    uint16_t logExtrema();
79
    /** Find the average of the log */
80
    uint16_t logAverage();
81 82 83
};

#endif // ABSTRACTCALIBRATOR_H