[libcamera-devel,RFC,v2,1/5] libcamera: Controls: Add ControlTypeMenu
diff mbox series

Message ID 20210413075013.3069213-2-hiroh@chromium.org
State Superseded
Headers show
Series
  • Report available test pattern modes
Related show

Commit Message

Hirokazu Honda April 13, 2021, 7:50 a.m. UTC
This adds control type for v4l2 menu.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
---
 include/libcamera/controls.h | 28 ++++++++++++++++++++++++++++
 src/libcamera/controls.cpp   |  7 +++++++
 2 files changed, 35 insertions(+)

Patch
diff mbox series

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 1a5690a5..357819e7 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -9,6 +9,7 @@ 
 #define __LIBCAMERA_CONTROLS_H__
 
 #include <assert.h>
+#include <sstream>
 #include <stdint.h>
 #include <string>
 #include <unordered_map>
@@ -32,6 +33,28 @@  enum ControlType {
 	ControlTypeString,
 	ControlTypeRectangle,
 	ControlTypeSize,
+	ControlTypeMenu,
+};
+
+struct ControlMenu {
+	uint32_t index;
+	bool isName = false;
+
+	union {
+		char name[28];
+		int64_t value;
+	};
+
+	std::string toString() const
+	{
+		std::stringstream ss;
+		ss << "index: " << index;
+		if (isName)
+			ss << "name: " << name;
+		else
+			ss << "value: " << value;
+		return ss.str();
+	}
 };
 
 namespace details {
@@ -85,6 +108,11 @@  struct control_type<Size> {
 	static constexpr ControlType value = ControlTypeSize;
 };
 
+template<>
+struct control_type<ControlMenu> {
+	static constexpr ControlType value = ControlTypeMenu;
+};
+
 template<typename T, std::size_t N>
 struct control_type<Span<T, N>> : public control_type<std::remove_cv_t<T>> {
 };
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index c58ed394..8ab5ac92 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -60,6 +60,7 @@  static constexpr size_t ControlValueSize[] = {
 	[ControlTypeString]		= sizeof(char),
 	[ControlTypeRectangle]		= sizeof(Rectangle),
 	[ControlTypeSize]		= sizeof(Size),
+	[ControlTypeMenu]		= sizeof(ControlMenu),
 };
 
 } /* namespace */
@@ -254,6 +255,12 @@  std::string ControlValue::toString() const
 			str += value->toString();
 			break;
 		}
+		case ControlTypeMenu: {
+			const ControlMenu *value =
+				reinterpret_cast<const ControlMenu *>(data);
+			str += value->toString();
+			break;
+		}
 		case ControlTypeNone:
 		case ControlTypeString:
 			break;