adds the rpm and the timer for the second spinning regime

This commit is contained in:
Robert Schauklies 2026-04-13 20:05:18 +02:00
parent 05b07e5ee3
commit 8048d48f18
3 changed files with 34 additions and 9 deletions

View file

@ -63,6 +63,7 @@ extern crate alloc;
const DEFAULT_TARGET_RPM: u32 = 4000; const DEFAULT_TARGET_RPM: u32 = 4000;
//in seconds //in seconds
const DEFAULT_SPIN_TIME: u64 = 10; const DEFAULT_SPIN_TIME: u64 = 10;
const DEFAULT_DRY_SPIN_TIME: u64 = 10;
// This creates a default app-descriptor required by the esp-idf bootloader. // This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description> // For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!(); esp_bootloader_esp_idf::esp_app_desc!();
@ -176,7 +177,9 @@ fn main() -> ! {
//we just set it to page0 to be sure //we just set it to page0 to be sure
display.send_command(b"page page0"); display.send_command(b"page page0");
let mut target_rpm = DEFAULT_TARGET_RPM; let mut target_rpm = DEFAULT_TARGET_RPM;
let mut timer:u64 = DEFAULT_SPIN_TIME; let mut timer: u64 = DEFAULT_SPIN_TIME;
let mut target_dry_rpm = DEFAULT_DRY_SPIN_TIME;
let mut dry_timer: u64 = DEFAULT_SPIN_TIME;
let mut started = false; let mut started = false;
loop { loop {
if display.read_ready() { if display.read_ready() {
@ -202,6 +205,14 @@ fn main() -> ! {
rprintln!("SETTING TIMER {}", x); rprintln!("SETTING TIMER {}", x);
timer = x as _; timer = x as _;
} }
Ok(Command::SetRpm2(x)) => {
rprintln!("SET_RPM with {}", x);
target_dry_rpm = x.try_into().expect("Couldn't cast RPM2 to u64");
}
Ok(Command::SetTimer2(x)) => {
rprintln!("SETTING TIMER {}", x);
dry_timer = x as _;
}
Ok(Command::SendConfig) => { Ok(Command::SendConfig) => {
rprintln!("SEND CONFIG"); rprintln!("SEND CONFIG");
let command = format!("rpm.val={}", DEFAULT_TARGET_RPM); let command = format!("rpm.val={}", DEFAULT_TARGET_RPM);
@ -241,7 +252,7 @@ fn main() -> ! {
x x
} }
None => { None => {
rpm_fail_ctr+=1; rpm_fail_ctr += 1;
// rprintln!("NO RPM!"); // rprintln!("NO RPM!");
current_rpm current_rpm
} }
@ -252,24 +263,28 @@ fn main() -> ! {
let timestamp = esp_hal::time::Instant::now() let timestamp = esp_hal::time::Instant::now()
.duration_since_epoch() .duration_since_epoch()
.as_millis(); .as_millis();
(control, ctx) = (control, ctx) = controller.compute(
controller.compute(ctx, current_rpm as _, set_point as _, Millis(timestamp), None); ctx,
current_rpm as _,
set_point as _,
Millis(timestamp),
None,
);
let dumped_context = ctx.last_time().expect("LAST TIME!"); let dumped_context = ctx.last_time().expect("LAST TIME!");
rprintln!("control:{},rpm:{}", control,current_rpm); rprintln!("control:{},rpm:{}", control, current_rpm);
//first we send the RPM! //first we send the RPM!
if display.write_ready(){ if display.write_ready() {
let running_rpm = format!("rpm.val={}", current_rpm); let running_rpm = format!("rpm.val={}", current_rpm);
display.send_command(running_rpm.to_string().as_bytes()); display.send_command(running_rpm.to_string().as_bytes());
} }
if display.write_ready(){ if display.write_ready() {
let counter = format!("counter.val={}", 1234); let counter = format!("counter.val={}", 1234);
display.send_command(counter.to_string().as_bytes()); display.send_command(counter.to_string().as_bytes());
} }
} }
rprintln!("COATING done!"); rprintln!("COATING done!");
rprintln!("RPM_READ_FAILS {}",rpm_fail_ctr); rprintln!("RPM_READ_FAILS {}", rpm_fail_ctr);
started = false; started = false;
display.send_command(b"page page0"); display.send_command(b"page page0");
} }

View file

@ -7,6 +7,8 @@ pub enum Command {
Stop, Stop,
SendConfig, SendConfig,
CommandSuccess, CommandSuccess,
SetRpm2(u32),
SetTimer2(u32),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum ErrCommand { pub enum ErrCommand {

View file

@ -116,6 +116,14 @@ impl<'a> Nextion<'a> {
Ok(Command::SetTimer(time)) Ok(Command::SetTimer(time))
} }
05 => Ok(Command::SendConfig), 05 => Ok(Command::SendConfig),
06 => {
let rpm = u32::from_le_bytes(buf[1..5].try_into().expect("failed to parse rpm!"));
Ok(Command::SetRpm2(rpm))
}
07 => {
let time = u32::from_le_bytes(buf[1..5].try_into().expect("failed to parse rpm!"));
Ok(Command::SetTimer2(time))
}
00 => Ok(Command::CommandSuccess), 00 => Ok(Command::CommandSuccess),
_ => Err(ErrCommand::NoValidCmd), _ => Err(ErrCommand::NoValidCmd),
} }