Implemented button

This commit is contained in:
Sebastian 2020-10-08 20:45:16 +02:00
parent c0283eefd8
commit 64a7b8c5ff
2 changed files with 21 additions and 6 deletions

View File

@ -51,6 +51,7 @@ pub struct App {
disp_rst: gpioa::PA1<Output<PushPull>>,
max_cs: gpioa::PA9<Output<PushPull>>,
qei: AppQEI,
button: gpiob::PB3<Input<Floating>>,
selected_profile: usize,
}
@ -84,13 +85,14 @@ pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> A
let gpiob = dp.GPIOB.split(&mut rcc.apb2);
let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
let (_, _, pb4) = afio.mapr.disable_jtag(gpioa.pa15, gpiob.pb3, gpiob.pb4);
let (_, pb3, pb4) = afio.mapr.disable_jtag(gpioa.pa15, gpiob.pb3, gpiob.pb4);
let qei = Timer::tim3(dp.TIM3, &clocks, &mut rcc.apb1).qei(
(pb4, gpiob.pb5),
&mut afio.mapr,
qei::QeiOptions::default(),
);
let button = pb3;
// SPI1
let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl);
@ -128,6 +130,7 @@ pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> A
disp_rst: rst,
max_cs: max_cs,
qei: qei,
button: button,
selected_profile: 0,
}
@ -203,8 +206,9 @@ impl App {
.draw(&mut disp)
.unwrap();
let mut press_count = 0;
let mut needs_redraw = true;
loop {
while press_count < 5 {
if needs_redraw {
for i in 0..profiles::REFLOW_PROFILES.len() {
let rect = Rectangle::new(
@ -231,12 +235,23 @@ impl App {
needs_redraw = false;
}
self.delay.delay_ms(100u16);
self.delay.delay_ms(10u16);
let new_selection = ((self.qei.count() 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();

View File

@ -34,7 +34,7 @@ impl ReflowProfile {
pub const REFLOW_PROFILES: [ReflowProfile; 4] = [
ReflowProfile {
name: "Profile 1",
name: "Too Hot",
points: [
ProfilePoint {
time: 0f32,
@ -63,7 +63,7 @@ pub const REFLOW_PROFILES: [ReflowProfile; 4] = [
],
},
ReflowProfile {
name: "Profile 2",
name: "To Cold",
points: [
ProfilePoint {
time: 0f32,
@ -92,7 +92,7 @@ pub const REFLOW_PROFILES: [ReflowProfile; 4] = [
],
},
ReflowProfile {
name: "Empty ",
name: "About Okay",
points: [
ProfilePoint {
time: 0f32,