瀏覽代碼

Merge branch 'master' of http://39.100.237.43:3000/kangjiaqi/USB_UVC_DETECT

kappo 1 月之前
父節點
當前提交
1552b588cc
共有 3 個文件被更改,包括 160 次插入34 次删除
  1. 34 0
      .gitignore
  2. 2 1
      .vscode/c_cpp_properties.json
  3. 124 33
      ImageTest/ImageTest.h

+ 34 - 0
.gitignore

@@ -4095,6 +4095,40 @@ build/Makefile
 build/.cmake/api/v1/reply/codemodel-v2-ff68604e9c8c7bb92954.json
 build/.cmake/api/v1/reply/index-2025-02-26T08-13-46-0073.json
 build/.cmake/api/v1/reply/target-UVC_Demo-Debug-60a9e96146f2940d6405.json
+build/CMakeFiles/3.30.0-rc3/CMakeCCompiler.cmake
+build/CMakeFiles/3.30.0-rc3/CMakeCXXCompiler.cmake
+build/CMakeFiles/3.30.0-rc3/CMakeRCCompiler.cmake
+build/CMakeFiles/3.30.0-rc3/CMakeSystem.cmake
+build/CMakeFiles/3.30.0-rc3/VCTargetsPath.txt
+build/CMakeFiles/3.30.0-rc3/VCTargetsPath.vcxproj
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/CMakeCCompilerId.c
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/CompilerIdC.vcxproj
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/Debug/CompilerIdC.exe.recipe
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/Debug/vcpkg.applocal.log
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/Debug/CompilerIdC.tlog/CL.command.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/Debug/CompilerIdC.tlog/Cl.items.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/Debug/CompilerIdC.tlog/CL.read.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/Debug/CompilerIdC.tlog/CL.write.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/Debug/CompilerIdC.tlog/CompilerIdC.lastbuildstate
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/Debug/CompilerIdC.tlog/link.command.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/Debug/CompilerIdC.tlog/link.read.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/Debug/CompilerIdC.tlog/link.secondary.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdC/Debug/CompilerIdC.tlog/link.write.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/CMakeCXXCompilerId.cpp
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/CompilerIdCXX.vcxproj
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/Debug/CompilerIdCXX.exe.recipe
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/Debug/vcpkg.applocal.log
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/Debug/CompilerIdCXX.tlog/CL.command.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/Debug/CompilerIdCXX.tlog/Cl.items.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/Debug/CompilerIdCXX.tlog/CL.read.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/Debug/CompilerIdCXX.tlog/CL.write.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/Debug/CompilerIdCXX.tlog/CompilerIdCXX.lastbuildstate
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/Debug/CompilerIdCXX.tlog/link.command.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/Debug/CompilerIdCXX.tlog/link.read.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/Debug/CompilerIdCXX.tlog/link.secondary.1.tlog
+build/CMakeFiles/3.30.0-rc3/CompilerIdCXX/Debug/CompilerIdCXX.tlog/link.write.1.tlog
+build/CMakeFiles/3.30.0-rc3/VCTargetsPath/x64/Debug/VCTargetsPath.recipe
+build/CMakeFiles/3.30.0-rc3/VCTargetsPath/x64/Debug/VCTargetsPath.tlog/VCTargetsPath.lastbuildstate
 build/backup-030320251408-pre-build.tgz
 build/build_20250303-1_arm64.deb
 build/description-pak

+ 2 - 1
.vscode/c_cpp_properties.json

@@ -16,7 +16,8 @@
             "defines": [
                 "_DEBUG",
                 "UNICODE",
-                "_UNICODE"
+                "_UNICODE",
+                "_LINUX_"
             ],
             "windowsSdkVersion": "10.0.22621.0",
             "compilerPath": "cl.exe",

+ 124 - 33
ImageTest/ImageTest.h

@@ -10,7 +10,7 @@
 #include <thread>
 #include <mutex>
 
-namespace UsbTest
+namespace UsbTest namespace UsbTest
 {
 
     void saveImageFromData(unsigned char *data, int width, int height, const std::string &filename = "./output.png");
@@ -53,31 +53,31 @@ namespace UsbTest
         std::chrono::high_resolution_clock::time_point end_time;
     };
 
