|
| 1 | +package org.team5499.monkeyLib.hardware |
| 2 | + |
| 3 | +import com.ctre.phoenix.motorcontrol.can.VictorSPX |
| 4 | +import com.ctre.phoenix.motorcontrol.ControlMode |
| 5 | +import com.ctre.phoenix.motorcontrol.DemandType |
| 6 | +import com.ctre.phoenix.motorcontrol.NeutralMode |
| 7 | + |
| 8 | +class LazyVictorSPX(deviceNumber: Int) : VictorSPX(deviceNumber) { |
| 9 | + |
| 10 | + private var lastSet = Double.NaN |
| 11 | + private var lastSecondarySet = Double.NaN |
| 12 | + private var lastControlMode: ControlMode? = null |
| 13 | + private var lastDemandType: DemandType? = null |
| 14 | + private var lastBrakeMode: NeutralMode? = null |
| 15 | + |
| 16 | + public override fun set(mode: ControlMode, value: Double) { |
| 17 | + if (value != lastSet || mode != lastControlMode) { |
| 18 | + lastSet = value |
| 19 | + lastControlMode = mode |
| 20 | + lastSecondarySet = Double.NaN |
| 21 | + lastDemandType = null |
| 22 | + super.set(mode, value) |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + public override fun set(mode: ControlMode, value0: Double, demandType: DemandType, value1: Double) { |
| 27 | + @Suppress("ComplexCondition") |
| 28 | + if (value0 != lastSet || mode != lastControlMode || |
| 29 | + demandType != lastDemandType || value1 != lastSecondarySet) { |
| 30 | + lastSet = value0 |
| 31 | + lastControlMode = mode |
| 32 | + lastDemandType = demandType |
| 33 | + lastSecondarySet = value1 |
| 34 | + super.set(mode, value0, demandType, value1) |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + public override fun setNeutralMode(brakeMode: NeutralMode) { |
| 39 | + if (lastBrakeMode != brakeMode) { |
| 40 | + lastBrakeMode = brakeMode |
| 41 | + super.setNeutralMode(brakeMode) |
| 42 | + } |
| 43 | + } |
| 44 | +} |
0 commit comments