comments and abort

This commit is contained in:
2024-08-24 00:35:54 -04:00
parent 3cf3dc5936
commit 7aab854a6b
2 changed files with 8 additions and 7 deletions

View File

@ -21,7 +21,7 @@ pub struct Dispatch {
impl Dispatch {
pub fn new() -> Dispatch {
let (s, r) = unbounded();
let (s, r) = unbounded(); //This should always be unbounded, because some callbacks have to send_blocking to it, and if the thread blocks, other tasks can't empty the queue!
let mut hmap = HashMap::new();
hmap.reserve(Commands::COUNT);
Dispatch { callbacks: hmap, recv: r, endpoint: s}
@ -29,7 +29,7 @@ impl Dispatch {
/// Get a channel receiver that will get callbacks for all commands in the listen_for vec.
pub fn get_callback_channel(&mut self, listen_for: &Vec<Commands>) -> RecvQ {
let (send, rec) = unbounded();
let (send, rec) = unbounded(); // TODO: these could be bounded instead, as these calls are all non-blocking.
for cmd in listen_for {
let callback_list = self.callbacks.get_mut(&discriminant(&cmd));
match callback_list {
@ -48,9 +48,6 @@ impl Dispatch {
rec
}
//TODO: Make a discriminant version of this function that takes a vec of discriminants
//TODO: Most of these channels could be fixed size instead unbound; probably only the incomming channel needs to be large.
/// Get a channel sender that will send commands to this dispatcher
pub fn get_cmd_channel(&mut self) -> SendQ {
self.endpoint.clone()

View File

@ -76,6 +76,9 @@ pub enum Menu<'a> {
Log { level: u8 },
/// Abort (resets microcontroller)
Abort,
}
pub fn process_menu(
@ -176,6 +179,7 @@ pub fn process_menu(
debug!("debug test");
trace!("trace test");
}
Menu::Abort => {panic!("CLI user requested abort");}
}
Ok(())
}
@ -224,8 +228,8 @@ pub async fn start_cli(dispatch: Sender<Commands>) -> anyhow::Result<()> {
}
Err(e) => match e.kind() {
std::io::ErrorKind::WouldBlock => {} // This is expected if there is no input
_ => {warn!("Error waiting for input: {}", e)}
_ => {warn!("Error waiting for CLI input: {}", e)}
}
};
}
}
}