♻️ Makes imu calibration use request reponse
This commit is contained in:
@@ -9,11 +9,7 @@
|
|||||||
import { useFeatureFlags } from '$lib/stores/featureFlags'
|
import { useFeatureFlags } from '$lib/stores/featureFlags'
|
||||||
import { Rotate3d } from '$lib/components/icons'
|
import { Rotate3d } from '$lib/components/icons'
|
||||||
|
|
||||||
import {
|
import { type IMUCalibrateData, IMUData } from '$lib/platform_shared/websocket_message'
|
||||||
IMUCalibrateData,
|
|
||||||
IMUCalibrateExecute,
|
|
||||||
IMUData
|
|
||||||
} from '$lib/platform_shared/websocket_message'
|
|
||||||
|
|
||||||
Chart.register(...registerables)
|
Chart.register(...registerables)
|
||||||
|
|
||||||
@@ -216,37 +212,31 @@
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const eventListeners: (() => void)[] = []
|
let unsubscribeImu: (() => void) | undefined
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
eventListeners.push(
|
unsubscribeImu = socket.on(IMUData, data => {
|
||||||
...[
|
console.log(data)
|
||||||
socket.on(IMUData, data => {
|
imu.addData(data)
|
||||||
console.log(data)
|
})
|
||||||
imu.addData(data)
|
|
||||||
}),
|
|
||||||
|
|
||||||
socket.on(IMUCalibrateData, data => {
|
|
||||||
isCalibrating = false
|
|
||||||
calibrationResult = data
|
|
||||||
})
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
initializeCharts()
|
initializeCharts()
|
||||||
intervalId = setInterval(updateData, 200)
|
intervalId = setInterval(updateData, 200)
|
||||||
})
|
})
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
for (let offFunction of eventListeners) {
|
unsubscribeImu?.()
|
||||||
offFunction()
|
|
||||||
}
|
|
||||||
clearInterval(intervalId)
|
clearInterval(intervalId)
|
||||||
})
|
})
|
||||||
|
|
||||||
function startCalibration() {
|
async function startCalibration() {
|
||||||
isCalibrating = true
|
isCalibrating = true
|
||||||
calibrationResult = null
|
calibrationResult = null
|
||||||
socket.sendEvent(IMUCalibrateExecute, {})
|
try {
|
||||||
|
const response = await socket.request({ imuCalibrateExecute: {} })
|
||||||
|
calibrationResult = response.imuCalibrateData ?? null
|
||||||
|
} finally {
|
||||||
|
isCalibrating = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user