Browse Source

avoid divided by zero error

The old code only checks touch->max_x > touch->min_x but not touch->max_x == touch->min_x. Thus may lead to divided by zero error.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1782 bbd45198-f89e-11dd-88c7-29a3b14d5316
chaos.proton@gmail.com 13 years ago
parent
commit
e803640027
1 changed files with 2 additions and 2 deletions
  1. 2 2
      bsp/stm32f10x/touch.c

+ 2 - 2
bsp/stm32f10x/touch.c

@@ -158,7 +158,7 @@ static void rtgui_touch_calculate()
             {
                 touch->x = (touch->x - touch->min_x) * X_WIDTH/(touch->max_x - touch->min_x);
             }
-            else
+            else if (touch->max_x < touch->min_x)
             {
                 touch->x = (touch->min_x - touch->x) * X_WIDTH/(touch->min_x - touch->max_x);
             }
@@ -167,7 +167,7 @@ static void rtgui_touch_calculate()
             {
                 touch->y = (touch->y - touch->min_y) * Y_WIDTH /(touch->max_y - touch->min_y);
             }
-            else
+            else if (touch->max_y < touch->min_y)
             {
                 touch->y = (touch->min_y - touch->y) * Y_WIDTH /(touch->min_y - touch->max_y);
             }