Skip to content

Commit

Permalink
fix serial wombat analog input
Browse files Browse the repository at this point in the history
  • Loading branch information
ctacke committed Jul 25, 2023
1 parent e9d6cc2 commit 1d73239
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class AnalogInputPort : AnalogPortBase, IAnalogInputPort
private readonly int supplyVoltage;
private readonly object _lock = new object();

private readonly List<Voltage> buffer = new List<Voltage>();
private readonly Voltage[] buffer;

/// <summary>
/// Is the port sampling
Expand Down Expand Up @@ -60,7 +60,7 @@ public class AnalogInputPort : AnalogPortBase, IAnalogInputPort
/// <summary>
/// The voltage sampling buffer
/// </summary>
public IList<Voltage> VoltageSampleBuffer => buffer;
public Voltage[] VoltageSampleBuffer => buffer;

/// <summary>
/// The sampling interval
Expand All @@ -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);
Expand All @@ -91,14 +92,7 @@ public Task<Voltage> 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);
}
Expand Down

0 comments on commit 1d73239

Please sign in to comment.