mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Camera app: don't repeat yourself
This commit is contained in:
@@ -260,12 +260,13 @@ class CameraApp(Activity):
|
|||||||
print("Taking picture...")
|
print("Taking picture...")
|
||||||
# Would be nice to check that there's enough free space here, and show an error if not...
|
# Would be nice to check that there's enough free space here, and show an error if not...
|
||||||
import os
|
import os
|
||||||
|
path = "data/images"
|
||||||
try:
|
try:
|
||||||
os.mkdir("data")
|
os.mkdir("data")
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
os.mkdir("data/images")
|
os.mkdir(path)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
if self.current_cam_buffer is None:
|
if self.current_cam_buffer is None:
|
||||||
@@ -281,7 +282,7 @@ class CameraApp(Activity):
|
|||||||
self.status_label_cont.remove_flag(lv.obj.FLAG.HIDDEN)
|
self.status_label_cont.remove_flag(lv.obj.FLAG.HIDDEN)
|
||||||
return
|
return
|
||||||
colorname = "RGB565" if self.colormode else "GRAY"
|
colorname = "RGB565" if self.colormode else "GRAY"
|
||||||
filename=f"data/images/camera_capture_{mpos.time.epoch_seconds()}_{self.width}x{self.height}_{colorname}.raw"
|
filename=f"{path}/picture_{mpos.time.epoch_seconds()}_{self.width}x{self.height}_{colorname}.raw"
|
||||||
try:
|
try:
|
||||||
with open(filename, 'wb') as f:
|
with open(filename, 'wb') as f:
|
||||||
f.write(self.current_cam_buffer) # This takes around 17 seconds to store 921600 bytes, so ~50KB/s, so would be nice to show some progress bar
|
f.write(self.current_cam_buffer) # This takes around 17 seconds to store 921600 bytes, so ~50KB/s, so would be nice to show some progress bar
|
||||||
|
|||||||
Reference in New Issue
Block a user