-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMMALLamp.cpp
116 lines (92 loc) · 2.58 KB
/
MMMALLamp.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
/*
* MMMALLamp.cpp
*
* Created on: Jul 19, 2013
* Author: Ji-Yu
*/
#include "MMMALLamp.h"
namespace MMMAL
{
const char * const MMMALLamp::DeviceName_ = "IXLamp";
const char * const MMMALLamp::Description_ = "Olympus IX Lamp";
const char * const MMMALLamp::Keyword_Voltage_ = "Voltage";
MMMALLamp::MMMALLamp() : initialized_(false), hub_(NULL)
{
InitializeDefaultErrorMessages();
CreateProperty(MM::g_Keyword_Name, DeviceName_, MM::String, true); // Name
CreateProperty(MM::g_Keyword_Description, Description_ , MM::String, true); // Description
}
MMMALLamp::~MMMALLamp()
{
Shutdown();
}
int MMMALLamp::Initialize()
{
int ret = DEVICE_OK;
if (initialized_)
{
return DEVICE_OK;
}
hub_ = static_cast<MMMALHub*>(GetParentHub());
if (hub_ == NULL)
{
return DEVICE_COMM_HUB_MISSING;
}
hub_->SetLampDevice(this);
ULONG pos = hub_->GetLampVoltage();
ULONG vMin, vMax;
hub_->GetLampVoltageRange(&vMin, &vMax);
CPropertyAction* pAct = new CPropertyAction (this, &MMMALLamp::OnVoltage);
ret = CreateProperty(Keyword_Voltage_, CDeviceUtils::ConvertToString((long)pos), MM::Integer, false, pAct);
if (ret != DEVICE_OK)
{
return ret;
}
SetPropertyLimits(Keyword_Voltage_, (long)vMin, (long)vMax);
initialized_ = true;
return ret;
}
int MMMALLamp::Shutdown()
{
if (hub_ != NULL)
{
hub_->SetLampDevice(NULL);
}
initialized_ = false;
return DEVICE_OK;
}
void MMMALLamp::GetName(char *pszName) const
{
GetProperty(MM::g_Keyword_Name, pszName);
}
bool MMMALLamp::Busy()
{
return hub_->IsLampBusy();
}
int MMMALLamp::OnVoltage(MM::PropertyBase* pProp, MM::ActionType eAct)
{
int ret = DEVICE_OK;
if (eAct == MM::BeforeGet)
{
ULONG v = hub_->GetLampVoltage();
pProp->Set((long) v);
}
else if (eAct == MM::AfterSet)
{
long voltage;
pProp->Get(voltage);
hub_->SetLampVoltage((ULONG) voltage, true);
}
return ret;
}
int MMMALLamp::VoltageChanged()
{
int ret = DEVICE_OK;
if (IsCallbackRegistered())
{
ULONG voltage = hub_->GetLampVoltage();
ret = GetCoreCallback()->OnPropertyChanged(this, Keyword_Voltage_, CDeviceUtils::ConvertToString((long)voltage));
}
return ret;
}
}