pub mod actions;
use anyhow::Result;
use std::sync::Arc;
use tokio::sync::mpsc;
use tracing::info;
use crate::console_error;
use crate::llm::ollama_client::OllamaClient;
use crate::server::bluetooth_ble::BluetoothBle;
use crate::state::app_state::AppState;
pub struct BluetoothBleMouse;
impl BluetoothBleMouse {
#[cfg(all(unix, feature = "bluetooth"))]
pub async fn spawn_with_llm_actions(
device_name: String,
llm_client: OllamaClient,
app_state: Arc<AppState>,
status_tx: mpsc::UnboundedSender<String>,
server_id: crate::state::ServerId,
instruction: String,
) -> Result<std::net::SocketAddr> {
info!("Starting BLE HID Mouse server: {}", device_name);
let mouse_instruction = format!(
"Configure as a BLE HID mouse with HID Service (UUID: 0x1812). {} {}",
instruction,
"Add HID Report Map, HID Report Input, HID Information, and HID Control Point characteristics for mouse."
);
let log_tx = status_tx.clone();
let log_name = device_name.clone();
match BluetoothBle::spawn_with_llm_actions(
device_name,
llm_client,
app_state,
status_tx,
server_id,
mouse_instruction,
)
.await
{
Ok(addr) => Ok(addr),
Err(e) => {
console_error!(log_tx, "{}", radio_start_failure(&log_name, &e));
Err(e)
}
}
}
}
pub fn radio_start_failure(device_name: &str, err: &anyhow::Error) -> String {
format!(
"BLE HID mouse '{device_name}' could not start \
(decision=refused_adapter_unavailable): {err}. No HID service was published and \
nothing is advertising."
)
}
#[cfg(any(all(unix, not(feature = "bluetooth")), not(unix)))]
impl BluetoothBleMouse {
pub async fn spawn_with_llm_actions(
_device_name: String,
_llm_client: OllamaClient,
_app_state: Arc<AppState>,
_status_tx: mpsc::UnboundedSender<String>,
_server_id: crate::state::ServerId,
_instruction: String,
) -> Result<std::net::SocketAddr> {
anyhow::bail!("BLE mouse support not enabled - compile with --features bluetooth-ble-mouse")
}
}
pub mod hid_mouse_buttons {
pub const BUTTON_LEFT: u8 = 0x01;
pub const BUTTON_RIGHT: u8 = 0x02;
pub const BUTTON_MIDDLE: u8 = 0x04;
}
pub const HID_MOUSE_INPUT_REPORT_LEN: usize = 4;
pub const HID_MOUSE_REPORT_DESCRIPTOR: &[u8] = &[
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, 0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, 0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x38, 0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x03, 0x81, 0x06, 0xC0, 0xC0, ];