Skip to content

Commit 0348aee

Browse files
committed
fix/m5camera: setCursor method error
1 parent eb299d3 commit 0348aee

File tree

3 files changed

+110
-26
lines changed

3 files changed

+110
-26
lines changed

m5stack/cmodules/m5camera/camera.pyi

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from typing import Union, Literal
2+
3+
RGB565: int
4+
GRAYSCALE: int
5+
YUV422: int
6+
FRAME_96X96: int
7+
FRAME_QQVGA: int
8+
FRAME_QCIF: int
9+
FRAME_HQVGA: int
10+
FRAME_240X240: int
11+
FRAME_QVGA: int
12+
FRAME_CIF: int
13+
FRAME_HVGA: int
14+
FRAME_VGA: int
15+
16+
DRAM: int
17+
PSRAM: int
18+
19+
def init(pixformat: int=RGB565, framesize: int=FRAME_QVGA, fb_count: int=2, fb_location: int=PSRAM) -> bool:
20+
...
21+
22+
def deinit() -> bool:
23+
...
24+
25+
def skip_frames(time: int=300) -> None:
26+
...
27+
28+
def capture() -> bytes:
29+
...
30+
31+
def capture_to_jpg(quality=int) -> bytes:
32+
...
33+
34+
def capture_to_bmp() -> bytes:
35+
...
36+
37+
def pixformat(format: RGB565 | GRAYSCALE | YUV422) -> bool:
38+
...
39+
40+
def framesize(size: FRAME_96X96 | FRAME_QQVGA | FRAME_QCIF | FRAME_HQVGA | FRAME_240X240 | FRAME_QVGA | FRAME_CIF | FRAME_HVGA | FRAME_VGA) -> bool:
41+
...
42+
43+
def contrast(value: -2 | -1 | 0 | 1 | 2) -> bool:
44+
...
45+
46+
def global_gain(value: Union[Literal[0], Literal[1], ..., Literal[0x3F]]) -> bool:
47+
...
48+
49+
def hmirror(direction: Union[Literal[0], Literal[1]]) -> bool:
50+
...
51+
52+
def vflip(direction: Union[Literal[0], Literal[1]]) -> bool:
53+
...
54+
55+
def colorbar(enable: Union[Literal[0], Literal[1]]) -> bool:
56+
...

m5stack/cmodules/m5camera/m5camera.c

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ STATIC bool camera_init_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t
129129
return true;
130130
}
131131

132-
STATIC mp_obj_t camera_init(mp_uint_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
132+
STATIC mp_obj_t camera_init(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
133133
bool init = camera_init_helper(n_pos_args, pos_args, kw_args);
134134
if (init) {
135135
return mp_const_true;
@@ -151,7 +151,7 @@ STATIC mp_obj_t camera_deinit() {
151151
}
152152
STATIC MP_DEFINE_CONST_FUN_OBJ_0(camera_deinit_obj, camera_deinit);
153153

154-
STATIC mp_obj_t camera_skip_frames(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
154+
STATIC mp_obj_t camera_skip_frames(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
155155
mp_map_elem_t *kw_arg = mp_map_lookup(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_time), MP_MAP_LOOKUP);
156156
mp_int_t time = 300; // OV Recommended.
157157

@@ -260,8 +260,12 @@ STATIC mp_obj_t camera_pixformat(mp_obj_t pixformat) {
260260
return mp_const_false;
261261
}
262262

263-
s->set_pixformat(s, format);
264-
return mp_const_none;
263+
int ret = s->set_pixformat(s, format);
264+
if (ret == 0) {
265+
return mp_const_true;
266+
} else {
267+
return mp_const_false;
268+
}
265269
}
266270
STATIC MP_DEFINE_CONST_FUN_OBJ_1(camera_pixformat_obj, camera_pixformat);
267271

@@ -277,8 +281,12 @@ STATIC mp_obj_t camera_framesize(mp_obj_t framesize) {
277281
return mp_const_false;
278282
}
279283

280-
s->set_framesize(s, size);
281-
return mp_const_none;
284+
int ret = s->set_framesize(s, size);
285+
if (ret == 0) {
286+
return mp_const_true;
287+
} else {
288+
return mp_const_false;
289+
}
282290
}
283291
STATIC MP_DEFINE_CONST_FUN_OBJ_1(camera_framesize_obj, camera_framesize);
284292

@@ -290,8 +298,12 @@ STATIC mp_obj_t camera_contrast(mp_obj_t contrast) {
290298
}
291299

292300
int val = mp_obj_get_int(contrast); // -2,2 (default 0). 2 highcontrast
293-
s->set_contrast(s, val);
294-
return mp_const_none;
301+
int ret = s->set_contrast(s, val);
302+
if (ret == 0) {
303+
return mp_const_true;
304+
} else {
305+
return mp_const_false;
306+
}
295307
}
296308
STATIC MP_DEFINE_CONST_FUN_OBJ_1(camera_contrast_obj, camera_contrast);
297309

@@ -303,8 +315,12 @@ STATIC mp_obj_t camera_global_gain(mp_obj_t gain_level) {
303315
}
304316

305317
int val = mp_obj_get_int(gain_level); // -2,2 (default 0). 2 highcontrast
306-
s->set_gain_ctrl(s, val);
307-
return mp_const_none;
318+
int ret = s->set_gain_ctrl(s, val);
319+
if (ret == 0) {
320+
return mp_const_true;
321+
} else {
322+
return mp_const_false;
323+
}
308324
}
309325
STATIC MP_DEFINE_CONST_FUN_OBJ_1(camera_global_gain_obj, camera_global_gain);
310326

