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

📄 vibdrvr_pdd.cpp

📁 Freescale ARM11系列CPU MX31的WINCE 5.0下的BSP
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        ret = FALSE;    //invalid get info code
    }

#ifdef DEBUG
    VibratorDriverDebugPrintOut();
#endif  // DEBUG  

        DEBUGMSG(ZONE_PDD, (_T("-VibratorDriverGetDeviceInfo\r\n")));
        
        return (ret);
}

//-----------------------------------------------------------------------------
//
// Function: VibratorDriverSetDevice
//
// This routine changes the configuration of an Vibrator.  The nInfoId parameter
// indicates what kind of configuration information is being changed.  
// Currently only the NLED_SETTINGS_INFO_ID value is supported.  The pInput
// parameter points to a buffer containing the data to be updated.  The size
// of the buffer depends on the value of nInfoId.
//
// Parameters:
//      InputParm 
//          [in] INT        nInfoId
//          [in] PVOID  pInput
//
// Returns:  
//      This routine returns TRUE if successful, or FALSE if there's a problem
//
//-----------------------------------------------------------------------------
BOOL WINAPI VibratorDriverSetDevice(INT     nInfoId, PVOID   pInput)
{
        DEBUGMSG(ZONE_PDD, (_T("+VibratorDriverSetDevice\r\n")));   
        RETAILMSG(1, (_T("+VibratorDriverSetDevice\r\n")));

    BOOL ret = TRUE;
    HANDLE hthread = NULL;  
    struct VIB_SETTINGS_INFO *p = (struct VIB_SETTINGS_INFO*)pInput;

    if(g_bThreadActive) //Check if a thread is running
    {
        SetEvent(g_hStopThreadEvent);
        WaitForSingleObject(g_hThreadStoppedEvent, INFINITE);
    }

    g_VibSettings.OffOnCycles = p->OffOnCycles;

    if(!g_VibSettings.OffOnCycles) //Vibrator off
    {
        if(g_bVibratorOn)
        {   
                if(g_pPmicVoltageRegulatorOff(V_VIB) != PMIC_SUCCESS)               
            {   
                DEBUGMSG(ZONE_PDD, (_T("VibratorDriverSetDevice: g_pPmicVibratorOff() Failed\r\n")));
                ret = FALSE;
                goto setdevice_err;
            }   
            g_bVibratorOn = FALSE;
        }   
    }
    else if(g_VibSettings.OffOnCycles == 1) //Vibrator on
    {
        g_VibSettings.OutputVoltage = p->OutputVoltage;
            
        if(!g_bVibratorOn)  
        {
            if(g_pPmicVoltageRegulatorSetVoltageLevel(V_VIB, g_VibSettings.OutputVoltage) != PMIC_SUCCESS)              
            {
                DEBUGMSG(ZONE_PDD, (_T("VibratorDriverSetDevice: g_pPmicVibratorOn() Failed\r\n")));
                ret = FALSE;
                goto setdevice_err;
            }
            if(g_pPmicVoltageRegulatorOn(V_VIB) != PMIC_SUCCESS)                
            {
                DEBUGMSG(ZONE_PDD, (_T("VibratorDriverSetDevice: g_pPmicVibratorOn() Failed\r\n")));
                ret = FALSE;
                goto setdevice_err;
            }
            g_bVibratorOn = TRUE;
        }   
    }
    else if(g_VibSettings.OffOnCycles == 2) //Vibrator cycles
    {       
        g_VibSettings.OutputVoltage = p->OutputVoltage;
        g_VibSettings.OnCycleTime = p->OnCycleTime;
        g_VibSettings.OffCyleTime = p->OffCyleTime;

        hthread =   CreateThread    (
                                    NULL,                                   // Default thread security descriptor
                                0,                                          // Default stack size
                                VibratorDriverSetDeviceThread,  // Start routine
                                &g_VibSettings,                         // Start routine parameter
                                0,                                          // Run immediately
                                NULL                                        // Thread ID
                                        );

        if (hthread == NULL)
            {
            ret = FALSE;
            goto setdevice_err;
            }
        
        CloseHandle(hthread);   
    }

#ifdef DEBUG
    VibratorDriverDebugPrintOut();
#endif  // DEBUG
    
setdevice_err:      
        RETAILMSG(1, (_T("-VibratorDriverSetDevice\r\n")));
        DEBUGMSG(ZONE_PDD, (_T("-VibratorDriverSetDevice\r\n")));
    
        return ret;
}

//-----------------------------------------------------------------------------
//
// Function: VibratorDriverPowerDown
//
// This routine is invoked by the driver MDD when the system suspends or
// resumes.  The power_down flag indicates whether the system is powering 
// up or powering down.
//
// Parameters:
//      InputParm 
//          [in] BOOL power_down
//
// Returns:  
//          None
//
//-----------------------------------------------------------------------------
VOID WINAPI VibratorDriverPowerDown(BOOL power_down)
{
        DEBUGMSG(ZONE_PDD, (_T("+VibratorDriverPowerDown\r\n")));
        RETAILMSG(1, (_T("+VibratorDriverPowerDown\r\n")));

    if(!power_down)
    {               
        if(g_bVibratorOn) 
        {   
            if(g_pPmicVoltageRegulatorSetVoltageLevel(V_VIB, g_VibSettings.OutputVoltage) != PMIC_SUCCESS)
            {   
                DEBUGMSG(ZONE_PDD, (_T("VibratorDriverPowerDown: g_pPmicVibratorOn() Failed\r\n")));
            }   
            if(g_pPmicVoltageRegulatorOn(V_VIB) != PMIC_SUCCESS)
            {   
                DEBUGMSG(ZONE_PDD, (_T("VibratorDriverPowerDown: g_pPmicVibratorOn() Failed\r\n")));
            }   
        }   
    }
    else
    {
        if(g_bVibratorOn) 
        {   
            if(g_pPmicVoltageRegulatorOff(V_VIB) != PMIC_SUCCESS)
            {   
                DEBUGMSG(ZONE_PDD, (_T("VibratorDriverPowerDown: g_pPmicVibratorOff() Failed\r\n")));
            }   
        }   
    }

        RETAILMSG(1, (_T("-VibratorDriverPowerDown\r\n")));
        DEBUGMSG(ZONE_PDD, (_T("-VibratorDriverPowerDown\r\n")));
        
        return;
}

