#[cfg(feature = "_ble")]
use rmk_types::ble::BleStatus;
use rmk_types::connection::{ConnectionStatus, ConnectionType};
use rmk_types::protocol::rynk::RynkError;
#[cfg(feature = "_ble")]
use rmk_types::protocol::rynk::command::{ClearBleProfile, GetBleStatus, SwitchBleProfile};
use rmk_types::protocol::rynk::command::{GetConnectionStatus, GetConnectionType};
use super::super::RynkService;
use super::Handle;
impl Handle<GetConnectionType> for RynkService<'_> {
async fn handle(&self, _: ()) -> Result<ConnectionType, RynkError> {
Ok(self.ctx.preferred_connection())
}
}
impl Handle<GetConnectionStatus> for RynkService<'_> {
async fn handle(&self, _: ()) -> Result<ConnectionStatus, RynkError> {
Ok(self.ctx.connection_status())
}
}
#[cfg(feature = "_ble")]
impl Handle<GetBleStatus> for RynkService<'_> {
async fn handle(&self, _: ()) -> Result<BleStatus, RynkError> {
Ok(self.ctx.connection_status().ble)
}
}
#[cfg(feature = "_ble")]
impl Handle<SwitchBleProfile> for RynkService<'_> {
async fn handle(&self, slot: u8) -> Result<(), RynkError> {
Self::check_ble_profile_slot(slot)?;
crate::channel::BLE_PROFILE_CHANNEL
.try_send(crate::ble::profile::BleProfileAction::Switch(slot))
.map_err(|_| RynkError::NotReady)
}
}
#[cfg(feature = "_ble")]
impl Handle<ClearBleProfile> for RynkService<'_> {
async fn handle(&self, slot: u8) -> Result<(), RynkError> {
Self::check_ble_profile_slot(slot)?;
crate::channel::BLE_PROFILE_CHANNEL
.try_send(crate::ble::profile::BleProfileAction::ClearSlot(slot))
.map_err(|_| RynkError::NotReady)
}
}
#[cfg(feature = "_ble")]
impl RynkService<'_> {
fn check_ble_profile_slot(slot: u8) -> Result<(), RynkError> {
if (slot as usize) >= crate::NUM_BLE_PROFILE {
Err(RynkError::Invalid)
} else {
Ok(())
}
}
}