More consistent bluetooth notify
This commit is contained in:
@ -14,9 +14,6 @@ const BLE_MAX_INTERVAL: u16 = 48; // x 1.25ms
|
||||
const BLE_LATENCY: u16 = 0; // Number of packets that can be missed, extending interval
|
||||
const BLE_TIMEOUT: u16 = 500; // x10ms
|
||||
|
||||
const BUTTON_PRESSED: [u8; 1] = [0x1];
|
||||
const BUTTON_RELEASED: [u8; 1] = [0x0];
|
||||
|
||||
const DEVICE_NAME: &str = "Gem Remotes";
|
||||
|
||||
const UUID_SERVICE_PAIR: BleUuid = uuid128!("9966ad5a-f13c-4b61-ba66-0861e08d09b4");
|
||||
@ -34,14 +31,9 @@ pub struct BleServer {
|
||||
impl BleServer {
|
||||
pub fn new(dp: &mut Dispatch) -> Self {
|
||||
let cmds = vec![
|
||||
// Switch to getting and updating notices; use the command version for sending commands only.
|
||||
//Commands::BluetoothUp { data: 0 },
|
||||
//Commands::BluetoothDown { data: 0 },
|
||||
//Commands::BluetoothStop { data: 0 },
|
||||
Commands::NotifyMotorDown,
|
||||
Commands::NotifyMotorStopping,
|
||||
Commands::NotifyMotorUp,
|
||||
Commands::NotifyMotorStopped,
|
||||
Commands::NotifyMotorDown { data: 0 },
|
||||
Commands::NotifyMotorStop { data: 0 },
|
||||
Commands::NotifyMotorUp { data: 0 },
|
||||
];
|
||||
let r = dp.get_callback_channel(&cmds);
|
||||
let s = dp.get_cmd_channel();
|
||||
@ -110,25 +102,14 @@ impl BleServer {
|
||||
trace!("Received update to bluetooth variable {:?}", cmd);
|
||||
match cmd {
|
||||
// TODO DISCUSS: This logic (if one button is pressed others are released) could be done in app instead.
|
||||
Commands::NotifyMotorUp => {
|
||||
button_up.lock().set_value(&BUTTON_PRESSED).notify();
|
||||
button_down.lock().set_value(&BUTTON_RELEASED).notify();
|
||||
button_stop.lock().set_value(&BUTTON_RELEASED).notify();
|
||||
Commands::NotifyMotorUp{data} => {
|
||||
button_up.lock().set_value(&[data]).notify();
|
||||
}
|
||||
Commands::NotifyMotorDown => {
|
||||
button_up.lock().set_value(&BUTTON_RELEASED).notify();
|
||||
button_down.lock().set_value(&BUTTON_PRESSED).notify();
|
||||
button_stop.lock().set_value(&BUTTON_RELEASED).notify();
|
||||
Commands::NotifyMotorDown{data} => {
|
||||
button_down.lock().set_value(&[data]).notify();
|
||||
}
|
||||
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();
|
||||
Commands::NotifyMotorStop{data} => {
|
||||
button_up.lock().set_value(&[data]).notify();
|
||||
}
|
||||
_ => {
|
||||
error!("Invalid command received by bluetooth handler {:?}", cmd);
|
||||
|
||||
Reference in New Issue
Block a user