Skip to content

Commit 8bff420

Browse files
committed
minor improvements
1 parent 5a96826 commit 8bff420

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

examples/CameraSettings.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
cam = Camera(frame_size=FrameSize.VGA, pixel_format=PixelFormat.JPEG, jpeg_quality=85, init=False)
77
# WLAN config
8-
ssid = 'Zopilote'
9-
password = '2018@Ihringen'
8+
ssid = '<yourSSID>'
9+
password = '<yourPW>'
1010

1111
station = network.WLAN(network.STA_IF)
1212
station.active(True)
@@ -87,16 +87,15 @@ async def handle_client(reader, writer):
8787
writer.close()
8888
await writer.wait_closed()
8989

90-
# Funktion zum Starten des Servers
9190
async def start_server():
9291
server = await asyncio.start_server(handle_client, "0.0.0.0", 80)
9392
print(f'Server is running on {station.ifconfig()[0]}:80')
9493
while True:
95-
await asyncio.sleep(3600) # Server läuft kontinuierlich; wir blockieren die Schleife
94+
await asyncio.sleep(3600)
9695

97-
# Starte den asyncio-Loop
9896
try:
9997
asyncio.run(start_server())
10098
except KeyboardInterrupt:
99+
cam.deinit()
101100
print("Server stopped")
102101

src/modcamera.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ static int map(int value, int fromLow, int fromHigh, int toLow, int toHigh) {
7979
return (int)((int32_t)(value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow);
8080
}
8181

82+
static int get_mapped_jpeg_quality(int8_t quality) {
83+
return map(quality, 0, 100, 63, 0);
84+
}
85+
8286
// Camera HAL Funcitons
8387
void mp_camera_hal_construct(
8488
mp_camera_obj_t *self,
@@ -153,7 +157,7 @@ void mp_camera_hal_init(mp_camera_obj_t *self) {
153157
camera_config_t temp_config = self->camera_config;
154158
temp_config.frame_size = FRAMESIZE_QVGA; //use values supported by all cameras
155159
temp_config.pixel_format = PIXFORMAT_RGB565; //use values supported by all cameras
156-
temp_config.jpeg_quality = (int8_t)map(self->camera_config.jpeg_quality,0,100,63,0);
160+
temp_config.jpeg_quality = get_mapped_jpeg_quality(self->camera_config.jpeg_quality);
157161
esp_err_t err = esp_camera_init(&temp_config);
158162
if (err != ESP_OK) {
159163
self->initialized = false;
@@ -223,7 +227,7 @@ void mp_camera_hal_reconfigure(mp_camera_obj_t *self, mp_camera_framesize_t fram
223227

224228
// Correct the quality before it is passed to esp32 driver and then "undo" the correction in the camera_config
225229
int8_t api_jpeg_quality = self->camera_config.jpeg_quality;
226-
self->camera_config.jpeg_quality = (int8_t)map(api_jpeg_quality,0,100,63,0);
230+
self->camera_config.jpeg_quality = get_mapped_jpeg_quality(api_jpeg_quality);
227231
esp_err_t err = esp_camera_init(&self->camera_config);
228232
self->camera_config.jpeg_quality = api_jpeg_quality;
229233

@@ -433,7 +437,7 @@ void mp_camera_hal_set_quality(mp_camera_obj_t * self, int value) {
433437
if (!sensor->set_quality) {
434438
mp_raise_ValueError(MP_ERROR_TEXT("No attribute quality"));
435439
}
436-
if (sensor->set_quality(sensor, map(value,0,100,63,0)) < 0) {
440+
if (sensor->set_quality(sensor, get_mapped_jpeg_quality(value)) < 0) {
437441
mp_raise_ValueError(MP_ERROR_TEXT("Invalid setting for quality"));
438442
} else {
439443
self->camera_config.jpeg_quality = value;

0 commit comments

Comments
 (0)