Example #1
0
void CMUCamera::setFeature(CameraFeature Feature, int Value, bool bIgnoreOldValue)
{
    if (bIgnoreOldValue || m_Features[Feature] != Value) {
        m_Features[Feature] = Value;
        if (Feature == CAM_FEATURE_STROBE_DURATION) {
            if (m_pCamera->HasStrobe()) {
                C1394CameraControlStrobe* pControl = m_pCamera->GetStrobeControl(0);
                int err = pControl->SetValue(Value);
                checkCMUWarning(err == CAM_SUCCESS, "Error setting camera strobe.");
            } else {
                AVG_TRACE(Logger::WARNING, "Camera does not support strobe.");
            }
        } else {
            CAMERA_FEATURE cmuFeature = getFeatureID(Feature);
            if (m_pCamera->HasFeature(cmuFeature)) {
                bool bAuto = (Value == -1);
                
                C1394CameraControl* pControl = m_pCamera->GetCameraControl(cmuFeature);
                int err1 = pControl->SetAutoMode(bAuto);
                int err2 = CAM_SUCCESS;
                if (!bAuto) {
                    err2 = pControl->SetValue(Value);
                }
                checkCMUWarning(err1 == CAM_SUCCESS && err2 == CAM_SUCCESS, 
                        string("Error setting camera feature: ") + 
                        cameraFeatureToString(Feature));
            } else {
                AVG_TRACE(Logger::WARNING, string("Camera does not support feature: ") + 
                        cameraFeatureToString(Feature));
            }
        }
    }
}
Example #2
0
void CMUCamera::getCameraControls(C1394Camera* pCamera, CameraInfo* pCamInfo)
{
    //Iterate over amount of possible Features (up to 24 in CMU1394 DCD 6.4.5.240)
    for (int indexFeature = 0; indexFeature <= 23; indexFeature++) {
        C1394CameraControl* feature = pCamera->GetCameraControl((CAMERA_FEATURE)indexFeature);
        if (feature == NULL) {
            continue;
        }
        bool hasFeature = pCamera->HasFeature((CAMERA_FEATURE)indexFeature);
        if (!hasFeature) {
            continue;
        }
        //FrameRate (also known as TransferRate) is not supported
        if (feature->GetFeatureID() == FEATURE_FRAME_RATE) {
            continue;
        }

        std::string featureName = feature->GetName();
        unsigned short min = -1;
        unsigned short max = -1;
        feature->GetRange(&min, &max);
        unsigned short value_low = -1;
        unsigned short value_high = -1; //TODO: For Whitebalance or Temperature etc.
        feature->GetValue(&value_low, &value_high);
        CameraControl camControl = CameraControl(featureName, (int)min, (int)max, (int)value_low);
        pCamInfo->addControl(camControl);
    }
}
Example #3
0
/*! 
   Disable auto shutter and set the shutter to the requested value. 

   \sa setAutoShutter()
   */
void vp1394CMUGrabber::setShutter(unsigned short shutter)
{
  initCamera();

  _shutter = shutter;

  unsigned short min,max;
  C1394CameraControl *Control;

  Control = camera->GetCameraControl(FEATURE_SHUTTER);
  Control->Inquire();
  Control->GetRange(&min,&max);

  if (_shutter < min)
  {
    _shutter = min;
    std::cout << "vp1394CMUGrabber warning: Desired exposure time register value of IEEE 1394 camera number " << index << " can't be less than " << _shutter << std::endl;
  }
  else if (_shutter > max)
  {
    _shutter = max;
    std::cout << "vp1394CMUGrabber warning: Desired exposure time register value of IEEE 1394 camera number " << index << " can't be greater than " << _shutter << std::endl;
  }
  Control->SetAutoMode(false);
  if(Control->SetValue(_shutter) != CAM_SUCCESS)
  {
    std::cout << "vp1394CMUGrabber warning: Can't set exposure time register value of IEEE 1394 camera number " << index << std::endl;
  }
}
Example #4
0
/*! 
   Disable auto gain and set the gain to the requested value. 

   \sa setAutoGain()
   */
void vp1394CMUGrabber::setGain(unsigned short gain)
{
  initCamera();
  _gain = gain;

  unsigned short min,max;
  C1394CameraControl *Control;

  Control = camera->GetCameraControl(FEATURE_GAIN);
  Control->Inquire();
  Control->GetRange(&min,&max);

  if (_gain < min)
  {
    _gain = min;
    std::cout << "vp1394CMUGrabber warning: Desired gain register value of IEEE 1394 camera number " << index << " can't be less than " << _gain << std::endl;
  } 
  else if (_gain > max)
  {
    _gain = max;
    std::cout << "vp1394CMUGrabber warning: Desired gain register value of IEEE 1394 camera number " << index << " can't be greater than " << _gain << std::endl;
  }
  
  Control->SetAutoMode(false);
  if(Control->SetValue(_gain) != CAM_SUCCESS)
  {
    std::cout << "vp1394CMUGrabber warning: Can't set gain register value of IEEE 1394 camera number " << index << std::endl;
  }
}
Example #5
0
/*! 
   Get the shutter min and max values. 

   \sa setAutoShutter(), setShutter()
   */
