From 2ee1da5bfef095c97e0a52eb8ed97ba6d34657b7 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Sat, 8 Jul 2023 20:59:07 +0200 Subject: [PATCH] Implement close command --- include/libmegapixels.h | 3 +++ src/pipeline.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/libmegapixels.h b/include/libmegapixels.h index d7e33a8..06c78aa 100644 --- a/include/libmegapixels.h +++ b/include/libmegapixels.h @@ -90,6 +90,9 @@ libmegapixels_load_file(libmegapixels_devconfig **config, const char *file); EXPORT int libmegapixels_open(libmegapixels_camera *camera); +EXPORT void +libmegapixels_close(libmegapixels_camera *camera); + EXPORT unsigned int libmegapixels_select_mode(libmegapixels_camera *camera, libmegapixels_mode *mode); diff --git a/src/pipeline.c b/src/pipeline.c index 9047d99..80275e7 100644 --- a/src/pipeline.c +++ b/src/pipeline.c @@ -169,6 +169,30 @@ libmegapixels_open(libmegapixels_camera *camera) return 0; } +void +libmegapixels_close(libmegapixels_camera *camera) +{ + if (camera->media_fd != 0) { + close(camera->media_fd); + camera->media_fd = 0; + } + if (camera->sensor_fd != 0) { + close(camera->sensor_fd); + camera->sensor_fd = 0; + } + if (camera->video_fd != 0) { + close(camera->video_fd); + camera->video_fd = 0; + } + + for (int i = 0; i < camera->num_handles; i++) { + if (camera->handles[i]->fd != 0) { + close(camera->handles[i]->fd); + camera->handles[i]->fd = 0; + } + } +} + unsigned int libmegapixels_select_mode(libmegapixels_camera *camera, libmegapixels_mode *mode) {