Skip to content

Commit 441341c

Browse files
committed
Merge branch 'main' into issue-97
2 parents b17329f + 550b7b2 commit 441341c

14 files changed

+231
-58
lines changed

Source/Devices/AuxiliaryIO.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ using namespace OnixSourcePlugin;
2929
AuxiliaryIO::AuxiliaryIO(std::string name, std::string hubName, const oni_dev_idx_t analogIndex, const oni_dev_idx_t digitalIndex, std::shared_ptr<Onix1> oni_ctx)
3030
: CompositeDevice(name, hubName, AuxiliaryIO::getCompositeDeviceType(), createAuxiliaryIODevices(hubName, analogIndex, digitalIndex, oni_ctx), oni_ctx)
3131
{
32+
analogIO = getDevice<AnalogIO>(OnixDeviceType::ANALOGIO);
33+
digitalIO = getDevice<DigitalIO>(OnixDeviceType::DIGITALIO);
3234
}
3335

3436
// NB: This constructor assumes that the digitalIO device is located at one index above the analogIndex
@@ -47,11 +49,13 @@ OnixDeviceVector AuxiliaryIO::createAuxiliaryIODevices(std::string hubName, cons
4749
return devices;
4850
}
4951

50-
void AuxiliaryIO::processFrames()
52+
bool AuxiliaryIO::isEnabled() const
5153
{
52-
auto analogIO = getAnalogIO();
53-
auto digitalIO = getDigitalIO();
54+
return analogIO->isEnabled();
55+
}
5456

57+
void AuxiliaryIO::processFrames()
58+
{
5559
if (!digitalIO->isEnabled() && !analogIO->isEnabled())
5660
{
5761
return;
@@ -99,10 +103,10 @@ CompositeDeviceType AuxiliaryIO::getCompositeDeviceType()
99103

100104
std::shared_ptr<AnalogIO> AuxiliaryIO::getAnalogIO()
101105
{
102-
return getDevice<AnalogIO>(OnixDeviceType::ANALOGIO);
106+
return analogIO;
103107
}
104108

105109
std::shared_ptr<DigitalIO> AuxiliaryIO::getDigitalIO()
106110
{
107-
return getDevice<DigitalIO>(OnixDeviceType::DIGITALIO);
111+
return digitalIO;
108112
}

Source/Devices/AuxiliaryIO.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ namespace OnixSourcePlugin
4040

4141
AuxiliaryIO(std::string name, std::string hubName, const oni_dev_idx_t analogIndex, const oni_dev_idx_t digitalIndex, std::shared_ptr<Onix1> oni_ctx);
4242

43+
bool isEnabled() const override;
44+
4345
static OnixDeviceType getDeviceType();
4446
static CompositeDeviceType getCompositeDeviceType();
4547

@@ -52,6 +54,9 @@ namespace OnixSourcePlugin
5254

5355
static OnixDeviceVector createAuxiliaryIODevices(std::string hubName, const oni_dev_idx_t analogIndex, const oni_dev_idx_t digitalIndex, std::shared_ptr<Onix1> oni_ctx);
5456

57+
std::shared_ptr<AnalogIO> analogIO;
58+
std::shared_ptr<DigitalIO> digitalIO;
59+
5560
JUCE_LEAK_DETECTOR(AuxiliaryIO);
5661
};
5762
}

Source/Devices/PortController.cpp

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,64 @@ int PortController::configureDevice()
3434
{
3535
if (deviceContext == nullptr || !deviceContext->isInitialized()) return 1;
3636

37-
return deviceContext->writeRegister(deviceIdx, (uint32_t)PortControllerRegister::ENABLE, 1);
37+
return deviceContext->writeRegister(deviceIdx, (uint32_t)PortControllerRegister::ENABLE, 1u);
38+
}
39+
40+
bool PortController::resetLinkFlags()
41+
{
42+
if (deviceContext == nullptr || !deviceContext->isInitialized()) return false;
43+
44+
int rc = deviceContext->writeRegister(deviceIdx, (uint32_t)PortControllerRegister::LINKFLAGS, 0b11);
45+
if (rc != ONI_ESUCCESS)
46+
{
47+
Onix1::showWarningMessageBoxAsync("Port Controller Error", "Unable to set the link flags for " + getName());
48+
return false;
49+
}
50+
51+
return true;
52+
}
53+
54+
uint32_t PortController::getLinkFlags()
55+
{
56+
uint32_t linkFlags;
57+
int rc = deviceContext->readRegister(deviceIdx, (uint32_t)PortControllerRegister::LINKFLAGS, &linkFlags);
58+
59+
if (rc != ONI_ESUCCESS)
60+
{
61+
Onix1::showWarningMessageBoxAsync("Port Controller Error", "Unable to read the link flags for " + getName());
62+
return false;
63+
}
64+
65+
return linkFlags;
66+
}
67+
68+
bool PortController::updateSettings()
69+
{
70+
return getLinkFlags() == 0;
71+
}
72+
73+
void PortController::addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers)
74+
{
75+
}
76+
77+
std::string PortController::getPortNameString() const
78+
{
79+
return OnixDevice::getPortName(port);
80+
}
81+
82+
PortName PortController::getPort() const
83+
{
84+
return port;
85+
}
86+
87+
bool PortController::getErrorFlag()
88+
{
89+
return errorFlag;
90+
}
91+
92+
double PortController::getLastVoltageSet() const
93+
{
94+
return lastVoltageSet;
3895
}
3996

4097
void PortController::startAcquisition()

Source/Devices/PortController.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ namespace OnixSourcePlugin
3939
DESPWR = 2,
4040
PORTVOLTAGE = 3,
4141
SAVEVOLTAGE = 4,
42-
LINKSTATE = 5
42+
LINKSTATE = 5,
43+
LINKFLAGS = 7,
4344
};
4445

4546
enum class PortStatusCode : uint32_t
@@ -83,14 +84,10 @@ namespace OnixSourcePlugin
8384
PortController(PortName port_, std::shared_ptr<Onix1> ctx_);
8485

8586
int configureDevice() override;
86-
87-
bool updateSettings() override { return true; }
88-
87+
bool updateSettings() override;
8988
void startAcquisition() override;
90-
9189
void processFrames() override;
92-
93-
void addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers) override {};
90+
void addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers) override;
9491

9592
void updateDiscoveryParameters(DiscoveryParameters parameters);
9693

@@ -106,12 +103,20 @@ namespace OnixSourcePlugin
106103

107104
static DiscoveryParameters getHeadstageDiscoveryParameters(std::string headstage);
108105

109-
std::string getPortName() const { return OnixDevice::getPortName(port); }
106+
std::string getPortNameString() const;
107+
108+
PortName getPort() const;
109+
110+
/** Check if the port status changed during acquisition and there is an error reported */
111+
bool getErrorFlag();
112+
113+
double getLastVoltageSet() const;
110114

111-
/** Check if the port status changed and there is an error reported */
112-
bool getErrorFlag() { return errorFlag; }
115+
/** Writes to the link flags register to reset the flags. This should be called after headstages are locked. */
116+
bool resetLinkFlags();
113117

114-
double getLastVoltageSet() const { return lastVoltageSet; }
118+
/** Returns the link flags value, which is zero unless the lock or pass was lost outside of acquisition */
119+
uint32_t getLinkFlags();
115120

116121
private:
117122

