VectorSensorWorker::VectorSensorWorker(const QString &eventFile, DeviceState &state
		, const trikHal::HardwareAbstractionInterface &hardwareAbstraction)
	: mEventFile(hardwareAbstraction.createEventFile(eventFile))
	, mState(state)
{
	mState.start();

	mReading << 0 << 0 << 0;
	mReadingUnsynced = mReading;

	mLastEventTimer.setInterval(maxEventDelay);
	mLastEventTimer.setSingleShot(false);

	mTryReopenTimer.setInterval(reopenDelay);
	mTryReopenTimer.setSingleShot(false);

	connect(mEventFile.data(), SIGNAL(newEvent(int, int, int, trikKernel::TimeVal))
			, this, SLOT(onNewEvent(int, int, int, trikKernel::TimeVal)));

	connect(&mLastEventTimer, SIGNAL(timeout()), this, SLOT(onSensorHanged()));
	connect(&mTryReopenTimer, SIGNAL(timeout()), this, SLOT(onTryReopen()));

	mEventFile->open();

	if (mEventFile->isOpened()) {
		mLastEventTimer.start();
	} else {
		QLOG_WARN() << "Sensor" << mState.deviceName() << ", device file can not be opened, will retry in"
				<< reopenDelay << "milliseconds";
		mTryReopenTimer.start();
		mState.fail();
	}
}
RangeSensorWorker::RangeSensorWorker(const QString &eventFile, DeviceState &state
		, const trikHal::HardwareAbstractionInterface &hardwareAbstraction)
	: mEventFile(hardwareAbstraction.createEventFile(eventFile))
	, mState(state)
{
	connect(mEventFile.data(), SIGNAL(newEvent(trikHal::EventFileInterface::EventType, int, int))
			, this, SLOT(onNewEvent(trikHal::EventFileInterface::EventType, int, int)));
}
EventDeviceWorker::EventDeviceWorker(const QString &deviceFilePath, DeviceState &state
		, const trikHal::HardwareAbstractionInterface &hardwareAbstraction)
	: mEventFile(hardwareAbstraction.createEventFile(deviceFilePath))
{
	state.start();
	if (!mEventFile->open()) {
		state.fail();
		return;
	}

	connect(mEventFile.data(), SIGNAL(newEvent(int, int, int, trikKernel::TimeVal))
			, this, SLOT(onNewEvent(int, int, int, trikKernel::TimeVal)));
}
Beispiel #4
0
KeysWorker::KeysWorker(const QString &keysPath, DeviceState &state
		, const trikHal::HardwareAbstractionInterface &hardwareAbstraction)
	: mEventFile(hardwareAbstraction.createEventFile(keysPath))
	, mState(state)
{
	mState.start();
	if (!mEventFile->open()) {
		mState.fail();
		return;
	}

	connect(mEventFile.data(), SIGNAL(newEvent(trikHal::EventFileInterface::EventType, int, int))
			, this, SLOT(readKeysEvent(trikHal::EventFileInterface::EventType, int, int)));
}
VectorSensorWorker::VectorSensorWorker(const QString &eventFile, DeviceState &state
		, const trikHal::HardwareAbstractionInterface &hardwareAbstraction)
	: mEventFile(hardwareAbstraction.createEventFile(eventFile))
	, mState(state)
{
	mReading << 0 << 0 << 0;
	mReadingUnsynced = mReading;

	mState.start();

	connect(mEventFile.data(), SIGNAL(newEvent(trikHal::EventFileInterface::EventType, int, int))
			, this, SLOT(onNewEvent(trikHal::EventFileInterface::EventType, int, int)));

	mEventFile->open();
}
VectorSensorWorker::VectorSensorWorker(const QString &eventFile, DeviceState &state
		, const trikHal::HardwareAbstractionInterface &hardwareAbstraction
		, QThread &thread)
	: mEventFile(hardwareAbstraction.createEventFile(eventFile, thread))
	, mState(state)
{
	mState.start();

	mReading << 0 << 0 << 0 << 0 << 0 << 0;
	mReadingUnsynced = mReading;

	moveToThread(&thread);

	mLastEventTimer.moveToThread(&thread);
	mLastEventTimer.setInterval(maxEventDelay);
	mLastEventTimer.setSingleShot(false);

	mTryReopenTimer.moveToThread(&thread);
	mTryReopenTimer.setInterval(reopenDelay);
	mTryReopenTimer.setSingleShot(false);

	connect(mEventFile.data(), SIGNAL(newEvent(int, int, int, trikKernel::TimeVal))
			, this, SLOT(onNewEvent(int, int, int, trikKernel::TimeVal)));

	connect(&mLastEventTimer, SIGNAL(timeout()), this, SLOT(onSensorHanged()));
	connect(&mTryReopenTimer, SIGNAL(timeout()), this, SLOT(onTryReopen()));

	mEventFile->open();
	thread.start();

	if (mEventFile->isOpened()) {
		// Timer should be started in its thread, so doing it via metacall
		QMetaObject::invokeMethod(&mLastEventTimer, "start");
	} else {
		QLOG_WARN() << "Sensor" << mState.deviceName() << ", device file can not be opened, will retry in"
				<< reopenDelay << "milliseconds";
		// Timer should be started in its thread, so doing it via metacall
		QMetaObject::invokeMethod(&mTryReopenTimer, "start");
		mState.fail();
	}
}