//-----------------------------------------------------------------------------
//
// Function: VibratorDriverSetDeviceThread
//
// This routine is invoked by CreateThread() function in VibratorDriverSetDevice when
// caller attempts to change the configuration of Vibrator
//
// Parameters:
//      InputParm 
//          [in] LPVOID lParam
//
// Returns:  
//      This routine returns 0
//
//-----------------------------------------------------------------------------
DWORD WINAPI VibratorDriverSetDeviceThread(LPVOID lParam)
{   
    g_bThreadActive = TRUE;

    DEBUGMSG(ZONE_PDD, (_T("+VibratorDriverSetDeviceThread\r\n")));
    RETAILMSG(1, (_T("+VibratorDriverSetDeviceThread\r\n")));
        
    VIB_SETTINGS_INFO *p = (struct VIB_SETTINGS_INFO*)lParam;

    while(1)
    {       
        if(g_pPmicVoltageRegulatorOn(V_VIB) == PMIC_SUCCESS)
                    g_bVibratorOn = TRUE;
        else
        {   
            DEBUGMSG(ZONE_PDD, (_T("VibratorDriverSetDeviceThread: g_pPmicVibratorOn() Failed\r\n")));
        }
                
        if(WaitForSingleObject(g_hStopThreadEvent, p->OnCycleTime) == WAIT_OBJECT_0)        
        {   
            if(g_pPmicVoltageRegulatorOff(V_VIB) == PMIC_SUCCESS)
                g_bVibratorOn = FALSE;
            else
            {   
                DEBUGMSG(ZONE_PDD, (_T("VibratorDriverSetDeviceThread: g_pPmicVibratorOff() Failed\r\n")));
            }
            break;
        }   

        if(g_pPmicVoltageRegulatorOn(V_VIB) == PMIC_SUCCESS)
            g_bVibratorOn = FALSE;
        else    
        {   
            DEBUGMSG(ZONE_PDD, (_T("VibratorDriverSetDeviceThread: g_pPmicVibratorOff() Failed\r\n")));                 
        }
        
        if(WaitForSingleObject(g_hStopThreadEvent, p->OffCyleTime) == WAIT_OBJECT_0)        
            break;
    }

    RETAILMSG(1, (_T("-VibratorDriverSetDeviceThread\r\n")));   
        DEBUGMSG(ZONE_PDD, (_T("-VibratorDriverSetDeviceThread\r\n")));

    SetEvent(g_hThreadStoppedEvent);    
    g_bThreadActive = FALSE;    
    return 0;
}

//-----------------------------------------------------------------------------
//
// Function: VibratorDriverDebugPrintOut
//
// This routine is called in VibratorDriverInitialize(),  VibratorDriverGetDeviceInfo() & 
// VibratorDriverSetDevice to print out debug contents in g_VibSupports & g_VibSettings 
// structures
//
// Parameters:
//      None
//
// Returns:  
//      None
//
//-----------------------------------------------------------------------------
#ifdef DEBUG
void WINAPI VibratorDriverDebugPrintOut(void)
{
    DEBUGMSG(ZONE_PDD, (_T("+VibratorDriverDebugPrintOut\r\n")));
    RETAILMSG(1, (_T("+VibratorDriverDebugPrintOut\r\n")));

    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: Vibrator Driver SUPPORTS Information\r\n")));
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: AdjustTotalCycleTime=%d\r\n"), g_VibSupports.AdjustTotalCycleTime));
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: AdjustOffCycleTime=%d\r\n"), g_VibSupports.AdjustOffCycleTime));
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: AdjustOnCyleTime=%d\r\n"), g_VibSupports.AdjustOnCyleTime));
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: MetaCycleOff=%d\r\n"), g_VibSupports.MetaCycleOff));
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: MetaCycleOn=%d\r\n"), g_VibSupports.MetaCycleOn));           
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: Vibrator Driver SETTINGS Information\r\n")));
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: OutputVoltage=%d\r\n"), g_VibSettings.OutputVoltage));
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: OffOnCycles=%d\r\n"), g_VibSettings.OffOnCycles));
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: MetaCycleOff=%d\r\n"), g_VibSettings.MetaCycleOff));
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: MetaCycleOn=%d\r\n"), g_VibSettings.MetaCycleOn));
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: OffCyleTime=%d\r\n"), g_VibSettings.OffCyleTime));
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: OnCycleTime=%d\r\n"), g_VibSettings.OnCycleTime));
    RETAILMSG(1, (_T("VibratorDriverDebugPrintOut: TotalCycleTime=%d\r\n"), g_VibSettings.TotalCycleTime));
                                                
    RETAILMSG(1, (_T("-VibratorDriverDebugPrintOut\r\n")));
        DEBUGMSG(ZONE_PDD, (_T("-VibratorDriverDebugPrintOut\r\n")));
        
    return;
}
#endif  // DEBUG

⌨️ 快捷键说明

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