新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 如何編寫Windows CE.net的usb驅動程序(2)

        如何編寫Windows CE.net的usb驅動程序(2)

        作者: 時間:2012-05-02 來源:網絡 收藏

        m_pInterface->lpEndpoints[0].Descriptor.bmAttributes));

        returnFALSE;

        }

        DEBUGMSG(ZONE_INIT,(TEXT(USBMouse:EP0:MaxPacket:%u,Interval:%urn),

        m_pInterface->lpEndpoints[0].Descriptor.wMaxPacketSize,

        m_pInterface->lpEndpoints[0].Descriptor.bInterval));

        m_hInterruptPipe=(*m_lpUsbFuncs->lpOpenPipe)(m_hDevice,

        m_pInterface->lpEndpoints[0].Descriptor);

        if(m_hInterruptPipe==NULL){

        RETAILMSG(1,(TEXT(Mouse:Erroropeninginterruptpipern)));

        return(FALSE);

        }

        m_hEvent=CreateEvent(NULL,FALSE,FALSE,NULL);

        if(m_hEvent==NULL)

        {

        RETAILMSG(1,(TEXT(USBMouse:ErroronCreateEventforconnecteventrn)));

        return(FALSE);

        }

        //創建數據接受線程

        m_hThread=CreateThread(0,0,MouseThreadStub,this,0,NULL);

        if(m_hThread==NULL)

        {

        RETAILMSG(1,(TEXT(USBMouse:ErroronCreateThreadrn)));

        return(FALSE);

        }

        return(TRUE);

        }

        //從USB鼠標設備中讀出數據,產生相應的鼠標事件。

        BOOLCMouse::SubmitInterrupt()

        {

        if(m_hInterruptTransfer)

        (*m_lpUsbFuncs->lpCloseTransfer)(m_hInterruptTransfer);

        //從USB鼠標PIPE中讀數據

        m_hInterruptTransfer=(*m_lpUsbFuncs->lpIssueInterruptTransfer)

        (m_hInterruptPipe,MouseTransferCompleteStub,this,

        USB_IN_TRANSFER|USB_SHORT_TRANSFER_OK,//表示讀數據

        min(m_pInterface->lpEndpoints[0].Descriptor.wMaxPacketSize,

        sizeof(m_pbDataBuffer)),

        m_pbDataBuffer,

        NULL);

        if(m_hInterruptTransfer==NULL)

        {

        DEBUGMSG(ZONE_ERROR,(L!USBMouse:ErrorinIssueInterruptTransferrn));

        returnFALSE;

        }

        else

        {

        DEBUGMSG(ZONE_TRANSFER,(LUSBMouse::SubmitInterrupt,Transfer:0x%Xrn,

        m_hInterruptTransfer));

        }

        returnTRUE;

        }

        //處理鼠標中斷傳輸的數據

        BOOLCMouse::HandleInterrupt()

        {

        DWORDdwError;

        DWORDdwBytes;

        DWORDdwFlags=0;

        INTdx=(signedchar)m_pbDataBuffer[1];

        INTdy=(signedchar)m_pbDataBuffer[2];

        BOOLfButton1=m_pbDataBuffer[0]0x01?TRUE:FALSE;

        BOOLfButton2=m_pbDataBuffer[0]0x02?TRUE:FALSE;

        BOOLfButton3=m_pbDataBuffer[0]0x04?TRUE:FALSE;

        if(!(*m_lpUsbFuncs->lpGetTransferStatus)(m_hInterruptTransfer,dwBytes,dwError))

        {

        DEBUGMSG(ZONE_ERROR,(TEXT(!USBMouse:ErrorinGetTransferStatus(0x%X)rn),

        m_hInterruptTransfer));

        returnFALSE;

        }

        else

        {

        DEBUGMSG(ZONE_TRANSFER,(TEXT(USBMouse::HandleInterrupt,hTransfer0x%Xcomplete(%ubytes,Error:%X)rn),

        m_hInterruptTransfer,dwBytes,dwError));

        }

        if(!SubmitInterrupt())

        returnFALSE;

        if(dwError!=USB_NO_ERROR)

        {

        DEBUGMSG(ZONE_ERROR,(TEXT(!USBMouse:Error0x%Xininterrupttransferrn),dwError));

        returnTRUE;

        }

        if(dwBytes3)

        {

        DEBUGMSG(ZONE_ERROR,(TEXT(!USBMouse:Invalidbytecnt%ufrominterrupttransferrn),dwBytes));

        returnTRUE;

        }

        if(dx||dy)

        dwFlags|=MOUSEEVENTF_MOVE;

        if(fButton1!=m_fPrevButton1)

        {

        if(fButton1)

        dwFlags|=MOUSEEVENTF_LEFTDOWN;

        else

        dwFlags|=MOUSEEVENTF_LEFTUP;

        }

        if(fButton2!=m_fPrevButton2)

        {

        if(fButton2)

        dwFlags|=MOUSEEVENTF_RIGHTDOWN;

        else

        dwFlags|=MOUSEEVENTF_RIGHTUP;

        }

        if(fButton3!=m_fPrevButton3)

        {

        if(fButton3)

        dwFlags|=MOUSEEVENTF_MIDDLEDOWN;

        else

        dwFlags|=MOUSEEVENTF_MIDDLEUP;

        }

        m_fPrevButton1=fButton1;

        m_fPrevButton2=fButton2;

        m_fPrevButton3=fButton3;

        DEBUGMSG(ZONE_EVENTS,

        (TEXT(USBMouseevent:dx:%d,dy:%d,dwFlags:0x%X(B1:%u,B2:%u,B3:%u)rn),

        dx,dy,dwFlags,fButton1,fButton2,fButton3));

        //通知系統產生鼠標事件

        if(m_fReadyForMouseEvents)

        mouse_event(dwFlags,dx,dy,0,0);

        else

        m_fReadyForMouseEvents=IsAPIReady(SH_WMGR);

        returnTRUE;

        }

        DWORDCALLBACKCMouse::MouseTransferCompleteStub(LPVOIDlpvNotifyParameter)

        {

        CMouse*pMouse=(CMouse*)lpvNotifyParameter;

        return(pMouse->MouseTransferComplete());

        }

        //數據傳輸完畢回調函數

        DWORDCMouse::MouseTransferComplete()

        {

        if(m_hEvent)

        SetEvent(m_hEvent);

        return0;

        }

        ULONGCALLBACKCMouse::MouseThreadStub(PVOIDcontext)

        {

        CMouse*pMouse=(CMouse*)context;

        return(pMouse->MouseThread());

        }

        //USB鼠標線程

        DWORDCMouse::MouseThread()

        {

        DEBUGMSG(ZONE_INIT,(TEXT(USBMouse:Workerthreadstartedrn)));

        SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_HIGHEST);



        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 江都市| 灵台县| 万荣县| 东港市| 龙南县| 凯里市| 资源县| 即墨市| 德化县| 徐水县| 古浪县| 天峨县| 内乡县| 财经| 德化县| 光山县| 昭通市| 巴林右旗| 舟曲县| 响水县| 湖北省| 平乡县| 芜湖市| 夹江县| 横山县| 庄河市| 全南县| 永城市| 中牟县| 乐陵市| 河池市| 泌阳县| 镇赉县| 磐石市| 河间市| 吴川市| 信阳市| 西城区| 个旧市| 太和县| 万全县|