-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuttons.cpp
97 lines (75 loc) · 2.17 KB
/
buttons.cpp
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
#include "buttons.h"
Buttons::Buttons() :
increaseDebounceTime(0), increaseDebounceDelay(500), increaseStep(0),
decreaseDebounceTime(0), decreaseDebounceDelay(500), decreaseStep(0),
directionDebounceTime(0), directionDebounceDelay(500),
resetDebounceTime(0), resetDebounceDelay(500),
menuDebounceTime(0), menuDebounceDelay(500) {
}
void Buttons::resetTrip() {
if((millis() - resetDebounceTime) > resetDebounceDelay) {
Serial.println("Reset trip");
tripMaster->resetTrip();
resetDebounceTime = millis();
}
}
void Buttons::increaseTrip() {
if((millis() - increaseDebounceTime) > increaseDebounceDelay) {
Serial.print("Increase ");
Serial.print(increaseStep);
Serial.print("\n");
tripMaster->increaseTrip();
increaseDebounceTime = millis();
}
}
void Buttons::decreaseTrip() {
if((millis() - decreaseDebounceTime) > decreaseDebounceDelay) {
Serial.print("Decrease ");
Serial.print(decreaseStep);
Serial.print("\n");
tripMaster->decreaseTrip();
decreaseDebounceTime = millis();
}
}
void Buttons::checkMenuChange() {
if((millis() - menuDebounceTime) > menuDebounceDelay) {
if(digitalRead(PinLayout::menuPin) == LOW)
{
Serial.println("Menu change");
}
tripMaster->toggleMenu();
menuDebounceTime = millis();
}
}
void Buttons::checkDirectionChange() {
if((millis() - directionDebounceTime) > directionDebounceDelay) {
if(digitalRead(PinLayout::directionPin) == LOW) {
/*
Serial.print("Direction change from ");
Serial.print(currentDirection);
Serial.print(" to ");
// F B N
switch(currentDirection) {
case forward:
currentDirection = backward;
break;
case backward:
currentDirection = neutral;
break;
case neutral:
currentDirection = forward;
default:
currentDirection = forward;
}
Serial.print(currentDirection);
Serial.print("\n");
*/
Serial.println("Direction change");
tripMaster->toggleDirection();
}
directionDebounceTime = millis();
}
}
void Buttons::registerTripMaster(TripMaster* _tripMaster) {
tripMaster = _tripMaster;
}