Skip to content

Commit f2fd173

Browse files
authored
Merge pull request #62 from open-ephys-plugins/issue-34
Finalize Milestone 1.0f and 2.0e
2 parents 4444259 + ec66d75 commit f2fd173

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4664
-4103
lines changed

Source/Devices/AnalogIO.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
#include "AnalogIO.h"
2424

25-
AnalogIO::AnalogIO(String name, const oni_dev_idx_t deviceIdx_, std::shared_ptr<Onix1> oni_ctx)
26-
: OnixDevice(name, BREAKOUT_BOARD_NAME, OnixDeviceType::ANALOGIO, deviceIdx_, oni_ctx)
25+
using namespace OnixSourcePlugin;
26+
27+
AnalogIO::AnalogIO(std::string name, std::string hubName, const oni_dev_idx_t deviceIdx_, std::shared_ptr<Onix1> oni_ctx)
28+
: OnixDevice(name, hubName, AnalogIO::getDeviceType(), deviceIdx_, oni_ctx)
2729
{
2830
StreamInfo analogInputStream = StreamInfo(
29-
OnixDevice::createStreamName({ getHeadstageName(), name, "AnalogInput" }),
31+
OnixDevice::createStreamName({ getHubName(), name, "AnalogInput" }),
3032
"Analog Input data",
3133
getStreamIdentifier(),
3234
getNumChannels(),
@@ -51,10 +53,16 @@ AnalogIO::AnalogIO(String name, const oni_dev_idx_t deviceIdx_, std::shared_ptr<
5153
dataType = AnalogIODataType::Volts;
5254
}
5355

54-
int AnalogIO::configureDevice()
56+
OnixDeviceType AnalogIO::getDeviceType()
5557
{
56-
if (deviceContext == nullptr || !deviceContext->isInitialized()) return -1;
58+
return OnixDeviceType::ANALOGIO;
59+
}
5760

61+
int AnalogIO::configureDevice()
62+
{
63+
if (deviceContext == nullptr || !deviceContext->isInitialized())
64+
throw error_str("Device context is not initialized properly for " + getName());
65+
5866
return deviceContext->writeRegister(deviceIdx, (uint32_t)AnalogIORegisters::ENABLE, (oni_reg_val_t)(isEnabled() ? 1 : 0));
5967
}
6068

Source/Devices/AnalogIO.h

Lines changed: 127 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -24,168 +24,173 @@
2424

2525
#include "../OnixDevice.h"
2626

27-
enum class AnalogIORegisters : uint32_t
27+
namespace OnixSourcePlugin
2828
{
29-
ENABLE = 0,
30-
CHDIR = 1,
31-
CH00_IN_RANGE = 2,
32-
CH01_IN_RANGE = 3,
33-
CH02_IN_RANGE = 4,
34-
CH03_IN_RANGE = 5,
35-
CH04_IN_RANGE = 6,
36-
CH05_IN_RANGE = 7,
37-
CH06_IN_RANGE = 8,
38-
CH07_IN_RANGE = 9,
39-
CH08_IN_RANGE = 10,
40-
CH09_IN_RANGE = 11,
41-
CH10_IN_RANGE = 12,
42-
CH11_IN_RANGE = 13,
43-
};
44-
45-
enum class AnalogIOVoltageRange : uint32_t
46-
{
47-
TenVolts = 0,
48-
TwoPointFiveVolts = 1,
49-
FiveVolts = 2
50-
};
51-
52-
enum class AnalogIODirection : uint32_t
53-
{
54-
Input = 0,
55-
Output = 1
56-
};
29+
enum class AnalogIORegisters : uint32_t
30+
{
31+
ENABLE = 0,
32+
CHDIR = 1,
33+
CH00_IN_RANGE = 2,
34+
CH01_IN_RANGE = 3,
35+
CH02_IN_RANGE = 4,
36+
CH03_IN_RANGE = 5,
37+
CH04_IN_RANGE = 6,
38+
CH05_IN_RANGE = 7,
39+
CH06_IN_RANGE = 8,
40+
CH07_IN_RANGE = 9,
41+
CH08_IN_RANGE = 10,
42+
CH09_IN_RANGE = 11,
43+
CH10_IN_RANGE = 12,
44+
CH11_IN_RANGE = 13,
45+
};
46+
47+
enum class AnalogIOVoltageRange : uint32_t
48+
{
49+
TenVolts = 0,
50+
TwoPointFiveVolts = 1,
51+
FiveVolts = 2
52+
};
5753

58-
enum class AnalogIODataType : uint32_t
59-
{
60-
S16 = 0,
61-
Volts = 1
62-
};
54+
enum class AnalogIODirection : uint32_t
55+
{
56+
Input = 0,
57+
Output = 1
58+
};
6359

64-
/*
65-
Configures and streams data from an AnalogIO device on a Breakout Board
66-
*/
67-
class AnalogIO : public OnixDevice
68-
{
69-
public:
70-
AnalogIO(String name, const oni_dev_idx_t, std::shared_ptr<Onix1> oni_ctx);
60+
enum class AnalogIODataType : uint32_t
61+
{
62+
S16 = 0,
63+
Volts = 1
64+
};
65+
66+
/*
67+
Configures and streams data from an AnalogIO device on a Breakout Board
68+
*/
69+
class AnalogIO : public OnixDevice
70+
{
71+
public:
72+
AnalogIO(std::string name, std::string hubName, const oni_dev_idx_t, std::shared_ptr<Onix1> oni_ctx);
7173

72-
/** Configures the device so that it is ready to stream with default settings */
73-
int configureDevice() override;
74+
/** Configures the device so that it is ready to stream with default settings */
75+
int configureDevice() override;
7476

75-
/** Update the settings of the device */
76-
bool updateSettings() override;
77+
/** Update the settings of the device */
78+
bool updateSettings() override;
7779

78-
/** Starts probe data streaming */
79-
void startAcquisition() override;
80+
/** Starts probe data streaming */
81+
void startAcquisition() override;
8082

81-
/** Stops probe data streaming*/
82-
void stopAcquisition() override;
83+
/** Stops probe data streaming*/
84+
void stopAcquisition() override;
8385

84-
/** Given the sourceBuffers from OnixSource, add all streams for the current device to the array */
85-
void addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers) override;
86+
/** Given the sourceBuffers from OnixSource, add all streams for the current device to the array */
87+
void addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers) override;
8688

87-
void addFrame(oni_frame_t*) override;
89+
void addFrame(oni_frame_t*) override;
8890

89-
void processFrames() override;
91+
void processFrames() override;
9092

91-
AnalogIODirection getChannelDirection(int channelNumber)
92-
{
93-
if (channelNumber > numChannels || channelNumber < 0)
93+
AnalogIODirection getChannelDirection(int channelNumber)
9494
{
95-
LOGE("Channel number must be between 0 and " + String(channelNumber));
96-
return AnalogIODirection::Input;
97-
}
95+
if (channelNumber > numChannels || channelNumber < 0)
96+
{
97+
LOGE("Channel number must be between 0 and " + String(channelNumber));
98+
return AnalogIODirection::Input;
99+
}
98100

99-
return channelDirection[channelNumber];
100-
}
101+
return channelDirection[channelNumber];
102+
}
101103

102-
static String getChannelDirection(AnalogIODirection direction)
103-
{
104-
switch (direction)
104+
static String getChannelDirection(AnalogIODirection direction)
105105
{
106-
case AnalogIODirection::Input:
107-
return "Input";
108-
case AnalogIODirection::Output:
109-
return "Output";
110-
default:
111-
return "";
106+
switch (direction)
107+
{
108+
case AnalogIODirection::Input:
109+
return "Input";
110+
case AnalogIODirection::Output:
111+
return "Output";
112+
default:
113+
return "";
114+
}
112115
}
113-
}
114116

115-
void setChannelDirection(int channelNumber, AnalogIODirection direction)
116-
{
117-
if (channelNumber > numChannels || channelNumber < 0)
117+
void setChannelDirection(int channelNumber, AnalogIODirection direction)
118118
{
119-
LOGE("Channel number must be between 0 and " + String(channelNumber));
120-
return;
121-
}
119+
if (channelNumber > numChannels || channelNumber < 0)
120+
{
121+
LOGE("Channel number must be between 0 and " + String(channelNumber));
122+
return;
123+
}
122124

123-
channelDirection[channelNumber] = direction;
124-
}
125+
channelDirection[channelNumber] = direction;
126+
}
125127

