Skip to content

Commit ba852f7

Browse files
committed
take calib snapshots in a loop
1 parent 5d39ef5 commit ba852f7

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
@@ -196,6 +196,7 @@ const calibCanceled = ref(false);
196196
const calibSuccess = ref<boolean | undefined>(undefined);
197197
const calibEndpointFail = ref(false);
198198
const endCalibration = () => {
199+
useCameraSettingsStore().stopCalibrationSnapshotLoop();
199200
calibSuccess.value = undefined;
200201
calibEndpointFail.value = false;
201202
@@ -515,6 +516,7 @@ const setSelectedVideoFormat = (format: VideoFormat) => {
515516
<v-btn
516517
size="small"
517518
block
519+
v-if="isCalibrating"
518520
:variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'outlined'"
519521
:color="useStateStore().calibrationData.hasEnoughImages ? 'buttonActive' : 'error'"
520522
:disabled="!isCalibrating || !settingsValid"
@@ -527,6 +529,22 @@ const setSelectedVideoFormat = (format: VideoFormat) => {
527529
useStateStore().calibrationData.hasEnoughImages ? "Finish Calibration" : "Cancel Calibration"
528530
}}</span>
529531
</v-btn>
532+
<v-btn
533+
size="small"
534+
block
535+
v-if="!isCalibrating"
536+
color="buttonActive"
537+
:variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'outlined'"
538+
:disabled="!settingsValid"
539+
tooltip="Automatically take calibration snapshots in a loop until calibration is ended"
540+
@click="
541+
startCalibration();
542+
useCameraSettingsStore().startCalibrationSnapshotLoop();
543+
"
544+
>
545+
<v-icon start class="calib-btn-icon" size="large"> mdi-autorenew </v-icon>
546+
<span class="calib-btn-label"> Start Snapshot Loop </span>
547+
</v-btn>
530548
</v-col>
531549
</div>
532550
</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)