Skip to content

Commit b339d54

Browse files
committed
Force hardware reconnect when communication lock is lost
1 parent 9bbfae1 commit b339d54

File tree

3 files changed

+89
-41
lines changed

3 files changed

+89
-41
lines changed

Source/OnixSource.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,6 @@ void OnixSource::setPortVoltage(PortName port, float voltage) const
314314
{
315315
if (!context.isInitialized()) return;
316316

317-
oni_ctx ctx = context.get();
318-
319317
switch (port)
320318
{
321319
case PortName::PortA:
@@ -514,6 +512,23 @@ bool OnixSource::stopAcquisition()
514512
oni_set_opt(context.get(), ONI_OPT_BLOCKREADSIZE, &block_read_size, sizeof(block_read_size));
515513
}
516514

515+
if (portA->getErrorFlag() || portB->getErrorFlag())
516+
{
517+
if (portA->getErrorFlag())
518+
{
519+
LOGE("Port A lost communication lock. Reconnect hardware to continue.");
520+
CoreServices::sendStatusMessage("Port A lost communication lock");
521+
}
522+
523+
if (portB->getErrorFlag())
524+
{
525+
LOGE("Port B lost communication lock. Reconnect hardware to continue.");
526+
CoreServices::sendStatusMessage("Port B lost communication lock");
527+
}
528+
529+
editor->updateConnectedStatus(false);
530+
}
531+
517532
for (auto source : sources)
518533
{
519534
if (!source->isEnabled()) continue;

Source/OnixSourceEditor.cpp

Lines changed: 70 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -111,67 +111,98 @@ OnixSourceEditor::OnixSourceEditor(GenericProcessor* parentNode, OnixSource* oni
111111

112112
void OnixSourceEditor::labelTextChanged(Label* l)
113113
{
114+
// TODO: Add headstage specific parameters to limit voltage within safe levels
114115
if (l == portVoltageValueA.get())
115116
{
117+
float input = l->getText().getFloatValue();
118+
119+
if (input < 0.0f)
120+
{
121+
l->setText("0.0", dontSendNotification);
122+
}
123+
else if (input > 7.0f)
124+
{
125+
l->setText("7.0", dontSendNotification);
126+
}
127+
}
128+
else if (l == portVoltageValueB.get())
129+
{
130+
float input = l->getText().getFloatValue();
131+
132+
if (input < 0.0f)
133+
{
134+
l->setText("0.0", dontSendNotification);
135+
}
136+
else if (input > 7.0f)
137+
{
138+
l->setText("7.0", dontSendNotification);
139+
}
116140
}
117141
}
118142

119143
void OnixSourceEditor::buttonClicked(Button* b)
120144
{
121145
if (b == connectButton.get())
122146
{
123-
if (connectButton->getToggleState() == true)
147+
updateConnectedStatus(connectButton->getToggleState());
148+
}
149+
}
150+
151+
void OnixSourceEditor::updateConnectedStatus(bool connected)
152+
{
153+
connectButton->setToggleState(connected, dontSendNotification);
154+
155+
if (connected)
156+
{
157+
// NB: Configure port voltages, using either the automated voltage discovery algorithm, or the explicit voltage value given
158+
if (isHeadstageSelected(PortName::PortA))
124159
{
125-
// NB: Configure port voltages, using either the automated voltage discovery algorithm, or the explicit voltage value given
126-
if (isHeadstageSelected(PortName::PortA))
127-
{
128-
if (!thread->configurePortVoltage(PortName::PortA, portVoltageValueA->getText()))
129-
{
130-
CoreServices::sendStatusMessage("Unable to acquire communication lock on Port A.");
131-
connectButton->setToggleState(false, true);
132-
return;
133-
}
134-
}
135-
else
160+
if (!thread->configurePortVoltage(PortName::PortA, portVoltageValueA->getText()))
136161
{
137-
thread->setPortVoltage(PortName::PortA, 0);
162+
CoreServices::sendStatusMessage("Unable to acquire communication lock on Port A.");
163+
connectButton->setToggleState(false, dontSendNotification);
164+
return;
138165
}
139-
140-
if (isHeadstageSelected(PortName::PortB))
141-
{
142-
if (!thread->configurePortVoltage(PortName::PortB, portVoltageValueB->getText()))
143-
{
144-
CoreServices::sendStatusMessage("Unable to acquire communication lock on Port B.");
145-
connectButton->setToggleState(false, true);
146-
return;
147-
}
148-
}
149-
else
150-
{
151-
thread->setPortVoltage(PortName::PortB, 0);
152-
}
153-
154-
thread->initializeDevices(true);
155-
canvas->refreshTabs();
156-
157-
connectButton->setLabel("DISCONNECT");
166+
}
167+
else
168+
{
169+
thread->setPortVoltage(PortName::PortA, 0);
170+
}
158171

159-
if (!thread->foundInputSource())
172+
if (isHeadstageSelected(PortName::PortB))
173+
{
174+
if (!thread->configurePortVoltage(PortName::PortB, portVoltageValueB->getText()))
160175
{
161-
CoreServices::sendStatusMessage("No Onix hardware found.");
162-
connectButton->setToggleState(false, true);
176+
CoreServices::sendStatusMessage("Unable to acquire communication lock on Port B.");
177+
connectButton->setToggleState(false, dontSendNotification);
178+
return;
163179
}
164180
}
165181
else
166182
{
167-
thread->setPortVoltage(PortName::PortA, 0);
168183
thread->setPortVoltage(PortName::PortB, 0);
184+
}
185+
186+
thread->initializeDevices(true);
187+
canvas->refreshTabs();
169188

170-
canvas->removeTabs();
171-
thread->disconnectDevices(true);
172-
connectButton->setLabel("CONNECT");
189+
connectButton->setLabel("DISCONNECT");
190+
191+
if (!thread->foundInputSource())
192+
{
193+
CoreServices::sendStatusMessage("No Onix hardware found.");
194+
connectButton->setToggleState(false, sendNotification);
173195
}
174196
}
197+
else
198+
{
199+
thread->setPortVoltage(PortName::PortA, 0);
200+
thread->setPortVoltage(PortName::PortB, 0);
201+
202+
canvas->removeTabs();
203+
thread->disconnectDevices(true);
204+
connectButton->setLabel("CONNECT");
205+
}
175206
}
176207

177208
void OnixSourceEditor::comboBoxChanged(ComboBox* cb)

Source/OnixSourceEditor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class OnixSourceEditor : public VisualizerEditor,
7676

7777
bool isHeadstageSelected(PortName port);
7878

79+
void updateConnectedStatus(bool);
80+
7981
OnixSourceCanvas* canvas;
8082

8183
private:

0 commit comments

Comments
 (0)