126-
AnalogIOVoltageRange getChannelVoltageRange(int channelNumber)
127-
{
128-
if (channelNumber > numChannels || channelNumber < 0)
128+
AnalogIOVoltageRange getChannelVoltageRange(int channelNumber)
129129
{
130-
LOGE("Channel number must be between 0 and " + String(channelNumber));
131-
return AnalogIOVoltageRange::FiveVolts;
130+
if (channelNumber > numChannels || channelNumber < 0)
131+
{
132+
LOGE("Channel number must be between 0 and " + String(channelNumber));
133+
return AnalogIOVoltageRange::FiveVolts;
134+
}
135+
136+
return channelVoltageRange[channelNumber];
132137
}
133138

134-
return channelVoltageRange[channelNumber];
135-
}
139+
void setChannelVoltageRange(int channelNumber, AnalogIOVoltageRange direction)
140+
{
141+
if (channelNumber > numChannels || channelNumber < 0)
142+
{
143+
LOGE("Channel number must be between 0 and " + String(channelNumber));
144+
return;
145+
}
136146

137-
AnalogIODataType getDataType() const { return dataType; }
147+
channelVoltageRange[channelNumber] = direction;
148+
}
138149

139-
int getNumChannels() { return numChannels; }
150+
AnalogIODataType getDataType() const { return dataType; }
140151

