Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

camera-manager: add absolute zoom #16

Merged
merged 1 commit into from
Mar 21, 2024
Merged
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
42 changes: 38 additions & 4 deletions camera-manager/siyi_camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "siyi_protocol.hpp"

#include <cassert>
#include <cmath>

namespace siyi {

Expand Down Expand Up @@ -311,7 +312,7 @@ class Camera {

_messager.send(_serializer.assemble_message(manual_zoom));

// We don't seem to be getting anything back.
// We don't seem to be getting anything back, it just times out.
//const auto maybe_ack_manual_zoom =
// _deserializer.disassemble_message<siyi::AckManualZoom>(_messager.receive());

Expand All @@ -323,8 +324,41 @@ class Camera {
return true;
}

[[nodiscard]] unsigned zoom() const {
return _ack_manual_zoom.zoom_multiple;
// Unavailable
//[[nodiscard]] unsigned zoom() const {
// return _ack_manual_zoom.zoom_multiple;
//}

bool absolute_zoom(float factor)
{
auto message = siyi::AbsoluteZoom{};

if (factor > static_cast<float>(0x1E)) {
std::cerr << "zoom factor too high" << std::endl;
return false;
}
if (factor < 1.f) {
std::cerr << "zoom factor too small" << std::endl;
return false;
}

message.absolute_movement_integer = static_cast<uint8_t>(factor);
message.absolute_movement_fractional = static_cast<uint8_t>(std::roundf((factor-static_cast<float>(message.absolute_movement_integer)) * 10.f));

std::cerr << "Sending abs zoom: " << (int)message.absolute_movement_integer << "." << (int)message.absolute_movement_fractional << std::endl;

_messager.send(_serializer.assemble_message(message));

// We don't seem to be getting anything back, it just times out.
//const auto maybe_ack_manual_zoom =
// _deserializer.disassemble_message<siyi::AckManualZoom>(_messager.receive());

//if (maybe_ack_manual_zoom) {
// std::cerr << "current zoom: " << maybe_ack_manual_zoom.value().zoom_multiple << '\n';
// _ack_manual_zoom = maybe_ack_manual_zoom.value();
// return false;
//}
return true;
}

private:
Expand All @@ -335,7 +369,7 @@ class Camera {
AckFirmwareVersion _version{};
AckGetStreamResolution _recording_settings{};
AckGetStreamResolution _stream_settings{};
AckManualZoom _ack_manual_zoom{};
// AckManualZoom _ack_manual_zoom{};
};

} // siyi
23 changes: 20 additions & 3 deletions camera-manager/siyi_cli.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "siyi_camera.hpp"
#include <cstdlib>
#include <iostream>
#include <string>
#include <string_view>

void print_usage(const std::string_view& bin_name)
Expand All @@ -19,6 +20,7 @@ void print_usage(const std::string_view& bin_name)
<< " - in (to start zooming in)\n"
<< " - out (to start zooming out)\n"
<< " - stop (to stop zooming)\n"
<< " - <factor> (1.0 to 6.0)\n"
<< "\n"
<< " get <stream|recording> settings Show all settings for stream or recording\n\n"
<< "\n"
Expand Down Expand Up @@ -287,16 +289,31 @@ int main(int argc, char* argv[])
return 1;
}
} else {
std::cout << "Invalid zoom command" << std::endl;
print_usage(argv[0]);
return 1;
float factor;
try {
factor = std::stof(option.data());
} catch (std::invalid_argument&) {
std::cout << "Invalid zoom command" << std::endl;
print_usage(argv[0]);
return 1;
};
siyi_camera.absolute_zoom(factor);
}
} else {
std::cout << "Not enough arguments\n";
print_usage(argv[0]);
return 1;
}

} else if (action == "zoom") {
if (argc >= 3) {

} else {
std::cout << "Not enough arguments\n";
print_usage(argv[0]);
return 1;
}

} else {
std::cout << "Unknown command\n";
print_usage(argv[0]);
Expand Down
1 change: 1 addition & 0 deletions camera-manager/siyi_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bool Messager::send(const std::vector<std::uint8_t>& message)
std::cerr << "Error sending UDP packet: " << strerror(errno) << std::endl;
return false;
}
// std::cerr << "Sent " << sent << std::endl;
return true;
}

Expand Down
17 changes: 17 additions & 0 deletions camera-manager/siyi_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,23 @@ class ManualZoom : public Payload<ManualZoom> {
std::int8_t zoom{};
};

class AbsoluteZoom : public Payload<AbsoluteZoom> {
public:
[[nodiscard]] std::vector<std::uint8_t> bytes_impl() const {
std::vector<std::uint8_t> result;
result.push_back(absolute_movement_integer);
result.push_back(absolute_movement_fractional);
return result;
}

static std::uint8_t cmd_id_impl() {
return 0x0F;
}

std::uint8_t absolute_movement_integer{};
std::uint8_t absolute_movement_fractional{};
};

class Messager
{
public:
Expand Down
Loading