split into hardware dependent / independent
This commit is contained in:
@ -2,34 +2,26 @@
|
||||
|
||||
use log::*; //{trace, debug, info, warn, error}
|
||||
use anyhow::Result;
|
||||
use async_channel::{unbounded, Receiver, Sender};
|
||||
use async_channel::unbounded;
|
||||
use gem_remotes_lib::{MotorCommands, MotorRecvQ, MotorSendQ};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Commands {
|
||||
StartUp,
|
||||
StartDown,
|
||||
Stop
|
||||
}
|
||||
|
||||
pub type SendQ = Sender<Commands>;
|
||||
pub type RecvQ = Receiver<Commands>;
|
||||
|
||||
pub struct MotorDriverDebug{
|
||||
endpoint: SendQ, // Endpoint to hand to dispatch or anyone else sending commands here.
|
||||
recv_q: RecvQ,
|
||||
endpoint: MotorSendQ, // Endpoint to hand to dispatch or anyone else sending commands here.
|
||||
recv_q: MotorRecvQ,
|
||||
}
|
||||
|
||||
/// Debug / example version of Motor Driver.
|
||||
impl MotorDriverDebug {
|
||||
pub fn new() -> Self {
|
||||
let (s,r) = unbounded();
|
||||
let (s,r) = unbounded(); // TODO: reserve a reasonable amount for all unbounded?
|
||||
MotorDriverDebug {
|
||||
endpoint: s,
|
||||
recv_q: r,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_endpoint(&self) -> SendQ {
|
||||
pub fn get_endpoint(&self) -> MotorSendQ {
|
||||
self.endpoint.clone()
|
||||
}
|
||||
|
||||
@ -40,11 +32,11 @@ impl MotorDriverDebug {
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_cmd(&self, cmd: Commands) -> Result<()> {
|
||||
async fn handle_cmd(&self, cmd: MotorCommands) -> Result<()> {
|
||||
match cmd {
|
||||
Commands::StartUp => {self.start_up().await?;}
|
||||
Commands::StartDown => {self.start_down().await?;}
|
||||
Commands::Stop => {self.stop().await?;}
|
||||
MotorCommands::StartUp => {self.start_up().await?;}
|
||||
MotorCommands::StartDown => {self.start_down().await?;}
|
||||
MotorCommands::Stop => {self.stop().await?;}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -62,3 +54,7 @@ impl MotorDriverDebug {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO: we should fix panic to ensure that we shut down motors before rebooting ESP!
|
||||
// Maybe by getting another endpoint and passing it to the panic handler? Add a different command that doesn't just stop, but stops and stops processing any new commands.
|
||||
Reference in New Issue
Block a user