Skip to content

Commit 4ac8fe0

Browse files
authored
Merge pull request #26 from open-ephys-plugins/issue-23
Add enable/disable button to BNO055 interface
2 parents 488e1ef + b8d163d commit 4ac8fe0

13 files changed

+355
-361
lines changed

Source/Devices/Bno055.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ Bno055::~Bno055()
9393

9494
int Bno055::configureDevice()
9595
{
96-
oni_write_reg(ctx, deviceIdx, (uint32_t)Bno055Registers::ENABLE, (uint32_t)1);
96+
int result = oni_write_reg(ctx, deviceIdx, (uint32_t)Bno055Registers::ENABLE, isEnabled() ? (oni_reg_val_t)1 : (oni_reg_val_t)0);
9797

98-
return 0;
98+
if (result != ONI_ESUCCESS) LOGE(oni_error_str(result));
99+
100+
return result;
99101
}
100102

101103
int Bno055::updateSettings()

Source/Devices/Neuropixels_1.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ int Neuropixels_1::configureDevice()
303303

304304
// Enable device streaming
305305
const oni_reg_addr_t enable_device_stream = 0x8000;
306-
errorCode = oni_write_reg(ctx, deviceIdx, enable_device_stream, 1);
306+
errorCode = oni_write_reg(ctx, deviceIdx, enable_device_stream, isEnabled() ? (oni_reg_val_t)1 : (oni_reg_val_t)0);
307307

308308
if (errorCode) { LOGE(oni_error_str(errorCode)); return -2; }
309309

Source/OnixSource.cpp

+4-11
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ void OnixSource::initializeDevices(bool updateStreamInfo)
8787
}
8888
oni_set_opt(ctx, ONIX_OPT_PASSTHROUGH, &val, sizeof(val));
8989

90-
val = 1;
91-
oni_set_opt(ctx, ONI_OPT_RESET, &val, sizeof(val));
90+
context.issueReset();
9291

9392
// Examine device table
9493
size_t num_devs_sz = sizeof(num_devs);
@@ -138,7 +137,6 @@ void OnixSource::initializeDevices(bool updateStreamInfo)
138137
static const String probeLetters = "ABCDEFGHI";
139138
const int bufferSizeInSeconds = 10;
140139
int npxProbeIdx = 0;
141-
int bnoIdx = 0;
142140

143141
for (size_t dev_idx = 0; dev_idx < num_devs; dev_idx++)
144142
{
@@ -176,7 +174,7 @@ void OnixSource::initializeDevices(bool updateStreamInfo)
176174
}
177175
else if (devices[dev_idx].id == ONIX_BNO055)
178176
{
179-
auto bno = std::make_unique<Bno055>("BNO-" + String::charToString(probeLetters[bnoIdx]), devices[dev_idx].idx, ctx);
177+
auto bno = std::make_unique<Bno055>("BNO055", devices[dev_idx].idx, ctx);
180178

181179
int result = bno->configureDevice();
182180

@@ -189,8 +187,6 @@ void OnixSource::initializeDevices(bool updateStreamInfo)
189187
bno->addSourceBuffers(sourceBuffers);
190188

191189
sources.add(bno.release());
192-
193-
bnoIdx++;
194190
}
195191
else if (devices[dev_idx].id == ONIX_DS90UB9RAW)
196192
{
@@ -225,8 +221,7 @@ void OnixSource::initializeDevices(bool updateStreamInfo)
225221
}
226222
}
227223

228-
val = 1;
229-
oni_set_opt(ctx, ONI_OPT_RESET, &val, sizeof(val));
224+
context.issueReset();
230225

231226
oni_size_t frame_size = 0;
232227
size_t frame_size_sz = sizeof(frame_size);
@@ -490,9 +485,7 @@ bool OnixSource::stopAcquisition()
490485
return false;
491486
}
492487

493-
uint32_t val = 1;
494-
oni_set_opt(context.get(), ONI_OPT_RESET, &val, sizeof(val));
495-
oni_set_opt(context.get(), ONI_OPT_BLOCKREADSIZE, &block_read_size, sizeof(block_read_size));
488+
context.issueReset();
496489
}
497490

498491
for (auto source : sources)

Source/OnixSource.h

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ class Onix1
6363

6464
oni_ctx get() const { return ctx; }
6565

66+
int issueReset() const
67+
{
68+
int val = 1;
69+
return oni_set_opt(ctx, ONI_OPT_RESET, &val, sizeof(val));
70+
}
71+
6672
private:
6773

6874
/** The ONI context object */
@@ -123,6 +129,8 @@ class OnixSource : public DataThread
123129

124130
void initializeContext();
125131

132+
int resetContext() { return context.issueReset(); }
133+
126134
void initializeDevices(bool updateStreamInfo = false);
127135

