122 lines
3.8 KiB
Rust
122 lines
3.8 KiB
Rust
use embedded_graphics::{
|
|
drawable::Drawable, fonts::Text, pixelcolor::BinaryColor, pixelcolor::Rgb565, prelude::*,
|
|
primitives::rectangle::Rectangle, primitives::Line, style::PrimitiveStyleBuilder,
|
|
style::TextStyleBuilder,
|
|
};
|
|
|
|
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
|
use profont::ProFont12Point;
|
|
|
|
use st7735_lcd::Orientation;
|
|
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 profile_selection(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 text_lager = TextStyleBuilder::new(ProFont12Point)
|
|
.text_color(Rgb565::WHITE)
|
|
.build();
|
|
|
|
let profile_box = PrimitiveStyleBuilder::new()
|
|
.fill_color(Rgb565::BLACK)
|
|
.stroke_color(Rgb565::WHITE)
|
|
.stroke_width(1)
|
|
.build();
|
|
|
|
let selected_box = PrimitiveStyleBuilder::new()
|
|
.fill_color(Rgb565::BLUE)
|
|
.stroke_color(Rgb565::WHITE)
|
|
.stroke_width(1)
|
|
.build();
|
|
|
|
Text::new("Selected a profile", Point::new(4, 4))
|
|
.into_styled(text_lager)
|
|
.draw(&mut disp)
|
|
.unwrap();
|
|
|
|
let encoder_start = self.qei.count();
|
|
|
|
let mut press_count = 0;
|
|
let mut needs_redraw = true;
|
|
while press_count < 5 {
|
|
if needs_redraw {
|
|
for i in 0..profiles::REFLOW_PROFILES.len() {
|
|
let style = if i == self.selected_profile {
|
|
selected_box
|
|
} else {
|
|
profile_box
|
|
};
|
|
Rectangle::new(
|
|
Point::new(0, 20 + (i as i32) * 16),
|
|
Point::new(159, 20 + (i as i32) * 16 + 16),
|
|
)
|
|
.into_styled(style)
|
|
.draw(&mut disp)
|
|
.unwrap();
|
|
|
|
Text::new(
|
|
profiles::REFLOW_PROFILES[i].get_name(),
|
|
Point::new(4, 21 + (i as i32) * 16),
|
|
)
|
|
.into_styled(text_lager)
|
|
.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)
|
|
% profiles::REFLOW_PROFILES.len();
|
|
if new_selection != self.selected_profile {
|
|
self.selected_profile = new_selection;
|
|
needs_redraw = true;
|
|
}
|
|
|
|
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;
|
|
|
|
self
|
|
}
|
|
}
|