-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCruiseControl.cpp
87 lines (75 loc) · 2.44 KB
/
CruiseControl.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
#include "CruiseControl.h"
#include "SM_16DIGIN.h"
#include "Globals.h"
#include "debug.h"
void cruise() {
// DB_PRINTLN("Enter Cruise");
// int cruise_on = 0;
// Update pins
int cruise_on = (digitalPins >> DIG_CRUISE_ON - 1) & 1;
DB_PRINT("cruise_on: ");
DB_PRINTLN(cruise_on);
int cruise_set = (digitalPins >> DIG_CRUISE_SET - 1) & 1;
DB_PRINT("cruise_set: ");
DB_PRINTLN(cruise_set);
int cruise_resume = (digitalPins >> DIG_CRUISE_RESUME - 1) & 1;
DB_PRINT("cruise_resume: ");
DB_PRINTLN(cruise_resume);
int cruise_cancel = (digitalPins >> DIG_BRAKE_LIGHT - 1) & 1;
DB_PRINT("cruise_cancel: ");
DB_PRINTLN(cruise_cancel);// cruiseActive = 0; cruise off
// cruiseActive = 1; cruise on, but not driving
// cruiseActive = 2; cruise on and driving
// Update cruise state based on inputs
if (!cruise_on) {
// initialize all settings
cruiseActive = 0;
// cruiseSpeedActive = 0;
cruiseSetValue = 0;
cruiseAccel = 0;
cruiseDecel = 0;
return;
} else if (cruise_on && (cruiseActive != 2)) {
cruiseActive = 1;
}
// Cruise on
if (cruise_resume && (cruiseActive == 2)) {
DB_PRINTLN(" resume pin is pressed while cruise is driving");
cruiseAccel = 1;
cruiseSetValue = speed;
// DB_PRINT("cruiseSetValue: ");
// DB_PRINTLN(cruiseSetValue);
}
if (cruise_resume && (cruiseActive == 1) && (cruiseSetValue != 0)) {
// set is/has been pressed, cruise is on, but not driving
// cruiseSpeedActive = 1;
cruiseActive = 2; // 2 means cruise is driving
// DB_PRINT("cruiseActive: ");
// DB_PRINTLN(cruiseActive);
}
if (cruise_set && (cruiseActive == 2)) {
// set is pressed, cruise is on, and driving
cruiseDecel = 1;
cruiseSetValue = speed;
// DB_PRINT("cruiseSetValue: ");
// DB_PRINTLN(cruiseSetValue);
}
if (cruise_set && (cruiseActive == 1)) {
// set is pressed, cruise is on, but not driving
speed = 55;
cruiseActive = 2;
cruiseSetValue = speed;
// DB_PRINT("cruiseActive: ");
// DB_PRINTLN(cruiseActive);
// DB_PRINT("cruiseSetValue: ");
// DB_PRINTLN(cruiseSetValue);
}
if (cruise_cancel && cruiseActive == 2) {
// cancel is pressed, cruise is on and driving
cruiseActive = 1; // Back to cruise on
}
DB_PRINT("cruiseActive: ");
DB_PRINTLN(cruiseActive);
DB_PRINT("cruiseSetValue: ");
DB_PRINTLN(cruiseSetValue);
}