Skip to content

Commit 01f7a1f

Browse files
Improve camera
1 parent f8da36b commit 01f7a1f

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

c_mpos/src/webcam.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include "py/runtime.h"
1313
#include "py/mperrno.h"
1414

15-
#define WIDTH 640
16-
#define HEIGHT 480
1715
#define NUM_BUFFERS 1
1816

1917
#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
285283
enum { ARG_device, ARG_width, ARG_height };
286284
static const mp_arg_t allowed_args[] = {
287285
{ MP_QSTR_device, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
288-
{ MP_QSTR_width, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = WIDTH} },
289-
{ MP_QSTR_height, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = HEIGHT} },
286+
{ MP_QSTR_width, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
287+
{ MP_QSTR_height, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
290288
};
291289

292290
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
class CameraApp(Activity):
2121

22+
button_width = 40
2223
width = 320
2324
height = 240
2425

@@ -70,31 +71,31 @@ def onCreate(self):
7071
# Initialize LVGL image widget
7172
self.create_preview_image()
7273
close_button = lv.button(self.main_screen)
73-
close_button.set_size(60,60)
74+
close_button.set_size(self.button_width,40)
7475
close_button.align(lv.ALIGN.TOP_RIGHT, 0, 0)
7576
close_label = lv.label(close_button)
7677
close_label.set_text(lv.SYMBOL.CLOSE)
7778
close_label.center()
7879
close_button.add_event_cb(lambda e: self.finish(),lv.EVENT.CLICKED,None)
7980
# Settings button
8081
settings_button = lv.button(self.main_screen)
81-
settings_button.set_size(60,60)
82-
settings_button.align(lv.ALIGN.TOP_RIGHT, 0, 60)
82+
settings_button.set_size(self.button_width,40)
83+
settings_button.align(lv.ALIGN.TOP_RIGHT, 0, 50)
8384
settings_label = lv.label(settings_button)
8485
settings_label.set_text(lv.SYMBOL.SETTINGS)
8586
settings_label.center()
8687
settings_button.add_event_cb(lambda e: self.open_settings(),lv.EVENT.CLICKED,None)
8788

8889
self.snap_button = lv.button(self.main_screen)
89-
self.snap_button.set_size(60, 60)
90+
self.snap_button.set_size(self.button_width, 40)
9091
self.snap_button.align(lv.ALIGN.RIGHT_MID, 0, 0)
9192
self.snap_button.add_flag(lv.obj.FLAG.HIDDEN)
9293
self.snap_button.add_event_cb(self.snap_button_click,lv.EVENT.CLICKED,None)
9394
snap_label = lv.label(self.snap_button)
9495
snap_label.set_text(lv.SYMBOL.OK)
9596
snap_label.center()
9697
self.qr_button = lv.button(self.main_screen)
97-
self.qr_button.set_size(60, 60)
98+
self.qr_button.set_size(self.button_width, 40)
9899
self.qr_button.add_flag(lv.obj.FLAG.HIDDEN)
99100
self.qr_button.align(lv.ALIGN.BOTTOM_RIGHT, 0, 0)
100101
self.qr_button.add_event_cb(self.qr_button_click,lv.EVENT.CLICKED,None)
@@ -172,10 +173,9 @@ def onPause(self, screen):
172173
print("camera app cleanup done.")
173174

174175
def set_image_size(self):
175-
#return
176176
disp = lv.display_get_default()
177177
target_h = disp.get_vertical_resolution()
178-
target_w = target_h
178+
target_w = disp.get_horizontal_resolution() - self.button_width - 5 # leave 5px for border
179179
if target_w == self.width and target_h == self.height:
180180
print("Target width and height are the same as native image, no scaling required.")
181181
return

tests/test_graphical_camera_settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def test_settings_button_click_no_crash(self):
112112
# The settings button is positioned at TOP_RIGHT with offset (0, 60)
113113
# On a 320x240 screen, this is approximately x=260, y=90
114114
# We'll click slightly inside the button to ensure we hit it
115-
settings_x = 290 # Right side of screen, inside the 60px button
116-
settings_y = 90 # 60px down from top, center of 60px button
115+
settings_x = 300 # Right side of screen, inside the 60px button
116+
settings_y = 60 # 60px down from top, center of 60px button
117117

118118
print(f"\nClicking settings button at ({settings_x}, {settings_y})")
119119
simulate_click(settings_x, settings_y, press_duration_ms=100)

0 commit comments

Comments
 (0)