reflow-firmware3.0/src/application/run_profile.rs

98 lines
3.0 KiB
Rust

use arrayvec::ArrayString;
use core::fmt::Write;
use embedded_graphics::{
drawable::Drawable, fonts::Text, pixelcolor::Rgb565, prelude::*, primitive_style,
primitives::rectangle::Rectangle, primitives::Line, style::PrimitiveStyle,
style::PrimitiveStyleBuilder, style::TextStyleBuilder,
};
use stm32f1xx_hal::{
delay::Delay,
gpio::{gpioa, gpiob, gpioc, Alternate, Floating, Input, Output, PushPull},
pac,
prelude::*,
qei, rcc,
spi::{Mode, Phase, Polarity, Spi, Spi1NoRemap},
stm32,
timer::{Tim3PartialRemap, Timer},
};
use crate::application::App;
use crate::profiles;
impl App {
pub fn run_profile(&mut self) {
let mut disp = self.get_display();
let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128))
.into_styled(self.styles.fill_black);
rect.draw(&mut disp).unwrap();
for x in (0..160).step_by(30) {
Line::new(Point::new(x, 20), Point::new(x, 127))
.into_styled(self.styles.grid)
.draw(&mut disp)
.unwrap();
}
for y in (0..110).step_by(10) {
Line::new(Point::new(0, 127 - y), Point::new(159, 127 - y))
.into_styled(self.styles.grid)
.draw(&mut disp)
.unwrap();
}
for t in 0..320 {
let y = 148
- (profiles::REFLOW_PROFILES[self.selected_profile].get_temp(t as f32) / 2.0)
as i32;
Pixel(Point::new((t / 2) as i32, y), self.styles.profile_color)
.draw(&mut disp)
.unwrap();
}
self.release_display(disp);
let preheat_target = profiles::REFLOW_PROFILES[self.selected_profile].get_temp(0.0);
let mut target_buf = ArrayString::<[_; 10]>::new();
// Output `xxx.xx`
write!(&mut target_buf, "{:.2}", preheat_target).expect("Failed to write to buffer");
let mut preheat_ok_count = 0;
while preheat_ok_count < 5 {
let temp = self.read_temperature();
if temp > preheat_target {
preheat_ok_count += 1;
} else {
preheat_ok_count = 0;
}
let mut temp_buf = ArrayString::<[_; 10]>::new();
// Output `xxx.xx`
write!(&mut temp_buf, "{:.2}", temp).expect("Failed to write to buffer");
let mut disp = self.get_display();
let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 10))
.into_styled(self.styles.fill_black);
rect.draw(&mut disp).unwrap();
Text::new(&temp_buf, Point::new(8, 0))
.into_styled(self.styles.text_red)
.draw(&mut disp)
.unwrap();
Text::new(&target_buf, Point::new(80, 0))
.into_styled(self.styles.text_green)
.draw(&mut disp)
.unwrap();
self.release_display(disp);
self.delay.delay_ms(1000u32);
}
loop {}
}
}