-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOscilloscopeWidget.h
More file actions
81 lines (62 loc) · 2.5 KB
/
OscilloscopeWidget.h
File metadata and controls
81 lines (62 loc) · 2.5 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma once
#include <QWidget>
#include <QVector>
#include <QPixmap>
#include <QTimer>
#include <QFont>
class OscilloscopeWidget : public QWidget {
Q_OBJECT
public:
enum TriggerMode { Auto, Normal, Single };
Q_ENUM(TriggerMode)
enum TriggerEdge { Rising, Falling, Both };
Q_ENUM(TriggerEdge)
explicit OscilloscopeWidget(QWidget *parent = nullptr);
void appendSamples(const QVector<uint16_t> &samples);
void clearData();
void setMaxDisplayPoints(int count);
void setVoltageRange(double minV, double maxV);
void setTriggerMode(TriggerMode mode);
void setTriggerEdge(TriggerEdge edge);
void setTriggerLevel(double voltage);
void armTrigger(); // Single 模式下重新使能触发
QSize sizeHint() const override { return QSize(600, 300); }
QSize minimumSizeHint() const override { return QSize(200, 120); }
protected:
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private slots:
void onRefreshTimer();
private:
void rebuildBackground();
void rebuildOffscreen();
int findTriggerPoint() const;
uint16_t voltageToAdc(double voltage) const;
int m_maxDisplayPoints = 400;
double m_minVoltage = 0.0;
double m_maxVoltage = 3.3;
// 触发
TriggerMode m_triggerMode = Auto;
TriggerEdge m_triggerEdge = Rising;
double m_triggerLevel = 1.65; // 默认中间电压
bool m_triggered = false; // Normal/Single 下是否已触发
bool m_armed = true; // Single 模式下是否使能
// 显示起点:Auto 模式为 -1(自由滚动),Normal/Single 为触发点
int m_displayStartIdx = -1;
QVector<uint16_t> m_data;
QPixmap m_background; // 网格+标签背景层(仅resize/电压范围变化时重建)
bool m_bgDirty = true; // 背景是否需要重建
QPixmap m_offscreen; // 完整帧缓存
bool m_offscreenDirty = true;
bool m_dataDirty = false;
QTimer *m_refreshTimer;
QFont m_labelFont; // Y轴/X轴标签字体
QFont m_valueFont; // 当前值显示字体
static constexpr int LEFT_MARGIN = 50;
static constexpr int RIGHT_MARGIN = 10;
static constexpr int TOP_MARGIN = 20;
static constexpr int BOTTOM_MARGIN = 25;
static constexpr int MAX_BUFFER_POINTS = 100000; // ~200KB,约0.5秒@200kHz
static constexpr QRgb WAVE_RGB = 0xff89b4fa; // ARGB: #89b4fa
static constexpr QRgb TRIGGER_RGB = 0xfff9e2af; // ARGB: #f9e2af (黄色触发电平线)
};