Change curCam to string to try to fix toggling problems.
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / CameraFeeds.java
index 3ca36b32a355f839baee3ff82c2da49ec1121ce2..99b988be9724c8f628e94895cd0b392c48747e30 100755 (executable)
@@ -1,97 +1,66 @@
 package org.usfirst.frc.team3501.robot;
 
-import com.ni.vision.NIVision;
-import com.ni.vision.NIVision.Image;
-
 import edu.wpi.cscore.AxisCamera;
 import edu.wpi.cscore.UsbCamera;
-import edu.wpi.cscore.VideoSource;
 import edu.wpi.first.wpilibj.CameraServer;
 
 public class CameraFeeds {
   // private final int intakeCam;
   // private final int climberCam;
-  private Image frame;
-  private String curCam = "intake";
+  private String curCam;
   private CameraServer server;
   private static UsbCamera intakeCam;
   private static AxisCamera climberCam;
+  private static String usbCamName;
+  private static String axisCamName;
+  private static CameraFeeds cameraFeeds = null;
 
   @SuppressWarnings("deprecation")
-  public CameraFeeds(/* Joystick Button */) {
-    // Get camera ids by supplying camera name ex 'cam0', found on roborio web
-    // interface
-    /*
-     * intakeCam =
-     * NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameCenter,
-     * NIVision.IMAQdxCameraControlMode.CameraControlModeController); climberCam
-     * = NIVision.IMAQdxOpenCamera(Constants.CameraFeeds.camNameRight,
-     * NIVision.IMAQdxCameraControlMode.CameraControlModeController); curCam =
-     * intakeCam; // Img that will contain camera img frame =
-     * NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0); // Server that
-     * we'll give the img to server = CameraServer.getInstance();
-     * server.setSize(Constants.CameraFeeds.imgQuality);
-     */
-    intakeCam = CameraServer.getInstance().startAutomaticCapture();
-    CameraServer.getInstance().startAutomaticCapture();
+  private CameraFeeds(/* Joystick Button */) {
+    System.out.println("Enter CameraFeeds constructor");
     server = CameraServer.getInstance();
-    climberCam = server.addAxisCamera("axisCamera", "10.35.1.11");
+    climberCam = server.addAxisCamera("ClimberCam", "10.35.1.11");
+    intakeCam = server.startAutomaticCapture();
+    usbCamName = intakeCam.getName();
+    axisCamName = climberCam.getName();
+    curCam = "intakeCam";
+    changeCam();
+    System.out.println("Leaving CameraFeeds constructor");
+  }
 
-    // server = CameraServer.getInstance();
-    // axisCamera = cameraServer2.addAxisCamera("axisCamera", "10.35.1.11");
-    // cameraFeeds = new CameraFeeds();
+  public static CameraFeeds getCameraFeeds() {
+    System.out.println("Enter CameraFeeds.getCameraFeeds");
+    if (cameraFeeds == null) {
+      cameraFeeds = new CameraFeeds();
+    }
+    System.out.println("Leaving CameraFeeds.getCameraFeeds");
+    return cameraFeeds;
   }
 
   public void init() {
-    changeCam(intakeCam);
+    System.out.println("Initializing...");
   }
 
-  public void run()
-  {
-    if(/*add test for toggle*/)
-      changeCam(intakeCam);
-
-    if(/*add test for toggle*/)
-      changeCam(climberCam);
-
-    updateCam();
-  }
-
-  /**
-   * Stop aka close camera stream
-   */
-  public void end() {
-    // NIVision.IMAQdxStopAcquisition(curCam);
+  public void toggleCamera() {
+    changeCam();
   }
 
   /**
    *
-   * Change the camera to get imgs from to a different one
+   * Change the camera to get image from to a different one
    *
-   * @param newId
-   *          for camera
+   * newId for camera
    */
-  public void changeCam(/* int newId */) {
-    if (curCam == "climber") {
-      server.removeCamera(/* Axis Camera name */);
-      server.addCamera(intakeCam);
-      curCam = "intake";
-    } else if (curCam == "intake") {
-      server.removeCamera(/* Usb Camera name */);
-      server.addCamera(climberCam);
-      curCam = "climber";
+  public void changeCam() {
+    System.out.println("enter toggleCamera");
+    if (curCam == "intakeCam") {
+      server.getVideo(axisCamName);
+      curCam = "climberCam";
+      System.out.println("Switching to climber camera, curCam = " + curCam);
+    } else if (curCam == "climberCam") {
+      server.getVideo(usbCamName);
+      curCam = "intakeCam";
+      System.out.println("Switching to intake camera, curCam = " + curCam);
     }
-    // NIVision.IMAQdxStopAcquisition(curCam);
-    // NIVision.IMAQdxConfigureGrab(newId);
-    // NIVision.IMAQdxStartAcquisition(newId);
-    // curCam = newId;
-  }
-
-  /**
-   * Get the img from current camera and give it to the server
-   */
-  public void updateCam() {
-    // NIVision.IMAQdxGrab(curCam, frame, 1);
-    // server.setImage(frame);
   }
 }