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 }
34 }
38 static void turn_off_assi();
42 static void open_sdc();
43
47 static void close_sdc();
48
52 static void activate_ebs();
53
57 static void deactivate_ebs();
58 // Add these function declarations in the public section of the DigitalSender class:
59
63 static void disable_ebs_actuator_1();
64
68 static void enable_ebs_actuator_1();
69
73 static void disable_ebs_actuator_2();
74
78 static void enable_ebs_actuator_2();
83 void blink_led(int pin);
95 void bspd_error();
99 void no_bspd_error();
103 static void toggle_watchdog();
107 static void close_watchdog_sdc();
111 void turn_on_yellow();
115 void turn_on_blue();
116};
117
118inline void DigitalSender::open_sdc() { DEBUG_PRINT("OPENING SDC"); digitalWrite(CLOSE_SDC, LOW); }
119
120inline void DigitalSender::close_sdc() { DEBUG_PRINT("CLOSING SDC"); digitalWrite(CLOSE_SDC, HIGH); }
121
123 digitalWrite(EBS_VALVE_1_PIN, HIGH);
124 digitalWrite(EBS_VALVE_2_PIN, HIGH);
125}
126
128 digitalWrite(EBS_VALVE_1_PIN, LOW);
129 digitalWrite(EBS_VALVE_2_PIN, LOW);
130}
131
132inline void DigitalSender::disable_ebs_actuator_1() { digitalWrite(EBS_VALVE_1_PIN, LOW); }
133
134inline void DigitalSender::enable_ebs_actuator_1() { digitalWrite(EBS_VALVE_1_PIN, HIGH); }
135
136inline void DigitalSender::disable_ebs_actuator_2() { digitalWrite(EBS_VALVE_2_PIN, LOW); }
137
138inline void DigitalSender::enable_ebs_actuator_2() { digitalWrite(EBS_VALVE_2_PIN, HIGH); }
139
141 analogWrite(ASSI_YELLOW_PIN, LOW);
142 analogWrite(ASSI_BLUE_PIN, LOW);
143}
144
145inline void DigitalSender::turn_on_yellow() { analogWrite(ASSI_YELLOW_PIN, 1023); }
146
147inline void DigitalSender::turn_on_blue() { analogWrite(ASSI_BLUE_PIN, 1023); }
148
149inline void DigitalSender::blink_led(const int pin) {
150 static bool blink_state = false;
151 blink_state = !blink_state;
152 analogWrite(pin, blink_state * 1023);
153}
154
155inline void DigitalSender::turn_on_brake_light() { digitalWrite(BRAKE_LIGHT, HIGH); }
156
157inline void DigitalSender::turn_off_brake_light() { digitalWrite(BRAKE_LIGHT, LOW); }
158
159inline void DigitalSender::bspd_error() { digitalWrite(SDC_BSPD_OUT, HIGH); }
160
161inline void DigitalSender::no_bspd_error() { digitalWrite(SDC_BSPD_OUT, LOW); }
162
164 static volatile bool wd_state = false;
165 wd_state = !wd_state;
166 digitalWrite(WD_ALIVE, wd_state);
167 // DEBUG_PRINT("Toggling watchdog: " + String(wd_state ? "ON" : "OFF"));
168}
169
170inline 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).
static void disable_ebs_actuator_2()
Disables EBS actuator 2.
static void enable_ebs_actuator_2()
Enables EBS actuator 2.
static void enable_ebs_actuator_1()
Enables EBS actuator 1.
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 disable_ebs_actuator_1()
Disables EBS actuator 1.
static void activate_ebs()
Activates the solenoid EBS valves.
static void deactivate_ebs()
Deactivates the solenoid EBS valves.
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.
#define DEBUG_PRINT(str)
constexpr int SDC_BSPD_OUT
constexpr int CLOSE_SDC
constexpr int WD_SDC_CLOSE
constexpr int WD_ALIVE
constexpr int ASSI_BLUE_PIN
constexpr int BRAKE_LIGHT
constexpr int ASSI_YELLOW_PIN
#define EBS_VALVE_2_PIN
#define EBS_VALVE_1_PIN