Skip to content

Commit 2e97c95

Browse files
authored
Restore original video mode index order (#1999)
1 parent 6610b21 commit 2e97c95

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSettables.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
import edu.wpi.first.util.PixelFormat;
2626
import java.util.ArrayList;
2727
import java.util.Arrays;
28+
import java.util.Collections;
2829
import java.util.HashMap;
2930
import java.util.List;
3031
import java.util.Optional;
32+
import java.util.stream.Collectors;
3133
import org.photonvision.common.configuration.CameraConfiguration;
3234
import org.photonvision.vision.camera.CameraQuirk;
3335
import org.photonvision.vision.processes.VisionSourceSettables;
@@ -287,11 +289,14 @@ private void cacheVideoModes() {
287289
var sortedList =
288290
videoModesList.stream()
289291
.distinct() // remove redundant video mode entries
290-
.sorted(((a, b) -> (a.width + a.height) - (b.width + b.height)))
291-
.toList();
292-
293-
for (VideoMode videoMode : sortedList) {
294-
videoModes.put(sortedList.indexOf(videoMode), videoMode);
292+
.sorted(((a, b) -> (b.width + b.height) - (a.width + a.height)))
293+
.collect(Collectors.toList());
294+
// The ordering is usually more logical when done like this. It typically puts higher FPSes
295+
// closer to the bottom.
296+
Collections.reverse(sortedList);
297+
298+
for (int i = 0; i < sortedList.size(); i++) {
299+
videoModes.put(i, sortedList.get(i));
295300
}
296301

297302
// If after all that we still have no video modes, not much we can do besides

0 commit comments

Comments
 (0)