Skip to content

Commit 8819afd

Browse files
Camera app: simplify
1 parent a7712f0 commit 8819afd

File tree

1 file changed

+19
-23
lines changed
  • internal_filesystem/apps/com.micropythonos.camera/assets

1 file changed

+19
-23
lines changed

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

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -214,28 +214,15 @@ def update_preview_image(self):
214214

215215
def qrdecode_one(self):
216216
try:
217-
import qrdecode
218-
import utime
217+
result = None
219218
before = time.ticks_ms()
219+
import qrdecode
220220
if self.colormode:
221221
result = qrdecode.qrdecode_rgb565(self.current_cam_buffer, self.width, self.height)
222222
else:
223223
result = qrdecode.qrdecode(self.current_cam_buffer, self.width, self.height)
224224
after = time.ticks_ms()
225-
#result = bytearray("INSERT_TEST_QR_DATA_HERE", "utf-8")
226-
if not result:
227-
self.status_label.set_text(self.status_label_text_searching)
228-
else:
229-
print(f"SUCCESSFUL QR DECODE TOOK: {after-before}ms")
230-
result = self.remove_bom(result)
231-
result = self.print_qr_buffer(result)
232-
print(f"QR decoding found: {result}")
233-
if self.scanqr_mode:
234-
self.setResult(True, result)
235-
self.finish()
236-
else:
237-
self.status_label.set_text(result) # in the future, the status_label text should be copy-paste-able
238-
self.stop_qr_decoding()
225+
print(f"qrdecode took {after-before}ms")
239226
except ValueError as e:
240227
print("QR ValueError: ", e)
241228
self.status_label.set_text(self.status_label_text_searching)
@@ -244,6 +231,18 @@ def qrdecode_one(self):
244231
self.status_label.set_text(self.status_label_text_found)
245232
except Exception as e:
246233
print("QR got other error: ", e)
234+
#result = bytearray("INSERT_TEST_QR_DATA_HERE", "utf-8")
235+
if result is None:
236+
return
237+
result = self.remove_bom(result)
238+
result = self.print_qr_buffer(result)
239+
print(f"QR decoding found: {result}")
240+
self.stop_qr_decoding()
241+
if self.scanqr_mode:
242+
self.setResult(True, result)
243+
self.finish()
244+
else:
245+
self.status_label.set_text(result) # in the future, the status_label text should be copy-paste-able
247246

248247
def snap_button_click(self, e):
249248
print("Picture taken!")
@@ -280,7 +279,7 @@ def stop_qr_decoding(self):
280279
self.keepliveqrdecoding = False
281280
self.qr_label.set_text(lv.SYMBOL.EYE_OPEN)
282281
self.status_label_text = self.status_label.get_text()
283-
if self.status_label_text in (self.status_label_text_searching or self.status_label_text_found): # if it found a QR code, leave it
282+
if self.status_label_text not in (self.status_label_text_searching or self.status_label_text_found): # if it found a QR code, leave it
284283
self.status_label_cont.add_flag(lv.obj.FLAG.HIDDEN)
285284

286285
def qr_button_click(self, e):
@@ -328,13 +327,10 @@ def try_capture(self, event):
328327
self.image_dsc.data = self.current_cam_buffer
329328
#self.image.invalidate() # does not work so do this:
330329
self.image.set_src(self.image_dsc)
330+
if self.keepliveqrdecoding:
331+
self.qrdecode_one()
331332
if not self.use_webcam:
332-
self.cam.free_buffer() # Free the old buffer, otherwise the camera doesn't provide a new one
333-
try:
334-
if self.keepliveqrdecoding:
335-
self.qrdecode_one()
336-
except Exception as qre:
337-
print(f"try_capture: qrdecode_one got exception: {qre}")
333+
self.cam.free_buffer() # After QR decoding, free the old buffer, otherwise the camera doesn't provide a new one
338334

339335
def init_internal_cam(self, width, height):
340336
"""Initialize internal camera with specified resolution.

0 commit comments

Comments
 (0)