/**\brief Tear down a C1394Camera Instance * \ingroup camcore * * Besides typical freeing of resources, this also calls StopImageAcquisition() * if necessary to disable the camera streaming and free kernel-side resources * as well. */ C1394Camera::~C1394Camera() { int i; DllTrace(DLL_TRACE_ENTER,"ENTER C1394Camera Destructor\n"); if(m_hDevInfo != INVALID_HANDLE_VALUE) SetupDiDestroyDeviceInfoList(m_hDevInfo); if(m_hDeviceAcquisition != INVALID_HANDLE_VALUE) StopImageAcquisition(); // nuke the strobe controls for(i=0; i<FEATURE_NUM_FEATURES; i++) if(this->m_pControls[i] != NULL) delete m_pControls[i]; if(m_pControlTrigger) delete m_pControlTrigger; if(m_pControlSize) delete m_pControlSize; // nuke the strobe controls for(i=0; i<4; i++) if(this->m_controlStrobes[i] != NULL) delete m_controlStrobes[i]; DllTrace(DLL_TRACE_EXIT,"EXIT C1394Camera Destructor\n"); }
/**\brief Read the Feature Status Register * \param pRawData If non-NULL, the raw 32-bits of the status register will be copied here * \return Essentially the same as C1394Camera::ReadQuadlet() * * This Reads the feature status register determined by m_offset into m_StatusReg. * If absolute control is active, the current absolute values is read into m_absval * * Note: This is the only way to read these variables from the camera. All other accessors * (StatusStuff, GetValue) simply return the values in the class members. */ int C1394CameraControl::Status(unsigned long *pRawData) { unsigned long *pulBits = (unsigned long *)&this->m_StatusReg; int ret; if((ret = m_pCamera->ReadQuadlet(m_statusoffset, pulBits) != CAM_SUCCESS)) { DllTrace(DLL_TRACE_ERROR,"C1394CameraControl::Status: error %d on ReadQuadlet\n", ret); return ret; } if(m_InquiryReg.absctl && m_StatusReg.absctl) { if((ret = m_pCamera->ReadQuadlet(m_absctloffset + 0x8, (unsigned long *)&m_absval) != CAM_SUCCESS)) { DllTrace(DLL_TRACE_ERROR,"C1394CameraControl::Inquire: error %d on ReadQuadlet(%08x)\n", ret,m_absctloffset + 0x8); return ret; } } if(pRawData) *pRawData = *pulBits; DllTrace(DLL_TRACE_EXIT,"EXIT Control::Status@0x%02x: %08x\n", m_offset,*pulBits); return ret; }
/**\brief Mutator for the current image size * \param width The horizontal size to set * \param height The vertical size to set * \return * - CAM_ERROR_NOT_INITIALIZED if format 7 and a valid mode are not selected in the container camera * - CAM_ERROR_PARAM_OUT_OF_RANGE if the provided size is either too large or is not a multiple of the size units * - Other errors: bad things happened in WriteQuadlet * * Size overrides position, so if the current position is outside the bounds of */ int C1394CameraControlSize::SetSize(unsigned short width, unsigned short height) { unsigned short maxh,maxv; unsigned short hunit,vunit; unsigned short top,left; int ret = CAM_SUCCESS; //SR DllTrace(DLL_TRACE_ENTER,"ENTER ControlSize::SetSize(%d,%d)\n",width,height); if(m_offset == 0) { ret = CAM_ERROR_NOT_INITIALIZED; goto _exit; } this->GetSizeLimits(&maxh,&maxv); this->GetSizeUnits(&hunit,&vunit); if(hunit == 0 || vunit == 0) { DllTrace(DLL_TRACE_ERROR,"ControlSize::SetSize: Broken Invariants: Size Units %d,%d\n",hunit,vunit); ret = CAM_ERROR; goto _exit; } if( width == 0 || height == 0 || width > maxh || height > maxv || (width % hunit) != 0 || (height % vunit) != 0) { DllTrace(DLL_TRACE_ERROR,"ControlSize::SetSize: Invalid parameter(s): %d,%d\n",width,height); ret = CAM_ERROR_PARAM_OUT_OF_RANGE; goto _exit; } // if we get here, the parameters are okay, so push the private register down m_StaImageSize = width; m_StaImageSize <<= 16; m_StaImageSize += height; if((ret = m_pCamera->WriteQuadlet(m_offset + 0x00C,m_StaImageSize)) != CAM_SUCCESS) goto _exit; // and check the position for consistency this->GetPos(&left,&top); this->GetPosLimits(&maxh,&maxv); if(left > maxh) left = maxh; if(top > maxv) top = maxv; if((ret = this->SetPos(left,top)) != CAM_SUCCESS) goto _exit; // SetSize mods the Tier 1 registers ret = this->UpdateTier1(TRUE); _exit: if(ret != CAM_SUCCESS) DllTrace(DLL_TRACE_ERROR,"ControlSize::SetSize: Error %d\n",ret); DllTrace(DLL_TRACE_EXIT,"EXIT ControlSize::SetSize(%d)\n",ret); return ret; }
/**\brief Trigger the transfer of exactly one frame from the camera * \ingroup camcore * \return CAM_SUCCESS if successful, CAM_ERROR otherwise * * This function is a wrapper for an otherwise simple procedure. Maybe it should * be inlined and just return whatever the WriteRegister returns * * This function is currently not used by anything at all because it does not integrate * cleanly with the acquisition code. */ int C1394Camera::OneShot() { ULONG ulRet; int retval = CAM_SUCCESS; DllTrace(DLL_TRACE_ENTER,"ENTER OneShot\n"); if((ulRet = WriteQuadlet(0x61c,0x80000000)) != 0) { DllTrace(DLL_TRACE_ERROR,"OneShot: error %08x on WriteQuadlet(0x61c)\n",ulRet); retval = CAM_ERROR; } DllTrace(DLL_TRACE_EXIT,"EXIT OneShot (%d)\n",retval); return retval; }
/**\brief Disable continuous streaming of camera data. * \ingroup camcore * \return CAM_SUCCESS if successful, CAM_ERROR otherwise * * This is essentially a one-liner that is referenced from one place and may soon be removed */ int C1394Camera::StopVideoStream() { ULONG ulRet; int retval = CAM_SUCCESS; DllTrace(DLL_TRACE_ENTER,"ENTER StopVideoStream\n"); if((ulRet = WriteQuadlet(0x614,0x00000000)) != 0) { DllTrace(DLL_TRACE_ERROR,"StopVideoStream: error %08x on WriteQuadlet(0x614)\n",ulRet); retval = CAM_ERROR; } DllTrace(DLL_TRACE_EXIT,"EXIT StopVideoStream (%d)\n",retval); return retval; }
/**\brief Display a modeless dialog to all the C1394CameraControl members of a C1394Camera class * \ingroup dialogs * \param hWndParent The parent window for this instance * \param pCamera Pointer to the camera to be controlled * \param bLoadDefaultView If TRUE, load the default control selections from the registry * \return HWND to the control window, NULL on error. GetLastError() should be handy. * * Note that this is modeless and thus allows multiple control windows to be * open for multiple cameras. Also note that you must provide your own message pump. */ HWND CAMAPI CameraControlDialog( HWND hWndParent, C1394Camera *pCamera, BOOL bLoadDefaultView ) { HWND hWnd; WNDCLASSEX wcex; DllTrace(DLL_TRACE_ENTER,"ENTER CameraControlDialog(%08x,%08x)\n", hWndParent, pCamera); // we need common controls for the slider class to work InitCommonControls(); // register the window class ZeroMemory(&wcex,sizeof(WNDCLASSEX)); wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)ControlDialogWndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = g_hInstDLL; wcex.hIcon = LoadIcon(g_hInstDLL, (LPCTSTR)IDR_ICON1); wcex.hIconSm = LoadIcon(g_hInstDLL, (LPCTSTR)IDR_ICON1); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_3DFACE+1); wcex.lpszMenuName = (LPCSTR)IDR_CONTROL_MENU; wcex.lpszClassName = "1394 Control Panes Dialog Class"; RegisterClassEx(&wcex); // Init the instance hWnd = InitControlDialogInstance (g_hInstDLL, hWndParent, pCamera); if(bLoadDefaultView) { DllTrace(DLL_TRACE_CHECK,"CameraControlDialog: Loading Default View\n"); SendMessage(hWnd,WM_COMMAND,MAKELONG(ID_FILE_LOADDEFAULTVIEW,0),0); } DllTrace(DLL_TRACE_EXIT,"EXIT CameraControlDialog(%08x)\n",hWnd); return hWnd; }
/**\brief Set the number of bytes per packet * \param bpp The number to set * \return * - CAM_ERROR_NOT_INITIALIZED if format 7 and a valid mode are not selected in the container camera * - CAM_ERROR_PARAM_OUT_OF_RANGE <i>bpp</i> is either out of bounds or does not conform to the required increments * - Other errors: bad things happened in WriteQuadlet * * This is roughly analagous to setting the frame rate for most cameras supporting format 7 */ int C1394CameraControlSize::SetBytesPerPacket(unsigned short bpp) { unsigned short min,max; int ret; if(this->m_offset == NULL) return CAM_ERROR_NOT_INITIALIZED; this->GetBytesPerPacketRange(&min,&max); if( min == 0 || max == 0 || bpp < min || bpp > max || (bpp % min) != 0) { DllTrace(DLL_TRACE_ERROR,"ControlSize::SetBytesPerPacket: Invalid Parameter (%d)\n",bpp); return CAM_ERROR_PARAM_OUT_OF_RANGE; } this->m_StaBytesPerPacket &= 0x0000FFFF; this->m_StaBytesPerPacket |= ((unsigned long)bpp)<<16; if((ret = m_pCamera->WriteQuadlet(m_offset + 0x044,m_StaBytesPerPacket)) != CAM_SUCCESS) return ret; // twiddling BytesPerPacket affects Tier 2 registers return UpdateTier2(TRUE); }
/**\brief Initialize a Control instance * \param pCamera The parent/container C1394Camera that this control class will operate on * \param feature The ID of the feature to manipulate * * If a valid feature is passed in, this will retrieve and compute the appropriate offsets for * the inquiry and status. If not (e.g. FEATURE_INVALID_FEATURE), then this step will be skipped * so subclass constructors (e.g. C1394CameraControlStrobe have an opportunity to init them cleanly * * Also, bad things will happen if the parent camera pointer is invalid. */ C1394CameraControl::C1394CameraControl(C1394Camera *pCamera, CAMERA_FEATURE feature): m_pCamera(pCamera), m_feature(feature) { if(m_pCamera == NULL) DllTrace(DLL_TRACE_ALWAYS, "C1394CameraControl: Parent pointer is NULL while constructing %08x, bad things will happen\n", this); // nuke the registers and absstuff *((unsigned long *)&this->m_InquiryReg) = 0; *((unsigned long *)&this->m_StatusReg) = 0; this->m_absmin = this->m_absmax = this->m_absval = 0.0f; // look up the offset and such if(m_feature >= FEATURE_BRIGHTNESS && m_feature < FEATURE_NUM_FEATURES) { this->m_offset = dc1394GetFeatureOffset(feature); this->m_statusoffset = this->m_offset + FEATURE_STATUS_INDEX; this->m_inquiryoffset = this->m_offset + FEATURE_INQUIRY_INDEX; } else { this->m_offset = 0; this->m_statusoffset = 0; this->m_inquiryoffset = 0; } }
/**\brief Trigger the transfer of exactly <i>N</i> frames from the camera * \param count The number of frames to transfer (0 to stop a running multishot) * \ingroup camcore * \return CAM_SUCCESS if successful, CAM_ERROR otherwise * * This function is a wrapper for an otherwise simple procedure. Maybe it should * be inlined and just return whatever the WriteRegister returns * * This function is currently not used by anything at all because it does not integrate * cleanly with the acquisition code. * * Also, MultiShot() should be implemented */ int C1394Camera::MultiShot(unsigned short count) { ULONG ulRet,ulData; int retval = CAM_SUCCESS; DllTrace(DLL_TRACE_ENTER,"ENTER MultiShot\n"); ulData = (ULONG) count; // count in the low 16 bits if(count != 0)(ulData |= 0x40000000); // bit 1 (second-to-highest) enables multishot DllTrace(DLL_TRACE_CHECK,"MultiShot: Writing 0x%08x to %03x\n",ulData,0x61c); if((ulRet = WriteQuadlet(0x61c,ulData)) != 0) { DllTrace(DLL_TRACE_ERROR,"MultiShot: error %08x on WriteQuadlet(0x61c)\n",ulRet); retval = CAM_ERROR; } DllTrace(DLL_TRACE_EXIT,"EXIT MultiShot (%d)\n",retval); return retval; }
/**\brief Mutator for the current image position * \param left The horizontal position to set * \param top The vertical position to set * \return * - CAM_ERROR_NOT_INITIALIZED if format 7 and a valid mode are not selected in the container camera * - CAM_ERROR_PARAM_OUT_OF_RANGE if the provided positions is either too large or is not a multiple of the position units * - Other errors: bad things happened in WriteQuadlet * * Position does not affect anything other than itself */ int C1394CameraControlSize::SetPos(unsigned short left, unsigned short top) { unsigned short maxh,maxv; unsigned short hunit,vunit; int ret = CAM_SUCCESS;//SR DllTrace(DLL_TRACE_ENTER,"ENTER ControlSize::SetPos(%d,%d)\n",left,top); if(m_offset == 0) { ret = CAM_ERROR_NOT_INITIALIZED; goto _exit; } this->GetSizeLimits(&maxh,&maxv); this->GetPosUnits(&hunit,&vunit); if(hunit == 0 || vunit == 0) { DllTrace(DLL_TRACE_ERROR,"ControlSize::SetPos: Broken Invariants: Pos Units %d,%d\n",hunit,vunit); ret = CAM_ERROR; goto _exit; } if( left > maxh || top > maxv || (left % hunit) != 0 || (top % vunit) != 0) { DllTrace(DLL_TRACE_ERROR,"ControlSize::SetPos: Invalid parameter(s): %d,%d\n",left,top); ret = CAM_ERROR_PARAM_OUT_OF_RANGE; goto _exit; } // if we get here, the parameters are okay, so push the private register down m_StaImagePos = left; m_StaImagePos <<= 16; m_StaImagePos += top; if((ret = m_pCamera->WriteQuadlet(m_offset + 0x008,m_StaImagePos)) != CAM_SUCCESS) goto _exit; _exit: if(ret != CAM_SUCCESS) DllTrace(DLL_TRACE_ERROR,"ControlSize::SetPos: Error %d\n",ret); DllTrace(DLL_TRACE_EXIT,"EXIT ControlSize::SetPos(%d)\n",ret); return ret; }
/**\brief Check the PnP Subsystem for attached devices. * \ingroup camcore * \return * - The number of cameras available, (zero if none) * - CAM_ERROR: Some problem with a system call, check GetLastError() * * This function is meant to replace CheckLink(), as it is more semantically correct */ int C1394Camera::RefreshCameraList() { int ret = CAM_ERROR; DllTrace(DLL_TRACE_ENTER,"ENTER RefreshCameraList\n"); if(m_hDevInfo != INVALID_HANDLE_VALUE) SetupDiDestroyDeviceInfoList(m_hDevInfo); m_dwDevCount = 0; if((m_hDevInfo = t1394CmdrGetDeviceList()) == INVALID_HANDLE_VALUE) { DllTrace(DLL_TRACE_ERROR,"RefreshCameraList: Error on CmdrGetDeviceList\n"); } else { // count devices char buf[512]; int i; ULONG sz = sizeof(buf); for(i=0; ;i++) { sz = sizeof(buf); if((ret = t1394CmdrGetDevicePath(m_hDevInfo,i,buf,&sz)) <= 0) { ret = (ret < 0 ? CAM_ERROR : i); break; } DllTrace(DLL_TRACE_CHECK,"RefreshCameraList: Enum %d: %s\n",i,buf); } } if(ret >= 0) { m_dwDevCount = ret; } else { DllTrace(DLL_TRACE_ERROR,"Error on getDevicePath:%d\n",GetLastError()); if(m_hDevInfo != INVALID_HANDLE_VALUE) { SetupDiDestroyDeviceInfoList(m_hDevInfo); m_hDevInfo = INVALID_HANDLE_VALUE; } } DllTrace(DLL_TRACE_EXIT,"EXIT RefreshCameraList (%d)\n",ret); return ret; }
/**\brief Read the Feature Inquiry Register * \param pRawData If non-NULL, the raw 32-bits of the inquiry register will be copied here * \return Essentially the same as C1394Camera::ReadQuadlet() * * This Reads the feature inquiry register determined by m_inquiryoffset into m_InquiryReg. * If absolute control is supported, the min and max absolute values are * read into m_absmin and m_absmax respectively. * * Note: This is the only way to read these registers from the camera. All other accessors * (HasStuff, GetRange) simply return the values in the class members. */ int C1394CameraControl::Inquire(unsigned long *pRawData) { unsigned long* pulBits = (unsigned long *)&this->m_InquiryReg; int ret; if((ret = m_pCamera->ReadQuadlet(m_inquiryoffset, pulBits) != CAM_SUCCESS)) { DllTrace(DLL_TRACE_ERROR,"C1394CameraControl::Inquire: error %d on ReadQuadlet (Inquiry)\n", ret); return ret; } if(m_InquiryReg.absctl) { /* has absolute value registers */ if((ret = m_pCamera->ReadQuadlet(m_offset + FEATURE_ABSCTL_INDEX, &m_absctloffset) != CAM_SUCCESS)) { DllTrace(DLL_TRACE_ERROR,"C1394CameraControl::Inquire: error %d on ReadQuadlet (Abs Offset)\n", ret); return ret; } // the returned offset is an absolute quadlet offset, requiring multiplication by 4 and a leading 0xF to work out m_absctloffset = (m_absctloffset << 2) | 0xf0000000; DllTrace(DLL_TRACE_CHECK,"C1394CameraControl: Control %04x has absolute offset %08x\n",m_offset,m_absctloffset); // read min, max, val if((ret = m_pCamera->ReadQuadlet(m_absctloffset + 0x0, (unsigned long *)&m_absmin) != CAM_SUCCESS)) { DllTrace(DLL_TRACE_ERROR,"C1394CameraControl::Inquire: error %d on ReadQuadlet(%08x)\n", ret,m_absctloffset + 0x0); return ret; } if((ret = m_pCamera->ReadQuadlet(m_absctloffset + 0x4, (unsigned long *)&m_absmax) != CAM_SUCCESS)) { DllTrace(DLL_TRACE_ERROR,"C1394CameraControl::Inquire: error %d on ReadQuadlet(%08x)\n", ret,m_absctloffset + 0x4); return ret; } } if(pRawData) *pRawData = *pulBits; return CAM_SUCCESS; }
/**\brief Check the 1394 subsystem for any connected cameras. * \ingroup camcore * \return * - CAM_SUCCESS: Found at least one camera and have selected camera 0 * - CAM_ERROR: Found no cameras on the 1394 bus(es) * * This function is now deprecated in favor of RefreshCameraList(). * It is maintained for backwards compatibility and will be removed * in a future version. */ int C1394Camera::CheckLink() { DllTrace(DLL_TRACE_ENTER,"ENTER CheckLink\n"); if(RefreshCameraList() > 0) { SelectCamera(0); m_linkChecked = true; return 0; } return -1; }
int C1394Camera::WriteQuadlet(unsigned long address, unsigned long data) { int ret = CAM_ERROR; int nretries = 4; DWORD dwRet; DllTrace(DLL_TRACE_ENTER,"ENTER WriteQuadlet (%08x,%08x)\n",address,data); if(!m_pName) { DllTrace(DLL_TRACE_ERROR,"WriteQuadlet: No Camera has been selected\n"); ret = CAM_ERROR_NOT_INITIALIZED; goto _exit; } // we're gonna try this nretries times, looking for // ERROR_SEM_TIMEOUT, which maps to STATUS_IO_TIMEOUT // meaning that the camera can't keep up. while((dwRet = WriteRegisterUL(m_pName,address,data)) != 0 && nretries > 0) { if(dwRet != ERROR_SEM_TIMEOUT) // some other error, break out break; // Sleep for 10 ms Sleep(10); nretries--; DllTrace(DLL_TRACE_WARNING,"WriteQuadlet: Warning: Timeout on WriteRegister@0x%08x. Retries Remaining: %d\n", address,nretries); } if(dwRet != 0) { DllTrace(DLL_TRACE_ERROR,"WriteQuadlet: Unrecoverable error %08x on WriteRegisterUL\n",dwRet); goto _exit; } ret = CAM_SUCCESS; _exit: DllTrace(DLL_TRACE_EXIT,"EXIT WriteQuadlet (%d)\n",ret); return ret; }
/**\brief Initialize and allocate the Isochronous resources necessary to start an isochronous * streaming operation. * \ingroup camcore * \return TRUE if initialization was successful, false if not (check GetLastError()) * * The information necessary to allocate stream resources is gleaned from the selected video modes * this whole function may be converted to a single IOCTL code and moved into kernel land. There is * no reason for userland to have any of this information. */ BOOL C1394Camera::InitResources() { ISOCH_STREAM_PARAMS StreamParams; ULONG ulRet,ulData; BOOL bRet = FALSE; DllTrace(DLL_TRACE_ENTER,"ENTER InitResources\n"); // Tripping either of these would indicate some sort of broken invariant // As they are also checked by StartImage*, which are the only functions // that call this. // however, we will check them anyway if (!m_pName) { DllTrace(DLL_TRACE_ERROR,"InitResources: Error: No camera selected\n"); goto _exit; } if(m_hDeviceAcquisition != INVALID_HANDLE_VALUE) { DllTrace(DLL_TRACE_ERROR,"InitResources: Error: Camera is busy, stop image acquisition first\n"); goto _exit; } // for the hell of it, make sure the camera is free to be allocated FreeResources(); ReadQuadlet(0x60c, &ulData); if(this->m_AcquisitionFlags & ACQ_SUBSCRIBE_ONLY) { if(ulData & 0x00008000) { // 1394b mode StreamParams.fulSpeed = 1 << (ulData & 0x0F); StreamParams.nChannel = ((ulData>>8) & 0x0F); } else {
/**\brief Get the a textual description of the camera indexed by <i>node</i>. * \param node The node to describe * \param buf The output buffer * \param buflen The output buffer length; * \ingroup camcore * \return Length of the string, 0 for an invalid node * * */ int C1394Camera::GetNodeDescription(int node, char *buf, int buflen) { char *pout, *pin, *pend; unsigned int sharps = 0; if(this->m_hDevInfo) { if(t1394CmdrGetDevicePath(m_hDevInfo,node,buf,(unsigned long *)&buflen) <= 0) { DllTrace(DLL_TRACE_ERROR,"SelectCamera: Error on GetDevicePath (%d)\n",GetLastError()); return 0; } pin = pout = buf; pend = pin + strlen(buf); // the format is junk#vendor&model#ID#junk // first sharp while(pin < pend && sharps < 3) { if(*pin == '#') { sharps++; if(sharps == 2) { *pout++ = ' '; *pout++ = '('; } if(sharps == 3) { *pout++ = ')'; *pout = 0; } } else if(sharps > 0) { if(*pin == '&') *pin = ' '; *pout++ = *pin; } pin++; } return (int)(pout - buf); } return 0; }
/**\brief Initiailze a Size control * \param pCamera The parent/container camera whose size os to be controlled */ C1394CameraControlSize::C1394CameraControlSize(C1394Camera *pCamera):m_pCamera(pCamera) { if(m_pCamera == NULL) DllTrace(DLL_TRACE_ALWAYS,"ControlSize: Construction: parent camera pointer is invalid: bad things will happen!\n"); //SR m_offset = 0; m_InqMaxSize = 0; m_InqUnitSize = 0; m_InqColorCodes = 0; m_InqUnitPos = 0; m_StaImagePos = 0; m_StaImageSize = 0; m_StaColorCode = 0; m_StaValueSetting = 0; m_InqPixels = 0; m_InqBytesHi = 0; m_InqBytesLo = 0; m_InqPacketParam = 0; m_InqDataDepth = 0; m_InqColorFilter = 0; m_StaBytesPerPacket = 0; m_InqPacketsPerFrame= 0; m_InqFrameInterval = 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; }
/**\brief Builds and displays an instance of the 1394 Camera Control Dialog * \ingroup dialogs * \param hInstance The instance the class was registered against * \param hWndParent The parent window * \param pCamera The Camera this dialog will control * \return HWND to the instance, NULL on error * * This is an internal function, so there is less idiotproofing */ HWND InitControlDialogInstance(HINSTANCE hInstance, HWND hWndParent, C1394Camera *pCamera) { HWND hWnd = NULL; PCONTROL_WINDOW_EXTENSION pWndExt; int i; DllTrace(DLL_TRACE_ENTER,"ENTER InitControlDialogInstance(%08x,%08x,%08x)\n", hInstance, hWndParent, pCamera); if(!pCamera) { DllTrace(DLL_TRACE_ERROR,"InitControlDialogInstance: NULL Camera Passed, Aborting!\n"); goto _exit; } pWndExt = (PCONTROL_WINDOW_EXTENSION) LocalAlloc(LPTR,sizeof(CONTROL_WINDOW_EXTENSION)); if(!pWndExt) { DllTrace(DLL_TRACE_ERROR,"InitControlDialogInstance: Failed to Allocate pWndExt (%08x)\n",GetLastError()); goto _exit; } pWndExt->pCamera = pCamera; hWnd = CreateWindow("1394 Control Panes Dialog Class", "1394 Camera Controls", WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_BORDER|WS_MINIMIZEBOX|WS_CLIPCHILDREN|WS_HSCROLL, CW_USEDEFAULT, 0, 200, 100, hWndParent, NULL, hInstance, NULL); if (!hWnd) { DllTrace(DLL_TRACE_ERROR,"InitControlDialogInstance: CreateWindow Failed (%08x)\n",GetLastError()); LocalFree(pWndExt); goto _exit; } pWndExt->hAccel = LoadAccelerators(hInstance,MAKEINTRESOURCE(IDR_CONTROL_ACCEL)); SetWindowLongPtr(hWnd,GWLP_USERDATA,(LONG_PTR)(pWndExt)); ShowWindow(hWnd, SW_SHOW); ShowScrollBar(hWnd,SB_HORZ,FALSE); UpdateWindow(hWnd); DllTrace(DLL_TRACE_CHECK,"InitControlDialogInstance: adding panes...\n"); for(i=0; i<FEATURE_NUM_FEATURES; i++) { C1394CameraControl *pControl; ULONG flags = PIF_VISIBLE; CAMERA_FEATURE fID = (CAMERA_FEATURE)(i); if((pControl = pCamera->GetCameraControl(fID)) != NULL) { if( fID == FEATURE_WHITE_BALANCE || fID == FEATURE_TEMPERATURE || fID == FEATURE_WHITE_SHADING ) flags |= PIF_TWO_SLIDERS; AddControlPane(hInstance,hWnd,pWndExt,pControl,flags); } } for(i=0; i<4; i++) { C1394CameraControlStrobe *pStrobe = pCamera->GetStrobeControl(i); if(pStrobe != NULL) { AddControlPane(hInstance,hWnd,pWndExt,(C1394CameraControl *)pStrobe,PIF_VISIBLE | PIF_TWO_SLIDERS | PIF_STROBE); } } ShowControlPanes(hWnd,TRUE); _exit: DllTrace(DLL_TRACE_EXIT,"EXIT InitControlDialogInstance (%08x)\n",hWnd); return hWnd; }
/**\brief Initializes a C1394Camera class * \ingroup camcore * * The constructor initializes internal state and assigns register offsets and parent pointers * to the public C1394CameraControl members. Many C++ compilers moan about using <i>this</i> * in initializers, and justifiably so. Each of these constructors does nothing more than store * <i>this</i> as its parent camera pointer. No further processing is done downstream of the constructor. */ C1394Camera::C1394Camera(): m_pName(NULL), m_linkChecked(false), m_cameraInitialized(false), m_node(-1), m_hDeviceAcquisition(INVALID_HANDLE_VALUE), m_hDevInfo(INVALID_HANDLE_VALUE), m_dwDevCount(0), m_videoFormat(0), m_videoMode(0), m_videoFrameRate(0), m_InqBasicFunc(0), m_InqFeatureHi(0), m_InqFeatureLo(0), m_InqOptionalFunc(0), m_StatusPowerControl(0), m_StatusVideoError(0), m_StatusVideoDepth(0), m_StatusFeatureErrorHi(0), m_StatusFeatureErrorLo(0), m_AdvFuncOffset(0), m_PIOFuncOffset(0), m_SIOFuncOffset(0), m_StrobeFuncOffset(0), m_StrobeRootCaps(0), m_maxBytes(0), m_maxBufferSize(0), m_maxSpeed(0), m_width(0), m_height(0), m_colorCode(COLOR_CODE_INVALID), m_pFirstBuffer(NULL), m_pLastBuffer(NULL), m_pCurrentBuffer(NULL), m_AcquisitionTimeout(0), m_AcquisitionFlags(0), m_AcquisitionBuffers(0) { int i,format,mode; DllTrace(DLL_TRACE_ENTER,"ENTER C1394Camera Constructor\n"); // this is the best place to trace the structure sizes DllTrace(DLL_TRACE_VERBOSE,"sizeof(C1394Camera) = %d\n",sizeof(C1394Camera)); DllTrace(DLL_TRACE_VERBOSE,"sizeof(C1394CameraControl) = %d\n",sizeof(C1394CameraControl)); DllTrace(DLL_TRACE_VERBOSE,"sizeof(C1394CameraControlSize) = %d\n",sizeof(C1394CameraControlSize)); DllTrace(DLL_TRACE_VERBOSE,"sizeof(C1394CameraControlTrigger) = %d\n",sizeof(C1394CameraControlTrigger)); ZeroMemory(&m_spec,sizeof(CAMERA_SPECIFICATION)); // initialize video settings arrays to false m_InqVideoFormats = 0; for (format=0; format<8; format++) { m_InqVideoModes[format] = 0; for (mode=0; mode<8; mode++) m_InqVideoRates[format][mode] = 0; } // initialize the feature controls for(i=0; i<FEATURE_NUM_FEATURES; i++) { if(i != FEATURE_TRIGGER_MODE && dc1394GetFeatureName((CAMERA_FEATURE)(i)) != NULL) m_pControls[i] = new C1394CameraControl(this,(CAMERA_FEATURE)(i)); else m_pControls[i] = NULL; } m_pControlTrigger = new C1394CameraControlTrigger(this); m_pControlSize = new C1394CameraControlSize(this); // initialize the strobe controls for(i=0; i<4; i++) this->m_controlStrobes[i] = new C1394CameraControlStrobe(this,i); m_nameModel[0] = 0; m_nameVendor[0] = 0; m_DevicePath[0] = 0; m_UniqueID.QuadPart = 0; DllTrace(DLL_TRACE_EXIT,"EXIT C1394Camera Constructor\n"); }
/**\brief Performs General initialization of the C1394Camera class for the currently selected camera * \ingroup camcore * \param reset If TRUE, this will poke the camera init register to restore it to powerup defaults * \return * CAM_SUCCESS: The camera is ready to start capturing Frames. * CAM_ERROR_NOT_INITIALIZED: No camera selected (this is poorly named and may be changed) * CAM_ERROR_BUSY: Usualy indicates broken invariants, but in and of itself prevents an * init in the middle of image acquisition * CAM_ERROR: Some register IO failed, GetLastError will tell why * * This Function currently causes a lot of I/O on the 1394 bus to populate the configuration and capability * information about the camera and all the available controllable features. If there are any standard video * formats available (e.g. not format 7), then the first available format, mode and rate are selected by default. */ int C1394Camera::InitCamera(BOOL reset) { GET_MAX_SPEED_BETWEEN_DEVICES maxSpeed; DWORD dwRet; int ret = CAM_ERROR; ULONG maxSpeedNotLocal, maxSpeedLocal; DllTrace(DLL_TRACE_ENTER,"ENTER InitCamera\n"); if(m_cameraInitialized) // this isn't really an error, but should be reported DllTrace(DLL_TRACE_WARNING,"InitCamera: Warning: Duplicate Call to InitCamera\n"); // clear it for another pass m_cameraInitialized = false; if(!m_pName) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error: no camera selected\n"); ret = CAM_ERROR_NOT_INITIALIZED; goto _exit; } if(m_hDeviceAcquisition != INVALID_HANDLE_VALUE) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error: Camera is busy, stop image acquisition first\n"); ret = CAM_ERROR_BUSY; goto _exit; } // this frees up any isoch resources that may be left behind // from a previous program that didn't clean up after itself // properly (i.e. crashed) // This is an ugly way to deal with it, but will have to work for now t1394IsochTearDownStream(m_pName); // determine max speed // this is used for allocating bandwidth and stuff maxSpeed.fulFlags = 0; maxSpeed.ulNumberOfDestinations = 0; if (dwRet = GetMaxSpeedBetweenDevices(m_pName, &maxSpeed)) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error %08x on GetMaxSpeedBetweenDevices (NotLocal)\n",dwRet); goto _exit; } maxSpeedNotLocal = maxSpeed.fulSpeed; maxSpeed.fulFlags = 1; if (dwRet = GetMaxSpeedBetweenDevices(m_pName, &maxSpeed)) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error %08x on GetMaxSpeedBetweenDevices (Local)\n",dwRet); goto _exit; } maxSpeedLocal = maxSpeed.fulSpeed; // select the smaller of the two m_maxSpeed = (maxSpeedLocal < maxSpeedNotLocal ? maxSpeedLocal : maxSpeedNotLocal); // reset to defaults if we want if(reset == TRUE) { if(WriteQuadlet(0x000,0x80000000) != CAM_SUCCESS) DllTrace(DLL_TRACE_WARNING,"InitCamera: Warning: Reset to defaults failed: %08x\n",GetLastError()); } // determine video formats/modes/rates // private functions return bools and do their own respective tracing if(!InquireVideoFormats()) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error on InquireVideoFormats\n"); goto _exit; } if(!InquireVideoModes()) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error on InquireVideoModes\n"); goto _exit; } if(!InquireVideoRates()) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error on InquireVideoRates\n"); goto _exit; } if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x400,&m_InqBasicFunc))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x400)\n",dwRet); goto _exit; } if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x404,&m_InqFeatureHi))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x404)\n",dwRet); goto _exit; } if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x408,&m_InqFeatureLo))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x408)\n",dwRet); goto _exit; } // Poke the error bits, if available this->StatusVideoErrors(TRUE); this->StatusFeatureError(FEATURE_BRIGHTNESS,TRUE); // the core registers have been updated, so it's safe to set this here // NOTE: this flag is very hackish, and should be replaced by explicitly nuking // the toplevel registers on Construction and SelectCamera() m_cameraInitialized = true; if(this->HasPowerControl()) { if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x610,&this->m_StatusPowerControl))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x reading Power Register\n"); goto _exit; } } if(this->HasAdvancedFeature()) { if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x480,&this->m_AdvFuncOffset))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x480)\n",dwRet); goto _exit; } m_AdvFuncOffset <<= 2; m_AdvFuncOffset |= 0xf0000000; } if(this->HasOptionalFeatures()) { // Read the Optional Function Bitmask if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x40C,&m_InqOptionalFunc))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x40C)\n",dwRet); goto _exit; } // And Check the Individual Features if(this->HasPIO()) { if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x484,&this->m_PIOFuncOffset))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x484)\n",dwRet); goto _exit; } m_PIOFuncOffset <<= 2; m_PIOFuncOffset |= 0xf0000000; } if(this->HasSIO()) { if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x488,&this->m_SIOFuncOffset))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x488)\n",dwRet); goto _exit; } m_SIOFuncOffset <<= 2; m_SIOFuncOffset |= 0xf0000000; } if(this->HasStrobe()) { if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x48C,&this->m_StrobeFuncOffset))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x48C)\n",dwRet); goto _exit; } m_StrobeFuncOffset <<= 2; m_StrobeFuncOffset |= 0xf0000000; if(CAM_SUCCESS != (dwRet = ReadQuadlet(this->m_StrobeFuncOffset,&this->m_StrobeRootCaps))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x%08x)\n", dwRet,this->m_StrobeFuncOffset); goto _exit; } } } RefreshControlRegisters(FALSE); UpdateParameters(); ret = CAM_SUCCESS; _exit: if(ret != CAM_SUCCESS) m_cameraInitialized = false; DllTrace(DLL_TRACE_EXIT,"EXIT InitCamera (%d)\n",ret); return ret; }
/**\brief Indexes into the current device list to point the class at a particular camera * \ingroup camcore * \param node: the (zero-indexed) id of the camera to select * \return * - CAM_SUCCESS on success * - CAM_ERROR_PARAM_OUT_OF_RANGE: you gave a bad camera number * - CAM_ERROR_BUSY: The currently Selected Camera is Busy, call StopImageAcquisition() first * - CAM_ERROR: general I/O error (probably GetCameraSpecification) * * This is the only class function that will generate dialog boxes and will do so * if and only if it believes that the device you selected isn't *really* a camera * that complies with the 1394 Digital Camera Specification. */ int C1394Camera::SelectCamera(int node) { char buf[256]; ULONG sz = sizeof(buf); int format, mode; int ret = CAM_ERROR; ULONG ulRet; DllTrace(DLL_TRACE_ENTER,"ENTER SelectCamera (%d)\n",node); if(m_hDeviceAcquisition != INVALID_HANDLE_VALUE) { DllTrace(DLL_TRACE_ERROR,"SelectCamera: Currently Selected Camera is Busy, you must call StopImageAcquisition First\n"); ret = CAM_ERROR_BUSY; goto _exit; } if(node < 0 || (unsigned int)node >= m_dwDevCount) { DllTrace(DLL_TRACE_ERROR,"SelectCamera: Camera %d out of range\n",node); ret = CAM_ERROR_PARAM_OUT_OF_RANGE; goto _exit; } if(t1394CmdrGetDevicePath(m_hDevInfo,node,buf,&sz) <= 0) { DllTrace(DLL_TRACE_ERROR,"SelectCamera: Error on GetDevicePath (%d)\n",GetLastError()); ret = CAM_ERROR; goto _exit; } // check the software version ZeroMemory(&m_spec,sizeof(CAMERA_SPECIFICATION)); if((ulRet = GetCameraSpecification(buf,&m_spec))) { DllTrace(DLL_TRACE_ERROR,"SelectCamera: Error %08x getting Camera Specification\n",ulRet); ret = CAM_ERROR; goto _exit; } if(m_spec.ulSpecification != 0x00A02D) DllTrace(DLL_TRACE_ALWAYS, "SelectCamera: Warning: Camera specification (%06x) does not match 0x00A02D\n", m_spec.ulSpecification); if (m_spec.ulVersion < 0x000100 || m_spec.ulVersion > 0x000104) DllTrace(DLL_TRACE_ALWAYS,"SelectCamera: Warning: Camera software version (%06x) is not supported\n",m_spec.ulVersion); // get the vendor and model names from the driver if((ulRet = GetModelName(buf,m_nameModel,255)) < 0) { DllTrace(DLL_TRACE_ERROR,"SelectCamera: Error on GetModelName\n"); DllTrace(DLL_TRACE_EXIT,"EXIT SelectCamera (%d)\n",CAM_ERROR); return CAM_ERROR; } else { // Null-Terminate m_nameModel[ulRet] = 0; } if((ulRet = GetVendorName(buf,m_nameVendor,255)) < 0) { DllTrace(DLL_TRACE_ERROR,"SelectCamera: Error on GetVendorName\n"); DllTrace(DLL_TRACE_EXIT,"EXIT SelectCamera (%d)\n",CAM_ERROR); return CAM_ERROR; } else { // Null-Terminate m_nameVendor[ulRet] = 0; } GetUniqueID(buf,&m_UniqueID); // whenever we switch cameras, reset our internal stuff m_cameraInitialized = false; // initialize video settings matrices to false m_InqVideoFormats = 0; for (format=0; format<8; format++) { m_InqVideoModes[format] = 0; for (mode=0; mode<8; mode++) m_InqVideoRates[format][mode] = 0; } // empty out the static registers m_InqBasicFunc = 0; m_InqVideoFormats = 0; m_InqFeatureHi = m_InqFeatureLo = 0; strncpy(m_DevicePath,buf,sizeof(m_DevicePath)); m_pName = m_DevicePath; m_node = node; ret = CAM_SUCCESS; DllTrace(DLL_TRACE_CHECK,"SelectCamera: Selected \"%s\"\n",m_pName); _exit: DllTrace(DLL_TRACE_EXIT,"EXIT SelectCamera (%d)\n",ret); return ret; }
/**\brief Walks the pane list and displays the appropriate controls * \ingroup dialogs * \param hWnd The window holding the panes * \param bChanged If TRUE, then number of active panes may have changed, se extra work is done to recount everything * \return TRUE for now (may eventually be FALSE on failures, if any) * * This is an internal-use-only function, so there is less * idiotproofing than there really should be */ BOOL ShowControlPanes(HWND hWnd,BOOL bChanged) { int i,x,y,h=0,w=0,n=0,totalw; RECT wRect,cRect; HWND hWndChild; SCROLLINFO si; PCONTROL_WINDOW_EXTENSION pExt = (PCONTROL_WINDOW_EXTENSION) GetWindowLongPtr(hWnd,GWLP_USERDATA); DllTrace(DLL_TRACE_ENTER,"ENTER ShowControlPanes(%08x,%d)\n",hWnd,bChanged); if(bChanged) { DllTrace(DLL_TRACE_CHECK,"ShowControlPanes: Pane status has changed, going to work...\n"); for(i=0; i<pExt->nPanes; i++) { if(pExt->PaneState[i]) { if(n == 0) { // get the w & h for the first window we get hWndChild = GetDlgItem(hWnd,ID_FIRST_CONTROL_PANE + i); GetWindowRect(hWndChild,&wRect); w = (wRect.right - wRect.left); h = wRect.bottom - wRect.top; } n++; } } if(n == 0) { DllTrace(DLL_TRACE_CHECK,"ShowControlPanes: No active windows found\n"); // no windows, make it small x = 200; y = 100; // and hide the scrollbar ShowScrollBar(hWnd,SB_HORZ,FALSE); pExt->trackpos = 0; } else { if(n > 6) { totalw = (n - 5) * w; // more than 6, show the scrollbar ShowScrollBar(hWnd,SB_HORZ,TRUE); // set up the params si.cbSize = sizeof(SCROLLINFO); si.nMax = totalw; si.nMin = 0; si.nPage = w; si.fMask = SIF_RANGE | SIF_PAGE; if(pExt->trackpos >= totalw - w) { // the number of panes shrank and we can see the last one pExt->trackpos = totalw - w - 1; si.nPos = pExt->trackpos; si.fMask |= SIF_POS; } SetScrollInfo(hWnd,SB_HORZ,&si,TRUE); // cap it at 6 wide n = 6; } else { // don't need it ShowScrollBar(hWnd,SB_HORZ,FALSE); pExt->trackpos = 0; } GetWindowRect(hWnd,&wRect); GetClientRect(hWnd,&cRect); x = (wRect.right - wRect.left) - (cRect.right - cRect.left); y = (wRect.bottom - wRect.top) - (cRect.bottom - cRect.top); y += h; x += n * w; } SetWindowPos(hWnd,NULL,0,0,x,y,SWP_NOMOVE); } // if(bChanged) x = -pExt->trackpos; for(i=0; i<pExt->nPanes; i++) { hWndChild = GetDlgItem(hWnd,ID_FIRST_CONTROL_PANE + i); GetWindowRect(hWndChild,&wRect); w = wRect.right - wRect.left; if(pExt->PaneState[i]) { if((x + w) > 0 && x <= (6 * w)) { SetWindowPos(hWndChild,NULL,x,0,0,0,SWP_NOSIZE); ShowWindow(hWndChild,SW_SHOW); } else { ShowWindow(hWndChild,SW_HIDE); } x += w; } else { ShowWindow(hWndChild,SW_HIDE); } } DllTrace(DLL_TRACE_EXIT,"EXIT ShowControlPanes (TRUE)\n"); return TRUE; }