|
25 | 25 | */
|
26 | 26 |
|
27 | 27 | #include "py/obj.h"
|
| 28 | +#include "py/objproperty.h" |
28 | 29 | #include "py/runtime.h"
|
29 | 30 |
|
30 | 31 | #include "shared/runtime/context_manager_helpers.h"
|
@@ -82,20 +83,70 @@ STATIC mp_obj_t imagecapture_parallelimagecapture_make_new(const mp_obj_type_t *
|
82 | 83 | return self;
|
83 | 84 | }
|
84 | 85 |
|
85 |
| -//| def capture(self, buffer: WriteableBuffer, width: int, height: int, bpp: int=16) -> None: |
86 |
| -//| """Capture a single frame into the given buffer""" |
| 86 | +//| def capture(self, buffer: WriteableBuffer) -> WriteableBuffer: |
| 87 | +//| """Capture a single frame into the given buffer. |
| 88 | +//| |
| 89 | +//| This will stop a continuous-mode capture, if one is in progress.""" |
87 | 90 | //| ...
|
88 | 91 | //|
|
89 | 92 | STATIC mp_obj_t imagecapture_parallelimagecapture_capture(mp_obj_t self_in, mp_obj_t buffer) {
|
90 | 93 | imagecapture_parallelimagecapture_obj_t *self = (imagecapture_parallelimagecapture_obj_t *)self_in;
|
91 |
| - mp_buffer_info_t bufinfo; |
92 |
| - mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_RW); |
93 |
| - common_hal_imagecapture_parallelimagecapture_capture(self, bufinfo.buf, bufinfo.len); |
| 94 | + common_hal_imagecapture_parallelimagecapture_singleshot_capture(self, buffer); |
94 | 95 |
|
95 |
| - return mp_const_none; |
| 96 | + return buffer; |
96 | 97 | }
|
97 | 98 | STATIC MP_DEFINE_CONST_FUN_OBJ_2(imagecapture_parallelimagecapture_capture_obj, imagecapture_parallelimagecapture_capture);
|
98 | 99 |
|
| 100 | +//| def continuous_capture_start(self, buffer1: WriteableBuffer, buffer2: WriteableBuffer, /) -> None: |
| 101 | +//| """Begin capturing into the given buffers in the background. |
| 102 | +//| |
| 103 | +//| Call `continuous_capture_get_frame` to get the next available |
| 104 | +//| frame, and `continuous_capture_stop` to stop capturing. |
| 105 | +//| |
| 106 | +//| Until `continuous_capture_stop` (or `deinit`) is called, the |
| 107 | +//| `ParallelImageCapture` object keeps references to ``buffer1`` and |
| 108 | +//| ``buffer2``, so the objects will not be garbage collected.""" |
| 109 | +//| ... |
| 110 | +//| |
| 111 | +STATIC mp_obj_t imagecapture_parallelimagecapture_continuous_capture_start(mp_obj_t self_in, mp_obj_t buffer1, mp_obj_t buffer2) { |
| 112 | + imagecapture_parallelimagecapture_obj_t *self = (imagecapture_parallelimagecapture_obj_t *)self_in; |
| 113 | + common_hal_imagecapture_parallelimagecapture_continuous_capture_start(self, buffer1, buffer2); |
| 114 | + |
| 115 | + return mp_const_none; |
| 116 | +} |
| 117 | +STATIC MP_DEFINE_CONST_FUN_OBJ_3(imagecapture_parallelimagecapture_continuous_capture_start_obj, imagecapture_parallelimagecapture_continuous_capture_start); |
| 118 | + |
| 119 | +//| def continuous_capture_get_frame(self) -> WriteableBuffer: |
| 120 | +//| """Return the next available frame, one of the two buffers passed to `continuous_capture_start`""" |
| 121 | +//| ... |
| 122 | +//| |
| 123 | +STATIC mp_obj_t imagecapture_parallelimagecapture_continuous_capture_get_frame(mp_obj_t self_in) { |
| 124 | + imagecapture_parallelimagecapture_obj_t *self = (imagecapture_parallelimagecapture_obj_t *)self_in; |
| 125 | + return common_hal_imagecapture_parallelimagecapture_continuous_capture_get_frame(self); |
| 126 | +} |
| 127 | +STATIC MP_DEFINE_CONST_FUN_OBJ_1(imagecapture_parallelimagecapture_continuous_capture_get_frame_obj, imagecapture_parallelimagecapture_continuous_capture_get_frame); |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | +//| def continuous_capture_stop(self) -> None: |
| 132 | +//| """Stop continuous capture. |
| 133 | +//| |
| 134 | +//| Calling this method also causes the object to release its |
| 135 | +//| references to the buffers passed to `continuous_capture_start`, |
| 136 | +//| potentially allowing the objects to be garbage collected.""" |
| 137 | +//| ... |
| 138 | +//| |
| 139 | +STATIC mp_obj_t imagecapture_parallelimagecapture_continuous_capture_stop(mp_obj_t self_in) { |
| 140 | + imagecapture_parallelimagecapture_obj_t *self = (imagecapture_parallelimagecapture_obj_t *)self_in; |
| 141 | + common_hal_imagecapture_parallelimagecapture_continuous_capture_stop(self); |
| 142 | + |
| 143 | + return mp_const_none; |
| 144 | +} |
| 145 | +STATIC MP_DEFINE_CONST_FUN_OBJ_1(imagecapture_parallelimagecapture_continuous_capture_stop_obj, imagecapture_parallelimagecapture_continuous_capture_stop); |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | + |
99 | 150 | //| def deinit(self) -> None:
|
100 | 151 | //| """Deinitialize this instance"""
|
101 | 152 | //| ...
|
@@ -134,6 +185,9 @@ STATIC const mp_rom_map_elem_t imagecapture_parallelimagecapture_locals_dict_tab
|
134 | 185 | { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&imagecapture_parallelimagecapture___exit___obj) },
|
135 | 186 |
|
136 | 187 | { MP_ROM_QSTR(MP_QSTR_capture), MP_ROM_PTR(&imagecapture_parallelimagecapture_capture_obj) },
|
| 188 | + { MP_ROM_QSTR(MP_QSTR_continuous_capture_start), MP_ROM_PTR(&imagecapture_parallelimagecapture_continuous_capture_start_obj) }, |
| 189 | + { MP_ROM_QSTR(MP_QSTR_continuous_capture_stop), MP_ROM_PTR(&imagecapture_parallelimagecapture_continuous_capture_stop_obj) }, |
| 190 | + { MP_ROM_QSTR(MP_QSTR_continuous_capture_get_frame), MP_ROM_PTR(&imagecapture_parallelimagecapture_continuous_capture_get_frame_obj) }, |
137 | 191 | };
|
138 | 192 |
|
139 | 193 | STATIC MP_DEFINE_CONST_DICT(imagecapture_parallelimagecapture_locals_dict, imagecapture_parallelimagecapture_locals_dict_table);
|
|
0 commit comments