forked from microsoft/microbit-robot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalibration.ts
57 lines (55 loc) · 1.96 KB
/
calibration.ts
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
namespace robot {
/**
* Registers button A, B, A+B to change the radio group and drift.
*/
export function startCalibrationButtons(calibrate?: boolean) {
const d = RobotDriver.instance()
input.onButtonPressed(Button.A, () =>
control.inBackground(() => {
if (d.configDrift !== undefined) {
d.playTone(440, 500)
if (d.configDrift) d.setRunDrift(d.runDrift - 1)
else d.setRadioGroup(d.radioGroup - 1)
}
showConfigurationState(d)
})
)
input.onButtonPressed(Button.B, () =>
control.inBackground(() => {
if (d.configDrift !== undefined) {
d.playTone(640, 500)
if (d.configDrift) d.setRunDrift(d.runDrift + 1)
else d.setRadioGroup(d.radioGroup + 1)
}
showConfigurationState(d)
})
)
input.onButtonPressed(Button.AB, () =>
control.inBackground(() => {
d.playTone(840, 500)
d.configDrift = !d.configDrift
showConfigurationState(d, true)
})
)
if (calibrate)
showConfigurationState(d, true)
}
function showConfigurationState(d: RobotDriver, showTitle?: boolean) {
d.showConfiguration++
try {
led.stopAnimation()
if (d.configDrift === undefined) {
basic.showString(
`RADIO ${d.radioGroup} DRIFT ${d.runDrift}`,
configuration.SCROLL_SPEED
)
} else {
const title = d.configDrift ? "DRIFT" : "RADIO"
const value = d.configDrift ? d.runDrift : d.radioGroup
basic.showString(title + " " + value, configuration.SCROLL_SPEED)
}
} finally {
d.showConfiguration--
}
}
}