Repository navigation
Expand file tree
/
Copy pathCameraControl.cs
More file actions
71 lines (61 loc) · 2.06 KB
/
Copy pathCameraControl.cs
File metadata and controls
71 lines (61 loc) · 2.06 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using static Scopie.LibQhy;
namespace Scopie;
internal readonly struct CameraControl
{
private const double ExposureFactor = 1_000_000.0;
private readonly IntPtr _qhyHandle;
private readonly ControlId _controlId;
private readonly bool _hasMinMaxStep;
private readonly double _min;
private readonly double _max;
private readonly double _step;
public static bool TryGet(IntPtr qhyHandle, ControlId controlId, out CameraControl cameraControl)
{
if (IsQHYCCDControlAvailable(qhyHandle, controlId) != 0)
{
cameraControl = default;
return false;
}
cameraControl = new CameraControl(qhyHandle, controlId);
return true;
}
private CameraControl(IntPtr qhyHandle, ControlId controlId)
{
_qhyHandle = qhyHandle;
_controlId = controlId;
_hasMinMaxStep = GetQHYCCDParamMinMaxStep(qhyHandle, controlId, out _min, out _max, out _step) == 0;
if (_controlId == ControlId.ControlExposure)
{
_min /= ExposureFactor;
_max /= ExposureFactor;
_step /= ExposureFactor;
}
}
public double Value
{
get
{
var v = GetQHYCCDParam(_qhyHandle, _controlId);
if (_controlId == ControlId.ControlExposure)
v /= ExposureFactor;
return v;
}
set
{
if (_controlId == ControlId.ControlExposure)
value *= ExposureFactor;
Check(SetQHYCCDParam(_qhyHandle, _controlId, value));
}
}
public string ToString(double value)
{
var v = value.Equals(uint.MaxValue) ? -1 : value;
return _hasMinMaxStep ? $"{_controlId} = {v} ({_min}-{_max} by {_step})" : $"{_controlId} = {value} (readonly)";
}
}
internal readonly struct CameraControlValue(CameraControl cameraControl)
{
public CameraControl CameraControl => cameraControl;
private readonly double _value = cameraControl.Value;
public override string ToString() => cameraControl.ToString(_value);
}