@@ -135,7 +140,7 @@ namespace OnixSourcePlugin
135140
{
136141
public:
137142
ConfigureVoltageWithProgressBar(DiscoveryParameters params, PortController* port)
138-
: ThreadWithProgressWindow("Configuring voltage on " + port->getPortName(), true, false)
143+
: ThreadWithProgressWindow("Configuring voltage on " + port->getPortNameString(), true, false)
139144
{
140145
m_params = params;
141146
m_port = port;

Source/Onix1.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace OnixSourcePlugin
3535
{
3636
constexpr char* NEUROPIXELSV1F_HEADSTAGE_NAME = "Neuropixels 1.0f Headstage";
3737
constexpr char* NEUROPIXELSV1E_HEADSTAGE_NAME = "Neuropixels 1.0e Headstage";
38-
constexpr char* NEUROPIXELSV2E_HEADSTAGE_NAME = "Neuropixels 2.0 Headstage";
38+
constexpr char* NEUROPIXELSV2E_HEADSTAGE_NAME = "Neuropixels 2.0e Headstage";
3939
constexpr char* BREAKOUT_BOARD_NAME = "Breakout Board";
4040

4141
class error_t : public std::exception

Source/OnixDevice.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ int OnixDevice::getPortOffset(PortName port)
153153
return (uint32_t)port << 8;
154154
}
155155

156-
std::string OnixDevice::getPortName(int offset)
156+
std::string OnixDevice::getPortName(oni_dev_idx_t index)
157157
{
158-
switch (offset)
158+
switch (getOffset(index))
159159
{
160160
case 0:
161161
return "";
@@ -173,11 +173,6 @@ std::string OnixDevice::getPortName(PortName port)
173173
return getPortName(getPortOffset(port));
174174
}
175175

176-
std::string OnixDevice::getPortName(oni_dev_idx_t index)
177-
{
178-
return getPortName(getOffset(index));
179-
}
180-
181176
PortName OnixDevice::getPortFromIndex(oni_dev_idx_t index)
182177
{
183178
return index & (1 << 8) ? PortName::PortA : PortName::PortB;
@@ -270,6 +265,18 @@ bool CompositeDevice::compareIndex(uint32_t index)
270265
return false;
271266
}
272267

268+
bool CompositeDevice::isEnabled() const
269+
{
270+
bool enabled = true;
271+
272+
for (const auto& device : devices)
273+
{
274+
enabled &= device->isEnabled();
275+
}
276+
277+
return enabled;
278+
}
279+
273280
bool CompositeDevice::isEnabled(uint32_t index)
274281
{
275282
for (const auto& device : devices)
@@ -286,6 +293,14 @@ bool CompositeDevice::isEnabled(uint32_t index)
286293
return false;
287294
}
288295

296+
void CompositeDevice::setEnabled(bool newState)
297+
{
298+
for (const auto& device : devices)
299+
{
300+
device->setEnabled(newState);
301+
}
302+
}
303+
289304
void CompositeDevice::setEnabled(uint32_t index, bool newState)
290305
{
291306
for (const auto& device : devices)

Source/OnixDevice.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ namespace OnixSourcePlugin
168168
virtual bool compareIndex(uint32_t index);
169169

170170
const std::string getName() { return name; }
171-
bool isEnabled() const { return enabled; }
172-
void setEnabled(bool newState) { enabled = newState; }
171+
virtual bool isEnabled() const { return enabled; }
172+
virtual void setEnabled(bool newState) { enabled = newState; }
173173
oni_dev_idx_t getDeviceIdx(bool getPassthroughIndex = false);
174174

175175
/** Creates a stream name using the provided inputs, returning a string following the pattern: name[0]-name[1]-name[2]-etc., with all spaces removed */
@@ -187,7 +187,6 @@ namespace OnixSourcePlugin
187187
void setHubName(std::string hubName) { m_hubName = hubName; }
188188

189189
static int getPortOffset(PortName port);
190-
static std::string getPortName(int offset);
191190
static std::string getPortName(PortName port);
192191
static std::string getPortName(oni_dev_idx_t index);
193192
static PortName getPortFromIndex(oni_dev_idx_t index);
@@ -250,7 +249,9 @@ namespace OnixSourcePlugin
250249
CompositeDeviceType getCompositeDeviceType() const;
251250

252251
bool compareIndex(uint32_t index) override;
252+
bool isEnabled() const override;
253253
bool isEnabled(uint32_t index);
254+
void setEnabled(bool newState) override;
254255
void setEnabled(uint32_t index, bool newState);
255256
int configureDevice() override;
256257
bool updateSettings() override;

0 commit comments

Comments
 (0)