Repository navigation
Expand file tree
/
Copy pathMMMALLightPath.cpp
More file actions
134 lines (102 loc) · 3.25 KB
/
Copy pathMMMALLightPath.cpp
File metadata and controls
134 lines (102 loc) · 3.25 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
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
/*
* MMMALLightPath.cpp
*
* Created on: Jul 13, 2013
* Author: Ji-Yu
*/
#include "MMMALLightPath.h"
namespace MMMAL
{
const char * const MMMALLightPath::DeviceName_ = "IXLightPath";
const char * const MMMALLightPath::Description_ = "Olympus IX LightPath";
MMMALLightPath::MMMALLightPath():
initialized_(false)
{
InitializeDefaultErrorMessages();
CreateProperty(MM::g_Keyword_Name, DeviceName_, MM::String, true); // Name
CreateProperty(MM::g_Keyword_Description, Description_, MM::String, true); // Description
}
MMMALLightPath::~MMMALLightPath()
{
Shutdown();
}
int MMMALLightPath::Shutdown()
{
initialized_ = false;
return DEVICE_OK;
}
void MMMALLightPath::GetName(char *pszName) const
{
GetProperty(MM::g_Keyword_Name, pszName);
}
bool MMMALLightPath::Busy()
{
return hub_->IsLightPathBusy();
}
unsigned long MMMALLightPath::GetNumberOfPositions() const
{
return hub_->GetLightPathNPositions();
};
int MMMALLightPath::Initialize()
{
int ret = DEVICE_OK;
if (initialized_)
{
return DEVICE_OK;
}
hub_ = static_cast<MMMALHub*>(GetParentHub());
if (hub_ == NULL)
{
return DEVICE_ERR;
}
hub_->SetLightPathDevice(this);
int pos = hub_->GetLightPathState();
CPropertyAction* pAct = new CPropertyAction (this, &MMMALLightPath::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, &MMMALLightPath::OnLabel);
ret = CreateProperty(MM::g_Keyword_Label, "", MM::String, false, pAct);
SetPositionLabel(1L, "Eyepiece");
SetPositionLabel(2L, "Camera");
if (GetNumberOfPositions() > 2)
{
SetPositionLabel(3L, "Bottom Port");
SetPositionLabel(3L, "Camer + Bottom Port");
}
initialized_ = true;
return ret;
}
int MMMALLightPath::OnState(MM::PropertyBase* pProp, MM::ActionType eAct)
{
int ret = DEVICE_OK;
if (eAct == MM::BeforeGet)
{
pProp->Set((long)(hub_->GetLightPathState()));
}
else if (eAct == MM::AfterSet) {
long pos;
pProp->Get(pos);
assert((unsigned long) pos <= GetNumberOfPositions() && pos > 0);
ret = hub_->SetLightPathState((int)pos, true);
}
return ret;
}
int MMMALLightPath::StateChanged()
{
int ret = DEVICE_OK;
if (IsCallbackRegistered())
{
int state = hub_->GetLightPathState();
ret = GetCoreCallback()->OnPropertyChanged(this, MM::g_Keyword_State, CDeviceUtils::ConvertToString(state));
char buf[MM::MaxStrLength];
GetPositionLabel(state, buf);
ret = GetCoreCallback()->OnPropertyChanged(this, MM::g_Keyword_Label, buf);
//std::clog << "Lightpath state changed " << state << std::endl;
}
return ret;
}
}