Update LED L3 after applying config #80

Closed
atse wants to merge 1 commits from atse:update-l3-led-on-config-apply into master
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() {
atse marked this conversation as resolved

I think this solution is laying on too high level, because directly depends on the call of one command.
I would either set them when pid is getting engaged from any place, or check the status in the main loop similar to automatic fan control and set leds accordingly.

I think this solution is laying on too high level, because directly depends on the call of one command. I would either set them when pid is getting engaged from any place, or check the status in the main loop similar to automatic fan control and set leds accordingly.

Yes, repeatedly writing a gpio in the main loop shouldn't use a lot of CPU and would make the code simpler.

Yes, repeatedly writing a gpio in the main loop shouldn't use a lot of CPU and would make the code simpler.
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) =>