Skip to content

Commit dbc2d6c

Browse files
Temperature presets
1 parent ee8cbd1 commit dbc2d6c

18 files changed

Lines changed: 288 additions & 155 deletions

example_configs/simulator.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ height = 272
44

55
[moonraker]
66
host = "localhost"
7-
port = 7125
7+
port = 7125
8+
9+
[heater_presets]
10+
extruder = [ 200, 240, 280 ]
11+
heater_bed = [ 60, 70 ]

moonraker-rs/src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
};
55

66
// TODO: Fill cache with configuration for min/max temp
7-
#[derive(Debug, Default)]
7+
#[derive(Debug, Default, Clone)]
88
pub struct Cache {
99
pub webhooks: Webhooks,
1010
pub motion_report: MotionReport,

moonraker-rs/src/moonraker_connection.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ pub struct MoonrakerConnection {
7171
outbound_event_sender: Sender<Arc<OutboundMessage>>,
7272
outbound_event_listener: Receiver<Arc<OutboundMessage>>,
7373
incrementing_id: Mutex<u32>,
74+
preconfigured_cache: Option<Cache>,
7475
}
7576

7677
impl MoonrakerConnection {
77-
pub fn new(host: &str, port: u16) -> Self {
78+
pub fn new(host: &str, port: u16, preconfigured_cache : Option<Cache>) -> Self {
7879
let host = format!("{}:{}", host, port);
7980

8081
let req = Request::builder()
@@ -107,6 +108,7 @@ impl MoonrakerConnection {
107108
outbound_event_sender: outbound_event_sender,
108109
outbound_event_listener: outbound_event_listener,
109110
incrementing_id: Mutex::new(1),
111+
preconfigured_cache
110112
}
111113
}
112114

@@ -126,7 +128,7 @@ impl MoonrakerConnection {
126128
.expect("Failed to internally send a disconnect event");
127129
let reader;
128130
let writer;
129-
let cache = Arc::new(Mutex::new(Cache::new()));
131+
let cache = Arc::new(Mutex::new(self.preconfigured_cache.clone().unwrap_or_default()));
130132

131133
match self.reconnect().await {
132134
Ok((r, w)) => {

moonraker-rs/src/printer_objects/extruder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use optional_struct::*;
22
use serde::Deserialize;
33

4-
use crate::printer_objects::TempControl;
4+
use crate::printer_objects::TemperatureConfiguration;
55

66
#[optional_struct]
77
#[derive(Debug, Deserialize, Clone)]
@@ -13,7 +13,7 @@ pub struct Extruder {
1313
pub pressure_advance: f32,
1414
pub smooth_time: f32,
1515
pub motion_queue: Option<String>,
16-
pub temp_control: TempControl
16+
pub configuration: TemperatureConfiguration
1717
}
1818

1919
impl Default for Extruder {
@@ -26,7 +26,7 @@ impl Default for Extruder {
2626
pressure_advance: 0.0,
2727
smooth_time: 0.0,
2828
motion_queue: None,
29-
temp_control: TempControl::default_hotend(),
29+
configuration: TemperatureConfiguration::default_hotend(),
3030
}
3131
}
3232
}
@@ -54,8 +54,8 @@ impl Extruder {
5454
if let Some(motion_queue) = extruder.motion_queue {
5555
self.motion_queue = Some(motion_queue);
5656
}
57-
if let Some(temp_control) = extruder.temp_control {
58-
self.temp_control = temp_control;
57+
if let Some(configuration) = extruder.configuration {
58+
self.configuration = configuration;
5959
}
6060
}
6161
}

moonraker-rs/src/printer_objects/heater_bed.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use optional_struct::*;
22
use serde::Deserialize;
33

4-
use crate::printer_objects::TempControl;
4+
use crate::printer_objects::TemperatureConfiguration;
55

66
#[optional_struct]
77
#[derive(Debug, Deserialize, Clone)]
88
pub struct HeaterBed {
99
pub temperature: f32,
1010
pub target: f32,
1111
pub power: f32,
12-
pub temp_control: TempControl,
12+
pub configuration: TemperatureConfiguration,
1313
}
1414

1515
impl Default for HeaterBed {
@@ -18,7 +18,7 @@ impl Default for HeaterBed {
1818
temperature: 0.0,
1919
target: 0.0,
2020
power: 0.0,
21-
temp_control: TempControl::default_bed(),
21+
configuration: TemperatureConfiguration::default_bed(),
2222
}
2323
}
2424
}
@@ -34,8 +34,8 @@ impl HeaterBed {
3434
if let Some(power) = heater_bed.power {
3535
self.power = power;
3636
}
37-
if let Some(temp_control) = heater_bed.temp_control {
38-
self.temp_control = temp_control;
37+
if let Some(configuration) = heater_bed.configuration {
38+
self.configuration = configuration;
3939
}
4040
}
4141
}

moonraker-rs/src/printer_objects/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub mod temperature_sensor;
1515
pub mod toolhead;
1616
pub mod virtual_sdcard;
1717
pub mod webhooks;
18-
pub mod temp_control;
18+
pub mod temp_config;
1919

2020
pub use display_status::*;
2121
pub use exclude_object::*;
@@ -34,4 +34,4 @@ pub use temperature_sensor::*;
3434
pub use toolhead::*;
3535
pub use virtual_sdcard::*;
3636
pub use webhooks::*;
37-
pub use temp_control::*;
37+
pub use temp_config::*;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use serde::Deserialize;
2+
3+
#[derive(Debug, Deserialize, Clone, PartialEq)]
4+
pub struct TemperatureConfiguration
5+
{
6+
pub presets : Vec<u32>
7+
}
8+
9+
impl TemperatureConfiguration {
10+
pub fn default_hotend() -> Self {
11+
Self {
12+
presets: vec![200, 240, 260],
13+
}
14+
}
15+
pub fn default_bed() -> Self {
16+
Self {
17+
presets: vec![40, 60, 70],
18+
}
19+
}
20+
pub fn default_fan() -> Self {
21+
Self {
22+
presets: vec![40, 50, 60],
23+
}
24+
}
25+
pub fn from(presets: Vec<u32>) -> Self {
26+
Self { presets }
27+
}
28+
}

moonraker-rs/src/printer_objects/temp_control.rs

Lines changed: 0 additions & 33 deletions
This file was deleted.

moonraker-rs/src/printer_objects/temperature_fan.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use optional_struct::*;
22
use serde::Deserialize;
33

4-
use crate::printer_objects::TempControl;
4+
use crate::printer_objects::TemperatureConfiguration;
55

66
#[optional_struct]
77
#[derive(Debug, Deserialize, Clone)]
@@ -10,7 +10,7 @@ pub struct TemperatureFan {
1010
pub rpm: Option<f32>,
1111
pub temperature: f32,
1212
pub target: f32,
13-
pub temp_control: TempControl
13+
pub configuration: TemperatureConfiguration
1414
}
1515

1616
impl Default for TemperatureFan {
@@ -20,7 +20,7 @@ impl Default for TemperatureFan {
2020
rpm: None,
2121
temperature: 0.0,
2222
target: 0.0,
23-
temp_control: TempControl::default_fan(),
23+
configuration: TemperatureConfiguration::default_fan(),
2424
}
2525
}
2626
}
@@ -51,8 +51,8 @@ impl TemperatureFan {
5151
if let Some(target) = fan.target {
5252
self.target = target;
5353
}
54-
if let Some(temp_control) = fan.temp_control {
55-
self.temp_control = temp_control;
54+
if let Some(configuration) = fan.configuration {
55+
self.configuration = configuration;
5656
}
5757
}
5858
}

src/config/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
use std::collections::HashMap;
2+
13
use crate::config::MoonrakerConfig;
4+
use moonraker_rs::printer_objects::TemperatureConfiguration;
25
use serde::Deserialize;
36

47
use super::DisplayConfig;
@@ -7,4 +10,5 @@ use super::DisplayConfig;
710
pub struct Config {
811
pub display: DisplayConfig,
912
pub moonraker: Option<MoonrakerConfig>,
13+
pub heater_presets: Option<HashMap<String, Vec<u32>>>,
1014
}

0 commit comments

Comments
 (0)