diff --git a/.gitignore b/.gitignore index e06e5aa..73fecc7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ !.idea/codeStyles **.iml build +src/main/resources/branch.txt +src/main/resources/buildtime.txt +src/main/resources/changes.txt +src/main/resources/commit.txt diff --git a/build.gradle b/build.gradle index 48cb7de..b080d30 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,7 @@ +import java.text.SimpleDateFormat + buildscript { - ext.kotlinVersion = '1.2.31' + ext.kotlinVersion = '1.2.50' ext.gradleRioVersion = '2018.03.06' ext.sertainVersion = '1.2.0' ext.ktlintVersion = '0.19.0' @@ -23,6 +25,7 @@ tasks.whenTaskAdded { task -> if (task.name == 'deploy' || task.name == 'deployMain') task.dependsOn 'assemble' } check.dependsOn 'ktlint' +compileKotlin.dependsOn 'versionTxt' repositories { google() @@ -93,3 +96,41 @@ task ktlint(type: JavaExec) { classpath = configurations.ktlint args 'src/**/*.kt' } + +def getGitHash = { -> + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'rev-parse', 'HEAD' + standardOutput = stdout + } + return stdout.toString().trim() +} + +def getGitBranch = { -> + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD' + standardOutput = stdout + } + return stdout.toString().trim() +} + +def getGitFilesChanged = { -> + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'diff', '--name-only', 'HEAD' + standardOutput = stdout + } + return stdout.toString().trim().replace('\n', ', ') +} + +task versionTxt() { + doLast { + String resourcesDir = "$projectDir/src/main/resources" + new File("$resourcesDir/branch.txt").text = getGitBranch() + new File("$resourcesDir/commit.txt").text = getGitHash() + new File("$resourcesDir/changes.txt").text = getGitFilesChanged() + new File("$resourcesDir/buildtime.txt").text = + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()) + } +} diff --git a/src/main/java/org/sert2521/powerup/Poe.kt b/src/main/java/org/sert2521/powerup/Poe.kt index dd89dcd..27b9b7b 100644 --- a/src/main/java/org/sert2521/powerup/Poe.kt +++ b/src/main/java/org/sert2521/powerup/Poe.kt @@ -9,6 +9,8 @@ import org.sert2521.powerup.intake.Intake import org.sert2521.powerup.util.Lights import org.sert2521.powerup.util.Modes import org.sert2521.powerup.util.UDPServer +import org.sert2521.powerup.util.initPreferences +import org.sert2521.powerup.util.logTelemetry import org.sertain.Robot class Poe : Robot() { @@ -20,7 +22,11 @@ class Poe : Robot() { Auto Modes Lights + UDPServer.start() CameraServer.getInstance().startAutomaticCapture() + + initPreferences() + logTelemetry() } } diff --git a/src/main/java/org/sert2521/powerup/util/Oi.kt b/src/main/java/org/sert2521/powerup/util/Oi.kt index c313c29..52129b0 100644 --- a/src/main/java/org/sert2521/powerup/util/Oi.kt +++ b/src/main/java/org/sert2521/powerup/util/Oi.kt @@ -3,6 +3,7 @@ package org.sert2521.powerup.util import edu.wpi.first.wpilibj.Joystick import edu.wpi.first.wpilibj.Preferences import edu.wpi.first.wpilibj.XboxController +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard // Driver joysticks. Left and right used for tank drive, only right used for arcade drive. val leftJoystick by lazy { Joystick(LEFT_STICK_PORT) } @@ -19,3 +20,37 @@ val normalEjectSpeedScalar get() = Preferences.getInstance().getDouble("normal_eject_speed_scalar", 0.6) val fastEjectSpeedScalar get() = Preferences.getInstance().getDouble("fast_eject_speed_scalar", 1.0) val driveSpeedScalar get() = Preferences.getInstance().getDouble("drive_speed_scalar", 0.85) + +fun initPreferences() { + Preferences.getInstance().putDouble("intake_speed_scalar", intakeSpeedScalar) + Preferences.getInstance().putDouble("normal_eject_speed_scalar", normalEjectSpeedScalar) + Preferences.getInstance().putDouble("fast_eject_speed_scalar", fastEjectSpeedScalar) + Preferences.getInstance().putDouble("drive_speed_scalar", driveSpeedScalar) +} + +fun logTelemetry() { + "branch.txt".asResource { + println("Branch: $it") + SmartDashboard.putString("branch", it) + } + + "commit.txt".asResource { + println("Commit: $it") + SmartDashboard.putString("commit", it) + } + + "changes.txt".asResource { + println("Changes: $it") + SmartDashboard.putString("changes", it) + } + + "buildtime.txt".asResource { + println("Buildtime: $it") + SmartDashboard.putString("buildtime", it) + } +} + +fun String.asResource(work: (String) -> Unit) { + val content = this.javaClass::class.java.getResource("/$this").readText() + work(content) +} diff --git a/src/main/resources/.gitkeep b/src/main/resources/.gitkeep new file mode 100644 index 0000000..e69de29