Skip to content

Commit

Permalink
consolidate hardware initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
vegano1 committed Jan 23, 2024
1 parent 48d6fe3 commit ce39ee7
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 156 deletions.
4 changes: 2 additions & 2 deletions hepa-uv/core/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ void hepauv_tasks::start_tasks(
can_task::start_reader(can_bus);

// TODO: including led_hardware for testing, this should be a AssesorClient
auto& hepa_task =
hepa_task_builder.start(5, "hepa_fan", gpio_drive_pins, hepa_hardware, queues);
auto& hepa_task = hepa_task_builder.start(5, "hepa_fan", gpio_drive_pins,
hepa_hardware, queues);
auto& uv_task =
uv_task_builder.start(5, "uv_ballast", gpio_drive_pins, queues);
auto& led_control_task =
Expand Down
114 changes: 0 additions & 114 deletions hepa-uv/firmware/hardware.c

This file was deleted.

6 changes: 3 additions & 3 deletions hepa-uv/firmware/hepa_control_hardware.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "hepa-uv/firmware/hepa_control_hardware.hpp"
#include "hepa-uv/firmware/hardware.h"

using namespace hepa_control_hardware;
#include "hepa-uv/firmware/hepauv_hardware.h"

using namespace hepa_control_hardware;

void HepaControlHardware::set_hepa_fan_speed(uint32_t duty_cycle) {
hepa_fan_hw_update_pwm(duty_cycle);
set_hepa_fan_pwm(duty_cycle);
}
4 changes: 1 addition & 3 deletions hepa-uv/firmware/led_control_task/led_control_hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
using namespace led_control_hardware;

// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
auto LEDControlHardware::initialize() -> void {
initialize_hepauv_hardware();
}
auto LEDControlHardware::initialize() -> void { initialize_hepauv_hardware(); }

void LEDControlHardware::set_button_led_power(uint8_t button, uint32_t r,
uint32_t g, uint32_t b,
Expand Down
5 changes: 3 additions & 2 deletions hepa-uv/firmware/main_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#include "common/firmware/utility_gpio.h"
#include "hepa-uv/core/messages.hpp"
#include "hepa-uv/core/tasks.hpp"
#include "hepa-uv/firmware/led_control_hardware.hpp"
#include "hepa-uv/firmware/hepa_control_hardware.hpp"
#include "hepa-uv/firmware/hepauv_hardware.h"
#include "hepa-uv/firmware/led_control_hardware.hpp"
#include "hepa-uv/firmware/utility_gpio.h"

static auto iWatchdog = iwdg::IndependentWatchDog{};
Expand Down Expand Up @@ -131,7 +131,8 @@ auto main() -> int {

canbus.start(can_bit_timings);

hepauv_tasks::start_tasks(canbus, gpio_drive_pins, hepa_hardware, led_hardware);
hepauv_tasks::start_tasks(canbus, gpio_drive_pins, hepa_hardware,
led_hardware);

iWatchdog.start(6);

Expand Down
23 changes: 14 additions & 9 deletions include/hepa-uv/core/hepa_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "common/core/message_queue.hpp"
#include "common/firmware/gpio.hpp"
#include "hepa-uv/core/constants.h"
#include "hepa-uv/core/messages.hpp"
#include "hepa-uv/core/led_control_task.hpp"
#include "hepa-uv/core/messages.hpp"
#include "hepa-uv/firmware/gpio_drive_hardware.hpp"
#include "hepa-uv/firmware/hepa_control_hardware.hpp"

Expand All @@ -18,10 +18,13 @@ using TaskMessage = interrupt_task_messages::TaskMessage;
template <led_control_task::TaskClient LEDControlClient>
class HepaMessageHandler {
public:
explicit HepaMessageHandler(gpio_drive_hardware::GpioDrivePins &drive_pins,
hepa_control_hardware::HepaControlHardware &hepa_hardware,
LEDControlClient &led_control_client)
: drive_pins{drive_pins}, hepa_hardware{hepa_hardware}, led_control_client{led_control_client} {
explicit HepaMessageHandler(
gpio_drive_hardware::GpioDrivePins &drive_pins,
hepa_control_hardware::HepaControlHardware &hepa_hardware,
LEDControlClient &led_control_client)
: drive_pins{drive_pins},
hepa_hardware{hepa_hardware},
led_control_client{led_control_client} {
// get current state
hepa_push_button = gpio::is_set(drive_pins.hepa_push_button);
// turn off the HEPA fan
Expand Down Expand Up @@ -93,10 +96,12 @@ class HepaTask {
* Task entry point.
*/
template <led_control_task::TaskClient LEDControlClient>
[[noreturn]] void operator()(gpio_drive_hardware::GpioDrivePins *drive_pins,
hepa_control_hardware::HepaControlHardware *hepa_hardware,
LEDControlClient *led_control_client) {
auto handler = HepaMessageHandler{*drive_pins, *hepa_hardware, *led_control_client};
[[noreturn]] void operator()(
gpio_drive_hardware::GpioDrivePins *drive_pins,
hepa_control_hardware::HepaControlHardware *hepa_hardware,
LEDControlClient *led_control_client) {
auto handler = HepaMessageHandler{*drive_pins, *hepa_hardware,
*led_control_client};
TaskMessage message{};
for (;;) {
if (queue.try_read(&message, queue.max_delay)) {
Expand Down
9 changes: 5 additions & 4 deletions include/hepa-uv/core/interfaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LEDControlInterface {
uint32_t b, uint32_t w) -> void = 0;
};

} // led_control namespace
} // namespace led_control

namespace hepa_control {

Expand All @@ -27,9 +27,10 @@ class HepaControlInterface {
HepaControlInterface(const HepaControlInterface&) = delete;
HepaControlInterface(HepaControlInterface&&) = delete;
auto operator=(HepaControlInterface&&) -> HepaControlInterface& = delete;
auto operator=(const HepaControlInterface&) -> HepaControlInterface& = delete;
auto operator=(const HepaControlInterface&)
-> HepaControlInterface& = delete;
virtual ~HepaControlInterface() = default;

virtual void set_hepa_fan_speed(uint32_t duty_cycle);
};
} // hepa_control namespace
};
} // namespace hepa_control
2 changes: 1 addition & 1 deletion include/hepa-uv/core/led_control_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include "common/core/message_queue.hpp"
#include "hepa-uv/core/constants.h"
#include "hepa-uv/core/messages.hpp"
#include "hepa-uv/core/interfaces.hpp"
#include "hepa-uv/core/messages.hpp"

namespace led_control_task {

Expand Down
2 changes: 1 addition & 1 deletion include/hepa-uv/core/tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "hepa-uv/core/led_control_task.hpp"
#include "hepa-uv/core/uv_task.hpp"
#include "hepa-uv/firmware/gpio_drive_hardware.hpp"
#include "hepa-uv/firmware/led_control_hardware.hpp"
#include "hepa-uv/firmware/hepa_control_hardware.hpp"
#include "hepa-uv/firmware/led_control_hardware.hpp"

namespace hepauv_tasks {

Expand Down
16 changes: 0 additions & 16 deletions include/hepa-uv/firmware/hardware.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/hepa-uv/firmware/hepa_control_hardware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class HepaControlHardware : public HepaControlInterface {
void set_hepa_fan_speed(uint32_t duty_cycle);
};

} // namespace led_control_hardware
} // namespace hepa_control_hardware

0 comments on commit ce39ee7

Please sign in to comment.