trikRuntime
vectorSensorWorker.h
Go to the documentation of this file.
1 /* Copyright 2014 - 2015 CyberTech Labs Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 #pragma once
16 
17 #include <QtCore/QObject>
18 #include <QtCore/QScopedPointer>
19 #include <QtCore/QVector>
20 #include <QtCore/QTimer>
21 #include <QtCore/QReadWriteLock>
22 #include <QtCore/QThread>
23 
25 
26 #include "deviceState.h"
27 
28 namespace trikKernel {
29 class TimeVal;
30 }
31 
32 namespace trikControl {
33 
35 class VectorSensorWorker : public QObject
36 {
37  Q_OBJECT
38 
39 public:
44  VectorSensorWorker(const QString &eventFile, DeviceState &state
45  , const trikHal::HardwareAbstractionInterface &hardwareAbstraction
46  , QThread &thread);
47 
48 signals:
50  void newData(QVector<int> reading, const trikKernel::TimeVal &eventTime);
51 
52 public slots:
54  QVector<int> read();
55 
56 private slots:
58  void onNewEvent(int eventType, int code, int value, const trikKernel::TimeVal &eventTime);
59 
62  void onSensorHanged();
63 
66  void onTryReopen();
67 
68 private:
70  QScopedPointer<trikHal::EventFileInterface> mEventFile;
71 
73  QVector<int> mReading;
74 
76  QVector<int> mReadingUnsynced;
77 
79  DeviceState &mState;
80 
82  QTimer mLastEventTimer;
83 
85  QTimer mTryReopenTimer;
86 
87  mutable QReadWriteLock mReadingLock;
88 };
89 
90 }
Definition: analogSensor.h:23
Helper class to track device state (off, starting, ready, stopping, fail).
Definition: deviceState.h:26
Structure of a time value in a convenient format.
Definition: timeVal.h:20
Handles events from sensor, intended to work in separate thread.
Definition: vectorSensorWorker.h:35
Definition: trikCommunicator.h:27
Hardware abstraction, provides devices that are used to communicate with robot hardware or emulate it...
Definition: hardwareAbstractionInterface.h:29