Skip to content
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
2 changes: 1 addition & 1 deletion Source/Devices/AnalogIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void AnalogIO::processFrames()

currentAverageFrame = 0;

timestamps[currentFrame] = frame->time;
timestamps[currentFrame] = deviceContext->convertTimestampToSeconds(frame->time);
sampleNumbers[currentFrame] = sampleNumber++;

currentFrame++;
Expand Down
39 changes: 26 additions & 13 deletions Source/Devices/AnalogIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ class AnalogIO : public OnixDevice
return channelDirection[channelNumber];
}

static String getChannelDirection(AnalogIODirection direction)
{
switch (direction)
{
case AnalogIODirection::Input:
return "Input";
case AnalogIODirection::Output:
return "Output";
default:
return "";
}
}

void setChannelDirection(int channelNumber, AnalogIODirection direction)
{
if (channelNumber > numChannels || channelNumber < 0)
Expand All @@ -121,21 +134,8 @@ class AnalogIO : public OnixDevice
return channelVoltageRange[channelNumber];
}

void setChannelVoltageRange(int channelNumber, AnalogIOVoltageRange direction)
{
if (channelNumber > numChannels || channelNumber < 0)
{
LOGE("Channel number must be between 0 and " + String(channelNumber));
return;
}

channelVoltageRange[channelNumber] = direction;
}

AnalogIODataType getDataType() const { return dataType; }

void setDataType(AnalogIODataType type) { dataType = type; }

int getNumChannels() { return numChannels; }

private:
Expand Down Expand Up @@ -174,5 +174,18 @@ class AnalogIO : public OnixDevice

static float getVoltsPerDivision(AnalogIOVoltageRange voltageRange);

void setChannelVoltageRange(int channelNumber, AnalogIOVoltageRange direction)
{
if (channelNumber > numChannels || channelNumber < 0)
{
LOGE("Channel number must be between 0 and " + String(channelNumber));
return;
}

channelVoltageRange[channelNumber] = direction;
}

void setDataType(AnalogIODataType type) { dataType = type; }

JUCE_LEAK_DETECTOR(AnalogIO);
};
2 changes: 1 addition & 1 deletion Source/Devices/Bno055.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void Bno055::processFrames()

int16_t* dataPtr = (int16_t*)frame->data;

bnoTimestamps[currentFrame] = frame->time;
bnoTimestamps[currentFrame] = deviceContext->convertTimestampToSeconds(frame->time);

int dataOffset = 4;

Expand Down
2 changes: 1 addition & 1 deletion Source/Devices/DigitalIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void DigitalIO::processFrames()
oni_frame_t* frame = frameArray.removeAndReturn(0);

uint16_t* dataPtr = (uint16_t*)frame->data;
uint64_t timestamp = frame->time;
uint64_t timestamp = deviceContext->convertTimestampToSeconds(frame->time);

int dataOffset = 4;

Expand Down
2 changes: 1 addition & 1 deletion Source/Devices/HarpSyncInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void HarpSyncInput::processFrames()

uint32_t* dataPtr = (uint32_t*)frame->data;

timestamps[currentFrame] = frame->time;
timestamps[currentFrame] = deviceContext->convertTimestampToSeconds(frame->time);

harpTimeSamples[currentFrame] = *(dataPtr + 2) + 1;

Expand Down
3 changes: 1 addition & 2 deletions Source/Devices/MemoryMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ void MemoryMonitor::processFrames()
oni_frame_t* frame = frameArray.removeAndReturn(0);

uint32_t* dataPtr = (uint32_t*)frame->data;
uint64_t timestamp = frame->time;

timestamps[currentFrame] = frame->time;
timestamps[currentFrame] = deviceContext->convertTimestampToSeconds(frame->time);

percentUsedSamples[currentFrame] = 100.0f * float(*(dataPtr + 2)) / totalMemory;

Expand Down
2 changes: 1 addition & 1 deletion Source/Devices/Neuropixels2e.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ void Neuropixels2e::processFrames()
uint16_t* amplifierData = dataPtr + 9;

sampleNumbers[frameCount] = sampleNumber;
timestamps[frameCount] = frame->time;
timestamps[frameCount] = deviceContext->convertTimestampToSeconds(frame->time);

for (int i = 0; i < FramesPerSuperFrame; i++)
{
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 @@ -472,7 +472,7 @@ void Neuropixels_1::processFrames()

uint16_t* dataPtr = (uint16_t*)frame->data;

apTimestamps[superFrameCount] = frame->time;
apTimestamps[superFrameCount] = deviceContext->convertTimestampToSeconds(frame->time);
apSampleNumbers[superFrameCount] = apSampleNumber++;

for (int i = 0; i < framesPerSuperFrame; i++)
Expand Down
16 changes: 8 additions & 8 deletions Source/Devices/OutputClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ class OutputClock : public OnixDevice

void processFrames() override {};

float getFrequencyHz() const { return frequencyHz; }
double getFrequencyHz() const { return frequencyHz; }

void setFrequencyHz(float frequency) { frequencyHz = frequency; }
void setFrequencyHz(double frequency) { frequencyHz = frequency; }

uint32_t getDutyCycle() const { return dutyCycle; }
int32_t getDutyCycle() const { return dutyCycle; }

void setDutyCycle(uint32_t dutyCycle_) { dutyCycle = dutyCycle_; }
void setDutyCycle(int32_t dutyCycle_) { dutyCycle = dutyCycle_; }

uint32_t getDelay() const { return delay; }
int32_t getDelay() const { return delay; }

void setDelay(uint32_t delay_) { delay = delay_; }
void setDelay(int32_t delay_) { delay = delay_; }

bool getGateRun() const { return gateRun; }

Expand All @@ -85,8 +85,8 @@ class OutputClock : public OnixDevice
private:

double frequencyHz = 1e6;
uint32_t dutyCycle = 50;
uint32_t delay = 0;
int32_t dutyCycle = 50;
int32_t delay = 0;

bool gateRun = true;

Expand Down
2 changes: 1 addition & 1 deletion Source/Devices/PolledBno055.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void PolledBno055::hiResTimerCallback()
rc = (uint64_t)deviceContext->readRegister(deviceIdx, DS90UB9x::LASTI2CH, &timestampH);
if (rc != ONI_ESUCCESS) return;

bnoTimestamps[currentFrame] = (uint64_t(timestampH) << 32) | uint64_t(timestampL);
bnoTimestamps[currentFrame] = deviceContext->convertTimestampToSeconds((uint64_t(timestampH) << 32) | uint64_t(timestampL));

sampleNumbers[currentFrame] = sampleNumber++;

Expand Down
4 changes: 4 additions & 0 deletions Source/Onix1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Onix1::Onix1(int hostIndex)
throw error_t(rc);

oni_version(&major, &minor, &patch);

rc = getOption(ONI_OPT_ACQCLKHZ, &ACQ_CLK_HZ);
if (rc != ONI_ESUCCESS)
throw error_t(rc);
}

Onix1::~Onix1()
Expand Down
6 changes: 5 additions & 1 deletion Source/Onix1.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class Onix1

int issueReset() { int val = 1; int rc = setOption(ONI_OPT_RESET, val); return rc; }

String getVersion() { return String(major) + "." + String(minor) + "." + String(patch); }
std::string getVersion() const { return std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch); }

double convertTimestampToSeconds(uint32_t timestamp) const { return static_cast<double>(timestamp) / ACQ_CLK_HZ; }

private:

Expand All @@ -99,6 +101,8 @@ class Onix1
int minor;
int patch;

uint32_t ACQ_CLK_HZ;

device_map_t deviceTable;

template<typename opt_t>
Expand Down
47 changes: 24 additions & 23 deletions Source/OnixSourceCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ void OnixSourceCanvas::updateSettingsInterfaceDataSource(std::shared_ptr<OnixDev

for (int j = 0; j < settingsInterfaces.size(); j++)
{
if (device->getDeviceIdx() == settingsInterfaces[j]->device->getDeviceIdx() &&
compareDeviceNames(device->getName(), settingsInterfaces[j]->device->getName()))
auto selectedDevice = settingsInterfaces[j]->getDevice();

if (device->getDeviceIdx() == selectedDevice->getDeviceIdx() &&
compareDeviceNames(device->getName(), selectedDevice->getName()))
{
ind = j;
break;
Expand All @@ -174,10 +176,12 @@ void OnixSourceCanvas::updateSettingsInterfaceDataSource(std::shared_ptr<OnixDev
return;
}

auto selectedDevice = settingsInterfaces[ind]->getDevice();

if (device->type == OnixDeviceType::NEUROPIXELS_1)
{
auto npx1Found = std::static_pointer_cast<Neuropixels_1>(device);
auto npx1Selected = std::static_pointer_cast<Neuropixels_1>(settingsInterfaces[ind]->device);
auto npx1Selected = std::static_pointer_cast<Neuropixels_1>(selectedDevice);
npx1Found->setSettings(npx1Selected->settings[0].get());
npx1Found->adcCalibrationFilePath = npx1Selected->adcCalibrationFilePath;
npx1Found->gainCalibrationFilePath = npx1Selected->gainCalibrationFilePath;
Expand All @@ -186,7 +190,7 @@ void OnixSourceCanvas::updateSettingsInterfaceDataSource(std::shared_ptr<OnixDev
else if (device->type == OnixDeviceType::OUTPUTCLOCK)
{
auto outputClockFound = std::static_pointer_cast<OutputClock>(device);
auto outputClockSelected = std::static_pointer_cast<OutputClock>(settingsInterfaces[ind]->device);
auto outputClockSelected = std::static_pointer_cast<OutputClock>(selectedDevice);
outputClockFound->setDelay(outputClockSelected->getDelay());
outputClockFound->setDutyCycle(outputClockSelected->getDutyCycle());
outputClockFound->setFrequencyHz(outputClockSelected->getFrequencyHz());
Expand All @@ -195,7 +199,7 @@ void OnixSourceCanvas::updateSettingsInterfaceDataSource(std::shared_ptr<OnixDev
else if (device->type == OnixDeviceType::ANALOGIO)
{
auto analogIOFound = std::static_pointer_cast<AnalogIO>(device);
auto analogIOSelected = std::static_pointer_cast<AnalogIO>(settingsInterfaces[ind]->device);
auto analogIOSelected = std::static_pointer_cast<AnalogIO>(selectedDevice);
for (int i = 0; i < analogIOFound->getNumChannels(); i++)
{
analogIOFound->setChannelDirection(i, analogIOSelected->getChannelDirection(i));
Expand All @@ -204,7 +208,7 @@ void OnixSourceCanvas::updateSettingsInterfaceDataSource(std::shared_ptr<OnixDev
else if (device->type == OnixDeviceType::NEUROPIXELSV2E)
{
auto npx2Found = std::static_pointer_cast<Neuropixels2e>(device);
auto npx2Selected = std::static_pointer_cast<Neuropixels2e>(settingsInterfaces[ind]->device);
auto npx2Selected = std::static_pointer_cast<Neuropixels2e>(selectedDevice);
npx2Found->setSettings(npx2Selected->settings[0].get(), 0);
npx2Found->setSettings(npx2Selected->settings[1].get(), 1);
npx2Found->setGainCorrectionFile(0, npx2Selected->getGainCorrectionFile(0));
Expand All @@ -213,9 +217,8 @@ void OnixSourceCanvas::updateSettingsInterfaceDataSource(std::shared_ptr<OnixDev
std::static_pointer_cast<NeuropixelsV2eInterface>(settingsInterfaces[ind])->updateDevice(npx2Found);
}

device->setEnabled(settingsInterfaces[ind]->device->isEnabled());
settingsInterfaces[ind]->device.reset();
settingsInterfaces[ind]->device = device;
device->setEnabled(selectedDevice->isEnabled());
settingsInterfaces[ind]->setDevice(device);
}

String OnixSourceCanvas::getTopLevelTabName(PortName port, String headstage)
Expand Down Expand Up @@ -263,7 +266,9 @@ void OnixSourceCanvas::removeTabs(PortName port)

for (int i = settingsInterfaces.size() - 1; i >= 0; i -= 1)
{
if ((settingsInterfaces[i]->device->getDeviceIdx() & offset) > 0)
auto selectedDevice = settingsInterfaces[i]->getDevice();

if ((selectedDevice->getDeviceIdx() & offset) > 0)
{
settingsInterfaces.erase(settingsInterfaces.begin() + i);
tabExists = true;
Expand Down Expand Up @@ -293,7 +298,9 @@ std::map<int, OnixDeviceType> OnixSourceCanvas::createSelectedMap(std::vector<st

for (const auto& settings : interfaces)
{
tabMap.insert({ settings->device->getDeviceIdx(), settings->device->type });
auto device = settings->getDevice();

tabMap.insert({ device->getDeviceIdx(), device->type });
}

return tabMap;
Expand Down Expand Up @@ -512,32 +519,26 @@ void OnixSourceCanvas::startAcquisition()
{
for (const auto& settingsInterface : settingsInterfaces)
{
if (settingsInterface->device != nullptr && settingsInterface->device->isEnabled())
{
settingsInterface->startAcquisition();
}
settingsInterface->startAcquisition();
}
}

void OnixSourceCanvas::stopAcquisition()
{
for (const auto& settingsInterface : settingsInterfaces)
{
if (settingsInterface->device != nullptr && settingsInterface->device->isEnabled())
{
settingsInterface->stopAcquisition();
}
settingsInterface->stopAcquisition();
}
}

void OnixSourceCanvas::saveCustomParametersToXml(XmlElement* xml)
{
//for (int i = 0; i < settingsInterfaces.size(); i++)
// settingsInterfaces[i]->saveParameters(xml);
for (int i = 0; i < settingsInterfaces.size(); i++)
settingsInterfaces[i]->saveParameters(xml);
}

void OnixSourceCanvas::loadCustomParametersFromXml(XmlElement* xml)
{
//for (int i = 0; i < settingsInterfaces.size(); i++)
// settingsInterfaces[i]->loadParameters(xml);
for (int i = 0; i < settingsInterfaces.size(); i++)
settingsInterfaces[i]->loadParameters(xml);
}
Loading