Przeglądaj źródła

V0.2.2
1、完成了处理眼图数据的代码翻译
2、完成了绘图部分
3、处理眼图数据的代码应该还有问题,无法显示出眼图

Apple 4 miesięcy temu
rodzic
commit
d637196aaa
8 zmienionych plików z 479 dodań i 59 usunięć
  1. 162 20
      EyeMap/OscData.cpp
  2. 16 3
      EyeMap/OscData.h
  3. 35 6
      EyeMap/eyemap.cpp
  4. 140 5
      GlobalInfo/GlobalInfo.cpp
  5. 64 9
      GlobalInfo/GlobalInfo.h
  6. 7 3
      oscwidget.cpp
  7. 2 0
      oscwidget.h
  8. 53 13
      oscwidget.ui

+ 162 - 20
EyeMap/OscData.cpp

@@ -86,6 +86,12 @@ bool OscilloscopeData::openOSC()
     m_usbInterface->usbCtrlTrans(0x17, 0x7f);
     /* 设置缓冲区大小 */
     m_usbInterface->setInfo(BUFFER_SIZE);
+    /* 获取零电压值 */
+    getZeroVoltage();
+    /* 获取电压校准系数 */
+    getVoltageCalibration();
+
+
     m_isOpen = true;
     return true;
 }
@@ -188,7 +194,11 @@ void OscilloscopeData::setChannelMerge(bool merge)
     m_usbInterface->usbCtrlTrans(0x24, m_ctrlByte1);
 }
 
-/* 设置通道A输入量程 */
+/**
+ * @brief 设置通道A输入量程,这个函数需要在打开示波器之后调用
+ * 
+ * @param range 
+ */
 void OscilloscopeData::setChannelARange(OscChannelRange range)
 {
     if(m_usbInterface == nullptr)
@@ -230,9 +240,15 @@ void OscilloscopeData::setChannelARange(OscChannelRange range)
         m_usbInterface->usbCtrlTrans(0x22, 0x00);
     }
     m_usbInterface->usbCtrlTrans(0x24, m_ctrlByte1);
+    
+    setZeroVoltageAndCalibration(OscChannel::CH_A, range);
 }
 
-/* 设置通道B输入量程 */
+/**
+ * @brief 设置通道B输入量程
+ * 
+ * @param range 
+ */
 void OscilloscopeData::setChannelBRange(OscChannelRange range)
 {
     if(m_usbInterface == nullptr)
@@ -281,6 +297,8 @@ void OscilloscopeData::setChannelBRange(OscChannelRange range)
         return;
     }
     m_usbInterface->usbCtrlTrans(0x24, m_ctrlByte1);
