-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerAux
More file actions
97 lines (78 loc) · 2.5 KB
/
PowerAux
File metadata and controls
97 lines (78 loc) · 2.5 KB
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
#include "DigitalOut.h"
#include "PowerAuxCANInterface.h"
#include "Printing.h"
#include "ThisThread.h"
#include "log.h"
#include "pindef.h"
#include <mbed.h>
#include <rtos.h>
#define LOG_LEVEL LOG_DEBUG
#define MAIN_LOOP_PERIOD 1s
#define ERROR_CHECK_PERIOD 100ms
#define FLASH_PERIOD 500ms
// TODO: add DRO pin to pindef.h and in main() set dro=1
PowerAuxCANInterface vehicle_can_interface(MAIN_CAN_RX, MAIN_CAN_TX,
MAIN_CAN_STBY);
bool flashLSignal, flashRSignal, flashHazards, flashBMS = false;
Thread signalFlashThread;
DigitalOut brake_lights(BRAKE_LIGHT_EN);
DigitalOut leftTurnSignal(LEFT_TURN_EN);
DigitalOut rightTurnSignal(RIGHT_TURN_EN);
DigitalOut bms_strobe(BMS_STROBE_EN);
DigitalOut drl(DRL_EN);
void signalFlashHandler() {
while (true){
// Change lights based on CAN information
if (flashBMS) {
bms_strobe = !bms_strobe
} else {
bms_strobe = 0
}
if (flashLSignal) {
leftTurnSignal = !leftTurnSignal
rightTurnSignal = false;
}
if (flashRSignal) {
rightTurnSignal = !rightTurnSignal;
leftTurnSignal = false;
}
if (flashHazards) {
rightTurnSignal = !rightTurnSignal;
leftTurnSignal = !leftTurnSignal;
}
if (flashBrakeLights) {
brake_lights = !brake_lights;
}
//Pause for 500ms
ThisThread::sleep_for(FLASH_PERIOD)
// Wait until flag has been raised
signalFlashThread.flags_wait_all(0x1)
}
}
AnalogIn fan_tach(FanTach);
AnalogIn brake_light_current(BRAKE_LIGHT_CURRENT);
AnalogIn headlight_current(DRL_CURRENT);
AnalogIn bms_strobe_current(BMS_STROBE_CURRENT);
AnalogIn left_turn_current(LEFT_TURN_CURRENT);
AnalogIn right_turn_current(RIGHT_TURN_CURRENT);
int main() {
dro = 0;
log_set_level(LOG_LEVEL);
log_debug("Start main()");
signalFlashThread.start(signalFlashHandler);
drl = 1;
while (true) {
log_debug("Main thread loop");
ThisThread::sleep_for(MAIN_LOOP_PERIOD);
}
}
// Process CAN Information
void PowerAuxCANInterface::handle(ECUPowerAuxCommands *can_struct) {
// Blinkers and Hazards
bool flashLSignal = can_struct->left_turn_signal;
bool flashRSignal = can_struct->right_turn_signal;
bool flashHazards = can_struct->hazards;
// Brake Lights
bool flashBrakeLights = can_struct->brake_lights;
signalFlashThread.flags_raise(0x1);
}