diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Driver/Mcp23xxx.DigitalInterruptPort.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Driver/Mcp23xxx.DigitalInterruptPort.cs
index ec1ecc7565..621b62be21 100644
--- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Driver/Mcp23xxx.DigitalInterruptPort.cs
+++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Driver/Mcp23xxx.DigitalInterruptPort.cs
@@ -14,7 +14,7 @@ public class DigitalInterruptPort : DigitalInterruptPortBase
public override bool State => state;
private bool state = false;
- private DateTime lastUpdate;
+ private int lastUpdate;
///
public override ResistorMode Resistor
@@ -52,13 +52,13 @@ public DigitalInterruptPort(IPin pin, InterruptMode interruptMode = InterruptMod
/// The new port state
internal void Update(bool newState)
{
- if (DateTime.UtcNow - lastUpdate < DebounceDuration)
+ var now = Environment.TickCount;
+
+ if (now - lastUpdate < DebounceDuration.TotalMilliseconds)
{
return;
}
- var now = DateTime.UtcNow;
-
if (newState != state)
{
switch (InterruptMode)
diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Driver/Pcx857x.DigitalInterruptPort.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Driver/Pcx857x.DigitalInterruptPort.cs
index 1f56366e13..7d839648b1 100644
--- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Driver/Pcx857x.DigitalInterruptPort.cs
+++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Driver/Pcx857x.DigitalInterruptPort.cs
@@ -30,7 +30,7 @@ public override ResistorMode Resistor
public override bool State => state;
private bool state = false;
- private DateTime lastUpdate;
+ private int lastUpdate;
private ResistorMode resistorMode = ResistorMode.Disabled;
@@ -68,13 +68,13 @@ public DigitalInterruptPort(IPin pin, InterruptMode interruptMode = InterruptMod
/// The new port state
internal void Update(bool newState)
{
- if (DateTime.UtcNow - lastUpdate < DebounceDuration)
+ var now = Environment.TickCount;
+
+ if (now - lastUpdate < DebounceDuration.TotalMilliseconds)
{
return;
}
- var now = DateTime.UtcNow;
-
if (newState != state)
{
switch (InterruptMode)
diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.KeyboardKey.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.KeyboardKey.cs
index 43afbe3828..8f55749296 100644
--- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.KeyboardKey.cs
+++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.KeyboardKey.cs
@@ -45,17 +45,17 @@ internal void SetState(bool newState)
case InterruptMode.EdgeRising:
if (State)
{
- RaiseChangedAndNotify(new DigitalPortResult(new DigitalState(State, DateTime.UtcNow), null));
+ RaiseChangedAndNotify(new DigitalPortResult(new DigitalState(State, Environment.TickCount), null));
}
break;
case InterruptMode.EdgeFalling:
if (!State)
{
- RaiseChangedAndNotify(new DigitalPortResult(new DigitalState(State, DateTime.UtcNow), null));
+ RaiseChangedAndNotify(new DigitalPortResult(new DigitalState(State, Environment.TickCount), null));
}
break;
case InterruptMode.EdgeBoth:
- RaiseChangedAndNotify(new DigitalPortResult(new DigitalState(State, DateTime.UtcNow), null));
+ RaiseChangedAndNotify(new DigitalPortResult(new DigitalState(State, Environment.TickCount), null));
break;
}
}
diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/SwitchingAnemometer.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/SwitchingAnemometer.cs
index 4ca8c780ab..4534cf2627 100644
--- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/SwitchingAnemometer.cs
+++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/SwitchingAnemometer.cs
@@ -63,7 +63,7 @@ public int SampleCount
///
/// Did we create the port(s) used by the peripheral
///
- readonly bool createdPort = false;
+ private readonly bool createdPort = false;
///
/// Creates a new `SwitchingAnemometer` using the specific digital input
@@ -152,7 +152,9 @@ protected override async Task ReadSensor()
StopUpdating();
}
- if (samples?.Count > 0 && (DateTime.UtcNow - samples?.Peek().New.Time > NoWindTimeout))
+ var now = Environment.TickCount;
+
+ if (samples?.Count > 0 && (TimeSpan.FromMilliseconds(now - samples?.Peek().New.Time ?? 0) > NoWindTimeout))
{ //we've exceeded the no wind interval time
samples?.Clear(); //will force a zero reading
}
@@ -166,7 +168,7 @@ protected override async Task ReadSensor()
{ // skip the first (old will be null)
if (sample.Old is { } old)
{
- speedSum += SwitchIntervalToKmh(sample.New.Time - old.Time);
+ speedSum += SwitchIntervalToKmh(TimeSpan.FromMilliseconds(sample.New.Time - old.Time));
}
}