+
+    setZeroVoltageAndCalibration(OscChannel::CH_B, range);
 }
 
 /**
@@ -535,48 +553,48 @@ void OscilloscopeData::getVoltageCalibration()
     unsigned char voltageCalibration = 0;
     /* 2V档位,正负8V量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0xc2);
-    m_mapChAVoltageCalibration.insert(OscChannelRange::CR_8V, voltageCalibration);
+    m_mapChAVoltageAmplitudeRatio.insert(OscChannelRange::CR_8V, voltageCalibration);
     /* 1V档位,正负5V量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0x03);
-    m_mapChAVoltageCalibration.insert(OscChannelRange::CR_5V, voltageCalibration);
+    m_mapChAVoltageAmplitudeRatio.insert(OscChannelRange::CR_5V, voltageCalibration);
     /* 500mV档位,正负2.5V量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0x08);
-    m_mapChAVoltageCalibration.insert(OscChannelRange::CR_2V5, voltageCalibration);
+    m_mapChAVoltageAmplitudeRatio.insert(OscChannelRange::CR_2V5, voltageCalibration);
     /* 200mV档位,正负1V量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0x06);
-    m_mapChAVoltageCalibration.insert(OscChannelRange::CR_1V, voltageCalibration);
+    m_mapChAVoltageAmplitudeRatio.insert(OscChannelRange::CR_1V, voltageCalibration);
     /* 100mV档位,正负500mV量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0x09);
-    m_mapChAVoltageCalibration.insert(OscChannelRange::CR_500MV, voltageCalibration);
+    m_mapChAVoltageAmplitudeRatio.insert(OscChannelRange::CR_500MV, voltageCalibration);
     /* 50mV档位,正负250mV量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0x0a);
-    m_mapChAVoltageCalibration.insert(OscChannelRange::CR_250MV, voltageCalibration);
+    m_mapChAVoltageAmplitudeRatio.insert(OscChannelRange::CR_250MV, voltageCalibration);
     /* 20mV档位,正负100mV量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0x2a);
-    m_mapChAVoltageCalibration.insert(OscChannelRange::CR_100MV, voltageCalibration);
+    m_mapChAVoltageAmplitudeRatio.insert(OscChannelRange::CR_100MV, voltageCalibration);
 
     /* 获取通道B电压校准系数 */
     /* 2V档位,正负8V量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0xd2);
-    m_mapChBVoltageCalibration.insert(OscChannelRange::CR_8V, voltageCalibration);
+    m_mapChBVoltageAmplitudeRatio.insert(OscChannelRange::CR_8V, voltageCalibration);
     /* 1V档位,正负5V量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0x04);
-    m_mapChBVoltageCalibration.insert(OscChannelRange::CR_5V, voltageCalibration);
+    m_mapChBVoltageAmplitudeRatio.insert(OscChannelRange::CR_5V, voltageCalibration);
     /* 500mV档位,正负2.5V量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0x0b);
-    m_mapChBVoltageCalibration.insert(OscChannelRange::CR_2V5, voltageCalibration);
+    m_mapChBVoltageAmplitudeRatio.insert(OscChannelRange::CR_2V5, voltageCalibration);
     /* 200mV档位,正负1V量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0x07);
-    m_mapChBVoltageCalibration.insert(OscChannelRange::CR_1V, voltageCalibration);
+    m_mapChBVoltageAmplitudeRatio.insert(OscChannelRange::CR_1V, voltageCalibration);
     /* 100mV档位,正负500mV量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0x0c);
-    m_mapChBVoltageCalibration.insert(OscChannelRange::CR_500MV, voltageCalibration);
+    m_mapChBVoltageAmplitudeRatio.insert(OscChannelRange::CR_500MV, voltageCalibration);
     /* 50mV档位,正负250mV量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0x0d);
-    m_mapChBVoltageCalibration.insert(OscChannelRange::CR_250MV, voltageCalibration);
+    m_mapChBVoltageAmplitudeRatio.insert(OscChannelRange::CR_250MV, voltageCalibration);
     /* 20mV档位,正负100mV量程 */
     voltageCalibration = m_usbInterface->usbCtrlTrans(0x90, 0x2d);
-    m_mapChBVoltageCalibration.insert(OscChannelRange::CR_100MV, voltageCalibration);
+    m_mapChBVoltageAmplitudeRatio.insert(OscChannelRange::CR_100MV, voltageCalibration);
 
 }
 
@@ -585,14 +603,14 @@ void OscilloscopeData::printVoltageCalibration(OscChannel channel)
 {
     if(channel == OscChannel::CH_A)
     {
-        for(auto it = m_mapChAVoltageCalibration.begin(); it != m_mapChAVoltageCalibration.end(); ++it)
+        for(auto it = m_mapChAVoltageAmplitudeRatio.begin(); it != m_mapChAVoltageAmplitudeRatio.end(); ++it)
         {
             SPDLOG_LOGGER_INFO(m_logger, "通道A {} 量程下的电压校准系数为: {}", static_cast<int>(it.key()), it.value());
         }
     }
     else if(channel == OscChannel::CH_B)
     {
-        for(auto it = m_mapChBVoltageCalibration.begin(); it != m_mapChBVoltageCalibration.end(); ++it)
+        for(auto it = m_mapChBVoltageAmplitudeRatio.begin(); it != m_mapChBVoltageAmplitudeRatio.end(); ++it)
         {
             SPDLOG_LOGGER_INFO(m_logger, "通道B {} 量程下的电压校准系数为: {}", static_cast<int>(it.key()), it.value());
         }
@@ -674,6 +692,7 @@ void OscilloscopeData::threadProcessData()
             m_mutexCaptureData.unlock();
             /* 处理数据 */
             SPDLOG_LOGGER_DEBUG(m_logger, "开始处理数据,通道A数据: {}, 通道B数据: {}", m_bufferChnA[32000], m_bufferChnB[32000]);
+            /* 矫正零电压值 */
         }
         /* 打印1000个数据 */
         // for(uint32_t i = 0; i < BUFFER_SIZE/2; i++)
@@ -688,6 +707,18 @@ void OscilloscopeData::threadProcessData()
     }
 }
 
