trikRuntime
rangeSensorWorker.h
Go to the documentation of this file.
1 /* Copyright 2014 - 2016 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/QString>
19 #include <QtCore/QScopedPointer>
20 #include <QReadWriteLock>
21 
23 #include <trikKernel/timeVal.h>
24 
25 #include "deviceState.h"
26 
27 namespace trikControl {
28 
31 class RangeSensorWorker : public QObject
32 {
33  Q_OBJECT
34 
35 public:
38  RangeSensorWorker(const QString &eventFile, DeviceState &state
39  , const trikHal::HardwareAbstractionInterface &hardwareAbstraction);
40 
41  ~RangeSensorWorker() override;
42 
43 signals:
45  void newData(int distance, int rawDistance, const trikKernel::TimeVal &eventTime);
46 
47 public slots:
49  void init();
50 
52  int read();
53 
55  int readRawData();
56 
58  void stop();
59 
60 private slots:
62  void onNewEvent(int eventType, int code, int value, const trikKernel::TimeVal &eventTime);
63 
64 private:
66  QScopedPointer<trikHal::EventFileInterface> mEventFile;
67 
68  int mDistance = -1;
69 
70  int mRawDistance = -1;
71 
73  DeviceState &mState;
74 
75  const trikHal::HardwareAbstractionInterface &mHardwareAbstraction;
76 
77  const QString mEventFileName;
78 
79  QReadWriteLock mDistanceLock;
80 };
81 
82 }
void init()
Initializes sensor and begins receiving events from it.
Definition: rangeSensorWorker.cpp:66
Worker object that processes range sensor output and updates stored reading.
Definition: rangeSensorWorker.h:31
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
int readRawData()
Returns current real raw reading of a sensor.
Definition: rangeSensorWorker.cpp:128
~RangeSensorWorker() override
Definition: rangeSensorWorker.cpp:35
Definition: trikCommunicator.h:27
void newData(int distance, int rawDistance, const trikKernel::TimeVal &eventTime)
Emitted when new data is received from a sensor.
RangeSensorWorker(const QString &eventFile, DeviceState &state, const trikHal::HardwareAbstractionInterface &hardwareAbstraction)
Constructor.
Definition: rangeSensorWorker.cpp:27
void stop()
Stops sensor until init() will be called again.
Definition: rangeSensorWorker.cpp:42
int read()
Returns current raw reading of a sensor.
Definition: rangeSensorWorker.cpp:117
Hardware abstraction, provides devices that are used to communicate with robot hardware or emulate it...
Definition: hardwareAbstractionInterface.h:29