forked from M-Labs/thermostat
led: remove
This commit is contained in:
parent
2f50071afa
commit
60a9c72bf0
46
src/led.rs
46
src/led.rs
@ -1,46 +0,0 @@
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use stm32f4xx_hal::gpio::{
|
||||
Output, PushPull,
|
||||
gpiob::{PB0, PB7, PB14},
|
||||
};
|
||||
|
||||
type GreenPin = PB0<Output<PushPull>>;
|
||||
type BluePin = PB7<Output<PushPull>>;
|
||||
type RedPin = PB14<Output<PushPull>>;
|
||||
|
||||
pub struct Led<PIN> {
|
||||
pin: PIN,
|
||||
}
|
||||
|
||||
impl<PIN: OutputPin> Led<PIN> {
|
||||
fn new(pin: PIN) -> Self {
|
||||
Led { pin }
|
||||
}
|
||||
|
||||
pub fn on(&mut self) {
|
||||
let _ = self.pin.set_high();
|
||||
}
|
||||
|
||||
pub fn off(&mut self) {
|
||||
let _ = self.pin.set_low();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Led<GreenPin> {
|
||||
pub fn green(pin: GreenPin) -> Self {
|
||||
Self::new(pin)
|
||||
}
|
||||
}
|
||||
|
||||
impl Led<BluePin> {
|
||||
pub fn blue(pin: BluePin) -> Self {
|
||||
Self::new(pin)
|
||||
}
|
||||
}
|
||||
|
||||
impl Led<RedPin> {
|
||||
pub fn red(pin: RedPin) -> Self {
|
||||
Self::new(pin)
|
||||
}
|
||||
}
|
12
src/main.rs
12
src/main.rs
@ -32,8 +32,6 @@ mod net;
|
||||
mod server;
|
||||
use server::Server;
|
||||
mod timer;
|
||||
mod led;
|
||||
use led::Led;
|
||||
|
||||
/// Interval at which to sample the ADC input and broadcast to all
|
||||
/// clients.
|
||||
@ -93,10 +91,6 @@ fn main() -> ! {
|
||||
let gpioc = dp.GPIOC.split();
|
||||
let gpiog = dp.GPIOG.split();
|
||||
|
||||
let mut led_green = Led::green(gpiob.pb0.into_push_pull_output());
|
||||
let mut led_blue = Led::blue(gpiob.pb7.into_push_pull_output());
|
||||
let mut led_red = Led::red(gpiob.pb14.into_push_pull_output());
|
||||
|
||||
info!("ADC init");
|
||||
let mut adc_input = AdcInput::new(dp.ADC1, gpioa.pa3);
|
||||
|
||||
@ -126,21 +120,17 @@ fn main() -> ! {
|
||||
loop {
|
||||
let now = timer::now().0;
|
||||
let instant = Instant::from_millis(i64::from(now));
|
||||
led_blue.on();
|
||||
cortex_m::interrupt::free(net::clear_pending);
|
||||
server.poll(instant)
|
||||
.unwrap_or_else(|e| {
|
||||
warn!("poll: {:?}", e);
|
||||
});
|
||||
led_blue.off();
|
||||
|
||||
let now = timer::now().0;
|
||||
if now - last_output >= OUTPUT_INTERVAL {
|
||||
led_red.on();
|
||||
let adc_value = adc_input.read();
|
||||
writeln!(server, "t={},pa3={}\r", now, adc_value).unwrap();
|
||||
last_output = now;
|
||||
led_red.off();
|
||||
}
|
||||
|
||||
// Update watchdog
|
||||
@ -148,10 +138,8 @@ fn main() -> ! {
|
||||
|
||||
cortex_m::interrupt::free(|cs| {
|
||||
if !net::is_pending(cs) {
|
||||
led_green.on();
|
||||
// Wait for interrupts
|
||||
wfi();
|
||||
led_green.off();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user