+/* 根据采样点数添加颜色 */
+void OscilloscopeData::threadAddColorBySample()
+{
+    // while(m_runCapture)
+    {
+        g_eyeMapMatrix.mutexEyeData.lock();
+        g_eyeMapMatrix.addColorBySample();
+        g_eyeMapMatrix.mutexEyeData.unlock();
+    }
+    
+}
+
 /**
  * @brief 解析数据,眼图需要的数据,从C#代码中移植过来
  * 
@@ -799,13 +830,13 @@ void OscilloscopeData::parseEyeMapData(unsigned char* buffer, unsigned int size)
     bool flag3 = true;
     /* 找到数组中的上升沿和下降沿,并记录其坐标 */
     uint8_t vaPre = 0;
-    uint8_t va = 0;
+    // uint8_t va = 0;
     uint8_t vaNext = 0;
     for (int i = 10; i < num3; i++)
     {
         /* 取出相邻的三个值 */
         vaPre = vecData[i - 1].value;
-        va = vecData[i].value;
+        // va = vecData[i].value;
         vaNext = vecData[i + 1].value;
         if (flag3)
         {
@@ -886,6 +917,7 @@ void OscilloscopeData::parseEyeMapData(unsigned char* buffer, unsigned int size)
     int num18 = 0;
     int num19 = 0;
     float num20 = 0.0;
+    /* 将数据拷贝到OscData的Matrix中 */
     for (int i = 0; i < list2.size(); i++)
     {
         std::vector<EyeDataT> list5 = list2[i];
@@ -913,7 +945,117 @@ void OscilloscopeData::parseEyeMapData(unsigned char* buffer, unsigned int size)
     g_eyeDataMatrix.eyeLessenTheBurden();
     list2.clear();
     // pEyeData[,] eyedata = globleVariables.g_IeyeDataMatrix.eyeZoomOut();
+    auto eyeData = g_eyeDataMatrix.eyeZoomOut();
     // GraphView.m_eyedMatrux.EyeDataMatrixCopy(eyedata);
+    g_eyeMapMatrix.mutexEyeData.lock();
+    g_eyeMapMatrix.copyDataMatrix(*eyeData);
+    g_eyeMapMatrix.mutexEyeData.unlock();
+}
+
+
+/* 设置零电压值和电压校准系数 */
+void OscilloscopeData::setZeroVoltageAndCalibration(OscChannel chn, OscChannelRange range)
+{
+
+    if(chn == OscChannel::CH_A)
+    {
+        /* 电压幅值比 */
+        uint8_t altitudeByteA = 0;
+        m_zeroVoltageA = m_mapChAZeroVoltage.value(range);
+        altitudeByteA = m_mapChAVoltageAmplitudeRatio.value(range);
+
+        if(range == OscChannelRange::CR_100MV)
+        {
+            m_voltageCalibrationA = (altitudeByteA * 2) / 255.0;
+            m_rangeRatioA = 0.1 / 255.0;
+        }
+        else if(range == OscChannelRange::CR_250MV)
+        {
+            m_voltageCalibrationA = (altitudeByteA * 2) / 255.0;
+            m_rangeRatioA = 0.25 / 255.0;
+        }
+        else if(range == OscChannelRange::CR_500MV)
+        {
+            m_voltageCalibrationA = (altitudeByteA * 2) / 255.0;
+            m_rangeRatioA = 0.5 / 255.0;
+        }
+        else if(range == OscChannelRange::CR_1V)
+        {
+            m_voltageCalibrationA = (altitudeByteA * 2) / 255.0;
+            m_rangeRatioA = 1.0 / 255.0;
+        }
+        else if(range == OscChannelRange::CR_2V5)
+        {
+            m_voltageCalibrationA = (altitudeByteA * 2) / 255.0;
+            m_rangeRatioA = 2.5 / 255.0;
+        }
+        else if(range == OscChannelRange::CR_5V)
+        {
+            m_voltageCalibrationA = (altitudeByteA * 2) / 255.0;
+            m_rangeRatioA = 5.0 / 255.0;
+        }
+        else if(range == OscChannelRange::CR_8V)
+        {
+            m_voltageCalibrationA = (altitudeByteA * 2) / 255.0;
+            m_rangeRatioA = 8.0 / 255.0;
+        }
+    }
+    else if(chn == OscChannel::CH_B)
+    {
+        /* 电压幅值比 */
+        uint8_t altitudeByteB = 0;      
+        m_zeroVoltageB = m_mapChBZeroVoltage.value(range);
+        altitudeByteB = m_mapChBVoltageAmplitudeRatio.value(range);
+
+        if(range == OscChannelRange::CR_100MV)
+        {
+            m_voltageCalibrationB = (altitudeByteB * 2) / 255.0;
+            m_rangeRatioB = 0.1 / 255.0;
+        }
+        else if(range == OscChannelRange::CR_250MV)
+        {
+            m_voltageCalibrationB = (altitudeByteB * 2) / 255.0;
+            m_rangeRatioB = 0.25 / 255.0;
+        }
+        else if(range == OscChannelRange::CR_500MV)
+        {
+            m_voltageCalibrationB = (altitudeByteB * 2) / 255.0;
+            m_rangeRatioB = 0.5 / 255.0;
+        }
+        else if(range == OscChannelRange::CR_1V)
+        {
+            m_voltageCalibrationB = (altitudeByteB * 2) / 255.0;
+            m_rangeRatioB = 1.0 / 255.0;
+        }
+        else if(range == OscChannelRange::CR_2V5)
+        {
+            m_voltageCalibrationB = (altitudeByteB * 2) / 255.0;
+            m_rangeRatioB = 2.5 / 255.0;
+        }
+        else if(range == OscChannelRange::CR_5V)
+        {
+            m_voltageCalibrationB = (altitudeByteB * 2) / 255.0;
+            m_rangeRatioB = 5.0 / 255.0;
+        }
+        else if(range == OscChannelRange::CR_8V)
+        {
+            m_voltageCalibrationB = (altitudeByteB * 2) / 255.0;
+            m_rangeRatioB = 8.0 / 255.0;
+        }
+    }
+
+    
+}
+
+
+/* 校准电压 */
+double OscilloscopeData::calibrationVoltageA(uint8_t& data)
+{
+    return m_voltageCalibrationA * m_rangeRatioA * (data - m_zeroVoltageA);
 }
 
+double OscilloscopeData::calibrationVoltageB(uint8_t& data)
+{
+    return m_voltageCalibrationB * m_rangeRatioB * (data - m_zeroVoltageB);
+}
 

+ 16 - 3
EyeMap/OscData.h

@@ -82,9 +82,16 @@ public:
     void threadCaptureData();
     /* 处理数据线程 */
     void threadProcessData();
+    /* 根据采样点数添加颜色 */
+    void threadAddColorBySample();
 
     /* 解析数据,眼图需要的数据 */
     void parseEyeMapData(unsigned char* buffer, unsigned int size);
+    /* 设置零电压值和电压校准系数 */
+    void setZeroVoltageAndCalibration(OscChannel chn, OscChannelRange range);
+    /* 校准电压 */
+    inline double calibrationVoltageA(uint8_t& data);
+    inline double calibrationVoltageB(uint8_t& data);
 
 private:
     std::shared_ptr<spdlog::logger> m_logger = nullptr;
@@ -105,9 +112,15 @@ private:
 
     QMap<OscChannelRange, unsigned char> m_mapChAZeroVoltage;   /* 通道A的零电压值 */
     QMap<OscChannelRange, unsigned char> m_mapChBZeroVoltage;   /* 通道B的零电压值 */
-    QMap<OscChannelRange, unsigned char> m_mapChAVoltageCalibration;   /* 通道A的电压校准系数 */
-    QMap<OscChannelRange, unsigned char> m_mapChBVoltageCalibration;   /* 通道B的电压校准系数 */
-
+    QMap<OscChannelRange, unsigned char> m_mapChAVoltageAmplitudeRatio;     /* 通道A的电压校准系数 */
+    QMap<OscChannelRange, unsigned char> m_mapChBVoltageAmplitudeRatio;     /* 通道B的电压校准系数 */
+
+    unsigned char m_zeroVoltageA = 0;                       /* 通道A零电压值 */
+    unsigned char m_zeroVoltageB = 0;                       /* 通道B零电压值 */
+    double m_voltageCalibrationA = 0;                       /* 通道A电压校准系数 */
+    double m_voltageCalibrationB = 0;                       /* 通道B电压校准系数 */
+    double m_rangeRatioA = 0.0;                             /* 通道A量程比例 */
+    double m_rangeRatioB = 0.0;                             /* 通道B量程比例 */
 };
 
 

+ 35 - 6
EyeMap/eyemap.cpp

@@ -3,6 +3,7 @@
 
 #include <QApplication>
 #include <QPainter>
+#include <QPaintEvent>
 
 EyeMap::EyeMap(QWidget *parent) :
     QWidget(parent),
@@ -16,7 +17,9 @@ EyeMap::EyeMap(QWidget *parent) :
         return;
     }
     /* 自定义大小 */
