Stopping and Stopped notifications distinct

This commit is contained in:
2024-08-24 10:12:23 -04:00
parent 7c2d3df16b
commit 70947d5fa7
5 changed files with 20 additions and 11 deletions

View File

@ -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(())}