3131LCD_CS = 15
3232LCD_BL = 48
3333
34+ I2C_FREQ = 400000
35+
3436# Display resolution
3537TFT_HOR_RES = 320
3638TFT_VER_RES = 240
7678mpos .ui .main_display .set_backlight (100 )
7779
7880# Touch handling
79- try :
80- import i2c
81- i2c_bus = i2c .I2C .Bus (host = 0 , scl = 38 , sda = 39 )
82- import mpos .indev .gt911 as gt911
83- touch_dev = i2c .I2C .Device (bus = i2c_bus , dev_id = gt911 .I2C_ADDR , reg_bits = gt911 .BITS )
84- indev = gt911 .GT911 (touch_dev , reset_pin = 1 , interrupt_pin = 40 , debug = False ) # debug makes it slower
85- from mpos import InputManager
86- InputManager .register_indev (indev )
87- except Exception as e :
88- print (f"Touch init got exception: { e } " )
81+ def init_touch ():
82+ try :
83+ import i2c
84+ i2c_bus = i2c .I2C .Bus (host = 0 , scl = 38 , sda = 39 , freq = I2C_FREQ , use_locks = False )
85+ import mpos .indev .gt911 as gt911
86+ touch_dev = i2c .I2C .Device (bus = i2c_bus , dev_id = gt911 .I2C_ADDR , reg_bits = gt911 .BITS )
87+ indev = gt911 .GT911 (touch_dev , reset_pin = 1 , interrupt_pin = 40 , debug = False ) # debug makes it slower
88+ from mpos import InputManager
89+ InputManager .register_indev (indev )
90+ except Exception as e :
91+ print (f"Touch init got exception: { e } " )
92+ init_touch ()
8993
9094# IO0 Button interrupt handler
9195def io0_interrupt_handler (pin ):
@@ -160,18 +164,7 @@ def init_cam(width, height, colormode):
160164 print ("input disabled" )
161165 except Exception as e :
162166 print (f"init_cam: disabling indev got exception: { e } " )
163- try :
164- import i2c
165- i2c_bus = i2c .I2C .Bus (host = 0 , scl = 38 , sda = 39 )
166- import mpos .indev .gt911 as gt911
167- touch_dev = i2c .I2C .Device (bus = i2c_bus , dev_id = gt911 .I2C_ADDR , reg_bits = gt911 .BITS )
168- indev = gt911 .GT911 (touch_dev , reset_pin = 1 , interrupt_pin = 40 , debug = True ) # remove debug because it's slower
169- print ("new indev created" )
170- from mpos import InputManager
171- InputManager .register_indev (indev )
172- print ("new indev registered" )
173- except Exception as e :
174- print (f"Indev enable got exception: { e } " )
167+ init_touch ()
175168
176169 except Exception as e :
177170 print (f"init_cam exception: { e } " )
@@ -194,18 +187,7 @@ def deinit_cam(cam):
194187 print (f"Warning: powering off camera got exception: { e } " )
195188 import time
196189 time .sleep_ms (100 )
197- try :
198- import i2c
199- i2c_bus = i2c .I2C .Bus (host = 0 , scl = 38 , sda = 39 )
200- import mpos .indev .gt911 as gt911
201- touch_dev = i2c .I2C .Device (bus = i2c_bus , dev_id = gt911 .I2C_ADDR , reg_bits = gt911 .BITS )
202- indev = gt911 .GT911 (touch_dev , reset_pin = 1 , interrupt_pin = 40 , debug = True ) # remove debug because it's slower
203- print ("new indev created" )
204- from mpos import InputManager
205- InputManager .register_indev (indev )
206- print ("new indev registered" )
207- except Exception as e :
208- print (f"Indev enable got exception: { e } " )
190+ init_touch ()
209191
210192def capture_cam (cam_obj , colormode ):
211193 return cam_obj .capture ()
0 commit comments