Skip to content

Commit c944e69

Browse files
run_desktop: backup and restore config file
1 parent 4b9a147 commit c944e69

File tree

3 files changed

+170
-0
lines changed

3 files changed

+170
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
diff --git a/src/manifest.py b/src/manifest.py
2+
index ff69f76..929ff84 100644
3+
--- a/src/manifest.py
4+
+++ b/src/manifest.py
5+
@@ -1,4 +1,5 @@
6+
# Include the board's default manifest.
7+
include("$(PORT_DIR)/boards/manifest.py")
8+
# Add custom driver
9+
-module("acamera.py")
10+
\ No newline at end of file
11+
+module("acamera.py")
12+
+include("/home/user/projects/MicroPythonOS/claude/MicroPythonOS/lvgl_micropython/build/manifest.py") # workaround to prevent micropython-camera-API from overriding the lvgl_micropython manifest...
13+
diff --git a/src/modcamera.c b/src/modcamera.c
14+
index 5a0bd05..c84f09d 100644
15+
--- a/src/modcamera.c
16+
+++ b/src/modcamera.c
17+
@@ -252,7 +252,7 @@ const mp_rom_map_elem_t mp_camera_hal_pixel_format_table[] = {
18+
const mp_rom_map_elem_t mp_camera_hal_frame_size_table[] = {
19+
{ MP_ROM_QSTR(MP_QSTR_R96X96), MP_ROM_INT((mp_uint_t)FRAMESIZE_96X96) },
20+
{ MP_ROM_QSTR(MP_QSTR_QQVGA), MP_ROM_INT((mp_uint_t)FRAMESIZE_QQVGA) },
21+
- { MP_ROM_QSTR(MP_QSTR_R128x128), MP_ROM_INT((mp_uint_t)FRAMESIZE_128X128) },
22+
+ { MP_ROM_QSTR(MP_QSTR_R128X128), MP_ROM_INT((mp_uint_t)FRAMESIZE_128X128) },
23+
{ MP_ROM_QSTR(MP_QSTR_QCIF), MP_ROM_INT((mp_uint_t)FRAMESIZE_QCIF) },
24+
{ MP_ROM_QSTR(MP_QSTR_HQVGA), MP_ROM_INT((mp_uint_t)FRAMESIZE_HQVGA) },
25+
{ MP_ROM_QSTR(MP_QSTR_R240X240), MP_ROM_INT((mp_uint_t)FRAMESIZE_240X240) },
26+
@@ -260,10 +260,17 @@ const mp_rom_map_elem_t mp_camera_hal_frame_size_table[] = {
27+
{ MP_ROM_QSTR(MP_QSTR_R320X320), MP_ROM_INT((mp_uint_t)FRAMESIZE_320X320) },
28+
{ MP_ROM_QSTR(MP_QSTR_CIF), MP_ROM_INT((mp_uint_t)FRAMESIZE_CIF) },
29+
{ MP_ROM_QSTR(MP_QSTR_HVGA), MP_ROM_INT((mp_uint_t)FRAMESIZE_HVGA) },
30+
+ { MP_ROM_QSTR(MP_QSTR_R480X480), MP_ROM_INT((mp_uint_t)FRAMESIZE_480X480) },
31+
{ MP_ROM_QSTR(MP_QSTR_VGA), MP_ROM_INT((mp_uint_t)FRAMESIZE_VGA) },
32+
+ { MP_ROM_QSTR(MP_QSTR_R640X640), MP_ROM_INT((mp_uint_t)FRAMESIZE_640X640) },
33+
+ { MP_ROM_QSTR(MP_QSTR_R720X720), MP_ROM_INT((mp_uint_t)FRAMESIZE_720X720) },
34+
{ MP_ROM_QSTR(MP_QSTR_SVGA), MP_ROM_INT((mp_uint_t)FRAMESIZE_SVGA) },
35+
+ { MP_ROM_QSTR(MP_QSTR_R800X800), MP_ROM_INT((mp_uint_t)FRAMESIZE_800X800) },
36+
+ { MP_ROM_QSTR(MP_QSTR_R960X960), MP_ROM_INT((mp_uint_t)FRAMESIZE_960X960) },
37+
{ MP_ROM_QSTR(MP_QSTR_XGA), MP_ROM_INT((mp_uint_t)FRAMESIZE_XGA) },
38+
+ { MP_ROM_QSTR(MP_QSTR_R1024X1024),MP_ROM_INT((mp_uint_t)FRAMESIZE_1024X1024) },
39+
{ MP_ROM_QSTR(MP_QSTR_HD), MP_ROM_INT((mp_uint_t)FRAMESIZE_HD) },
40+
+ { MP_ROM_QSTR(MP_QSTR_R1280X1280),MP_ROM_INT((mp_uint_t)FRAMESIZE_1280X1280) },
41+
{ MP_ROM_QSTR(MP_QSTR_SXGA), MP_ROM_INT((mp_uint_t)FRAMESIZE_SXGA) },
42+
{ MP_ROM_QSTR(MP_QSTR_UXGA), MP_ROM_INT((mp_uint_t)FRAMESIZE_UXGA) },
43+
{ MP_ROM_QSTR(MP_QSTR_FHD), MP_ROM_INT((mp_uint_t)FRAMESIZE_FHD) },
44+
@@ -435,3 +442,22 @@ int mp_camera_hal_get_pixel_height(mp_camera_obj_t *self) {
45+
framesize_t framesize = sensor->status.framesize;
46+
return resolution[framesize].height;
47+
}
48+
+
49+
+int mp_camera_hal_set_res_raw(mp_camera_obj_t *self, int startX, int startY, int endX, int endY, int offsetX, int offsetY, int totalX, int totalY, int outputX, int outputY, bool scale, bool binning) {
50+
+ check_init(self);
51+
+ sensor_t *sensor = esp_camera_sensor_get();
52+
+ if (!sensor->set_res_raw) {
53+
+ mp_raise_ValueError(MP_ERROR_TEXT("Sensor does not support set_res_raw"));
54+
+ }
55+
+
56+
+ if (self->captured_buffer) {
57+
+ esp_camera_return_all();
58+
+ self->captured_buffer = NULL;
59+
+ }
60+
+
61+
+ int ret = sensor->set_res_raw(sensor, startX, startY, endX, endY, offsetX, offsetY, totalX, totalY, outputX, outputY, scale, binning);
62+
+ if (ret < 0) {
63+
+ mp_raise_ValueError(MP_ERROR_TEXT("Failed to set raw resolution"));
64+
+ }
65+
+ return ret;
66+
+}
67+
diff --git a/src/modcamera.h b/src/modcamera.h
68+
index a3ce749..a8771bd 100644
69+
--- a/src/modcamera.h
70+
+++ b/src/modcamera.h
71+
@@ -211,7 +211,7 @@ extern const mp_rom_map_elem_t mp_camera_hal_pixel_format_table[9];
72+
* @brief Table mapping frame sizes API to their corresponding values at HAL.
73+
* @details Needs to be defined in the port-specific implementation.
74+
*/
75+
-extern const mp_rom_map_elem_t mp_camera_hal_frame_size_table[24];
76+
+extern const mp_rom_map_elem_t mp_camera_hal_frame_size_table[31];
77+
78+
/**
79+
* @brief Table mapping gainceiling API to their corresponding values at HAL.
80+
@@ -278,4 +278,24 @@ DECLARE_CAMERA_HAL_GET(int, pixel_width)
81+
DECLARE_CAMERA_HAL_GET(const char *, sensor_name)
82+
DECLARE_CAMERA_HAL_GET(bool, supports_jpeg)
83+
84+
-#endif // MICROPY_INCLUDED_MODCAMERA_H
85+
\ No newline at end of file
86+
+/**
87+
+ * @brief Sets the raw resolution parameters including ROI (Region of Interest).
88+
+ *
89+
+ * @param self Pointer to the camera object.
90+
+ * @param startX X start position.
91+
+ * @param startY Y start position.
92+
+ * @param endX X end position.
93+
+ * @param endY Y end position.
94+
+ * @param offsetX X offset.
95+
+ * @param offsetY Y offset.
96+
+ * @param totalX Total X size.
97+
+ * @param totalY Total Y size.
98+
+ * @param outputX Output X size.
99+
+ * @param outputY Output Y size.
100+
+ * @param scale Enable scaling.
101+
+ * @param binning Enable binning.
102+
+ * @return 0 on success, negative value on error.
103+
+ */
104+
+extern int mp_camera_hal_set_res_raw(mp_camera_obj_t *self, int startX, int startY, int endX, int endY, int offsetX, int offsetY, int totalX, int totalY, int outputX, int outputY, bool scale, bool binning);
105+
+
106+
+#endif // MICROPY_INCLUDED_MODCAMERA_H
107+
diff --git a/src/modcamera_api.c b/src/modcamera_api.c
108+
index 39afa71..8f888ca 100644
109+
--- a/src/modcamera_api.c
110+
+++ b/src/modcamera_api.c
111+
@@ -285,6 +285,48 @@ CREATE_GETSET_FUNCTIONS(wpc, mp_obj_new_bool, mp_obj_is_true);
112+
CREATE_GETSET_FUNCTIONS(raw_gma, mp_obj_new_bool, mp_obj_is_true);
113+
CREATE_GETSET_FUNCTIONS(lenc, mp_obj_new_bool, mp_obj_is_true);
114+
115+
+// set_res_raw function for ROI (Region of Interest) / digital zoom
116+
+static mp_obj_t camera_set_res_raw(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
117+
+ mp_camera_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
118+
+ enum { ARG_startX, ARG_startY, ARG_endX, ARG_endY, ARG_offsetX, ARG_offsetY, ARG_totalX, ARG_totalY, ARG_outputX, ARG_outputY, ARG_scale, ARG_binning };
119+
+ static const mp_arg_t allowed_args[] = {
120+
+ { MP_QSTR_startX, MP_ARG_INT | MP_ARG_REQUIRED },
121+
+ { MP_QSTR_startY, MP_ARG_INT | MP_ARG_REQUIRED },
122+
+ { MP_QSTR_endX, MP_ARG_INT | MP_ARG_REQUIRED },
123+
+ { MP_QSTR_endY, MP_ARG_INT | MP_ARG_REQUIRED },
124+
+ { MP_QSTR_offsetX, MP_ARG_INT | MP_ARG_REQUIRED },
125+
+ { MP_QSTR_offsetY, MP_ARG_INT | MP_ARG_REQUIRED },
126+
+ { MP_QSTR_totalX, MP_ARG_INT | MP_ARG_REQUIRED },
127+
+ { MP_QSTR_totalY, MP_ARG_INT | MP_ARG_REQUIRED },
128+
+ { MP_QSTR_outputX, MP_ARG_INT | MP_ARG_REQUIRED },
129+
+ { MP_QSTR_outputY, MP_ARG_INT | MP_ARG_REQUIRED },
130+
+ { MP_QSTR_scale, MP_ARG_BOOL, {.u_bool = false} },
131+
+ { MP_QSTR_binning, MP_ARG_BOOL, {.u_bool = false} },
132+
+ };
133+
+
134+
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
135+
+ mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
136+
+
137+
+ int ret = mp_camera_hal_set_res_raw(
138+
+ self,
139+
+ args[ARG_startX].u_int,
140+
+ args[ARG_startY].u_int,
141+
+ args[ARG_endX].u_int,
142+
+ args[ARG_endY].u_int,
143+
+ args[ARG_offsetX].u_int,
144+
+ args[ARG_offsetY].u_int,
145+
+ args[ARG_totalX].u_int,
146+
+ args[ARG_totalY].u_int,
147+
+ args[ARG_outputX].u_int,
148+
+ args[ARG_outputY].u_int,
149+
+ args[ARG_scale].u_bool,
150+
+ args[ARG_binning].u_bool
151+
+ );
152+
+
153+
+ return mp_obj_new_int(ret);
154+
+}
155+
+static MP_DEFINE_CONST_FUN_OBJ_KW(camera_set_res_raw_obj, 1, camera_set_res_raw);
156+
+
157+
//API-Tables
158+
static const mp_rom_map_elem_t camera_camera_locals_table[] = {
159+
{ MP_ROM_QSTR(MP_QSTR_reconfigure), MP_ROM_PTR(&camera_reconfigure_obj) },
160+
@@ -293,6 +335,7 @@ static const mp_rom_map_elem_t camera_camera_locals_table[] = {
161+
{ MP_ROM_QSTR(MP_QSTR_free_buffer), MP_ROM_PTR(&camera_free_buf_obj) },
162+
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&camera_init_obj) },
163+
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&mp_camera_deinit_obj) },
164+
+ { MP_ROM_QSTR(MP_QSTR_set_res_raw), MP_ROM_PTR(&camera_set_res_raw_obj) },
165+
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_camera_deinit_obj) },
166+
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) },
167+
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_camera___exit___obj) },

scripts/cleanup_pyc.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
find internal_filesystem -iname "*.pyc" -exec rm {} \;

scripts/run_desktop.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ if [ -f "$script" ]; then
6262
"$binary" -v -i "$script"
6363
else
6464
echo "Running app $script"
65+
mv data/com.micropythonos.settings/config.json data/com.micropythonos.settings/config.json.backup
6566
# When $script is empty, it just doesn't find the app and stays at the launcher
6667
echo '{"auto_start_app": "'$script'"}' > data/com.micropythonos.settings/config.json
6768
"$binary" -X heapsize=$HEAPSIZE -v -i -c "$(cat main.py)"
69+
mv data/com.micropythonos.settings/config.json.backup data/com.micropythonos.settings/config.json
6870
fi
6971

7072
popd

0 commit comments

Comments
 (0)