main: optimize+doc resets

This commit is contained in:
Astro 2020-03-19 22:01:16 +01:00
parent 163bb38f68
commit a94650e208
1 changed files with 13 additions and 9 deletions

View File

@ -160,7 +160,9 @@ fn main() -> ! {
server.for_each(|mut socket, session| { server.for_each(|mut socket, session| {
if ! socket.is_open() { if ! socket.is_open() {
let _ = socket.listen(TCP_PORT); let _ = socket.listen(TCP_PORT);
if session.is_dirty() {
session.reset(); session.reset();
}
} else if socket.can_send() && socket.can_recv() && socket.send_capacity() - socket.send_queue() > 128 { } else if socket.can_send() && socket.can_recv() && socket.send_capacity() - socket.send_queue() > 128 {
match socket.recv(|buf| session.feed(buf)) { match socket.recv(|buf| session.feed(buf)) {
Ok(SessionOutput::Nothing) => {} Ok(SessionOutput::Nothing) => {}
@ -337,22 +339,24 @@ fn main() -> ! {
use command_parser::PidParameter::*; use command_parser::PidParameter::*;
match parameter { match parameter {
Target => Target =>
pid.set_target(value), pid.target = value,
KP => KP =>
pid.update_parameters(|parameters| parameters.kp = value), pid.parameters.kp = value,
KI => KI =>
pid.update_parameters(|parameters| parameters.ki = value), pid.parameters.ki = value,
KD => KD =>
pid.update_parameters(|parameters| parameters.kd = value), pid.parameters.kd = value,
OutputMin => OutputMin =>
pid.update_parameters(|parameters| parameters.output_min = value), pid.parameters.output_min = value,
OutputMax => OutputMax =>
pid.update_parameters(|parameters| parameters.output_max = value), pid.parameters.output_max = value,
IntegralMin => IntegralMin =>
pid.update_parameters(|parameters| parameters.integral_min = value), pid.parameters.integral_min = value,
IntegralMax => IntegralMax =>
pid.update_parameters(|parameters| parameters.integral_max = value), pid.parameters.integral_max = value,
} }
// TODO: really reset PID state
// after each parameter change?
pid.reset(); pid.reset();
let _ = writeln!(socket, "PID parameter updated"); let _ = writeln!(socket, "PID parameter updated");
} }