Skip to content

Commit cf72e28

Browse files
committed
[WIP] Initial setup to add support for Neuropixels 1.0
1 parent c9894d7 commit cf72e28

File tree

7 files changed

+312
-139
lines changed

7 files changed

+312
-139
lines changed

Source/Devices/Neuropixels_1.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
------------------------------------------------------------------
3+
4+
This file is part of the Open Ephys GUI
5+
Copyright (C) 2020 Allen Institute for Brain Science and Open Ephys
6+
7+
------------------------------------------------------------------
8+
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+
*/
23+
#include "Neuropixels_1.h"
24+
#include <oni.h>
25+
#include <onix.h>
26+
27+
Neuropixels_1::Neuropixels_1(String name)
28+
: OnixDevice(name, NEUROPIXELS_1)
29+
{
30+
StreamInfo apStream;
31+
apStream.name = name + "-AP";
32+
apStream.description = "Neuropixels 1.0 AP band data stream";
33+
apStream.identifier = "onix-neuropixels1.data.ap";
34+
apStream.numChannels = 384;
35+
apStream.sampleRate = 30000.0f;
36+
apStream.channelPrefix = "AP";
37+
apStream.bitVolts = 0.195f;
38+
apStream.channelType = ContinuousChannel::Type::ELECTRODE;
39+
streams.add(apStream);
40+
41+
StreamInfo lfpStream;
42+
lfpStream.name = name + "-LFP";
43+
lfpStream.description = "Neuropixels 1.0 LFP band data stream";
44+
lfpStream.identifier = "onix-neuropixels1.data.lfp";
45+
lfpStream.numChannels = 384;
46+
lfpStream.sampleRate = 2500.0f;
47+
lfpStream.channelPrefix = "LFP";
48+
lfpStream.bitVolts = 0.195f;
49+
lfpStream.channelType = ContinuousChannel::Type::ELECTRODE;
50+
streams.add(lfpStream);
51+
}
52+
53+
54+
Neuropixels_1::~Neuropixels_1()
55+
{
56+
57+
}
58+
59+
60+
void Neuropixels_1::addFrame()
61+
{
62+
63+
}

Source/Devices/Neuropixels_1.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
------------------------------------------------------------------
3+
4+
This file is part of the Open Ephys GUI
5+
Copyright (C) 2020 Allen Institute for Brain Science and Open Ephys
6+
7+
------------------------------------------------------------------
8+
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+
*/
23+
24+
#ifndef NEUROPIXELS1_H_DEFINED
25+
#define NEUROPIXELS1_H_DEFINED
26+
27+
#include "../OnixDevice.h"
28+
29+
#include <ctime>
30+
#include <chrono>
31+
32+
enum NeuropixelsRegisters
33+
{
34+
OP_MODE = 0x00,
35+
REC_MOD = 0x01,
36+
CAL_MOD = 0x02
37+
};
38+
39+
/**
40+
41+
Streams data from an ONIX device
42+
43+
*/
44+
class Neuropixels_1 : public OnixDevice
45+
{
46+
public:
47+
48+
/** Constructor */
49+
Neuropixels_1(String name);
50+
51+
/** Destructor */
52+
~Neuropixels_1();
53+
54+
DataBuffer* apBuffer = deviceBuffer;
55+
DataBuffer* lfpBuffer;
56+
57+
void addFrame() override;
58+
59+
private:
60+
61+
float samples[384 * MAX_SAMPLES_PER_BUFFER];
62+
int64 sampleNumbers[MAX_SAMPLES_PER_BUFFER];
63+
double timestamps[MAX_SAMPLES_PER_BUFFER];
64+
uint64 event_codes[MAX_SAMPLES_PER_BUFFER];
65+
66+
};
67+
68+
69+
#endif

Source/OnixDevice.cpp

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,59 +23,17 @@
2323

2424
#include "OnixDevice.h"
2525

26-
OnixDevice::OnixDevice(String name, int channels_, float sampleRate_, OnixDeviceType type_)
27-
: Thread(name), numChannels(channels_), sampleRate(sampleRate_), type(type_)
26+
OnixDevice::OnixDevice(String name, OnixDeviceType type_)
27+
: Thread(name), type(type_)
2828
{
29-
29+
3030
}
3131

3232

