Compare commits
5 Commits
efd3277966
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ac157a4d3 | |||
| 8b5ff4ef93 | |||
| c271df4bce | |||
| 28e8fdaa4a | |||
| 22859bbe8f |
@ -30,23 +30,23 @@ embassy = ["esp-idf-svc/embassy-sync", "esp-idf-svc/critical-section", "esp-idf-
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
gem-remotes-lib = { path = "../gem-remotes-lib" }
|
gem-remotes-lib = { path = "../gem-remotes-lib" }
|
||||||
log = { version = "0.4", default-features = false, features = ["max_level_trace"] }
|
log = { version = "0.4", default-features = false, features = ["max_level_trace"] }
|
||||||
esp-idf-svc = { version = "0.49", default-features = false }
|
esp-idf-svc = { version = "0.51.0", default-features = false }
|
||||||
esp32-nimble = "0.7.0"
|
esp32-nimble = "0.11.1"
|
||||||
esp-idf-hal = "0.44.1"
|
esp-idf-hal = "0.45.2"
|
||||||
esp-idf-sys = "0.35.0"
|
esp-idf-sys = "0.36.1"
|
||||||
embedded-cli = "0.2.1"
|
embedded-cli = "0.2.1"
|
||||||
embedded-io = "0.6.1"
|
embedded-io = "0.6.1"
|
||||||
anyhow = "1.0.86"
|
anyhow = "1.0.86"
|
||||||
futures-lite = "2.3.0"
|
futures-lite = "2.3.0"
|
||||||
async-executor = "1.13.0"
|
async-executor = "1.13.0"
|
||||||
async-channel = "2.3.1"
|
async-channel = "2.3.1"
|
||||||
strum = "0.26.3"
|
strum = "0.27.2"
|
||||||
strum_macros = "0.26.4"
|
strum_macros = "0.27.2"
|
||||||
closure = "0.3.0"
|
closure = "0.3.0"
|
||||||
bitflags = "2.6.0"
|
bitflags = "2.9.4"
|
||||||
|
|
||||||
[build-dependencies]
|
[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.
|
# 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]
|
[package.metadata.cargo-udeps.ignore]
|
||||||
|
|||||||
@ -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_AUX: BleUuid = uuid128!("c1401124-8dda-45a3-959b-d23a0f8f53d7");
|
||||||
const UUID_BUTTON_LEARN: BleUuid = uuid128!("c1401223-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_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
|
// Status Characteristics
|
||||||
const UUID_STATUS_LIMITS: BleUuid = uuid128!("c1401321-8dda-45a3-959b-d23a0f8f53d7");
|
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})
|
on_bluetooth_cmd(&sender, args, Commands::BluetoothAuto {data: Button::Released})
|
||||||
}));
|
}));
|
||||||
let button_auto_name = button_auto.lock().create_descriptor(BleUuid::Uuid16(0x2901), DescriptorProperties::READ);
|
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 --------------------------------------------------------
|
// --- Device Name Bluetooth GATT --------------------------------------------------------
|
||||||
let device_name = lift_service.lock().create_characteristic(
|
let device_name = lift_service.lock().create_characteristic(
|
||||||
UUID_BLUETOOTH_NAME,
|
UUID_BLUETOOTH_NAME,
|
||||||
@ -214,21 +214,21 @@ impl BleServer {
|
|||||||
UUID_STATUS_MOTOR,
|
UUID_STATUS_MOTOR,
|
||||||
NimbleProperties::READ | NimbleProperties::INDICATE,
|
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_motor_name.lock().set_value(b"Status of motors");
|
||||||
// --- Status Status Bluetooth GATT --------------------------------------------------------
|
// --- Status Status Bluetooth GATT --------------------------------------------------------
|
||||||
let status_status = lift_service.lock().create_characteristic(
|
let status_status = lift_service.lock().create_characteristic(
|
||||||
UUID_STATUS_STATUS,
|
UUID_STATUS_STATUS,
|
||||||
NimbleProperties::READ | NimbleProperties::INDICATE,
|
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_status_name.lock().set_value(b"Status flags");
|
||||||
// --- Status Reason Bluetooth GATT --------------------------------------------------------
|
// --- Status Reason Bluetooth GATT --------------------------------------------------------
|
||||||
let status_reason = lift_service.lock().create_characteristic(
|
let status_reason = lift_service.lock().create_characteristic(
|
||||||
UUID_STATUS_REASON,
|
UUID_STATUS_REASON,
|
||||||
NimbleProperties::READ | NimbleProperties::INDICATE,
|
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");
|
status_reason_name.lock().set_value(b"Status reason");
|
||||||
|
|
||||||
// Default to not pairable
|
// Default to not pairable
|
||||||
|
|||||||
@ -72,6 +72,7 @@ async fn main_loop() -> Result<()> {
|
|||||||
|
|
||||||
// Setup of various drivers that need to out-live the executor
|
// Setup of various drivers that need to out-live the executor
|
||||||
let mut f_pic = FakePic::with_defaults(&mut dp);
|
let mut f_pic = FakePic::with_defaults(&mut dp);
|
||||||
|
f_pic.sync_pic().await?;
|
||||||
// Setup callback timers
|
// Setup callback timers
|
||||||
let mut button_timer = MessageTimer::<Commands, Commands>::new_on_dispatch(
|
let mut button_timer = MessageTimer::<Commands, Commands>::new_on_dispatch(
|
||||||
Commands::ButtonTimerRestart,
|
Commands::ButtonTimerRestart,
|
||||||
|
|||||||
@ -17,5 +17,5 @@ async-channel = "2.3.1"
|
|||||||
async-io = "2.3.4"
|
async-io = "2.3.4"
|
||||||
bitflags = "2.6.0"
|
bitflags = "2.6.0"
|
||||||
log = "0.4.22"
|
log = "0.4.22"
|
||||||
strum = "0.26.3"
|
strum = "0.27.2"
|
||||||
strum_macros = "0.26.4"
|
strum_macros = "0.27.2"
|
||||||
|
|||||||
@ -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)
|
// Distinguish toggles(like auto) which is on/off from buttons (which are pressed/released)
|
||||||
//TODONOW: remove?
|
//TODONOW: remove?
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
|||||||
@ -15,7 +15,7 @@ use crate::fake_motor::{Motors,MotorStatus};
|
|||||||
use crate::fake_limits::{Limits, LimitStatus, EMPTY_LIMITS};
|
use crate::fake_limits::{Limits, LimitStatus, EMPTY_LIMITS};
|
||||||
use crate::fake_status::Statuses;
|
use crate::fake_status::Statuses;
|
||||||
use crate::dispatch::{Dispatch, DispatchRecvQ, DispatchSendQ};
|
use crate::dispatch::{Dispatch, DispatchRecvQ, DispatchSendQ};
|
||||||
use crate::commands::{Commands};
|
use crate::commands::{Commands, button_from_bool};
|
||||||
|
|
||||||
pub struct FakePic {
|
pub struct FakePic {
|
||||||
motor_state: Motors,
|
motor_state: Motors,
|
||||||
@ -71,6 +71,18 @@ impl FakePic {
|
|||||||
recv_q: dp.get_callback_channel(&cmd_filter),
|
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 ======================================================
|
// === Change Fake Hardware Parameters ======================================================
|
||||||
pub fn change_limits(&mut self, l: Limits) -> () {
|
pub fn change_limits(&mut self, l: Limits) -> () {
|
||||||
self.limit_state = l;
|
self.limit_state = l;
|
||||||
@ -82,11 +94,13 @@ impl FakePic {
|
|||||||
pub async fn toggle_aux(&mut self) -> Result<()> {
|
pub async fn toggle_aux(&mut self) -> Result<()> {
|
||||||
self.status_state ^= Statuses::AUX;
|
self.status_state ^= Statuses::AUX;
|
||||||
self.send_q.send(Commands::BluetoothStatusStatus { data: self.status_state }).await?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub async fn toggle_auto(&mut self) -> Result<()> {
|
pub async fn toggle_auto(&mut self) -> Result<()> {
|
||||||
self.status_state ^= Statuses::AUTO;
|
self.status_state ^= Statuses::AUTO;
|
||||||
self.send_q.send(Commands::BluetoothStatusStatus { data: self.status_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?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub async fn press_learn(&mut self) -> Result<()> {
|
pub async fn press_learn(&mut self) -> Result<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user