/** * Add an walb device. * RETURN: * false when some error occurs. */ bool addNolock(const std::string &wdevName) { std::string path = device::getPollingPath(wdevName); Fd fd(::open(path.c_str(), O_RDONLY), std::string("addNolock:can't open ") + path); if (!addName(wdevName, fd())) return false; resetTrigger(fd()); struct epoll_event ev; ::memset(&ev, 0, sizeof(ev)); ev.events = EPOLLPRI; ev.data.fd = fd(); if (::epoll_ctl(efd_(), EPOLL_CTL_ADD, fd(), &ev) < 0) { delName(wdevName, fd()); return false; } fd.dontClose(); return true; }
void SoundTowns_Darkmoon::playTrack(uint8 track) { if (track >= 120 || !_sfxEnabled) return; uint8 *pcm = 0; switch (_soundTable[track].type) { case -1: if (track == 0) haltTrack(); else if (track == 2) beginFadeOut(); break; case 0: if (_soundTable[track].para1 == -1 || (uint32)_soundTable[track].para1 > _pcmDataSize) return; pcm = _pcmData + _soundTable[track].para1; WRITE_LE_UINT16(&pcm[24], _soundTable[track].para2 * 98 / 1000); _intf->callback(39, 0x47); _intf->callback(37, 0x47, 60, track == 11 ? 127 : _pcmVol, pcm); break; case 2: resetTrigger(); g_system->getAudioCDManager()->play(_soundTable[track].para1 - 1, 1, 0, 0); break; case 3: _lastSfxChan ^= 3; _intf->callback(39, _lastSfxChan); _intf->callback(4, _lastSfxChan, _soundTable[track].para1); _intf->callback(1, _lastSfxChan, _soundTable[track].para2, 127); break; default: break; } }
/** * DO NOT call this from multiple threads. * This will throw an exception if caught SIGINT. */ StrVec poll(int timeoutMs = -1) { const char *const FUNC = __func__; StrVec v; int nfds = ::epoll_wait(efd_(), &ev_[0], ev_.size(), timeoutMs); if (nfds < 0) { LOGs.error() << FUNC << "epoll_wait failed" << cybozu::ErrorNo(); return v; } std::lock_guard<std::mutex> lk(mutex_); for (int i = 0; i < nfds; i++) { int fd = ev_[i].data.fd; std::string name = getName(fd); if (!name.empty()) { v.push_back(name); #if 0 printEvent(ev_[i]); #endif resetTrigger(fd); } } return v; }
static void testNoiselessDecoderProcedure(EngineTestHelper ð, int errorToleranceCnt DECLARE_ENGINE_PARAMETER_SUFFIX) { printf("*** (bc->useNoiselessTriggerDecoder = %s)\r\n", CONFIGB(useNoiselessTriggerDecoder) ? "true" : "false"); resetTrigger(eth); // first, no noise fireNoisyCycle60_2(ð, 2, 1000, -1, 0, 0, 0); // should be no errors anyway ASSERT_EQ( 0, engine->triggerCentral.triggerState.totalTriggerErrorCounter) << "testNoiselessDecoderProcedure totalTriggerErrorCounter"; // check if we're imitating the 60-2 signal correctly ASSERT_EQ( 0, eth.engine.triggerCentral.triggerState.getCurrentIndex()) << "index #1"; // check rpm (60secs / (1000us * 60teeth)) = 1000rpm ASSERT_EQ( 1000, GET_RPM()) << "testNoiselessDecoder RPM"; // add noise1 - 1 spike in the middle of the 2nd rising pulse fireNoisyCycle60_2(ð, 2, 1000, 2, 10, 500, 1); assertEqualsM("testNoiselessDecoder noise#1", errorToleranceCnt, engine->triggerCentral.triggerState.totalTriggerErrorCounter); resetTrigger(eth); // add noise2 - 1 spike in the middle of the 2nd falling pulse fireNoisyCycle60_2(ð, 2, 1000, 3, 10, 500, 1); //assertEqualsM("noise#2", errorToleranceCnt, engine->triggerCentral.triggerState.totalTriggerErrorCounter); resetTrigger(eth); // add noise3 - in the middle of the sync.gap, // so that we cannot tell for sure if it's a start of another 'extra' tooth or just a noise inside the gap, // that's why we used expectedEventCount[] in our filtering algo to make a prediction about gap fireNoisyCycle60_2(ð, 2, 1000, 114, 10, 1500, 1); // so everything runs smoothly! assertEqualsM("noise#3", errorToleranceCnt, engine->triggerCentral.triggerState.totalTriggerErrorCounter); resetTrigger(eth); // add noise4 - too close to the start of the real next signal, so the noise spike is accepted as a signal // but when the real signal comes shortly afterwards, it we be treated as a noise spike, fireNoisyCycle60_2(ð, 2, 1000, 4, 10, 980, 1); // and we won't get out of sync! assertEqualsM("noise#4", errorToleranceCnt, engine->triggerCentral.triggerState.totalTriggerErrorCounter); resetTrigger(eth); // add noise5 - one very long 333us noise spike fireNoisyCycle60_2(ð, 2, 1000, 4, 333, 10, 1); // still ok assertEqualsM("noise#5", errorToleranceCnt, engine->triggerCentral.triggerState.totalTriggerErrorCounter); resetTrigger(eth); // add noise6 - 10 short spikes across the entire signal pulse const int failProofNumSpikes = 10; fireNoisyCycle60_2(ð, 2, 1000, 4, 5, 10, failProofNumSpikes); // we barely survived this time assertEqualsM("testNoiselessDecoder noise#6", errorToleranceCnt, engine->triggerCentral.triggerState.totalTriggerErrorCounter); resetTrigger(eth); // add noise7 - 34 short spikes across the entire signal pulse fireNoisyCycle60_2(ð, 2, 1000, 2, 10, 10, failProofNumSpikes + 1); // alas, this is a hard case even for noiseless decoder, and it fails... // but still we're close to 33% signal-noise ratio threshold - not bad! // so here's an error anyway! ASSERT_EQ( 1, engine->triggerCentral.triggerState.totalTriggerErrorCounter) << "testNoiselessDecoder noise#7_fail_test"; }
void LinePlotCanvas::paint(QPainter *painter) { if (!updateTriggered()) return; resetTrigger(); LinePlot *plot = qobject_cast<LinePlot*>(parent()); if (!plot) return; Axis2DBase *monAxis = plot->axis2d(); NDArray &xArray = plot->xData(), &yArray = plot->yData(); bool emptyX = (plot->xSize() == 0); int N = (emptyX) ? plot->ySize() : qMin( plot->xSize(), plot->ySize() ); if (!monAxis || N == 0 || yArray.type() == NDArray::Unknown) return; // Nothing to do NDArrayTyped<qreal> yData = yArray.convert<qreal>(); QRectF lim = monAxis->limits(); // Get the transform params QTransform tran = Util::plotToView(QSizeF(plot->width(), plot->height()), lim, monAxis->xAxis()->inverted(), monAxis->yAxis()->inverted()); qreal tx, ty, sx, sy, limx, limy; Util::plotToView(plot->width(), plot->height(), lim, monAxis->xAxis()->inverted(), monAxis->yAxis()->inverted(), tx, ty, sx, sy); limx = lim.x(); limy = lim.y(); bool is_lines = (plot->line()->style() != "."); if (is_lines && N < 2) return; // Nothing to draw // Allow the printer state to be restored painter->save(); // painter->setTransform(QTransform()); preparePainter(painter, plot); if (is_lines) { QPainterPath path; int starty = plot->startIndexY(); auto y = yData.begin() + starty; if (emptyX) { // Get the first point int startx = 0; qreal x = 0; DRAW_LINES(x, *y); } else { auto xData = xArray.convert<qreal>(); // Get the first point int startx = plot->startIndexX(); auto x = xData.begin() + startx; DRAW_LINES(*x, *y); } // qDebug() << "Path:" << path; painter->drawPath(path); } else { // Just drawing markers, therefore no need to "cut" lines, etc qreal radius = painter->pen().widthF() * 0.5; qreal px, py; if (emptyX) { int x = 0; auto y = yData.begin(); DRAW_DOTS(x, *y); } else { auto xData = xArray.convert<qreal>(); auto x = xData.begin(), y = yData.begin(); DRAW_DOTS(*x, *y); } } // Restore the painter to its former glory painter->restore(); }
WPointGrey::~WPointGrey() { try { if (initialized) { // End acquisition for each camera // Notice that what is usually a one-step process is now two steps // because of the additional step of selecting the camera. It is worth // repeating that camera selection needs to be done once per loop. // It is possible to interact with cameras through the camera list with // GetByIndex(); this is an alternative to retrieving cameras as // Spinnaker::CameraPtr objects that can be quick and easy for small tasks. // for (auto i = 0; i < mCameraList.GetSize(); i++) mCameraList.GetByIndex(i)->EndAcquisition(); for (auto i = 0; i < mCameraList.GetSize(); i++) { // Select camera auto cameraPtr = mCameraList.GetByIndex(i); // Retrieve GenICam nodemap auto& iNodeMap = cameraPtr->GetNodeMap(); // // Disable chunk data // result = disableChunkData(iNodeMap); // // if (result < 0) // // return result; // Reset trigger auto result = resetTrigger(iNodeMap); if (result < 0) op::error("Error happened..." + std::to_string(result), __LINE__, __FUNCTION__, __FILE__); // Deinitialize each camera // Each camera must be deinitialized separately by first // selecting the camera and then deinitializing it. cameraPtr->DeInit(); } op::log("Completed. Releasing...", op::Priority::High); // Clear camera list before releasing mSystemPtr mCameraList.Clear(); // Release mSystemPtr mSystemPtr->ReleaseInstance(); } op::log("Done! Exitting...", op::Priority::High); } catch (const Spinnaker::Exception& e) { op::error(e.what(), __LINE__, __FUNCTION__, __FILE__); } catch (const std::exception& e) { op::error(e.what(), __LINE__, __FUNCTION__, __FILE__); } }