-
Notifications
You must be signed in to change notification settings - Fork 0
/
EABase_InputList.h
79 lines (71 loc) · 1.61 KB
/
EABase_InputList.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
#ifndef __EABase_InputList_H
#define __EABase_InputList_H
#include "EABase.h"
#include "EABase_OutputList.h"
#include "EABase_Chip.h"
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class EABase_InputList : public EABase_OutputList
{
public:
EABase_InputList(EABase_ChipIO *Chip, EABase_PINNO *pins, bool pullup = false, bool invert = false, uint16_t prelTime = 0) : EABase_OutputList(Chip, pins)
{
_pullup = pullup;
_invert = invert;
_currValue = 0;
setPrelTime(prelTime);
}
void setup()
{
_Chip->setMode(_pins, (_pullup == true ? INPUT_PULLUP : INPUT), _invert);
}
void setPrelTime(uint16_t prelTime)
{
_preltime = prelTime;
_lastMillis = 0;
}
EABase_PINDATA get()
{
EABase_PINDATA value;
if (_preltime == 0)
return EABase_OutputList::get();
if (_lastMillis == 0)
{
value = EABase_OutputList::get();
if (value != _lastValue)
{
_lastValue = value;
_lastMillis = millis();
}
}
else
{
if (millis() - _lastMillis > _preltime)
{
value = EABase_OutputList::get();
if (_lastValue == value)
{
_currValue = value;
_lastMillis = 0;
}
else
{
_lastValue = value;
_lastMillis = millis();
}
}
}
return _currValue;
}
private:
bool _pullup;
bool _invert;
uint16_t _preltime;
unsigned long _lastMillis;
uint16_t _currValue;
uint16_t _lastValue;
};
#endif