Cuando leo datos del sensor GPS, viene con un ligero retraso. No obtienes valores como 0,1 0,2 0,3 0,4 0,5, etc., pero vienen como 1 y luego de repente 5 o 9 o 12. En este caso, la aguja salta de un lado a otro. ¿Alguien tiene una idea de cómo hacer que la aguja se mueva suavemente? ¿Supongo que se necesita algún tipo de retraso?
Algo así como, tomado de otro control:
async void animateProgress(int progress) { sweepAngle = 1; // Looping at data interval of 5 for (int i = 0; i < progress; i=i+5) { sweepAngle = i; await Task.Delay(3); } }Sin embargo, estoy un poco confundido sobre cómo implementar eso.
Aquí hay un código para dibujar una aguja en un lienzo:
private void OnDrawNeedle() { using (var needlePath = new SKPath()) { //first set up needle pointing towards 0 degrees (or 6 o'clock) var widthOffset = ScaleToSize(NeedleWidth / 2.0f); var needleOffset = ScaleToSize(NeedleOffset); var needleStart = _center.Y - needleOffset; var needleLength = ScaleToSize(NeedleLength); needlePath.MoveTo(_center.X - widthOffset, needleStart); needlePath.LineTo(_center.X + widthOffset, needleStart); needlePath.LineTo(_center.X, needleStart + needleLength); needlePath.LineTo(_center.X - widthOffset, needleStart); needlePath.Close(); //then calculate needle position in degrees var needlePosition = StartAngle + ((Value - RangeStart) / (RangeEnd - RangeStart) * SweepAngle); //finally rotate needle to actual value needlePath.Transform(SKMatrix.CreateRotationDegrees(needlePosition, _center.X, _center.Y)); using (var needlePaint = new SKPaint()) { needlePaint.IsAntialias = true; needlePaint.Color = NeedleColor.ToSKColor(); needlePaint.Style = SKPaintStyle.Fill; _canvas.DrawPath(needlePath, needlePaint); } } }EDITAR:
Todavía teniendo momentos difíciles para entender el proceso.
Digamos que no quiero aplicar este filtro para el control pero lo tengo en ViewModel para filtrar el valor. Tengo una clase de la que obtengo datos, por ejemplo, GPSTracker. GPSTracker proporciona valor de velocidad, luego me suscribo a EventListener en mi HomeViewModel y quiero filtrar el valor entrante.
Basado en la respuesta de Adams: