Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chrono/src/main/java/com/blazedeveloper/chrono/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -140,6 +141,7 @@ object Logger {
@JvmStatic fun output(key: String, value: DoubleArray) = ifRunning { outputsTable.put(key, value) }
@JvmStatic fun <E : Enum<E>> output(key: String, value: E) = ifRunning { outputsTable.put(key, value) }
@JvmStatic fun <E : Enum<E>> output(key: String, value: Array<E>) = 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -87,7 +89,12 @@ class LogTable @JvmOverloads constructor(
fun <E : Enum<E>> 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 <E : Enum<E>> put(key: String, value: Array<E>) = put(key, value.map { it.name }.toTypedArray())
fun <E : Enum<E>> put(key: String, value: Array<E>) =
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].
Expand Down Expand Up @@ -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 <reified E: Enum<E>> get(key: String, default: Array<E>) =
inline fun <reified E : Enum<E>> get(key: String, default: Array<E>) =
get(key, default.map { it.name }.toTypedArray()).map { enumValueOf<E>(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]
}
}
}