run splash on own thread
This commit is contained in:
		
							parent
							
								
									abc449acbc
								
							
						
					
					
						commit
						0f1a6f1ba0
					
				
					 3 changed files with 30 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -53,5 +53,5 @@ set(PROJECT_SOURCES
 | 
			
		|||
 | 
			
		||||
add_executable(MAClient ${PROJECT_SOURCES})
 | 
			
		||||
target_compile_options(MAClient PRIVATE "-std=gnu++17" "-Wall" "-O2" "-fno-strict-aliasing")
 | 
			
		||||
target_link_libraries(MAClient PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Concurrent ${OpenCV_LIBS} -luvoscam -luvosled -luvosunwrap)
 | 
			
		||||
target_link_libraries(MAClient PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Concurrent ${OpenCV_LIBS} -luvoscam -luvosled -luvosunwrap -pthread)
 | 
			
		||||
target_include_directories(${PROJECT_NAME} PRIVATE ${OpenCV_INCLUDE_DIRS} src src/ui)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,8 @@
 | 
			
		|||
#include <string>
 | 
			
		||||
#include <functional>
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <thread>
 | 
			
		||||
#include <chrono>
 | 
			
		||||
#include <QTimer>
 | 
			
		||||
 | 
			
		||||
Cameras::Cameras(uvosled* led): led_(led)
 | 
			
		||||
| 
						 | 
				
			
			@ -80,8 +81,7 @@ bool Cameras::addCamera(const cam::Camera::Description& desc)
 | 
			
		|||
		camera->cam()->setAcquisitionMode(cam::Camera::MODE_FREE);
 | 
			
		||||
		camera->cam()->setFrameRate(10);
 | 
			
		||||
		camera->cam()->startAcquisition();
 | 
			
		||||
		struct timespec tv = {0, 200000000};
 | 
			
		||||
		nanosleep(&tv, nullptr);
 | 
			
		||||
		std::this_thread::sleep_for (std::chrono::milliseconds(200));
 | 
			
		||||
		camera->cam()->stopAcquisition();
 | 
			
		||||
		cameras_.pop_back();
 | 
			
		||||
		camera = nullptr;
 | 
			
		||||
| 
						 | 
				
			
			@ -97,7 +97,7 @@ bool Cameras::addCamera(const cam::Camera::Description& desc)
 | 
			
		|||
		camera->cam()->setAcquisitionMode(cam::Camera::MODE_FREE);
 | 
			
		||||
		camera->cam()->setFrameRate(10);
 | 
			
		||||
		camera->cam()->startAcquisition();
 | 
			
		||||
		QTimer::singleShot(5000, [camera, this](){finishAddCamera(camera);});
 | 
			
		||||
		QTimer::singleShot(5000, [this, camera](){finishAddCamera(camera);});
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										37
									
								
								src/main.cpp
									
										
									
									
									
								
							
							
						
						
									
										37
									
								
								src/main.cpp
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -6,7 +6,8 @@
 | 
			
		|||
#include <QMessageBox>
 | 
			
		||||
#include <QSplashScreen>
 | 
			
		||||
#include <QDir>
 | 
			
		||||
#include <QThread>
 | 
			
		||||
#include <thread>
 | 
			
		||||
#include <chrono>
 | 
			
		||||
#include <opencv2/core/mat.hpp>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <uvosunwrap/log.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -23,6 +24,8 @@ const char* organziation = "UVOS";
 | 
			
		|||
const char* application  = "UVOS";
 | 
			
		||||
const char* version  = "UVOS";
 | 
			
		||||
 | 
			
		||||
std::atomic<bool> closeSplash = false;
 | 
			
		||||
 | 
			
		||||
std::vector<cam::Camera::Description> showCameraSelectionDialog(bool* accepted = nullptr)
 | 
			
		||||
{
 | 
			
		||||
	std::vector<cam::Camera::Description> ret;
 | 
			
		||||
| 
						 | 
				
			
			@ -54,24 +57,34 @@ void showProfileDialog(Cameras* cameras)
 | 
			
		|||
	cameras->disable(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void showSplash()
 | 
			
		||||
{
 | 
			
		||||
	QSplashScreen splash(QPixmap(":/images/splash.png"));
 | 
			
		||||
	splash.show();
 | 
			
		||||
	while(!closeSplash)
 | 
			
		||||
	{
 | 
			
		||||
		splash.repaint();
 | 
			
		||||
		std::this_thread::sleep_for(std::chrono::milliseconds(100));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
	Log::level = Log::WARN;
 | 
			
		||||
 | 
			
		||||
	QApplication a(argc, argv);
 | 
			
		||||
	QCoreApplication::setOrganizationName("UVOS");
 | 
			
		||||
	QCoreApplication::setOrganizationDomain("uvos.xyz");
 | 
			
		||||
	QCoreApplication::setApplicationName("LubircantThiknessMapperUi");
 | 
			
		||||
	QCoreApplication::setApplicationVersion("0.1");
 | 
			
		||||
 | 
			
		||||
	std::thread splashThred(&showSplash);
 | 
			
		||||
 | 
			
		||||
	uvosled led;
 | 
			
		||||
	int uvosledRet = uvosled_connect(&led);
 | 
			
		||||
	int ret;
 | 
			
		||||
	
 | 
			
		||||
	{
 | 
			
		||||
		QApplication a(argc, argv);
 | 
			
		||||
		QCoreApplication::setOrganizationName("UVOS");
 | 
			
		||||
		QCoreApplication::setOrganizationDomain("uvos.xyz");
 | 
			
		||||
		QCoreApplication::setApplicationName("LubircantThiknessMapperUi");
 | 
			
		||||
		QCoreApplication::setApplicationVersion("0.1");
 | 
			
		||||
 | 
			
		||||
		QSplashScreen splash(QPixmap(":/images/splash.png"));
 | 
			
		||||
		splash.show();
 | 
			
		||||
 | 
			
		||||
		QDir().mkpath(Profile::profileLocation());
 | 
			
		||||
 | 
			
		||||
		qRegisterMetaType<cv::Mat>("cv::Mat");
 | 
			
		||||
| 
						 | 
				
			
			@ -88,7 +101,7 @@ int main(int argc, char *argv[])
 | 
			
		|||
			uvosled_poweron(&led);
 | 
			
		||||
			// Give cameras some time to power on
 | 
			
		||||
			// TODO: figure out how to do this better
 | 
			
		||||
			sleep(10);
 | 
			
		||||
			std::this_thread::sleep_for(std::chrono::seconds(10));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Cameras cameras(uvosledRet < 0 ? nullptr : &led);
 | 
			
		||||
| 
						 | 
				
			
			@ -127,7 +140,7 @@ int main(int argc, char *argv[])
 | 
			
		|||
 | 
			
		||||
		cameras.load(settings);
 | 
			
		||||
 | 
			
		||||
		splash.hide();
 | 
			
		||||
		closeSplash = true;
 | 
			
		||||
		w.show();
 | 
			
		||||
 | 
			
		||||
		if(uvosledRet < 0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue