This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

哪位高手能解释一下触摸板例程里GetGesture这个函数呀



这个函数看不懂是什么意思,谁能给解释一下呀,不胜感激


unsigned char GetGesture(unsigned char wheel_position)
{
unsigned char gesture = INVALID_GESTURE, direction, ccw_check, cw_check;
// ******************************************************************************
// gesturing
// determine if a direction/swipe is occuring
// the difference between the initial position and
// the current wheel position should not exceed 8
// 0-1-2-3-4-5-6-7-8-9-A-B-C-D-E-F-0...
//
// E-F-0-1-2: cw, 4
// 2-1-0-F-E: ccw, 4
// A-B-C-D-E-F

//if(initial_wheel_position == INVALID_WHEEL_POSITION)
//{
//gesture = 0;
//initial_wheel_position = wheel_position;
//}
//else

if(last_wheel_position != ILLEGAL_SLIDER_WHEEL_POSITION)
{
if(last_wheel_position > wheel_position)
{
// E-D-C-B-A: ccw, 4
// counter clockwise: 0 < (init_wheel_position - wheel_position) < 8
// gesture = init_wheel_position - wheel_position
//
// E-F-0-1-2: cw, 4
// clockwise: 0 < (init_wheel_position+wheel_position)-16 <8
//
ccw_check = last_wheel_position - wheel_position;
if(ccw_check < 8)
{
gesture = ccw_check;
direction = COUNTER_CLOCKWISE;
}
else
{
// E-F-0-1-2: cw, 4
// 16 - 14 + 2 = 4
cw_check = 16 - last_wheel_position + wheel_position ;
if(cw_check < 8)
{
gesture = cw_check;
direction = CLOCKWISE;
}
}
}
else
{
// initial_wheel_position <= wheel_position
//
// 2-1-0-F-E: ccw, 4
// counter clockwise:
// 0 < (init_wheel_position+wheel_position)-16 <8
// gesture = init_wheel_position - wheel_position
//
// 0-1-2-3-4: cw, 4
// clockwise: 0 < (wheel_position - init_wheel_position) < 8
//
cw_check = wheel_position - last_wheel_position ;
if(cw_check < 8)
{
gesture = cw_check;
direction = CLOCKWISE;
}
else
{
// 2-1-0-F-E: ccw, 4
// 16 + 2 - 14 = 4
ccw_check = 16 + last_wheel_position - wheel_position ;
if(ccw_check < 8)
{
gesture = ccw_check;
direction = COUNTER_CLOCKWISE;
}
}
}
}
if (gesture == INVALID_GESTURE)
return gesture;
if (direction == COUNTER_CLOCKWISE)
return (gesture + 16);
else
return gesture;
}