pycamera: Add missing code for ControlTypePoint

In the python bindings ControlTypePoint is not handled in the
corresponding conversion functions. Add that.

While at it, sort the listings in the same order as the enum in
controls.h.

Fixes: 200d535ca8 ("libcamera: controls: Add ControlTypePoint")
Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Stefan Klug 2024-10-18 18:06:33 +02:00 committed by Kieran Bingham
parent ed3f3f6aa6
commit 2460049b67
2 changed files with 12 additions and 7 deletions

View file

@ -32,7 +32,8 @@ void init_py_enums(py::module &m)
.value("Float", ControlType::ControlTypeFloat) .value("Float", ControlType::ControlTypeFloat)
.value("String", ControlType::ControlTypeString) .value("String", ControlType::ControlTypeString)
.value("Rectangle", ControlType::ControlTypeRectangle) .value("Rectangle", ControlType::ControlTypeRectangle)
.value("Size", ControlType::ControlTypeSize); .value("Size", ControlType::ControlTypeSize)
.value("Point", ControlType::ControlTypePoint);
py::enum_<Orientation>(m, "Orientation") py::enum_<Orientation>(m, "Orientation")
.value("Rotate0", Orientation::Rotate0) .value("Rotate0", Orientation::Rotate0)

View file

@ -34,6 +34,8 @@ static py::object valueOrTuple(const ControlValue &cv)
py::object controlValueToPy(const ControlValue &cv) py::object controlValueToPy(const ControlValue &cv)
{ {
switch (cv.type()) { switch (cv.type()) {
case ControlTypeNone:
return py::none();
case ControlTypeBool: case ControlTypeBool:
return valueOrTuple<bool>(cv); return valueOrTuple<bool>(cv);
case ControlTypeByte: case ControlTypeByte:
@ -46,14 +48,14 @@ py::object controlValueToPy(const ControlValue &cv)
return valueOrTuple<float>(cv); return valueOrTuple<float>(cv);
case ControlTypeString: case ControlTypeString:
return py::cast(cv.get<std::string>()); return py::cast(cv.get<std::string>());
case ControlTypeRectangle:
return valueOrTuple<Rectangle>(cv);
case ControlTypeSize: { case ControlTypeSize: {
const Size *v = reinterpret_cast<const Size *>(cv.data().data()); const Size *v = reinterpret_cast<const Size *>(cv.data().data());
return py::cast(v); return py::cast(v);
} }
case ControlTypeNone: case ControlTypeRectangle:
return py::none(); return valueOrTuple<Rectangle>(cv);
case ControlTypePoint:
return valueOrTuple<Point>(cv);
default: default:
throw std::runtime_error("Unsupported ControlValue type"); throw std::runtime_error("Unsupported ControlValue type");
} }
@ -73,6 +75,8 @@ static ControlValue controlValueMaybeArray(const py::object &ob)
ControlValue pyToControlValue(const py::object &ob, ControlType type) ControlValue pyToControlValue(const py::object &ob, ControlType type)
{ {
switch (type) { switch (type) {
case ControlTypeNone:
return ControlValue();
case ControlTypeBool: case ControlTypeBool:
return ControlValue(ob.cast<bool>()); return ControlValue(ob.cast<bool>());
case ControlTypeByte: case ControlTypeByte:
@ -89,8 +93,8 @@ ControlValue pyToControlValue(const py::object &ob, ControlType type)
return controlValueMaybeArray<Rectangle>(ob); return controlValueMaybeArray<Rectangle>(ob);
case ControlTypeSize: case ControlTypeSize:
return ControlValue(ob.cast<Size>()); return ControlValue(ob.cast<Size>());
case ControlTypeNone: case ControlTypePoint:
return ControlValue(); return controlValueMaybeArray<Point>(ob);
default: default:
throw std::runtime_error("Control type not implemented"); throw std::runtime_error("Control type not implemented");
} }