-
Notifications
You must be signed in to change notification settings - Fork 2
/
BulkDataMaster.kt
65 lines (50 loc) · 1.7 KB
/
BulkDataMaster.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.firstinspires.ftc.teamcode.bulkLib
import android.content.*
import com.qualcomm.hardware.lynx.*
import com.qualcomm.hardware.lynx.commands.core.*
import com.qualcomm.robotcore.eventloop.opmode.*
object BulkDataMaster : OpModeManagerNotifier.Notifications {
private val dataMap = HashMap<Int, BulkInputManager>()
private val imuMap = HashMap<Int, OptimizedGyro>()
@OpModeRegistrar
fun setupOpModeListenerOnStartRobot(context: Context, manager: AnnotatedOpModeManager) {
BlackMagic.opModeManager.registerListener(this)
}
override fun onOpModePostStop(opMode: OpMode?) {
}
override fun onOpModePreInit(opMode: OpMode?) {
dataMap.clear()
imuMap.clear()
}
override fun onOpModePreStart(opMode: OpMode?) {
}
fun inputFrom(lynxModule: LynxModule): BulkInput {
val address = lynxModule.moduleAddress
if (!dataMap.containsKey(address))
dataMap[address] = BulkInputManager(lynxModule)
return dataMap[address]!!.cache
}
fun clearInputCaches() {
for (m in dataMap.values)
m.clearCache()
}
fun clearGyroCaches() {
for (g in imuMap.values)
g.clearCache()
}
fun clearAllCaches() {
clearInputCaches()
clearGyroCaches()
}
fun reset() {
imuMap.clear()
dataMap.clear()
}
fun putGyro(address: Int, gyro: OptimizedGyro) {
if (!imuMap.containsKey(address))
imuMap[address] = gyro
}
}
val LynxModule.cachedInput: LynxGetBulkInputDataResponse
get() = BulkDataMaster.inputFrom(this).response
fun LynxGetBulkInputDataResponse.getAnalogInputVoltage(port: Int) = getAnalogInput(port) / 1000.0