Compare commits

...

5 Commits

6 changed files with 38 additions and 16 deletions

View File

@ -30,23 +30,23 @@ embassy = ["esp-idf-svc/embassy-sync", "esp-idf-svc/critical-section", "esp-idf-
[dependencies]
gem-remotes-lib = { path = "../gem-remotes-lib" }
log = { version = "0.4", default-features = false, features = ["max_level_trace"] }
esp-idf-svc = { version = "0.49", default-features = false }
esp32-nimble = "0.7.0"
esp-idf-hal = "0.44.1"
esp-idf-sys = "0.35.0"
esp-idf-svc = { version = "0.51.0", default-features = false }
esp32-nimble = "0.11.1"
esp-idf-hal = "0.45.2"
esp-idf-sys = "0.36.1"
embedded-cli = "0.2.1"
embedded-io = "0.6.1"
anyhow = "1.0.86"
futures-lite = "2.3.0"
async-executor = "1.13.0"
async-channel = "2.3.1"
strum = "0.26.3"
strum_macros = "0.26.4"
strum = "0.27.2"
strum_macros = "0.27.2"
closure = "0.3.0"
bitflags = "2.6.0"
bitflags = "2.9.4"
[build-dependencies]
embuild = "0.32.0"
embuild = "0.33.1"
# Cargo udeps can check for unused dependencies; but if there is a dependency we want it to ignore put it here.
[package.metadata.cargo-udeps.ignore]

View File

@ -60,7 +60,7 @@ const UUID_BUTTON_STOP: BleUuid = uuid128!("c1401123-8dda-45a3-959b-d23a0f8f53d7
const UUID_BUTTON_AUX: BleUuid = uuid128!("c1401124-8dda-45a3-959b-d23a0f8f53d7");
const UUID_BUTTON_LEARN: BleUuid = uuid128!("c1401223-8dda-45a3-959b-d23a0f8f53d7");
const UUID_BUTTON_AUTO: BleUuid = uuid128!("c1401225-8dda-45a3-959b-d23a0f8f53d7");
const UUID_BLUETOOTH_NAME: BleUuid = uuid128!("c1411224-8dda-45a3-959b-d23a0f8f53d7");
const UUID_BLUETOOTH_NAME: BleUuid = uuid128!("c1401224-8dda-45a3-959b-d23a0f8f53d7");
// Status Characteristics
const UUID_STATUS_LIMITS: BleUuid = uuid128!("c1401321-8dda-45a3-959b-d23a0f8f53d7");
@ -192,7 +192,7 @@ impl BleServer {
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");
button_auto_name.lock().set_value(b"Command Auto");
// --- Device Name Bluetooth GATT --------------------------------------------------------
let device_name = lift_service.lock().create_characteristic(
UUID_BLUETOOTH_NAME,
@ -214,21 +214,21 @@ impl BleServer {
UUID_STATUS_MOTOR,
NimbleProperties::READ | NimbleProperties::INDICATE,
);
let status_motor_name = status_limits.lock().create_descriptor(BleUuid::Uuid16(0x2901), DescriptorProperties::READ);
let status_motor_name = status_motor.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);
let status_status_name = status_status.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);
let status_reason_name = status_reason.lock().create_descriptor(BleUuid::Uuid16(0x2901), DescriptorProperties::READ);
status_reason_name.lock().set_value(b"Status reason");
// Default to not pairable

View File

@ -72,6 +72,7 @@ async fn main_loop() -> Result<()> {
// Setup of various drivers that need to out-live the executor
let mut f_pic = FakePic::with_defaults(&mut dp);
f_pic.sync_pic().await?;
// Setup callback timers
let mut button_timer = MessageTimer::<Commands, Commands>::new_on_dispatch(
Commands::ButtonTimerRestart,

View File

@ -17,5 +17,5 @@ async-channel = "2.3.1"
async-io = "2.3.4"
bitflags = "2.6.0"
log = "0.4.22"
strum = "0.26.3"
strum_macros = "0.26.4"
strum = "0.27.2"
strum_macros = "0.27.2"

View File

@ -81,6 +81,13 @@ impl Button {
}
}
pub fn button_from_bool(b: bool) -> Button {
match b {
true => Button::Pressed,
false => Button::Released,
}
}
// Distinguish toggles(like auto) which is on/off from buttons (which are pressed/released)
//TODONOW: remove?
#[derive(Copy, Clone, Debug)]

View File

@ -15,7 +15,7 @@ use crate::fake_motor::{Motors,MotorStatus};
use crate::fake_limits::{Limits, LimitStatus, EMPTY_LIMITS};
use crate::fake_status::Statuses;
use crate::dispatch::{Dispatch, DispatchRecvQ, DispatchSendQ};
use crate::commands::{Commands};
use crate::commands::{Commands, button_from_bool};
pub struct FakePic {
motor_state: Motors,
@ -71,6 +71,18 @@ impl FakePic {
recv_q: dp.get_callback_channel(&cmd_filter),
}
}
// === Sync with the pic controller =========================================================
// Since we don't have a pic controller, just update the bluetooth with the internal state
// of the fake controller.
pub async fn sync_pic(&mut self) -> Result<()> {
self.send_q.send(Commands::BluetoothStatusMotor { data: self.motor_state }).await?;
self.send_q.send(Commands::BluetoothStatusLimits { data: self.limit_state }).await?;
self.send_q.send(Commands::BluetoothStatusStatus { data: self.status_state }).await?;
self.send_q.send(Commands::BluetoothAuto { data: button_from_bool(!self.status_state.intersection(Statuses::AUTO).is_empty()) }).await?;
self.send_q.send(Commands::BluetoothAux { data: button_from_bool(!self.status_state.intersection(Statuses::AUX).is_empty()) }).await?;
self.send_q.send(Commands::BluetoothLearn { data: button_from_bool(!self.status_state.intersection(Statuses::LEARN).is_empty()) }).await?;
Ok(())
}
// === Change Fake Hardware Parameters ======================================================
pub fn change_limits(&mut self, l: Limits) -> () {
self.limit_state = l;
@ -82,11 +94,13 @@ impl FakePic {
pub async fn toggle_aux(&mut self) -> Result<()> {
self.status_state ^= Statuses::AUX;
self.send_q.send(Commands::BluetoothStatusStatus { data: self.status_state }).await?;
self.send_q.send(Commands::BluetoothAux { data: button_from_bool(!self.status_state.intersection(Statuses::AUX).is_empty()) }).await?;
Ok(())
}
pub async fn toggle_auto(&mut self) -> Result<()> {
self.status_state ^= Statuses::AUTO;
self.send_q.send(Commands::BluetoothStatusStatus { data: self.status_state }).await?;
self.send_q.send(Commands::BluetoothAuto { data: button_from_bool(!self.status_state.intersection(Statuses::AUTO).is_empty()) }).await?;
Ok(())
}
pub async fn press_learn(&mut self) -> Result<()> {