alert-me/display/src/ble/gatt.rs

40 lines
1.2 KiB
Rust
Raw Normal View History

2024-09-24 20:40:35 +00:00
use crate::ble::config_service::ConfigService;
use crate::ble::config_service::ConfigServiceEvent;
2024-05-20 09:18:17 +00:00
use crate::ble::battery_service::BatteryService;
use crate::ble::battery_service::BatteryServiceEvent;
use defmt::info;
use nrf_softdevice::ble::gatt_server;
use nrf_softdevice::ble::Connection;
use nrf_softdevice::ble::DisconnectedError;
#[nrf_softdevice::gatt_server]
pub struct Server {
pub bas: BatteryService,
2024-09-24 20:40:35 +00:00
pub config: ConfigService,
2024-05-20 09:18:17 +00:00
}
pub async fn run(conn: &Connection, server: &Server) -> DisconnectedError {
info!("gatt started");
gatt_server::run(conn, server, |e| match e {
ServerEvent::Bas(e) => match e {
BatteryServiceEvent::BatteryLevelCccdWrite { notifications } => {
info!("battery notifications: {}", notifications)
}
},
2024-09-24 20:40:35 +00:00
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);
}
},
2024-05-20 09:18:17 +00:00
})
.await
}