Skip to content

Commit

Permalink
rename light_control_task to led_control_task
Browse files Browse the repository at this point in the history
  • Loading branch information
vegano1 committed Jan 20, 2024
1 parent 796a647 commit a636eae
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 156 deletions.
16 changes: 8 additions & 8 deletions hepa-uv/core/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@ static auto hepa_task_builder =
static auto uv_task_builder =
freertos_task::TaskStarter<512, uv_task::UVTask>{};

static auto light_control_task_builder =
freertos_task::TaskStarter<512, light_control_task::LightControlTask>{};
static auto led_control_task_builder =
freertos_task::TaskStarter<512, led_control_task::LEDControlTask>{};

/**
* Start hepa_uv tasks.
*/
void hepauv_tasks::start_tasks(
can::bus::CanBus& can_bus,
gpio_drive_hardware::GpioDrivePins& gpio_drive_pins,
light_control_hardware::LightControlHardware& led_hardware) {
led_control_hardware::LEDControlHardware& led_hardware) {
auto& can_writer = can_task::start_writer(can_bus);
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, led_hardware);
auto& uv_task = uv_task_builder.start(5, "uv_ballast", gpio_drive_pins, led_hardware);
auto& light_control_task = light_control_task_builder.start(5, "push_button_leds", led_hardware);
auto& led_control_task = led_control_task_builder.start(5, "push_button_leds", led_hardware);

tasks.hepa_task_handler = &hepa_task;
tasks.uv_task_handler = &uv_task;
tasks.light_control_task_handler = &light_control_task;
tasks.led_control_task_handler = &led_control_task;
tasks.can_writer = &can_writer;

queues.set_queue(&can_writer.get_queue());
queues.hepa_queue = &hepa_task.get_queue();
queues.uv_queue = &uv_task.get_queue();
queues.light_control_queue = &light_control_task.get_queue();
queues.led_control_queue = &led_control_task.get_queue();
}

hepauv_tasks::QueueClient::QueueClient(can::ids::NodeId this_fw)
Expand All @@ -61,8 +61,8 @@ void hepauv_tasks::QueueClient::send_uv_message(const uv_task::TaskMessage& m) {
uv_queue->try_write(m);
}

