trikRuntime
analogSensor.h
Go to the documentation of this file.
1 /* Copyright 2013 - 2015 Nikita Batov, Kseniya Gonta and 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 
20 #include "sensorInterface.h"
21 #include "deviceState.h"
22 
23 namespace trikKernel {
24 class Configurer;
25 }
26 
27 namespace trikControl {
28 
29 class MspCommunicatorInterface;
30 
33 {
34  Q_OBJECT
35 
36 public:
41  AnalogSensor(const QString &port, const trikKernel::Configurer &configurer, MspCommunicatorInterface &communicator);
42 
43  Status status() const override;
44 
45  int minValue() const override;
46 
47  int maxValue() const override;
48 
49 public slots:
51  int read() override;
52 
54  int readRawData() override;
55 
56 private:
57  enum class Type
58  {
60  sharpGP2
61 
63  , analog
64  };
65 
66  void calculateLNS(const QString &port, const trikKernel::Configurer &configurer);
67  void calculateKB(const QString &port, const trikKernel::Configurer &configurer);
68 
69  MspCommunicatorInterface &mCommunicator;
70  int mI2cCommandNumber = 0;
71  Type mIRType;
72 
74  qreal mK = 0;
75 
77  qreal mB = 0;
78 
81  int mL = 0;
82 
85  int mN = 0;
86 
89  int mS = 0;
90 
92  int mMinValue = 0;
93 
95  int mMaxValue = 0;
96 
98  DeviceState mState;
99 };
100 
101 }
Definition: analogSensor.h:23
Generic configuration helper, parses configuration XML files and presents configuration as a set of a...
Definition: configurer.h:28
static const int port
Definition: trikCommunicatorTest.cpp:24
Analog TRIK sensor.
Definition: analogSensor.h:32
Helper class to track device state (off, starting, ready, stopping, fail).
Definition: deviceState.h:26
Status
Device status.
Definition: deviceInterface.h:33
Abstract interface for communication with MSP, may be implemented by I2C or USB buses, depending on current MSP configuration.
Definition: mspCommunicatorInterface.h:26
Definition: trikCommunicator.h:27
Abstract sensor, inherited by various sensor types.
Definition: sensorInterface.h:26