-    setFixedSize(1600, 900);
+    setFixedSize(1920, 1080);
+    /* 初始化全局数据 */
+    g_eyeMapMatrix.initEyeMapData(this->width(), this->height());
 
     SPDLOG_LOGGER_INFO(m_logger, "EyeMap 初始化成功");
 
@@ -36,15 +39,41 @@ EyeMap::~EyeMap()
 void EyeMap::paintEvent(QPaintEvent *event)
 {
     QPainter painter(this);
-    /* 绘制背景 */
+    
+    QPen pen;
+    pen.setColor(Qt::black);
+    pen.setWidth(1);
+    pen.setStyle(Qt::SolidLine);
+    QBrush brush;
+    brush.setColor(Qt::yellow);
+    brush.setStyle(Qt::SolidPattern);
+    
     painter.setRenderHint(QPainter::Antialiasing, true);
-    painter.setPen(QPen(Qt::blue, 1, Qt::SolidLine));
-    painter.setBrush(QBrush(Qt::black, Qt::SolidPattern));
-    painter.drawRect(0, 0, 1600, 900);
+    /* 绘制背景 */
+    painter.setPen(pen);
+    painter.setBrush(brush);
+    // painter.drawRect(0, 0, 1600, 900);
     /* 绘制刻度 */
 
     /* 绘制网格 */
     
-    /* 绘制眼图 */
+    /* 绘制眼图,就是绘制 1000 * 256 个矩形 */
+    painter.setPen(QPen(Qt::NoPen));
+    g_eyeMapMatrix.mutexEyeData.lock();
+    for(int i = 0; i < 1000; i++)
+    {
+        for(int j = 0; j < 256; j++)
+        {
+            // if(g_eyeMapMatrix.dataMatrix[i][j].isDraw == false)
+            // {
+            //     continue;
+            // }
+            painter.setBrush(QBrush(g_eyeMapMatrix.dataMatrix[i][j].color));
+            painter.drawRect(g_eyeMapMatrix.dataMatrix[i][j].rect);
+        }
+    }
+    g_eyeMapMatrix.mutexEyeData.unlock();
+
+    event->accept();
 }
 

