diff --git a/hepa-uv/core/tasks.cpp b/hepa-uv/core/tasks.cpp index 34723e19a..e0c14e8d0 100644 --- a/hepa-uv/core/tasks.cpp +++ b/hepa-uv/core/tasks.cpp @@ -29,12 +29,13 @@ static auto light_control_task_builder = void hepauv_tasks::start_tasks( can::bus::CanBus& can_bus, gpio_drive_hardware::GpioDrivePins& gpio_drive_pins, - light_control_task::LightControlInterface& led_hardware) { + light_control_hardware::LightControlHardware& led_hardware) { auto& can_writer = can_task::start_writer(can_bus); can_task::start_reader(can_bus); - auto& hepa_task = hepa_task_builder.start(5, "hepa_fan", gpio_drive_pins); - auto& uv_task = uv_task_builder.start(5, "uv_ballast", gpio_drive_pins); + // 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); tasks.hepa_task_handler = &hepa_task; diff --git a/hepa-uv/firmware/led_hardware.c b/hepa-uv/firmware/led_hardware.c index 0de441c5c..6c6f431de 100644 --- a/hepa-uv/firmware/led_hardware.c +++ b/hepa-uv/firmware/led_hardware.c @@ -424,10 +424,10 @@ void button_led_hw_update_pwm(uint32_t duty_cycle, LED_TYPE led, PUSH_BUTTON_TYP } else if (button == UV_BUTTON) { switch(led) { case RED_LED: - htim8.Instance->CCR2 = duty_cycle; + htim8.Instance->CCR3 = duty_cycle; break; case GREEN_LED: - htim8.Instance->CCR3 = duty_cycle; + htim8.Instance->CCR2 = duty_cycle; break; case BLUE_LED: htim1.Instance->CCR4 = duty_cycle; diff --git a/hepa-uv/firmware/light_control_task/light_control_hardware.cpp b/hepa-uv/firmware/light_control_task/light_control_hardware.cpp index 0d747690b..2eea74e2f 100644 --- a/hepa-uv/firmware/light_control_task/light_control_hardware.cpp +++ b/hepa-uv/firmware/light_control_task/light_control_hardware.cpp @@ -10,4 +10,8 @@ auto LightControlHardware::initialize() -> void { button_led_hw_initialize_leds( void LightControlHardware::set_led_power(uint8_t button, uint8_t led, uint32_t duty_cycle) { button_led_hw_update_pwm(duty_cycle, static_cast(led), static_cast(button)); +} + +void LightControlHardware::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(button), r, g, b, w); } \ No newline at end of file diff --git a/include/hepa-uv/core/hepa_task.hpp b/include/hepa-uv/core/hepa_task.hpp index bf9e5fb1a..5290c501f 100644 --- a/include/hepa-uv/core/hepa_task.hpp +++ b/include/hepa-uv/core/hepa_task.hpp @@ -5,8 +5,10 @@ #include "common/core/logging.h" #include "common/core/message_queue.hpp" #include "common/firmware/gpio.hpp" +#include "hepa-uv/core/messages.hpp" #include "hepa-uv/firmware/gpio_drive_hardware.hpp" -#include "messages.hpp" +#include "hepa-uv/firmware/light_control_hardware.hpp" +#include "hepa-uv/core/constants.h" namespace hepa_task { @@ -14,8 +16,11 @@ using TaskMessage = interrupt_task_messages::TaskMessage; class HepaMessageHandler { public: - explicit HepaMessageHandler(gpio_drive_hardware::GpioDrivePins &drive_pins) - : drive_pins{drive_pins} { + explicit HepaMessageHandler( + gpio_drive_hardware::GpioDrivePins &drive_pins, + light_control_hardware::LightControlHardware &led_hardware + ) + : drive_pins{drive_pins}, led_hardware{led_hardware} { // get current state hepa_push_button = gpio::is_set(drive_pins.hepa_push_button); // turn off the HEPA fan @@ -42,8 +47,10 @@ class HepaMessageHandler { // handle state changes here if (hepa_push_button) { gpio::set(drive_pins.hepa_on_off); + led_hardware.set_button_led_power(HEPA_BUTTON, 0, 50, 0, 0); } else { gpio::reset(drive_pins.hepa_on_off); + led_hardware.set_button_led_power(HEPA_BUTTON, 0, 0, 0, 50); } } @@ -55,6 +62,7 @@ class HepaMessageHandler { bool hepa_fan_on = false; gpio_drive_hardware::GpioDrivePins &drive_pins; + light_control_hardware::LightControlHardware &led_hardware; }; /** @@ -77,8 +85,9 @@ class HepaTask { * Task entry point. */ [[noreturn]] void operator()( - gpio_drive_hardware::GpioDrivePins *drive_pins) { - auto handler = HepaMessageHandler{*drive_pins}; + gpio_drive_hardware::GpioDrivePins *drive_pins, + light_control_hardware::LightControlHardware *led_hardware) { + auto handler = HepaMessageHandler{*drive_pins, *led_hardware}; TaskMessage message{}; for (;;) { if (queue.try_read(&message, queue.max_delay)) { diff --git a/include/hepa-uv/core/light_control_task.hpp b/include/hepa-uv/core/light_control_task.hpp index 408f1200d..2a181b136 100644 --- a/include/hepa-uv/core/light_control_task.hpp +++ b/include/hepa-uv/core/light_control_task.hpp @@ -21,6 +21,8 @@ class LightControlInterface { virtual ~LightControlInterface() = default; virtual auto set_led_power(uint8_t button, uint8_t led, uint32_t duty_cycle) -> void = 0; + + virtual auto set_button_led_power(uint8_t button, uint32_t r, uint32_t g, uint32_t b, uint32_t w) -> void = 0; }; class LightControlMessageHandler { diff --git a/include/hepa-uv/core/tasks.hpp b/include/hepa-uv/core/tasks.hpp index 00d890fe5..9a985e42d 100644 --- a/include/hepa-uv/core/tasks.hpp +++ b/include/hepa-uv/core/tasks.hpp @@ -4,6 +4,7 @@ #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/firmware/gpio_drive_hardware.hpp" namespace hepauv_tasks { @@ -13,7 +14,7 @@ namespace hepauv_tasks { */ void start_tasks(can::bus::CanBus& can_bus, gpio_drive_hardware::GpioDrivePins& gpio_drive_pins, - light_control_task::LightControlInterface& led_hardware); + light_control_hardware::LightControlHardware& led_hardware); /** * Access to all the message queues in the system. diff --git a/include/hepa-uv/core/uv_task.hpp b/include/hepa-uv/core/uv_task.hpp index 0787b6fb0..703ef3759 100644 --- a/include/hepa-uv/core/uv_task.hpp +++ b/include/hepa-uv/core/uv_task.hpp @@ -4,21 +4,27 @@ #include "common/core/bit_utils.hpp" #include "common/core/logging.h" #include "common/core/message_queue.hpp" +#include "hepa-uv/core/constants.h" +#include "hepa-uv/core/messages.hpp" #include "hepa-uv/firmware/gpio_drive_hardware.hpp" -#include "messages.hpp" +#include "hepa-uv/firmware/light_control_hardware.hpp" #include "ot_utils/freertos/freertos_timer.hpp" namespace uv_task { // How long to keep the UV light on in ms. -static constexpr uint32_t DELAY_MS = 1000 * 60 * 15; // 15 minutes +// static constexpr uint32_t DELAY_MS = 1000 * 60 * 15; // 15 minutes +static constexpr uint32_t DELAY_MS = 5000; // FOR TESTING using TaskMessage = interrupt_task_messages::TaskMessage; class UVMessageHandler { public: - explicit UVMessageHandler(gpio_drive_hardware::GpioDrivePins &drive_pins) + explicit UVMessageHandler( + gpio_drive_hardware::GpioDrivePins &drive_pins, + light_control_hardware::LightControlHardware &led_hardware) : drive_pins{drive_pins}, + led_hardware{led_hardware}, _timer( "UVTask", [ThisPtr = this] { ThisPtr->timer_callback(); }, DELAY_MS) { @@ -43,6 +49,7 @@ class UVMessageHandler { // call back to turn off the UV ballast auto timer_callback() -> void { gpio::reset(drive_pins.uv_on_off); + led_hardware.set_button_led_power(UV_BUTTON, 0, 0, 0, 50); uv_push_button = false; uv_fan_on = false; } @@ -67,17 +74,19 @@ class UVMessageHandler { // reset push button state if the door is opened or the reed switch is // not set - if (!door_closed || !reed_switch_set) uv_push_button = false; + // if (!door_closed || !reed_switch_set) uv_push_button = false; // set the UV Ballast - if (door_closed && reed_switch_set && uv_push_button) { + if (uv_push_button) { gpio::set(drive_pins.uv_on_off); + led_hardware.set_button_led_power(UV_BUTTON, 0, 50, 0, 0); // start the turn off timer if (_timer.is_running()) _timer.stop(); _timer.start(); uv_fan_on = true; } else { gpio::reset(drive_pins.uv_on_off); + led_hardware.set_button_led_power(UV_BUTTON, 0, 0, 0, 50); if (_timer.is_running()) _timer.stop(); uv_fan_on = false; } @@ -92,6 +101,7 @@ class UVMessageHandler { bool uv_fan_on = false; gpio_drive_hardware::GpioDrivePins &drive_pins; + light_control_hardware::LightControlHardware &led_hardware; ot_utils::freertos_timer::FreeRTOSTimer _timer; }; @@ -115,8 +125,9 @@ class UVTask { * Task entry point. */ [[noreturn]] void operator()( - gpio_drive_hardware::GpioDrivePins *drive_pins) { - auto handler = UVMessageHandler{*drive_pins}; + gpio_drive_hardware::GpioDrivePins *drive_pins, + light_control_hardware::LightControlHardware *led_hardware) { + auto handler = UVMessageHandler{*drive_pins, *led_hardware}; TaskMessage message{}; for (;;) { if (queue.try_read(&message, queue.max_delay)) { diff --git a/include/hepa-uv/firmware/light_control_hardware.hpp b/include/hepa-uv/firmware/light_control_hardware.hpp index 2bf18027f..dca89163b 100644 --- a/include/hepa-uv/firmware/light_control_hardware.hpp +++ b/include/hepa-uv/firmware/light_control_hardware.hpp @@ -16,6 +16,7 @@ class LightControlHardware : public light_control_task::LightControlInterface { auto initialize() -> void; void set_led_power(uint8_t button, uint8_t led, uint32_t duty_cycle) final; + void set_button_led_power(uint8_t button, uint32_t r, uint32_t g, uint32_t b, uint32_t w) final; }; } // namespace light_control_hardware \ No newline at end of file