-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMMALMirrorUnit.cpp
149 lines (114 loc) · 3.76 KB
/
MMMALMirrorUnit.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
/*
* MMMALMirrorUnit.cpp
*
* Created on: Jul 13, 2013
* Author: Ji-Yu
*/
#include "MMMALMirrorUnit.h"
namespace MMMAL
{
const char * const MMMALMirrorUnit::DeviceName_ = "IXMirrorUnit";
const char * const MMMALMirrorUnit::Description_ = "Olympus IX Mirror Unit";
const char * const MMMALMirrorUnit::Keyword_N_Positions_ = "NumOfPositions";
MMMALMirrorUnit::MMMALMirrorUnit():initialized_(false)
{
InitializeDefaultErrorMessages();
CreateProperty(MM::g_Keyword_Name, DeviceName_, MM::String, true); // Name
CreateProperty(MM::g_Keyword_Description, Description_ , MM::String, true); // Description
}
MMMALMirrorUnit::~MMMALMirrorUnit()
{
Shutdown();
}
int MMMALMirrorUnit::Shutdown()
{
if (hub_ != NULL)
{
hub_->SetMirrorUnitDevice(NULL);
}
initialized_ = false;
return DEVICE_OK;
}
void MMMALMirrorUnit::GetName(char *pszName) const
{
GetProperty(MM::g_Keyword_Name, pszName);
}
bool MMMALMirrorUnit::Busy()
{
return hub_->IsMirrorUnitBusy();
}
unsigned long MMMALMirrorUnit::GetNumberOfPositions() const
{
return hub_->GetMirrorUnitNPositions();
}
int MMMALMirrorUnit::Initialize()
{
int ret = DEVICE_OK;
if (initialized_)
return DEVICE_OK;
hub_ = static_cast<MMMALHub*>(GetParentHub());
if (hub_ == NULL)
{
return DEVICE_ERR;
}
hub_->SetMirrorUnitDevice(this);
int pos = hub_->GetMirrorUnitPosition();
CPropertyAction* pAct = new CPropertyAction (this, &MMMALMirrorUnit::OnState);
ret = CreateProperty(MM::g_Keyword_State, CDeviceUtils::ConvertToString((long)pos), MM::Integer, false, pAct);
if (ret != DEVICE_OK)
{
return ret;
}
SetPropertyLimits(MM::g_Keyword_State, 1, GetNumberOfPositions());
pAct = new CPropertyAction (this, &MMMALMirrorUnit::OnLabel);
ret = CreateProperty(MM::g_Keyword_Label, "", MM::String, false, pAct);
for (unsigned i = 1; i <= GetNumberOfPositions(); i++)
{
long bufSize = MM::MaxStrLength;
char buf[MM::MaxStrLength];
if (malGetCubeName(hub_->GetMALObject(), (MAL_MS_CUBEPOSITION)(MAL_MS_CUBEPOS0 + i), &bufSize, buf) == MAL_OK && bufSize > 0)
{
if (strcmp(buf, "---") != 0)
{
SetPositionLabel(i, buf);
}
else
{
SetPositionLabel(i, CDeviceUtils::ConvertToString((int)i));
}
}
}
initialized_ = true;
return ret;
}
int MMMALMirrorUnit::OnState(MM::PropertyBase* pProp, MM::ActionType eAct)
{
if (eAct == MM::BeforeGet)
{
pProp->Set((long)(hub_->GetMirrorUnitPosition()));
return DEVICE_OK;
}
else if (eAct == MM::AfterSet)
{
long pos;
pProp->Get(pos);
assert((unsigned long) pos <= GetNumberOfPositions() && pos > 0);
return hub_->SetMirrorUnitPosition((int)pos, true);
}
return DEVICE_OK;
}
int MMMALMirrorUnit::StateChanged()
{
int ret = DEVICE_OK;
if (IsCallbackRegistered())
{
int pos = hub_->GetMirrorUnitPosition();
ret = GetCoreCallback()->OnPropertyChanged(this, MM::g_Keyword_State, CDeviceUtils::ConvertToString(pos));
char buf[MM::MaxStrLength];
GetPositionLabel(pos, buf);
ret = GetCoreCallback()->OnPropertyChanged(this, MM::g_Keyword_Label, buf);
//std::clog << "Lightpath state changed " << state << std::endl;
}
return ret;
}
}