+ 140 - 5
GlobalInfo/GlobalInfo.cpp

@@ -1,11 +1,22 @@
 #include "GlobalInfo.h"
 
-
+/* OscData使用的眼图矩阵 */
 EyeDataMatrix g_eyeDataMatrix;
+/* OscWidget使用的眼图矩阵 */
+EyeMapMatrix g_eyeMapMatrix;
+
+
+
+EyeDataMatrix::EyeDataMatrix() : dataMatrix(1000, std::vector<EyeDataSample>(256))
+{
+
+}
+
 
+/* 给一个采样点添加个数,为啥使用浮点数,添加0.99,不直接添加正数呢 */
 void EyeDataMatrix::addData(int x, int y) 
 {
-    if(dataMatrix[x][y].Cnt < 79999.0)
+    if(dataMatrix[x][y].fCnt < 79999.0)
     {
         dataMatrix[x][y].fCnt += eyenWeightCoefficient;
     }
@@ -69,9 +80,9 @@ void EyeDataMatrix::eyeLessenTheBurden()
 }
 
 
-EyeDataSample** EyeDataMatrix::eyeZoomOut()
+std::shared_ptr<Vec2D> EyeDataMatrix::eyeZoomOut()
 {
-	EyeDataSample (*array)[256] = new EyeDataSample[1000][256];
+	std::shared_ptr<Vec2D> array = std::make_shared<Vec2D>(1000, std::vector<EyeDataSample>(256));
 	for (int i = 0; i < 1000; i++)
 	{
 		for (int j = 0; j < 256; j++)
@@ -85,10 +96,134 @@ EyeDataSample** EyeDataMatrix::eyeZoomOut()
 				pEyeData2.fCnt /= 100.0;
 				pEyeData2.Cnt = (int)pEyeData2.fCnt;
 			}
-			array[i][j] = pEyeData2;
+			(*array)[i][j] = pEyeData2;
 		}
 	}
 	return array;
 }
 
 
+/* 初始化数据点 */
+void EyeMapMatrix::initEyeMapData(int width, int height)
+{
+    float saH = (float)height / 256.0;
+    float saW = (float)width / 1000.0;
+    for(int i = 0; i < 1000; i++)
+    {
+        for(int j = 0; j < 256; j++)
+        {
+            dataMatrix[i][j].x = (int)(i * saW);
+            dataMatrix[i][j].y = (int)(j * saH);
+            dataMatrix[i][j].rect = QRect(dataMatrix[i][j].x, dataMatrix[i][j].y, (int)saW, (int)saH);
+        }
+    }
+}
+
+/* 拷贝数据到数组中 */
+void EyeMapMatrix::copyDataMatrix(Vec2D& data)
+{
+    for (int i = 0; i < 1000; i++)
+    {
+        for (int j = 0; j < 256; j++)
+        {
+            if (dataMatrix[i][j].Count != data[i][j].fCnt)
+            {
+                if (data[i][j].fCnt > 799.0)
+                {
+                    dataMatrix[i][j].Count = 799;
+                }
+                else
+                {
+                    dataMatrix[i][j].Count = data[i][j].fCnt;
+                }
+            }
+        }
+    }
+}
+
+/* 将Count数值与颜色对应 */
+void EyeMapMatrix::addColorBySample()
+{
+    int r = 0;
+    int g = 0;
+    int b = 0;
+    double dec = 255 / 100.0;
+    for(int i = 0; i < 1000; i++)
+    {
+        for(int j = 0; j < 256; j++)
+        {
+            if(dataMatrix[i][j].isDraw == false)
+            {
+                continue;
+            }
+            if(dataMatrix[i][j].Count < 0)
+            {
+                dataMatrix[i][j].Count = 0;
+                continue;
+            }
+            if(dataMatrix[i][j].Count > 799)
+            {
+                dataMatrix[i][j].Count = 799;
+            }
+            /* 1~100,RGB开始减G,往紫色方向走,为显示清楚,G直接从200开始减 */
+            if(dataMatrix[i][j].Count >= 1 && dataMatrix[i][j].Count <= 100)
+            {
+                r = 255;
+                g = 200 - dataMatrix[i][j].Count * 2;
+                b = 255;
+            }
+            /* 101~200,R0B开始减R,往蓝色方向走,这里开始100分成255份 */
+            else if(dataMatrix[i][j].Count >= 101 && dataMatrix[i][j].Count <= 200)
+            {
+                r = 255 - (dataMatrix[i][j].Count - 100) * dec;
+                g = 0;
+                b = 255;
+            }
+            /* 201~300,00B开始增加G,往青色方向走 */
+            else if (dataMatrix[i][j].Count >= 201 && dataMatrix[i][j].Count <= 300)
+            {
+                r = 0;
+                g = (dataMatrix[i][j].Count - 200) * dec;
+                b = 255;
+            }
+            /* 301~400,0GB开始减B,往绿色方向走 */
+            else if (dataMatrix[i][j].Count >= 301 && dataMatrix[i][j].Count <= 400)
+            {
+                r = 0;
+                g = 255;
+                b = 255 - (dataMatrix[i][j].Count - 300) * dec;
+            }
+            /* 401~500,0G0开始增加R,往黄色方向走 */
+            else if (dataMatrix[i][j].Count >= 401 && dataMatrix[i][j].Count <= 500)
+            {
+                r = (dataMatrix[i][j].Count - 400) * dec;
+                g = 255;
+                b = 0;
+            }
+            /* 501~600,RG0开始减G,往红色方向走 */
+            else if (dataMatrix[i][j].Count >= 501 && dataMatrix[i][j].Count <= 600)
+            {
+                r = 255;
+                g = 255 - (dataMatrix[i][j].Count - 500) * dec;
+                b = 0;
+            }
+            /* 601~700,R00开始减R,往黑色方向走 */
+            else if (dataMatrix[i][j].Count >= 601 && dataMatrix[i][j].Count <= 700)
+            {
+                r = 255 - (dataMatrix[i][j].Count - 600) * dec;
+                g = 0;
+                b = 0;
+            }
+            /* 大于700,直接显示黑色 */
+            else
+            {
+                r = 0;
+                g = 0;
+                b = 0;
+            }
+            dataMatrix[i][j].color = QColor(r, g, b);
+        }
+    }
+}
+
+

