Added firmware
This commit is contained in:
parent
f2fe686b0e
commit
4fb87dbae1
15 changed files with 2170 additions and 163 deletions
53
daemon/src/rotor.rs
Normal file
53
daemon/src/rotor.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
use anyhow::Result;
|
||||
use log::{debug, error, info, warn};
|
||||
use tokio::{
|
||||
self,
|
||||
io::{AsyncBufReadExt, AsyncWriteExt, BufStream},
|
||||
net::{TcpListener, TcpStream},
|
||||
sync::{self, mpsc, watch},
|
||||
time,
|
||||
};
|
||||
|
||||
use crate::rotctlprotocol::{parse_command, Command};
|
||||
|
||||
pub async fn control_rotor(
|
||||
mut rx_cmd: mpsc::Receiver<Command>,
|
||||
pos_tx: watch::Sender<(f32, f32)>,
|
||||
) -> Result<()> {
|
||||
let mut actual_az = 0.0;
|
||||
let mut actual_el = 0.0;
|
||||
|
||||
let mut target_az = 0.0;
|
||||
let mut target_el = 0.0;
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
Some(command) = rx_cmd.recv() => {
|
||||
match command {
|
||||
Command::SetPos(az, el) => {
|
||||
info!("Received set pos {} {}", az, el);
|
||||
target_az = az;
|
||||
target_el = el;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
_ = time::sleep(time::Duration::from_millis(100)) => {
|
||||
if target_az < actual_az {
|
||||
actual_az -= 1.0;
|
||||
} else if target_az > actual_az {
|
||||
actual_az += 1.0;
|
||||
}
|
||||
|
||||
if target_el < actual_el {
|
||||
actual_el -= 1.0;
|
||||
} else if target_el > actual_el {
|
||||
actual_el += 1.0;
|
||||
}
|
||||
|
||||
pos_tx.send((actual_az, actual_el)).unwrap();
|
||||
},
|
||||
else => return Ok(())
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue