-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rates.cs
249 lines (221 loc) · 7.67 KB
/
Rates.cs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using ASCOM.DeviceInterface;
using System.Collections;
using System.Threading;
namespace ASCOM.Starbook
{
#region Rate class
//
// The Rate class implements IRate, and is used to hold values
// for AxisRates. You do not need to change this class.
//
// The Guid attribute sets the CLSID for ASCOM.Starbook.Rate
// The ClassInterface/None addribute prevents an empty interface called
// _Rate from being created and used as the [default] interface
//
[Guid("76ec59a2-057d-4d14-9891-b3da6461a101")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class Rate : ASCOM.DeviceInterface.IRate
{
private double maximum = 0;
private double minimum = 0;
//
// Default constructor - Internal prevents public creation
// of instances. These are values for AxisRates.
//
internal Rate(double minimum, double maximum)
{
this.maximum = maximum;
this.minimum = minimum;
}
#region Implementation of IRate
public void Dispose()
{
// TODO Add any required object cleanup here
}
public double Maximum
{
get { return this.maximum; }
set { this.maximum = value; }
}
public double Minimum
{
get { return this.minimum; }
set { this.minimum = value; }
}
#endregion
}
#endregion
#region AxisRates
//
// AxisRates is a strongly-typed collection that must be enumerable by
// both COM and .NET. The IAxisRates and IEnumerable interfaces provide
// this polymorphism.
//
// The Guid attribute sets the CLSID for ASCOM.Starbook.AxisRates
// The ClassInterface/None addribute prevents an empty interface called
// _AxisRates from being created and used as the [default] interface
//
[Guid("50d4c593-6164-4a28-a96a-a3bacaaa1baf")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class AxisRates : IAxisRates, IEnumerable
{
private TelescopeAxes axis;
private List<Rate> rates;
//
// Constructor - Internal prevents public creation
// of instances. Returned by Telescope.AxisRates.
//
internal AxisRates(TelescopeAxes axis)
{
this.axis = axis;
this.rates = new List<Rate>();
//
// This collection must hold zero or more Rate objects describing the
// rates of motion ranges for the Telescope.MoveAxis() method
// that are supported by your driver. It is OK to leave this
// array empty, indicating that MoveAxis() is not supported.
//
// Note that we are constructing a rate array for the axis passed
// to the constructor. Thus we switch() below, and each case should
// initialize the array for the rate for the selected axis.
//
switch (axis)
{
case TelescopeAxes.axisPrimary:
case TelescopeAxes.axisSecondary:
{
HashSet<double> rates = new HashSet<double>();
for (int index = 0; index <= 8; index++)
{
double rate = Telescope.GuideRate(index);
if (!rates.Contains(rate))
{
rates.Add(rate);
this.rates.Add(new Rate(rate, rate));
}
}
break;
}
case TelescopeAxes.axisTertiary:
{
break;
}
}
}
#region IAxisRates Members
public int Count
{
get { return this.rates.Count; }
}
public void Dispose()
{
// TODO Add any required object cleanup here
}
public IEnumerator GetEnumerator()
{
return rates.GetEnumerator();
}
public IRate this[int index]
{
get { return this.rates[index - 1]; } // 1-based
}
#endregion
}
#endregion
#region TrackingRates
//
// TrackingRates is a strongly-typed collection that must be enumerable by
// both COM and .NET. The ITrackingRates and IEnumerable interfaces provide
// this polymorphism.
//
// The Guid attribute sets the CLSID for ASCOM.Starbook.TrackingRates
// The ClassInterface/None addribute prevents an empty interface called
// _TrackingRates from being created and used as the [default] interface
//
// This class is implemented in this way so that applications based on .NET 3.5
// will work with this .NET 4.0 object. Changes to this have proved to be challenging
// and it is strongly suggested that it isn't changed.
//
[Guid("1923d589-c738-4ffd-a6b9-16ba01548579")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class TrackingRates : ITrackingRates, IEnumerable, IEnumerator
{
private readonly DriveRates[] trackingRates;
// this is used to make the index thread safe
private readonly ThreadLocal<int> pos = new ThreadLocal<int>(() => { return -1; });
private static readonly object lockObj = new object();
//
// Default constructor - Internal prevents public creation
// of instances. Returned by Telescope.AxisRates.
//
internal TrackingRates()
{
//
// This array must hold ONE or more DriveRates values, indicating
// the tracking rates supported by your telescope. The one value
// (tracking rate) that MUST be supported is driveSidereal!
//
this.trackingRates = new[] { DriveRates.driveSidereal };
// TODO Initialize this array with any additional tracking rates that your driver may provide
}
#region ITrackingRates Members
public int Count
{
get { return this.trackingRates.Length; }
}
public IEnumerator GetEnumerator()
{
pos.Value = -1;
return this as IEnumerator;
}
public void Dispose()
{
// TODO Add any required object cleanup here
}
public DriveRates this[int index]
{
get { return this.trackingRates[index - 1]; } // 1-based
}
#endregion
#region IEnumerable members
public object Current
{
get
{
lock (lockObj)
{
if (pos.Value < 0 || pos.Value >= trackingRates.Length)
{
throw new System.InvalidOperationException();
}
return trackingRates[pos.Value];
}
}
}
public bool MoveNext()
{
lock (lockObj)
{
if (++pos.Value >= trackingRates.Length)
{
return false;
}
return true;
}
}
public void Reset()
{
pos.Value = -1;
}
#endregion
}
#endregion
}