+ 64 - 9
GlobalInfo/GlobalInfo.h

@@ -2,6 +2,9 @@
 #define GLOBALINFO_H
 
 #include <mutex>
+#include <vector>
+#include <QRect>
+#include <QColor>
 
 /* 示波器通道 */
 enum class OscChannel
@@ -72,10 +75,10 @@ struct EyeDataT
 /* 眼图数据点 */
 struct EyeDataSample
 {
-    int x;
-    int y;
-    double fCnt;
-    int Cnt;
+    int x;              /* X坐标? */
+    int y;              /* Y坐标? */
+    double fCnt;        /* 颜色深浅? */
+    int Cnt;            /*  */
     unsigned char data;
 
     EyeDataSample() : x(0), y(0), fCnt(0.0), Cnt(0), data(0) {}
@@ -92,8 +95,8 @@ struct EyeDataSample
     }
 };
 
-
-
+/* 类型重命名 */
+using Vec2D = std::vector<std::vector<EyeDataSample>>;
 /**
  * @brief 眼图数据
  * 
@@ -103,16 +106,17 @@ class EyeDataMatrix
 
 public:
     EyeDataMatrix();
-    ~EyeDataMatrix();
+    ~EyeDataMatrix() {}
 
-    EyeDataSample dataMatrix[1000][256];
+    Vec2D dataMatrix;
+    // EyeDataSample dataMatrix[1000][256];
     std::mutex mutexEyeData;
     
 
     void addData(int x, int y);
     void eyeStatisticalWeight();
     void eyeLessenTheBurden();
-    EyeDataSample** eyeZoomOut();
+    std::shared_ptr<Vec2D> eyeZoomOut();
 
 private:
     double eyenWeightCoefficient = 0.99;
@@ -122,5 +126,56 @@ private:
 extern EyeDataMatrix g_eyeDataMatrix;
 
 
+/**
+ * @brief 绘制到窗口的眼图数据
+ *        总共有1000 * 245个数据点充满屏幕,每个数据点是个矩形
+ *        每个数据点的颜色深浅由fCnt决定,该点的数据越多,像素颜色越深
+ * 
+ */
+struct EyeMapDataSample
+{
+    bool isDraw;    /* 是否绘制 */
+    int x;
+    int y;
+    int Count;      /* 像素点的个数(颜色深度),这里限制为799,不知道为什么 */
+    unsigned char data;     /* 数据值 */
+    QRect rect;     /* 像素点的矩形区域 */
+    QColor color;   /* 颜色 */
+
+    EyeMapDataSample() : isDraw(false), x(0), y(0), Count(0), data(0), color(255, 255, 255) {}
+    EyeMapDataSample(EyeDataSample& data) : isDraw(false), x(data.x), y(data.y), Count(data.Cnt), data(data.data) {}
+    EyeMapDataSample& operator=(const EyeMapDataSample& data) {
+        x = data.x;
+        y = data.y;
+        Count = data.Count;
+        isDraw = data.isDraw;
+        rect = data.rect;
+        return *this;
+    }
+};
+
+using Vec2DMap = std::vector<std::vector<EyeMapDataSample>>;
+/**
+ * @brief 眼图数据矩阵
+ * 
+ */
+class EyeMapMatrix
+{
+public:
+    EyeMapMatrix() : dataMatrix(1000, std::vector<EyeMapDataSample>(256)) {}
+    ~EyeMapMatrix() {}
+
+    Vec2DMap dataMatrix;
+    std::mutex mutexEyeData;
+    /* 初始化数据点 */
+    void initEyeMapData(int width, int height);
+    /* 拷贝数据到数组中 */
+    void copyDataMatrix(Vec2D& data);
+    /* 将Count数值与颜色对应 */
+    void addColorBySample();
+};
+extern EyeMapMatrix g_eyeMapMatrix;
+
+
 
 #endif /* GLOBALINFO_H */