3333
void OnixDevice::run()
3434
{
35-
36-
int64 sampleNumber = 0;
37-
int64 uSecPerBuffer = samplesPerBuffer / sampleRate * 1e6;
38-
eventCode = 0;
39-
40-
int64 start = Time::getHighResolutionTicks();
41-
int64 bufferCount = 0;
42-
4335
while (!threadShouldExit())
4436
{
4537

46-
bufferCount++;
47-
48-
// grab available data and add to buffer
49-
50-
/*for (int sample_num = 0; sample_num < samplesPerBuffer; sample_num++)
51-
{
52-
53-
for (int i = 0; i < numChannels; i++)
54-
{
55-
samples[i + sample_num * numChannels] = (*data)[sampleNumber % availableSamples];
56-
}
57-
58-
sampleNumbers[sample_num] = sampleNumber++;
59-
timestamps[sample_num] = -1.0;
60-
61-
if (sampleNumber % int(sampleRate) == 0)
62-
{
63-
if (eventCode == 0)
64-
eventCode = 1;
65-
else
66-
eventCode = 0;
67-
}
68-
69-
event_codes[sample_num] = eventCode;
70-
}
71-
72-
buffer->addToBuffer(samples, sampleNumbers, timestamps, event_codes, samplesPerBuffer);
73-
74-
int64 uSecElapsed = int64(Time::highResolutionTicksToSeconds(Time::getHighResolutionTicks() - start) * 1e6);
75-
76-
if (uSecElapsed < (uSecPerBuffer * bufferCount))
77-
{
78-
std::this_thread::sleep_for(std::chrono::microseconds((uSecPerBuffer * bufferCount) - uSecElapsed));
79-
}*/
8038
}
8139
}

Source/OnixDevice.h

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
2222
*/
2323

24-
#ifndef SIMULATEDSOURCE_H_DEFINED
25-
#define SIMULATEDSOURCE_H_DEFINED
24+
#ifndef __OnixDevice_H__
25+
#define __OnixDevice_H__
2626

2727
#include <DataThreadHeaders.h>
2828

@@ -45,6 +45,17 @@ enum OnixDeviceType {
4545
ADC
4646
};
4747

48+
struct StreamInfo {
49+
String name;
50+
String description;
51+
String identifier;
52+
int numChannels;
53+
float sampleRate;
54+
String channelPrefix;
55+
ContinuousChannel::Type channelType;
56+
float bitVolts;
57+
};
58+
4859
/**
4960
5061
Streams data from an ONIX device
@@ -55,35 +66,40 @@ class OnixDevice : public Thread
5566
public:
5667

5768
/** Constructor */
58-
OnixDevice(String name, int channels, float sampleRate, OnixDeviceType type);
69+
OnixDevice(String name, OnixDeviceType type);
5970

6071
/** Destructor */
6172
~OnixDevice() { }
6273

74+
virtual void addFrame() = 0;
75+
76+
const String getName() { return name; }
77+
78+
OnixDeviceType type;
79+
6380
/** Holds incoming data */
64-
DataBuffer* buffer;
81+
DataBuffer* deviceBuffer;
82+
83+
Array<StreamInfo> streams;
6584

6685
private:
6786

6887
/** Updates buffer during acquisition */
6988
void run() override;
7089

71-
OnixDeviceType type;
72-
7390
std::vector<float>* data;
7491
int availableSamples;
7592
int samplesPerBuffer;
7693

77-
int numChannels;
78-
int packetSize;
79-
float sampleRate;
8094
int64 numSamples;
8195
uint64 eventCode;
8296

83-
float samples[384 * MAX_SAMPLES_PER_BUFFER];
84-
int64 sampleNumbers[MAX_SAMPLES_PER_BUFFER];
85-
double timestamps[MAX_SAMPLES_PER_BUFFER];
86-
uint64 event_codes[MAX_SAMPLES_PER_BUFFER];
97+
String name;
98+
99+
// float samples[384 * MAX_SAMPLES_PER_BUFFER];
100+
// int64 sampleNumbers[MAX_SAMPLES_PER_BUFFER];
101+
// double timestamps[MAX_SAMPLES_PER_BUFFER];
102+
// uint64 event_codes[MAX_SAMPLES_PER_BUFFER];
87103

88104
};
89105

0 commit comments

Comments
 (0)