|
24 | 24 |
|
25 | 25 | #include "../OnixDevice.h" |
26 | 26 |
|
27 | | -enum class AnalogIORegisters : uint32_t |
| 27 | +namespace OnixSourcePlugin |
28 | 28 | { |
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 | + }; |
57 | 53 |
|
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 | + }; |
63 | 59 |
|
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); |
71 | 73 |
|
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; |
74 | 76 |
|
75 | | - /** Update the settings of the device */ |
76 | | - bool updateSettings() override; |
| 77 | + /** Update the settings of the device */ |
| 78 | + bool updateSettings() override; |
77 | 79 |
|
78 | | - /** Starts probe data streaming */ |
79 | | - void startAcquisition() override; |
| 80 | + /** Starts probe data streaming */ |
| 81 | + void startAcquisition() override; |
80 | 82 |
|
81 | | - /** Stops probe data streaming*/ |
82 | | - void stopAcquisition() override; |
| 83 | + /** Stops probe data streaming*/ |
| 84 | + void stopAcquisition() override; |
83 | 85 |
|
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; |
86 | 88 |
|
87 | | - void addFrame(oni_frame_t*) override; |
| 89 | + void addFrame(oni_frame_t*) override; |
88 | 90 |
|
89 | | - void processFrames() override; |
| 91 | + void processFrames() override; |
90 | 92 |
|
91 | | - AnalogIODirection getChannelDirection(int channelNumber) |
92 | | - { |
93 | | - if (channelNumber > numChannels || channelNumber < 0) |
| 93 | + AnalogIODirection getChannelDirection(int channelNumber) |
94 | 94 | { |
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 | + } |
98 | 100 |
|
99 | | - return channelDirection[channelNumber]; |
100 | | - } |
| 101 | + return channelDirection[channelNumber]; |
| 102 | + } |
101 | 103 |
|
102 | | - static String getChannelDirection(AnalogIODirection direction) |
103 | | - { |
104 | | - switch (direction) |
| 104 | + static String getChannelDirection(AnalogIODirection direction) |
105 | 105 | { |
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 | + } |
112 | 115 | } |
113 | | - } |
114 | 116 |
|
115 | | - void setChannelDirection(int channelNumber, AnalogIODirection direction) |
116 | | - { |
117 | | - if (channelNumber > numChannels || channelNumber < 0) |
| 117 | + void setChannelDirection(int channelNumber, AnalogIODirection direction) |
118 | 118 | { |
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 | + } |
122 | 124 |
|
123 | | - channelDirection[channelNumber] = direction; |
124 | | - } |
| 125 | + channelDirection[channelNumber] = direction; |
| 126 | + } |
125 | 127 |
|
126 | | - AnalogIOVoltageRange getChannelVoltageRange(int channelNumber) |
127 | | - { |
128 | | - if (channelNumber > numChannels || channelNumber < 0) |
| 128 | + AnalogIOVoltageRange getChannelVoltageRange(int channelNumber) |
129 | 129 | { |
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]; |
132 | 137 | } |
133 | 138 |
|
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 | + } |
136 | 146 |
|
137 | | - AnalogIODataType getDataType() const { return dataType; } |
| 147 | + channelVoltageRange[channelNumber] = direction; |
| 148 | + } |
138 | 149 |
|
139 | | - int getNumChannels() { return numChannels; } |
| 150 | + AnalogIODataType getDataType() const { return dataType; } |
140 | 151 |
|
141 | | -private: |
| 152 | + void setDataType(AnalogIODataType type) { dataType = type; } |
142 | 153 |
|
143 | | - DataBuffer* analogInputBuffer = nullptr; |
| 154 | + int getNumChannels() { return numChannels; } |
144 | 155 |
|
145 | | - static const int AnalogIOFrequencyHz = 100000; |
| 156 | + static OnixDeviceType getDeviceType(); |
146 | 157 |
|
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: |
150 | 159 |
|
151 | | - static const int numberOfDivisions = 1 << 16; |
152 | | - const int dacMidScale = 1 << 15; |
| 160 | + DataBuffer* analogInputBuffer = nullptr; |
153 | 161 |
|
154 | | - std::array<AnalogIODirection, numChannels> channelDirection; |
155 | | - std::array<AnalogIOVoltageRange, numChannels> channelVoltageRange; |
| 162 | + static const int AnalogIOFrequencyHz = 100000; |
156 | 163 |
|
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; |
158 | 167 |
|
159 | | - Array<oni_frame_t*, CriticalSection, numFrames> frameArray; |
| 168 | + static const int numberOfDivisions = 1 << 16; |
| 169 | + const int dacMidScale = 1 << 15; |
160 | 170 |
|
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; |
164 | 173 |
|
165 | | - bool shouldAddToBuffer = false; |
| 174 | + AnalogIODataType dataType = AnalogIODataType::Volts; |
166 | 175 |
|
167 | | - std::array<float, numFrames* numChannels> analogInputSamples; |
| 176 | + Array<oni_frame_t*, CriticalSection, numFrames> frameArray; |
168 | 177 |
|
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; |
172 | 181 |
|
173 | | - std::array<float, numChannels> voltsPerDivision; |
| 182 | + bool shouldAddToBuffer = false; |
174 | 183 |
|
175 | | - static float getVoltsPerDivision(AnalogIOVoltageRange voltageRange); |
| 184 | + std::array<float, numFrames* numChannels> analogInputSamples; |
176 | 185 |
|
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]; |
184 | 189 |
|
185 | | - channelVoltageRange[channelNumber] = direction; |
186 | | - } |
| 190 | + std::array<float, numChannels> voltsPerDivision; |
187 | 191 |
|
188 | | - void setDataType(AnalogIODataType type) { dataType = type; } |
| 192 | + static float getVoltsPerDivision(AnalogIOVoltageRange voltageRange); |
189 | 193 |
|
190 | | - JUCE_LEAK_DETECTOR(AnalogIO); |
191 | | -}; |
| 194 | + JUCE_LEAK_DETECTOR(AnalogIO); |
| 195 | + }; |
| 196 | +} |
0 commit comments