trikRuntime
keysWorker.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/QScopedPointer>
19 #include <QtCore/QSet>
20 #include <QtCore/QReadWriteLock>
21 
23 
24 #include "deviceState.h"
25 
26 namespace trikControl {
27 
29 class KeysWorker : public QObject
30 {
31  Q_OBJECT
32 
33 public:
38  KeysWorker(const QString &keysPath, DeviceState &state
39  , const trikHal::HardwareAbstractionInterface &hardwareAbstraction);
40 
42  void reset();
43 
44 public slots:
46  bool wasPressed(int code);
47 
48 private slots:
49  void readKeysEvent(int eventType, int code, int value, const trikKernel::TimeVal &eventTime);
50 
51 signals:
55  void buttonPressed(int code, int value);
56 
57 private:
58  QScopedPointer<trikHal::EventFileInterface> mEventFile;
59  int mButtonCode = 0;
60  int mButtonValue = 0;
61  QSet<int> mWasPressed;
62  QReadWriteLock mLock;
63 
65  DeviceState &mState;
66 };
67 
68 }
bool wasPressed(int code)
Returns true if a key with given code was pressed.
Definition: keysWorker.cpp:49
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
void reset()
Clear data about previous key pressures.
Definition: keysWorker.cpp:40
KeysWorker(const QString &keysPath, DeviceState &state, const trikHal::HardwareAbstractionInterface &hardwareAbstraction)
Constructor.
Definition: keysWorker.cpp:25
void buttonPressed(int code, int value)
Triggered when button state changed (pressed or released).
Definition: trikCommunicator.h:27
Watches for keys on a brick, intended to work in separate thread.
Definition: keysWorker.h:29
Hardware abstraction, provides devices that are used to communicate with robot hardware or emulate it...
Definition: hardwareAbstractionInterface.h:29