mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11: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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user