void hepauv_tasks::QueueClient::send_light_control_message(const light_control_task::TaskMessage& m) {
light_control_queue->try_write(m);
void hepauv_tasks::QueueClient::send_led_control_message(const led_control_task::TaskMessage& m) {
led_control_queue->try_write(m);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion hepa-uv/firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(REVISIONS hepa-rev1)
# Add source files that should be checked by clang-tidy here
set(HEPA_UV_FW_LINTABLE_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/freertos_idle_timer_task.cpp
${CMAKE_CURRENT_SOURCE_DIR}/light_control_task/light_control_hardware.cpp
${CMAKE_CURRENT_SOURCE_DIR}/led_control_task/led_control_hardware.cpp
${COMMON_EXECUTABLE_DIR}/system/iwdg.cpp
${CAN_FW_DIR}/hal_can_bus.cpp
${CAN_FW_DIR}/utils.c
Expand Down
13 changes: 13 additions & 0 deletions hepa-uv/firmware/led_control_task/led_control_hardware.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "hepa-uv/firmware/led_control_hardware.hpp"

#include "hepa-uv/core/led_control_task.hpp"
#include "hepa-uv/firmware/led_hardware.h"

using namespace led_control_hardware;

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

void LEDControlHardware::set_button_led_power(uint8_t button, uint32_t r, uint32_t g, uint32_t b, uint32_t w) {
set_button_led_pwm(static_cast<PUSH_BUTTON_TYPE>(button), r, g, b, w);
}
17 changes: 0 additions & 17 deletions hepa-uv/firmware/light_control_task/light_control_hardware.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions hepa-uv/firmware/main_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "hepa-uv/core/tasks.hpp"
#include "hepa-uv/firmware/utility_gpio.h"
#include "hepa-uv/firmware/led_hardware.h"
#include "hepa-uv/firmware/light_control_hardware.hpp"
#include "hepa-uv/firmware/led_control_hardware.hpp"

static auto iWatchdog = iwdg::IndependentWatchDog{};

Expand Down Expand Up @@ -117,7 +117,7 @@ extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
}
}

static auto led_hardware = light_control_hardware::LightControlHardware();
static auto led_hardware = led_control_hardware::LEDControlHardware();

auto main() -> int {
HardwareInit();
Expand Down
8 changes: 4 additions & 4 deletions include/hepa-uv/core/hepa_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "common/firmware/gpio.hpp"
#include "hepa-uv/core/messages.hpp"
#include "hepa-uv/firmware/gpio_drive_hardware.hpp"
#include "hepa-uv/firmware/light_control_hardware.hpp"
#include "hepa-uv/firmware/led_control_hardware.hpp"
#include "hepa-uv/core/constants.h"

namespace hepa_task {
Expand All @@ -18,7 +18,7 @@ class HepaMessageHandler {
public:
explicit HepaMessageHandler(
gpio_drive_hardware::GpioDrivePins &drive_pins,
light_control_hardware::LightControlHardware &led_hardware
led_control_hardware::LEDControlHardware &led_hardware
)
: drive_pins{drive_pins}, led_hardware{led_hardware} {
// get current state
Expand Down Expand Up @@ -62,7 +62,7 @@ class HepaMessageHandler {
bool hepa_fan_on = false;

gpio_drive_hardware::GpioDrivePins &drive_pins;
light_control_hardware::LightControlHardware &led_hardware;
led_control_hardware::LEDControlHardware &led_hardware;
};

/**
Expand All @@ -86,7 +86,7 @@ class HepaTask {
*/
[[noreturn]] void operator()(
gpio_drive_hardware::GpioDrivePins *drive_pins,
light_control_hardware::LightControlHardware *led_hardware) {
led_control_hardware::LEDControlHardware *led_hardware) {
auto handler = HepaMessageHandler{*drive_pins, *led_hardware};
TaskMessage message{};
for (;;) {
Expand Down
89 changes: 89 additions & 0 deletions include/hepa-uv/core/led_control_task.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#pragma once

#include <concepts>

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

namespace led_control_task {

using TaskMessage = led_control_task_messages::TaskMessage;

class LEDControlInterface {
public:
LEDControlInterface() = default;
LEDControlInterface(const LEDControlInterface&) = delete;
LEDControlInterface(LEDControlInterface&&) = delete;
auto operator=(LEDControlInterface&&) -> LEDControlInterface& = delete;
auto operator=(const LEDControlInterface&)
-> LEDControlInterface& = delete;
virtual ~LEDControlInterface() = default;

virtual auto set_button_led_power(uint8_t button, uint32_t r, uint32_t g, uint32_t b, uint32_t w) -> void = 0;
};

class LEDControlMessageHandler {
public:
LEDControlMessageHandler(LEDControlInterface& hardware)
: _hardware(hardware) {}

auto handle_message(const TaskMessage& message) -> void {
std::visit([this](auto m) { this->handle(m); }, message);
}

private:
auto handle(std::monostate&) -> void {}

auto handle(const led_control_task_messages::PushButtonLED& msg) -> void {
// Sets the Push button LED colors
_hardware.set_button_led_power(
msg.button,
static_cast<uint32_t>(msg.r),
static_cast<uint32_t>(msg.g),
static_cast<uint32_t>(msg.b),
static_cast<uint32_t>(msg.w)
);
}

LEDControlInterface& _hardware;
};

/**
* The task entry point.
*/
template <template <class> class QueueImpl>
requires MessageQueue<QueueImpl<TaskMessage>, TaskMessage>
class LEDControlTask {
public:
using Messages = TaskMessage;
using QueueType = QueueImpl<TaskMessage>;
LEDControlTask(QueueType& queue) : queue{queue} {}
LEDControlTask(const LEDControlTask& c) = delete;
LEDControlTask(const LEDControlTask&& c) = delete;
auto operator=(const LEDControlTask& c) = delete;
auto operator=(const LEDControlTask&& c) = delete;
~LEDControlTask() = default;

/**
* Task entry point.
*/
[[noreturn]] void operator()(LEDControlInterface* hardware_handle) {
auto handler =
LEDControlMessageHandler(*hardware_handle);
TaskMessage message{};

for (;;) {
if (queue.try_read(&message, queue.max_delay)) {
handler.handle_message(message);
}
}
}

[[nodiscard]] auto get_queue() const -> QueueType& { return queue; }

private:
QueueType& queue;
};

} // namespace led_control_task
87 changes: 0 additions & 87 deletions include/hepa-uv/core/light_control_task.hpp

This file was deleted.

16 changes: 8 additions & 8 deletions include/hepa-uv/core/tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "common/core/freertos_timer.hpp"
#include "hepa-uv/core/hepa_task.hpp"
#include "hepa-uv/core/uv_task.hpp"
#include "hepa-uv/core/light_control_task.hpp"
#include "hepa-uv/firmware/light_control_hardware.hpp"
#include "hepa-uv/core/led_control_task.hpp"
#include "hepa-uv/firmware/led_control_hardware.hpp"
#include "hepa-uv/firmware/gpio_drive_hardware.hpp"

namespace hepauv_tasks {
Expand All @@ -14,7 +14,7 @@ namespace hepauv_tasks {
*/
void start_tasks(can::bus::CanBus& can_bus,
gpio_drive_hardware::GpioDrivePins& gpio_drive_pins,
light_control_hardware::LightControlHardware& led_hardware);
led_control_hardware::LEDControlHardware& led_hardware);

/**
* Access to all the message queues in the system.
Expand All @@ -24,16 +24,16 @@ struct QueueClient : can::message_writer::MessageWriter {

void send_hepa_message(const hepa_task::TaskMessage& m);
void send_uv_message(const uv_task::TaskMessage& m);
void send_light_control_message(const light_control_task::TaskMessage& m);
void send_led_control_message(const led_control_task::TaskMessage& m);

freertos_message_queue::FreeRTOSMessageQueue<hepa_task::TaskMessage>*
hepa_queue{nullptr};

freertos_message_queue::FreeRTOSMessageQueue<uv_task::TaskMessage>*
uv_queue{nullptr};

freertos_message_queue::FreeRTOSMessageQueue<light_control_task::TaskMessage>*
light_control_queue{nullptr};
freertos_message_queue::FreeRTOSMessageQueue<led_control_task::TaskMessage>*
led_control_queue{nullptr};
};

/**
Expand All @@ -49,8 +49,8 @@ struct AllTask {
uv_task::UVTask<freertos_message_queue::FreeRTOSMessageQueue>*
uv_task_handler{nullptr};

light_control_task::LightControlTask<freertos_message_queue::FreeRTOSMessageQueue>*
light_control_task_handler{nullptr};
led_control_task::LEDControlTask<freertos_message_queue::FreeRTOSMessageQueue>*
led_control_task_handler{nullptr};
};

/**
Expand Down
Loading

0 comments on commit a636eae

Please sign in to comment.