⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cameradevice.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//      FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice :: CameraPowerUp(BOOL enableMode)
{
   BOOL bResult;

   CAM_FUNCTION_ENTRY();
   
   if (D0 != m_Dx)
   {
     // Power Up CSI module. Enable clock & CSI module.
     m_pCsi->CsiEnable();

     if (TRUE == enableMode)
     {
        // When: open the device.
        // Power Up Prp module. Initialize interrupt and event
        bResult = m_pPrp->PrpPowerUp();
        
        // If power up failure, it will release the resource automatically.
        if (FALSE == bResult)
        {
           DEBUGMSG(ZONE_ERROR, (TEXT("%s : m_pPrp->PrpPowerUp failed\r\n"), __WFUNCTION__));
           return FALSE;
        }
     }
  
     // Power Up Prp module. Enable clock & module; 
     // If there is a module has opened PrP module or PrP enable failure, PrpEnable() return FALSE.
     bResult = m_pPrp->PrpEnable();

     if (FALSE == bResult)
     {
        DEBUGMSG(ZONE_ERROR, (TEXT("%s : m_pPrp->PrpEnable failed\r\n"), __WFUNCTION__));
        m_pPrp->PrpPowerDown();
        return FALSE;
     }

     // Set the current Power status of the device.
     m_Dx = D0;
   }

   CAM_FUNCTION_EXIT();

   return TRUE;
}

//-----------------------------------------------------------------------------
//
// Function:           CameraPowerDown
//
// Description:        Power down the driver
//
// Parameters:   
//      disableMode
//         [in]  If TRUE, disable the clock and other hardware related resource after disable this mode.
//                        doing this before close the device
//               If FALSE, disable the device clock only. 
//                        doing this by power management.
//
// Returns:            None
//
//-----------------------------------------------------------------------------
void CCameraDevice :: CameraPowerDown(BOOL disableMode)
{
   CAM_FUNCTION_ENTRY();

   if (D4 != m_Dx)
   {
     // Power Down Prp module. Disable clock & module;
     m_pPrp->PrpDisable();
     if (TRUE == disableMode)
     {
        // When: close the device.
        // Power Down Prp module. Deinitialize interrupt and event
        m_pPrp->PrpPowerDown();
     }

     // Power Down CSI module. Disable clock & CSI module.
     m_pCsi->CsiDisable();

     // Set the current Power status of the device.
     m_Dx = D4;
   }    

   CAM_FUNCTION_EXIT();
}

