Added confirmation screen
This commit is contained in:
parent
64a7b8c5ff
commit
86b4b8448b
|
@ -9,7 +9,7 @@ use embedded_graphics::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||||
use profont::{ProFont12Point, ProFont9Point};
|
use profont::{ProFont12Point, ProFont14Point, ProFont9Point};
|
||||||
use rtt_target::{rprintln, rtt_init_print};
|
use rtt_target::{rprintln, rtt_init_print};
|
||||||
use st7735_lcd::Orientation;
|
use st7735_lcd::Orientation;
|
||||||
use stm32f1xx_hal::{
|
use stm32f1xx_hal::{
|
||||||
|
@ -139,12 +139,18 @@ pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> A
|
||||||
impl App {
|
impl App {
|
||||||
pub fn run(mut self) -> ! {
|
pub fn run(mut self) -> ! {
|
||||||
self = self.splash_screen();
|
self = self.splash_screen();
|
||||||
self = self.profile_selection();
|
loop {
|
||||||
|
self = self.profile_selection();
|
||||||
loop {}
|
let (confirmed, app) = self.confirm_profile();
|
||||||
|
self = app;
|
||||||
|
if !confirmed {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
self = self.run_profile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn splash_screen(mut self) -> App {
|
fn splash_screen(mut self) -> App {
|
||||||
let mut disp =
|
let mut disp =
|
||||||
st7735_lcd::ST7735::new(self.spi, self.disp_dc, self.disp_rst, true, false, 160, 128);
|
st7735_lcd::ST7735::new(self.spi, self.disp_dc, self.disp_rst, true, false, 160, 128);
|
||||||
self.disp_cs.set_low().unwrap();
|
self.disp_cs.set_low().unwrap();
|
||||||
|
@ -166,8 +172,6 @@ impl App {
|
||||||
|
|
||||||
self.delay.delay_ms(2000u16);
|
self.delay.delay_ms(2000u16);
|
||||||
|
|
||||||
rect.draw(&mut disp).unwrap();
|
|
||||||
|
|
||||||
let (spi, disp_dc, disp_rst) = disp.release();
|
let (spi, disp_dc, disp_rst) = disp.release();
|
||||||
self.spi = spi;
|
self.spi = spi;
|
||||||
self.disp_dc = disp_dc;
|
self.disp_dc = disp_dc;
|
||||||
|
@ -176,7 +180,7 @@ impl App {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn profile_selection(mut self) -> App {
|
fn profile_selection(mut self) -> App {
|
||||||
let mut disp =
|
let mut disp =
|
||||||
st7735_lcd::ST7735::new(self.spi, self.disp_dc, self.disp_rst, true, false, 160, 128);
|
st7735_lcd::ST7735::new(self.spi, self.disp_dc, self.disp_rst, true, false, 160, 128);
|
||||||
self.disp_cs.set_low().unwrap();
|
self.disp_cs.set_low().unwrap();
|
||||||
|
@ -185,6 +189,13 @@ impl App {
|
||||||
disp.set_orientation(&Orientation::LandscapeSwapped)
|
disp.set_orientation(&Orientation::LandscapeSwapped)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let style_black = PrimitiveStyleBuilder::new()
|
||||||
|
.fill_color(Rgb565::BLACK)
|
||||||
|
.build();
|
||||||
|
let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128)).into_styled(style_black);
|
||||||
|
|
||||||
|
rect.draw(&mut disp).unwrap();
|
||||||
|
|
||||||
let text_lager = TextStyleBuilder::new(ProFont12Point)
|
let text_lager = TextStyleBuilder::new(ProFont12Point)
|
||||||
.text_color(Rgb565::WHITE)
|
.text_color(Rgb565::WHITE)
|
||||||
.build();
|
.build();
|
||||||
|
@ -206,23 +217,25 @@ impl App {
|
||||||
.draw(&mut disp)
|
.draw(&mut disp)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let encoder_start = self.qei.count();
|
||||||
|
|
||||||
let mut press_count = 0;
|
let mut press_count = 0;
|
||||||
let mut needs_redraw = true;
|
let mut needs_redraw = true;
|
||||||
while press_count < 5 {
|
while press_count < 5 {
|
||||||
if needs_redraw {
|
if needs_redraw {
|
||||||
for i in 0..profiles::REFLOW_PROFILES.len() {
|
for i in 0..profiles::REFLOW_PROFILES.len() {
|
||||||
let rect = Rectangle::new(
|
let style = if i == self.selected_profile {
|
||||||
|
selected_box
|
||||||
|
} else {
|
||||||
|
profile_box
|
||||||
|
};
|
||||||
|
Rectangle::new(
|
||||||
Point::new(0, 20 + (i as i32) * 16),
|
Point::new(0, 20 + (i as i32) * 16),
|
||||||
Point::new(159, 20 + (i as i32) * 16 + 16),
|
Point::new(159, 20 + (i as i32) * 16 + 16),
|
||||||
);
|
)
|
||||||
|
.into_styled(style)
|
||||||
let styled_rect = if i == self.selected_profile {
|
.draw(&mut disp)
|
||||||
rect.into_styled(selected_box)
|
.unwrap();
|
||||||
} else {
|
|
||||||
rect.into_styled(profile_box)
|
|
||||||
};
|
|
||||||
|
|
||||||
styled_rect.draw(&mut disp).unwrap();
|
|
||||||
|
|
||||||
Text::new(
|
Text::new(
|
||||||
profiles::REFLOW_PROFILES[i].get_name(),
|
profiles::REFLOW_PROFILES[i].get_name(),
|
||||||
|
@ -236,7 +249,8 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.delay.delay_ms(10u16);
|
self.delay.delay_ms(10u16);
|
||||||
let new_selection = ((self.qei.count() as usize) / 4) % profiles::REFLOW_PROFILES.len();
|
let new_selection = (((self.qei.count().wrapping_sub(encoder_start)) as usize) / 4)
|
||||||
|
% profiles::REFLOW_PROFILES.len();
|
||||||
if new_selection != self.selected_profile {
|
if new_selection != self.selected_profile {
|
||||||
self.selected_profile = new_selection;
|
self.selected_profile = new_selection;
|
||||||
needs_redraw = true;
|
needs_redraw = true;
|
||||||
|
@ -261,4 +275,149 @@ impl App {
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn confirm_profile(mut self) -> (bool, App) {
|
||||||
|
let mut disp =
|
||||||
|
st7735_lcd::ST7735::new(self.spi, self.disp_dc, self.disp_rst, true, false, 160, 128);
|
||||||
|
self.disp_cs.set_low().unwrap();
|
||||||
|
|
||||||
|
disp.init(&mut self.delay).unwrap();
|
||||||
|
disp.set_orientation(&Orientation::LandscapeSwapped)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let style_black = PrimitiveStyleBuilder::new()
|
||||||
|
.fill_color(Rgb565::BLACK)
|
||||||
|
.build();
|
||||||
|
let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128)).into_styled(style_black);
|
||||||
|
rect.draw(&mut disp).unwrap();
|
||||||
|
|
||||||
|
let text = TextStyleBuilder::new(ProFont12Point)
|
||||||
|
.text_color(Rgb565::WHITE)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let text_big = TextStyleBuilder::new(ProFont14Point)
|
||||||
|
.text_color(Rgb565::WHITE)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let text_big_black = TextStyleBuilder::new(ProFont14Point)
|
||||||
|
.text_color(Rgb565::BLACK)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let normal_box = PrimitiveStyleBuilder::new()
|
||||||
|
.fill_color(Rgb565::BLACK)
|
||||||
|
.stroke_color(Rgb565::WHITE)
|
||||||
|
.stroke_width(1)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let ok_box = PrimitiveStyleBuilder::new()
|
||||||
|
.fill_color(Rgb565::GREEN)
|
||||||
|
.stroke_color(Rgb565::WHITE)
|
||||||
|
.stroke_width(1)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let cancel_box = PrimitiveStyleBuilder::new()
|
||||||
|
.fill_color(Rgb565::RED)
|
||||||
|
.stroke_color(Rgb565::WHITE)
|
||||||
|
.stroke_width(1)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Text::new("Confirm profile", Point::new(4, 4))
|
||||||
|
.into_styled(text)
|
||||||
|
.draw(&mut disp)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Text::new(
|
||||||
|
profiles::REFLOW_PROFILES[self.selected_profile].get_name(),
|
||||||
|
Point::new(20, 50),
|
||||||
|
)
|
||||||
|
.into_styled(text_big)
|
||||||
|
.draw(&mut disp)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut press_count = 0;
|
||||||
|
let mut needs_redraw = true;
|
||||||
|
let mut confirmed = false;
|
||||||
|
let encoder_start = self.qei.count();
|
||||||
|
|
||||||
|
while press_count < 5 {
|
||||||
|
if needs_redraw {
|
||||||
|
let style = if confirmed { ok_box } else { normal_box };
|
||||||
|
Rectangle::new(Point::new(4, 104), Point::new(70, 124))
|
||||||
|
.into_styled(style)
|
||||||
|
.draw(&mut disp)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let text_style = if confirmed { text_big_black } else { text_big };
|
||||||
|
Text::new("Start", Point::new(12, 105))
|
||||||
|
.into_styled(text_style)
|
||||||
|
.draw(&mut disp)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let style = if !confirmed { cancel_box } else { normal_box };
|
||||||
|
Rectangle::new(Point::new(90, 104), Point::new(155, 124))
|
||||||
|
.into_styled(style)
|
||||||
|
.draw(&mut disp)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let text_style = if !confirmed { text_big_black } else { text_big };
|
||||||
|
Text::new("Cancel", Point::new(96, 105))
|
||||||
|
.into_styled(text_style)
|
||||||
|
.draw(&mut disp)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
needs_redraw = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.delay.delay_ms(10u16);
|
||||||
|
let new_selection =
|
||||||
|
(((self.qei.count().wrapping_sub(encoder_start)) as usize) / 4) % 2 == 0;
|
||||||
|
if new_selection != confirmed {
|
||||||
|
needs_redraw = true;
|
||||||
|
confirmed = new_selection;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !needs_redraw && self.button.is_low().unwrap() {
|
||||||
|
press_count += 1;
|
||||||
|
} else {
|
||||||
|
press_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the button has been released, before continuing to the next stage
|
||||||
|
while !self.button.is_high().unwrap() {
|
||||||
|
self.delay.delay_ms(10u16);
|
||||||
|
}
|
||||||
|
|
||||||
|
let (spi, disp_dc, disp_rst) = disp.release();
|
||||||
|
self.spi = spi;
|
||||||
|
self.disp_dc = disp_dc;
|
||||||
|
self.disp_rst = disp_rst;
|
||||||
|
|
||||||
|
(confirmed, self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_profile(mut self) -> App {
|
||||||
|
let mut disp =
|
||||||
|
st7735_lcd::ST7735::new(self.spi, self.disp_dc, self.disp_rst, true, false, 160, 128);
|
||||||
|
self.disp_cs.set_low().unwrap();
|
||||||
|
|
||||||
|
disp.init(&mut self.delay).unwrap();
|
||||||
|
disp.set_orientation(&Orientation::LandscapeSwapped)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let style_black = PrimitiveStyleBuilder::new()
|
||||||
|
.fill_color(Rgb565::BLACK)
|
||||||
|
.build();
|
||||||
|
let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128)).into_styled(style_black);
|
||||||
|
rect.draw(&mut disp).unwrap();
|
||||||
|
|
||||||
|
let (spi, disp_dc, disp_rst) = disp.release();
|
||||||
|
self.spi = spi;
|
||||||
|
self.disp_dc = disp_dc;
|
||||||
|
self.disp_rst = disp_rst;
|
||||||
|
|
||||||
|
loop {}
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub const REFLOW_PROFILES: [ReflowProfile; 4] = [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
ReflowProfile {
|
ReflowProfile {
|
||||||
name: "To Cold",
|
name: "Too Cold",
|
||||||
points: [
|
points: [
|
||||||
ProfilePoint {
|
ProfilePoint {
|
||||||
time: 0f32,
|
time: 0f32,
|
||||||
|
|
Loading…
Reference in New Issue