dsosignal.h 7.28 KB
Newer Older
1
/*
DreamSourceLab's avatar
DreamSourceLab committed
2 3
 * This file is part of the DSView project.
 * DSView is based on PulseView.
4
 *
5
 * Copyright (C) 2013 DreamSourceLab <support@dreamsourcelab.com>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This program 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */


DreamSourceLab's avatar
DreamSourceLab committed
23 24
#ifndef DSVIEW_PV_DSOSIGNAL_H
#define DSVIEW_PV_DSOSIGNAL_H
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

#include "signal.h"

#include <boost/shared_ptr.hpp>

namespace pv {

namespace data {
class Logic;
class Dso;
class Analog;
class DsoSnapshot;
}

namespace view {

class DsoSignal : public Signal
{
Andy Dneg's avatar
Andy Dneg committed
43 44 45 46 47 48 49 50 51 52
    Q_OBJECT

public:
    static const int UpMargin = 30;
    static const int DownMargin = 0;
    static const int RightMargin = 30;
    static const float EnvelopeThreshold;
    static const int HoverPointSize = 2;
    static const int RefreshShort = 200;

53 54
private:
	static const QColor SignalColours[4];
DreamSourceLab's avatar
DreamSourceLab committed
55
    static const int HitCursorMargin = 3;
56
    static const uint64_t vDialValueStep = 1000;
DreamSourceLab's avatar
DreamSourceLab committed
57 58 59
    static const uint64_t vDialUnitCount = 2;
    static const QString vDialUnit[vDialUnitCount];

60 61
    static const uint8_t DefaultBits = 8;
    static const int TrigMargin = 16;
62
    static const int RefreshLong = 800;
63
    static const int AutoTime = 10000;
64
    static const int AutoLock = 3;
DreamSourceLab's avatar
DreamSourceLab committed
65

66 67
    static const int TrigHRng = 2;

68
public:
69 70 71 72 73
    enum DsoSetRegions {
        DSO_NONE = -1,
        DSO_VDIAL,
        DSO_CHEN,
        DSO_ACDC,
74
        DSO_AUTO,
75 76 77 78 79
        DSO_X1,
        DSO_X10,
        DSO_X100,
    };

80 81 82 83 84 85 86
private:
    static const uint16_t MS_RectRad = 5;
    static const uint16_t MS_IconSize = 16;
    static const uint16_t MS_RectWidth = 120;
    static const uint16_t MS_RectMargin = 10;
    static const uint16_t MS_RectHeight = 25;

87
public:
DreamSourceLab's avatar
DreamSourceLab committed
88 89
    DsoSignal(boost::shared_ptr<pv::device::DevInst> dev_inst,
              boost::shared_ptr<pv::data::Dso> data,
90
              sr_channel *probe);
91 92 93

    virtual ~DsoSignal();

DreamSourceLab's avatar
DreamSourceLab committed
94
    boost::shared_ptr<pv::data::SignalData> data() const;
DreamSourceLab's avatar
DreamSourceLab committed
95
    boost::shared_ptr<pv::data::Dso> dso_data() const;
DreamSourceLab's avatar
DreamSourceLab committed
96

97
    void set_scale(int height);
98
    float get_scale();
Andy Dneg's avatar
Andy Dneg committed
99 100 101
    uint8_t get_bits();
    double get_ref_min() const;
    double get_ref_max() const;
102

103 104
    int get_name_width() const;

DreamSourceLab's avatar
DreamSourceLab committed
105 106 107 108 109 110
    /**
     *
     */
    void set_enable(bool enable);
    bool get_vDialActive() const;
    void set_vDialActive(bool active);
Andy Dneg's avatar
Andy Dneg committed
111 112
    bool go_vDialPre(bool manul);
    bool go_vDialNext(bool manul);
113
    bool update_capture(bool instant);
Andy Dneg's avatar
Andy Dneg committed
114
    dslDial *get_vDial() const;
DreamSourceLab's avatar
DreamSourceLab committed
115 116
    uint64_t get_vDialValue() const;
    uint16_t get_vDialSel() const;
DreamSourceLab's avatar
DreamSourceLab committed
117 118
    uint8_t get_acCoupling() const;
    void set_acCoupling(uint8_t coupling);
Andy Dneg's avatar
Andy Dneg committed
119 120 121