-    class GlobalResolutionTimer: public HighResolutionTimer
+    class GlobalResolutionTimer : public HighResolutionTimer
     {
-        public:
-           static GlobalResolutionTimer& getInstance()
-           {
-               static GlobalResolutionTimer instance;
-               return instance;
-           }
-
-           void start()
-           {
-               start_time = std::chrono::high_resolution_clock::now();   
-           }
-
-           std::string pressStopWatchString()
-           {
-                end_time = std::chrono::high_resolution_clock::now();   
-                return "Elapsed Time: " + std::to_string(elapsed_milliseconds()) + " ms";
-           }
+    public:
+        static GlobalResolutionTimer &getInstance()
+        {
+            static GlobalResolutionTimer instance;
+            return instance;
+        }
+
+        void start()
+        {
+            start_time = std::chrono::high_resolution_clock::now();
+        }
+
+        std::string pressStopWatchString()
+        {
+            end_time = std::chrono::high_resolution_clock::now();
+            return "Elapsed Time: " + std::to_string(elapsed_milliseconds()) + " ms";
+        }
     };
 
     class SimulateTrigger
     {
     public:
-        static SimulateTrigger& getInstance()
+        static SimulateTrigger &getInstance()
         {
             static SimulateTrigger instance;
             return instance;
@@ -89,9 +89,9 @@ namespace UsbTest
             {
                 triggering = true;
                 triggerStatus.resize(3);
-                triggerStatus[0]=false;
-                triggerStatus[1]=false;  
-                triggerStatus[2]=false;  
+                triggerStatus[0] = false;
+                triggerStatus[1] = false;
+                triggerStatus[2] = false;
                 triggerThread = std::thread(&SimulateTrigger::triggerLoop, this);
             }
         }
@@ -124,8 +124,8 @@ namespace UsbTest
         }
 
         // Delete copy constructor and assignment operator to prevent copying
-        SimulateTrigger(const SimulateTrigger&) = delete;
-        SimulateTrigger& operator=(const SimulateTrigger&) = delete;
+        SimulateTrigger(const SimulateTrigger &) = delete;
+        SimulateTrigger &operator=(const SimulateTrigger &) = delete;
 
         void triggerLoop()
         {
@@ -136,9 +136,9 @@ namespace UsbTest
                 {
                     // Simulate the trigger signal
                     std::lock_guard<std::mutex> lock(triggerMutex);
-                    triggerStatus[0]=true;
-                    triggerStatus[1]=true;
-                    triggerStatus[2]=true;
+                    triggerStatus[0] = true;
+                    triggerStatus[1] = true;
+                    triggerStatus[2] = true;
                 }
             }
         }
@@ -147,13 +147,108 @@ namespace UsbTest
         std::thread triggerThread;
         std::mutex triggerMutex;
         std::vector<bool> triggerStatus;
+    };
+
+    class GlobalResolutionTimer : public HighResolutionTimer
+    {
+    public:
+        static GlobalResolutionTimer &getInstance()
+        {
+            static GlobalResolutionTimer instance;
+            return instance;
+        }
+
+        void start()
+        {
+            start_time = std::chrono::high_resolution_clock::now();
+        }
 
+        std::string pressStopWatchString()
+        {
+            end_time = std::chrono::high_resolution_clock::now();
+            return "Elapsed Time: " + std::to_string(elapsed_milliseconds()) + " ms";
+        }
+    };
+
+    class SimulateTrigger
+    {
+    public:
+        static SimulateTrigger &getInstance()
+        {
+            static SimulateTrigger instance;
+            return instance;
+        }
+
+        void startTrigger()
+        {
+            if (!triggering)
+            {
+                triggering = true;
+                triggerStatus.resize(3);
+                triggerStatus[0] = false;
+                triggerStatus[1] = false;
+                triggerStatus[2] = false;
+                triggerThread = std::thread(&SimulateTrigger::triggerLoop, this);
+            }
+        }
+
+        void stopTrigger()
+        {
+            if (triggering)
+            {
+                triggering = false;
+                if (triggerThread.joinable())
+                {
+                    triggerThread.join();
+                }
+            }
+        }
+
+        bool isTriggering(int index)
+        {
+            bool status = triggerStatus[index];
+            std::lock_guard<std::mutex> lock(triggerMutex);
+            triggerStatus[index] = false;
+            return status;
+        }
+
+    private:
+        SimulateTrigger() : triggering(false) {}
+        ~SimulateTrigger()
+        {
+            stopTrigger();
+        }
+
+        // Delete copy constructor and assignment operator to prevent copying
+        SimulateTrigger(const SimulateTrigger &) = delete;
+        SimulateTrigger &operator=(const SimulateTrigger &) = delete;
+
+        void triggerLoop()
+        {
+            while (triggering)
+            {
+                std::this_thread::sleep_for(std::chrono::milliseconds(188));
+                if (triggering)
+                {
+                    // Simulate the trigger signal
+                    std::lock_guard<std::mutex> lock(triggerMutex);
+                    triggerStatus[0] = true;
+                    triggerStatus[1] = true;
+                    triggerStatus[2] = true;
+                }
+            }
+        }
+
+        std::atomic<bool> triggering;
+        std::thread triggerThread;
+        std::mutex triggerMutex;
+        std::vector<bool> triggerStatus;
     };
 
     class TimeRecorder
     {
     public:
-        static TimeRecorder& getInstance()
+        static TimeRecorder &getInstance()
         {
             static TimeRecorder instance;
             return instance;
@@ -164,8 +259,6 @@ namespace UsbTest
             log_file = std::fstream("TimeLog.txt", std::ios::app);
         }
 
-        
-
         void recordTime(std::string &message)
         {
             if (log_file.is_open())
@@ -185,9 +278,7 @@ namespace UsbTest
         }
 
         std::fstream log_file;
-
     };
 
-
 }
 #endif // IMAGE_TEST_H