Skip to content

Commit a41ad7a

Browse files
committed
Merge branch 'feature/blink-power-light' into feature/control-dc-power
2 parents c6f2adb + 7a1eb40 commit a41ad7a

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

src/main.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ const APP: () = {
7878
///
7979
/// Sets up the hardware and spawns the regular tasks.
8080
///
81-
/// * Task `led_status_blink` - blinks the LED
81+
/// * Task `led_power_blink` - blinks the LED
8282
/// * Task `button_poll` - checks the power and reset buttons
83-
#[init(spawn = [led_status_blink, button_poll])]
83+
#[init(spawn = [led_power_blink, button_poll])]
8484
fn init(ctx: init::Context) -> init::LateResources {
8585
defmt::info!("Neotron BMC version {:?} booting", VERSION);
8686

@@ -138,7 +138,7 @@ const APP: () = {
138138

139139
serial.listen(serial::Event::Rxne);
140140

141-
ctx.spawn.led_status_blink().unwrap();
141+
ctx.spawn.led_power_blink().unwrap();
142142

143143
ctx.spawn.button_poll().unwrap();
144144

@@ -196,30 +196,32 @@ const APP: () = {
196196
///
197197
/// This task is called periodically. We check whether the status LED is currently on or off,
198198
/// and set it to the opposite. This makes the LED blink.
199-
#[task(schedule = [led_status_blink], resources = [led_status])]
200-
fn led_status_blink(ctx: led_status_blink::Context) {
199+
#[task(schedule = [led_power_blink], resources = [led_power, state_dc_power_enabled])]
200+
fn led_power_blink(ctx: led_power_blink::Context) {
201201
// Use the safe local `static mut` of RTIC
202202
static mut LED_STATE: bool = false;
203203

204-
defmt::trace!("blink time {}", ctx.scheduled.counts());
205-
206-
if *LED_STATE {
207-
ctx.resources.led_status.set_low().unwrap();
208-
*LED_STATE = false;
209-
} else {
210-
ctx.resources.led_status.set_high().unwrap();
211-
*LED_STATE = true;
204+
if *ctx.resources.state_dc_power_enabled == DcPowerState::Off {
205+
defmt::trace!("blink time {}", ctx.scheduled.counts());
206+
if *LED_STATE {
207+
ctx.resources.led_power.set_low().unwrap();
208+
*LED_STATE = false;
209+
} else {
210+
ctx.resources.led_power.set_high().unwrap();
211+
*LED_STATE = true;
212+
}
213+
let next = ctx.scheduled + LED_PERIOD_MS.millis();
214+
defmt::trace!("Next blink at {}", next.counts());
215+
ctx.schedule.led_power_blink(next).unwrap();
212216
}
213-
let next = ctx.scheduled + LED_PERIOD_MS.millis();
214-
defmt::trace!("Next blink at {}", next.counts());
215-
ctx.schedule.led_status_blink(next).unwrap();
216217
}
217218

218219
/// This task polls our power and reset buttons.
219220
///
220221
/// We poll them rather than setting up an interrupt as we need to debounce them, which involves waiting a short period and checking them again. Given that we have to do that, we might as well not bother with the interrupt.
221222
#[task(
222223
schedule = [button_poll],
224+
spawn = [led_power_blink],
223225
resources = [
224226
led_power, button_power, press_button_power_short, press_button_power_long, state_dc_power_enabled,
225227
pin_sys_reset, pin_dc_on
@@ -259,9 +261,13 @@ const APP: () = {
259261
ctx.resources.pin_sys_reset.set_low().unwrap();
260262
// TODO: Wait for 100ms for chips to stop?
261263
ctx.resources.pin_dc_on.set_low().unwrap();
264+
// Start LED blinking again
265+
ctx.spawn.led_power_blink().unwrap();
262266
}
263267
_ => {
264268
// Do nothing
269+
// TODO: Put system in reset here
270+
// TODO: Disable DC PSU here
265271
}
266272
}
267273

0 commit comments

Comments
 (0)