Skip to content

Commit 32603cd

Browse files
Fix scanqr intent handling
1 parent df51526 commit 32603cd

File tree

1 file changed

+11
-10
lines changed
  • internal_filesystem/apps/com.micropythonos.camera/assets

1 file changed

+11
-10
lines changed

internal_filesystem/apps/com.micropythonos.camera/assets/camera_app.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class CameraApp(Activity):
5050
status_label_cont = None
5151

5252
def onCreate(self):
53-
self.scanqr_intent = self.getIntent().extras.get("scanqr_intent")
5453
self.main_screen = lv.obj()
5554
self.main_screen.set_style_pad_all(1, 0)
5655
self.main_screen.set_style_border_width(0, 0)
@@ -115,16 +114,16 @@ def onCreate(self):
115114
self.setContentView(self.main_screen)
116115

117116
def onResume(self, screen):
118-
self.load_settings_cached()
119-
self.start_cam()
120-
if not self.cam and self.scanqr_mode:
121-
print("No camera found, stopping camera app")
122-
self.finish()
123-
# Camera is running and refreshing
117+
self.scanqr_intent = self.getIntent().extras.get("scanqr_intent")
124118
self.status_label_cont.add_flag(lv.obj.FLAG.HIDDEN)
125-
if self.scanqr_mode:
119+
if self.scanqr_mode or self.scanqr_intent:
126120
self.start_qr_decoding()
121+
if not self.cam and self.scanqr_mode:
122+
print("No camera found, stopping camera app")
123+
self.finish()
127124
else:
125+
self.load_settings_cached()
126+
self.start_cam()
128127
self.qr_button.remove_flag(lv.obj.FLAG.HIDDEN)
129128
self.snap_button.remove_flag(lv.obj.FLAG.HIDDEN)
130129

@@ -176,6 +175,7 @@ def stop_cam(self):
176175
i2c.writeto(camera_addr, bytes([reg_high, reg_low, power_off_command]))
177176
except Exception as e:
178177
print(f"Warning: powering off camera got exception: {e}")
178+
self.cam = None
179179
if self.image_dsc: # it's important to delete the image when stopping the camera, otherwise LVGL might try to display it and crash
180180
print("emptying self.current_cam_buffer...")
181181
self.image_dsc.data = None
@@ -286,8 +286,9 @@ def start_qr_decoding(self):
286286
# Activate QR mode settings
287287
self.load_settings_cached()
288288
# Check if it's necessary to restart the camera:
289-
if self.width != oldwidth or self.height != oldheight or self.colormode != oldcolormode:
290-
self.stop_cam()
289+
if not self.cam or self.width != oldwidth or self.height != oldheight or self.colormode != oldcolormode:
290+
if self.cam:
291+
self.stop_cam()
291292
self.start_cam()
292293
self.qr_label.set_text(lv.SYMBOL.EYE_CLOSE)
293294
self.status_label_cont.remove_flag(lv.obj.FLAG.HIDDEN)

0 commit comments

Comments
 (0)