diff --git a/chrono/src/main/java/com/blazedeveloper/chrono/Logger.kt b/chrono/src/main/java/com/blazedeveloper/chrono/Logger.kt index f89cc32..092c4ef 100644 --- a/chrono/src/main/java/com/blazedeveloper/chrono/Logger.kt +++ b/chrono/src/main/java/com/blazedeveloper/chrono/Logger.kt @@ -5,6 +5,7 @@ import com.blazedeveloper.chrono.dataflow.ReplaySource import com.blazedeveloper.chrono.output.ConsoleLogger import com.blazedeveloper.chrono.structure.LogTable import com.blazedeveloper.chrono.structure.LoggableInputs +import com.qualcomm.robotcore.hardware.NormalizedRGBA import kotlin.system.exitProcess import kotlin.time.Duration import kotlin.time.Duration.Companion.nanoseconds @@ -140,6 +141,7 @@ object Logger { @JvmStatic fun output(key: String, value: DoubleArray) = ifRunning { outputsTable.put(key, value) } @JvmStatic fun > output(key: String, value: E) = ifRunning { outputsTable.put(key, value) } @JvmStatic fun > output(key: String, value: Array) = ifRunning { outputsTable.put(key, value) } + @JvmStatic fun output(key: String, value: NormalizedRGBA) = ifRunning { outputsTable.put(key, value) } /** Sends data to receivers. Runs after user code. **/ internal fun postUser() = ifRunning { diff --git a/chrono/src/main/java/com/blazedeveloper/chrono/structure/LogTable.kt b/chrono/src/main/java/com/blazedeveloper/chrono/structure/LogTable.kt index 059c4bc..af89d63 100644 --- a/chrono/src/main/java/com/blazedeveloper/chrono/structure/LogTable.kt +++ b/chrono/src/main/java/com/blazedeveloper/chrono/structure/LogTable.kt @@ -1,6 +1,8 @@ package com.blazedeveloper.chrono.structure import com.blazedeveloper.chrono.structure.LogValue.Companion.asLogValue +import com.qualcomm.robotcore.hardware.NormalizedRGBA +import kotlin.math.abs import kotlin.time.Duration class LogTable @JvmOverloads constructor( @@ -87,7 +89,12 @@ class LogTable @JvmOverloads constructor( fun > put(key: String, value: E) = put(key, value.name) /** Puts an enum array [value] represented by a string into the table at a specified [key] */ - fun > put(key: String, value: Array) = put(key, value.map { it.name }.toTypedArray()) + fun > put(key: String, value: Array) = + put(key, value.map { it.name }.toTypedArray()) + + /** Puts a normalized color represented by a float array (ARGB order) into the table at a specified key */ + fun put(key: String, value: NormalizedRGBA) = + put(key, floatArrayOf(value.alpha, value.red, value.green, value.blue)) /** * Gets a raw LogValue from the table at the specified [key]. @@ -216,6 +223,21 @@ class LogTable @JvmOverloads constructor( * If the data does not exist or is of the wrong type, * the [default] is returned. */ - inline fun > get(key: String, default: Array) = + inline fun > get(key: String, default: Array) = get(key, default.map { it.name }.toTypedArray()).map { enumValueOf(it) }.toTypedArray() + + /** + * Gets a color object from the table at the specified [key], + * If the data does not exist or is of the wrong type, + * the [default] is returned. + */ + fun get(key: String, default: NormalizedRGBA): NormalizedRGBA { + val array = get(key, floatArrayOf(default.alpha, default.red, default.green, default.blue)) + return NormalizedRGBA().apply { + alpha = array[0] + red = array[1] + green = array[2] + blue = array[3] + } + } } \ No newline at end of file