added temp reading.
This commit is contained in:
		
							parent
							
								
									188fb05b25
								
							
						
					
					
						commit
						c1e16006f3
					
				
					 1 changed files with 29 additions and 14 deletions
				
			
		
							
								
								
									
										37
									
								
								src/main.rs
									
										
									
									
									
								
							
							
						
						
									
										37
									
								
								src/main.rs
									
										
									
									
									
								
							| 
						 | 
					@ -7,7 +7,10 @@
 | 
				
			||||||
    )]
 | 
					    )]
 | 
				
			||||||
mod app {
 | 
					mod app {
 | 
				
			||||||
    extern crate alloc;
 | 
					    extern crate alloc;
 | 
				
			||||||
    use alloc::{format, string::{self, String, ToString}};
 | 
					    use alloc::{
 | 
				
			||||||
 | 
					        format,
 | 
				
			||||||
 | 
					        string::{self, String, ToString},
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
    use core::fmt::Write;
 | 
					    use core::fmt::Write;
 | 
				
			||||||
    use cortex_m::delay::Delay;
 | 
					    use cortex_m::delay::Delay;
 | 
				
			||||||
    use defmt_rtt as _;
 | 
					    use defmt_rtt as _;
 | 
				
			||||||
| 
						 | 
					@ -89,7 +92,7 @@ mod app {
 | 
				
			||||||
    #[monotonic(binds = TIMER_IRQ_0, default = true)]
 | 
					    #[monotonic(binds = TIMER_IRQ_0, default = true)]
 | 
				
			||||||
    type Rp2040Mono = Rp2040Monotonic;
 | 
					    type Rp2040Mono = Rp2040Monotonic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    struct Thermocouple {
 | 
					    pub struct Thermocouple {
 | 
				
			||||||
        cs: Pin<Gpio5, FunctionSio<SioOutput>, PullDown>,
 | 
					        cs: Pin<Gpio5, FunctionSio<SioOutput>, PullDown>,
 | 
				
			||||||
        spi: ThermocoupleSpi,
 | 
					        spi: ThermocoupleSpi,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -107,6 +110,7 @@ mod app {
 | 
				
			||||||
    struct Shared {
 | 
					    struct Shared {
 | 
				
			||||||
        delay: Delay,
 | 
					        delay: Delay,
 | 
				
			||||||
        recent_temp: f32,
 | 
					        recent_temp: f32,
 | 
				
			||||||
 | 
					        uart: Uart,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[local]
 | 
					    #[local]
 | 
				
			||||||
| 
						 | 
					@ -215,14 +219,16 @@ mod app {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let mono = Rp2040Mono::new(ctx.device.TIMER);
 | 
					        let mono = Rp2040Mono::new(ctx.device.TIMER);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // write_lcd(&mut lcd, &mut delay, "Starting");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        display::spawn(ToString::to_string(&"Starting")).unwrap();
 | 
					        display::spawn(ToString::to_string(&"Starting")).unwrap();
 | 
				
			||||||
        heartbeat::spawn().unwrap();
 | 
					        heartbeat::spawn().unwrap();
 | 
				
			||||||
        second_heartbeat::spawn().unwrap();
 | 
					        second_heartbeat::spawn().unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        (
 | 
					        (
 | 
				
			||||||
            Shared { delay, recent_temp: 0.0 },
 | 
					            Shared {
 | 
				
			||||||
 | 
					                delay,
 | 
				
			||||||
 | 
					                recent_temp: 0.0,
 | 
				
			||||||
 | 
					                uart,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
            Local {
 | 
					            Local {
 | 
				
			||||||
                led: led_pin,
 | 
					                led: led_pin,
 | 
				
			||||||
                thermocouple,
 | 
					                thermocouple,
 | 
				
			||||||
| 
						 | 
					@ -249,10 +255,21 @@ mod app {
 | 
				
			||||||
        // }
 | 
					        // }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn write_lcd(lcd: &mut Lcd, delay: &mut Delay, string: &str) {
 | 
					    #[task(local = [thermocouple], shared = [recent_temp, uart])]
 | 
				
			||||||
        lcd.reset(delay).unwrap();
 | 
					    fn read_temp(mut ctx: read_temp::Context) {
 | 
				
			||||||
        lcd.clear(delay).unwrap();
 | 
					        match ctx.local.thermocouple.read_temp() {
 | 
				
			||||||
        lcd.write_str(string, delay).unwrap();
 | 
					            Ok(v) => {
 | 
				
			||||||
 | 
					                ctx.shared.recent_temp.lock(|t| *t = v);
 | 
				
			||||||
 | 
					                ctx.shared
 | 
				
			||||||
 | 
					                    .uart
 | 
				
			||||||
 | 
					                    .lock(|u| writeln!(u, "{:02.2} C", v).unwrap());
 | 
				
			||||||
 | 
					                let str = format!("{:02.2} C", v);
 | 
				
			||||||
 | 
					                display::spawn(str).unwrap();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Err(e) => defmt::error!("error reading temp {}", defmt::Debug2Format(&e)),
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        let one_second = Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks(ONE_SEC_TICKS);
 | 
				
			||||||
 | 
					        read_temp::spawn_after(one_second).unwrap();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[task(local = [lcd], shared = [delay], capacity = 5)]
 | 
					    #[task(local = [lcd], shared = [delay], capacity = 5)]
 | 
				
			||||||
| 
						 | 
					@ -272,7 +289,6 @@ mod app {
 | 
				
			||||||
        // Re-spawn this task after 1 second
 | 
					        // Re-spawn this task after 1 second
 | 
				
			||||||
        let one_second = Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks(ONE_SEC_TICKS);
 | 
					        let one_second = Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks(ONE_SEC_TICKS);
 | 
				
			||||||
        heartbeat::spawn_after(one_second).unwrap();
 | 
					        heartbeat::spawn_after(one_second).unwrap();
 | 
				
			||||||
        display::spawn(ToString::to_string(&"tick")).unwrap();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[task(local = [external_led])]
 | 
					    #[task(local = [external_led])]
 | 
				
			||||||
| 
						 | 
					@ -284,6 +300,5 @@ mod app {
 | 
				
			||||||
        let one_and_one_half_second =
 | 
					        let one_and_one_half_second =
 | 
				
			||||||
            Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks((ONE_SEC_TICKS as f64 * 1.14) as u64);
 | 
					            Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks((ONE_SEC_TICKS as f64 * 1.14) as u64);
 | 
				
			||||||
        second_heartbeat::spawn_after(one_and_one_half_second).unwrap();
 | 
					        second_heartbeat::spawn_after(one_and_one_half_second).unwrap();
 | 
				
			||||||
        display::spawn(ToString::to_string(&"tock")).unwrap();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue