wip
This commit is contained in:
parent
e2c5b7400f
commit
ff7849043f
11 changed files with 138 additions and 62 deletions
12
display/src/ble/config_service.rs
Normal file
12
display/src/ble/config_service.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
const MAX_STRING_LENGTH: usize = 128;
|
||||
|
||||
#[nrf_softdevice::gatt_service(uuid = "437dc41e-d899-40ac-9c83-188c8c4d9fe7")]
|
||||
pub struct ConfigService {
|
||||
#[characteristic(uuid = "e7b9ebd9-57e0-4821-8fa3-55e22cd7b705", read, write)]
|
||||
#[description = "WiFi SSID"]
|
||||
pub wifi_ssid: [u8; MAX_STRING_LENGTH],
|
||||
#[characteristic(uuid = "1bcc70df-179e-4853-bb74-c22380f491a3", read, write)]
|
||||
pub wifi_pw: [u8; MAX_STRING_LENGTH],
|
||||
#[characteristic(uuid = "3c9e4967-f792-4903-a968-490271cb7eeb", read, write)]
|
||||
pub mqtt_broker: [u8; MAX_STRING_LENGTH],
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
use crate::ble::config_service::ConfigService;
|
||||
use crate::ble::config_service::ConfigServiceEvent;
|
||||
|
||||
use crate::ble::battery_service::BatteryService;
|
||||
use crate::ble::battery_service::BatteryServiceEvent;
|
||||
|
||||
|
@ -9,6 +12,7 @@ use nrf_softdevice::ble::DisconnectedError;
|
|||
#[nrf_softdevice::gatt_server]
|
||||
pub struct Server {
|
||||
pub bas: BatteryService,
|
||||
pub config: ConfigService,
|
||||
}
|
||||
|
||||
pub async fn run(conn: &Connection, server: &Server) -> DisconnectedError {
|
||||
|
@ -19,6 +23,17 @@ pub async fn run(conn: &Connection, server: &Server) -> DisconnectedError {
|
|||
info!("battery notifications: {}", notifications)
|
||||
}
|
||||
},
|
||||
ServerEvent::Config(e) => match e {
|
||||
ConfigServiceEvent::WifiSsidWrite(val) => {
|
||||
info!("new ssid: {}", val);
|
||||
}
|
||||
ConfigServiceEvent::WifiPwWrite(val) => {
|
||||
info!("new pw: {}", val);
|
||||
}
|
||||
ConfigServiceEvent::MqttBrokerWrite(val) => {
|
||||
info!("new broker: {}", val);
|
||||
}
|
||||
},
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
use core::mem;
|
||||
|
||||
use crate::ble::gatt::Server;
|
||||
use defmt::{info, unwrap};
|
||||
use embassy_executor::Spawner;
|
||||
use nrf_softdevice::{raw, Softdevice};
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn softdevice_task(sd: &'static Softdevice) -> ! {
|
||||
sd.run().await
|
||||
}
|
||||
|
||||
fn configure(device_name: &str) -> nrf_softdevice::Config {
|
||||
nrf_softdevice::Config {
|
||||
clock: Some(raw::nrf_clock_lf_cfg_t {
|
||||
source: raw::NRF_CLOCK_LF_SRC_RC as u8,
|
||||
rc_ctiv: 16,
|
||||
rc_temp_ctiv: 2,
|
||||
accuracy: raw::NRF_CLOCK_LF_ACCURACY_500_PPM as u8,
|
||||
}),
|
||||
conn_gap: Some(raw::ble_gap_conn_cfg_t {
|
||||
conn_count: 6,
|
||||
event_length: 24,
|
||||
}),
|
||||
conn_gatt: Some(raw::ble_gatt_conn_cfg_t { att_mtu: 256 }),
|
||||
gatts_attr_tab_size: Some(raw::ble_gatts_cfg_attr_tab_size_t {
|
||||
attr_tab_size: raw::BLE_GATTS_ATTR_TAB_SIZE_DEFAULT,
|
||||
}),
|
||||
gap_role_count: Some(raw::ble_gap_cfg_role_count_t {
|
||||
adv_set_count: 1,
|
||||
periph_role_count: 3,
|
||||
central_role_count: 3,
|
||||
central_sec_count: 0,
|
||||
_bitfield_1: raw::ble_gap_cfg_role_count_t::new_bitfield_1(0),
|
||||
}),
|
||||
gap_device_name: Some(raw::ble_gap_cfg_device_name_t {
|
||||
p_value: device_name.as_bytes().as_ptr() as *const u8 as _,
|
||||
current_len: 9,
|
||||
max_len: 9,
|
||||
write_perm: unsafe { mem::zeroed() },
|
||||
_bitfield_1: raw::ble_gap_cfg_device_name_t::new_bitfield_1(
|
||||
raw::BLE_GATTS_VLOC_STACK as u8,
|
||||
),
|
||||
}),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run<'a>(spawner: Spawner, device_name: &str) -> (&'a Softdevice, Server) {
|
||||
let config = configure(device_name);
|
||||
|
||||
let sd = Softdevice::enable(&config);
|
||||
let server = unwrap!(Server::new(sd));
|
||||
unwrap!(spawner.spawn(softdevice_task(sd)));
|
||||
info!("softdevice started");
|
||||
|
||||
(sd, server)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue