mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-29 02:21:41 +00:00
Add libpicam with gain slider bugfix (#278)
* Add libpicam with gain slider bugfix * Patches to get zero-copy working with Pi3. -- Success/Failure mistmatch assumptions - lots of functions in the JNI return true on failure (not true on success) -- isVSCMSupported() is currently implemented to be "isVSCMNotSupported()" Likely, we'll want at least some .so changes Co-authored-by: Chris Gerth <chrisgerth010592@gmail.com>
This commit is contained in:
@@ -85,7 +85,7 @@ public class PicamJNI {
|
||||
}
|
||||
|
||||
public static boolean isSupported() {
|
||||
return libraryLoaded && isVCSMSupported() && getSensorModel() != SensorModel.Disconnected;
|
||||
return libraryLoaded && !isVCSMSupported() && getSensorModel() != SensorModel.Disconnected;
|
||||
}
|
||||
|
||||
public static SensorModel getSensorModel() {
|
||||
|
||||
@@ -136,22 +136,22 @@ public class ZeroCopyPicamSource extends VisionSource {
|
||||
@Override
|
||||
public void setExposure(double exposure) {
|
||||
lastExposure = exposure;
|
||||
var success = PicamJNI.setExposure((int) Math.round(exposure));
|
||||
if (!success) logger.warn("Couldn't set Pi camera exposure");
|
||||
var failure = PicamJNI.setExposure((int) Math.round(exposure));
|
||||
if (failure) logger.warn("Couldn't set Pi camera exposure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBrightness(int brightness) {
|
||||
lastBrightness = brightness;
|
||||
var success = PicamJNI.setBrightness(brightness);
|
||||
if (!success) logger.warn("Couldn't set Pi camera brightness");
|
||||
var failure = PicamJNI.setBrightness(brightness);
|
||||
if (failure) logger.warn("Couldn't set Pi camera brightness");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGain(int gain) {
|
||||
lastGain = gain;
|
||||
var success = PicamJNI.setGain(gain);
|
||||
if (!success) logger.warn("Couldn't set Pi camera gain");
|
||||
var failure = PicamJNI.setGain(gain);
|
||||
if (failure) logger.warn("Couldn't set Pi camera gain");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,12 +162,12 @@ public class ZeroCopyPicamSource extends VisionSource {
|
||||
@Override
|
||||
protected void setVideoModeInternal(VideoMode videoMode) {
|
||||
var mode = (FPSRatedVideoMode) videoMode;
|
||||
var success = PicamJNI.destroyCamera();
|
||||
if (!success)
|
||||
var failure = PicamJNI.destroyCamera();
|
||||
if (failure)
|
||||
throw new RuntimeException(
|
||||
"Couldn't destroy a zero copy Pi camera while switching video modes");
|
||||
success = PicamJNI.createCamera(mode.width, mode.height, mode.fpsActual);
|
||||
if (!success)
|
||||
failure = PicamJNI.createCamera(mode.width, mode.height, mode.fpsActual);
|
||||
if (failure)
|
||||
throw new RuntimeException(
|
||||
"Couldn't create a zero copy Pi camera while switching video modes");
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ public class AcceleratedPicamFrameProvider implements FrameProvider {
|
||||
this.settables = visionSettables;
|
||||
|
||||
var vidMode = settables.getCurrentVideoMode();
|
||||
var success = PicamJNI.createCamera(vidMode.width, vidMode.height, vidMode.fps);
|
||||
if (!success) {
|
||||
success = PicamJNI.destroyCamera();
|
||||
if (!success) throw new RuntimeException("Couldn't destroy Pi camera after init failure!");
|
||||
var failure = PicamJNI.createCamera(vidMode.width, vidMode.height, vidMode.fps);
|
||||
if (failure) {
|
||||
failure = PicamJNI.destroyCamera();
|
||||
if (failure) throw new RuntimeException("Couldn't destroy Pi camera after init failure!");
|
||||
throw new RuntimeException(
|
||||
"Couldn't initialize zero copy Pi camera; check stdout for native code logs");
|
||||
}
|
||||
|
||||
@@ -302,6 +302,7 @@ public class VisionSourceManager {
|
||||
var cameraSources = new ArrayList<VisionSource>();
|
||||
for (var configuration : camConfigs) {
|
||||
if (configuration.baseName.startsWith("mmal service") && PicamJNI.isSupported()) {
|
||||
configuration.cameraType = CameraType.ZeroCopyPicam;
|
||||
var piCamSrc = new ZeroCopyPicamSource(configuration);
|
||||
|
||||
configuration.cameraType = CameraType.ZeroCopyPicam;
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user