|
24 | 24 |
|
25 | 25 | using namespace OnixSourcePlugin; |
26 | 26 |
|
| 27 | +const std::map<OnixDeviceType, std::string> OnixDevice::TypeString = { |
| 28 | + {OnixDeviceType::BNO, "BNO055"}, |
| 29 | + {OnixDeviceType::POLLEDBNO, "BNO055"}, |
| 30 | + {OnixDeviceType::NEUROPIXELSV1E, "Neuropixels 1.0e"}, |
| 31 | + {OnixDeviceType::NEUROPIXELSV1F, "Neuropixels 1.0f"}, |
| 32 | + {OnixDeviceType::NEUROPIXELSV2E, "Neuropixels 2.0"}, |
| 33 | + {OnixDeviceType::PORT_CONTROL, "Port Control"}, |
| 34 | + {OnixDeviceType::MEMORYMONITOR, "Memory Monitor"}, |
| 35 | + {OnixDeviceType::OUTPUTCLOCK, "Output Clock"}, |
| 36 | + {OnixDeviceType::HARPSYNCINPUT, "Harp Sync Input"}, |
| 37 | + {OnixDeviceType::ANALOGIO, "Analog IO"}, |
| 38 | + {OnixDeviceType::DIGITALIO, "Digital IO"} |
| 39 | +}; |
| 40 | + |
27 | 41 | OnixDevice::OnixDevice(std::string name_, std::string hubName, OnixDeviceType type_, const oni_dev_idx_t deviceIdx_, std::shared_ptr<Onix1> ctx, bool passthrough) |
28 | 42 | : type(type_), deviceIdx(deviceIdx_), frameQueue(32) |
29 | 43 | { |
@@ -57,22 +71,40 @@ std::string OnixDevice::createStreamName(std::vector<std::string> names) |
57 | 71 | return streamName; |
58 | 72 | } |
59 | 73 |
|
| 74 | +bool OnixDevice::isValidPassthroughIndex(oni_dev_idx_t passthroughIndex) |
| 75 | +{ |
| 76 | + return passthroughIndex == (uint32_t)PassthroughIndex::A || passthroughIndex == (uint32_t)PassthroughIndex::B; |
| 77 | +} |
| 78 | + |
60 | 79 | oni_dev_idx_t OnixDevice::getHubIndexFromPassthroughIndex(oni_dev_idx_t passthroughIndex) |
61 | 80 | { |
62 | | - if (passthroughIndex != (uint32_t)PassthroughIndex::A && passthroughIndex != (uint32_t)PassthroughIndex::B) |
| 81 | + if (!isValidPassthroughIndex(passthroughIndex)) |
63 | 82 | { |
64 | | - LOGE("Invalid passthrough index given. Value was ", passthroughIndex); |
| 83 | + Onix1::showWarningMessageBoxAsync("Invalid Index", "Invalid passthrough index given. Value was " + std::to_string(passthroughIndex)); |
65 | 84 | return 0; |
66 | 85 | } |
67 | 86 |
|
68 | 87 | return (passthroughIndex - 7) << 8; |
69 | 88 | } |
70 | 89 |
|
| 90 | +oni_dev_idx_t OnixDevice::getPassthroughIndexFromHubIndex(oni_dev_idx_t hubIndex) |
| 91 | +{ |
| 92 | + auto index = (hubIndex >> 8) + 7; |
| 93 | + |
| 94 | + if (!isValidPassthroughIndex(index)) |
| 95 | + { |
| 96 | + Onix1::showWarningMessageBoxAsync("Invalid Index", "Invalid hub index given. Value was " + std::to_string(hubIndex)); |
| 97 | + return 0; |
| 98 | + } |
| 99 | + |
| 100 | + return index; |
| 101 | +} |
| 102 | + |
71 | 103 | oni_dev_idx_t OnixDevice::getDeviceIndexFromPassthroughIndex(oni_dev_idx_t passthroughIndex) const |
72 | 104 | { |
73 | | - if (passthroughIndex != (uint32_t)PassthroughIndex::A && passthroughIndex != (uint32_t)PassthroughIndex::B) |
| 105 | + if (!isValidPassthroughIndex(passthroughIndex)) |
74 | 106 | { |
75 | | - LOGE("Invalid passthrough index given. Value was ", passthroughIndex); |
| 107 | + Onix1::showWarningMessageBoxAsync("Invalid Index", "Invalid passthrough index given. Value was " + std::to_string(passthroughIndex)); |
76 | 108 | return 0; |
77 | 109 | } |
78 | 110 |
|
@@ -203,8 +235,8 @@ std::vector<int> OnixDevice::getUniqueOffsets(OnixDeviceMap devices, bool ignore |
203 | 235 | { |
204 | 236 | std::vector<int> indices; |
205 | 237 |
|
206 | | - for (const auto& [key, _] : devices) |
207 | | - { |
| 238 | + for (const auto& [key, _] : devices) |
| 239 | + { |
208 | 240 | indices.emplace_back(key); |
209 | 241 | } |
210 | 242 |
|
@@ -241,141 +273,3 @@ void OnixDevice::stopAcquisition() |
241 | 273 | oni_destroy_frame(frame); |
242 | 274 | } |
243 | 275 | } |
244 | | - |
245 | | -CompositeDevice::CompositeDevice(std::string name_, std::string hubName, CompositeDeviceType type_, const oni_dev_idx_t devIdx, OnixDeviceVector devices_, std::shared_ptr<Onix1> oni_ctx) |
246 | | - : OnixDevice(name_, hubName, OnixDeviceType::COMPOSITE, devIdx, oni_ctx) |
247 | | -{ |
248 | | - compositeType = type_; |
249 | | - devices = devices_; |
250 | | -} |
251 | | - |
252 | | -CompositeDeviceType CompositeDevice::getCompositeDeviceType() const |
253 | | -{ |
254 | | - return compositeType; |
255 | | -} |
256 | | - |
257 | | -bool CompositeDevice::compareIndex(uint32_t index) |
258 | | -{ |
259 | | - for (const auto& device : devices) |
260 | | - { |
261 | | - if (device->getDeviceIdx() == index) |
262 | | - return true; |
263 | | - } |
264 | | - |
265 | | - return false; |
266 | | -} |
267 | | - |
268 | | -bool CompositeDevice::isEnabled() const |
269 | | -{ |
270 | | - bool enabled = true; |
271 | | - |
272 | | - for (const auto& device : devices) |
273 | | - { |
274 | | - enabled &= device->isEnabled(); |
275 | | - } |
276 | | - |
277 | | - return enabled; |
278 | | -} |
279 | | - |
280 | | -bool CompositeDevice::isEnabled(uint32_t index) |
281 | | -{ |
282 | | - for (const auto& device : devices) |
283 | | - { |
284 | | - if (device->compareIndex(index)) |
285 | | - return device->isEnabled(); |
286 | | - } |
287 | | - |
288 | | - Onix1::showWarningMessageBoxAsync( |
289 | | - "Unknown Index", |
290 | | - "Could not get the enabled status of a device at index " + std::to_string(index) + ", it was not found in " + getName() |
291 | | - ); |
292 | | - |
293 | | - return false; |
294 | | -} |
295 | | - |
296 | | -void CompositeDevice::setEnabled(bool newState) |
297 | | -{ |
298 | | - for (const auto& device : devices) |
299 | | - { |
300 | | - device->setEnabled(newState); |
301 | | - } |
302 | | -} |
303 | | - |
304 | | -void CompositeDevice::setEnabled(uint32_t index, bool newState) |
305 | | -{ |
306 | | - for (const auto& device : devices) |
307 | | - { |
308 | | - if (device->compareIndex(index)) |
309 | | - { |
310 | | - device->setEnabled(newState); |
311 | | - return; |
312 | | - } |
313 | | - } |
314 | | - |
315 | | - Onix1::showWarningMessageBoxAsync( |
316 | | - "Unknown Index", |
317 | | - "Could not set the enabled status of a device at index " + std::to_string(index) + ", it was not found in " + getName() |
318 | | - ); |
319 | | - |
320 | | - return; |
321 | | -} |
322 | | - |
323 | | -int CompositeDevice::configureDevice() |
324 | | -{ |
325 | | - int result = ONI_ESUCCESS; |
326 | | - |
327 | | - for (const auto& device : devices) |
328 | | - { |
329 | | - result |= device->configureDevice(); |
330 | | - } |
331 | | - |
332 | | - return result; |
333 | | -} |
334 | | - |
335 | | -bool CompositeDevice::updateSettings() |
336 | | -{ |
337 | | - bool result = true; |
338 | | - |
339 | | - for (const auto& device : devices) |
340 | | - { |
341 | | - result &= device->updateSettings(); |
342 | | - } |
343 | | - |
344 | | - return result; |
345 | | -} |
346 | | - |
347 | | -void CompositeDevice::startAcquisition() |
348 | | -{ |
349 | | - for (const auto& device : devices) |
350 | | - { |
351 | | - device->startAcquisition(); |
352 | | - } |
353 | | -} |
354 | | - |
355 | | -void CompositeDevice::stopAcquisition() |
356 | | -{ |
357 | | - for (const auto& device : devices) |
358 | | - { |
359 | | - device->stopAcquisition(); |
360 | | - } |
361 | | -} |
362 | | - |
363 | | -void CompositeDevice::addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers) |
364 | | -{ |
365 | | - for (const auto& device : devices) |
366 | | - { |
367 | | - device->addSourceBuffers(sourceBuffers); |
368 | | - } |
369 | | -} |
370 | | - |
371 | | -void CompositeDevice::addFrame(oni_frame_t* frame) |
372 | | -{ |
373 | | - for (const auto& device : devices) |
374 | | - { |
375 | | - if (device->compareIndex(frame->dev_idx)) |
376 | | - { |
377 | | - device->addFrame(frame); |
378 | | - return; |
379 | | - } |
380 | | - } |
381 | | -} |
0 commit comments