+ 7 - 3
oscwidget.cpp

@@ -16,7 +16,12 @@ OscWidget::OscWidget(QWidget *parent) :
         return;
     }
     /* 自定义大小 */
-    setFixedSize(1600, 900);
+    // setFixedSize(1920, 1080);
+
+    /* 设置眼图窗口 */
+    m_eyeMap = new EyeMap(ui->widget_display);
+
+    
 
     SPDLOG_LOGGER_INFO(m_logger, "EyeMap 初始化成功");
     OscData.initOsc();
@@ -28,11 +33,9 @@ OscWidget::OscWidget(QWidget *parent) :
         return;
     }
     /* 获取零电压值 */
-    OscData.getZeroVoltage();
     OscData.printZeroVoltage(OscChannel::CH_A);
     OscData.printZeroVoltage(OscChannel::CH_B);
     /* 获取电压校准系数 */
-    OscData.getVoltageCalibration();
     OscData.printVoltageCalibration(OscChannel::CH_A);
     OscData.printVoltageCalibration(OscChannel::CH_B);
 
@@ -67,6 +70,7 @@ void OscWidget::on_pBtn_capOne_clicked()
     SPDLOG_LOGGER_INFO(m_logger, "采集一次数据");
     OscData.threadCaptureData();
     OscData.threadProcessData();
+    OscData.threadAddColorBySample();
     
     update();
 }

+ 2 - 0
oscwidget.h

@@ -3,6 +3,7 @@
 
 #include <QWidget>
 #include "spdlog/spdlog.h"
+#include "eyemap.h"
 
 namespace Ui {
 class OscWidget;
@@ -22,6 +23,7 @@ private slots:
 private:
     Ui::OscWidget *ui;
     std::shared_ptr<spdlog::logger> m_logger = nullptr;
+    EyeMap* m_eyeMap = nullptr;
 };
 
 #endif // OSCWIDGET_H

+ 53 - 13
oscwidget.ui

@@ -6,26 +6,66 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>1049</width>
-    <height>755</height>
+    <width>1600</width>
+    <height>1080</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
-  <widget class="QPushButton" name="pBtn_capOne">
-   <property name="geometry">
-    <rect>
-     <x>110</x>
-     <y>80</y>
-     <width>121</width>
-     <height>41</height>
-    </rect>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="spacing">
+    <number>0</number>
    </property>
-   <property name="text">
-    <string>采集一次数据</string>
+   <property name="leftMargin">
+    <number>0</number>
    </property>
-  </widget>
+   <property name="topMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <property name="bottomMargin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="QWidget" name="widget_display" native="true">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="minimumSize">
+      <size>
+       <width>1600</width>
+       <height>900</height>
+      </size>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QWidget" name="widget" native="true">
+     <layout class="QGridLayout" name="gridLayout">
+      <item row="0" column="0">
+       <widget class="QPushButton" name="pBtn_capOne">
+        <property name="text">
+         <string>采集一次数据</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QPushButton" name="pushButton">
+        <property name="text">
+         <string>PushButton</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
  </widget>
  <resources/>
  <connections/>