Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,22 @@ protected void onCameraConnected() {
cameraPropertiesCached = true;
}

/**
* Returns if the camera is currently connected. Use checkCameraConnected instead to properly
* handle camera connection.
*/
public abstract boolean isConnected();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With how I restructured things isConnected probably should not be called by unrelated classes. The only place it is currently called is in VisionModule, for which I'm not sure which method yields better results.


public abstract boolean checkCameraConnected();
/** Checks if the camera is currently connected. Also handles connection events. */
public boolean checkCameraConnected() {
boolean connected = this.isConnected();

if (!cameraPropertiesCached && connected) {
onCameraConnected();
}

return connected;
}

/**
* Returns if the camera has connected at some point. This is not if it is currently connected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public class LibcameraGpuFrameProvider extends FrameProvider {

public LibcameraGpuFrameProvider(LibcameraGpuSettables visionSettables) {
this.settables = visionSettables;

var vidMode = settables.getCurrentVideoMode();
settables.setVideoMode(vidMode);
this.cameraPropertiesCached =
true; // Camera properties are not able to be changed so they are always cached
}

@Override
Expand Down Expand Up @@ -150,7 +145,7 @@ public void release() {
}

@Override
public boolean checkCameraConnected() {
public boolean isConnected() {
String[] cameraNames = LibCameraJNI.getCameraNames();
for (String name : cameraNames) {
if (name.equals(settables.getConfiguration().getDevicePath())) {
Expand All @@ -160,9 +155,13 @@ public boolean checkCameraConnected() {
return false;
}

// To our knowledge the camera is always connected (after boot) with csi cameras
@Override
public boolean isConnected() {
return checkCameraConnected();
protected void onCameraConnected() {
logger.info("Camera connected! running callback");

super.onCameraConnected();

var vidMode = settables.getCurrentVideoMode();
settables.setVideoMode(vidMode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ public USBFrameProvider(
this.connectedCallback = connectedCallback;
}

@Override
public boolean checkCameraConnected() {
boolean connected = camera.isConnected();

if (!cameraPropertiesCached && connected) {
logger.info("Camera connected! running callback");
onCameraConnected();
}

return connected;
}

final double CSCORE_DEFAULT_FRAME_TIMEOUT = 1.0 / 4.0;

@Override
Expand Down Expand Up @@ -145,6 +133,8 @@ public void release() {

@Override
public void onCameraConnected() {
logger.info("Camera connected! running callback");

super.onCameraConnected();

this.connectedCallback.run();
Expand Down
Loading