|
3 | 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | 4 |
|
5 | 5 | #include "GPhoto2Integration.hpp" |
| 6 | + |
6 | 7 | #include <QImage> |
| 8 | +#include <fstream> |
7 | 9 | #include <Pbox/Logger.hpp> |
8 | 10 | #include "GPhoto2Context.hpp" |
9 | 11 |
|
@@ -109,17 +111,49 @@ std::optional<QImage> captureImage(Context &context) |
109 | 111 | gp_camera_capture(context.camera.get(), GP_CAPTURE_IMAGE, &camera_file_path, context.context.get()); |
110 | 112 | if (ret_val < GP_OK) |
111 | 113 | { |
112 | | - LOG_ERROR(logger_gphoto2(), "could invoke gphoto2 capture"); |
| 114 | + LOG_ERROR(logger_gphoto2(), "could not invoke gphoto2 capture: {}", ret_val); |
113 | 115 | return std::nullopt; |
114 | 116 | } |
115 | | - gp_camera_file_get(context.camera.get(), |
116 | | - camera_file_path.folder, |
117 | | - camera_file_path.name, |
118 | | - GP_FILE_TYPE_NORMAL, |
119 | | - file.get(), |
120 | | - context.context.get()); |
| 117 | + LOG_INFO(logger_gphoto2(), "captured image to {}", camera_file_path.name); |
| 118 | + |
| 119 | + const auto file_get_ret_val = gp_camera_file_get(context.camera.get(), |
| 120 | + camera_file_path.folder, |
| 121 | + camera_file_path.name, |
| 122 | + GP_FILE_TYPE_NORMAL, |
| 123 | + file.get(), |
| 124 | + context.context.get()); |
| 125 | + if (file_get_ret_val < GP_OK) |
| 126 | + { |
| 127 | + LOG_ERROR(logger_gphoto2(), "could not get file: {}", file_get_ret_val); |
| 128 | + } |
121 | 129 |
|
122 | | - return readImageFromFile(file.get()); |
| 130 | + auto image = readImageFromFile(file.get()); |
| 131 | + |
| 132 | + return image; |
| 133 | +} |
| 134 | +bool readUntilTimeout(Context &context) |
| 135 | +{ |
| 136 | + while (true) |
| 137 | + { |
| 138 | + CameraEventType evtype; |
| 139 | + void *data = nullptr; |
| 140 | + |
| 141 | + const int ret = gp_camera_wait_for_event(context.camera.get(), 100, &evtype, &data, context.context.get()); |
| 142 | + |
| 143 | + if (ret < GP_OK) |
| 144 | + { |
| 145 | + LOG_ERROR(logger_gphoto2(), "could not wait for event: {}", ret); |
| 146 | + break; |
| 147 | + } |
| 148 | + |
| 149 | + if (evtype == GP_EVENT_TIMEOUT) |
| 150 | + { |
| 151 | + LOG_DEBUG(logger_gphoto2(), "got timeout event"); |
| 152 | + return true; |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + return false; |
123 | 157 | } |
124 | 158 |
|
125 | 159 | namespace |
|
0 commit comments