duvc-ctl 2.0.0
USB Video Class Camera Control Library
Loading...
Searching...
No Matches
logitech.cpp
Go to the documentation of this file.
1
6#ifdef _WIN32
7
11
12#include <ks.h>
13#include <ksproxy.h>
14
15// IF ks.h not available, define manually:
16#ifndef KSPROPERTY_SUPPORT_GET
17#define KSPROPERTY_SUPPORT_GET 1
18#define KSPROPERTY_SUPPORT_SET 2
19#endif
20
21namespace duvc::logitech {
22
25 try {
26 KsPropertySet prop_set(device);
27 if (!prop_set.is_valid()) {
30 "Device does not support vendor properties");
31 }
32
33 return prop_set.get_property(LOGITECH_PROPERTY_SET,
34 static_cast<uint32_t>(prop));
35
36 } catch (const std::exception &e) {
37 DUVC_LOG_ERROR("Exception getting Logitech property: " +
38 std::string(e.what()));
40 }
41}
42
44 const std::vector<uint8_t> &data) {
45 try {
46 KsPropertySet prop_set(device);
47 if (!prop_set.is_valid()) {
49 "Device does not support vendor properties");
50 }
51
52 return prop_set.set_property(LOGITECH_PROPERTY_SET,
53 static_cast<uint32_t>(prop), data);
54
55 } catch (const std::exception &e) {
56 DUVC_LOG_ERROR("Exception setting Logitech property: " +
57 std::string(e.what()));
58 return Err<void>(ErrorCode::SystemError, e.what());
59 }
60}
61
63 try {
64 KsPropertySet prop_set(device);
65 if (!prop_set.is_valid()) {
66 return Ok(false);
67 }
68
69 // Try to query support for a basic property
70 auto result = prop_set.query_support(
73
74 if (result.is_ok()) {
76 return Ok((support_flags &
78 }
79
80 return Ok(false);
81
82 } catch (const std::exception &e) {
83 DUVC_LOG_DEBUG("Exception checking Logitech support: " +
84 std::string(e.what()));
85 return Ok(false); // Assume not supported on error
86 }
87}
88
89template <typename T>
93 if (!data_result.is_ok()) {
94 return Err<T>(data_result.error());
95 }
96
97 const auto &data = data_result.value();
98 if (data.size() != sizeof(T)) {
100 "Property data size mismatch for Logitech property");
101 }
102
103 T value;
104 std::memcpy(&value, data.data(), sizeof(T));
105 return Ok(value);
106}
107
108template <typename T>
111 const T &value) {
112 std::vector<uint8_t> data(sizeof(T));
113 std::memcpy(data.data(), &value, sizeof(T));
114 return set_logitech_property(device, prop, data);
115}
116
117// Explicit template instantiations for common types
124
127 const uint32_t &);
130 const int32_t &);
133 const bool &);
134
135} // namespace duvc::logitech
136
137#endif // _WIN32
#define DUVC_LOG_ERROR(msg)
Definition api.h:1077
#define DUVC_LOG_DEBUG(msg)
Definition api.h:1074
RAII wrapper for IKsPropertySet interface.
Result type that can contain either a value or an error.
Definition result.h:75
const T & value() const &
Get the value (assumes success)
Definition result.h:114
bool is_ok() const
Check if result contains a value (success)
Definition result.h:101
const Error & error() const
Get the error (assumes error)
Definition result.h:128
IKsPropertySet wrapper for vendor properties.
Structured logging interface for duvc-ctl.
#define KSPROPERTY_SUPPORT_SET
Definition logitech.cpp:18
#define KSPROPERTY_SUPPORT_GET
Definition logitech.cpp:17
Logitech-specific vendor property definitions and helpers.
template Result< void > set_logitech_property_typed< int32_t >(const Device &, LogitechProperty, const int32_t &)
Result< void > set_logitech_property_typed(const Device &device, LogitechProperty prop, const T &value)
Set typed Logitech property value.
Definition logitech.cpp:109
template Result< void > set_logitech_property_typed< uint32_t >(const Device &, LogitechProperty, const uint32_t &)
Result< bool > supports_logitech_properties(const Device &device)
Check if device supports Logitech vendor properties.
Definition logitech.cpp:62
Result< void > set_logitech_property(const Device &device, LogitechProperty prop, const std::vector< uint8_t > &data)
Set Logitech vendor property from raw byte vector.
Definition logitech.cpp:43
Result< T > get_logitech_property_typed(const Device &device, LogitechProperty prop)
Get typed Logitech property value.
Definition logitech.cpp:90
Result< std::vector< uint8_t > > get_logitech_property(const Device &device, LogitechProperty prop)
Get Logitech vendor property as raw byte vector.
Definition logitech.cpp:23
LogitechProperty
Logitech vendor property IDs.
Definition logitech.h:40
@ RightLight
RightLight auto-exposure and brightness optimization.
constexpr GUID LOGITECH_PROPERTY_SET
Logitech vendor-specific property set GUID.
Definition logitech.h:28
template Result< bool > get_logitech_property_typed< bool >(const Device &, LogitechProperty)
template Result< void > set_logitech_property_typed< bool >(const Device &, LogitechProperty, const bool &)
template Result< int32_t > get_logitech_property_typed< int32_t >(const Device &, LogitechProperty)
template Result< uint32_t > get_logitech_property_typed< uint32_t >(const Device &, LogitechProperty)
@ InvalidValue
Property value out of range.
@ PropertyNotSupported
Property not supported by device.
@ SystemError
System/platform error.
Result< void > Ok()
Helper to create successful void Result.
Definition result.h:222
Represents a camera device.
Definition types.h:131