-
Notifications
You must be signed in to change notification settings - Fork 0
/
ioslot.h
347 lines (267 loc) · 5.82 KB
/
ioslot.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#ifndef IOSLOT_H
#define IOSLOT_H
#include <QObject>
#include <QSharedPointer>
enum IoslotDriver
{
EmptySlotDriver = 0,
AnalogInputDriver,
DiscreteInputDriver,
DiscreteOutputDriver,
DHTxxDriver,
DallasTemperatureDriver,
MHZ19Driver,
SHT2xDriver
};
enum IoslotType
{
UnknownIoslotType,
AnalogInputType,
DiscreteInputType,
DiscreteOutputType
};
class IoslotEditorProvider;
class IoslotBinProvider;
class IoslotXmlProvider;
class IoslotProviders : public QObject {
Q_OBJECT
public:
virtual QSharedPointer<IoslotEditorProvider> editorProvider() = 0;
virtual QSharedPointer<IoslotBinProvider> binProvider() = 0;
virtual QSharedPointer<IoslotXmlProvider> xmlProvider() = 0;
};
class IoslotProvidersV1 : public IoslotProviders {
Q_OBJECT
public:
explicit IoslotProvidersV1(QSharedPointer<IoslotEditorProvider> editorProvider_,
QSharedPointer<IoslotBinProvider> binProvider_,
QSharedPointer<IoslotXmlProvider> xmlProvider_);
virtual QSharedPointer<IoslotEditorProvider> editorProvider();
virtual QSharedPointer<IoslotBinProvider> binProvider();
virtual QSharedPointer<IoslotXmlProvider> xmlProvider();
private:
QSharedPointer<IoslotEditorProvider> d_editorProvider;
QSharedPointer<IoslotBinProvider> d_binProvider;
QSharedPointer<IoslotXmlProvider> d_xmlProvider;
};
class Ioslot : public QObject
{
Q_OBJECT
public:
explicit Ioslot(int id,
int type,
int driver,
QObject *parent = 0);
virtual ~Ioslot();
void setName(const QString &name);
const QString &name() const;
int id() const;
int type() const;
int driver() const;
void setProviders(QSharedPointer<IoslotProviders> providers);
QSharedPointer<IoslotProviders> providers() const;
Q_SIGNALS:
void changed(Ioslot *sender = 0);
public Q_SLOTS:
private:
int d_id;
int d_type;
int d_driver;
QString d_name;
QSharedPointer<IoslotProviders> d_providers;
};
/*
* EmptySlot
* */
class EmptySlot : public Ioslot
{
Q_OBJECT
public:
explicit EmptySlot(int id,
QObject *parent = 0);
virtual ~EmptySlot();
Q_SIGNALS:
public Q_SLOTS:
};
/*
* AnalogInputSlot
* */
class AnalogInputSlot : public Ioslot
{
Q_OBJECT
public:
explicit AnalogInputSlot(int id,
QObject *parent = 0);
virtual ~AnalogInputSlot();
void setNum(int num);
int num() const;
void setLinear(quint16 x1, float y1, quint16 x2, float y2);
quint16 x1() const;
quint16 x2() const;
float y1() const;
float y2() const;
Q_SIGNALS:
public Q_SLOTS:
private:
int d_num;
quint16 d_x1;
quint16 d_x2;
float d_y1;
float d_y2;
};
/*
* DiscreteInputSlot
* */
class DiscreteInputSlot : public Ioslot
{
Q_OBJECT
public:
explicit DiscreteInputSlot(int id,
QObject *parent = 0);
virtual ~DiscreteInputSlot();
void setPin(int pin);
int pin() const;
void setInverse(bool inverse);
bool inverse() const;
Q_SIGNALS:
public Q_SLOTS:
private:
int d_pin;
bool d_inverse;
};
/*
* DiscreteOutputSlot
* */
class DiscreteOutputSlot : public Ioslot
{
Q_OBJECT
public:
explicit DiscreteOutputSlot(int id,
QObject *parent = 0);
virtual ~DiscreteOutputSlot();
void setPin(int pin);
int pin() const;
void setInverse(bool inverse);
bool inverse() const;
enum LogicOperation {
LogicOr = 0,
LogicAnd
};
void setOperation(int operation);
int operation() const;
Q_SIGNALS:
public Q_SLOTS:
private:
int d_operation;
int d_pin;
bool d_inverse;
};
/*
* DHTxxSlot
* */
enum DHTxxModification {
DHT11,
DHT22
};
enum DHTxxParameter {
DHTxxTemperature,
DHTxxHumidity
};
class DHTxxSlot : public Ioslot
{
Q_OBJECT
public:
explicit DHTxxSlot(int id,
QObject *parent = 0);
virtual ~DHTxxSlot();
void setModification(int modification);
int modification() const;
void setParameter(int parameter);
int parameter() const;
void setPin(int pin);
int pin() const;
Q_SIGNALS:
public Q_SLOTS:
private:
int d_modification;
int d_parameter;
int d_pin;
};
/*
* DallasTemperatureSlot
* */
class DallasTemperatureSlot : public Ioslot
{
Q_OBJECT
public:
explicit DallasTemperatureSlot(int id,
QObject *parent = 0);
virtual ~DallasTemperatureSlot();
void setPin(int pin);
int pin() const;
Q_SIGNALS:
public Q_SLOTS:
private:
int d_pin;
};
/*
* MH-Z19
* */
class MHZ19Slot : public Ioslot
{
Q_OBJECT
public:
explicit MHZ19Slot(int id,
QObject *parent = 0);
virtual ~MHZ19Slot();
void setReceivePin(int pin);
int receivePin() const;
void setTransmitPin(int pin);
int transmitPin() const;
Q_SIGNALS:
public Q_SLOTS:
private:
int d_receivePin;
int d_transmitPin;
};
/*
* SHT2x
* */
enum SHT2xParameter {
SHT2xTemperature,
SHT2xHumidity
};
class SHT2xSlot : public Ioslot
{
Q_OBJECT
public:
explicit SHT2xSlot(int id,
QObject *parent = 0);
virtual ~SHT2xSlot();
void setParameter(int parameter);
int parameter() const;
void setSdaPin(int pin);
int sdaPin() const;
void setSclPin(int pin);
int sclPin() const;
Q_SIGNALS:
public Q_SLOTS:
private:
int d_parameter;
int d_sdaPin;
int d_sclPin;
};
/*
* IoslotConv
* */
class IoslotConv
{
public:
template<class S>
static QSharedPointer<S> toSlot(QSharedPointer<Ioslot> &ioslot) {
QSharedPointer<S> s = ioslot.dynamicCast<S>();
return s;
}
};
Q_DECLARE_METATYPE(QSharedPointer<Ioslot>)
#endif // IOSLOT_H