/// <summary> /// Read a specified navigation value /// </summary> /// <param name="value">Navigation value to read</param> /// <returns>true if the operation succeeded, false otherwise</returns> public async Task <ReadNavigationValueResult> ReadNavigationValue(NavigationValue value) { ReadNavigationValueResult ret = new ReadNavigationValueResult(); // List characteristics ret.Success = await InitCharacteristics(); if (ret.Success) { // Look for the selected characteristic BleValue val = new BleValue(); BleGattCharacteristic nav_characteristic = _navigation_characteristics[value]; ret.Success = await BleDevice.ReadValueAsync(nav_characteristic, val); if (ret.Success) { switch (value) { case NavigationValue.Speed: { ret.SpeedValue = val.ToUInt16(); break; } case NavigationValue.Latitude: { ret.LatitudeValue = val.ToFloat64(); break; } case NavigationValue.Longitude: { ret.LongitudeValue = val.ToFloat64(); break; } case NavigationValue.TrackAngle: { ret.TrackAngleValue = val.ToUInt16(); break; } default: { ret.Success = false; break; } } } } return(ret); }
/// <summary> /// Called when a navigation value is being notified /// </summary> /// <param name="characteristic">Characteristic which notified the value</param> /// <param name="value">New characteristic value</param> private void OnNavigationNotification(BleGattCharacteristic characteristic, BleValue value) { if (characteristic.Guid == SpeedGuid) { SpeedChanged?.Invoke(value.ToUInt16()); } else if (characteristic.Guid == LatitudeGuid) { LatitudeChanged?.Invoke(value.ToFloat64()); } else if (characteristic.Guid == LongitudeGuid) { LongitudeChanged?.Invoke(value.ToFloat64()); } else if (characteristic.Guid == TrackAngleGuid) { TrackAngleChanged?.Invoke(value.ToUInt16()); } else { } }