Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enable/disable button to BNO055 interface #26

Merged
merged 3 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Source/Devices/Bno055.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ Bno055::~Bno055()

int Bno055::enableDevice()
{
oni_write_reg(ctx, deviceIdx, (uint32_t)Bno055Registers::ENABLE, (uint32_t)1);
int result = oni_write_reg(ctx, deviceIdx, (uint32_t)Bno055Registers::ENABLE, isEnabled() ? (oni_reg_val_t)1 : (oni_reg_val_t)0);

return 0;
if (result != ONI_ESUCCESS) LOGE(oni_error_str(result));

return result;
}

int Bno055::updateSettings()
Expand Down
2 changes: 1 addition & 1 deletion Source/Devices/Neuropixels_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ int Neuropixels_1::enableDevice()

// Enable device streaming
const oni_reg_addr_t enable_device_stream = 0x8000;
errorCode = oni_write_reg(ctx, deviceIdx, enable_device_stream, 1);
errorCode = oni_write_reg(ctx, deviceIdx, enable_device_stream, isEnabled() ? (oni_reg_val_t)1 : (oni_reg_val_t)0);

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

Expand Down
15 changes: 4 additions & 11 deletions Source/OnixSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ void OnixSource::initializeDevices(bool updateStreamInfo)
}
oni_set_opt(ctx, ONIX_OPT_PASSTHROUGH, &val, sizeof(val));

val = 1;
oni_set_opt(ctx, ONI_OPT_RESET, &val, sizeof(val));
context.issueReset();

// Examine device table
size_t num_devs_sz = sizeof(num_devs);
Expand Down Expand Up @@ -138,7 +137,6 @@ void OnixSource::initializeDevices(bool updateStreamInfo)
static const String probeLetters = "ABCDEFGHI";
const int bufferSizeInSeconds = 10;
int npxProbeIdx = 0;
int bnoIdx = 0;

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

int result = bno->enableDevice();

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

sources.add(bno.release());

bnoIdx++;
}
else if (devices[dev_idx].id == ONIX_DS90UB9RAW)
{
Expand Down Expand Up @@ -225,8 +221,7 @@ void OnixSource::initializeDevices(bool updateStreamInfo)
}
}

val = 1;
oni_set_opt(ctx, ONI_OPT_RESET, &val, sizeof(val));
context.issueReset();

oni_size_t frame_size = 0;
size_t frame_size_sz = sizeof(frame_size);
Expand Down Expand Up @@ -490,9 +485,7 @@ bool OnixSource::stopAcquisition()
return false;
}

uint32_t val = 1;
oni_set_opt(context.get(), ONI_OPT_RESET, &val, sizeof(val));
oni_set_opt(context.get(), ONI_OPT_BLOCKREADSIZE, &block_read_size, sizeof(block_read_size));
context.issueReset();
}

for (auto source : sources)
Expand Down
8 changes: 8 additions & 0 deletions Source/OnixSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ class Onix1

oni_ctx get() const { return ctx; }

int issueReset() const
{
int val = 1;
return oni_set_opt(ctx, ONI_OPT_RESET, &val, sizeof(val));
}

private:

/** The ONI context object */
Expand Down Expand Up @@ -123,6 +129,8 @@ class OnixSource : public DataThread

void initializeContext();

int resetContext() { return context.issueReset(); }

void initializeDevices(bool updateStreamInfo = false);

void disconnectDevices(bool updateStreamInfo = false);
Expand Down
5 changes: 5 additions & 0 deletions Source/OnixSourceCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ void OnixSourceCanvas::resized()
topLevelTabComponent->setBounds(0, -3, getWidth(), getHeight() + 3);
}

int OnixSourceCanvas::resetContext()
{
return onixSource->resetContext();
}

void OnixSourceCanvas::startAcquisition()
{
for (auto settingsInterface : settingsInterfaces)
Expand Down
2 changes: 2 additions & 0 deletions Source/OnixSourceCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class OnixSourceCanvas : public Visualizer

OwnedArray<SettingsInterface> settingsInterfaces;

int resetContext();

private:

Array<OnixDevice*> dataSources;
Expand Down
2 changes: 1 addition & 1 deletion Source/PortController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool PortController::setVoltage(oni_ctx ctx, float voltage) const
sleep_for(std::chrono::milliseconds(500));

auto val = 1;
ONI_OK_RETURN_BOOL(oni_set_opt(ctx, ONI_OPT_RESET, &val, sizeof(val)));
oni_set_opt(ctx, ONI_OPT_RESET, &val, sizeof(val));

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

Expand Down
35 changes: 28 additions & 7 deletions Source/UI/Bno055Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,44 @@
#include "Bno055Interface.h"

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

type = SettingsInterface::Type::BNO055_SETTINGS_INTERFACE;
}

Bno055Interface::~Bno055Interface()
void Bno055Interface::buttonClicked(Button* button)
{
if (button == deviceEnableButton.get())
{
device->setEnabled(deviceEnableButton->getToggleState());
device->enableDevice();
canvas->resetContext();

if (device->isEnabled())
{
deviceEnableButton->setLabel("ENABLED");
}
else
{
deviceEnableButton->setLabel("DISABLED");
}

CoreServices::updateSignalChain(editor);
}
}

void Bno055Interface::startAcquisition()
Expand All @@ -54,7 +79,3 @@ void Bno055Interface::saveParameters(XmlElement* xml)
void Bno055Interface::loadParameters(XmlElement* xml)
{
}

void Bno055Interface::updateInfoString()
{
}
14 changes: 8 additions & 6 deletions Source/UI/Bno055Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@

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

class Bno055Interface : public SettingsInterface
class Bno055Interface : public SettingsInterface,
public Button::Listener
{
public:
/** Constructor */
Bno055Interface(OnixDevice* d, OnixSourceEditor* e, OnixSourceCanvas* c);

/** Destructor */
~Bno055Interface();

/** Disables buttons and starts animation if necessary */
void startAcquisition() override;

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

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

Bno055* device;
/** Listener methods*/
void buttonClicked(Button*) override;

private:

Bno055* device;

std::unique_ptr<UtilityButton> deviceEnableButton;
};

#endif // !__BNO055INTERFACE_H__
Loading