141-
private:
152+
void setDataType(AnalogIODataType type) { dataType = type; }
142153

143-
DataBuffer* analogInputBuffer = nullptr;
154+
int getNumChannels() { return numChannels; }
144155

145-
static const int AnalogIOFrequencyHz = 100000;
156+
static OnixDeviceType getDeviceType();
146157

147-
static const int numFrames = 25;
148-
static const int framesToAverage = 4; // NB: Downsampling from 100 kHz to 25 kHz
149-
static const int numChannels = 12;
158+
private:
150159

151-
static const int numberOfDivisions = 1 << 16;
152-
const int dacMidScale = 1 << 15;
160+
DataBuffer* analogInputBuffer = nullptr;
153161

154-
std::array<AnalogIODirection, numChannels> channelDirection;
155-
std::array<AnalogIOVoltageRange, numChannels> channelVoltageRange;
162+
static const int AnalogIOFrequencyHz = 100000;
156163

157-
AnalogIODataType dataType = AnalogIODataType::Volts;
164+
static const int numFrames = 25;
165+
static const int framesToAverage = 4; // NB: Downsampling from 100 kHz to 25 kHz
166+
static const int numChannels = 12;
158167

159-
Array<oni_frame_t*, CriticalSection, numFrames> frameArray;
168+
static const int numberOfDivisions = 1 << 16;
169+
const int dacMidScale = 1 << 15;
160170

161-
unsigned short currentFrame = 0;
162-
unsigned short currentAverageFrame = 0;
163-
int sampleNumber = 0;
171+
std::array<AnalogIODirection, numChannels> channelDirection;
172+
std::array<AnalogIOVoltageRange, numChannels> channelVoltageRange;
164173

165-
bool shouldAddToBuffer = false;
174+
AnalogIODataType dataType = AnalogIODataType::Volts;
166175

167-
std::array<float, numFrames* numChannels> analogInputSamples;
176+
Array<oni_frame_t*, CriticalSection, numFrames> frameArray;
168177

169-
double timestamps[numFrames];
170-
int64 sampleNumbers[numFrames];
171-
uint64 eventCodes[numFrames];
178+
unsigned short currentFrame = 0;
179+
unsigned short currentAverageFrame = 0;
180+
int sampleNumber = 0;
172181

173-
std::array<float, numChannels> voltsPerDivision;
182+
bool shouldAddToBuffer = false;
174183

175-
static float getVoltsPerDivision(AnalogIOVoltageRange voltageRange);
184+
std::array<float, numFrames* numChannels> analogInputSamples;
176185

177-
void setChannelVoltageRange(int channelNumber, AnalogIOVoltageRange direction)
178-
{
179-
if (channelNumber > numChannels || channelNumber < 0)
180-
{
181-
LOGE("Channel number must be between 0 and " + String(channelNumber));
182-
return;
183-
}
186+
double timestamps[numFrames];
187+
int64 sampleNumbers[numFrames];
188+
uint64 eventCodes[numFrames];
184189

185-
channelVoltageRange[channelNumber] = direction;
186-
}
190+
std::array<float, numChannels> voltsPerDivision;
187191

188-
void setDataType(AnalogIODataType type) { dataType = type; }
192+
static float getVoltsPerDivision(AnalogIOVoltageRange voltageRange);
189193

190-
JUCE_LEAK_DETECTOR(AnalogIO);
191-
};
194+
JUCE_LEAK_DETECTOR(AnalogIO);
195+
};
196+
}

0 commit comments

Comments
 (0)