Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Photobox/GPhoto2/Source/GPhoto2Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ exec::task<void> GPhoto2Camera::asyncCaptureLoop()
Q_EMIT imageCaptured(image.value());
}
return image.has_value();
}) //
| stdexec::continues_on(scheduler_->getWorkScheduler()) //
| stdexec::then([this, &context](auto hasValue) {
return GPhoto2::readUntilTimeout(*context);
}) //
| exec::repeat_effect_until(); // todo: this now retries forever to capture a image.
// maybe retry_n times and emit an error?
Expand Down
48 changes: 40 additions & 8 deletions Photobox/GPhoto2/Source/GPhoto2Integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,49 @@ std::optional<QImage> captureImage(Context &context)
gp_camera_capture(context.camera.get(), GP_CAPTURE_IMAGE, &camera_file_path, context.context.get());
if (ret_val < GP_OK)
{
LOG_ERROR(logger_gphoto2(), "could invoke gphoto2 capture");
LOG_ERROR(logger_gphoto2(), "could not invoke gphoto2 capture: {}", ret_val);
return std::nullopt;
}
gp_camera_file_get(context.camera.get(),
camera_file_path.folder,
camera_file_path.name,
GP_FILE_TYPE_NORMAL,
file.get(),
context.context.get());
LOG_INFO(logger_gphoto2(), "captured image to {}", camera_file_path.name);

const auto file_get_ret_val = gp_camera_file_get(context.camera.get(),
camera_file_path.folder,
camera_file_path.name,
GP_FILE_TYPE_NORMAL,
file.get(),
context.context.get());
if (file_get_ret_val < GP_OK)
{
LOG_ERROR(logger_gphoto2(), "could not get file: {}", file_get_ret_val);
}

return readImageFromFile(file.get());
auto image = readImageFromFile(file.get());

return image;
}
bool readUntilTimeout(Context &context)
{
while (true)
{
CameraEventType evtype;
void *data = nullptr;

const int ret = gp_camera_wait_for_event(context.camera.get(), 100, &evtype, &data, context.context.get());

if (ret < GP_OK)
{
LOG_ERROR(logger_gphoto2(), "could not wait for event: {}", ret);
break;
}

if (evtype == GP_EVENT_TIMEOUT)
{
LOG_DEBUG(logger_gphoto2(), "got timeout event");
return true;
}
}

return false;
}

namespace
Expand Down
2 changes: 2 additions & 0 deletions Photobox/GPhoto2/Source/GPhoto2Integration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ bool autodetectAndConnectCamera(Context &context);
std::optional<QImage> capturePreviewImage(Context &context);

std::optional<QImage> captureImage(Context &context);

bool readUntilTimeout(Context &context);
} // namespace Pbox::GPhoto2