Stopping and Stopped notifications distinct
This commit is contained in:
@ -39,8 +39,9 @@ impl BleServer {
|
||||
//Commands::BluetoothDown { data: 0 },
|
||||
//Commands::BluetoothStop { data: 0 },
|
||||
Commands::NotifyMotorDown,
|
||||
Commands::NotifyMotorStop,
|
||||
Commands::NotifyMotorStopping,
|
||||
Commands::NotifyMotorUp,
|
||||
Commands::NotifyMotorStopped,
|
||||
];
|
||||
let r = dp.get_callback_channel(&cmds);
|
||||
let s = dp.get_cmd_channel();
|
||||
@ -94,7 +95,7 @@ impl BleServer {
|
||||
);
|
||||
button_stop.lock().set_value(&[1])
|
||||
.on_write(closure!(clone sender, |args: &mut OnWriteArgs| {
|
||||
on_bluetooth_cmd(&sender, args, Commands::BluetoothStop {data: 0})
|
||||
on_bluetooth_cmd(&sender, args, Commands::BluetoothStop {_data: 0})
|
||||
}));
|
||||
|
||||
|
||||
@ -119,11 +120,16 @@ impl BleServer {
|
||||
button_down.lock().set_value(&BUTTON_PRESSED).notify();
|
||||
button_stop.lock().set_value(&BUTTON_RELEASED).notify();
|
||||
}
|
||||
Commands::NotifyMotorStop => {
|
||||
Commands::NotifyMotorStopping => {
|
||||
button_up.lock().set_value(&BUTTON_RELEASED).notify();
|
||||
button_down.lock().set_value(&BUTTON_RELEASED).notify();
|
||||
button_stop.lock().set_value(&BUTTON_PRESSED).notify();
|
||||
}
|
||||
Commands::NotifyMotorStopped => {
|
||||
button_up.lock().set_value(&BUTTON_RELEASED).notify();
|
||||
button_down.lock().set_value(&BUTTON_RELEASED).notify();
|
||||
button_stop.lock().set_value(&BUTTON_RELEASED).notify();
|
||||
}
|
||||
_ => {
|
||||
error!("Invalid command received by bluetooth handler {:?}", cmd);
|
||||
// No need to reboot as state is recoverable.
|
||||
@ -148,9 +154,9 @@ fn on_bluetooth_cmd(sender: &SendQ, args: &mut OnWriteArgs, cmd: Commands) {
|
||||
sender.send_blocking(Commands::BluetoothDown {data: v[0]} )
|
||||
} else {error!("Received zero-byte bluetooth characteristic update {:?}", cmd); Ok(())}
|
||||
}
|
||||
Commands::BluetoothStop { data: _ } => {
|
||||
Commands::BluetoothStop { _data: _ } => {
|
||||
if v.len() > 0 {
|
||||
sender.send_blocking(Commands::BluetoothStop {data: v[0]} )
|
||||
sender.send_blocking(Commands::BluetoothStop {_data: v[0]} )
|
||||
} else {error!("Received zero-byte bluetooth characteristic update {:?}", cmd); Ok(())}
|
||||
}
|
||||
_ => {error!("Tried to handle an unknown bluetooth command: {:?}",cmd);Ok(())}
|
||||
|
||||
@ -14,7 +14,7 @@ pub enum Commands {
|
||||
// Inputs from bluetooth
|
||||
BluetoothUp {data: u8},
|
||||
BluetoothDown {data: u8},
|
||||
BluetoothStop {data: u8}, // There is no state where releasing the stop button induces a change.
|
||||
BluetoothStop {_data: u8}, // There is no state where releasing the stop button induces a change.
|
||||
|
||||
// Internal messages
|
||||
StopTimerExpired, // Sent when the 2 second stop sequence is complete
|
||||
@ -26,7 +26,8 @@ pub enum Commands {
|
||||
|
||||
NotifyMotorUp,
|
||||
NotifyMotorDown,
|
||||
NotifyMotorStop,
|
||||
NotifyMotorStopping,
|
||||
NotifyMotorStopped, // Signaled after stop timeout
|
||||
}
|
||||
|
||||
pub type CmdType = std::mem::Discriminant<Commands>;
|
||||
|
||||
@ -44,7 +44,7 @@ impl Controller {
|
||||
Commands::PicRecvStop,
|
||||
Commands::BluetoothUp{data: 0},
|
||||
Commands::BluetoothDown{data: 0},
|
||||
Commands::BluetoothStop{data: 0},
|
||||
Commands::BluetoothStop{_data: 0},
|
||||
Commands::StopTimerExpired,
|
||||
Commands::ButtonTimerExpired,
|
||||
];
|
||||
@ -53,7 +53,9 @@ impl Controller {
|
||||
|
||||
async fn enter_state(&mut self, new_s: &ControllerStates) -> Result<()> {
|
||||
match new_s {
|
||||
ControllerStates::Stopped => {}
|
||||
ControllerStates::Stopped => {
|
||||
self.send.send(Commands::NotifyMotorStopped).await?;
|
||||
}
|
||||
ControllerStates::Stopping => {
|
||||
self.send.send(Commands::StopTimerRestart).await?;
|
||||
self.motor_q.send(MotorCommands::Stop).await?;
|
||||
|
||||
@ -80,7 +80,7 @@ impl MotorDriverDebug {
|
||||
}
|
||||
pub async fn stop(&self) -> Result<()> {
|
||||
warn!("Stopping motor");
|
||||
self.dispatch.send(Dispatch_Commands::NotifyMotorStop).await?;
|
||||
self.dispatch.send(Dispatch_Commands::NotifyMotorStopping).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ pub fn process_menu(
|
||||
Menu::BluetoothStop { data } => {
|
||||
cli.writer()
|
||||
.write_str("SendingBluetoothStop")?;
|
||||
let _ = dispatch.send_blocking(Commands::BluetoothStop { data: data });
|
||||
let _ = dispatch.send_blocking(Commands::BluetoothStop { _data: data });
|
||||
}
|
||||
Menu::BluetoothLearn { data } => {
|
||||
cli.writer()
|
||||
|
||||
Reference in New Issue
Block a user