tweaking to fix misc. fake pic errors

This commit is contained in:
2024-11-03 15:29:40 -05:00
parent 045237d44f
commit 26cd5584e9
5 changed files with 223 additions and 75 deletions

View File

@ -147,6 +147,8 @@ impl BleServer {
.on_write(closure!(clone sender, |args: &mut OnWriteArgs| {
on_bluetooth_cmd(&sender, args, Commands::BluetoothDown {data: Button::Released})
}));
let button_down_name = button_down.lock().create_descriptor(BleUuid::Uuid16(0x2901), DescriptorProperties::READ);
button_down_name.lock().set_value(b"Command Down");
// --- Button Stop Bluetooth GATT --------------------------------------------------------
let button_stop = lift_service.lock().create_characteristic(
UUID_BUTTON_STOP,
@ -156,6 +158,8 @@ impl BleServer {
.on_write(closure!(clone sender, |args: &mut OnWriteArgs| {
on_bluetooth_cmd(&sender, args, Commands::BluetoothStop {data: Button::Released})
}));
let button_stop_name = button_stop.lock().create_descriptor(BleUuid::Uuid16(0x2901), DescriptorProperties::READ);
button_stop_name.lock().set_value(b"Command Stop");
// --- Button Aux Bluetooth GATT --------------------------------------------------------
let button_aux = lift_service.lock().create_characteristic(
UUID_BUTTON_AUX,
@ -165,6 +169,8 @@ impl BleServer {
.on_write(closure!(clone sender, |args: &mut OnWriteArgs| {
on_bluetooth_cmd(&sender, args, Commands::BluetoothAux {data: Button::Released})
}));
let button_aux_name = button_aux.lock().create_descriptor(BleUuid::Uuid16(0x2901), DescriptorProperties::READ);
button_aux_name.lock().set_value(b"Command Aux");
// --- Button Learn Bluetooth GATT --------------------------------------------------------
let button_learn = lift_service.lock().create_characteristic(
UUID_BUTTON_LEARN,
@ -174,6 +180,8 @@ impl BleServer {
.on_write(closure!(clone sender, |args: &mut OnWriteArgs| {
on_bluetooth_cmd(&sender, args, Commands::BluetoothLearn {data: Button::Released})
}));
let button_learn_name = button_learn.lock().create_descriptor(BleUuid::Uuid16(0x2901), DescriptorProperties::READ);
button_learn_name.lock().set_value(b"Command Learn");
// --- Button Auto Bluetooth GATT --------------------------------------------------------
let button_auto = lift_service.lock().create_characteristic(
UUID_BUTTON_AUTO,
@ -183,6 +191,8 @@ impl BleServer {
.on_write(closure!(clone sender, |args: &mut OnWriteArgs| {
on_bluetooth_cmd(&sender, args, Commands::BluetoothAuto {data: Button::Released})
}));
let button_auto_name = button_auto.lock().create_descriptor(BleUuid::Uuid16(0x2901), DescriptorProperties::READ);
button_auto_name.lock().set_value(b"Command Learn");
// --- Device Name Bluetooth GATT --------------------------------------------------------
let device_name = lift_service.lock().create_characteristic(
UUID_BLUETOOTH_NAME,
@ -197,21 +207,29 @@ impl BleServer {
UUID_STATUS_LIMITS,
NimbleProperties::READ | NimbleProperties::INDICATE,
);
let status_limits_name = status_limits.lock().create_descriptor(BleUuid::Uuid16(0x2901), DescriptorProperties::READ);
status_limits_name.lock().set_value(b"Status of limits");
// --- Status Motor Bluetooth GATT --------------------------------------------------------
let status_motor = lift_service.lock().create_characteristic(
UUID_STATUS_MOTOR,
NimbleProperties::READ | NimbleProperties::INDICATE,
);
let status_motor_name = status_limits.lock().create_descriptor(BleUuid::Uuid16(0x2901), DescriptorProperties::READ);
status_motor_name.lock().set_value(b"Status of motors");
// --- Status Status Bluetooth GATT --------------------------------------------------------
let status_status = lift_service.lock().create_characteristic(
UUID_STATUS_STATUS,
NimbleProperties::READ | NimbleProperties::INDICATE,
);
let status_status_name = status_limits.lock().create_descriptor(BleUuid::Uuid16(0x2901), DescriptorProperties::READ);
status_status_name.lock().set_value(b"Status flags");
// --- Status Reason Bluetooth GATT --------------------------------------------------------
let status_reason = lift_service.lock().create_characteristic(
UUID_STATUS_REASON,
NimbleProperties::READ | NimbleProperties::INDICATE,
);
let status_reason_name = status_limits.lock().create_descriptor(BleUuid::Uuid16(0x2901), DescriptorProperties::READ);
status_reason_name.lock().set_value(b"Status reason");
// Default to not pairable
self.advertise_unpairable()?;

View File

@ -100,6 +100,7 @@ impl<Q: PartialEq, S: Clone> MessageTimer<Q, S> {
Err(_) => {
trace!("Timeout reached");
self.send_q.send(self.done.clone()).await.expect("Failed to send timeout");
self.state = State::Stopped;
}
}
}

View File

@ -23,14 +23,14 @@ use ::{
//time::Duration, // could also use core::time::Duration?
},
core::time::Duration,
std::sync::Arc,
};
use async_channel::Sender;
use log::*; //{trace, debug, info, warn, error}
use gem_remotes_lib::{
Button,
Commands
Button, Commands, LimitStatus, EMPTY_LIMITS
};
#[derive(Command)]
@ -61,10 +61,37 @@ pub enum Menu{//<'a> {
/// 0 for not pressed, 1 for pressed
data: u8,
},
/// Send a bluetooth characteristic: Limits
BluetoothTopLimit { data: u8 },
/// Send a bluetooth characteristic: Limits
BluetoothBottomLimit { data: u8 },
/// Send a bluetooth characteristic: Aux
BluetoothAux {
/// 0 for not pressed, 1 for pressed
data: u8,
},
/// Send command from Fake PIC to toggle Aux
FPicAux,
/// Send command from Fake PIC to toggle Auto
FPicAuto,
/// Send command from Fake PIC to trigger learn mode
FPicLearn,
/// Send command from Fake PIC that is button press Up
FPicUp,
/// Send command from Fake PIC that is button press Down
FPicDown,
/// Send command from Fake PIC that is button press Stop (Can also be used as Up or Down release)
FPicStop,
/// Send command from Fake PIC to toggle Panic
FPicPanic,
/// Send command from Fake PIC to engage Lockout
FPicLockout,
/// Clear limit for first limit
FPicLimitClear1,
/// Activate top limit for first limit
FPicLimitTop1,
/// Activate bottom limit for first limit
FPicLimitBottom1,
/// Set hardware fault (Reason will be given as "test fault")
FPicFault,
/// Have the fake PIC output its internal state
FPicOutput,
/// Send a bluetooth characteristic: Wifi SSID
//BluetoothWifiSsid { ssid: &'a str },
@ -132,25 +159,81 @@ pub fn process_menu(
}
}
Menu::BluetoothLearn { data } => {
cli.writer()
.write_str("TODO: simulate bluetooth characteristic change")?;
let _ = data;
let but = input_to_button(data);
match but {
Some(d) => {
println!("Sending PicRecvUp command");
let _ = dispatch.send_blocking(Commands::BluetoothLearn{data: d});
}
None => {println!("Incorrect value; enter 0 or 1")}
}
}
Menu::BluetoothAuto { data } => {
cli.writer()
.write_str("TODO: simulate bluetooth characteristic change")?;
let _ = data;
let but = input_to_button(data);
match but {
Some(d) => {
println!("Sending PicRecvUp command");
let _ = dispatch.send_blocking(Commands::BluetoothAuto{data: d});
}
None => {println!("Incorrect value; enter 0 or 1")}
}
}
Menu::BluetoothTopLimit { data } => {
cli.writer()
.write_str("TODO: simulate bluetooth characteristic change")?;
let _ = data;
Menu::BluetoothAux { data } => {
let but = input_to_button(data);
match but {
Some(d) => {
println!("Sending PicRecvUp command");
let _ = dispatch.send_blocking(Commands::BluetoothAux{data: d});
}
None => {println!("Incorrect value; enter 0 or 1")}
}
}
Menu::BluetoothBottomLimit { data } => {
cli.writer()
.write_str("TODO: simulate bluetooth characteristic change")?;
let _ = data;
Menu::FPicAux => {
let _ = dispatch.send_blocking(Commands::FPicToggleAux);
}
Menu::FPicAuto => {
let _ = dispatch.send_blocking(Commands::FPicToggleAuto);
}
Menu::FPicLearn => {
let _ = dispatch.send_blocking(Commands::FPicPressLearn);
}
Menu::FPicUp => {
let _ = dispatch.send_blocking(Commands::FPicPressUp);
}
Menu::FPicDown => {
let _ = dispatch.send_blocking(Commands::FPicPressDown);
}
Menu::FPicStop => {
let _ = dispatch.send_blocking(Commands::FPicPressStop);
}
Menu::FPicPanic => {
let _ = dispatch.send_blocking(Commands::FPicTogglePanic);
}
Menu::FPicLockout => {
let _ = dispatch.send_blocking(Commands::FPicLockout);
}
Menu::FPicFault => {
let _ = dispatch.send_blocking(Commands::FPicFault { data: Arc::new("Test Fault".to_string()) });
}
Menu::FPicOutput => {
let _ = dispatch.send_blocking(Commands::FPicOutput);
}
Menu::FPicLimitClear1 => {
let mut lim = EMPTY_LIMITS;
lim.only_starboard_bow = LimitStatus::NotActive;
let _ = dispatch.send_blocking(Commands::FPicLimit { data: lim });
}
Menu::FPicLimitTop1 => {
let mut lim = EMPTY_LIMITS;
lim.only_starboard_bow = LimitStatus::TopActive;
let _ = dispatch.send_blocking(Commands::FPicLimit { data: lim });
}
Menu::FPicLimitBottom1 => {
let mut lim = EMPTY_LIMITS;
lim.only_starboard_bow = LimitStatus::BottomActive;
let _ = dispatch.send_blocking(Commands::FPicLimit { data: lim });
}
/*Menu::BluetoothWifiSsid { ssid } => {
cli.writer()
.write_str("TODO: simulate bluetooth characteristic change")?;