diff --git a/Sources/src/Visnode/main.cpp b/Sources/src/Visnode/main.cpp index 627f7d3..df50d7e 100644 --- a/Sources/src/Visnode/main.cpp +++ b/Sources/src/Visnode/main.cpp @@ -19,6 +19,7 @@ std::future menudraw = std::async (ui::UiDrawer::drawMenu); ui::UiDrawer::drawStartupSequence(); //show startup sequence while camera manager is starting menudraw.get(); fobj.get(); + cameraManager::runCapture(); SerialPortManager::init(); ui::UiController::exitCalled = false; @@ -26,13 +27,13 @@ ui::UiController::runIntro = false; std::thread* t = new std::thread(ui::UiDrawer::runDrawUi); Threadweaver::stick_this_thread_to_core(t,1); -Threadweaver::osUiDrawerThread = t; +Threadweaver::gfxPipelineThread = t; while(!ui::UiController::exitCalled){ sleep(5); } -t->join(); +Threadweaver::gfxPipelineThread->join(); return 0; } \ No newline at end of file diff --git a/Sources/src/Visnode/prog b/Sources/src/Visnode/prog index 9d0b0fd..84a622c 100755 Binary files a/Sources/src/Visnode/prog and b/Sources/src/Visnode/prog differ diff --git a/Sources/src/Visnode/threadweaver/threadweaver.cpp b/Sources/src/Visnode/threadweaver/threadweaver.cpp index abe7529..00b64c5 100644 --- a/Sources/src/Visnode/threadweaver/threadweaver.cpp +++ b/Sources/src/Visnode/threadweaver/threadweaver.cpp @@ -3,6 +3,7 @@ std::vector Threadweaver::captureThreads; std::thread* Threadweaver::hardwareWatcherThread; std::thread* Threadweaver::osUiDrawerThread; +std::thread* Threadweaver::gfxPipelineThread; void Threadweaver::stick_this_thread_to_core(std::thread* t,int core_id){ unsigned num_cpus = std::thread::hardware_concurrency(); diff --git a/Sources/src/Visnode/threadweaver/threadweaver.hpp b/Sources/src/Visnode/threadweaver/threadweaver.hpp index 8d4b003..b1191da 100644 --- a/Sources/src/Visnode/threadweaver/threadweaver.hpp +++ b/Sources/src/Visnode/threadweaver/threadweaver.hpp @@ -9,6 +9,7 @@ class Threadweaver{ public: static std::vector captureThreads; static std::thread* hardwareWatcherThread; + static std::thread* gfxPipelineThread; static std::thread* osUiDrawerThread; static void stick_this_thread_to_core(std::thread* t,int core_id); diff --git a/Sources/src/Visnode/ui/_ui.hpp b/Sources/src/Visnode/ui/_ui.hpp index bd34823..a9b36ad 100644 --- a/Sources/src/Visnode/ui/_ui.hpp +++ b/Sources/src/Visnode/ui/_ui.hpp @@ -26,7 +26,9 @@ namespace ui { //Defines a single ui window (by default two will be displayed) class Ui{ public: + UMat drawBuffer; UMat drawSurface; //Current frame + int id; std::string myWindow; void draw(); }; @@ -47,9 +49,12 @@ namespace ui { }; class UiManager{ //manager is static because we only ever need one public: + static vector accessLocks; static vector managedUIs; + static bool uiShouldRun; static void init(); - static void cleanup(); + static void cleanup(); + static void beginDrawRoutineForUi(Ui* u); }; class UiController{ public: diff --git a/Sources/src/Visnode/ui/ui.cpp b/Sources/src/Visnode/ui/ui.cpp index 9d49299..c5fec5d 100644 --- a/Sources/src/Visnode/ui/ui.cpp +++ b/Sources/src/Visnode/ui/ui.cpp @@ -3,6 +3,10 @@ void ui::Ui::draw(){ if(drawSurface.empty()) return; - imshow(this->myWindow, this->drawSurface); - waitKey(1); + UiManager::accessLocks.at(this->id)->lock(); + drawBuffer = drawSurface; + UiManager::accessLocks.at(this->id)->unlock(); + + imshow(this->myWindow, this->drawBuffer); + waitKey(17); } \ No newline at end of file diff --git a/Sources/src/Visnode/ui/uiDrawer.cpp b/Sources/src/Visnode/ui/uiDrawer.cpp index b98b411..e9499bd 100644 --- a/Sources/src/Visnode/ui/uiDrawer.cpp +++ b/Sources/src/Visnode/ui/uiDrawer.cpp @@ -37,8 +37,10 @@ namespace ui{ cv::hconcat(mats,finished); DEBUG_LOG("concated mats") + + UiManager::accessLocks.at(0)->lock(); UiManager::managedUIs[0]->drawSurface = finished; //write the final image to the psvr UI buffer - UiManager::managedUIs[0]->draw(); //send the image to the psvr + UiManager::accessLocks.at(0)->unlock(); } void UiDrawer::drawStartupSequence(){ diff --git a/Sources/src/Visnode/ui/uiManager.cpp b/Sources/src/Visnode/ui/uiManager.cpp index e03aa2d..52e9784 100644 --- a/Sources/src/Visnode/ui/uiManager.cpp +++ b/Sources/src/Visnode/ui/uiManager.cpp @@ -2,9 +2,19 @@ namespace ui{ vector UiManager::managedUIs; + vector UiManager::accessLocks; + bool UiManager::uiShouldRun; + + void UiManager::beginDrawRoutineForUi(Ui* u){ + while(!ui::UiManager::uiShouldRun){} + while(ui::UiManager::uiShouldRun){ + u->draw(); + } + } //initializes the ui manager, following default values void UiManager::init(){ + uiShouldRun = false; waitKey(1); for(int i=0; imyWindow << " created at " << DEFAULT_UI_OFFSET_X+i*960 << " , " << DEFAULT_UI_OFFSET_Y << endl; + newUI->id = i; + managedUIs.push_back(newUI); //add new ui in the ui map, mapped to the window's name + accessLocks.push_back(new mutex()); + accessLocks.at(i)->unlock(); + std::thread* t = new std::thread(ui::UiManager::beginDrawRoutineForUi,newUI); + Threadweaver::stick_this_thread_to_core(t,0); + Threadweaver::osUiDrawerThread = t; //TODO fix? } + uiShouldRun = true; } void UiManager::cleanup(){