<repo_name>NewbergFTC/Bulletproof-2016-2017<file_sep>/Bulletproof/src/main/java/us/newberg/bulletproof/lib/Sensors.java
package us.newberg.bulletproof.lib;

import com.elvishew.xlog.XLog;
import com.qualcomm.hardware.hitechnic.HiTechnicNxtLightSensor;
import com.qualcomm.robotcore.hardware.HardwareMap;

public class Sensors
{
    public static HiTechnicNxtLightSensor LightSensor;

    public static void Init(HardwareMap hardware)
    {
        LightSensor = (HiTechnicNxtLightSensor) hardware.lightSensor.get("Lightsensor");

        XLog.tag("Sensors").d("Sensors initialized");
    }
}
<file_sep>/STYLE.md
# 6712 BulletProof Java Style Guide
###### Revision 0 (WIP)
- [Introduction](#introduction)
- [File Basics](#file-basics)
    - [Source File Basics](#source-file-basics)
- [Formatting](#formatting)

## Introduction
The purpose of this style guide is to provide a standard of code that is consistant and easy to read. This guide will insure that your code is professional-looking and readable on the many devices and screen sizes we work with.

---

## File Basics
- File name: The source file name will match the case-sensitive name of the top-level class it contains.
- File encoding: UTF-8
- Whitespace characters: Spaces, not tabs, will be used for indentation and general whitespace.
- Column Width: The max column width is 120 characters. All lines must be line-wrapped if they exceed this number.

---

### Source File Basics
- Package statement: The package statement will not be line-wrapped.
- Import statements: Import statements will not be line-wrapped.
    - Imports will be ordered as follows:
        1. All standard library imports
        2. All other third party imports
        3. All project imports
        4. All static imports
    - One or two blank lines will follow each block.
    - There are no other blank lines between imports.
    - Within each block, imports will be in an alphabetical order.
- Class declaration: Each top-level class resides in its own source file.
    - Class member ordering: Class members will be ordered in _some logical order_.
    - Method names: When a class has multiple methods with the same name, and/or multiple constructors, they will appear sequentially.

---

### Formatting
- Braces: Braces are always used with `` if ``, `` else ``, `` while ``, `` for ``, `` do `` statements, even if the body contains one line, or is empty.
    - Line breaks <!-- TODO(Garrison): Examples -->
        - Line break before the opening brace
        - Line break after the opening brace
        - Line break before closing brace
        - Line break after the closing brace
<file_sep>/Bulletproof/src/main/java/us/newberg/bulletproof/opmodes/StraightOpMode.java
package us.newberg.bulletproof.opmodes;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;

import us.newberg.bulletproof.Direction;

/**
 * FTC team 6712 Bulletproof
 */

@Autonomous(name = "Straight", group = "Common")
public class StraightOpMode extends BulletproofOpMode
{
    @Override
    protected void Run() throws InterruptedException
    {
        _driveTrain.Drive(Direction.NORTH, 0.8f, 39, 10000, this);
    }
}
<file_sep>/Bulletproof/src/main/java/us/newberg/bulletproof/opmodes/RedShootMoveSideOpMode.java
package us.newberg.bulletproof.opmodes;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;

import us.newberg.bulletproof.Direction;
import us.newberg.bulletproof.modules.Flipper;
import us.newberg.bulletproof.lib.Motors;

/**
 * FTC team 6712 Bulletproof
 */
@Autonomous(name = "Red Shoot Move Side", group = "Red")
public class RedShootMoveSideOpMode extends BulletproofOpMode
{
    @Override
    protected void Run() throws InterruptedException
    {
		_flipper.AutoMoveBlocking(this);

        Motors.Collector.setPower(-1.0f);
        sleep(3000);
        Motors.Collector.setPower(0);

        _flipper.AutoMoveBlocking(this);

        _driveTrain.Drive(Direction.NORTH_EAST, 0.5f, 3.7f * 12.0f, 5000, this);
        sleep(500);
        _driveTrain.Drive(-0.5f, -0.5f);
        sleep(500);
        _driveTrain.StopAll();
        sleep(500);
        _driveTrain.Drive(Direction.NORTH, 1.0f, 2.0f * 12.0f, 10000, this);
    }
}
<file_sep>/Makefile
.PHONY: build install start pullLogs

all: build install start

build:
	@printf '\e[34mBuilding...\n'
	@./gradlew :Bulletproof:build

install:
	@printf '\e[34mInstalling...\n'
	@adb push ./Bulletproof/build/outputs/apk/Bulletproof-debug.apk /data/local/tmp/com.qualcomm.ftcrobotcontroller
	@adb shell pm install -r "/data/local/tmp/com.qualcomm.ftcrobotcontroller"

start:
	@printf '\e[34mStarting...\n'
	@adb shell am start -n "com.qualcomm.ftcrobotcontroller/org.firstinspires.ftc.robotcontroller.internal.FtcRobotControllerActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
	@sl

pullLogs:
	@adb pull /sdcard/bullet ./logs<file_sep>/Bulletproof/src/main/java/us/newberg/bulletproof/modules/Flipper.java
package us.newberg.bulletproof.modules;

import com.elvishew.xlog.XLog;
import com.qualcomm.robotcore.hardware.DcMotor;

import us.newberg.bulletproof.lib.Motors;
import us.newberg.bulletproof.opmodes.BulletproofOpMode;
import us.or.k12.newberg.newbergcommon.WatchDog;


/**
 * FTC team 6712 Bulletproof
 */
public class Flipper
{
    public static final String TAG = "Flipper";

    public static final float GEAR_RATIO = 20.0f / 3.0f; // 6 2/3
    public static final float HALF_GEAR_RATIO = GEAR_RATIO / 2; // One flick

    public enum State
    {
        NOTHING,
        MANUAL,
        AUTO
    }

    private Flipper.State _state;
    private FlipperHelper _helper;

    private DcMotor _flipperMotor;

    private WatchDog _watchDog;

    public Flipper(DcMotor motor)
    {
        _helper = new FlipperHelper(this);
        _flipperMotor = motor;
        _watchDog = new WatchDog();
    }

    public void AutoMoveBlocking(BulletproofOpMode caller) throws InterruptedException
    {
        XLog.tag(TAG).d("Auto-move Blocking Start");

        _helper.SetTask(HelperTask.STOP);
        _watchDog.Watch(_helper, 15000);

        StartAutoMove();

        while (GetState() == Flipper.State.AUTO)
        {
            caller.sleep(1);
            caller.Update();
        }

        _watchDog.Stop();

        XLog.tag(TAG).d("Auto-move Blocking Stop");
    }

    public void StartAutoMove()
    {
        XLog.tag(TAG).d("Auto-move Start");

        final float targetTicks = (float) _flipperMotor.getCurrentPosition() + ((float)Motors.TICKS_PER_ROTATION * HALF_GEAR_RATIO * 1.7f);

        _state = State.AUTO;

        new Thread(new Runnable()
        {
         	@Override
            public void run()
            {
                while (_flipperMotor.getCurrentPosition() < targetTicks)
                {
                                   SetPower(1.0f);

        			_state = State.AUTO;
                }

                SetPower(0.0f);
                _state = State.NOTHING;

                XLog.tag(TAG).d("Auto-move Stop");
            }
        }).start();
    }

    public void SetPower(double power)
    {
        XLog.tag(TAG).d("Set power to " + String.valueOf(power));

        _flipperMotor.setPower(power);
    }

    public Flipper.State GetState()
    {
        return _state;
    }

    private enum HelperTask
    {
        NONE,
        COMPLETE,
        STOP,
    }

    private class FlipperHelper implements Runnable
    {
        private Flipper _flipper;
        private HelperTask _task;

        private FlipperHelper(Flipper target)
        {
            _flipper = target;
            _task = HelperTask.NONE;
        }

        private void SetTask(HelperTask task)
        {
            _task = task;
        }

        public HelperTask GetTask()
        {
            return _task;
        }

        private void StopAll()
        {
            _flipper.SetPower(0);
        }

        @Override
        public void run()
        {
            switch (_task)
            {
                default:
                case NONE:
                    break;

                case STOP:
                    StopAll();
                    SetTask(HelperTask.COMPLETE);
                    break;
            }
        }
    }
}
<file_sep>/settings.gradle
include ':FtcRobotController'
include ':Bulletproof'
include ':NewbergCommon'

include ':opencv-java'
<file_sep>/Bulletproof/src/main/java/us/newberg/bulletproof/Direction.java
package us.newberg.bulletproof;

/**
 * FTC team 6712 Bulletproof
 */
public enum Direction
{
    NORTH,
    NORTH_EAST,
    EAST,
    SOUTH_EAST,
    SOUTH,
    SOUTH_WEST,
    WEST,
    NORTH_WEST
}
<file_sep>/Bulletproof/src/main/java/us/newberg/bulletproof/modules/Collector.java
package us.newberg.bulletproof.modules;

import com.elvishew.xlog.XLog;
import com.qualcomm.robotcore.hardware.DcMotor;

import us.newberg.bulletproof.opmodes.BulletproofOpMode;

import us.or.k12.newberg.newbergcommon.WatchDog;

public class Collector
{
    public static final String TAG = "Collector";

    public static double MAIN_POWER = 1.0;
    public static double STOP_POWER = 0.0;

    private DcMotor _motor;

    private WatchDog _watchDog;

    public Collector(DcMotor motor)
    {
        _motor = motor;
        Stop();

        XLog.tag(TAG).d("Initialized");
    }

    public void StartPull()
    {
        _motor.setPower(MAIN_POWER);

        XLog.tag(TAG).d("Pulling");
    }

    public void StartPush()
    {
        _motor.setPower(-MAIN_POWER);

        XLog.tag(TAG).d("Pushing");
    }

    public void Stop()
    {
        _motor.setPower(STOP_POWER);

        XLog.tag(TAG).d("Stop");
    }
}
<file_sep>/Bulletproof/src/main/java/us/newberg/bulletproof/lib/Motors.java
package us.newberg.bulletproof.lib;

/**
 * FTC team 6712 Bulletproof
 */

import com.elvishew.xlog.XLog;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.HardwareMap;

public class Motors
{
    public static final double WHEEL_CIRCUMFRENCE = Math.PI * 4;               // inches
    public static final double TICKS_PER_ROTATION = 1120;                       // ticks
    public static final double TICKS_TO_DEG       = 360 / TICKS_PER_ROTATION;  // deg / ticks
    public static final double DEG_TO_TICKS       = TICKS_PER_ROTATION / 360;  // ticks / deg
    public static final double TICKS_TO_INCHES    = TICKS_PER_ROTATION / WHEEL_CIRCUMFRENCE;  // ticks / in
    public static final double INCHES_TO_TICKS    = WHEEL_CIRCUMFRENCE / TICKS_PER_ROTATION;  // in / ticks
    public static final double WHEEL_DISTANCE_CORRECTION = 1.414213526373095; // sqrt(2)

    public static DcMotor FrontLeft;
    public static DcMotor FrontRight;
    public static DcMotor BackLeft;
    public static DcMotor BackRight;
    public static DcMotor Collector;
    public static DcMotor Flipper;

    public static void Init(HardwareMap hardwareMap)
    {
        FrontLeft = hardwareMap.dcMotor.get("frontLeft");
        FrontRight = hardwareMap.dcMotor.get("frontRight");
        BackLeft = hardwareMap.dcMotor.get("backLeft");
        BackRight = hardwareMap.dcMotor.get("backRight");
        Collector = hardwareMap.dcMotor.get("collector");
        Flipper = hardwareMap.dcMotor.get("flipper");

        FrontLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
        FrontRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
        BackLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
        BackRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);

        XLog.tag("Motors").d("Motors initialized");
    }
}
<file_sep>/Bulletproof/src/main/java/us/newberg/bulletproof/modules/ButtonPusher.java
package us.newberg.bulletproof.modules;

import com.elvishew.xlog.XLog;
import com.qualcomm.robotcore.hardware.Servo;

import org.firstinspires.ftc.robotcore.external.Telemetry;

/**
 * FTC team 6712 Bulletproof
 */
public class ButtonPusher
{
    public static final String TAG = "ButtonPusher";

    public static float LEFT_DEPLOY_POS = 1f;
    public static float LEFT_CLOSE_POS = 0f;
    public static float RIGHT_DEPLOY_POS = 1f;
    public static float RIGHT_CLOSE_POS = 0f;

    private enum State
    {
        DEPLOYED,
        CLOSED
    }

    private Servo _servoLeft;
    private Servo _servoRight;

    private State _stateLeft;
    private State _stateRight;

    public ButtonPusher(Servo left, Servo right)
    {
        _servoLeft = left;
        _servoRight = right;

        _servoLeft.setPosition(LEFT_CLOSE_POS);
        _servoRight.setPosition(RIGHT_CLOSE_POS);

        _stateLeft = State.CLOSED;
        _stateRight = State.CLOSED;

        XLog.tag(TAG).d("Initialized");
    }

    public void DeployLeft()
    {
        _servoLeft.setPosition(LEFT_DEPLOY_POS);
        _stateLeft = State.DEPLOYED;

        XLog.tag(TAG).d("Deploy Left");
    }

    public void DeployRight()
    {
        _servoRight.setPosition(RIGHT_DEPLOY_POS);
        _stateRight = State.DEPLOYED;

        XLog.tag(TAG).d("Deploy Right");
    }

    public void CloseLeft()
    {
        _servoLeft.setPosition(LEFT_CLOSE_POS);
        _stateLeft = State.CLOSED;

        XLog.tag(TAG).d("Close Left");
    }

    public void CloseRight()
    {
        _servoRight.setPosition(RIGHT_CLOSE_POS);
        _stateRight = State.CLOSED;

        XLog.tag(TAG).d("Close Right");
    }

    public void ToggleLeft()
    {
        if (_stateLeft == State.CLOSED)
        {
            DeployLeft();
        }
        else
        {
            CloseLeft();
        }
    }

    public void ToggleRight()
    {
        if (_stateRight == State.CLOSED)
        {
            DeployRight();
        }
        else
        {
            CloseRight();
        }
    }
}
<file_sep>/README.md
# FTC Team 6712 Bulletproof
## 2016-2017 FTC Season
---
