Improve camera

This commit is contained in:
Thomas Farstrike
2025-11-25 09:25:36 +01:00
parent f8da36b630
commit 01f7a1f84f
3 changed files with 11 additions and 13 deletions
+2 -4
View File
@@ -12,8 +12,6 @@
#include "py/runtime.h"
#include "py/mperrno.h"
#define WIDTH 640
#define HEIGHT 480
#define NUM_BUFFERS 1
#define WEBCAM_DEBUG_PRINT(...) mp_printf(&mp_plat_print, __VA_ARGS__)
@@ -285,8 +283,8 @@ static mp_obj_t webcam_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
enum { ARG_device, ARG_width, ARG_height };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_device, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_width, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = WIDTH} },
{ MP_QSTR_height, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = HEIGHT} },
{ MP_QSTR_width, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_height, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
@@ -19,6 +19,7 @@ import mpos.time
class CameraApp(Activity):
button_width = 40
width = 320
height = 240
@@ -70,7 +71,7 @@ class CameraApp(Activity):
# Initialize LVGL image widget
self.create_preview_image()
close_button = lv.button(self.main_screen)
close_button.set_size(60,60)
close_button.set_size(self.button_width,40)
close_button.align(lv.ALIGN.TOP_RIGHT, 0, 0)
close_label = lv.label(close_button)
close_label.set_text(lv.SYMBOL.CLOSE)
@@ -78,15 +79,15 @@ class CameraApp(Activity):
close_button.add_event_cb(lambda e: self.finish(),lv.EVENT.CLICKED,None)
# Settings button
settings_button = lv.button(self.main_screen)
settings_button.set_size(60,60)
settings_button.align(lv.ALIGN.TOP_RIGHT, 0, 60)
settings_button.set_size(self.button_width,40)
settings_button.align(lv.ALIGN.TOP_RIGHT, 0, 50)
settings_label = lv.label(settings_button)
settings_label.set_text(lv.SYMBOL.SETTINGS)
settings_label.center()
settings_button.add_event_cb(lambda e: self.open_settings(),lv.EVENT.CLICKED,None)
self.snap_button = lv.button(self.main_screen)
self.snap_button.set_size(60, 60)
self.snap_button.set_size(self.button_width, 40)
self.snap_button.align(lv.ALIGN.RIGHT_MID, 0, 0)
self.snap_button.add_flag(lv.obj.FLAG.HIDDEN)
self.snap_button.add_event_cb(self.snap_button_click,lv.EVENT.CLICKED,None)
@@ -94,7 +95,7 @@ class CameraApp(Activity):
snap_label.set_text(lv.SYMBOL.OK)
snap_label.center()
self.qr_button = lv.button(self.main_screen)
self.qr_button.set_size(60, 60)
self.qr_button.set_size(self.button_width, 40)
self.qr_button.add_flag(lv.obj.FLAG.HIDDEN)
self.qr_button.align(lv.ALIGN.BOTTOM_RIGHT, 0, 0)
self.qr_button.add_event_cb(self.qr_button_click,lv.EVENT.CLICKED,None)
@@ -172,10 +173,9 @@ class CameraApp(Activity):
print("camera app cleanup done.")
def set_image_size(self):
#return
disp = lv.display_get_default()
target_h = disp.get_vertical_resolution()
target_w = target_h
target_w = disp.get_horizontal_resolution() - self.button_width - 5 # leave 5px for border
if target_w == self.width and target_h == self.height:
print("Target width and height are the same as native image, no scaling required.")
return
+2 -2
View File
@@ -112,8 +112,8 @@ class TestGraphicalCameraSettings(unittest.TestCase):
# The settings button is positioned at TOP_RIGHT with offset (0, 60)
# On a 320x240 screen, this is approximately x=260, y=90
# We'll click slightly inside the button to ensure we hit it
settings_x = 290 # Right side of screen, inside the 60px button
settings_y = 90 # 60px down from top, center of 60px button
settings_x = 300 # Right side of screen, inside the 60px button
settings_y = 60 # 60px down from top, center of 60px button
print(f"\nClicking settings button at ({settings_x}, {settings_y})")
simulate_click(settings_x, settings_y, press_duration_ms=100)