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

📄 wmtouch.c

📁 pxa270平台 windows mobile 5.2 wm9713 触摸屏+音频驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    return WMS_SUCCESS;

error:
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMIsPenDown
 *
 * This function queries the device to determine whether the pen is currently
 * down.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_BOOL
 *      TRUE if the pen is down.
 *---------------------------------------------------------------------------*/
WM_BOOL WMIsPenDown( WM_DEVICE_HANDLE hDevice )
{
    WM_DEVICE_CONTEXT           *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
    WM_BOOL                     penDown;

    penDown = WMPlatformIsTouchGPIOSignalled( hDevice );
    if ( !penDown )
    {
        if ( pDeviceContext->v_pADCData->flags & WM_TOUCH_HISTORY_PEN_DOWN )
        {
            penDown = TRUE;
        }
        else
        {
            penDown = private_IsPenDebouncing( hDevice );
        }
    }
    return penDown;
}

/*-----------------------------------------------------------------------------
 * Function:    WMTouchStartCapture
 *
 * Called when pen down is detected - starts the timers.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMTouchStartCapture( WM_DEVICE_HANDLE hDevice )
{
    WMSTATUS    status;

    /* Check we've got AUX ADC */
    if ( !WM_IS_AUXADC_SUPPORTED( hDevice ) )
    {
        status = WMS_UNSUPPORTED;
        goto error0;
    }

    /*
     * Take the mutex.
     */
    if ( !WMLockGlobalData( hDevice ) )
    {
        status = WMS_LOCK_TIMED_OUT;
        goto error0;
    }

    /*
     * Tell the power stuff we've had pen detect.
     */
    status = WMTouchPowerUp( hDevice, WM_POWER_PEN_DETECTED );
    if ( WM_ERROR( status ) )
    {
        goto error1;
    }

    /* Set the ADC going */
    status = WMAuxADCStart( hDevice, WM_ADC_TOUCH );
    
    /* Clear stale points from the history buffer */
    private_ResetHistory( hDevice );

    /*
     * Let other threads in.
     */
    WMUnlockGlobalData( hDevice );

    return status;

error1:
    WMUnlockGlobalData( hDevice );

error0:
    return status;    
}

/*-----------------------------------------------------------------------------
 * Function:    WMTouchEndCapture
 *
 * Called when pen up is detected - cancels any outstanding timers and resets
 * pen down interrupts if appropriate.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
void WMTouchEndCapture( WM_DEVICE_HANDLE hDevice )
{
    /* Stop the ADC */
    WMAuxADCStop( hDevice, WM_ADC_TOUCH );

    /*
     * Tell the power stuff we've no longer got pen detected.
     */
    WMTouchPowerDown( hDevice, WM_POWER_PEN_DETECTED );
}

/*-----------------------------------------------------------------------------
 * Function:    WMGetSmoothedTouchCoordinates
 *
 * Returns the next touch panel point, after doing smoothing and averaging.
 *
 * ** NB Cannot be called at interrupt level. **
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *      pXCoord             Variable to receive X coordinate
 *      pYCoord             Variable to receive Y coordinate
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMGetSmoothedTouchCoordinates( WM_DEVICE_HANDLE  hDevice,
                                        WM_REGVAL         *pXCoord,
                                        WM_REGVAL         *pYCoord
                                      )
{
    WM_DEVICE_CONTEXT           *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
    WMSTATUS                    status;

    /* Check we've got AUX ADC */
    if ( !WM_IS_AUXADC_SUPPORTED( hDevice ) )
    {
        status = WMS_UNSUPPORTED;
        goto error0;
    }

    /*
     * Take the mutex.
     */
    if ( !WMLockGlobalData( hDevice ) )
    {
        status = WMS_LOCK_TIMED_OUT;
        goto error0;
    }

    /* Fill our points buffer */
    status = private_FillHistoryBuffer( hDevice );
    if ( WM_ERROR( status ) )
    {
        switch ( status )
        {
        case WMS_NO_DATA:
            /* 
             * Assume it's because the pen came up, and let the debounce logic
             * handle timing glitches.
             */
        case WMS_NO_PEN_DOWN:
            /*
             * We've got pen-up. Ignore the first few just in case it's a bounce.
             * The way we do this is to assume we are debouncing, and then call
             * private_IsPenDebouncing to check how long ago our last point was.
             * This will reset the debounce condition if we've passed our
             * debounce timeout.
             */
            pDeviceContext->v_pADCData->flags |= WM_TOUCH_HISTORY_DEBOUNCING;
            if ( !private_IsPenDebouncing( hDevice ) )
            {
                /*
                 * The pen's been up longer than our debounce period.
                 * It must really be up.
                 */
                pDeviceContext->v_pADCData->flags &=
                            ~(WM_TOUCH_HISTORY_PEN_DOWN|WM_TOUCH_HISTORY_DEBOUNCING);
                goto error1;
            }
            
            break;
            
        default:
            goto error1;
        }
    }
    else
    {
        /* It's a good point.  Reset our debounce flag */
        pDeviceContext->v_pADCData->flags &= ~WM_TOUCH_HISTORY_DEBOUNCING;
    }

    /* Now get the averaged point */
    status = private_GetAveragedCoordinates( hDevice, pXCoord, pYCoord );
    if ( WM_ERROR( status ) )
    {
        goto error1;
    }

    /*
     * Let other threads in.
     */
    WMUnlockGlobalData( hDevice );

    return WMS_SUCCESS;