//-----------------------------------------------------------------------------
//
// Function:    SetCameraPower
//
// Description: Set the camera power state.  Only the D0 and D4 states are supported.
//
// Parameters:
//      power_state
//          [in] New camera power state.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------
void CCameraDevice::SetCameraPower(CEDEVICE_POWER_STATE power_state)
{
    static CSSTATE restoreVfState = CSSTATE_STOP;
    static CSSTATE restoreEncState = CSSTATE_STOP;

    CAM_FUNCTION_ENTRY();

    switch (power_state)
    {
        case D0:
            // State set to D0 (full power).  Restore channels that were
            // previously running.  Otherwise, take no action.
            {
                // If there is one pin device is active, power up the camera device.
                if ((m_StrmInstances[PREVIEW].pPinDev != NULL) ||\
                    (m_StrmInstances[CAPTURE].pPinDev != NULL))
                {
                    if (FALSE == CameraPowerUp(FALSE))
                     {
                        DEBUGMSG(ZONE_ERROR, (TEXT("%s : Camera Power Up Failed\r\n"), __WFUNCTION__));    
                        return ;
                     }
                }
                
                if (m_StrmInstances[PREVIEW].pPinDev != NULL)
                {
                    // Restore Viewfinding state if needed
                    if (restoreVfState == CSSTATE_PAUSE)
                    {
                        // Restore state
                        m_StrmInstances[PREVIEW].pPinDev->SetState(CSSTATE_PAUSE, NULL);

                        // clear restoreVfState (CSSTATE_STOP is equivalent to clearing)
                        restoreVfState = CSSTATE_STOP;
                    }
                    else if (restoreVfState == CSSTATE_RUN)
                    {
                        // If we are restoring to RUN state, we must first
                        // move into pause state
                        m_StrmInstances[PREVIEW].pPinDev->SetState(CSSTATE_PAUSE, NULL);

                        // Restore state
                        m_StrmInstances[PREVIEW].pPinDev->SetState(CSSTATE_RUN, NULL);

                        // clear restoreVfState (CSSTATE_STOP is equivalent to clearing)
                        restoreVfState = CSSTATE_STOP;
                    }
                }

                if (m_StrmInstances[CAPTURE].pPinDev != NULL)
                {
                    // Restore Encoding state if needed
                    if (restoreEncState == CSSTATE_PAUSE)
                    {
                        // Restore state
                        m_StrmInstances[CAPTURE].pPinDev->SetState(CSSTATE_PAUSE, NULL);

                        // clear restoreEncState (CSSTATE_STOP is equivalent to clearing)
                        restoreEncState = CSSTATE_STOP;
                    }
                    else if (restoreEncState == CSSTATE_RUN)
                    {
                        // If we are restoring to RUN state, we must first
                        // move into pause state
                        m_StrmInstances[CAPTURE].pPinDev->SetState(CSSTATE_PAUSE, NULL);

                        // Restore state
                        m_StrmInstances[CAPTURE].pPinDev->SetState(CSSTATE_RUN, NULL);

                        // clear restoreEncState (CSSTATE_STOP is equivalent to clearing)
                        restoreEncState = CSSTATE_STOP;
                    }
                }
            }
            break;

        case D4:
            // State set to D4 (off).  Turn off any channels that are running.
            // If state is already D4, do nothing.
            {
                if (m_StrmInstances[CAPTURE].pPinDev != NULL)
                {
                    // If CAPTURE channel is not stopped, we must stop it
                    if (m_StrmInstances[CAPTURE].pPinDev->m_CsState != CSSTATE_STOP)
                    {
                        // Save current state in order to restore
                        restoreEncState = m_StrmInstances[CAPTURE].pPinDev->m_CsState;

                        // Stop Capture
                        m_StrmInstances[CAPTURE].pPinDev->SetState(CSSTATE_STOP, NULL);
                    }
                }

                if (m_StrmInstances[PREVIEW].pPinDev != NULL)
                {
                    // If PREVIEW channel is not stopped, we must stop it
                    if (m_StrmInstances[PREVIEW].pPinDev->m_CsState != CSSTATE_STOP)
                    {
                        // Save current state in order to restore
                        restoreVfState = m_StrmInstances[PREVIEW].pPinDev->m_CsState;

                        // Stop Preview
                        m_StrmInstances[PREVIEW].pPinDev->SetState(CSSTATE_STOP, NULL);
                    }
                }

                // If there is more than one pin device is active, power down the camera device.
                if ((m_StrmInstances[PREVIEW].pPinDev != NULL) ||\
                    (m_StrmInstances[CAPTURE].pPinDev != NULL))
                {
                    CameraPowerDown(FALSE);
                }
          }
            break;

        default: // Invalid state
            break;
    }

   CAM_FUNCTION_EXIT();
}

//-----------------------------------------------------------------------------
//
// Function: CameraMarkAsModified
//
// This function informs the camera driver that important
// configuration paramaters have been modified.  This ensures
// that the camera will reconfigure the preprocessing before
// starting again.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------
void CCameraDevice::CameraMarkAsModified(ULONG ulPinId)
{
    CAM_FUNCTION_ENTRY();

    // Assure that we will reconfigure Camera driver before starting.
    m_bCameraConfig = FALSE;

    CAM_FUNCTION_EXIT();
}

