Update LED L3 after applying config

PID may be engaged or disengaged after loading config, so make sure LED
L3 updates to match.
pull/80/head
atse 2023-08-10 11:47:40 +08:00
parent f29e86310d
commit 146d3543e5
3 changed files with 13 additions and 5 deletions

View File

@ -278,12 +278,12 @@ impl Handler {
Ok(Handler::Handled)
}
fn load_channel (socket: &mut TcpSocket, channels: &mut Channels, store: &mut FlashStore, channel: Option<usize>) -> Result<Handler, Error> {
fn load_channel (socket: &mut TcpSocket, channels: &mut Channels, leds: &mut Leds, store: &mut FlashStore, channel: Option<usize>) -> Result<Handler, Error> {
for c in 0..CHANNELS {
if channel.is_none() || channel == Some(c) {
match store.read_value::<ChannelConfig>(CHANNEL_CONFIG_KEY[c]) {
Ok(Some(config)) => {
config.apply(channels, c);
config.apply(channels, c, leds);
send_line(socket, b"{}");
}
Ok(None) => {
@ -436,7 +436,7 @@ impl Handler {
Command::SteinhartHart { channel, parameter, value } => Handler::set_steinhart_hart(socket, channels, channel, parameter, value),
Command::PostFilter { channel, rate: None } => Handler::reset_post_filter(socket, channels, channel),
Command::PostFilter { channel, rate: Some(rate) } => Handler::set_post_filter(socket, channels, channel, rate),
Command::Load { channel } => Handler::load_channel(socket, channels, store, channel),
Command::Load { channel } => Handler::load_channel(socket, channels, leds, store, channel),
Command::Save { channel } => Handler::save_channel(socket, channels, channel, store),
Command::Ipv4(config) => Handler::set_ipv4(socket, store, config),
Command::Reset => Handler::reset(channels),

View File

@ -10,6 +10,7 @@ use crate::{
command_parser::CenterPoint,
pid,
steinhart_hart,
leds::Leds,
};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@ -44,7 +45,7 @@ impl ChannelConfig {
}
}
pub fn apply(&self, channels: &mut Channels, channel: usize) {
pub fn apply(&self, channels: &mut Channels, channel: usize, leds: &mut Leds) {
let state = channels.channel_state(channel);
state.center = self.center.clone();
state.pid.parameters = self.pid.clone();
@ -59,6 +60,13 @@ impl ChannelConfig {
adc_postfilter => Some(adc_postfilter),
};
let _ = channels.adc.set_postfilter(channel as u8, adc_postfilter);
// Update L3 if PID status changed
if channels.pid_engaged() {
leds.g3.on();
} else {
leds.g3.off();
}
}
}

View File

@ -143,7 +143,7 @@ fn main() -> ! {
for c in 0..CHANNELS {
match store.read_value::<ChannelConfig>(CHANNEL_CONFIG_KEY[c]) {
Ok(Some(config)) =>
config.apply(&mut channels, c),
config.apply(&mut channels, c, &mut leds),
Ok(None) =>
error!("flash config not found for channel {}", c),
Err(e) =>