1use std::marker::PhantomData;
2
3use bluest;
4use bluest::Adapter;
5use bluest::Device;
6
7use crate::color::ColorChar;
8
9#[derive(Debug, Clone)]
12pub struct LightStick<T> {
13 pub(crate) device: Device,
14 pub(crate) adapter: Adapter,
15 pub(crate) _marker: PhantomData<T>,
16}
17
18#[derive(Debug, Clone)]
19pub struct Discovered;
20#[derive(Debug, Clone)]
21pub struct Connected;
22
23impl LightStick<Discovered> {
24 pub async fn connect(self) -> Result<LightStick<Connected>, bluest::Error> {
28 self.adapter.connect_device(&self.device).await?;
29 Ok(LightStick {
30 device: self.device,
31 adapter: self.adapter,
32 _marker: PhantomData,
33 })
34 }
35}
36
37impl LightStick<Connected> {
38 pub async fn disconnect(self) -> Result<(), bluest::Error> {
44 self.adapter.disconnect_device(&self.device).await
45 }
46
47 pub async fn get_characteristic<'connected>(&'connected self) -> ColorChar<'connected> {
49 ColorChar::new(&self).await
50 }
51
52 pub fn get_id(&self) -> bluest::DeviceId {
53 self.device.id()
54 }
55}