gcode_serial/models/
action.rs

1use crate::models::file::{FinishedPrint, GcodeFile};
2use crate::models::temperature::Temperature;
3use serde::{Deserialize, Serialize};
4use strum::Display;
5
6/// Main struct to communicate with the lib
7#[derive(Clone, Serialize, Deserialize)]
8pub enum Action {
9    /// telemetry data from the lib
10    Telemetry(TelemetryData),
11    /// The state of the printer changed (eg. idle or active)
12    StateChange(PrinterStatus),
13    /// a action from the printer (eg. cancel or pause)
14    PrinterAction(PrinterAction),
15    /// send a command to the lib
16    Command(Command),
17}
18
19#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Display)]
20pub enum PrinterStatus {
21    Disconnected,
22    Active,
23    Idle,
24    Errored,
25}
26
27/// Action sent by printer
28#[derive(Clone, Serialize, Deserialize, Display)]
29pub enum PrinterAction {
30    Cancel,
31    Pause,
32    Resume,
33}
34
35#[derive(Clone, Serialize, Deserialize)]
36pub enum TelemetryData {
37    /// Hotend and Bed Temperature telemtry
38    Temps(Temperature),
39    /// commands left in Que
40    Progress(u32),
41    /// Currently only used by sd-card prints (percentage completed)
42    PercentDone(u32),
43    /// Currently only used by sd-card prints (Minutes left to print)
44    MinsRemaining(u32),
45    /// total number of commands of active print
46    TotalCommandCount(u32),
47    /// target extruder temp changed
48    TargetExtruderTemp(u32),
49    /// target bed temp changed
50    TargetBedTemp(u32),
51    /// zHeight changed
52    ZHeight(f32),
53    /// Maximum ZHeight of the current print
54    MaxZHeight(f32),
55    /// Fan speed changed
56    FanSpeed(f32),
57    /// Active print file changed either file or none
58    ActiveFileChange(Option<GcodeFile>),
59    /// Finished print event
60    PrintFinished(FinishedPrint),
61}
62
63/// Send an Action command to the lib
64#[derive(Clone, Serialize, Deserialize)]
65pub enum Command {
66    /// Set target temps (bed, extruder)
67    SetTemps(u16, u16),
68    /// Start printing a file given by path
69    StartPrint(String),
70    /// stop currently active print
71    StopPrint,
72}