Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
digitalSender.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Arduino.h>
4
5#include "digitalSettings.hpp"
6#include "metro.h"
7
16private:
17 Metro blink_imer_{LED_BLINK_INTERVAL};
18
22 static void turn_off_assi();
23
24public:
25 // Array of valid output pins
26 static constexpr std::array<int, 9> validOutputPins = {
29 // SDC_LOGIC_WATCHDOG_OUT_PIN
30 };
31
38 for (const auto pin : validOutputPins) {
39 pinMode(pin, OUTPUT);
40 }
41 }
42
46 static void open_sdc();
47
51 static void close_sdc();
52
56 static void activate_ebs();
57
61 static void deactivate_ebs();
62
67
71 static void enter_manual_state();
72
76 static void enter_off_state();
77
81 static void enter_ready_state();
82
87
91 static void enter_finish_state();
92
97 void blink_led(int pin);
98};
99
101 digitalWrite(SDC_LOGIC_CLOSE_SDC_PIN, LOW);
102 digitalWrite(MASTER_SDC_OUT_PIN, LOW);
103}
104
106 digitalWrite(SDC_LOGIC_CLOSE_SDC_PIN, HIGH);
107 digitalWrite(MASTER_SDC_OUT_PIN, HIGH);
108}
109
111 digitalWrite(EBS_VALVE_1_PIN, HIGH);
112 digitalWrite(EBS_VALVE_2_PIN, HIGH);
113}
114
116 digitalWrite(EBS_VALVE_1_PIN, LOW);
117 digitalWrite(EBS_VALVE_2_PIN, LOW);
118}
119
120inline void DigitalSender::turn_off_assi() {
121 analogWrite(ASSI_YELLOW_PIN, LOW);
122 analogWrite(ASSI_BLUE_PIN, LOW);
123}
124
126 turn_off_assi();
127 blink_imer_.reset();
128 activate_ebs();
129 open_sdc();
130}
131
133 turn_off_assi();
135 close_sdc();
136}
137
139 turn_off_assi();
141 open_sdc();
142}
143
145 turn_off_assi();
146 analogWrite(ASSI_YELLOW_PIN, 1023); // Analog works better
147 activate_ebs();
148 close_sdc();
149}
150
152 turn_off_assi();
153 blink_imer_.reset();
155 close_sdc();
156}
157
159 turn_off_assi();
160 analogWrite(ASSI_BLUE_PIN, 1023); // Analog works better
161 activate_ebs();
162 open_sdc();
163}
164
165inline void DigitalSender::blink_led(const int pin) {
166 static bool blink_state = false;
167 if (blink_imer_.check()) {
168 blink_state = !blink_state;
169 analogWrite(pin, blink_state * 1023); // Analog works better
170 }
171}
Class responsible for controlling digital outputs in the Master Teensy.
void enter_emergency_state()
ASSI LEDs blue flashing, sdc open and buzzer ringing.
static constexpr std::array< int, 9 > validOutputPins
DigitalSender()
Constructor for the DigitalSender class.
void blink_led(int pin)
Blinks the LED at the given pin.
static void enter_finish_state()
ASSI blue LED on, ebs valves activated, sdc open.
static void enter_manual_state()
Everything off, sdc closed.
void enter_driving_state()
ASSI LEDs yellow flashing, ebs valves deactivated, sdc closed.
static void activate_ebs()
Activates the solenoid EBS valves.
static void deactivate_ebs()
Deactivates the solenoid EBS valves.
static void open_sdc()
Opens the SDC in Master and SDC Logic.
static void enter_ready_state()
ASSI yellow LED on, ebs valves activated, sdc closed.
static void close_sdc()
Closes the SDC in Master and SDC Logic.
static void enter_off_state()
Everything off, sdc open.
Our own implementation of Metro class.
Definition metro.h:13
void reset()
Resets the timer to the current time.
Definition metro.h:124
bool check()
Checks if the interval has passed and resets the timer if true.
Definition metro.h:90
constexpr int LED_BLINK_INTERVAL
constexpr int ASSI_BLUE_PIN
constexpr int ASSI_YELLOW_PIN
#define SDC_LOGIC_CLOSE_SDC_PIN
#define EBS_VALVE_2_PIN
#define EBS_VALVE_1_PIN
#define MASTER_SDC_OUT_PIN