Explorar el Código

【修改】屏幕的最大坐标大小由宏控制

SummerGift hace 6 años
padre
commit
4eb8632ef1
Se han modificado 1 ficheros con 9 adiciones y 7 borrados
  1. 9 7
      port/machine_lcd.c

+ 9 - 7
port/machine_lcd.c

@@ -35,6 +35,8 @@
 #include "machine_lcd.h"
 #include <drv_lcd.h>
 
+#define MAX_CO (240 - 1)
+
 typedef struct _machine_lcd_obj_t {
     mp_obj_base_t base;
 } machine_lcd_obj_t;
@@ -97,7 +99,7 @@ STATIC mp_obj_t machine_lcd_pixel(size_t n_args, const mp_obj_t *args) {
     int x = mp_obj_get_int(args[1]);
     int y = mp_obj_get_int(args[2]);
     
-    error_check((x >= 0 && x <= 239) && (y >= 0 && y <= 239) , "The min/max X/Y coordinates is 0/239");
+    error_check((x >= 0 && x <= MAX_CO) && (y >= 0 && y <= MAX_CO) , "The min/max X/Y coordinates is 0/239");
 
     int col = mp_obj_get_int(args[3]);
     lcd_draw_point_color(x, y, col);
@@ -119,7 +121,7 @@ STATIC mp_obj_t machine_lcd_text(size_t n_args, const mp_obj_t *args) {
     int y = mp_obj_get_int(args[3]);
     int size = mp_obj_get_int(args[4]);
     
-    error_check((x >= 0 && x <= 239) && (y >= 0 && y <= 239) , "The min/max X/Y coordinates is 0/239");
+    error_check((x >= 0 && x <= MAX_CO) && (y >= 0 && y <= MAX_CO) , "The min/max X/Y coordinates is 0/239");
     
     error_check(size == 16 || size == 24 || size == 32, "lcd only support font size 16 24 32");
     
@@ -142,8 +144,8 @@ STATIC mp_obj_t machine_lcd_line(size_t n_args, const mp_obj_t *args) {
     int x2 = mp_obj_get_int(args[3]);
     int y2 = mp_obj_get_int(args[4]);
     
-    error_check((x1 >= 0 && x1 <= 239) && (y1 >= 0 && y1 <= 239) , "The min/max X/Y coordinates is 0/239");
-    error_check((x2 >= 0 && x2 <= 239) && (y2 >= 0 && y2 <= 239) , "The min/max X/Y coordinates is 0/239");
+    error_check((x1 >= 0 && x1 <= MAX_CO) && (y1 >= 0 && y1 <= MAX_CO) , "The min/max X/Y coordinates is 0/239");
+    error_check((x2 >= 0 && x2 <= MAX_CO) && (y2 >= 0 && y2 <= MAX_CO) , "The min/max X/Y coordinates is 0/239");
 
     lcd_draw_line(x1, y1, x2, y2);
     return mp_const_none;
@@ -163,8 +165,8 @@ STATIC mp_obj_t machine_lcd_rectangle(size_t n_args, const mp_obj_t *args) {
     int x2 = mp_obj_get_int(args[3]);
     int y2 = mp_obj_get_int(args[4]);
 
-    error_check((x1 >= 0 && x1 <= 239) && (y1 >= 0 && y1 <= 239) , "The min/max X/Y coordinates is 0/239");
-    error_check((x2 >= 0 && x2 <= 239) && (y2 >= 0 && y2 <= 239) , "The min/max X/Y coordinates is 0/239");
+    error_check((x1 >= 0 && x1 <= MAX_CO) && (y1 >= 0 && y1 <= MAX_CO) , "The min/max X/Y coordinates is 0/239");
+    error_check((x2 >= 0 && x2 <= MAX_CO) && (y2 >= 0 && y2 <= MAX_CO) , "The min/max X/Y coordinates is 0/239");
 
     lcd_draw_rectangle(x1, y1, x2, y2);
     return mp_const_none;
@@ -183,7 +185,7 @@ STATIC mp_obj_t machine_lcd_circle(size_t n_args, const mp_obj_t *args) {
     int y1 = mp_obj_get_int(args[2]);
     int r  = mp_obj_get_int(args[3]);
 
-    error_check((x1 >= 0 && x1 <= 239) && (y1 >= 0 && y1 <= 239) , "The min/max X/Y coordinates is 0/239");
+    error_check((x1 >= 0 && x1 <= MAX_CO) && (y1 >= 0 && y1 <= MAX_CO) , "The min/max X/Y coordinates is 0/239");
 
     lcd_draw_circle(x1, y1, r);
     return mp_const_none;