Skip to content

Commit

Permalink
Merge pull request #18 from julianoes/pr-camera-manager-zoom
Browse files Browse the repository at this point in the history
camera-manager: add zoom
  • Loading branch information
julianoes authored Mar 25, 2024
2 parents e6f8875 + b8e58b2 commit 9dc1c41
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rpi-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
apt-get update
apt-get install -y libgstreamer1.0-dev libgstrtspserver-1.0-dev build-essential cmake git wget rubygems
gem install fpm
wget https://github.com/mavlink/MAVSDK/releases/download/v2.4.0/libmavsdk-dev_2.4.0_debian12_arm64.deb
dpkg -i libmavsdk-dev_2.4.0_debian12_arm64.deb
rm libmavsdk-dev_2.4.0_debian12_arm64.deb
wget https://github.com/mavlink/MAVSDK/releases/download/v2.6.0/libmavsdk-dev_2.6.0_debian12_arm64.deb
dpkg -i libmavsdk-dev_2.6.0_debian12_arm64.deb
rm libmavsdk-dev_2.6.0_debian12_arm64.deb
git config --global --add safe.directory "$GITHUB_WORKSPACE"
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=install -Bbuild -S.
cmake --build build -j$(nproc) --target install
Expand Down
31 changes: 31 additions & 0 deletions camera-manager/camera_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,37 @@ int main(int argc, char* argv[])
storage_information);
});

camera_server.subscribe_zoom_range([&](float zoom_factor) {
if (zoom_factor < 1.f) {
std::cout << "Zoom below 1x not possible" << std::endl;
camera_server.respond_zoom_range(mavsdk::CameraServer::CameraFeedback::Failed);
return;
}
if (zoom_factor > 6.f) {
std::cout << "Zoom above 6x not possible" << std::endl;
camera_server.respond_zoom_range(mavsdk::CameraServer::CameraFeedback::Failed);
return;
}

siyi_camera.absolute_zoom(zoom_factor);
camera_server.respond_zoom_range(mavsdk::CameraServer::CameraFeedback::Ok);
});

camera_server.subscribe_zoom_in_start([&](int) {
siyi_camera.zoom(siyi::Camera::Zoom::In);
camera_server.respond_zoom_in_start(mavsdk::CameraServer::CameraFeedback::Ok);
});

camera_server.subscribe_zoom_out_start([&](int) {
siyi_camera.zoom(siyi::Camera::Zoom::Out);
camera_server.respond_zoom_in_start(mavsdk::CameraServer::CameraFeedback::Ok);
});

camera_server.subscribe_zoom_stop([&](int) {
siyi_camera.zoom(siyi::Camera::Zoom::Stop);
camera_server.respond_zoom_stop(mavsdk::CameraServer::CameraFeedback::Ok);
});

// Run as a server and never quit
while (true) {
std::this_thread::sleep_for(std::chrono::seconds(1));
Expand Down
3 changes: 3 additions & 0 deletions camera-manager/siyi_camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,14 @@ class Camera {
switch (option) {
case Zoom::In:
manual_zoom.zoom = 1;
std::cerr << "Starting to zoom in" << std::endl;
break;
case Zoom::Out:
manual_zoom.zoom = -1;
std::cerr << "Starting to zoom out" << std::endl;
break;
case Zoom::Stop:
std::cerr << "Stopping to zoom" << std::endl;
manual_zoom.zoom = 0;
break;
}
Expand Down

0 comments on commit 9dc1c41

Please sign in to comment.