-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rtd_Controller.cpp
83 lines (69 loc) · 1.76 KB
/
Rtd_Controller.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
#include "Rtd_Controller.h"
#include "Pins.h"
#include "Logger.h"
// Must define instance prior to use
Rtd_Controller* Rtd_Controller::instance = NULL;
// Private constructor
Rtd_Controller::Rtd_Controller()
: enabled(false),
begun(false)
{
// Initialization done above
}
void Rtd_Controller::begin() {
if(begun) {
return;
}
begun = true;
pinMode(SHUTDOWN_CIRCUIT_PIN, OUTPUT);
digitalWrite(SHUTDOWN_CIRCUIT_PIN, HIGH);
pinMode(BSPD_LATCHED_PIN, OUTPUT);
digitalWrite(BSPD_LATCHED_PIN, HIGH);
pinMode(MC_ENABLE_PIN_1, OUTPUT);
pinMode(MC_ENABLE_PIN_2, OUTPUT);
pinMode(MC_ENABLE_PIN_3, OUTPUT);
pinMode(MC_ENABLE_PIN_4, OUTPUT);
setEnablePins(LOW);
pinMode(FAN_PIN, OUTPUT);
digitalWrite(FAN_PIN, LOW);
analogWrite(FAN_PIN, 128);
}
Rtd_Controller& Rtd_Controller::getInstance() {
if(!instance) {
instance = new Rtd_Controller();
instance->begin();
}
return *instance;
}
Rtd_Controller& RTD() {
return Rtd_Controller::getInstance();
}
void Rtd_Controller::enable() {
enabled = true;
setEnablePins(HIGH);
}
void Rtd_Controller::disable() {
enabled = false;
setEnablePins(LOW);
}
void Rtd_Controller::setEnablePins(uint8_t direction) {
if (direction == LOW) {
// Set pins 4-7 to low, all others stay the same
// (note that pins are ordered as 0b7...0)
PORTK = PORTK & 0b00001111;
}
else if (direction == HIGH) {
// Set pins 4-7 to high, all others stay the same
// (note that pins are ordered as 0b7...0)
PORTK = PORTK | 0b11110000;
}
}
void Rtd_Controller::shutdown(String reason = "") {
disable();
Computer().logTwo("vehicle_shutdown", reason);
Xbee().logTwo("vehicle_shutdown", reason);
digitalWrite(SHUTDOWN_CIRCUIT_PIN, LOW);
}
bool Rtd_Controller::isEnabled() {
return enabled;
}