#[cfg(feature = "_ble")]
use rmk_types::battery::BatteryStatus;
use rmk_types::led_indicator::LedIndicator;
#[cfg(feature = "split")]
use rmk_types::protocol::rynk::PeripheralStatus;
#[cfg(feature = "_ble")]
use rmk_types::protocol::rynk::command::GetBatteryStatus;
#[cfg(feature = "split")]
use rmk_types::protocol::rynk::command::GetPeripheralStatus;
use rmk_types::protocol::rynk::command::{GetCurrentLayer, GetLedIndicator, GetMatrixState, GetSleepState, GetWpm};
use rmk_types::protocol::rynk::{MATRIX_BITMAP_SIZE, MatrixState, RynkError};
use super::super::RynkService;
use super::Handle;
impl Handle<GetCurrentLayer> for RynkService<'_> {
async fn handle(&self, _: ()) -> Result<u8, RynkError> {
Ok(self.ctx.active_layer())
}
}
impl Handle<GetMatrixState> for RynkService<'_> {
async fn handle(&self, _: ()) -> Result<MatrixState, RynkError> {
let mut bitmap: heapless::Vec<u8, MATRIX_BITMAP_SIZE> = heapless::Vec::new();
bitmap.resize_default(MATRIX_BITMAP_SIZE).expect("bitmap size matches");
self.ctx.read_matrix_state(&mut bitmap);
Ok(MatrixState { pressed_bitmap: bitmap })
}
}
#[cfg(feature = "_ble")]
impl Handle<GetBatteryStatus> for RynkService<'_> {
async fn handle(&self, _: ()) -> Result<BatteryStatus, RynkError> {
Ok(self.ctx.battery_status())
}
}
#[cfg(feature = "split")]
impl Handle<GetPeripheralStatus> for RynkService<'_> {
async fn handle(&self, id: u8) -> Result<PeripheralStatus, RynkError> {
crate::split::driver::current_peripheral_status(id as usize).ok_or(RynkError::Invalid)
}
}
impl Handle<GetWpm> for RynkService<'_> {
async fn handle(&self, _: ()) -> Result<u16, RynkError> {
Ok(crate::processor::builtin::wpm::current_wpm())
}
}
impl Handle<GetSleepState> for RynkService<'_> {
async fn handle(&self, _: ()) -> Result<bool, RynkError> {
Ok(crate::state::current_sleep_state())
}
}
impl Handle<GetLedIndicator> for RynkService<'_> {
async fn handle(&self, _: ()) -> Result<LedIndicator, RynkError> {
Ok(self.ctx.led_indicator())
}
}