Made motor driver independent task
This commit is contained in:
@ -10,7 +10,6 @@ use log::*; //{trace, debug, info, warn, error}
|
||||
use anyhow::Result;
|
||||
use async_executor::Executor;
|
||||
use futures_lite::future;
|
||||
use std::boxed::Box;
|
||||
|
||||
// Debug modules
|
||||
mod test_console;
|
||||
@ -38,35 +37,23 @@ fn main() {
|
||||
//log::set_max_level(log::LevelFilter::Info);
|
||||
|
||||
match future::block_on(main_loop()) {
|
||||
Ok(_) => {error!("Exited main loop normally, but this should be impossible.")}
|
||||
Err(e) => {error!("Exited main loop with error {}", e)}
|
||||
Ok(_) => {error!("Exited main loop with no errors, but this should not happen."); panic!();}
|
||||
Err(e) => {error!("Exited main loop with error {}", e); panic!();}
|
||||
};
|
||||
//TODO: can we restart the microcontroller here?
|
||||
}
|
||||
|
||||
/*
|
||||
async fn test_loop() -> Result<()> {
|
||||
let timer_service = EspTaskTimerService::new()?;
|
||||
|
||||
let mut async_timer = timer_service.timer_async()?;
|
||||
loop {
|
||||
async_timer.after(Duration::from_secs(5)).await?;
|
||||
debug!("Tick ");
|
||||
}
|
||||
} */
|
||||
|
||||
async fn main_loop() -> Result<()> {
|
||||
info!("Entering main loop");
|
||||
|
||||
// Create dispatch early so it can outlive most other things
|
||||
let mut dp = dispatch::Dispatch::new();
|
||||
|
||||
// Debug Drivers
|
||||
let motor_driver = Box::new(motor_driver::MotorDriverDebug {});
|
||||
// Debug Drivers (TODO: remove debug)
|
||||
let motor_driver = motor_driver::MotorDriverDebug::new(dp.get_cmd_channel());
|
||||
|
||||
// Setup of various drivers that need to out-live the executor
|
||||
let m_chan = motor_controller::Controller::prepare_controller(&mut dp);
|
||||
let mut motor_control = motor_controller::Controller::new(m_chan, dp.get_cmd_channel(), motor_driver);
|
||||
let mut motor_control = motor_controller::Controller::new(m_chan, dp.get_cmd_channel(), motor_driver.get_endpoint());
|
||||
// Setup callback timers
|
||||
let mut button_timer = MessageTimer::<Commands, Commands>::new_on_dispatch(
|
||||
Commands::ButtonTimerRestart,
|
||||
@ -85,7 +72,7 @@ async fn main_loop() -> Result<()> {
|
||||
let executor = Executor::new();
|
||||
let mut tasks:Vec<_> = Vec::new();
|
||||
|
||||
//Queue Up debug tasks (TODO: remove)
|
||||
//Queue Up debug tasks (TODO: remove debug)
|
||||
let cli_endpoint = dp.get_cmd_channel();
|
||||
tasks.push(executor.spawn(test_console::start_cli(cli_endpoint)));
|
||||
//tasks.push(executor.spawn(test_loop()));
|
||||
@ -97,6 +84,7 @@ async fn main_loop() -> Result<()> {
|
||||
tasks.push(executor.spawn(button_timer.run()));
|
||||
tasks.push(executor.spawn(stopping_timer.run()));
|
||||
tasks.push(executor.spawn(ble_server.run()));
|
||||
tasks.push(executor.spawn(motor_driver.run()));
|
||||
tasks.push(executor.spawn(dp.cmd_loop()));
|
||||
|
||||
//Once we have all our tasks, await on them all to run them in parallel.
|
||||
@ -107,4 +95,6 @@ async fn main_loop() -> Result<()> {
|
||||
info!("exiting main loop");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TODO: check many of these mut functions to see if they don't need to be.
|
||||
Reference in New Issue
Block a user