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