/*************************************************************************\
* "$RCSfile: _main.cpp,v $"                                               *
***************************************************************************
* Information by CVS or VSS:                                              *
*     Last check in on: $Date: 2011-09-08 15:48:38 $                      *
*     by                $Author: goebel $
*     Revision        : $Revision: 1.37 $                                 *
\*************************************************************************/
/*! \file _main.cpp
*	\brief Main function
**************************************************************************/

#include "VIC_PS.h"
#include "CRegion.h"
#include "CLog.hpp"
#include "CFeature.hpp"
#include "CPSApp.hpp"
#include "CDlg.hpp"
#include "CDlgMain.hpp"
#include "CDlgSaveImage.hpp"
#include "CDlgPreviewSettings.hpp"
#include "CDlgLog.hpp"
#include "CDlgCam.hpp"
#include "CDlgCamExpert.hpp"
#include "CDlgAppV.hpp"
#include "CDlgTools.hpp"
#include "CDlgConfig.hpp"
#include "CDlgDigIO.hpp"
#include "CDlgPassword.hpp"
#include "CDlgFileMgr.hpp"
#include "CXml.hpp"
#include "CCpuLoad.hpp"

extern "C"
{
void task_main(void);
}

CDlgApp *pDlgApp = NULL;	//!< User application dialog

/*************************************************************************/
int main()
/*************************************************************************/
/*! @brief Main function.
*
*	Initializes DSP hardware and then jumps to idle loop.
**************************************************************************/
{
	// *** Init VisionBox hardware ***
	if (VIB_Init() < 0)
	{
		printf("Error in VIB_Init!\n");
		exit(-1);
	}

	return 0; // Jump into idle loop
}

/*************************************************************************/
void task_main(void)
/*************************************************************************/
/*! @brief Main task.
*
* Construction of most classes, call of CPSApp::MainUILoop() and clean up.
**************************************************************************/
{
	int Width, Height;
	int y;
	CPSApp *pApp;
	CDlgMain *pDlgMain;

	// *** Create all classes ***
	CLog::CreateInstance();
	CCpuLoad::CreateInstance();
	pApp = CPSApp::CreateInstance();
	pApp->Init();
	Height = pApp->GetHeight();
	Width = pApp->GetWidth();
	pDlgMain = CDlgMain::CreateInstance(0, 0, 216, Height);
	y = pDlgMain->GetYOrigin();
	CDlgSaveImage::CreateInstance(0, y, 216, Height - y);
	CDlgPreviewSettings::CreateInstance(0, y, 216, Height - y);
	CDlgPreviewSettings::GetInstance()->SetPVImageOffset(224, 32);
	CDlgLog::CreateInstance(0, y, Width, Height - y);
	CDlgCam::CreateInstance(0, y, 216, Height - y);
	CDlgCamExpert::CreateInstance(0, y, 216, Height - y);
	pDlgApp = new CDlgApp(0, y, 216, Height - y);
	CDlgTools::CreateInstance(0, y, 216, Height - y);
	CDlgConfig::CreateInstance(0, y, Width, Height - y);
	CDlgDigIO::CreateInstance(0, 2 * y, 216, Height - 2 * y);
	CDlgPassword::CreateInstance();
	CDlgFileMgr::CreateInstance();
	CXml::CreateInstance();

	// *** Call main user interface loop ***
	pApp->MainUILoop();

	VIB_WaitBios(100);

	// *** Clean up ***
	CXml::DisposeInstance();
	delete pDlgApp;
	CPSApp::DisposeInstance();

	// *** Reboot ***
	if (!strncmp(getenv("OS"), "Windows", 7))
		exit(0);
	VIB_Reboot();
}

/*************************************************************************/
