//***************************************************************************** // //! Debounces presses of the touch screen. //! //! This function is called when a new X/Y sample pair has been captured in //! order to perform debouncing of the touch screen. //! //! \return None. // //***************************************************************************** static void TouchScreenDebouncer(void) { long lX, lY, lTemp; // // Convert the ADC readings into pixel values on the screen. // lX = g_sTouchX; lY = g_sTouchY; lTemp = (((lX * g_plParmSet[0]) + (lY * g_plParmSet[1]) + g_plParmSet[2]) / g_plParmSet[6]); lY = (((lX * g_plParmSet[3]) + (lY * g_plParmSet[4]) + g_plParmSet[5]) / g_plParmSet[6]); lX = lTemp; // // See if the touch screen is being touched. // if((g_sTouchX < g_sTouchMin) || (g_sTouchY < g_sTouchMin)) { // // See if the pen is not up right now. // if(g_cState != 0x00) { // // Decrement the state count. // g_cState--; // // See if the pen has been detected as up three times in a row. // if(g_cState == 0x80) { // // Indicate that the pen is up. // g_cState = 0x00; // // See if there is a touch screen event handler. // if(g_pfnTSHandler) { // // Send the pen up message to the touch screen event // handler. // g_pfnTSHandler(WIDGET_MSG_PTR_UP, g_psSamples[g_cIndex], g_psSamples[g_cIndex + 1]); } } } } else { // // See if the pen is not down right now. // if(g_cState != 0x83) { // // Increment the state count. // g_cState++; // // See if the pen has been detected as down three times in a row. // if(g_cState == 0x03) { // // Indicate that the pen is up. // g_cState = 0x83; // // Set the index to -8, so that the next 3 samples are stored // into the sample buffer before sending anything back to the // touch screen event handler. // g_cIndex = -8; // // Store this sample into the sample buffer. // g_psSamples[0] = lX; g_psSamples[1] = lY; } } else { // // See if the sample buffer pre-fill has completed. // if(g_cIndex == -2) { // // See if there is a touch screen event handler. // if(g_pfnTSHandler) { // // Send the pen down message to the touch screen event // handler. // g_pfnTSHandler(WIDGET_MSG_PTR_DOWN, g_psSamples[0], g_psSamples[1]); } // // Store this sample into the sample buffer. // g_psSamples[0] = lX; g_psSamples[1] = lY; // // Set the index to the next sample to send. // g_cIndex = 2; } // // Otherwise, see if the sample buffer pre-fill is in progress. // else if(g_cIndex < 0) { // // Store this sample into the sample buffer. // g_psSamples[g_cIndex + 10] = lX; g_psSamples[g_cIndex + 11] = lY; // // Increment the index. // g_cIndex += 2; } // // Otherwise, the sample buffer is full. // else { // // See if there is a touch screen event handler. // if(g_pfnTSHandler) { // // Send the pen move message to the touch screen event // handler. // g_pfnTSHandler(WIDGET_MSG_PTR_MOVE, g_psSamples[g_cIndex], g_psSamples[g_cIndex + 1]); } // // Store this sample into the sample buffer. // g_psSamples[g_cIndex] = lX; g_psSamples[g_cIndex + 1] = lY; // // Increment the index. // g_cIndex = (g_cIndex + 2) & 7; } } } }
//***************************************************************************** // //! Debounces presses of the touch screen. //! //! This function is called when a new X/Y sample pair has been captured in //! order to perform debouncing of the touch screen. //! //! \return None. // //***************************************************************************** static void TouchScreenDebouncer(void) { int32_t i32X, i32Y, i32Temp; // // Convert the ADC readings into pixel values on the screen. // i32X = g_i16TouchX; i32Y = g_i16TouchY; i32Temp = (((i32X * g_pi32TouchParameters[0]) + (i32Y * g_pi32TouchParameters[1]) + g_pi32TouchParameters[2]) / g_pi32TouchParameters[6]); i32Y = (((i32X * g_pi32TouchParameters[3]) + (i32Y * g_pi32TouchParameters[4]) + g_pi32TouchParameters[5]) / g_pi32TouchParameters[6]); i32X = i32Temp; // // See if the touch screen is being touched. // if((g_i16TouchX < g_i16TouchMin) || (g_i16TouchY < g_i16TouchMin)) { // // If there are no valid values yet then ignore this state. // if((g_ui8State & 0x80) == 0) { g_ui8State = 0; } // // See if the pen is not up right now. // if(g_ui8State != 0x00) { // // Decrement the state count. // g_ui8State--; // // See if the pen has been detected as up three times in a row. // if(g_ui8State == 0x80) { // // Indicate that the pen is up. // g_ui8State = 0x00; // // See if there is a touch screen event handler. // if(g_pfnTSHandler) { // // If we got caught pre-filling the values, just return the // first valid value as a press and release. If this is // not done there is a perceived miss of a press event. // if(g_i8Index < 0) { g_pfnTSHandler(WIDGET_MSG_PTR_DOWN, g_pi16Samples[0], g_pi16Samples[1]); g_i8Index = 0; } // // Send the pen up message to the touch screen event // handler. // g_pfnTSHandler(WIDGET_MSG_PTR_UP, g_pi16Samples[g_i8Index], g_pi16Samples[g_i8Index + 1]); } } } } else { // // If the state was counting down above then fall back to the idle // state and start waiting for new values. // if((g_ui8State & 0x80) && (g_ui8State != 0x83)) { // // Restart the release count down. // g_ui8State = 0x83; } // // See if the pen is not down right now. // if(g_ui8State != 0x83) { // // Increment the state count. // g_ui8State++; // // See if the pen has been detected as down three times in a row. // if(g_ui8State == 0x03) { // // Indicate that the pen is down. // g_ui8State = 0x83; // // Set the index to -8, so that the next 3 samples are stored // into the sample buffer before sending anything back to the // touch screen event handler. // g_i8Index = -8; // // Store this sample into the sample buffer. // g_pi16Samples[0] = i32X; g_pi16Samples[1] = i32Y; } } else { // // See if the sample buffer pre-fill has completed. // if(g_i8Index == -2) { // // See if there is a touch screen event handler. // if(g_pfnTSHandler) { // // Send the pen down message to the touch screen event // handler. // g_pfnTSHandler(WIDGET_MSG_PTR_DOWN, g_pi16Samples[0], g_pi16Samples[1]); } // // Store this sample into the sample buffer. // g_pi16Samples[0] = i32X; g_pi16Samples[1] = i32Y; // // Set the index to the next sample to send. // g_i8Index = 2; } // // Otherwise, see if the sample buffer pre-fill is in progress. // else if(g_i8Index < 0) { // // Store this sample into the sample buffer. // g_pi16Samples[g_i8Index + 10] = i32X; g_pi16Samples[g_i8Index + 11] = i32Y; // // Increment the index. // g_i8Index += 2; } // // Otherwise, the sample buffer is full. // else { // // See if there is a touch screen event handler. // if(g_pfnTSHandler) { // // Send the pen move message to the touch screen event // handler. // g_pfnTSHandler(WIDGET_MSG_PTR_MOVE, g_pi16Samples[g_i8Index], g_pi16Samples[g_i8Index + 1]); } // // Store this sample into the sample buffer. // g_pi16Samples[g_i8Index] = i32X; g_pi16Samples[g_i8Index + 1] = i32Y; // // Increment the index. // g_i8Index = (g_i8Index + 2) & 7; } } } }