@@ -107,9 +107,9 @@ def run(self):
107107 font_size = image .string_size (btn_str )
108108
109109 while not app .need_exit ():
110+ img = self .cam .read ()
111+ touch_status = self .ts .read ()
110112 if self .status == Status .GET_RETANGLE :
111- img = self .cam .read ()
112- touch_status = self .ts .read ()
113113 if touch_status [2 ]: # Finger press detected
114114 if not pressing :
115115 target .x = touch_status [0 ]
@@ -141,8 +141,6 @@ def run(self):
141141 elif self .status == Status .DETECT :
142142 pitch_error = 0
143143 roll_error = 0
144- img = self .cam .read () # Reads an image frame.
145- touch_status = self .ts .read ()
146144 if touch_status [2 ]:
147145 self .status = Status .GET_RETANGLE
148146 img_w = img .width ()
@@ -158,7 +156,7 @@ def run(self):
158156
159157 print (b .cx (), b .cy ())
160158 for i in range (4 ):
161- img .draw_line (corners [i ][0 ], corners [i ][1 ], corners [(i + 1 ) % 4 ][0 ], corners [(i + 1 ) % 4 ][1 ], image .COLOR_RED )
159+ img .draw_line (corners [i ][0 ], corners [i ][1 ], corners [(i + 1 ) % 4 ][0 ], corners [(i + 1 ) % 4 ][1 ], image .COLOR_RED , 4 )
162160
163161 if obj_x != - 1 and obj_y != - 1 :
164162 center_x = img_w / 2
@@ -182,15 +180,14 @@ def run(self):
182180 app .set_exit_flag (True )
183181 break
184182
185- t = self .ts .read ()
186- img = img .resize (self .disp .width (), self .disp .height (), image .Fit .FIT_CONTAIN )
187- if self .check_touch_box (t , self .exit_box , 20 ):
188- img .draw_image (self .exit_box [0 ], self .exit_box [1 ], self .img_exit_touch )
189- self .need_exit = True
190- else :
191- img .draw_image (self .exit_box [0 ], self .exit_box [1 ], self .img_exit )
183+ img = img .resize (self .disp .width (), self .disp .height (), image .Fit .FIT_CONTAIN )
184+ if self .check_touch_box (touch_status , self .exit_box , 20 ):
185+ img .draw_image (self .exit_box [0 ], self .exit_box [1 ], self .img_exit_touch )
186+ self .need_exit = True
187+ else :
188+ img .draw_image (self .exit_box [0 ], self .exit_box [1 ], self .img_exit )
192189
193- self .disp .show (img )
190+ self .disp .show (img )
194191if __name__ == '__main__' :
195192 s = servos .Servos (SERVO_ID , SERVO_PORT_NAME , SERVO_BAUDRATE , SERVO_MIN_POSITION , SERVO_MAX_POSITION )
196193 pid_pitch = servos .PID (p = pitch_pid [0 ], i = pitch_pid [1 ], d = pitch_pid [2 ], imax = pitch_pid [3 ])
0 commit comments