void vp1394CMUGrabber::getShutterMinMax(unsigned short &min, unsigned short &max)
{
  initCamera();

  C1394CameraControl *Control;
  Control = camera->GetCameraControl(FEATURE_SHUTTER);
  Control->Inquire();
  Control->GetRange(&min, &max);
}
Example #6
0
void CMUCamera::internalGetFeature(CameraFeature Feature, unsigned short* val1, 
        unsigned short* val2) const
{
    *val1 = -1;
    *val2 = -1;
    CAMERA_FEATURE cmuFeature = getFeatureID(Feature);
    if (m_pCamera->HasFeature(cmuFeature)) {
        C1394CameraControl* pControl = m_pCamera->GetCameraControl(cmuFeature);
        pControl->Status();
        pControl->GetValue(val1, val2);
    } else {
        AVG_TRACE(Logger::WARNING, string("Error reading camera feature: ") + 
                cameraFeatureToString(Feature));
    }
}
Example #7
0
void CMUCamera::setFeatureOneShot(CameraFeature Feature)
{
    CAMERA_FEATURE cmuFeature = getFeatureID(Feature);
    if (cmuFeature != FEATURE_INVALID_FEATURE && m_pCamera->HasFeature(cmuFeature)) {
        C1394CameraControl* pControl = m_pCamera->GetCameraControl(cmuFeature);
        int err1 = pControl->SetOnOff(false);
        int err2 = pControl->SetAutoMode(false);
        int err3 = pControl->SetOnePush(true);
        checkCMUWarning(err1 == CAM_SUCCESS && err2 == CAM_SUCCESS 
                && err3 == CAM_SUCCESS,
                string("Error setting feature: ") + cameraFeatureToString(Feature));
    } else {
        AVG_TRACE(Logger::WARNING, string("Camera does not support feature: ") + 
                cameraFeatureToString(Feature));
    }
}
Example #8
0
void CMUCamera::setWhitebalance(int u, int v, bool bIgnoreOldValue)
{
    if (bIgnoreOldValue || m_WhitebalanceU != u || m_WhitebalanceV != v) {
        m_WhitebalanceU = u;
        m_WhitebalanceV = v;
        CAMERA_FEATURE cmuFeature = getFeatureID(CAM_FEATURE_WHITE_BALANCE);
        if (m_pCamera->HasFeature(FEATURE_WHITE_BALANCE)) {
            bool bAuto = (u == -1);
            
            C1394CameraControl* pControl = m_pCamera->GetCameraControl(cmuFeature);
            int err1 = pControl->SetAutoMode(bAuto);
            int err2 = CAM_SUCCESS;
            if (!bAuto) {
                err2 = pControl->SetValue(u, v);
            }
            checkCMUWarning(err1 == CAM_SUCCESS && err2 == CAM_SUCCESS,
                    string("Error setting camera feature: ") + 
                    cameraFeatureToString(CAM_FEATURE_WHITE_BALANCE));
        } else {
            AVG_TRACE(Logger::WARNING, string("Camera does not support feature: ") + 
                    cameraFeatureToString(CAM_FEATURE_WHITE_BALANCE));
        }
    }
}
Example #9
0
bool Sync1394Camera::InitCamera(int cameraID, SyncCamParams m_config, float x_offset, float y_offset, float yaw_offset, float fudge) 
{
	C1394Camera* camptr;
	
	isRunning = false;
	Sync1394Camera::config = m_config;	
	int effWidth = config.partialWidth;
	int effHeight = config.partialHeight;
	
	camptr = &camera;

	if (config.isColor) 
		size = effWidth * effHeight * 3;
	else	
		size = effWidth * effHeight;
	if (config.BitDepth16) size *= 2;

	buf = new unsigned char[size];

	if(camptr->RefreshCameraList() == 0 ) 
	{ 
		printf("RefreshCameraList failed.\n");
		return false; 
	} 
	if (cameraID == 0)
	{
		start_tick = clock();
	}
	//artagLoc->initARtagPose(640, 480, 200.0, x_offset, y_offset, yaw_offset, fudge);
	artagLoc->initARtagPose(640, 480, 180.0, x_offset, y_offset, yaw_offset, fudge);
	//artagLoc->initARtagPose(640, 480, 160.0, x_offset, y_offset, yaw_offset, fudge);
	if(camptr->SelectCamera(cameraID)!=CAM_SUCCESS)	
	{ 
		printf("Could not select camera\n" ); 
		return false; 
	}
	camId = cameraID;
	if(camptr->InitCamera(true)!=CAM_SUCCESS)	
	{	
		printf("Could not init camera\n" ); 
		return false; 
	}	
	if(camptr->SetVideoFormat(config.videoFormat)!=CAM_SUCCESS)								
	{ 
		printf("Could not SetVideoFormat on camera\n" ); 
	}
	if(camptr->SetVideoMode(config.videoMode)!=CAM_SUCCESS)										
	{ 
		printf("Could not SetVideoMode on camera\n"); 
	}
	if (config.usePartialScan == false)
	{
		if(camptr->SetVideoFrameRate(config.videoFrameRate)!=CAM_SUCCESS)														
		{ 
			printf("Could not set video frame rate!");	
			return false;
		} //30 fps
	}
	else if (config.usePartialScan)
	{
		unsigned short w, h; 
		C1394CameraControlSize* p_size_control = camptr->GetCameraControlSize();
		p_size_control->GetSizeLimits(&w, &h);
		if ((w>effWidth) || (h>effHeight))																			
		{ 
			printf("FATAL: Bad Partial Scan Size Specified! Specified w:%d h:%d, Max: w:%d h:%d",effWidth,effHeight,w,h);	
			return false;
		} 
		if (config.isColor)
		{
			if( p_size_control->SetColorCode(COLOR_CODE_YUV422) != CAM_SUCCESS ) 	
			{ 
				printf("SetColorCode failed.\n"); 
				return false; 
			} 
		}
		else
		{
			if( p_size_control->SetColorCode(config.BitDepth16?COLOR_CODE_Y16:COLOR_CODE_Y8) != CAM_SUCCESS ) 
			{ 
				printf("SetColorCode failed (BW).\n"); 
				return false; 
			} 
		}
		if( p_size_control->SetSize(effWidth,effHeight) != CAM_SUCCESS )	
		{ 
			printf("SetSize failed.\n"); 
			return false; 
		} 
		if( p_size_control->SetPos(config.partialLeft,config.partialTop) != CAM_SUCCESS )
		{ 
			printf("SetPos failed.\n"); 
			return false; 
		} 
		if (p_size_control->SetBytesPerPacket (config.bytesPerPacket) != CAM_SUCCESS)
		{ 
			printf("SetBytesPerPacket failed.\n"); 
			return false; 
		} 

		float interval=0.0; p_size_control->GetFrameInterval (&interval);
		if (((float)config.syncFPS) > (1.0f/interval))													
		{ 
			printf("WARNING: SyncFPS (%f) is greater than the actual camera FPS (%f)\n",(float)config.syncFPS,(1.0f/interval));
		}
		printf("Frame Interval is: %f",interval);
	}
	if (config.isSlave)	
	{ 
		printf("Using SLAVE configuration.\n");
	}

	if (!config.AutoGain)
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_GAIN);
		if (ctrl->SetAutoMode(false) != CAM_SUCCESS)
		{	
			printf("Gain SetManualMode failed.\n");
		}
		ctrl->SetValue(GAINVAL);
		if (ctrl->StatusAutoMode() == true)
		{	
			printf("I HAVE AUTOGAIN ASSHOLE");
		}
		unsigned short gainval = 0;
		ctrl->GetValue(&gainval);
		if (DEBUG_SYNC1394) printf("gain: %d\n",gainval);
	}
	else
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_GAIN);
		ctrl->SetValue(GAINVAL);
		if (ctrl->SetAutoMode(true) != CAM_SUCCESS)
		{	
			printf("Gain SetAutoMode failed.\n");
		}
		if (ctrl->StatusAutoMode() == true)
		{	
			if (DEBUG_SYNC1394) printf("AutoGain successfully set!\n");
		}
	}
	
	minGain=0;
	maxGain=0;
	GetGainMinMax( camptr, &minGain, &maxGain);
	if (DEBUG_SYNC1394) printf("Min gain: %d, Max gain: %d\n",minGain,maxGain);
	
	if (!config.AutoShutter)
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_SHUTTER);
		if (ctrl->SetAutoMode(false) != CAM_SUCCESS)
		{	
			printf("Shutter SetManualMode failed.\n");
		}
		ctrl->SetValue(SHUTTERVAL);
		/*if (ctrl->SetValue(530) != CAM_SUCCESS)
		{	
			printf("Shutter SetValue failed.\n");
		}*/
		if (ctrl->StatusAutoMode() == true)
		{	
			printf("I HAVE AUTOSHUTTER ASSHOLE");
		}
	}
	else
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_SHUTTER);
		ctrl->SetValue(SHUTTERVAL);
		if (ctrl->SetAutoMode(true) != CAM_SUCCESS)
		{	
			printf("Shutter SetAutoMode failed.\n");
		}
		if (ctrl->StatusAutoMode() == true)
		{	
			if (DEBUG_SYNC1394) printf("AutoShutter successfully set!\n");
		}
	}

	if (!config.AutoBrightness)
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_BRIGHTNESS);
		if (ctrl->SetAutoMode(false) != CAM_SUCCESS)
		{	
			printf("Brightness SetManualMode failed.\n");
		}
		ctrl->SetValue(154);
		if (ctrl->StatusAutoMode() == true)
		{	
			printf("I HAVE AUTOBRIGHTNESS ASSHOLE");
		}
		unsigned short bval = 0;
		ctrl->GetValue(&bval);
		if (DEBUG_SYNC1394) printf("brightness: %d\n",bval);
	}
	else
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_BRIGHTNESS);
		ctrl->SetValue(154);
		if (ctrl->SetAutoMode(true) != CAM_SUCCESS)
		{	
			printf("Brightness SetAutoMode failed.\n");
		}
		if (ctrl->StatusAutoMode() == true)
		{	
			if (DEBUG_SYNC1394) printf("AutoBrightness successfully set!\n");
		}
	}
	
	if (config.gammaEnable)
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_GAMMA);
		if (ctrl->SetOnOff(true) != CAM_SUCCESS)
		{	
			printf("Gamma SetOnOff failed.\n");
		}
		if (ctrl->SetValue(1) != CAM_SUCCESS)
		{
			printf("Gamma SetValue failed.\n");
		}
	}

	minShutter=0;
	maxShutter=0;
	GetShutterMinMax(camptr, &minShutter, &maxShutter);
	if (DEBUG_SYNC1394) printf("Min shutter: %d, Max shutter: %d\n",minShutter,maxShutter);

	if (config.adjWB)
	{
		C1394CameraControl* ctrl = camptr->GetCameraControl (FEATURE_WHITE_BALANCE);
		if (ctrl->SetValue(WHITEBALANCE_VALUE1,WHITEBALANCE_VALUE2) != CAM_SUCCESS)
		{
			printf("WhiteBalance SetValue failed.\n");
		}
	}
	
	printf("Completed Init of Camera %d\n", camId);

	if (config.eTrigEnabled)
	{
		C1394CameraControlTrigger* trig = camptr->GetCameraControlTrigger();
		if (trig->SetTriggerSource (config.syncCamInput)!=CAM_SUCCESS)
			printf("Could Not Set Trigger Source!\n");
		else
		{
			if (trig->SetMode (0))
				printf("Could Not Set Trigger Mode!\n");
			else
			{
				if (trig->SetOnOff (true))
					printf("Could Not Set Trigger ON!\n");
				else
				{
					trig->Status();
					printf("External Trigger Initialized.\n");
				}
			}
		}
	}
	else
	{
		if (config.syncEnabled)
		{
			udp_params paramsRX  = udp_params(); 
			paramsRX.remote_ip = inet_addr(UDP_BROADCAST_IP);
			paramsRX.local_port = UDP_BROADCAST_PORT;
			paramsRX.reuse_addr = 1;
			try
			{		
				udpRX = new udp_connection(paramsRX);  
			}
			catch (exception)
			{
				printf("Couldn't init UDP RX on  %s:%d  \n",UDP_BROADCAST_IP,paramsRX.local_port);
				return false;
			}

			udpRX->set_callback(MakeDelegate(this,&Sync1394Camera::UDPCallback), udpRX);

			udp_params paramsTX  =  udp_params(); 

			try
			{		
				udpTX = new udp_connection(paramsTX);  
			}
			catch (exception)
			{
				printf("Couldn't init UDP TX on port %d\n",paramsTX.local_port);
				return false;
			}

			if (config.isSlave == false)
			{
				char regmsg[] = {CAMERA_MSG_REGISTER, config.syncID & 0xFF, 0x00, 0x00, 0x00, 0x00,(paramsRX.local_port>>8)&0xff, paramsRX.local_port&0xff}; //register message
				udpTX->send_message (regmsg,8,UDP_CONTROL_IP,UDP_CONTROL_PORT);
				Sleep(100);
				char fpsmsg[] = {CAMERA_MSG_SETFPS, config.syncID & 0xff, config.syncFPS &0xff};
				udpTX->send_message (fpsmsg,3,UDP_CONTROL_IP,UDP_CONTROL_PORT);
				Sleep(100);
				char initmsg[] = {CAMERA_START, config.syncID & 0xFF}; //start message
				udpTX->send_message (initmsg,2,UDP_CONTROL_IP,UDP_CONTROL_PORT);
				if (config.ghettoSync == false)
				{
					C1394CameraControlTrigger* trig = camptr->GetCameraControlTrigger ();

					unsigned short modein=0; unsigned short modeparam =0; unsigned short trigsrc=0;
					if (trig->SetTriggerSource (config.syncCamInput)!=CAM_SUCCESS)
						printf("Could Not Set Trigger Source!\n");
					if (trig->SetMode (0))
						printf("Could Not Set Trigger Mode!\n");
					if (trig->SetOnOff (true))
						printf("Could Not Set Trigger ON!\n");
				}
			}
			if (DEBUG_SYNC1394) printf("Timing Initialized.\n");	
		}
Example #10
0
/**\brief Window procedure for the control dialog
 * \ingroup dialogs
 * \param hWnd The dialog window handle
 * \param message The message to process
 * \param wParam the window parameter
 * \param lParam the (often unused) generic long parameter
 * 
 * Duties:
 *  - menu items
 *     - load/save view settings to from/to registry
 *     - close the window
 *     - view menu toggles panes on and off
 *  - messages
 *     - paint: nothing (for now)
 *     - destroy: localfree the window extension structure
 *     - hscroll: scroll the panes back and forth
 */
LRESULT CALLBACK ControlDialogWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	int i;
	PAINTSTRUCT ps;
	HDC hdc;
	HKEY  hKey,hCSK;
	DWORD dwRet,dwDisposition,dwFoo,dwSize = sizeof(DWORD),dwType = REG_DWORD;
	SCROLLINFO si;
	PCONTROL_WINDOW_EXTENSION pExt = (PCONTROL_WINDOW_EXTENSION) GetWindowLongPtr(hWnd,GWLP_USERDATA);
	PCONTROL_PANE_EXTENSION pPaneExt;
	C1394Camera *pCam;
	C1394CameraControl *pControl;
	char buf[256];
	LRESULT lRetval = 0;
	HWND hWndChild;
	MSG msg;
	LARGE_INTEGER UniqueID;
	
	DllTrace(DLL_TRACE_ENTER,"ControlDialogProc(%08x,%08x,%08x,%08x)\n",
		hWnd,
		message,
		wParam,
		lParam);
	
	/* to maintain reasonable encapsulation, we need to translate our own accelerator messages */
	if(pExt)
	{
		msg.hwnd = hWnd;
		msg.message = message;
		msg.wParam = wParam;
		msg.lParam = lParam;
		TranslateAccelerator(hWnd,pExt->hAccel,&msg);
		message = msg.message;
		lParam = msg.lParam;
		wParam = msg.wParam;
	}
	
	switch (message) 
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam); 
		wmEvent = HIWORD(wParam); 
		// Parse the menu selections:
		switch (wmId)
		{
		case ID_CONTROL_POLLALL:
			for(i=0; i<pExt->nPanes; i++)
			{
				if(pExt->PaneState[i])
					SendDlgItemMessage(hWnd,ID_FIRST_CONTROL_PANE + i,WM_COMMAND,MAKELONG(IDC_BUT_POLL,0),0);
			}
			break;
		case ID_FILE_LOADDEFAULTVIEW:
			pCam = pExt->pCamera;
			if(pCam)
			{
				if((hCSK = OpenCameraSettingsKey(NULL,0,KEY_ALL_ACCESS)) != NULL)
				{
					pCam->GetCameraUniqueID(&UniqueID);
					StringCbPrintf(buf,sizeof(buf),"%08x%08x\\ControlPanes\\DefaultView",UniqueID.HighPart,UniqueID.LowPart);
					dwRet = RegCreateKeyEx(hCSK,buf,0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dwDisposition);
					if(dwRet == ERROR_SUCCESS)
					{
						if(dwDisposition == REG_CREATED_NEW_KEY)
						{
							// we made a new key, so we need to write the initial settings
							for(i=0; i<pExt->nPanes; i++)
							{
								hWndChild = GetDlgItem(hWnd,ID_FIRST_CONTROL_PANE + i);
								pPaneExt = (PCONTROL_PANE_EXTENSION) GetWindowLongPtr(hWndChild,GWLP_USERDATA);
								dwFoo = 1;
								dwRet = RegSetValueEx(hKey,pPaneExt->pane_name,0,REG_DWORD,(LPBYTE)&dwFoo,dwSize);
								if(dwRet != ERROR_SUCCESS)
									DllTrace(DLL_TRACE_ERROR,
									"ControlDialogProc: Load Default View: error %d setting registry key for %s\n",
									dwRet,pPaneExt->pane_name);
							}
						}
						
						
						for(i=0; i<pExt->nPanes; i++)
						{
							hWndChild = GetDlgItem(hWnd,ID_FIRST_CONTROL_PANE + i);
							pPaneExt = (PCONTROL_PANE_EXTENSION) GetWindowLongPtr(hWndChild,GWLP_USERDATA);
							dwFoo = pExt->PaneState[i];
							dwRet = RegQueryValueEx(hKey,pPaneExt->pane_name,0,&dwType,(LPBYTE)&(dwFoo),&dwSize);
							
							if(dwRet != ERROR_SUCCESS)
								DllTrace(DLL_TRACE_ERROR,
								"ControlDialogProc: Load Default View: error %d setting registry key for %s\n",
								dwRet,pPaneExt->pane_name);
							
							CheckMenuItem(
								GetMenu(hWnd),
								ID_VIEW_CONTROL_START + i,
								MF_BYCOMMAND | (dwFoo ? MF_CHECKED : MF_UNCHECKED));
							
							pExt->PaneState[i] = (BOOL)dwFoo;
							
						}
						
						ShowControlPanes(hWnd,TRUE);
						
						RegCloseKey(hKey);
					} else {
						DllTrace(DLL_TRACE_ERROR,"ControlPaneDlgProc: Load Default View: Error %08x on RegCreateKeyEx\n",dwRet);
					}
					RegCloseKey(hCSK);
				} else {
					DllTrace(DLL_TRACE_ERROR,"ControlPaneDlgProc: Failed to open camera settings key: %s",StrLastError());
				}
			} else {
				// no camera: nothing to do
			}
			break;
			
		case ID_FILE_SAVEDEFAULTVIEW:
			pCam = pExt->pCamera;
			if(pCam)
			{
				if((hCSK = OpenCameraSettingsKey(NULL,0,KEY_ALL_ACCESS)) != NULL)
				{
					pCam->GetCameraUniqueID(&UniqueID);
					StringCbPrintf(buf,sizeof(buf),"%08x%08x\\ControlPanes\\DefaultView",UniqueID.HighPart,UniqueID.LowPart);
					dwRet = RegCreateKeyEx(hCSK,buf,0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dwDisposition);
					if(dwRet == ERROR_SUCCESS)
					{
						for(i=0; i<pExt->nPanes; i++)
						{
							hWndChild = GetDlgItem(hWnd,ID_FIRST_CONTROL_PANE + i);
							pPaneExt = (PCONTROL_PANE_EXTENSION) GetWindowLongPtr(hWndChild,GWLP_USERDATA);
							dwFoo = pExt->PaneState[i];
							dwRet = RegSetValueEx(hKey,pPaneExt->pane_name,0,REG_DWORD,(LPBYTE)&dwFoo,dwSize);
							if(dwRet != ERROR_SUCCESS)
								DllTrace(DLL_TRACE_ERROR,
								"ControlDialogProc: Save Default View: error %d setting registry key for %s\n",
								dwRet,pPaneExt->pane_name);
						}
						RegCloseKey(hKey);
					} else {
						DllTrace(DLL_TRACE_ERROR,"ControlDialogProc: Save Default View: Error %d opening key %s\n",dwRet,buf);
					}
					RegCloseKey(hCSK);
				} else {
					DllTrace(DLL_TRACE_ERROR,"ControlPaneDlgProc: Failed to open camera settings key: %s",StrLastError());
				}			
			} else {
				// no camera, nothing to do
			}
			break;
			
		case ID_FILE_CLOSE:
			DestroyWindow(hWnd);
			break;
		case ID_VIEW_ALLCONTROLS:
			for(i=0; i<pExt->nPanes; i++)
			{
				pExt->PaneState[i] = 1;
				CheckMenuItem(
					GetMenu(hWnd),
					ID_VIEW_CONTROL_START + i,
					MF_BYCOMMAND | MF_CHECKED);
			}
			ShowControlPanes(hWnd,TRUE);
			break;
		case ID_VIEW_STRICT_PRESENT:
			for(i=0; i<pExt->nPanes; i++)
			{
				HWND hWndPanel = GetDlgItem(hWnd,ID_FIRST_CONTROL_PANE + i);
				PCONTROL_PANE_EXTENSION pCPExt;
				pCPExt = (PCONTROL_PANE_EXTENSION)GetWindowLongPtr(hWndPanel,GWLP_USERDATA);
				pControl = pCPExt->pControl;
				pExt->PaneState[i] = 
					(((pCPExt->flags & PIF_STROBE) != 0) || pExt->pCamera->HasFeature(pControl->GetFeatureID()) &&
					pControl->HasPresence() &&
					pControl->StatusPresence());
				CheckMenuItem(
					GetMenu(hWnd),
					ID_VIEW_CONTROL_START + i,
					MF_BYCOMMAND | (pExt->PaneState[i] ? MF_CHECKED : MF_UNCHECKED));
			}
			ShowControlPanes(hWnd,TRUE);
			break;
		case ID_VIEW_LOOSE_PRESENT:
			for(i=0; i<pExt->nPanes; i++)
			{
				HWND hWndPanel = GetDlgItem(hWnd,ID_FIRST_CONTROL_PANE + i);
				PCONTROL_PANE_EXTENSION pCPExt;
				pCPExt = (PCONTROL_PANE_EXTENSION)GetWindowLongPtr(hWndPanel,GWLP_USERDATA);
				pControl = pCPExt->pControl;
				pExt->PaneState[i] = (pExt->pCamera->HasFeature(pControl->GetFeatureID()) ||
					pControl->HasPresence() ||
					pControl->StatusPresence());
				CheckMenuItem(
					GetMenu(hWnd),
					ID_VIEW_CONTROL_START + i,
					MF_BYCOMMAND | (pExt->PaneState[i] ? MF_CHECKED : MF_UNCHECKED));
			}
			ShowControlPanes(hWnd,TRUE);
			break;
		default:
			if(wmId >= ID_VIEW_CONTROL_START && wmId < ID_VIEW_CONTROL_END)
			{
				// toggle a pane
				i = wmId - ID_VIEW_CONTROL_START;
				pExt->PaneState[i] ^= 1;
				CheckMenuItem(
					GetMenu(hWnd),
					wmId,
					MF_BYCOMMAND | (pExt->PaneState[i] ? MF_CHECKED : MF_UNCHECKED));
				ShowControlPanes(hWnd,TRUE);
			} else {
				lRetval = DefWindowProc(hWnd, message, wParam, lParam);
			}
			
		} // switch(wmId)
		break;
		
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: Add any drawing code here...
		EndPaint(hWnd, &ps);
		break;
		
	case WM_DESTROY:
		DllTrace(DLL_TRACE_CHECK,"ControlDialogWndProc: WM_DESTROY: Freeing %08x\n",pExt);
		DestroyAcceleratorTable(pExt->hAccel);
		SetFocus(pExt->hWndParent);
		LocalFree(pExt);
		break;
		
	case WM_HSCROLL:
		si.cbSize = sizeof(SCROLLINFO);
		si.fMask = SIF_ALL;
		GetScrollInfo(hWnd,SB_HORZ,&si);
		switch(LOWORD(wParam))
		{
		case SB_THUMBPOSITION:
			si.nPos = si.nTrackPos;
			break;
		case SB_LEFT:
		case SB_LINELEFT:
			si.nPos -= 10;
			break;
		case SB_RIGHT:
		case SB_LINERIGHT:
			si.nPos += 10;
			break;
		case SB_PAGELEFT:
			si.nPos -= si.nPage;
			break;
		case SB_PAGERIGHT:
			si.nPos += si.nPage;
			break;
		}
		si.fMask = SIF_POS;
		pExt->trackpos = (LOWORD(wParam) == SB_THUMBTRACK ? si.nTrackPos : si.nPos);
		if(pExt->trackpos < 0)
			pExt->trackpos = 0;
		if(pExt->trackpos >= (si.nMax - (int)si.nPage))
			pExt->trackpos = si.nMax - si.nPage - 1;
		SetScrollInfo(hWnd,SB_HORZ,&si,TRUE);
		if(LOWORD(wParam) != SB_THUMBPOSITION)
			ShowControlPanes(hWnd,FALSE);
		break;
		
		default:
			lRetval = DefWindowProc(hWnd, message, wParam, lParam);
   }
   
   DllTrace(DLL_TRACE_EXIT,"EXIT ControlDialogWndProc (%d)\n",lRetval);
   return lRetval;
}
/*!
 Init the selected camera.
 */
