nonsense, nothing is fixed

This commit is contained in:
Priec
2026-01-18 20:49:34 +01:00
parent a910015856
commit 94c591c087
5 changed files with 46 additions and 31 deletions

View File

@@ -15,7 +15,7 @@ use crate::mpu::api::sender;
use crate::mpu::driver::Mpu6050;
/// Sampling interval in milliseconds.
/// 50ms = 20Hz, reasonable for display updates.
/// 50ms = 20Hz
const SAMPLE_INTERVAL_MS: u64 = 50;
/// MPU6050 I2C address (0x68 with AD0 low, 0x69 with AD0 high)
@@ -52,7 +52,7 @@ pub async fn mpu_task(i2c: I2cDevice) {
Timer::after(Duration::from_secs(2)).await;
continue;
}
Err(_e) => {
Err(_) => {
warn!(
"I2C error verifying MPU6050 (attempt {})",
init_attempts
@@ -68,7 +68,7 @@ pub async fn mpu_task(i2c: I2cDevice) {
info!("MPU6050 initialized successfully");
break;
}
Err(_e) => {
Err(_) => {
error!("MPU6050 init failed (attempt {})", init_attempts);
Timer::after(Duration::from_secs(2)).await;
continue;
@@ -78,11 +78,14 @@ pub async fn mpu_task(i2c: I2cDevice) {
// Allow sensor to stabilize after wake-up
Timer::after(Duration::from_millis(100)).await;
info!("MPU task entering sampling loop ({}ms interval)", SAMPLE_INTERVAL_MS);
info!(
"MPU task entering sampling loop ({}ms interval)",
SAMPLE_INTERVAL_MS
);
let tx = sender();
let mut consecutive_errors = 0u32;
let mut sent_count: u32 = 0;
loop {
let start = Instant::now();
@@ -98,13 +101,20 @@ pub async fn mpu_task(i2c: I2cDevice) {
timestamp_ms: start.as_millis(),
};
// Try to send; if queue is full, drop oldest by using try_send
// This ensures we never block the sampling loop
if tx.try_send(reading).is_err() {
// Queue full - that's okay, main will get the next one
sent_count = sent_count.wrapping_add(1);
if tx.try_send(reading).is_ok() {
if sent_count % 20 == 0 {
info!(
"IMU send#{} ax:{:.2} ay:{:.2} az:{:.2} t:{:.1}",
sent_count, accel_g[0], accel_g[1], accel_g[2], temp_c
);
}
} else if sent_count % 20 == 0 {
info!("IMU drop: channel full ({} sent)", sent_count);
}
}
Err(_e) => {
Err(_) => {
consecutive_errors += 1;
if consecutive_errors == 1 || consecutive_errors % 10 == 0 {
warn!("MPU read error (consecutive: {})", consecutive_errors);
@@ -122,7 +132,7 @@ pub async fn mpu_task(i2c: I2cDevice) {
}
}
// Sleep for remainder of interval
// Maintain a steady period
let elapsed = start.elapsed();
let target = Duration::from_millis(SAMPLE_INTERVAL_MS);
if elapsed < target {