From 30fba3f679fda77ba3fdda4594594e9daa4dc0e4 Mon Sep 17 00:00:00 2001 From: 28shettr <28shettr@elmbrookstudents.org> Date: Fri, 24 Jul 2026 17:41:52 -0500 Subject: [PATCH 01/10] added digital sensor module --- .../dev/nextftc/hardware/lynx/NextLynxModule.kt | 6 ++++++ .../hardware/sensors/NextDigitalSensor.kt | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/hardware/src/main/kotlin/dev/nextftc/hardware/lynx/NextLynxModule.kt b/hardware/src/main/kotlin/dev/nextftc/hardware/lynx/NextLynxModule.kt index cc695ce..793f25f 100644 --- a/hardware/src/main/kotlin/dev/nextftc/hardware/lynx/NextLynxModule.kt +++ b/hardware/src/main/kotlin/dev/nextftc/hardware/lynx/NextLynxModule.kt @@ -1,6 +1,7 @@ package dev.nextftc.hardware.lynx import com.qualcomm.hardware.lynx.LynxDcMotorController +import com.qualcomm.hardware.lynx.LynxDigitalChannelController import com.qualcomm.hardware.lynx.LynxModule import com.qualcomm.hardware.lynx.LynxServoController import dev.nextftc.hardware.RobotController @@ -47,4 +48,9 @@ class NextLynxModule internal constructor(initializer: () -> LynxModule, @JvmFie val servoController: LynxServoController by LazyHardware { LynxServoController(RobotController.appContext, module) } + + /** Creates or gets a [LynxDigitalController] bound to this module. */ + val digitalController: LynxDigitalChannelController by LazyHardware { + LynxDigitalChannelController(RobotController.appContext, module) + } } diff --git a/hardware/src/main/kotlin/dev/nextftc/hardware/sensors/NextDigitalSensor.kt b/hardware/src/main/kotlin/dev/nextftc/hardware/sensors/NextDigitalSensor.kt index a3a1b62..bbdba81 100644 --- a/hardware/src/main/kotlin/dev/nextftc/hardware/sensors/NextDigitalSensor.kt +++ b/hardware/src/main/kotlin/dev/nextftc/hardware/sensors/NextDigitalSensor.kt @@ -8,8 +8,11 @@ package dev.nextftc.hardware.sensors +import com.qualcomm.hardware.lynx.LynxModule import com.qualcomm.robotcore.hardware.DigitalChannel +import com.qualcomm.robotcore.hardware.DigitalChannelImpl import dev.nextftc.hardware.RobotController +import dev.nextftc.hardware.lynx.NextLynxModule import dev.nextftc.hardware.util.LazyHardware /** @@ -42,9 +45,22 @@ class NextDigitalSensor @JvmOverloads constructor( private val inverted: Boolean = true, ) { /** + * @param module The Lynx Module, see [RobotController.controlHub], [RobotController.expansionHub], + * @param port The digital sensor port (in the range [0, 7]) * @param name Hardware map name to resolve the [DigitalChannel] from. * @param inverted If true, [isTriggered] is the opposite of the raw state. Defaults to true. */ + @JvmOverloads + constructor(module: NextLynxModule, port: Int, inverted: Boolean = true) : this( + { + DigitalChannelImpl( + module.digitalController, + port, + ) + }, + inverted, + ) + @JvmOverloads constructor(name: String, inverted: Boolean = true) : this( { From 93ab7f033cbb09ee7f4c266190ca18b634460356 Mon Sep 17 00:00:00 2001 From: 28shettr <28shettr@elmbrookstudents.org> Date: Fri, 24 Jul 2026 18:42:06 -0500 Subject: [PATCH 02/10] i2c lynx module stuff --- .../dev/nextftc/hardware/lynx/NextLynxModule.kt | 13 +++++++++++++ .../dev/nextftc/hardware/util/LazyHardware.kt | 9 +++++++++ .../main/kotlin/dev/nextftc/robot/RobotScanner.kt | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/hardware/src/main/kotlin/dev/nextftc/hardware/lynx/NextLynxModule.kt b/hardware/src/main/kotlin/dev/nextftc/hardware/lynx/NextLynxModule.kt index 793f25f..4d123c9 100644 --- a/hardware/src/main/kotlin/dev/nextftc/hardware/lynx/NextLynxModule.kt +++ b/hardware/src/main/kotlin/dev/nextftc/hardware/lynx/NextLynxModule.kt @@ -1,7 +1,10 @@ package dev.nextftc.hardware.lynx +import android.R import com.qualcomm.hardware.lynx.LynxDcMotorController import com.qualcomm.hardware.lynx.LynxDigitalChannelController +import com.qualcomm.hardware.lynx.LynxI2cDeviceSynch +import com.qualcomm.hardware.lynx.LynxI2cDeviceSynchV2 import com.qualcomm.hardware.lynx.LynxModule import com.qualcomm.hardware.lynx.LynxServoController import dev.nextftc.hardware.RobotController @@ -27,6 +30,10 @@ class NextLynxModule internal constructor(initializer: () -> LynxModule, @JvmFie private val module by LazyHardware(initializer) + private val i2cControllers = Array(4) { bus -> + LazyHardware { LynxI2cDeviceSynchV2(RobotController.appContext, module, bus) } + } + /** Current module temperature. */ val temperature: Temperature get() = module.getTemperature(TempUnit.CELSIUS).celsius @@ -49,6 +56,12 @@ class NextLynxModule internal constructor(initializer: () -> LynxModule, @JvmFie LynxServoController(RobotController.appContext, module) } + /** Creates or gets a [LynxDigitalController] bound to this module. */ + fun i2cController(bus: Int): LynxI2cDeviceSynchV2 { + require(bus in 0..3) { "I2C bus must be in range of 0 - 3, got $bus" } + return i2cControllers[bus].get() + } + /** Creates or gets a [LynxDigitalController] bound to this module. */ val digitalController: LynxDigitalChannelController by LazyHardware { LynxDigitalChannelController(RobotController.appContext, module) diff --git a/hardware/src/main/kotlin/dev/nextftc/hardware/util/LazyHardware.kt b/hardware/src/main/kotlin/dev/nextftc/hardware/util/LazyHardware.kt index ef3fa85..5cb0712 100644 --- a/hardware/src/main/kotlin/dev/nextftc/hardware/util/LazyHardware.kt +++ b/hardware/src/main/kotlin/dev/nextftc/hardware/util/LazyHardware.kt @@ -28,6 +28,15 @@ class LazyHardware(private val initializer: () -> T) : ReadOnlyProperty + value = hardwareObject + onInit.forEach { block -> block.configure(hardwareObject) } + Log.d("NextFTC", "Initialized lazy $hardwareObject") + } + } + private val onInit = mutableListOf>() fun applyAfterInit(block: Configurator) { diff --git a/robot/src/main/kotlin/dev/nextftc/robot/RobotScanner.kt b/robot/src/main/kotlin/dev/nextftc/robot/RobotScanner.kt index 90d67b9..0e28093 100644 --- a/robot/src/main/kotlin/dev/nextftc/robot/RobotScanner.kt +++ b/robot/src/main/kotlin/dev/nextftc/robot/RobotScanner.kt @@ -124,9 +124,9 @@ internal object RobotScanner : Scanner { object RobotState : OnCreateEventLoop { /** The singleton or freshly constructed instance of the user's robot. */ internal lateinit var robot: NextRobot - + override fun onCreateEventLoop(context: Context, ftcEventLoop: FtcEventLoop) { robot = RobotScanner.robotConstructor() ftcEventLoop.opModeManager.registerListener(DriverStationTelemetry) } -} \ No newline at end of file +} From 827336d7d10bdc631f8ea19ac3b8f1845048eb09 Mon Sep 17 00:00:00 2001 From: 28shettr <28shettr@elmbrookstudents.org> Date: Fri, 24 Jul 2026 18:42:55 -0500 Subject: [PATCH 03/10] i2c lynx module stuff --- .idea/caches/deviceStreaming.xml | 169 +++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) diff --git a/.idea/caches/deviceStreaming.xml b/.idea/caches/deviceStreaming.xml index dde3dd1..cdd61d8 100644 --- a/.idea/caches/deviceStreaming.xml +++ b/.idea/caches/deviceStreaming.xml @@ -99,6 +99,18 @@