error1:
    WMUnlockGlobalData( hDevice );
    
error0:
    *pXCoord = WM_INVALID_SAMPLE;
    *pYCoord = WM_INVALID_SAMPLE;
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMGetRawTouchCoordinates
 *
 * Returns the next touch panel point directly from the digitiser.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *      pXCoord             Variable to receive X coordinate
 *      pYCoord             Variable to receive Y coordinate
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMGetRawTouchCoordinates( WM_DEVICE_HANDLE   hDevice,
                                   WM_REGVAL          *pXCoord,
                                   WM_REGVAL          *pYCoord
                                 )
{
    WM_DEVICE_CONTEXT           *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
    WMSTATUS                    status;
    WM_REGVAL                   tmpX, tmpY;
    WM_BOOL                     penDown;
    WM_BOOL                     penWasDown;
    int                         penUpReject = 0;

    /* Check we've got AUX ADC */
    if ( !WM_IS_AUXADC_SUPPORTED( hDevice ) )
    {
        status = WMS_UNSUPPORTED;
        goto error0;
    }
    
    /*
     * Take the mutex.
     */
    if ( !WMLockGlobalData( hDevice ) )
    {
        status = WMS_LOCK_TIMED_OUT;
        goto error0;
    }

    /*
     * Now check if this is the pen going down, and deal with that.
     */
    penWasDown = pDeviceContext->v_pADCData->flags & 
                        (WM_TOUCH_HISTORY_PEN_DOWN|WM_TOUCH_HISTORY_DEBOUNCING);
    if ( !penWasDown )
    {
        /* WM_INCREMENT_COUNTER( pDeviceContext, TouchPenDowns ); */

        status = WMTouchStartCapture( hDevice );
        if ( WM_ERROR( status ) )
        {
            goto error1;
        }
        pDeviceContext->v_pADCData->flags |= WM_TOUCH_HISTORY_PEN_DOWN;
    }

    /*
     * Now get the raw points.  Note if the pen has just gone down,
     * there may be stale pen-up points in the FIFO, so keep reading
     * until we get WMS_NO_DATA instead of WMS_NO_PEN_DOWN (or, of
     * course, a good point).
     */
    do
    {
        status = WMSampleADC( hDevice, WM_ADC_X_COORD, &tmpX );
        if ( WM_SUCCESS( status ) || WMS_NO_PEN_DOWN == status )
        {
            WMSTATUS newStatus;

            /*
             * We need to read Y as well as X when doing pen rejection
             * to make sure we eat the stale pen-ups from Y as well.
             * However, we don't want to get a stale X point and have
             * a good Y point force it through, so we only succeed if
             * both succeed.
             */
            newStatus = WMSampleADC( hDevice, WM_ADC_Y_COORD, &tmpY );
            if ( WM_ERROR( newStatus ) )
            {
                status = newStatus;
            }
        }

        if ( WMS_NO_PEN_DOWN == status )
        {
            penUpReject++;
        }
    } while ( !penWasDown && WMS_NO_PEN_DOWN == status && penUpReject < 16 );

    /* WM_INCREMENT_COUNTER( pDeviceContext, TouchReadings ); */
    if ( WM_SUCCESS( status ) )
    {
        *pXCoord = tmpX;
        *pYCoord = tmpY;
        penDown = TRUE;
    }
    else
    {
        /* WM_INCREMENT_COUNTER( pDeviceContext, TouchErrors ); */
        
        if ( WMS_NO_PEN_DOWN == status )
        {
            penDown = FALSE;
        }
        else
        {
            penDown = WMIsPenDown( hDevice );
        }
    }

⌨️ 快捷键说明

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