Skip to content

Commit 026a619

Browse files
committed
take calib snapshots in a loop
1 parent 8e88a9a commit 026a619

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

photon-client/src/components/cameras/CameraCalibrationCard.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ const calibCanceled = ref(false);
184184
const calibSuccess = ref<boolean | undefined>(undefined);
185185
const calibEndpointFail = ref(false);
186186
const endCalibration = () => {
187+
useCameraSettingsStore().stopCalibrationSnapshotLoop();
187188
calibSuccess.value = undefined;
188189
calibEndpointFail.value = false;
189190
@@ -490,6 +491,7 @@ const setSelectedVideoFormat = (format: VideoFormat) => {
490491
<v-btn
491492
size="small"
492493
block
494+
v-if="isCalibrating"
493495
:variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'outlined'"
494496
:color="useStateStore().calibrationData.hasEnoughImages ? 'buttonActive' : 'error'"
495497
:disabled="!isCalibrating || !settingsValid"
@@ -502,6 +504,22 @@ const setSelectedVideoFormat = (format: VideoFormat) => {
502504
useStateStore().calibrationData.hasEnoughImages ? "Finish Calibration" : "Cancel Calibration"
503505
}}</span>
504506
</v-btn>
507+
<v-btn
508+
size="small"
509+
block
510+
v-if="!isCalibrating"
511+
color="buttonActive"
512+
:variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'outlined'"
513+
:disabled="!settingsValid"
514+
tooltip="Automatically take calibration snapshots in a loop until calibration is ended"
515+
@click="
516+
startCalibration();
517+
useCameraSettingsStore().startCalibrationSnapshotLoop();
518+
"
519+
>
520+
<v-icon start class="calib-btn-icon" size="large"> mdi-autorenew </v-icon>
521+
<span class="calib-btn-label"> Start Snapshot Loop </span>
522+
</v-btn>
505523
</v-col>
506524
</div>
507525
</v-card-text>

photon-client/src/stores/settings/CameraSettingsStore.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,32 @@ export const useCameraSettingsStore = defineStore("cameraSettings", {
422422
};
423423
useStateStore().websocket?.send(payload, true);
424424
},
425+
426+
/**
427+
* Start repeatedly calling takeCalibrationSnapshot every intervalMs milliseconds.
428+
* No-op if already running. Call stopCalibrationSnapshotLoop() to stop.
429+
*
430+
* @param intervalMs interval in milliseconds between snapshots (default 1000)
431+
* @param cameraUniqueName camera to snapshot (captured when the loop starts)
432+
*/
433+
startCalibrationSnapshotLoop(intervalMs = 500, cameraUniqueName: string = useStateStore().currentCameraUniqueName) {
434+
// store the interval id on the store instance (avoid changing state shape)
435+
if ((this as any)._calibrationSnapshotInterval != null) return;
436+
// take one immediately then schedule
437+
this.takeCalibrationSnapshot(cameraUniqueName);
438+
(this as any)._calibrationSnapshotInterval = window.setInterval(() => {
439+
this.takeCalibrationSnapshot(cameraUniqueName);
440+
}, intervalMs);
441+
},
442+
443+
/**
444+
* Stop a running calibration snapshot loop started with startCalibrationSnapshotLoop().
445+
*/
446+
stopCalibrationSnapshotLoop() {
447+
if ((this as any)._calibrationSnapshotInterval == null) return;
448+
clearInterval((this as any)._calibrationSnapshotInterval);
449+
(this as any)._calibrationSnapshotInterval = null;
450+
},
425451
/**
426452
* Save a snapshot of the input frame of the camera.
427453
*

0 commit comments

Comments
 (0)