Skip to main content

printobserver_core/records/
camera_check.rs

1//! What a start reads of a camera check: the operator's check, before a
2//! print, that the camera is still aligned with its calibration on the empty
3//! build sheet.
4//!
5//! The check itself — the frame, the fit, the correction it puts in force —
6//! is the server's record, written into the printer's timeline as a
7//! [`CAMERA_CHECKED_KIND`] event, because judging a frame against a
8//! calibration is the server's. A start that names a check is held to three
9//! of that record's fields, read back as a [`CameraCheckStanding`].
10
11use printobserver_types::contract::Sample;
12use printobserver_types::schemars::JsonSchema;
13use printobserver_types::serde::{Deserialize, Serialize};
14
15use crate::records::ids::CameraCheckId;
16use crate::records::preflight::SheetId;
17
18/// The kind a camera check is written into the printer timeline under.
19pub const CAMERA_CHECKED_KIND: &str = "camera_checked";
20
21/// What one camera check found.
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
23#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
24#[schemars(crate = "printobserver_types::schemars")]
25pub enum CameraCheckVerdict {
26    /// The camera is aligned with its calibration, and the check carries the
27    /// correction a print started under it is drawn through.
28    Aligned,
29    /// The camera moved, or the sheet lies beyond the tolerance: a
30    /// calibration run is owed.
31    NotAligned,
32    /// The camera gave no frame that can show it.
33    Unavailable,
34}
35
36impl CameraCheckVerdict {
37    /// The verdict as the record spells it.
38    #[must_use]
39    pub const fn as_str(self) -> &'static str {
40        match self {
41            Self::Aligned => "aligned",
42            Self::NotAligned => "not_aligned",
43            Self::Unavailable => "unavailable",
44        }
45    }
46}
47
48/// The fields of a camera check a start is held to, read back from its
49/// record: every other field the record carries is the server's.
50#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
51#[serde(crate = "printobserver_types::serde")]
52pub struct CameraCheckStanding {
53    /// The check.
54    pub id: CameraCheckId,
55    /// The sheet it was made on.
56    pub sheet: SheetId,
57    /// What it found.
58    pub verdict: CameraCheckVerdict,
59}
60
61/// Why a start naming a camera check was refused.
62#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
63#[serde(
64    crate = "printobserver_types::serde",
65    tag = "objection",
66    rename_all = "snake_case",
67    deny_unknown_fields
68)]
69#[schemars(crate = "printobserver_types::schemars")]
70pub enum CameraCheckObjection {
71    /// No camera check of that identifier is recorded.
72    Unknown,
73    /// The check did not find the camera aligned.
74    NotAligned {
75        /// What it found instead.
76        verdict: CameraCheckVerdict,
77    },
78    /// The check was made on another sheet than the one the manifest declares.
79    OtherSheet {
80        /// The sheet the check was made on.
81        checked_on: SheetId,
82        /// The sheet the manifest declares.
83        declared: SheetId,
84    },
85}
86
87impl Sample for CameraCheckVerdict {
88    fn sample_full() -> Self {
89        Self::Aligned
90    }
91
92    fn sample_alternates() -> Vec<Self> {
93        vec![Self::NotAligned, Self::Unavailable]
94    }
95}
96
97impl Sample for CameraCheckObjection {
98    fn sample_full() -> Self {
99        Self::OtherSheet {
100            checked_on: sheet("textured-pei"),
101            declared: sheet("smooth-pei"),
102        }
103    }
104
105    fn sample_minimal() -> Self {
106        Self::Unknown
107    }
108
109    fn sample_alternates() -> Vec<Self> {
110        vec![Self::NotAligned {
111            verdict: CameraCheckVerdict::Unavailable,
112        }]
113    }
114}
115
116/// A sheet named by something.
117fn sheet(id: &str) -> SheetId {
118    SheetId::try_from(id.to_owned()).expect("a sheet named by something")
119}