@@ -315,8 +331,12 @@ STATIC mp_obj_t camera_hmirror(mp_obj_t direction) {
315331
return mp_const_false;
316332
}
317333
int dir = mp_obj_get_int(direction);
318-
s->set_hmirror(s, dir);
319-
return mp_const_none;
334+
int ret = s->set_hmirror(s, dir);
335+
if (ret == 0) {
336+
return mp_const_true;
337+
} else {
338+
return mp_const_false;
339+
}
320340
}
321341
STATIC MP_DEFINE_CONST_FUN_OBJ_1(camera_hmirror_obj, camera_hmirror);
322342

@@ -327,8 +347,12 @@ STATIC mp_obj_t camera_vflip(mp_obj_t direction) {
327347
return mp_const_false;
328348
}
329349
int dir = mp_obj_get_int(direction);
330-
s->set_vflip(s, dir);
331-
return mp_const_none;
350+
int ret = s->set_vflip(s, dir);
351+
if (ret == 0) {
352+
return mp_const_true;
353+
} else {
354+
return mp_const_false;
355+
}
332356
}
333357
STATIC MP_DEFINE_CONST_FUN_OBJ_1(camera_vflip_obj, camera_vflip);
334358

@@ -339,8 +363,12 @@ STATIC mp_obj_t camera_colorbar(mp_obj_t enable) {
339363
return mp_const_false;
340364
}
341365
int val = mp_obj_get_int(enable);
342-
s->set_colorbar(s, (bool)val);
343-
return mp_const_none;
366+
int ret = s->set_colorbar(s, (bool)val);
367+
if (ret == 0) {
368+
return mp_const_true;
369+
} else {
370+
return mp_const_false;
371+
}
344372
}
345373
STATIC MP_DEFINE_CONST_FUN_OBJ_1(camera_colorbar_obj, camera_colorbar);
346374

m5stack/libs/m5camera.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
FrameSize = namedtuple("FrameSize", ["width", "height"])
3737

38-
_frame_sizes = {
38+
_frame_size_table = {
3939
FRAME_96X96: FrameSize(width=96, height=96),
4040
FRAME_QQVGA: FrameSize(width=160, height=120),
4141
FRAME_QCIF: FrameSize(width=176, height=144),
@@ -54,28 +54,30 @@
5454
_height = 0
5555
_max_width = 0
5656
_max_height = 0
57+
_frame_size = None
5758
_visible = True
5859

5960

61+
6062
def init(
6163
x, y, width, height, pixformat=RGB565, framesize=FRAME_QVGA, fb_count=2, fb_location=IN_PSRAM
6264
) -> None:
63-
global _x, _y, _width, _height, _max_width, _max_height
65+
global _x, _y, _width, _height, _max_width, _max_height, _frame_size
6466
_x = x
6567
_y = y
6668
_max_width = width
6769
_max_height = height
68-
frame_size = _frame_sizes.get(framesize)
69-
_width = frame_size.width if frame_size.width < _max_width else _max_width
70-
_height = frame_size.height if frame_size.height < _max_height else _max_height
70+
_frame_size = _frame_size_table.get(framesize)
71+
_width = _frame_size.width if _frame_size.width < _max_width else _max_width
72+
_height = _frame_size.height if _frame_size.height < _max_height else _max_height
7173
camera.init(
7274
pixformat=pixformat, framesize=framesize, fb_count=fb_count, fb_location=fb_location
7375
)
7476
# camera.skip_frames(10)
7577

7678

7779
def framesize(size) -> None:
78-
frame_size = _frame_sizes.get(size)
80+
frame_size = _frame_size_table.get(size)
7981
if frame_size is None:
8082
return
8183
global _width, _height, _max_width, _max_height
@@ -94,12 +96,11 @@ def disp_to_screen():
9496
gc.collect()
9597

9698

97-
# fixme
9899
def setCursor(x=0, y=0, w=0, h=0):
99-
global _x, _y, _max_width, _width, _max_height, _height
100+
global _x, _y, _max_width, _width, _max_height, _height, _frame_size
100101
_x = x
101102
_y = y
102-
frame_size = _frame_sizes.get(framesize)
103+
frame_size = _frame_size_table.get(_frame_size)
103104
if w is not 0:
104105
_max_width = w
105106
_width = frame_size.width if frame_size.width < _max_width else _max_width
@@ -108,7 +109,6 @@ def setCursor(x=0, y=0, w=0, h=0):
108109
_height = frame_size.height if frame_size.height < _max_height else _max_height
109110

110111

111-
# fixme
112112
def setVisible(enable: bool):
113113
global _visible
114114
_visible = enable

0 commit comments

Comments
 (0)