-
Notifications
You must be signed in to change notification settings - Fork 0
/
touchcontrol.h
68 lines (63 loc) · 1.75 KB
/
touchcontrol.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
#ifndef MQTT_LEDSTRIP_TOUCHCONTROL_H
#define MQTT_LEDSTRIP_TOUCHCONTROL_H
#include "Arduino.h"
#include "config.h"
#define TOUCH_PIN T0
typedef void(*ControlFn)(int);
class TouchControl {
public:
TouchControl()
{
_pressFn = [](int val){ };
_releaseFn = [](int val){ };
_stilldownFn = [](int val){ };
_pin = TOUCH_PIN;
_threshold = TOUCH_THRESHOLD;
_name = "button";
};
TouchControl(
String name,
int pin,
int threshold,
ControlFn pressFn
) :
_pressFn { pressFn },
_releaseFn { [](int val){ } },
_stilldownFn { [](int val){ } },
_pin { pin },
_name { name },
_threshold { threshold }
{ };
TouchControl(
String name,
int pin,
int threshold,
ControlFn pressFn,
ControlFn stilldownFn,
ControlFn releaseFn
) :
_name { name },
_pin { pin },
_threshold { threshold },
_pressFn { pressFn },
_stilldownFn { stilldownFn },
_releaseFn { releaseFn }
{ };
TouchControl(String name, int pin, int threshold);
int get_state();
void set_press(ControlFn pressFn);
void set_release(ControlFn releaseFn);
void set_stilldown(ControlFn stilldownFn);
bool is_pressed();
void update();
private:
String _name;
int _pressed = 0;
int _val;
int _pin;
int _threshold;
ControlFn _pressFn;
ControlFn _releaseFn;
ControlFn _stilldownFn;
};
#endif //MQTT_LEDSTRIP_TOUCHCONTROL_H