128136
void disconnectDevices(bool updateStreamInfo = false);

Source/OnixSourceCanvas.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ void OnixSourceCanvas::resized()
183183
topLevelTabComponent->setBounds(0, -3, getWidth(), getHeight() + 3);
184184
}
185185

186+
int OnixSourceCanvas::resetContext()
187+
{
188+
return onixSource->resetContext();
189+
}
190+
186191
void OnixSourceCanvas::startAcquisition()
187192
{
188193
for (auto settingsInterface : settingsInterfaces)

Source/OnixSourceCanvas.h

+2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class OnixSourceCanvas : public Visualizer
137137

138138
OwnedArray<SettingsInterface> settingsInterfaces;
139139

140+
int resetContext();
141+
140142
private:
141143

142144
Array<OnixDevice*> dataSources;

Source/PortController.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ bool PortController::setVoltage(oni_ctx ctx, float voltage) const
8585
sleep_for(std::chrono::milliseconds(500));
8686

8787
auto val = 1;
88-
ONI_OK_RETURN_BOOL(oni_set_opt(ctx, ONI_OPT_RESET, &val, sizeof(val)));
88+
oni_set_opt(ctx, ONI_OPT_RESET, &val, sizeof(val));
8989

9090
sleep_for(std::chrono::milliseconds(200));
9191

Source/UI/Bno055Interface.cpp

+28-7
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,44 @@
2424
#include "Bno055Interface.h"
2525

2626
Bno055Interface::Bno055Interface(OnixDevice* d, OnixSourceEditor* e, OnixSourceCanvas* c) :
27-
SettingsInterface(d, e,c),
27+
SettingsInterface(d, e, c),
2828
device((Bno055*)d)
2929
{
3030
if (device != nullptr)
3131
{
32-
// TODO: Show something in the canvas that indicates the device is connected
32+
deviceEnableButton = std::make_unique<UtilityButton>("ENABLED");
33+
deviceEnableButton->setFont(FontOptions("Fira Code", "Regular", 12.0f));
34+
deviceEnableButton->setRadius(3.0f);
35+
deviceEnableButton->setBounds(35, 35, 100, 22);
36+
deviceEnableButton->setClickingTogglesState(true);
37+
deviceEnableButton->setToggleState(device->isEnabled(), dontSendNotification);
38+
deviceEnableButton->setTooltip("If disabled, BNO055 device will not stream data during acquisition");
39+
deviceEnableButton->addListener(this);
40+
addAndMakeVisible(deviceEnableButton.get());
3341
}
3442

3543
type = SettingsInterface::Type::BNO055_SETTINGS_INTERFACE;
3644
}
3745

38-
Bno055Interface::~Bno055Interface()
46+
void Bno055Interface::buttonClicked(Button* button)
3947
{
48+
if (button == deviceEnableButton.get())
49+
{
50+
device->setEnabled(deviceEnableButton->getToggleState());
51+
device->enableDevice();
52+
canvas->resetContext();
53+
54+
if (device->isEnabled())
55+
{
56+
deviceEnableButton->setLabel("ENABLED");
57+
}
58+
else
59+
{
60+
deviceEnableButton->setLabel("DISABLED");
61+
}
62+
63+
CoreServices::updateSignalChain(editor);
64+
}
4065
}
4166

4267
void Bno055Interface::startAcquisition()
@@ -54,7 +79,3 @@ void Bno055Interface::saveParameters(XmlElement* xml)
5479
void Bno055Interface::loadParameters(XmlElement* xml)
5580
{
5681
}
57-
58-
void Bno055Interface::updateInfoString()
59-
{
60-
}

Source/UI/Bno055Interface.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@
3131

3232
#include "../Devices/Bno055.h"
3333

34-
class Bno055Interface : public SettingsInterface
34+
class Bno055Interface : public SettingsInterface,
35+
public Button::Listener
3536
{
3637
public:
3738
/** Constructor */
3839
Bno055Interface(OnixDevice* d, OnixSourceEditor* e, OnixSourceCanvas* c);
3940

40-
/** Destructor */
41-
~Bno055Interface();
42-
4341
/** Disables buttons and starts animation if necessary */
4442
void startAcquisition() override;
4543

@@ -53,12 +51,16 @@ class Bno055Interface : public SettingsInterface
5351
void loadParameters(XmlElement* xml) override;
5452

5553
/** Updates the info string on the right-hand side of the component */
56-
void updateInfoString() override;
54+
void updateInfoString() override {};
5755

58-
Bno055* device;
56+
/** Listener methods*/
57+
void buttonClicked(Button*) override;
5958

6059
private:
6160

61+
Bno055* device;
62+
63+
std::unique_ptr<UtilityButton> deviceEnableButton;
6264
};
6365

6466
#endif // !__BNO055INTERFACE_H__

0 commit comments

Comments
 (0)