/// <summary> /// Sets up the notifications; /// Will call Status /// </summary> /// <param name="notifyType"></param> /// <returns>true if the notify was set up. </returns> public async Task <bool> NotifyAnalogAsync(GattClientCharacteristicConfigurationDescriptorValue notifyType = GattClientCharacteristicConfigurationDescriptorValue.Notify) { if (!await EnsureCharacteristicAsync()) { return(false); } var ch = Characteristics[4]; if (ch == null) { return(false); } GattCommunicationStatus result = GattCommunicationStatus.ProtocolError; try { result = await ch.WriteClientCharacteristicConfigurationDescriptorAsync(notifyType); if (!NotifyAnalog_ValueChanged_Set) { // Only set the event callback once NotifyAnalog_ValueChanged_Set = true; ch.ValueChanged += (sender, args) => { var datameaning = "I32^100000_/|FIXED|A1|volts I32^100000_/|FIXED|A2|volts I32^100000_/|FIXED|A3|volts I32^100000_/|FIXED|A4|volts"; var parseResult = BluetoothDeviceController.BleEditor.ValueParser.Parse(args.CharacteristicValue, datameaning); Analog_A1 = parseResult.ValueList.GetValue("A1").AsDouble; Analog_A2 = parseResult.ValueList.GetValue("A2").AsDouble; Analog_A3 = parseResult.ValueList.GetValue("A3").AsDouble; Analog_A4 = parseResult.ValueList.GetValue("A4").AsDouble; AnalogEvent?.Invoke(parseResult); }; } } catch (Exception e) { Status.ReportStatus($"NotifyAnalog: {e.Message}", result); return(false); } Status.ReportStatus($"NotifyAnalog: set notification", result); return(true); }
private void Update() { analog = host.GetAnalogVec(tracker, channel); OnAnalog.Invoke(analog); }