//-----------------------------------------------------------------------------
//
// Function: BindApplicationProc
//
// Saves the handle of the caller process.
//
// Parameters:
//      hCurrentProc
//          [in] Handle to caller process to save.
//
// Returns:
//      TRUE if success
//      FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::BindApplicationProc(HANDLE hCurrentProc)
{
    if ( NULL != m_hCallerProcess )
    {
        return FALSE;
    }

    if (FALSE == CameraPowerUp(TRUE))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("%s : Camera Power Up Failed\r\n"), __WFUNCTION__));    
        return FALSE;
    }

    m_ulCTypes = 3;

    // Check the registry to see what format and number of pins we support.
    HKEY hKey = NULL;

    if ( ERROR_SUCCESS == RegOpenKeyEx( HKEY_LOCAL_MACHINE, L"Drivers\\Capture\\Camera", 0, 0, &hKey ) )
    {
        DWORD dwType  = 0;
        DWORD dwSize  = sizeof ( DWORD );
        DWORD dwValue = 0;

        //WCHAR szGuid[MAX_PATH];
        //GUID  guid;

        // Find out if we should be using some other number of pins. The only
        // valid options are 2 or 3. Default to 3.
        if ( ERROR_SUCCESS == RegQueryValueEx( hKey, L"PinCount", 0, &dwType, (BYTE *)&dwValue, &dwSize ) )
        {
            if ( REG_DWORD == dwType
                 && sizeof ( DWORD ) == dwSize
                 && 2 == dwValue )
            {
                m_ulCTypes = 2;
            }
        }

/*
        if ( ERROR_SUCCESS == RegQueryValueEx( hKey, L"StreamGuid0", 0, &dwType, (BYTE *)szGuid, &dwSize ) )
        {
            if ( REG_SZ == dwType
                 && ConvertStringToGuid( szGuid, &guid ) )
            {
                DCAM_StreamMode_0.DataRange.SubFormat = guid;
            }
        }

        if ( ERROR_SUCCESS == RegQueryValueEx( hKey, L"StreamGuid1", 0, &dwType, (BYTE *)szGuid, &dwSize ) )
        {
            if ( REG_SZ == dwType
                 && ConvertStringToGuid( szGuid, &guid ) )
            {
                DCAM_StreamMode_1.DataRange.SubFormat = guid;
            }
        }

        if ( ERROR_SUCCESS == RegQueryValueEx( hKey, L"StreamGuid2", 0, &dwType, (BYTE *)szGuid, &dwSize ) )
        {
            if ( REG_SZ == dwType
                 && ConvertStringToGuid( szGuid, &guid ) )
            {
                DCAM_StreamMode_2.DataRange.SubFormat = guid;
            }
        }

        if ( ERROR_SUCCESS == RegQueryValueEx( hKey, L"StreamGuid3", 0, &dwType, (BYTE *)szGuid, &dwSize ) )
        {
            if ( REG_SZ == dwType
                 && ConvertStringToGuid( szGuid, &guid ) )
            {
                DCAM_StreamMode_3.DataRange.SubFormat = guid;
            }
        }

        if ( ERROR_SUCCESS == RegQueryValueEx( hKey, L"StreamGuid4", 0, &dwType, (BYTE *)szGuid, &dwSize ) )
        {
            if ( REG_SZ == dwType
                 && ConvertStringToGuid( szGuid, &guid ) )
            {
                DCAM_StreamMode_4.DataRange.SubFormat = guid;
            }
        }
/*
        if ( ERROR_SUCCESS == RegQueryValueEx( hKey, L"StreamGuid6", 0, &dwType, (BYTE *)szGuid, &dwSize ) )
        {
            if ( REG_SZ == dwType
                 && ConvertStringToGuid( szGuid, &guid ) )
            {
                DCAM_StreamMode_6.DataRange.SubFormat = guid;
            }
        }
*/
        RegCloseKey( hKey );
    }

    m_hCallerProcess = hCurrentProc;

    return TRUE;
}


//-----------------------------------------------------------------------------
//
// Function: UnBindApplicationProc

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -