Started on graph drawing

This commit is contained in:
Sebastian 2020-12-21 15:14:08 +01:00
parent 86b4b8448b
commit cdcc336d12
2 changed files with 42 additions and 14 deletions

View File

@ -4,7 +4,7 @@ use cortex_m::asm;
use cortex_m_rt::{entry, exception};
use embedded_graphics::{
drawable::Drawable, fonts::Text, image::Image, pixelcolor::BinaryColor, pixelcolor::Rgb565,
prelude::*, primitives::rectangle::Rectangle, style::PrimitiveStyleBuilder,
prelude::*, primitives::rectangle::Rectangle, primitives::Line, style::PrimitiveStyleBuilder,
style::TextStyleBuilder,
};
@ -411,6 +411,34 @@ impl App {
let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128)).into_styled(style_black);
rect.draw(&mut disp).unwrap();
let style_grid = PrimitiveStyleBuilder::new()
.stroke_color(Rgb565::new(4, 8, 4))
.stroke_width(1)
.build();
for x in (0..160).step_by(30) {
Line::new(Point::new(x, 20), Point::new(x, 127))
.into_styled(style_grid)
.draw(&mut disp)
.unwrap();
}
for y in (0..110).step_by(10) {
Line::new(Point::new(0, 127 - y), Point::new(195, 127 - y))
.into_styled(style_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), Rgb565::new(24, 48, 24))
.draw(&mut disp)
.unwrap();
}
let (spi, disp_dc, disp_rst) = disp.release();
self.spi = spi;
self.disp_dc = disp_dc;

View File

@ -15,7 +15,7 @@ impl ReflowProfile {
pub fn get_temp(&self, time: f32) -> f32 {
let mut pos = 0;
while time > self.points[pos].time && pos < 6 {
while pos < 6 && time > self.points[pos].time {
pos += 1;
}
@ -27,7 +27,7 @@ impl ReflowProfile {
let delta = (self.points[pos].temp - self.points[pos - 1].temp)
/ (self.points[pos].time - self.points[pos - 1].time);
(time - self.points[pos - 1].time) * delta
self.points[pos - 1].temp + (time - self.points[pos - 1].time) * delta
}
}
}
@ -38,27 +38,27 @@ pub const REFLOW_PROFILES: [ReflowProfile; 4] = [
points: [
ProfilePoint {
time: 0f32,
temp: 0f32,
temp: 40f32,
},
ProfilePoint {
time: 0f32,
temp: 0f32,
time: 90f32,
temp: 145f32,
},
ProfilePoint {
time: 0f32,
temp: 0f32,
time: 180f32,
temp: 180f32,
},
ProfilePoint {
time: 0f32,
temp: 0f32,
time: 210f32,
temp: 230f32,
},
ProfilePoint {
time: 0f32,
temp: 0f32,
time: 230f32,
temp: 230f32,
},
ProfilePoint {
time: 0f32,
temp: 0f32,
time: 320f32,
temp: 40f32,
},
],
},