alert-me/display/src/ble/gatt.rs
2024-09-24 22:40:35 +02:00

40 lines
1.2 KiB
Rust

use crate::ble::config_service::ConfigService;
use crate::ble::config_service::ConfigServiceEvent;
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,
pub config: ConfigService,
}
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)
}
},
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
}