    void set_trig_vpos(int pos, bool delta_change = true);
    void set_trig_ratio(double ratio, bool delta_change = true);
122
    double get_trig_vrate() const;
Andy Dneg's avatar
Andy Dneg committed
123

124
    void set_factor(uint64_t factor);
125
    uint64_t get_factor();
Andy Dneg's avatar
Andy Dneg committed
126 127
    void set_show(bool show);
    bool show() const;
128
    void set_mValid(bool valid);
129

130
    bool load_settings();
131
    int commit_settings();
132 133 134 135 136 137

    /**
      *
      */
    bool measure(const QPointF &p);
    bool get_hover(uint64_t &index, QPointF &p, double &value);
Andy Dneg's avatar
Andy Dneg committed
138
    QPointF get_point(uint64_t index, float &value);
DreamSourceLab's avatar
DreamSourceLab committed
139

DreamSourceLab's avatar
DreamSourceLab committed
140 141 142
    /**
      * auto set the vertical and Horizontal scale
      */
143 144 145
    void auto_start();
    void autoV_end();
    void autoH_end();
Andy Dneg's avatar
Andy Dneg committed
146
    void auto_end();
DreamSourceLab's avatar
DreamSourceLab committed
147

DreamSourceLab's avatar
DreamSourceLab committed
148 149 150
    /**
     * Gets the mid-Y position of this signal.
     */
151
    int get_zero_vpos() const;
Andy Dneg's avatar
Andy Dneg committed
152 153
    double get_zero_ratio() const;
    int get_hw_offset() const;
DreamSourceLab's avatar
DreamSourceLab committed
154 155 156
    /**
     * Sets the mid-Y position of this signal.
     */
157
    void set_zero_vpos(int pos);
Andy Dneg's avatar
Andy Dneg committed
158 159 160 161 162 163 164 165 166 167 168 169
    void set_zero_ratio(double ratio);
    double get_voltage(uint64_t index);
    QString get_voltage(double v, int p, bool scaled = false);
    QString get_time(double t);

    /**
     *
     */
    int ratio2value(double ratio) const;
    int ratio2pos(double ratio) const;
    double value2ratio(int value) const;
    double pos2ratio(int pos) const;
DreamSourceLab's avatar
DreamSourceLab committed
170

171 172 173 174 175
    /**
     * paint prepare
     **/
    void paint_prepare();

DreamSourceLab's avatar
DreamSourceLab committed
176 177 178 179 180 181
    /**
     * Paints the background layer of the trace with a QPainter
     * @param p the QPainter to paint into.
     * @param left the x-coordinate of the left edge of the signal
     * @param right the x-coordinate of the right edge of the signal
     **/
Andy Dneg's avatar
Andy Dneg committed
182
    void paint_back(QPainter &p, int left, int right, QColor fore, QColor back);
DreamSourceLab's avatar
DreamSourceLab committed
183

184 185 186 187 188 189
	/**
	 * Paints the signal with a QPainter
	 * @param p the QPainter to paint into.
	 * @param left the x-coordinate of the left edge of the signal.
	 * @param right the x-coordinate of the right edge of the signal.
	 **/
Andy Dneg's avatar
Andy Dneg committed
190
    void paint_mid(QPainter &p, int left, int right, QColor fore, QColor back);
191

DreamSourceLab's avatar
DreamSourceLab committed
192 193 194 195 196 197
    /**
     * Paints the signal with a QPainter
     * @param p the QPainter to paint into.
     * @param left the x-coordinate of the left edge of the signal.
     * @param right the x-coordinate of the right edge of the signal.
     **/
Andy Dneg's avatar
Andy Dneg committed
198
    void paint_fore(QPainter &p, int left, int right, QColor fore, QColor back);
199

200
    QRect get_view_rect() const;
201

DreamSourceLab's avatar
DreamSourceLab committed
202
    QRectF get_trig_rect(int left, int right) const;
203

Andy Dneg's avatar
Andy Dneg committed
204
    QString get_measure(enum DSO_MEASURE_TYPE type);
205

206 207 208 209 210 211
    QRectF get_rect(DsoSetRegions type, int y, int right);

    bool mouse_press(int right, const QPoint pt);

    bool mouse_wheel(int right, const QPoint pt, const int shift);

212

DreamSourceLab's avatar
DreamSourceLab committed
213
protected:
Andy Dneg's avatar
Andy Dneg committed
214
    void paint_type_options(QPainter &p, int right, const QPoint pt, QColor fore);
215 216

private:
Andy Dneg's avatar
Andy Dneg committed
217
    void paint_trace(QPainter &p,
218
        const boost::shared_ptr<pv::data::DsoSnapshot> &snapshot,
Andy Dneg's avatar
Andy Dneg committed
219
        int zeroY, int left, const int64_t start, const int64_t end, int hw_offset,
DreamSourceLab's avatar
v0.3  
DreamSourceLab committed
220 221
        const double pixels_offset, const double samples_per_pixel,
        uint64_t num_channels);
222

Andy Dneg's avatar
Andy Dneg committed
223
    void paint_envelope(QPainter &p,
224
        const boost::shared_ptr<pv::data::DsoSnapshot> &snapshot,
Andy Dneg's avatar
Andy Dneg committed
225
        int zeroY, int left, const int64_t start, const int64_t end, int hw_offset,
DreamSourceLab's avatar
DreamSourceLab committed
226 227 228
        const double pixels_offset, const double samples_per_pixel,
        uint64_t num_channels);

Andy Dneg's avatar
Andy Dneg committed
229 230
    void paint_hover_measure(QPainter &p, QColor fore, QColor back);
    void auto_set();
231 232 233 234

private:
    boost::shared_ptr<pv::data::Dso> _data;
	float _scale;
235
    bool _en_lock;
Andy Dneg's avatar
Andy Dneg committed
236
    bool _show;
DreamSourceLab's avatar
DreamSourceLab committed
237 238 239

    dslDial *_vDial;
    bool _vDialActive;
DreamSourceLab's avatar
DreamSourceLab committed
240
    uint8_t _acCoupling;
241
    uint8_t _bits;
Andy Dneg's avatar
Andy Dneg committed
242 243
    double _ref_min;
    double _ref_max;
DreamSourceLab's avatar
DreamSourceLab committed
244

245 246
    int _trig_value;
    double _trig_delta;
Andy Dneg's avatar
Andy Dneg committed
247
    int _zero_offset;
DreamSourceLab's avatar
DreamSourceLab committed
248

Andy Dneg's avatar
Andy Dneg committed
249
    bool _mValid;
DreamSourceLab's avatar
DreamSourceLab committed
250 251 252
    uint8_t _max;
    uint8_t _min;
    double _period;
Andy Dneg's avatar
Andy Dneg committed
253 254 255 256 257 258 259 260 261 262 263
    bool _level_valid;
    uint8_t _high;
    uint8_t _low;
    double _rms;
    double _mean;
    double _rise_time;
    double _fall_time;
    double _high_time;
    double _burst_time;
    uint32_t _pcount;

DreamSourceLab's avatar
DreamSourceLab committed
264 265
    bool _autoV;
    bool _autoH;
Andy Dneg's avatar
Andy Dneg committed
266 267
    bool _autoV_over;
    uint16_t _auto_cnt;
268 269 270 271

    bool _hover_en;
    uint64_t _hover_index;
    QPointF _hover_point;
Andy Dneg's avatar
Andy Dneg committed
272
    float _hover_value;
273 274 275 276 277
};

} // namespace view
} // namespace pv

DreamSourceLab's avatar
DreamSourceLab committed
278
#endif // DSVIEW_PV_DSOSIGNAL_H