LazyHardware

class LazyHardware<T>(initializer: () -> T) : ReadOnlyProperty<Any?, T>

Lazily initializes a hardware object on first access.

The cached object is discarded when an OpMode stops (see RobotController), so the next access re-runs the initializer against the new hardware map. Blocks passed to applyAfterInit are re-applied on every initialization.

Constructors

Link copied to clipboard
constructor(initializer: () -> T)

Functions

Link copied to clipboard
fun applyAfterInit(block: Configurator<T>)

Runs block on the hardware object now if it is initialized, and again after every (re-)initialization.

fun applyAfterInit(key: Any, block: Configurator<T>)

Like applyAfterInit, but replaces any earlier block registered with the same key, so repeatedly updating one setting does not accumulate blocks.

Link copied to clipboard
open operator override fun getValue(thisRef: Any?, property: KProperty<*>): T
Link copied to clipboard
fun onOpModeStop(block: () -> Unit)

Runs block every time the cached object is discarded (for example when an OpMode stops). Use this to invalidate state that mirrors the hardware, such as write caches.