package ftc8390.vv;

import android.graphics.Bitmap;

import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;

import for_camera_opmodes.LinearOpModeCamera;

/**
 * TeleOp Mode
 * <p/>
 * Enables control of the robot via the gamepad
 */

@TeleOp(name = "TestColorDetector", group = "Test")
//@Disabled
public class TestColorDetector extends LinearOpModeCamera {

    DcMotor motorRight;
    DcMotor motorLeft;

    int ds2 = 2;  // additional downsampling of the image
    // set to 1 to disable further downsampling

    @Override
    public void runOpMode() {

        String colorString = "NONE";

        // linear OpMode, so could do stuff like this too.
        /*
        motorLeft = hardwareMap.dcMotor.get("motor_1");
        motorRight = hardwareMap.dcMotor.get("motor_2");
        motorLeft.setDirection(DcMotor.Direction.REVERSE);
        */

        if (isCameraAvailable()) {

            setCameraDownsampling(8);
            // parameter determines how downsampled you want your images
            // 8, 4, 2, or 1.
            // higher number is more downsampled, so less resolution but faster
            // 1 is original resolution, which is detailed but slow
            // must be called before super.init sets up the camera
            BeaconColorDetector BCD = new BeaconColorDetector();
            BCD.init(hardwareMap);
            telemetry.addLine("Wait for camera to finish initializing!");
            telemetry.update();
            startCamera();  // can take a while.
            // best started before waitForStart
            telemetry.addLine("Camera ready!");
            telemetry.update();

            waitForStart();

            // LinearOpMode, so could do stuff like this too.
            /*
            motorLeft.setPower(1);  // drive forward
            motorRight.setPower(1);
            sleep(1000);            // for a second.
            motorLeft.setPower(0);  // stop drive motors.
            motorRight.setPower(0);
            sleep(1000);            // wait a second.
            */

            while (opModeIsActive()) {
                if (imageReady()) { // only do this if an image has been returned from the camera
                    Bitmap rgbImage;
                    rgbImage = convertYuvImageToRgb(yuvImage, width, height, ds2);

                    if(BCD.blueIsOnLeft(rgbImage))
                        colorString = "BlueOnLeft";
                    else
                        colorString = "BlueOnRight";

                } else {
                    colorString = "NONE";
                }

                telemetry.addData("Color:", "Color detected is: " + colorString);
                telemetry.update();
                sleep(10);
            }
            stopCamera();

        }
    }
}

@@ -407,56 +407,8 @@
  %7B%0A%0A
-    DcMotor motorRight;%0A    DcMotor motorLeft;%0A%0A
     
@@ -461,16 +461,16 @@
 e image%0A
+
     // s
@@ -597,262 +597,8 @@
 %22;%0A%0A
-        // linear OpMode, so could do stuff like this too.%0A        /*%0A        motorLeft = hardwareMap.dcMotor.get(%22motor_1%22);%0A        motorRight = hardwareMap.dcMotor.get(%22motor_2%22);%0A        motorLeft.setDirection(DcMotor.Direction.REVERSE);%0A        */%0A%0A
     
@@ -1365,24 +1365,24 @@
 .update();%0A%0A
+
             
@@ -1402,391 +1402,8 @@
 );%0A%0A
-            // LinearOpMode, so could do stuff like this too.%0A            /*%0A            motorLeft.setPower(1);  // drive forward%0A            motorRight.setPower(1);%0A            sleep(1000);            // for a second.%0A            motorLeft.setPower(0);  // stop drive motors.%0A            motorRight.setPower(0);%0A            sleep(1000);            // wait a second.%0A            */%0A%0A
     

clean comments