forked from ln-dotnet/ln.type
42 lines
1.0 KiB
C#
42 lines
1.0 KiB
C#
// /**
|
|
// * File: DvDt.cs
|
|
// * Author: haraldwolff
|
|
// *
|
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|
// *
|
|
// *
|
|
// **/
|
|
using System;
|
|
namespace ln.type
|
|
{
|
|
public class dVdT
|
|
{
|
|
public double Current { get; private set; }
|
|
public double LastValue => lastValue;
|
|
public DateTime LastTimeStamp => lastTimestamp;
|
|
|
|
DateTime lastTimestamp;
|
|
double lastValue;
|
|
|
|
public dVdT()
|
|
{
|
|
lastTimestamp = DateTime.MinValue;
|
|
lastValue = 0.0;
|
|
}
|
|
|
|
public void Update(double value)
|
|
{
|
|
DateTime now = DateTime.Now;
|
|
double interval = (now - lastTimestamp).TotalSeconds;
|
|
if (Math.Abs(interval) > double.Epsilon)
|
|
{
|
|
double dV = value - lastValue;
|
|
Current = dV / interval;
|
|
lastTimestamp = now;
|
|
lastValue = value;
|
|
}
|
|
}
|
|
}
|
|
}
|