mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Implement listener interfaces.
This commit is contained in:
@@ -121,9 +121,6 @@ public class CameraServerJNI {
|
||||
public static native void setSourceConnected(int source, boolean connected);
|
||||
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, 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);
|
||||
|
||||
//
|
||||
@@ -156,8 +153,8 @@ public class CameraServerJNI {
|
||||
//
|
||||
// Listener Functions
|
||||
//
|
||||
//public static native int addListener(void (*callback)(VideoEvent event),
|
||||
// int eventMask);
|
||||
public static native int addListener(VideoListenerFunction listener,
|
||||
int eventMask, boolean immediateNotify);
|
||||
|
||||
public static native void removeListener(int handle);
|
||||
|
||||
|
||||
83
java/src/edu/wpi/cameraserver/VideoEvent.java
Normal file
83
java/src/edu/wpi/cameraserver/VideoEvent.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.cameraserver;
|
||||
|
||||
/// Video event
|
||||
public class VideoEvent {
|
||||
public enum Type {
|
||||
kSourceCreated(0x0001),
|
||||
kSourceDestroyed(0x0002),
|
||||
kSourceConnected(0x0004),
|
||||
kSourceDisconnected(0x0008),
|
||||
kSourceVideoModesUpdated(0x0010),
|
||||
kSourceVideoModeChanged(0x0020),
|
||||
kSinkCreated(0x0100),
|
||||
kSinkDestroyed(0x0200),
|
||||
kSinkEnabled(0x0400),
|
||||
kSinkDisabled(0x0800),
|
||||
kSourcePropertyCreated(0x1000),
|
||||
kSourcePropertyValueUpdated(0x2000),
|
||||
kSourcePropertyChoicesUpdated(0x4000);
|
||||
|
||||
private int value;
|
||||
|
||||
private Type(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
private static final Type[] m_typeValues = Type.values();
|
||||
|
||||
VideoEvent(int type, int source, int sink, String name, int pixelFormat,
|
||||
int width, int height, int fps, int property, int propertyType,
|
||||
int value, String valueStr) {
|
||||
this.type = m_typeValues[type];
|
||||
this.sourceHandle = source;
|
||||
this.sinkHandle = sink;
|
||||
this.name = name;
|
||||
this.mode = new VideoMode(pixelFormat, width, height, fps);
|
||||
this.propertyHandle = property;
|
||||
this.propertyType = VideoProperty.m_typeValues[propertyType];
|
||||
this.value = value;
|
||||
this.valueStr = valueStr;
|
||||
}
|
||||
|
||||
public Type type;
|
||||
|
||||
// Valid for kSource* and kSink* respectively
|
||||
private int sourceHandle;
|
||||
private int sinkHandle;
|
||||
|
||||
// Source/sink name
|
||||
public String name;
|
||||
|
||||
// Fields for kSourceVideoModeChanged event
|
||||
public VideoMode mode;
|
||||
|
||||
// Fields for kSourceProperty* events
|
||||
private int propertyHandle;
|
||||
public VideoProperty.Type propertyType;
|
||||
public int value;
|
||||
public String valueStr;
|
||||
|
||||
public VideoSource getSource() {
|
||||
return new VideoSource(CameraServerJNI.copySource(sourceHandle));
|
||||
}
|
||||
|
||||
public VideoSink getSink() {
|
||||
return new VideoSink(CameraServerJNI.copySink(sinkHandle));
|
||||
}
|
||||
|
||||
public VideoProperty getProperty() {
|
||||
return new VideoProperty(propertyHandle, propertyType);
|
||||
}
|
||||
|
||||
}
|
||||
35
java/src/edu/wpi/cameraserver/VideoListener.java
Normal file
35
java/src/edu/wpi/cameraserver/VideoListener.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.cameraserver;
|
||||
|
||||
/// An event listener. This calls back to a desigated callback function when
|
||||
/// an event matching the specified mask is generated by the library.
|
||||
public class VideoListener {
|
||||
/// Create an event listener.
|
||||
/// @param listener Listener function
|
||||
/// @param eventMask Bitmask of VideoEvent.Type values
|
||||
/// @param immediateNotify Whether callback should be immediately called with
|
||||
/// a representative set of events for the current library state.
|
||||
public VideoListener(VideoListenerFunction listener, int eventMask,
|
||||
boolean immediateNotify) {
|
||||
m_handle = CameraServerJNI.addListener(listener, eventMask, immediateNotify);
|
||||
}
|
||||
|
||||
public synchronized void free() {
|
||||
if (m_handle != 0) {
|
||||
CameraServerJNI.removeListener(m_handle);
|
||||
}
|
||||
m_handle = 0;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return m_handle != 0;
|
||||
}
|
||||
|
||||
private int m_handle;
|
||||
}
|
||||
12
java/src/edu/wpi/cameraserver/VideoListenerFunction.java
Normal file
12
java/src/edu/wpi/cameraserver/VideoListenerFunction.java
Normal file
@@ -0,0 +1,12 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.cameraserver;
|
||||
|
||||
public interface VideoListenerFunction {
|
||||
void apply(VideoEvent event);
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class VideoProperty {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
private static final Type[] m_typeValues = Type.values();
|
||||
static final Type[] m_typeValues = Type.values();
|
||||
|
||||
public String getName() {
|
||||
return CameraServerJNI.getPropertyName(m_handle);
|
||||
@@ -94,6 +94,11 @@ public class VideoProperty {
|
||||
m_type = m_typeValues[CameraServerJNI.getPropertyType(handle)];
|
||||
}
|
||||
|
||||
VideoProperty(int handle, Type type) {
|
||||
m_handle = handle;
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
int m_handle;
|
||||
private Type m_type;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user