void 
vp1394CMUGrabber::initCamera()
{
  int camerror;
  unsigned long width, height;


  if (camera->CheckLink() != CAM_SUCCESS)
  {
    vpERROR_TRACE("C1394Camera error: Found no cameras on the 1394 bus");
    throw (vpFrameGrabberException(vpFrameGrabberException::initializationError,"The is no detected camera") );
  }

  camerror = camera->InitCamera();
  if ( camerror != CAM_SUCCESS )
  {
    switch (camerror)
    {
      case CAM_ERROR_NOT_INITIALIZED:
        vpERROR_TRACE("vp1394CMUGrabber error: No camera selected",index);
        throw (vpFrameGrabberException(vpFrameGrabberException::initializationError,"The is no selected camera") );
        break;
      case CAM_ERROR_BUSY:
        vpERROR_TRACE("vp1394CMUGrabber error: The camera %i is busy",index);
        throw (vpFrameGrabberException(vpFrameGrabberException::initializationError,"The required camera is in use by other application") );
        break;
      case CAM_ERROR:
        vpERROR_TRACE("vp1394CMUGrabber error: General I/O error when selecting camera number %i",index);
        throw (vpFrameGrabberException(vpFrameGrabberException::initializationError,"Resolve camera can not be used") );
        break;
    }
    close();
  }

  if (camera->Has1394b())
    camera->Set1394b(TRUE);

  // Set format and mode
  if ((_format != -1) && (_mode != -1))
  {
    if (!camera->HasVideoMode(_format, _mode))
    {
      close();
      vpERROR_TRACE("vp1394CMUGrabber error: The image format is not supported by the IEEE 1394 camera number %i",index);
      throw (vpFrameGrabberException(vpFrameGrabberException::settingError,"Video mode not supported") );
    }

    if (camera->SetVideoFormat(_format) != CAM_SUCCESS)
    {
      close();
      vpERROR_TRACE("vp1394CMUGrabber error: Can't set video format of IEEE 1394 camera number %i",index);
      throw (vpFrameGrabberException(vpFrameGrabberException::settingError,"Can't set video format") );
    }

    if (camera->SetVideoMode(_mode) != CAM_SUCCESS)
    {
      close();
      vpERROR_TRACE("vp1394CMUGrabber error: Can't set video mode of IEEE 1394 camera number %i",index);
      throw (vpFrameGrabberException(vpFrameGrabberException::settingError,"Can't set video mode") );
    }
  }
  else {
    // Get the current format and mode
    _format = camera->GetVideoFormat();
    _mode = camera->GetVideoMode();
  }

  // Update the color coding
  _color = getVideoColorCoding();
  //std::cout << "color coding: " << _color << std::endl;

  // Set fps
  if (_fps!=-1)
  {
    if (!camera->HasVideoFrameRate(_format,_mode,_fps))
    {
      close();
      vpERROR_TRACE("vp1394CMUGrabber error: The frame rate is not supported by the IEEE 1394 camera number %i for the selected image format",index);
      throw (vpFrameGrabberException(vpFrameGrabberException::settingError,"The frame rate is not supported") );
    }

    if (camera->SetVideoFrameRate(_fps) != CAM_SUCCESS)
    {
      close();
      vpERROR_TRACE("vp1394CMUGrabber error: Can't set video frame rate of IEEE 1394 camera number %i",index);
      throw (vpFrameGrabberException(vpFrameGrabberException::settingError,"Can't set video frame rate") );
    }
  }

  // Set shutter and gain
  if ( _modeauto == false )
  {
    unsigned short min,max;
    C1394CameraControl *Control;

    Control = camera->GetCameraControl(FEATURE_GAIN);
    Control->Inquire();
    Control->GetRange(&min,&max);

    if (_gain<min)
    {
      _gain = min;
      std::cout << "vp1394CMUGrabber warning: Desired gain register value of IEEE 1394 camera number " << index << " can't be less than " << _gain << std::endl;
    } else
      if (_gain>max)
      {
        _gain = max;
        std::cout << "vp1394CMUGrabber warning: Desired gain register value of IEEE 1394 camera number " << index << " can't be greater than " << _gain << std::endl;
      }

    Control->SetAutoMode(false);
    if(Control->SetValue(_gain) != CAM_SUCCESS)
    {
      std::cout << "vp1394CMUGrabber warning: Can't set gain register value of IEEE 1394 camera number " << index << std::endl;
    }

    Control = camera->GetCameraControl(FEATURE_SHUTTER);
    Control->Inquire();
    Control->GetRange(&min,&max);

    if (_shutter<min)
    {
      _shutter = min;
      std::cout << "vp1394CMUGrabber warning: Desired exposure time register value of IEEE 1394 camera number " << index << " can't be less than " << _shutter << std::endl;
    }
    else if (_shutter>max)
    {
      _shutter = max;
      std::cout << "vp1394CMUGrabber warning: Desired exposure time register value of IEEE 1394 camera number " << index << " can't be greater than " << _shutter << std::endl;
    }
    Control->SetAutoMode(false);
    if(Control->SetValue(_shutter) != CAM_SUCCESS)
    {
      std::cout << "vp1394CMUGrabber warning: Can't set exposure time register value of IEEE 1394 camera number " << index << std::endl;
    }
  }
  else
  {
    camera->GetCameraControl(FEATURE_SHUTTER)->SetAutoMode(true);
    camera->GetCameraControl(FEATURE_GAIN)->SetAutoMode(true);
  }

  // Set trigger off
  camera->GetCameraControlTrigger()->SetOnOff(false);


  camera->GetVideoFrameDimensions(&width,&height);
  this->height = height;
  this->width = width;

  init = true;

} // end camera init