Repository navigation
Expand file tree
/
Copy pathSimShutter.h
More file actions
89 lines (71 loc) · 2.28 KB
/
Copy pathSimShutter.h
File metadata and controls
89 lines (71 loc) · 2.28 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
// Copyright 2025-2026 Board of Regents of the University of Wisconsin System
// SPDX-License-Identifier: BSD-2-Clause
#pragma once
#include "SimHub.h"
#include "DeviceBase.h"
#include <atomic>
#include <string>
#include <utility>
class SimShutter : public CShutterBase<SimShutter> {
std::string name_;
SimHub *hub_ = nullptr;
// Shutter state
std::atomic<bool> isOpen_{false};
public:
explicit SimShutter(std::string name) : name_(std::move(name)) {}
~SimShutter() { Shutdown(); }
bool Busy() final {
// TODO: Could introduce a small delay here
return false;
}
void GetName(char *name) const final {
CDeviceUtils::CopyLimitedString(name, name_.c_str());
}
int Fire(double /*deltaT*/) final { return DEVICE_UNSUPPORTED_COMMAND; }
int Initialize() final {
hub_ = static_cast<SimHub *>(GetParentHub());
if (!hub_) {
return DEVICE_COMM_HUB_MISSING;
}
isOpen_ = false;
int ret = CreateIntegerProperty(
MM::g_Keyword_State, 0, false,
new MM::ActionLambda(
[this](MM::PropertyBase *pProp, MM::ActionType eAct) {
if (eAct == MM::BeforeGet) {
pProp->Set(isOpen_ ? 1L : 0L);
} else if (eAct == MM::AfterSet) {
long v{};
pProp->Get(v);
return SetOpen(v != 0);
}
return DEVICE_OK;
}));
if (ret != DEVICE_OK)
return ret;
ret = AddAllowedValue(MM::g_Keyword_State, "0");
if (ret != DEVICE_OK)
return ret;
ret = AddAllowedValue(MM::g_Keyword_State, "1");
if (ret != DEVICE_OK)
return ret;
hub_->SetGetShutterOpenFunction([this] { return isOpen_.load(); });
return DEVICE_OK;
}
int Shutdown() final {
isOpen_ = false;
if (hub_) {
hub_->SetGetShutterOpenFunction([] { return true; });
hub_ = nullptr;
}
return DEVICE_OK;
}
int SetOpen(bool open = true) final {
isOpen_ = open;
return DEVICE_OK;
}
int GetOpen(bool &open) final {
open = isOpen_;
return DEVICE_OK;
}
};