Skip to content

Commit 23e9414

Browse files
Camera: disable GT911 touch screen to avoid conflict
1 parent 12e9922 commit 23e9414

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

internal_filesystem/lib/mpos/ui/camera_activity.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,15 @@ def start_cam(self):
138138
# Init camera:
139139
self.cam = self.init_internal_cam(self.width, self.height)
140140
if self.cam:
141-
self.image.set_rotation(900) # internal camera is rotated 90 degrees
141+
try:
142+
from mpos import InputManager
143+
indev = InputManager.list_indevs()[0]
144+
indev.enable(False)
145+
InputManager.unregister_indev(indev)
146+
print("input disabled")
147+
except Exception as e:
148+
print(f"disabling indev got exception: {e}")
149+
#self.image.set_rotation(900) # internal camera is rotated 90 degrees
142150
# Apply saved camera settings, only for internal camera for now:
143151
self.apply_camera_settings(self.scanqr_prefs if self.scanqr_mode else self.prefs, self.cam, self.use_webcam) # needs to be done AFTER the camera is initialized
144152
else:
@@ -166,7 +174,7 @@ def stop_cam(self):
166174
# Power off, otherwise it keeps using a lot of current
167175
try:
168176
from machine import Pin, I2C
169-
i2c = I2C(1, scl=Pin(16), sda=Pin(21)) # Adjust pins and frequency
177+
i2c = I2C(1, scl=Pin(38), sda=Pin(39)) # Adjust pins and frequency
170178
#devices = i2c.scan()
171179
#print([hex(addr) for addr in devices]) # finds it on 60 = 0x3C after init
172180
camera_addr = 0x3C # for OV5640
@@ -177,6 +185,28 @@ def stop_cam(self):
177185
i2c.writeto(camera_addr, bytes([reg_high, reg_low, power_off_command]))
178186
except Exception as e:
179187
print(f"Warning: powering off camera got exception: {e}")
188+
import time
189+
time.sleep_ms(100)
190+
try:
191+
# hardware reset might work too, but doesn't seem to:
192+
#from mpos import InputManager
193+
#indev = InputManager.list_indevs()[0]
194+
#indev.hw_reset()
195+
#indev.enable(True)
196+
#print("input enabled")
197+
#time.sleep(1)
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}")
209+
180210
self.cam = None
181211
if self.image_dsc: # it's important to delete the image when stopping the camera, otherwise LVGL might try to display it and crash
182212
print("emptying self.current_cam_buffer...")

0 commit comments

Comments
 (0)