Skip to content

Commit

Permalink
Fix for extremely slow line sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
yurii-litvinov committed Nov 6, 2015
1 parent 82c48f0 commit 4f62b22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion trikControl/src/abstractVirtualSensorWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ using namespace trikControl;
AbstractVirtualSensorWorker::AbstractVirtualSensorWorker(const QString &script, const QString &inputFile
, const QString &outputFile, DeviceState &state, trikHal::HardwareAbstractionInterface &hardwareAbstraction)
: mSystemConsole(hardwareAbstraction.systemConsole())
, mOutputFifo(hardwareAbstraction.createFifo(outputFile))
, mScript(script)
, mInputFile(hardwareAbstraction.createOutputDeviceFile(inputFile))
, mState(state)
, mHardwareAbstraction(hardwareAbstraction)
, mOutputFile(outputFile)
{
}

Expand All @@ -59,6 +60,8 @@ void AbstractVirtualSensorWorker::stop()

void AbstractVirtualSensorWorker::init()
{
mOutputFifo.reset(mHardwareAbstraction.createFifo(mOutputFile));

if (mState.isReady() && QFileInfo(mInputFile->fileName()).exists() && QFileInfo(mOutputFifo->fileName()).exists()) {
// Sensor is up and ready.
QLOG_ERROR() << "Trying to init video sensor that is already running, ignoring";
Expand Down
6 changes: 6 additions & 0 deletions trikControl/src/abstractVirtualSensorWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ private slots:

/// Current state of a device, shared between worker and proxy.
DeviceState &mState;

/// Reference to hardware abstraction needed to create FIFO objects in correct thread.
trikHal::HardwareAbstractionInterface &mHardwareAbstraction;

/// Name of an output file.
const QString mOutputFile;
};

}
6 changes: 3 additions & 3 deletions trikScriptRunner/src/threading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void Threading::startMainThread(const QString &script)
mFinishedThreads.clear();
mPreventFromStart.clear();

QRegExp const mainRegexp("(.*var main\\s*=\\s*\\w*\\s*function\\(.*\\).*)|(.*function\\s+%1\\s*\\(.*\\).*)");
bool needCallMain = mainRegexp.exactMatch(script) && !script.trimmed().endsWith("main();");
const QRegExp mainRegexp("(.*var main\\s*=\\s*\\w*\\s*function\\(.*\\).*)|(.*function\\s+%1\\s*\\(.*\\).*)");
const bool needCallMain = mainRegexp.exactMatch(script) && !script.trimmed().endsWith("main();");

startThread("main", mScriptWorker->createScriptEngine(), needCallMain ? script + "\nmain();" : script);
}
Expand Down Expand Up @@ -84,7 +84,7 @@ void Threading::startThread(const QString &threadId, QScriptEngine *engine, cons
}

QLOG_INFO() << "Starting new thread" << threadId << "with engine" << engine;
ScriptThread *thread = new ScriptThread(*this, threadId, engine, script);
ScriptThread * const thread = new ScriptThread(*this, threadId, engine, script);
connect(&mScriptControl, SIGNAL(quitSignal()), thread, SIGNAL(stopRunning()), Qt::DirectConnection);
mThreads[threadId] = thread;
mFinishedThreads.remove(threadId);
Expand Down

0 comments on commit 4f62b22

Please sign in to comment.