CCS/CapTouch_Tuning/Library/CTS_Layer.c
/***************************************************************************/
/**
 * @ingroup CTS_support
 * @brief   Determine which element within a sensor has the largest response
 * 
 *          This function compares and normalizes the change in capacitance to
 *          determine which element has the dominant response.  The deltaCnt
 *          values for each element that exceed the threshold are also 
 *          converted from a 'raw' measurement to a percentage of the maximum 
 *          response.
 * @param   groupOfElements Pointer to buttons to be scanned
 * @param   deltaCnt Address to where the measurements are to be written
 * @return  result index to the element which is dominant
 ******************************************************************************/
@ingroup CTS_support
@brief   Determine which element within a sensor has the largest response

This function compares and normalizes the change in capacitance to
determine which element has the dominant response.  The deltaCnt
values for each element that exceed the threshold are also
converted from a 'raw' measurement to a percentage of the maximum
response.
@param   groupOfElements Pointer to buttons to be scanned
@param   deltaCnt Address to where the measurements are to be written
@return  result index to the element which is dominant
@ingroup CTS_support @brief Determine which element within a sensor has the largest response This function compares and normalizes the change in capacitance to determine which element has the dominant response . The deltaCnt values for each element that exceed the threshold are also converted from a ' raw ' measurement to a percentage of the maximum response . @param groupOfElements Pointer to buttons to be scanned @param deltaCnt Address to where the measurements are to be written @return result index to the element which is dominant
uint8_t Dominant_Element(const struct Sensor* groupOfElements, uint16_t* deltaCnt)
{
    uint8_t i;
    uint16_t percentDelta=0; 
    uint8_t dominantElement=0;
    for(i=0;i<groupOfElements->numElements;i++)
    {  
        if(deltaCnt[i]>=(groupOfElements->arrayPtr[i])->threshold)
        {
            if(deltaCnt[i] > ((groupOfElements->arrayPtr[i])->maxResponse))
            {
                deltaCnt[i] = (groupOfElements->arrayPtr[i])->maxResponse;
            }
            deltaCnt[i] = (100*(deltaCnt[i]
                           -(groupOfElements->arrayPtr[i])->threshold))
            		         /((groupOfElements->arrayPtr[i])->maxResponse
            				    -(groupOfElements->arrayPtr[i])->threshold);
            if(deltaCnt[i] >= percentDelta)
            {
                percentDelta = deltaCnt[i];
                dominantElement = i;
            }
        }
        else
        {
            deltaCnt[i] = 0;
        }
    } 
    return dominantElement;
}
uint8_t Dominant_Element ( const struct Sensor * groupOfElements , uint16_t * deltaCnt ) { uint8_t i ; uint16_t percentDelta = 0 ; uint8_t dominantElement = 0 ; for ( i = 0 ; i < groupOfElements -> numElements ; i ++ ) { if ( deltaCnt [ i ] >= ( groupOfElements -> arrayPtr [ i ] ) -> threshold ) { if ( deltaCnt [ i ] > ( ( groupOfElements -> arrayPtr [ i ] ) -> maxResponse ) ) { deltaCnt [ i ] = ( groupOfElements -> arrayPtr [ i ] ) -> maxResponse ; } deltaCnt [ i ] = ( 100 * ( deltaCnt [ i ] - ( groupOfElements -> arrayPtr [ i ] ) -> threshold ) ) / ( ( groupOfElements -> arrayPtr [ i ] ) -> maxResponse - ( groupOfElements -> arrayPtr [ i ] ) -> threshold ) ; if ( deltaCnt [ i ] >= percentDelta ) { percentDelta = deltaCnt [ i ] ; dominantElement = i ; } } else { deltaCnt [ i ] = 0 ; } } return dominantElement ; }
@ingroup CTS_support
 @brief   Determine which element within a sensor has the largest response
@ingroup CTS_support @brief Determine which element within a sensor has the largest response
// limit response to the maximum // (maxResponse - threshold) cannot exceed 655 // 100*(delta - threshold) / (maxResponse - threshold) //update percentDelta // end for loop