From 1d732396354ac229ea686c7cd72cc5d892e7cedb Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Tue, 25 Jul 2023 16:30:36 -0500 Subject: [PATCH] fix serial wombat analog input --- .../Driver/SerialWombatBase.AnalogInputPort.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Driver/SerialWombatBase.AnalogInputPort.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Driver/SerialWombatBase.AnalogInputPort.cs index 0a55998c10..444177ae0f 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Driver/SerialWombatBase.AnalogInputPort.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Driver/SerialWombatBase.AnalogInputPort.cs @@ -28,7 +28,7 @@ public class AnalogInputPort : AnalogPortBase, IAnalogInputPort private readonly int supplyVoltage; private readonly object _lock = new object(); - private readonly List buffer = new List(); + private readonly Voltage[] buffer; /// /// Is the port sampling @@ -60,7 +60,7 @@ public class AnalogInputPort : AnalogPortBase, IAnalogInputPort /// /// The voltage sampling buffer /// - public IList VoltageSampleBuffer => buffer; + public Voltage[] VoltageSampleBuffer => buffer; /// /// The sampling interval @@ -76,6 +76,7 @@ public AnalogInputPort(SerialWombatBase controller, IPin pin, IAnalogChannelInfo SampleCount = sampleCount; this.controller = controller; + buffer = new Voltage[sampleCount]; supplyVoltage = (int)(controller.GetSupplyVoltage().Millivolts); ReferenceVoltage = new Voltage(supplyVoltage, Voltage.UnitType.Millivolts); @@ -91,14 +92,7 @@ public Task Read() var data = controller.ReadPublicData((byte)Pin.Key); Voltage = new Voltage((data * supplyVoltage) >> 16, Voltage.UnitType.Millivolts); - if (buffer.Count == 0) - { - buffer.Add(Voltage); - } - else - { - buffer[0] = Voltage; - } + buffer[0] = Voltage; return Task.FromResult(Voltage); }