calculate the ips based on the magnetic field strength
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -277,6 +277,7 @@ dependencies = [
|
|||||||
"embedded-graphics",
|
"embedded-graphics",
|
||||||
"embedded-hal-bus",
|
"embedded-hal-bus",
|
||||||
"heapless 0.9.2",
|
"heapless 0.9.2",
|
||||||
|
"libm",
|
||||||
"log",
|
"log",
|
||||||
"mipidsi",
|
"mipidsi",
|
||||||
"mmc56x3",
|
"mmc56x3",
|
||||||
@@ -829,6 +830,12 @@ version = "0.2.180"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
|
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libm"
|
||||||
|
version = "0.2.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "litrs"
|
name = "litrs"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ embedded-graphics = "0.8.1"
|
|||||||
mmc56x3 = "0.1.0"
|
mmc56x3 = "0.1.0"
|
||||||
static_cell = { version = "2.1.1" }
|
static_cell = { version = "2.1.1" }
|
||||||
portable-atomic = { version = "1.13.1", features = ["critical-section"] }
|
portable-atomic = { version = "1.13.1", features = ["critical-section"] }
|
||||||
|
libm = "0.2.16"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|||||||
32
src/main.rs
32
src/main.rs
@@ -5,6 +5,7 @@ use embassy_executor::Spawner;
|
|||||||
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel};
|
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel};
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
use embedded_graphics::draw_target::DrawTargetExt;
|
use embedded_graphics::draw_target::DrawTargetExt;
|
||||||
|
use heapless::Deque;
|
||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -45,6 +46,7 @@ async fn main(spawner: Spawner) {
|
|||||||
|
|
||||||
spawner.must_spawn(measure_task(mag_sens));
|
spawner.must_spawn(measure_task(mag_sens));
|
||||||
spawner.must_spawn(display_task(display));
|
spawner.must_spawn(display_task(display));
|
||||||
|
spawner.must_spawn(proccess_readings());
|
||||||
|
|
||||||
Timer::after_secs(30).await;
|
Timer::after_secs(30).await;
|
||||||
init::reboot().await;
|
init::reboot().await;
|
||||||
@@ -52,7 +54,7 @@ async fn main(spawner: Spawner) {
|
|||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
async fn measure_task(mut sensor: MagSensor) {
|
async fn measure_task(mut sensor: MagSensor) {
|
||||||
let sample_window = Duration::from_millis(500);
|
let sample_window = Duration::from_millis(200);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match sensor.read_messurement().await {
|
match sensor.read_messurement().await {
|
||||||
@@ -72,8 +74,8 @@ async fn measure_task(mut sensor: MagSensor) {
|
|||||||
async fn display_task(mut display: SPIDisplay) {
|
async fn display_task(mut display: SPIDisplay) {
|
||||||
let mut como_display = CoMoDisplay::new(display.color_converted());
|
let mut como_display = CoMoDisplay::new(display.color_converted());
|
||||||
loop {
|
loop {
|
||||||
let _reading = DISPLAY_CHANNEL.receive().await;
|
let reading = DISPLAY_CHANNEL.receive().await;
|
||||||
match como_display.draw() {
|
match como_display.draw(reading) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
error!("Failed to draw");
|
error!("Failed to draw");
|
||||||
@@ -81,3 +83,27 @@ async fn display_task(mut display: SPIDisplay) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn proccess_readings() {
|
||||||
|
let mut fifo: Deque<f32, 20> = Deque::new();
|
||||||
|
DISPLAY_CHANNEL.send(15_f32).await;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let reading = SENSOR_CHANNEL.receive().await;
|
||||||
|
let strength =
|
||||||
|
libm::sqrtf(reading.x * reading.x + reading.y * reading.y + reading.z * reading.z);
|
||||||
|
let ips = strength * 0.15;
|
||||||
|
|
||||||
|
if fifo.is_full()
|
||||||
|
&& let Some(delayed_value) = fifo.pop_front()
|
||||||
|
{
|
||||||
|
if DISPLAY_CHANNEL.is_full() {
|
||||||
|
let _ = DISPLAY_CHANNEL.try_receive();
|
||||||
|
}
|
||||||
|
DISPLAY_CHANNEL.send(delayed_value).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
fifo.push_back(ips).ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user