From 49de28d3d0ee0cd6d70a96bc8ffe260674ed4689 Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Mon, 1 May 2017 23:44:09 -0400 Subject: [PATCH] Add overloads for property types except enum (#73) - Fixes #70 --- include/cscore_oo.h | 28 ++++++++++++++++++++++ include/cscore_oo.inl | 30 +++++++++++++++++++++++ java/src/edu/wpi/cscore/CvSource.java | 34 +++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/include/cscore_oo.h b/include/cscore_oo.h index 2114963c5d..afe33e0789 100644 --- a/include/cscore_oo.h +++ b/include/cscore_oo.h @@ -408,6 +408,34 @@ class CvSource : public VideoSource { int minimum, int maximum, int step, int defaultValue, int value); + /// Create an integer property. + /// @param name Property name + /// @param minimum Minimum value + /// @param maximum Maximum value + /// @param step Step value + /// @param defaultValue Default value + /// @param value Current value + /// @return Property + VideoProperty CreateIntegerProperty(llvm::StringRef name, + int minimum, int maximum, int step, + int defaultValue, int value); + + /// Create a boolean property. + /// @param name Property name + /// @param defaultValue Default value + /// @param value Current value + /// @return Property + VideoProperty CreateBooleanProperty(llvm::StringRef name, + bool defaultValue, bool value); + + /// Create a string property. + /// @param name Property name + /// @param defaultValue Default value + /// @param value Current value + /// @return Property + VideoProperty CreateStringProperty(llvm::StringRef name, + llvm::StringRef value); + /// Configure enum property choices. /// @param property Property /// @param choices Choices diff --git a/include/cscore_oo.inl b/include/cscore_oo.inl index 7c545cc4b0..be31d376b9 100644 --- a/include/cscore_oo.inl +++ b/include/cscore_oo.inl @@ -369,6 +369,36 @@ inline VideoProperty CvSource::CreateProperty(llvm::StringRef name, minimum, maximum, step, defaultValue, value, &m_status)}; } +inline VideoProperty CvSource::CreateIntegerProperty(llvm::StringRef name, + int minimum, int maximum, + int step, int defaultValue, + int value) { + m_status = 0; + return VideoProperty{CreateSourceProperty( + m_handle, name, static_cast(static_cast(VideoProperty::Kind::kInteger)), + minimum, maximum, step, defaultValue, value, &m_status)}; +} + +inline VideoProperty CvSource::CreateBooleanProperty(llvm::StringRef name, + bool defaultValue, + bool value) { + m_status = 0; + return VideoProperty{CreateSourceProperty( + m_handle, name, static_cast(static_cast(VideoProperty::Kind::kBoolean)), + 0, 1, 1, defaultValue ? 1 : 0, value ? 1 : 0, &m_status)}; +} + +inline VideoProperty CvSource::CreateStringProperty(llvm::StringRef name, + llvm::StringRef value) { + m_status = 0; + auto prop = VideoProperty{CreateSourceProperty( + m_handle, name, static_cast(static_cast(VideoProperty::Kind::kString)), + 0, 0, 0, 0, 0, &m_status)}; + prop.SetString(value); + return prop; +} + + inline void CvSource::SetEnumPropertyChoices( const VideoProperty& property, llvm::ArrayRef choices) { m_status = 0; diff --git a/java/src/edu/wpi/cscore/CvSource.java b/java/src/edu/wpi/cscore/CvSource.java index eba7711857..8edd34f7e7 100644 --- a/java/src/edu/wpi/cscore/CvSource.java +++ b/java/src/edu/wpi/cscore/CvSource.java @@ -84,6 +84,40 @@ public class CvSource extends VideoSource { return new VideoProperty( CameraServerJNI.createSourceProperty(m_handle, name, kind.getValue(), minimum, maximum, step, defaultValue, value)); } + + /// Create an integer property. + /// @param name Property name + /// @param minimum Minimum value + /// @param maximum Maximum value + /// @param step Step value + /// @param defaultValue Default value + /// @param value Current value + /// @return Property + public VideoProperty createIntegerProperty(String name, int minimum, int maximum, int step, int defaultValue, int value) { + return new VideoProperty( + CameraServerJNI.createSourceProperty(m_handle, name, VideoProperty.Kind.kInteger.getValue(), minimum, maximum, step, defaultValue, value)); + } + + /// Create a boolean property. + /// @param name Property name + /// @param defaultValue Default value + /// @param value Current value + /// @return Property + public VideoProperty createBooleanProperty(String name, boolean defaultValue, boolean value) { + return new VideoProperty( + CameraServerJNI.createSourceProperty(m_handle, name, VideoProperty.Kind.kBoolean.getValue(), 0, 1, 1, defaultValue ? 1 : 0, value ? 1 : 0)); + } + + /// Create a string property. + /// @param name Property name + /// @param value Current value + /// @return Property + public VideoProperty createStringProperty(String name, String value) { + VideoProperty prop = new VideoProperty( + CameraServerJNI.createSourceProperty(m_handle, name, VideoProperty.Kind.kString.getValue(), 0, 0, 0, 0, 0)); + prop.setString(value); + return prop; + } /// Create a property with a change callback. /// @param name Property name