mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
CvSource: Update interface functions.
- Add SetDescription - Supply minimum, maximum, step, defaultValue, and value to CreateProperty - Add SetEnumPropertyChoices
This commit is contained in:
@@ -150,12 +150,19 @@ void CS_PutSourceFrame(CS_Source source, struct CvMat* image,
|
||||
void CS_NotifySourceError(CS_Source source, const char* msg, CS_Status* status);
|
||||
void CS_SetSourceConnected(CS_Source source, CS_Bool connected,
|
||||
CS_Status* status);
|
||||
void CS_SetSourceDescription(CS_Source source, const char* description,
|
||||
CS_Status* status);
|
||||
CS_Property CS_CreateSourceProperty(CS_Source source, const char* name,
|
||||
enum CS_PropertyType type,
|
||||
CS_Status* status);
|
||||
enum CS_PropertyType type, int minimum,
|
||||
int maximum, int step, int defaultValue,
|
||||
int value, CS_Status* status);
|
||||
CS_Property CS_CreateSourcePropertyCallback(
|
||||
CS_Source source, const char* name, enum CS_PropertyType type, void* data,
|
||||
CS_Source source, const char* name, enum CS_PropertyType type, int minimum,
|
||||
int maximum, int step, int defaultValue, int value, void* data,
|
||||
void (*onChange)(void* data, CS_Property property), CS_Status* status);
|
||||
void CS_SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
const char** choices, int count,
|
||||
CS_Status* status);
|
||||
void CS_RemoveSourceProperty(CS_Source source, CS_Property property,
|
||||
CS_Status* status);
|
||||
void CS_RemoveSourcePropertyByName(CS_Source source, const char* name,
|
||||
|
||||
@@ -138,11 +138,19 @@ void PutSourceFrame(CS_Source source, cv::Mat& image, CS_Status* status);
|
||||
void NotifySourceError(CS_Source source, llvm::StringRef msg,
|
||||
CS_Status* status);
|
||||
void SetSourceConnected(CS_Source source, bool connected, CS_Status* status);
|
||||
void SetSourceDescription(CS_Source source, llvm::StringRef description,
|
||||
CS_Status* status);
|
||||
CS_Property CreateSourceProperty(CS_Source source, llvm::StringRef name,
|
||||
CS_PropertyType type, CS_Status* status);
|
||||
CS_PropertyType type, int minimum, int maximum,
|
||||
int step, int defaultValue, int value,
|
||||
CS_Status* status);
|
||||
CS_Property CreateSourcePropertyCallback(
|
||||
CS_Source source, llvm::StringRef name, CS_PropertyType type,
|
||||
CS_Source source, llvm::StringRef name, CS_PropertyType type, int minimum,
|
||||
int maximum, int step, int defaultValue, int value,
|
||||
std::function<void(CS_Property property)> onChange, CS_Status* status);
|
||||
void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
llvm::ArrayRef<std::string> choices,
|
||||
CS_Status* status);
|
||||
void RemoveSourceProperty(CS_Source source, CS_Property property,
|
||||
CS_Status* status);
|
||||
void RemoveSourceProperty(CS_Source source, llvm::StringRef name,
|
||||
|
||||
@@ -224,24 +224,47 @@ class CvSource : public VideoSource {
|
||||
/// @param connected True for connected, false for disconnected
|
||||
void SetConnected(bool connected);
|
||||
|
||||
/// Set source description.
|
||||
/// @param description Description
|
||||
void SetDescription(llvm::StringRef description);
|
||||
|
||||
/// Create a property.
|
||||
/// @param name Property name
|
||||
/// @param type Property type
|
||||
/// @param minimum Minimum value
|
||||
/// @param maximum Maximum value
|
||||
/// @param step Step value
|
||||
/// @param defaultValue Default value
|
||||
/// @param value Current value
|
||||
/// @return Property
|
||||
VideoProperty CreateProperty(llvm::StringRef name, VideoProperty::Type type);
|
||||
VideoProperty CreateProperty(llvm::StringRef name, VideoProperty::Type type,
|
||||
int minimum, int maximum, int step,
|
||||
int defaultValue, int value);
|
||||
|
||||
/// Create a property with a change callback.
|
||||
/// @param name Property name
|
||||
/// @param type Property type
|
||||
/// @param minimum Minimum value
|
||||
/// @param maximum Maximum value
|
||||
/// @param step Step value
|
||||
/// @param defaultValue Default value
|
||||
/// @param value Current value
|
||||
/// @param onChange Callback to call when the property value changes
|
||||
/// @return Property
|
||||
VideoProperty CreateProperty(
|
||||
llvm::StringRef name, VideoProperty::Type type,
|
||||
llvm::StringRef name, VideoProperty::Type type, int minimum, int maximum,
|
||||
int step, int defaultValue, int value,
|
||||
std::function<void(VideoProperty property)> onChange);
|
||||
|
||||
/// Configure enum property choices.
|
||||
/// @param property Property
|
||||
/// @param choices Choices
|
||||
void SetEnumPropertyChoices(const VideoProperty& property,
|
||||
llvm::ArrayRef<std::string> choices);
|
||||
|
||||
/// Remove a property.
|
||||
/// @param property Property
|
||||
void RemoveProperty(VideoProperty property);
|
||||
void RemoveProperty(const VideoProperty& property);
|
||||
|
||||
/// Remove a property.
|
||||
/// @param name Property name
|
||||
|
||||
@@ -197,25 +197,41 @@ inline void CvSource::SetConnected(bool connected) {
|
||||
SetSourceConnected(m_handle, connected, &m_status);
|
||||
}
|
||||
|
||||
inline void CvSource::SetDescription(llvm::StringRef description) {
|
||||
m_status = 0;
|
||||
SetSourceDescription(m_handle, description, &m_status);
|
||||
}
|
||||
|
||||
inline VideoProperty CvSource::CreateProperty(llvm::StringRef name,
|
||||
VideoProperty::Type type) {
|
||||
VideoProperty::Type type,
|
||||
int minimum, int maximum,
|
||||
int step, int defaultValue,
|
||||
int value) {
|
||||
m_status = 0;
|
||||
return VideoProperty{CreateSourceProperty(
|
||||
m_handle, name, static_cast<CS_PropertyType>(static_cast<int>(type)),
|
||||
&m_status)};
|
||||
minimum, maximum, step, defaultValue, value, &m_status)};
|
||||
}
|
||||
|
||||
inline VideoProperty CvSource::CreateProperty(
|
||||
llvm::StringRef name, VideoProperty::Type type,
|
||||
llvm::StringRef name, VideoProperty::Type type, int minimum, int maximum,
|
||||
int step, int defaultValue, int value,
|
||||
std::function<void(VideoProperty property)> onChange) {
|
||||
m_status = 0;
|
||||
return VideoProperty{CreateSourcePropertyCallback(
|
||||
m_handle, name, static_cast<CS_PropertyType>(static_cast<int>(type)),
|
||||
minimum, maximum, step, defaultValue, value,
|
||||
[=](CS_Property property) { onChange(VideoProperty{property}); },
|
||||
&m_status)};
|
||||
}
|
||||
|
||||
inline void CvSource::RemoveProperty(VideoProperty property) {
|
||||
inline void CvSource::SetEnumPropertyChoices(
|
||||
const VideoProperty& property, llvm::ArrayRef<std::string> choices) {
|
||||
m_status = 0;
|
||||
SetSourceEnumPropertyChoices(m_handle, property.m_handle, choices, &m_status);
|
||||
}
|
||||
|
||||
inline void CvSource::RemoveProperty(const VideoProperty& property) {
|
||||
m_status = 0;
|
||||
RemoveSourceProperty(m_handle, property.m_handle, &m_status);
|
||||
}
|
||||
|
||||
@@ -563,20 +563,58 @@ JNIEXPORT void JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_setSourceConnec
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: createSourceProperty
|
||||
* Signature: (ILjava/lang/String;I)I
|
||||
* Method: setSourceDescription
|
||||
* Signature: (ILjava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_createSourceProperty
|
||||
(JNIEnv *env, jclass, jint source, jstring name, jint type)
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_setSourceDescription
|
||||
(JNIEnv *env, jclass, jint source, jstring description)
|
||||
{
|
||||
CS_Status status = 0;
|
||||
auto val =
|
||||
cs::CreateSourceProperty(source, JStringRef{env, name},
|
||||
static_cast<CS_PropertyType>(type), &status);
|
||||
cs::SetSourceDescription(source, JStringRef{env, description}, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: createSourceProperty
|
||||
* Signature: (ILjava/lang/String;IIIIII)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_createSourceProperty
|
||||
(JNIEnv *env, jclass, jint source, jstring name, jint type, jint minimum, jint maximum, jint step, jint defaultValue, jint value)
|
||||
{
|
||||
CS_Status status = 0;
|
||||
auto val = cs::CreateSourceProperty(
|
||||
source, JStringRef{env, name}, static_cast<CS_PropertyType>(type),
|
||||
minimum, maximum, step, defaultValue, value, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: setSourceEnumPropertyChoices
|
||||
* Signature: (II[Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_cameraserver_CameraServerJNI_setSourceEnumPropertyChoices
|
||||
(JNIEnv *env, jclass, jint source, jint property, jobjectArray choices)
|
||||
{
|
||||
size_t len = env->GetArrayLength(choices);
|
||||
llvm::SmallVector<std::string, 8> vec;
|
||||
vec.reserve(len);
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
JLocal<jstring> elem{
|
||||
env, static_cast<jstring>(env->GetObjectArrayElement(choices, i))};
|
||||
if (!elem) {
|
||||
// TODO
|
||||
return;
|
||||
}
|
||||
vec.push_back(JStringRef{env, elem}.str());
|
||||
}
|
||||
CS_Status status = 0;
|
||||
cs::SetSourceEnumPropertyChoices(source, property, vec, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_cameraserver_CameraServerJNI
|
||||
* Method: removeSourceProperty
|
||||
|
||||
@@ -119,11 +119,12 @@ public class CameraServerJNI {
|
||||
public static native void putSourceFrame(int source, long imageNativeObj);
|
||||
public static native void notifySourceError(int source, String msg);
|
||||
public static native void setSourceConnected(int source, boolean connected);
|
||||
public static native int createSourceProperty(int source, String name, int type);
|
||||
public static native void setSourceDescription(int source, String description);
|
||||
public static native int createSourceProperty(int source, String name, int type, int minimum, int maximum, int step, int defaultValue, int value);
|
||||
//public static native int createSourcePropertyCallback(int source, String name,
|
||||
// int type,
|
||||
// void (*onChange)(String name,
|
||||
// int property));
|
||||
// int type, int minimum, int maximum, int step, int defaultValue, int value,
|
||||
// void (*onChange)(int property));
|
||||
public static native void setSourceEnumPropertyChoices(int source, int property, String[] choices);
|
||||
public static native void removeSourceProperty(int source, int property);
|
||||
public static native void removeSourcePropertyByName(int source, String name);
|
||||
|
||||
|
||||
@@ -46,25 +46,48 @@ public class CvSource extends VideoSource {
|
||||
CameraServerJNI.setSourceConnected(m_handle, connected);
|
||||
}
|
||||
|
||||
/// Set source description.
|
||||
/// @param description Description
|
||||
public void setDescription(String description) {
|
||||
CameraServerJNI.setSourceDescription(m_handle, description);
|
||||
}
|
||||
|
||||
/// Create a property.
|
||||
/// @param name Property name
|
||||
/// @param type Property type
|
||||
/// @param minimum Minimum value
|
||||
/// @param maximum Maximum value
|
||||
/// @param step Step value
|
||||
/// @param defaultValue Default value
|
||||
/// @param value Current value
|
||||
/// @return Property
|
||||
public VideoProperty createProperty(String name, VideoProperty.Type type) {
|
||||
public VideoProperty createProperty(String name, VideoProperty.Type type, int minimum, int maximum, int step, int defaultValue, int value) {
|
||||
return new VideoProperty(
|
||||
CameraServerJNI.createSourceProperty(m_handle, name, type.getValue()));
|
||||
CameraServerJNI.createSourceProperty(m_handle, name, type.getValue(), minimum, maximum, step, defaultValue, value));
|
||||
}
|
||||
|
||||
/// Create a property with a change callback.
|
||||
/// @param name Property name
|
||||
/// @param type Property type
|
||||
/// @param minimum Minimum value
|
||||
/// @param maximum Maximum value
|
||||
/// @param step Step value
|
||||
/// @param defaultValue Default value
|
||||
/// @param value Current value
|
||||
/// @param onChange Callback to call when the property value changes
|
||||
/// @return Property
|
||||
//public VideoProperty createProperty(
|
||||
// String name, VideoProperty.Type type,
|
||||
// std::function<void(String name, VideoProperty property)>
|
||||
// String name, VideoProperty.Type type, int minimum, int maximum, int step, int defaultValue, int value,
|
||||
// std::function<void(VideoProperty property)>
|
||||
// onChange);
|
||||
|
||||
/// Configure enum property choices.
|
||||
/// @param property Property
|
||||
/// @param choices Choices
|
||||
public void SetEnumPropertyChoices(VideoProperty property, String[] choices) {
|
||||
CameraServerJNI.setSourceEnumPropertyChoices(m_handle, property.m_handle, choices);
|
||||
}
|
||||
|
||||
/// Remove a property.
|
||||
/// @param name Property name
|
||||
public void removeProperty(VideoProperty property) {
|
||||
|
||||
@@ -198,21 +198,37 @@ void CS_SetSourceConnected(CS_Source source, CS_Bool connected,
|
||||
return cs::SetSourceConnected(source, connected, status);
|
||||
}
|
||||
|
||||
void CS_SetSourceDescription(CS_Source source, const char* description,
|
||||
CS_Status* status) {
|
||||
return cs::SetSourceDescription(source, description, status);
|
||||
}
|
||||
|
||||
CS_Property CS_CreateSourceProperty(CS_Source source, const char* name,
|
||||
enum CS_PropertyType type,
|
||||
CS_Status* status) {
|
||||
return cs::CreateSourceProperty(source, name, type, status);
|
||||
enum CS_PropertyType type, int minimum,
|
||||
int maximum, int step, int defaultValue,
|
||||
int value, CS_Status* status) {
|
||||
return cs::CreateSourceProperty(source, name, type, minimum, maximum, step,
|
||||
defaultValue, value, status);
|
||||
}
|
||||
|
||||
CS_Property CS_CreateSourcePropertyCallback(
|
||||
CS_Source source, const char* name, enum CS_PropertyType type, void* data,
|
||||
void (*onChange)(void* data, CS_Property property),
|
||||
CS_Status* status) {
|
||||
CS_Source source, const char* name, enum CS_PropertyType type, int minimum,
|
||||
int maximum, int step, int defaultValue, int value, void* data,
|
||||
void (*onChange)(void* data, CS_Property property), CS_Status* status) {
|
||||
return cs::CreateSourcePropertyCallback(
|
||||
source, name, type,
|
||||
source, name, type, minimum, maximum, step, defaultValue, value,
|
||||
[=](CS_Property property) { onChange(data, property); }, status);
|
||||
}
|
||||
|
||||
void CS_SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
const char** choices, int count,
|
||||
CS_Status* status) {
|
||||
llvm::SmallVector<std::string, 8> vec;
|
||||
vec.reserve(count);
|
||||
for (int i = 0; i < count; ++i) vec.push_back(choices[i]);
|
||||
return cs::SetSourceEnumPropertyChoices(source, property, vec, status);
|
||||
}
|
||||
|
||||
void CS_RemoveSourceProperty(CS_Source source, CS_Property property,
|
||||
CS_Status* status) {
|
||||
return cs::RemoveSourceProperty(source, property, status);
|
||||
|
||||
@@ -342,17 +342,31 @@ void SetSourceConnected(CS_Source source, bool connected, CS_Status* status) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void SetSourceDescription(CS_Source source, llvm::StringRef description,
|
||||
CS_Status* status) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
CS_Property CreateSourceProperty(CS_Source source, llvm::StringRef name,
|
||||
CS_PropertyType type, CS_Status* status) {
|
||||
CS_PropertyType type, int minimum, int maximum,
|
||||
int step, int defaultValue, int value,
|
||||
CS_Status* status) {
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
CS_Property CreateSourcePropertyCallback(
|
||||
CS_Source source, llvm::StringRef name, CS_PropertyType type,
|
||||
CS_Source source, llvm::StringRef name, CS_PropertyType type, int minimum,
|
||||
int maximum, int step, int defaultValue, int value,
|
||||
std::function<void(CS_Property property)> onChange, CS_Status* status) {
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
llvm::ArrayRef<std::string> choices,
|
||||
CS_Status* status) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void RemoveSourceProperty(CS_Source source, CS_Property property,
|
||||
CS_Status* status) {
|
||||
// TODO
|
||||
|
||||
Reference in New Issue
Block a user