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
6#include "metro.h"
7
16private:
17public:
18 // Array of valid output pins
19 static constexpr std::array<int, 9> validOutputPins = {
22 // SDC_LOGIC_WATCHDOG_OUT_PIN
23 };
24
31 for (const auto pin : validOutputPins) {
32 pinMode(pin, OUTPUT);
33 }
35 }
39 static void turn_off_assi();
43 static void open_sdc();
44
48 static void close_sdc();
49
53 static void activate_ebs();
54
58 static void deactivate_ebs();
59 // Add these function declarations in the public section of the DigitalSender class:
60
64 static void disable_ebs_actuator_REAR();
65
69 static void enable_ebs_actuator_REAR();
70
74 static void disable_ebs_actuator_FRONT();
75
79 static void enable_ebs_actuator_FRONT();
84 void blink_led(int pin);
96 void bspd_error();
100 void no_bspd_error();
104 static void toggle_watchdog();
108 static void close_watchdog_sdc();
112 void turn_on_yellow();
116 void turn_on_blue();
117};
118
119inline void DigitalSender::open_sdc() { digitalWrite(CLOSE_SDC, LOW); }
120
121inline void DigitalSender::close_sdc() { digitalWrite(CLOSE_SDC, HIGH); }
122
124 digitalWrite(EBS_VALVE_REAR_PIN, HIGH);
125 digitalWrite(EBS_VALVE_FRONT_PIN, HIGH);
126}
127
129 digitalWrite(EBS_VALVE_REAR_PIN, LOW);
130 digitalWrite(EBS_VALVE_FRONT_PIN, LOW);
131}
132
134
136
138
140
142 analogWrite(ASSI_YELLOW_PIN, LOW);
143 analogWrite(ASSI_BLUE_PIN, LOW);
144}
145
146inline void DigitalSender::turn_on_yellow() { analogWrite(ASSI_YELLOW_PIN, 1023); }
147
148inline void DigitalSender::turn_on_blue() { analogWrite(ASSI_BLUE_PIN, 1023); }
149
150inline void DigitalSender::blink_led(const int pin) {
151 static bool blink_state = false;
152 blink_state = !blink_state;
153 analogWrite(pin, blink_state * 1023);
154}
155
156inline void DigitalSender::turn_on_brake_light() { digitalWrite(BRAKE_LIGHT, HIGH); }
157
158inline void DigitalSender::turn_off_brake_light() { digitalWrite(BRAKE_LIGHT, LOW); }
159
160inline void DigitalSender::bspd_error() { digitalWrite(SDC_BSPD_OUT, HIGH); }
161
162inline void DigitalSender::no_bspd_error() { digitalWrite(SDC_BSPD_OUT, LOW); }
163
165 static volatile bool wd_state = false;
166 wd_state = !wd_state;
167 digitalWrite(WD_ALIVE, wd_state);
168 // DEBUG_PRINT("Toggling watchdog: " + String(wd_state ? "ON" : "OFF"));
169}
170
171inline void DigitalSender::close_watchdog_sdc() { digitalWrite(WD_SDC_CLOSE, HIGH); }
Class responsible for controlling digital outputs in the Master Teensy.
void bspd_error()
Turns on the BSPD error signal.
static constexpr std::array< int, 9 > validOutputPins
static void turn_off_assi()
Turns off both ASSI LEDs (yellow and blue).
DigitalSender()
Constructor for the DigitalSender class.
void blink_led(int pin)
Blinks the LED at the given pin.
static void close_watchdog_sdc()
Closes the watchdog signal for SDC.
void turn_on_brake_light()
Turns on the brake light.
void no_bspd_error()
Turns off the BSPD error signal.
void turn_on_blue()
Turns on the blue ASSI LED.
void turn_off_brake_light()
Turns off the brake light.
static void enable_ebs_actuator_FRONT()
Enables EBS actuator 2.
static void enable_ebs_actuator_REAR()
Enables EBS actuator 1.
static void disable_ebs_actuator_FRONT()
Disables EBS actuator 2.
static void activate_ebs()
Activates the solenoid EBS valves.
static void deactivate_ebs()
Deactivates the solenoid EBS valves.
static void disable_ebs_actuator_REAR()
Disables EBS actuator 1.
static void toggle_watchdog()
Toggles the watchdog signal.
static void open_sdc()
Opens the SDC in Master and SDC Logic.
static void close_sdc()
Closes the SDC in Master and SDC Logic.
void turn_on_yellow()
Turns on the yellow ASSI LED.
constexpr int SDC_BSPD_OUT
constexpr int CLOSE_SDC
constexpr int EBS_VALVE_FRONT_PIN
constexpr int EBS_VALVE_REAR_PIN
constexpr int WD_SDC_CLOSE
constexpr int WD_ALIVE
constexpr int ASSI_BLUE_PIN
constexpr int BRAKE_LIGHT
constexpr int ASSI_YELLOW_PIN