Added movement task and rewired the channels

This commit is contained in:
Sebastian 2022-08-21 18:11:58 +02:00
parent ace48440f3
commit 90768d9bf0
4 changed files with 101 additions and 18 deletions

View file

@ -4,6 +4,7 @@ use embassy_stm32::time::Hertz;
use embassy_time::{Duration, Timer};
use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
use embassy_util::channel::mpmc::Receiver;
use embassy_util::{select, Either};
use embedded_graphics::{
mono_font::{
@ -21,14 +22,14 @@ use heapless::String;
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
use crate::AzElPair;
use crate::{AzElPair, RotorState};
#[embassy_executor::task]
pub async fn display_task(
i2c1: peripherals::I2C1,
sda: peripherals::PB6,
scl: peripherals::PB7,
cmd_receiver: Receiver<'static, ThreadModeRawMutex, AzElPair, 1>,
cmd_receiver: Receiver<'static, ThreadModeRawMutex, RotorState, 1>,
) {
let i2c = i2c::I2c::new(i2c1, sda, scl, Hertz::hz(100_000), i2c::Config::default());
@ -46,9 +47,13 @@ pub async fn display_task(
.fill_color(BinaryColor::On)
.build();
loop {
let pair = cmd_receiver.recv().await;
let mut rotor_state = RotorState {
actual_pos: AzElPair { az: 0, el: 0 },
setpoint_pos: AzElPair { az: 0, el: 0 },
stopped: false,
};
loop {
display.clear();
Text::new("AFG rotor ctrl v0.1.0", Point::new(0, 6), text_small)
@ -69,19 +74,28 @@ pub async fn display_task(
.unwrap();
let mut tmp: String<16> = String::new();
write!(tmp, "AZ: {}", pair.az).unwrap();
write!(tmp, "AZ: {}", rotor_state.setpoint_pos.az).unwrap();
Text::new(&tmp, Point::new(1, 30), text_large_inv)
.draw(&mut display)
.unwrap();
tmp.clear();
write!(tmp, "EL: {}", pair.el).unwrap();
write!(tmp, "EL: {}", rotor_state.setpoint_pos.el).unwrap();
Text::new(&tmp, Point::new(64, 30), text_large_inv)
.draw(&mut display)
.unwrap();
display.flush().unwrap();
Timer::after(Duration::from_millis(500)).await;
let result = select(
Timer::after(Duration::from_millis(100)),
cmd_receiver.recv(),
)
.await;
match result {
Either::First(_) => {}
Either::Second(new_state) => rotor_state = new_state,
}
}
}