Skip to content

Commit

Permalink
refactor: Remove StatusLight, BrakeLight, Speaker, and Button classes…
Browse files Browse the repository at this point in the history
… which just wrapped peripherals.
  • Loading branch information
BlakeFreer committed Nov 30, 2024
1 parent 41dbd6f commit 06f8055
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 70 deletions.
58 changes: 1 addition & 57 deletions firmware/projects/FrontController/inc/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
#include <cstdint>

#include "../generated/can/pt_bus.hpp"
#include "../generated/can/veh_bus.hpp"
#include "../generated/can/veh_messages.hpp"
#include "shared/periph/adc.hpp"
#include "shared/periph/can.hpp"
#include "shared/periph/gpio.hpp"
#include "shared/util/mappers/linear_map.hpp"
#include "shared/util/mappers/mapper.hpp"
#include "shared/util/moving_average.hpp"

Expand Down Expand Up @@ -42,45 +40,6 @@ class AnalogInput {
const shared::util::Mapper<double, uint16_t>* adc_to_position_;
};

class Speaker {
public:
Speaker(shared::periph::DigitalOutput& digital_output)
: digital_output_(digital_output) {}

void Update(bool state) const {
digital_output_.Set(state);
}

private:
shared::periph::DigitalOutput& digital_output_;
};

class BrakeLight {
public:
BrakeLight(shared::periph::DigitalOutput& digital_output)
: digital_output_(digital_output) {}

void Update(bool state) const {
digital_output_.Set(state);
}

private:
shared::periph::DigitalOutput& digital_output_;
};

class Button {
public:
Button(shared::periph::DigitalInput& digital_input)
: digital_input_(digital_input) {}

bool Read() const {
return digital_input_.Read();
}

private:
shared::periph::DigitalInput& digital_input_;
};

/**
* @brief Struct containing all data required for each simulink AMK input
* @note (SAM): Do not edit this struct, even though it will be very similar to
Expand Down Expand Up @@ -216,18 +175,3 @@ class Contactors {
private:
generated::can::VehBus& can_bus_;
};

class StatusLight {
public:
StatusLight(shared::periph::DigitalOutput& digital_output)
: digital_output_(digital_output) {}

void Toggle() {
digital_output_.Set(next_value_);
next_value_ = !next_value_;
}

private:
bool next_value_ = true;
shared::periph::DigitalOutput& digital_output_;
};
19 changes: 6 additions & 13 deletions firmware/projects/FrontController/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
#include "generated/can/veh_messages.hpp"
#include "inc/app.hpp"
#include "inc/simulink.hpp"
#include "shared/os/os.hpp"
#include "shared/periph/adc.hpp"
#include "shared/periph/gpio.hpp"
#include "shared/util/mappers/linear_map.hpp"
#include "shared/util/mappers/mapper.hpp"

/***************************************************************
CAN
Expand All @@ -28,10 +25,6 @@ PtBus pt_can_bus{bindings::pt_can_base};

ControlSystem control_system{};

Speaker driver_speaker{bindings::driver_speaker};
BrakeLight brake_light{bindings::brake_light};
StatusLight status_light{bindings::status_light};

// See fc_docs/pedal_function and
// vehicle_control_system/firmware_io/simulink_input.csv
auto accel_pedal_1_map = shared::util::LinearMap<double, uint16_t>{
Expand Down Expand Up @@ -79,8 +72,6 @@ AnalogInput steering_wheel{
&steering_wheel_map,
};

Button start_button{bindings::start_button};

AMKMotor motor_left{pt_can_bus, 1};
AMKMotor motor_right{pt_can_bus, 0};

Expand Down Expand Up @@ -120,7 +111,7 @@ SimulinkInput ReadCtrlSystemInput() {
input.DI_SteeringAngle = steering_wheel.Update();
input.DI_FrontBrakePressure = brake_pedal_front.Update();
input.DI_RearBrakePressure = brake_pedal_rear.Update();
input.DI_StartButton = start_button.Read();
input.DI_StartButton = bindings::start_button.Read();
input.DI_AccelPedalPosition1 = accel_pedal_1.Update();
input.DI_AccelPedalPosition2 = accel_pedal_2.Update();

Expand Down Expand Up @@ -188,9 +179,9 @@ SimulinkInput ReadCtrlSystemInput() {
* @param output
*/
void SetCtrlSystemOutput(const SimulinkOutput& output) {
driver_speaker.Update(output.DI_DriverSpeaker);
bindings::driver_speaker.Set(output.DI_DriverSpeaker);

brake_light.Update(output.DI_BrakeLightEn);
bindings::brake_light.Set(output.DI_BrakeLightEn);

// @todo This Update() is not implemented
// status_light.Update(output.DI_p_PWMstatusLightCycle,
Expand Down Expand Up @@ -232,7 +223,9 @@ void SetCtrlSystemOutput(const SimulinkOutput& output) {
*
*/
void UpdateStatusLight() {
status_light.Toggle();
static bool toggle = true;
bindings::status_light.Set(toggle);
toggle = !toggle;
}

/***************************************************************
Expand Down

0 comments on commit 06f8055

Please sign in to comment.