Skip to content

Commit 9cf2e1c

Browse files
committed
take calib snapshots in a loop
1 parent 9f6d8ca commit 9cf2e1c

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
@@ -505,6 +506,7 @@ const setSelectedVideoFormat = (format: VideoFormat) => {
505506
<v-btn
506507
size="small"
507508
block
509+
v-if="isCalibrating"
508510
:variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'outlined'"
509511
:color="useStateStore().calibrationData.hasEnoughImages ? 'buttonActive' : 'error'"
510512
:disabled="!isCalibrating || !settingsValid"
@@ -517,6 +519,22 @@ const setSelectedVideoFormat = (format: VideoFormat) => {
517519
useStateStore().calibrationData.hasEnoughImages ? "Finish Calibration" : "Cancel Calibration"
518520
}}</span>
519521
</v-btn>
522+
<v-btn
523+
size="small"
524+
block
525+
v-if="!isCalibrating"
526+
color="buttonActive"
527+
:variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'outlined'"
528+
:disabled="!settingsValid"
529+
tooltip="Automatically take calibration snapshots in a loop until calibration is ended"
530+
@click="
531+
startCalibration();
532+
useCameraSettingsStore().startCalibrationSnapshotLoop();
533+
"
534+
>
535+
<v-icon start class="calib-btn-icon" size="large"> mdi-autorenew </v-icon>
536+
<span class="calib-btn-label"> Start Snapshot Loop </span>
537+
</v-btn>
520538
</v-col>
521539
</div>
522540
</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)