forked from chopshop-166/chopshoplib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
102 changed files
with
1,303 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# | ||
# https://help.github.com/articles/dealing-with-line-endings/ | ||
# | ||
# These are explicitly windows files and should use crlf | ||
*.bat text eol=crlf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,7 +136,7 @@ $RECYCLE.BIN/ | |
|
||
### Gradle ### | ||
.gradle | ||
/build/ | ||
build/ | ||
|
||
# Ignore Gradle GUI config | ||
gradle-app.setting | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* This file was generated by the Gradle 'init' task. | ||
*/ | ||
|
||
plugins { | ||
// Support convention plugins written in Groovy. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build. | ||
id 'groovy-gradle-plugin' | ||
} | ||
|
||
repositories { | ||
// Use the plugin portal to apply community plugins in convention plugins. | ||
gradlePluginPortal() | ||
} |
11 changes: 11 additions & 0 deletions
11
buildSrc/src/main/groovy/com.chopshop166.chopshoplib.java-application-conventions.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* This file was generated by the Gradle 'init' task. | ||
*/ | ||
|
||
plugins { | ||
// Apply the common convention plugin for shared build configuration between library and application projects. | ||
id 'com.chopshop166.chopshoplib.java-common-conventions' | ||
|
||
// Apply the application plugin to add support for building a CLI application in Java. | ||
id 'application' | ||
} |
21 changes: 21 additions & 0 deletions
21
buildSrc/src/main/groovy/com.chopshop166.chopshoplib.java-common-conventions.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* This file was generated by the Gradle 'init' task. | ||
*/ | ||
|
||
plugins { | ||
// Apply the java Plugin to add support for Java. | ||
id 'java' | ||
} | ||
|
||
dependencies { | ||
// Use JUnit Jupiter API for testing. | ||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' | ||
|
||
// Use JUnit Jupiter Engine for testing. | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' | ||
} | ||
|
||
tasks.named('test') { | ||
// Use junit platform for unit tests. | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
id 'com.chopshop166.chopshoplib.java-library-conventions' | ||
id 'com.github.spotbugs' version '4.7.3' | ||
id 'edu.wpi.first.GradleRIO' version '2021.3.1' | ||
} | ||
|
||
dependencies { | ||
|
||
api wpi.deps.wpilib() | ||
api wpi.deps.vendor.java() | ||
|
||
implementation group: 'com.google.guava', name: 'guava', version: '30.1-jre' | ||
} | ||
|
||
publishing { | ||
publications { | ||
core(MavenPublication) { | ||
from components.java | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
core/src/main/java/com/chopshop166/chopshoplib/Dashboard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
@file:OptIn(kotlin.experimental.ExperimentalTypeInference::class) | ||
package com.chopshop166.chopshoplib | ||
|
||
import edu.wpi.cscore.VideoSink | ||
import edu.wpi.cscore.VideoSource | ||
import edu.wpi.first.cameraserver.CameraServer | ||
import edu.wpi.first.wpilibj.Sendable | ||
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard | ||
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardContainer | ||
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard | ||
|
||
class DashboardWrapper internal constructor () { | ||
operator fun set(name: String, value: Sendable) = (name displays value) | ||
operator fun set(name: String, value: Boolean) = (name displays value) | ||
operator fun set(name: String, value: String) = (name displays value) | ||
operator fun set(name: String, value: Double) = (name displays value) | ||
operator fun set(name: String, value: Int) = (name displays value) | ||
|
||
operator fun get(name: String) = SmartDashboard.getData(name) | ||
|
||
operator fun invoke(block: DashboardWrapper.() -> Unit = {}) = apply(block) | ||
|
||
infix fun String.displays(value: Sendable) = SmartDashboard.putData(this, value) | ||
infix fun String.displays(value: Boolean) = SmartDashboard.putBoolean(this, value) | ||
infix fun String.displays(value: String) = SmartDashboard.putString(this, value) | ||
infix fun String.displays(value: Double) = SmartDashboard.putNumber(this, value) | ||
infix fun String.displays(value: Int) = SmartDashboard.putNumber(this, value.toDouble()) | ||
|
||
fun entry(name: String) = SmartDashboard.getEntry(name) | ||
} | ||
val dashboard = DashboardWrapper() | ||
|
||
class ShuffleboardContainerWrapper internal constructor (val con : ShuffleboardContainer) { | ||
|
||
val title : String get() { return con.getTitle() } | ||
|
||
operator fun set(name: String, value: Sendable) = name(value) | ||
@OverloadResolutionByLambdaReturnType | ||
@JvmName("setBoolean") operator fun set(name: String, value: () -> Boolean) = name(value) | ||
@JvmName("setString") operator fun set(name: String, value: () -> String) = name(value) | ||
@JvmName("setNumber") operator fun set(name: String, value: () -> Double) = name(value) | ||
@JvmName("setInt") operator fun set(name: String, value: () -> Int) = name(value) | ||
|
||
operator fun get(name: String) = ShuffleboardContainerWrapper(con.getLayout(name)) | ||
fun layout(name : String, block: ShuffleboardContainerWrapper.() -> Unit = {}) = this[name].run(block) | ||
|
||
operator fun String.invoke(value: Sendable) = con.add(this, value) | ||
@OverloadResolutionByLambdaReturnType | ||
@JvmName("invokeBoolean") operator fun String.invoke(value: () -> Boolean) = con.addBoolean(this, value) | ||
@JvmName("invokeString") operator fun String.invoke(value: () -> String) = con.addString(this, value) | ||
@JvmName("invokeNumber") operator fun String.invoke(value: () -> Double) = con.addNumber(this, value) | ||
@JvmName("invokeInt") operator fun String.invoke(value: () -> Int) = con.addNumber(this) { value().toDouble() } | ||
} | ||
fun shuffleboard(name : String, block: ShuffleboardContainerWrapper.() -> Unit = {}) = ShuffleboardContainerWrapper(Shuffleboard.getTab(name)).apply(block) | ||
|
||
class ChooserWrapper<T>(val chooser: SendableChooser<T>) { | ||
infix fun String.default(value: T) { chooser.setDefaultOption(this, value) } | ||
infix fun String.chooses(value: T) { chooser.addOption(this, value) } | ||
} | ||
|
||
inline fun <reified T> chooser(block: ChooserWrapper<T>.() -> Unit) = SendableChooser<T>().apply { | ||
ChooserWrapper<T>(this).block() | ||
} | ||
|
||
class VideoSourceWrapper(val source: VideoSource) { | ||
operator fun get(name: String) = source.getProperty(name).get() | ||
operator fun set(name: String, value: Int) = source.getProperty(name).set(value) | ||
} | ||
|
||
class VideoSinkWrapper(val sink: VideoSink) { | ||
operator fun get(name: String) = sink.getProperty(name).get() | ||
operator fun set(name: String, value: Int) = sink.getProperty(name).set(value) | ||
} | ||
|
||
class CameraServerWrapper(private val base: CameraServer) { | ||
fun server(block: VideoSinkWrapper.() -> Unit = {}) = | ||
base.getServer().apply { VideoSinkWrapper(this).block() } | ||
fun server(name: String, block: VideoSinkWrapper.() -> Unit = {}) = | ||
base.getServer(name).apply { VideoSinkWrapper(this).block() } | ||
fun source(block: VideoSourceWrapper.() -> Unit = {}) = | ||
base.startAutomaticCapture().apply { VideoSourceWrapper(this).block() } | ||
fun source(dev: Int, block: VideoSourceWrapper.() -> Unit = {}) = | ||
base.startAutomaticCapture(dev).apply { VideoSourceWrapper(this).block() } | ||
fun source(camera: VideoSource, block: VideoSinkWrapper.() -> Unit = {}) = | ||
base.startAutomaticCapture(camera).apply { VideoSinkWrapper(this).block() } | ||
fun source(name: String, dev: Int, block: VideoSourceWrapper.() -> Unit = {}) = | ||
base.startAutomaticCapture(name, dev).apply { VideoSourceWrapper(this).block() } | ||
fun source(name: String, path: String, block: VideoSourceWrapper.() -> Unit = {}) = | ||
base.startAutomaticCapture(name, path).apply { VideoSourceWrapper(this).block() } | ||
} | ||
|
||
val cameraServer = CameraServerWrapper(CameraServer.getInstance()) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.chopshop166.chopshoplib | ||
|
||
import kotlin.math.max | ||
import kotlin.math.min | ||
import kotlin.math.pow | ||
import kotlin.math.withSign | ||
|
||
fun Double.clamped(minVal : Double, maxVal : Double) = max(minVal, min(maxVal, this)) | ||
fun Float.clamped(minVal : Float, maxVal : Float) = max(minVal, min(maxVal, this)) | ||
fun Int.clamped(minVal : Int, maxVal : Int) = max(minVal, min(maxVal, this)) | ||
fun Long.clamped(minVal : Long, maxVal : Long) = max(minVal, min(maxVal, this)) | ||
|
||
fun Double.signPow(exp : Double) = pow(exp).withSign(this) | ||
|
||
typealias BoolFunc = ()->Boolean | ||
operator fun BoolFunc.not() = {!this()} | ||
infix fun BoolFunc.and(other : BoolFunc) = {this() && other()} | ||
infix fun BoolFunc.or(other : BoolFunc) = {this() || other()} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.