-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathWait.cs
More file actions
47 lines (37 loc) · 1.27 KB
/
Copy pathWait.cs
File metadata and controls
47 lines (37 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
namespace NetduinoDevice
{
public class Delay
{
private const long TicksPerMicrosecond = TimeSpan.TicksPerMillisecond / 1000;
public static void Microseconds(uint microSeconds)
{
long stopTicks = Utility.GetMachineTime().Ticks +
(microSeconds * TicksPerMicrosecond);
while (Utility.GetMachineTime().Ticks < stopTicks) { }
}
private static long[] Axes = new long[3];
/// <summary>
/// Per-axis delay: don't wait if the last pulse already happened more
/// than "delay" ago (most likely moving another axis).
/// </summary>
/// <param name="axis">X = 0; Y = 1; Z = 2:</param>
/// <param name="microSeconds">Maximum microseconds to wait</param>
public static void Axis(Axis axis, uint microSeconds)
{
long increment = microSeconds * TicksPerMicrosecond;
long targetTicks = Axes[(int)axis] + increment;
long current;
while ( (current = Utility.GetMachineTime().Ticks) < targetTicks) { }
Axes[(int)axis] = current;
}
}
public enum Axis
{
X = 0,
Y = 1,
Z = 2
}
}