-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMMALFocus.cpp
299 lines (238 loc) · 6.89 KB
/
MMMALFocus.cpp
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
* MMMALFocus.cpp
*
* Created on: Jul 13, 2013
* Author: Ji-Yu
*/
#include "MMMALFocus.h"
namespace MMMAL
{
const char * const MMMALFocus::DeviceName_ = "IXFocus";
const char * const MMMALFocus::Description_ = "Olympus IX Focus";
const char * const MMMALFocus::Keyword_Position_ = "Position";
const char * const MMMALFocus::Keyword_NearLimit_ = "Near Limit";
const char * const MMMALFocus::Keyword_FarLimit_ = "Far Limit";
const char * const MMMALFocus::Keyword_Sensitivity_ = "Sensitivity";
MMMALFocus::MMMALFocus() : initialized_(false), stepSize_(0.001), origin_(0), hub_(NULL)
{
InitializeDefaultErrorMessages();
CreateProperty(MM::g_Keyword_Name, DeviceName_, MM::String, true); // Name
CreateProperty(MM::g_Keyword_Description, Description_, MM::String, true); // Description
}
MMMALFocus::~MMMALFocus()
{
Shutdown();
}
void MMMALFocus::GetName(char *pszName) const
{
GetProperty(MM::g_Keyword_Name, pszName);
}
double MMMALFocus::GetStepSize()
{
return stepSize_;
}
bool MMMALFocus::Busy()
{
return hub_->IsFocusBusy();
}
int MMMALFocus::Shutdown()
{
if (hub_ != NULL)
{
hub_->SetFocusDevice(NULL);
hub_ = NULL;
}
initialized_ = false;
return DEVICE_OK;
}
int MMMALFocus::Initialize()
{
int ret;
CPropertyAction* pAct;
if (initialized_)
{
return DEVICE_OK;
}
hub_ = static_cast<MMMALHub*>(GetParentHub());
if (hub_ == NULL)
{
return DEVICE_ERR;
}
hub_->SetFocusDevice(this);
double curPos;
ret = GetPositionUm(curPos);
pAct = new CPropertyAction (this, &MMMALFocus::OnPosition);
ret = CreateProperty(Keyword_Position_, CDeviceUtils::ConvertToString(curPos), MM::Float, false, pAct);
if (ret != DEVICE_OK)
{
return ret;
}
pAct = new CPropertyAction (this, &MMMALFocus::OnNearLimit);
ret = CreateProperty(Keyword_NearLimit_, CDeviceUtils::ConvertToString(curPos), MM::Float, false, pAct);
if (ret != DEVICE_OK)
{
return ret;
}
pAct = new CPropertyAction (this, &MMMALFocus::OnFarLimit);
ret = CreateProperty(Keyword_FarLimit_, CDeviceUtils::ConvertToString(curPos), MM::Float, false, pAct);
if (ret != DEVICE_OK)
{
return ret;
}
pAct = new CPropertyAction (this, &MMMALFocus::OnSensitivity);
ret = CreateProperty(Keyword_Sensitivity_, "0", MM::Integer, false, pAct);
if (ret != DEVICE_OK)
{
return ret;
}
initialized_ = true;
return DEVICE_OK;
}
int MMMALFocus::SetPositionUm(double posUm)
{
long steps;
steps = (long) (posUm / stepSize_) + origin_;
return SetPositionSteps(steps);
}
int MMMALFocus::GetPositionUm(double& posUm)
{
long steps;
int ret = GetPositionSteps(steps);
posUm = (steps - origin_) * stepSize_;
return ret;
}
int MMMALFocus::SetPositionSteps(long steps)
{
LONGLONG posPm = (LONGLONG)steps * 1000;
return hub_->SetFocusPosition(posPm, true);
}
int MMMALFocus::GetPositionSteps(long& steps)
{
LONGLONG posPm = hub_->GetFocusPosition();
steps = (long)(posPm / 1000);
return DEVICE_OK;
}
int MMMALFocus::SetOrigin()
{
long steps;
int ret = GetPositionSteps(steps);
if (ret == DEVICE_OK)
{
origin_ = steps;
}
else
{
return ret;
}
return DEVICE_OK;
}
int MMMALFocus::GetLimits(double& min, double& max)
{
LONGLONG lmin;
LONGLONG lmax;
hub_->GetFocusLimits(&lmax, &lmin); //nearlimit and farlimit, farlimit is the smaller one
min = (double) (lmin / 1000 - origin_) * stepSize_;
max = (double) (lmax / 1000 - origin_) * stepSize_;
return DEVICE_OK;
}
int MMMALFocus::IsStageSequenceable(bool& seq) const
{
seq = false;
return DEVICE_OK;
}
bool MMMALFocus::IsContinuousFocusDrive() const
{
return false;
}
int MMMALFocus::OnPosition(MM::PropertyBase* pProp, MM::ActionType eAct)
{
int ret = DEVICE_OK;
double positionUm;
if (eAct == MM::BeforeGet)
{
ret = GetPositionUm(positionUm);
pProp->Set(positionUm);
}
else if (eAct == MM::AfterSet)
{
pProp->Get(positionUm);
ret = SetPositionUm(positionUm);
}
return ret;
}
int MMMALFocus::OnNearLimit(MM::PropertyBase* pProp, MM::ActionType eAct)
{
int ret = DEVICE_OK;
double nLimit, fLimit;
GetLimits(fLimit, nLimit);
if (eAct == MM::BeforeGet)
{
pProp->Set(nLimit);
}
else if (eAct == MM::AfterSet)
{
LONGLONG llNLimit, llFLimit;
pProp->Get(nLimit);
llNLimit = (LONGLONG)((nLimit / stepSize_ + origin_) * 1000);
llFLimit = (LONGLONG)((fLimit / stepSize_ + origin_) * 1000);
ret = hub_->SetFocusLimits(llNLimit,llFLimit);
}
return ret;
}
int MMMALFocus::OnFarLimit(MM::PropertyBase* pProp, MM::ActionType eAct)
{
int ret = DEVICE_OK;
double nLimit, fLimit;
GetLimits(fLimit, nLimit);
if (eAct == MM::BeforeGet)
{
pProp->Set(fLimit);
}
else if (eAct == MM::AfterSet)
{
LONGLONG llNLimit, llFLimit;
pProp->Get(fLimit);
llNLimit = (LONGLONG)((nLimit / stepSize_ + origin_) * 1000);
llFLimit = (LONGLONG)((fLimit / stepSize_ + origin_) * 1000);
ret = hub_->SetFocusLimits(llNLimit,llFLimit);
}
return ret;
}
int MMMALFocus::PositionChanged()
{
int ret = DEVICE_OK;
if (IsCallbackRegistered())
{
LONGLONG pos = hub_->GetFocusPosition();
double posUm = (pos / 1000 - origin_) * stepSize_;
ret = GetCoreCallback()->OnPropertyChanged(this, Keyword_Position_, CDeviceUtils::ConvertToString(posUm));
//std::clog << "Z position changed " << posUm << std::endl;
}
return ret;
}
int MMMALFocus::OnSensitivity(MM::PropertyBase* pProp, MM::ActionType eAct)
{
int ret = DEVICE_OK;
if (eAct == MM::BeforeGet)
{
long stepSize;
ret = hub_->GetFocusStepSize(&stepSize);
if (ret != DEVICE_OK)
{
return ret;
}
pProp->Set(stepSize);
}
else if(eAct == MM::AfterSet)
{
long stepSize;
pProp->Get(stepSize);
ret = hub_->SetFocusStepSize(stepSize);
if (ret != DEVICE_OK)
{
return ret;
}
}
return ret;
}
}