| 140 | } |
| 141 | |
| 142 | pub async fn unsubscribe(&mut self) -> Result<()> { |
| 143 | if let Some(token) = &self.notify_token { |
| 144 | self.characteristic.RemoveValueChanged(*token)?; |
| 145 | } |
| 146 | self.notify_token = None; |
| 147 | let config = GattClientCharacteristicConfigurationDescriptorValue::None; |
| 148 | let status = self |
| 149 | .characteristic |
| 150 | .WriteClientCharacteristicConfigurationDescriptorAsync(config)? |
| 151 | .into_future() |
| 152 | .await?; |
| 153 | trace!("unsubscribe {:?}", status); |
| 154 | if status == GattCommunicationStatus::Success { |
| 155 | Ok(()) |
| 156 | } else { |
| 157 | Err(Error::Other( |
| 158 | format!("Windows UWP threw error on unsubscribe: {:?}", status).into(), |
| 159 | )) |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | pub fn uuid(&self) -> Uuid { |
| 164 | utils::to_uuid(&self.characteristic.Uuid().unwrap()) |