close cameras before cutting power
This commit is contained in:
		
							parent
							
								
									b5c3ca5f35
								
							
						
					
					
						commit
						b569b3495d
					
				
					 1 changed files with 93 additions and 90 deletions
				
			
		
							
								
								
									
										183
									
								
								src/main.cpp
									
										
									
									
									
								
							
							
						
						
									
										183
									
								
								src/main.cpp
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -58,101 +58,104 @@ 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");
 | 
			
		||||
 | 
			
		||||
	QSplashScreen splash(QPixmap(":/images/splash.png"));
 | 
			
		||||
	splash.show();
 | 
			
		||||
 | 
			
		||||
	QDir().mkpath(Profile::profileLocation());
 | 
			
		||||
 | 
			
		||||
	qRegisterMetaType<cv::Mat>("cv::Mat");
 | 
			
		||||
	qRegisterMetaType<size_t>("size_t");
 | 
			
		||||
	qRegisterMetaType<Camera::Image>("Camera::Image");
 | 
			
		||||
	qRegisterMetaType<Camera::Image>("Image");
 | 
			
		||||
	qRegisterMetaType<std::vector<Camera::Image>>("std::vector<Camera::Image>");
 | 
			
		||||
 | 
			
		||||
	QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
 | 
			
		||||
 | 
			
		||||
	uvosled led;
 | 
			
		||||
	int uvosledRet = uvosled_connect(&led);
 | 
			
		||||
 | 
			
		||||
	if(uvosledRet >= 0)
 | 
			
		||||
	int ret;
 | 
			
		||||
	
 | 
			
		||||
	{
 | 
			
		||||
		qDebug()<<"uvosled_poweron";
 | 
			
		||||
		uvosled_poweron(&led);
 | 
			
		||||
		// Give cameras some time to power on
 | 
			
		||||
		// TODO: figure out how to do this better
 | 
			
		||||
		sleep(10);
 | 
			
		||||
		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");
 | 
			
		||||
		qRegisterMetaType<size_t>("size_t");
 | 
			
		||||
		qRegisterMetaType<Camera::Image>("Camera::Image");
 | 
			
		||||
		qRegisterMetaType<Camera::Image>("Image");
 | 
			
		||||
		qRegisterMetaType<std::vector<Camera::Image>>("std::vector<Camera::Image>");
 | 
			
		||||
 | 
			
		||||
		QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
 | 
			
		||||
 | 
			
		||||
		if(uvosledRet >= 0)
 | 
			
		||||
		{
 | 
			
		||||
			qDebug()<<"uvosled_poweron";
 | 
			
		||||
			uvosled_poweron(&led);
 | 
			
		||||
			// Give cameras some time to power on
 | 
			
		||||
			// TODO: figure out how to do this better
 | 
			
		||||
			sleep(10);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Cameras cameras(uvosledRet < 0 ? nullptr : &led);
 | 
			
		||||
		cameras.setFree(false);
 | 
			
		||||
		ImagePipeline pipe(&cameras);
 | 
			
		||||
 | 
			
		||||
		MainWindow w;
 | 
			
		||||
 | 
			
		||||
		QObject::connect(&cameras, &Cameras::cameraAdded, &w, &MainWindow::addCamera);
 | 
			
		||||
		QObject::connect(&cameras, &Cameras::cameraRemoved, &w, &MainWindow::removeCamera);
 | 
			
		||||
		QObject::connect(&w, &MainWindow::sigCapture, [&cameras](){cameras.start(); cameras.trigger();});
 | 
			
		||||
 | 
			
		||||
		QObject::connect(&w, &MainWindow::sigChooseCameras, [&cameras]()
 | 
			
		||||
		{
 | 
			
		||||
			bool accepted;
 | 
			
		||||
			std::vector<cam::Camera::Description> descs = showCameraSelectionDialog(&accepted);
 | 
			
		||||
			if(accepted)
 | 
			
		||||
				cameras.setCameras(descs);
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		QObject::connect(&w, &MainWindow::sigEditProfiles, [&cameras, &w](){showProfileDialog(&cameras); w.refreshProfiles();});
 | 
			
		||||
		QObject::connect(&pipe, &ImagePipeline::sigResult, w.mainImageViewer(), &CvImageViewer::setImage, Qt::QueuedConnection);
 | 
			
		||||
		QObject::connect(&pipe, &ImagePipeline::sigResult, [&w](){w.statusMsg("idle");});
 | 
			
		||||
		QObject::connect(&pipe, &ImagePipeline::sigInvalidProfile, &w, &MainWindow::profileInconpatible);
 | 
			
		||||
 | 
			
		||||
		QObject::connect(&w, &MainWindow::sigProfile, [&pipe](QString name)
 | 
			
		||||
		{
 | 
			
		||||
			Profile profile;
 | 
			
		||||
			profile.load(name);
 | 
			
		||||
			if(profile.cameras.size() != 0)
 | 
			
		||||
				qDebug()<<"loading profile"<<name<<"with"<<profile.cameras.size()<<"cameras and first camera"<<profile.cameras.at(0).id;
 | 
			
		||||
			else
 | 
			
		||||
				qDebug()<<"empty profile!!";
 | 
			
		||||
			pipe.setProfile(profile);
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		cameras.load(settings);
 | 
			
		||||
 | 
			
		||||
		splash.hide();
 | 
			
		||||
		w.show();
 | 
			
		||||
 | 
			
		||||
		if(uvosledRet < 0)
 | 
			
		||||
			QMessageBox::warning(&w, "UVOS LED", "Can not connect to the UVOS LED device");
 | 
			
		||||
 | 
			
		||||
		if(cameras.getCameras().empty())
 | 
			
		||||
		{
 | 
			
		||||
			QMessageBox::information(&w, "Cameras", "No cameras configured, please choose at least one camera.");
 | 
			
		||||
			cameras.setCameras(showCameraSelectionDialog());
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		QString name = w.getProfileName();
 | 
			
		||||
		if(!name.isEmpty())
 | 
			
		||||
		{
 | 
			
		||||
			Profile profile;
 | 
			
		||||
			profile.load(w.getProfileName());
 | 
			
		||||
			if(profile.cameras.size() != 0)
 | 
			
		||||
				qDebug()<<"loading profile"<<name<<"with"<<profile.cameras.size()<<"cameras and first camera"<<profile.cameras.at(0).id;
 | 
			
		||||
			else
 | 
			
		||||
				qDebug()<<"empty profile!!";
 | 
			
		||||
			pipe.setProfile(profile);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		ret =  a.exec();
 | 
			
		||||
 | 
			
		||||
		cameras.store(settings);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	Cameras cameras(uvosledRet < 0 ? nullptr : &led);
 | 
			
		||||
	cameras.setFree(false);
 | 
			
		||||
	ImagePipeline pipe(&cameras);
 | 
			
		||||
 | 
			
		||||
	MainWindow w;
 | 
			
		||||
 | 
			
		||||
	QObject::connect(&cameras, &Cameras::cameraAdded, &w, &MainWindow::addCamera);
 | 
			
		||||
	QObject::connect(&cameras, &Cameras::cameraRemoved, &w, &MainWindow::removeCamera);
 | 
			
		||||
	QObject::connect(&w, &MainWindow::sigCapture, [&cameras](){cameras.start(); cameras.trigger();});
 | 
			
		||||
 | 
			
		||||
	QObject::connect(&w, &MainWindow::sigChooseCameras, [&cameras]()
 | 
			
		||||
	{
 | 
			
		||||
		bool accepted;
 | 
			
		||||
		std::vector<cam::Camera::Description> descs = showCameraSelectionDialog(&accepted);
 | 
			
		||||
		if(accepted)
 | 
			
		||||
			cameras.setCameras(descs);
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	QObject::connect(&w, &MainWindow::sigEditProfiles, [&cameras, &w](){showProfileDialog(&cameras); w.refreshProfiles();});
 | 
			
		||||
	QObject::connect(&pipe, &ImagePipeline::sigResult, w.mainImageViewer(), &CvImageViewer::setImage, Qt::QueuedConnection);
 | 
			
		||||
	QObject::connect(&pipe, &ImagePipeline::sigResult, [&w](){w.statusMsg("idle");});
 | 
			
		||||
	QObject::connect(&pipe, &ImagePipeline::sigInvalidProfile, &w, &MainWindow::profileInconpatible);
 | 
			
		||||
 | 
			
		||||
	QObject::connect(&w, &MainWindow::sigProfile, [&pipe](QString name)
 | 
			
		||||
	{
 | 
			
		||||
		Profile profile;
 | 
			
		||||
		profile.load(name);
 | 
			
		||||
		if(profile.cameras.size() != 0)
 | 
			
		||||
			qDebug()<<"loading profile"<<name<<"with"<<profile.cameras.size()<<"cameras and first camera"<<profile.cameras.at(0).id;
 | 
			
		||||
		else
 | 
			
		||||
			qDebug()<<"empty profile!!";
 | 
			
		||||
		pipe.setProfile(profile);
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	cameras.load(settings);
 | 
			
		||||
 | 
			
		||||
	splash.hide();
 | 
			
		||||
	w.show();
 | 
			
		||||
 | 
			
		||||
	if(uvosledRet < 0)
 | 
			
		||||
		QMessageBox::warning(&w, "UVOS LED", "Can not connect to the UVOS LED device");
 | 
			
		||||
 | 
			
		||||
	if(cameras.getCameras().empty())
 | 
			
		||||
	{
 | 
			
		||||
		QMessageBox::information(&w, "Cameras", "No cameras configured, please choose at least one camera.");
 | 
			
		||||
		cameras.setCameras(showCameraSelectionDialog());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	QString name = w.getProfileName();
 | 
			
		||||
	if(!name.isEmpty())
 | 
			
		||||
	{
 | 
			
		||||
		Profile profile;
 | 
			
		||||
		profile.load(w.getProfileName());
 | 
			
		||||
		if(profile.cameras.size() != 0)
 | 
			
		||||
			qDebug()<<"loading profile"<<name<<"with"<<profile.cameras.size()<<"cameras and first camera"<<profile.cameras.at(0).id;
 | 
			
		||||
		else
 | 
			
		||||
			qDebug()<<"empty profile!!";
 | 
			
		||||
		pipe.setProfile(profile);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	int ret =  a.exec();
 | 
			
		||||
 | 
			
		||||
	cameras.store(settings);
 | 
			
		||||
 | 
			
		||||
	if(uvosledRet >= 0)
 | 
			
		||||
		uvosled_poweroff(&led);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue