Implement close command

This commit is contained in:
Martijn Braam
2023-07-08 20:59:07 +02:00
parent 4e17daf32e
commit 2ee1da5bfe
2 changed files with 27 additions and 0 deletions

View File

@@ -90,6 +90,9 @@ libmegapixels_load_file(libmegapixels_devconfig **config, const char *file);
EXPORT int EXPORT int
libmegapixels_open(libmegapixels_camera *camera); libmegapixels_open(libmegapixels_camera *camera);
EXPORT void
libmegapixels_close(libmegapixels_camera *camera);
EXPORT unsigned int EXPORT unsigned int
libmegapixels_select_mode(libmegapixels_camera *camera, libmegapixels_mode *mode); libmegapixels_select_mode(libmegapixels_camera *camera, libmegapixels_mode *mode);

View File

@@ -169,6 +169,30 @@ libmegapixels_open(libmegapixels_camera *camera)
return 0; 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 unsigned int
libmegapixels_select_mode(libmegapixels_camera *camera, libmegapixels_mode *mode) libmegapixels_select_mode(libmegapixels_camera *camera, libmegapixels_mode *mode)
{ {