From 5be47846e7c9f4e574167e444701b2fb102df0b3 Mon Sep 17 00:00:00 2001 From: kalman Date: Thu, 31 May 2018 15:09:00 +0800 Subject: [PATCH] change the way to get xu control's range --- src/internal/channels.cc | 16 +++++----------- src/internal/channels.h | 4 ++-- src/uvc/uvc-libuvc.cc | 2 +- src/uvc/uvc-v4l2.cc | 11 +++++++++-- src/uvc/uvc-wmf.cc | 24 ++++++++++++++++++++++++ src/uvc/uvc.h | 4 ++-- 6 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/internal/channels.cc b/src/internal/channels.cc index b8841db..3fcd3e8 100644 --- a/src/internal/channels.cc +++ b/src/internal/channels.cc @@ -838,15 +838,15 @@ bool Channels::PuControlQuery( } bool Channels::XuControlRange( - channel_t channel, int32_t *min, int32_t *max, int32_t *def) const { - return XuControlRange(mynteye_xu, channel, min, max, def); + channel_t channel, uint8_t id, int32_t *min, int32_t *max, int32_t *def) const { + return XuControlRange(mynteye_xu, channel, id, min, max, def); } bool Channels::XuControlRange( - const uvc::xu &xu, uint8_t selector, int32_t *min, int32_t *max, + const uvc::xu &xu, uint8_t selector, uint8_t id, int32_t *min, int32_t *max, int32_t *def) const { CHECK_NOTNULL(device_); - return uvc::xu_control_range(*device_, xu, selector, min, max, def); + return uvc::xu_control_range(*device_, xu, selector, id, min, max, def); } bool Channels::XuControlQuery( @@ -983,14 +983,8 @@ Channels::control_info_t Channels::PuControlInfo(Option option) const { Channels::control_info_t Channels::XuControlInfo(Option option) const { int id = XuCamCtrlId(option); - std::uint8_t data[3] = {static_cast((id | 0x80) & 0xFF), 0, 0}; - if (!XuCamCtrlQuery(uvc::XU_QUERY_SET, 3, data)) { - LOG(WARNING) << "Get XuControlInfo of " << option << " failed"; - return {0, 0, 0}; - } - int32_t min = 0, max = 0, def = 0; - if (!XuControlRange(CHANNEL_CAM_CTRL, &min, &max, &def)) { + if (!XuControlRange(CHANNEL_CAM_CTRL, static_cast(id), &min, &max, &def)) { LOG(WARNING) << "Get XuControlInfo of " << option << " failed"; } return {min, max, def}; diff --git a/src/internal/channels.h b/src/internal/channels.h index d4e2d78..c80c620 100644 --- a/src/internal/channels.h +++ b/src/internal/channels.h @@ -98,9 +98,9 @@ class MYNTEYE_API Channels { bool PuControlQuery(Option option, uvc::pu_query query, int32_t *value) const; bool XuControlRange( - channel_t channel, int32_t *min, int32_t *max, int32_t *def) const; + channel_t channel, uint8_t id, int32_t *min, int32_t *max, int32_t *def) const; bool XuControlRange( - const uvc::xu &xu, uint8_t selector, int32_t *min, int32_t *max, + const uvc::xu &xu, uint8_t selector, uint8_t id, int32_t *min, int32_t *max, int32_t *def) const; bool XuControlQuery( diff --git a/src/uvc/uvc-libuvc.cc b/src/uvc/uvc-libuvc.cc index e3e2c34..242c098 100644 --- a/src/uvc/uvc-libuvc.cc +++ b/src/uvc/uvc-libuvc.cc @@ -132,7 +132,7 @@ bool pu_control_query( } bool xu_control_range( - const device &device, const xu &xu, uint8_t selector, int32_t *min, + const device &device, const xu &xu, uint8_t selector, uint8_t id, int32_t *min, int32_t *max, int32_t *def) { // TODO(JohnZhao) UNUSED(device) diff --git a/src/uvc/uvc-v4l2.cc b/src/uvc/uvc-v4l2.cc index 91b2540..5f47eb6 100755 --- a/src/uvc/uvc-v4l2.cc +++ b/src/uvc/uvc-v4l2.cc @@ -492,10 +492,17 @@ bool pu_control_query( } bool xu_control_range( - const device &device, const xu &xu, uint8_t selector, int32_t *min, - int32_t *max, int32_t *def) { + const device &device, const xu &xu, uint8_t selector, uint8_t id, + int32_t *min, int32_t *max, int32_t *def) { bool ret = true; std::uint8_t data[3]{}; + std::uint8_t query_id[3]{(id | 0x80), 0, 0}; + + if(!xu_control_query(device, xu, selcetor, XU_QUERY_SET, 3, query_id)) { + LOG(WARNING) << "xu_control_range query failed"; + ret = false; + } + if (xu_control_query(device, xu, selcetor, XU_QUERY_MIN, 3, data)) { *min = (data[1] << 8) | (data[2]); } else { diff --git a/src/uvc/uvc-wmf.cc b/src/uvc/uvc-wmf.cc index d350a73..29aaf6d 100644 --- a/src/uvc/uvc-wmf.cc +++ b/src/uvc/uvc-wmf.cc @@ -565,6 +565,7 @@ static std::string to_string(uint16_t size, uint8_t *data) { return ss.str(); } +/* static std::vector xu_control_desc(const device &device, const xu &xu, ULONG id, ULONG flags) { auto ks_control = const_cast(device).get_ks_control(xu); @@ -640,6 +641,7 @@ bool xu_control_range( << ": min=" << *min << ", max=" << *max << ", def=" << *def; return true; } +*/ static void xu_control_get(const device &device, const xu &xu, uint8_t selector, uint16_t size, uint8_t *data) { @@ -682,6 +684,28 @@ static void xu_control_set(const device &device, const xu &xu, uint8_t selector, VLOG_INFO << __func__ << " " << static_cast(selector) << " done"; } +static int32_t xu_control_range_basic(const device &device, const xu &xu, uint8_t selector, uint8_t id) { + int32_t value = 0; + std::uint8_t data[3]{}; + std::uint8_t query_id[3]{id, 0, 0}; + + xu_control_set(device,xu,selector,3,query_id); + xu_control_get(device,xu,selector,3,data); + value = (data[1] << 8) | (data[2]); + + return value; +} + +bool xu_control_range( + const device &device, const xu &xu, uint8_t selector, uint8_t id, + int32_t *min, int32_t *max, int32_t *def) { + VLOG_INFO << __func__ << " " << static_cast(selector); + *min = xu_control_range_basic(device,xu,selector,id|0x90); + *max = xu_control_range_basic(device,xu,selector,id|0xa0); + *def = xu_control_range_basic(device,xu,selector,id|0xc0); + return true; +} + bool xu_control_query( const device &device, const xu &xu, uint8_t selector, xu_query query, uint16_t size, uint8_t *data) { diff --git a/src/uvc/uvc.h b/src/uvc/uvc.h index 2f9a970..2d35f42 100644 --- a/src/uvc/uvc.h +++ b/src/uvc/uvc.h @@ -73,8 +73,8 @@ MYNTEYE_API bool pu_control_query( // Access XU (Extension Unit) controls MYNTEYE_API bool xu_control_range( - const device &device, const xu &xu, uint8_t selector, int32_t *min, - int32_t *max, int32_t *def); + const device &device, const xu &xu, uint8_t selector, uint8_t id, + int32_t *min, int32_t *max, int32_t *def); MYNTEYE_API bool xu_control_query( // XU_QUERY_SET, XU_QUERY_GET const device &device, const xu &xu, uint8_t selector, xu_query query, uint16_t size, uint8_t *data);