diff --git a/Firmware/CoverUI/YardForce/Hatch.cpp b/Firmware/CoverUI/YardForce/Hatch.cpp index d8e5a0a..20cd8f8 100644 --- a/Firmware/CoverUI/YardForce/Hatch.cpp +++ b/Firmware/CoverUI/YardForce/Hatch.cpp @@ -5,17 +5,14 @@ * This is for YardForce models (like SA, SC or NX), whose CoverUI is behind a hatch. * Those need some special (button) handling because opening the hatch (to reach the buttons), triggers stop-emergency. * @version 0.2 - * @date 2023-11-05 + * @date 2024-09-30 * - * @copyright Copyright (c) 2023 + * @copyright Copyright (c) 2023, 2024 * */ #include -// #include -#include -// #include "include/Hatch.hpp" -// #include "include/LEDcontrol.hpp" + #include "include/main.h" /** @@ -38,7 +35,7 @@ unsigned int Hatch::handle_button(unsigned int button_id, uint32_t press_time) void Hatch::queue_button(uint8_t button_id, uint8_t press_duration, uint32_t delay) { - fake_button_queue.push_back({button_id, press_duration, millis() + delay}); + fake_button_queue.push({button_id, press_duration, millis() + delay}); }; /** @@ -46,15 +43,12 @@ void Hatch::queue_button(uint8_t button_id, uint8_t press_duration, uint32_t del */ void Hatch::process_queued() { - if (fake_button_queue.empty()) + if (fake_button_queue.empty() || fake_button_queue.full()) return; - for (auto it = fake_button_queue.begin(); it != fake_button_queue.end(); ++it) - { - if (millis() >= it->delay_end) - { - buttons.send(it->button_id, it->press_duration); - it = fake_button_queue.erase(it); - } + auto first = fake_button_queue.front(); + if (millis() >= first.delay_end) { + buttons.send(first.button_id, first.press_duration); + fake_button_queue.pop(); } }; diff --git a/Firmware/CoverUI/YardForce/include/Hatch.hpp b/Firmware/CoverUI/YardForce/include/Hatch.hpp index f8a1c9e..4f8c012 100644 --- a/Firmware/CoverUI/YardForce/include/Hatch.hpp +++ b/Firmware/CoverUI/YardForce/include/Hatch.hpp @@ -4,17 +4,19 @@ * @brief YardForce CoverUI Hatch header for OpenMower https://github.com/ClemensElflein/OpenMower * This is for YardForce models (like SA, SC or NX), whose CoverUI is behind a hatch. * Those need some special (button) handling because opening the hatch (to reach the buttons), triggers stop-emergency. - * @version 0.2 - * @date 2023-11-05 + * @version 0.3 + * @date 2024-09-30 * - * @copyright Copyright (c) 2023 + * @copyright Copyright (c) 2023, 2024 * */ #ifndef YARDFORCE_HATCH_HPP #define YARDFORCE_HATCH_HPP #include -#include +#include + +#define FAKE_BUTTON_QUEUE_SIZE 10 class Hatch { @@ -33,7 +35,7 @@ class Hatch void process_queued(); protected: - std::list fake_button_queue; + etl::queue fake_button_queue; }; #endif // YARDFORCE_HATCH_HPP diff --git a/Firmware/CoverUI/platformio.ini b/Firmware/CoverUI/platformio.ini index 3449363..410692e 100644 --- a/Firmware/CoverUI/platformio.ini +++ b/Firmware/CoverUI/platformio.ini @@ -317,6 +317,9 @@ build_flags = -DMCU_STM32 -DMDL_RMECOWV100 +lib_deps = + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f YardForce/util/stlink-stm.cfg @@ -345,6 +348,9 @@ build_flags = -DMOD_EMERGENCY -DMOD_STOP +lib_deps = + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f YardForce/util/stlink-stm.cfg @@ -373,6 +379,9 @@ build_flags = -DMOD_EMERGENCY -DMOD_HALL +lib_deps = + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f YardForce/util/stlink-stm.cfg @@ -402,6 +411,9 @@ build_flags = -DMOD_HALL -DMOD_STOP +lib_deps = + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f YardForce/util/stlink-stm.cfg @@ -431,6 +443,9 @@ build_flags = -DMCU_STM32 -DMDL_RMECOWV110 +lib_deps = + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f YardForce/util/stlink-stm.cfg @@ -460,6 +475,9 @@ build_flags = -DMOD_EMERGENCY -DMOD_HALL +lib_deps = + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f YardForce/util/stlink-stm.cfg @@ -490,6 +508,9 @@ build_flags = -DMOD_HALL -DMOD_STOP +lib_deps = + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f YardForce/util/stlink-stm.cfg @@ -519,6 +540,9 @@ build_flags = -DMOD_EMERGENCY -DMOD_STOP +lib_deps = + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f YardForce/util/stlink-stm.cfg @@ -552,6 +576,9 @@ build_flags = -DMCU_GD32 -DMDL_RMECOWV110 +lib_deps = + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f YardForce/util/stlink-gd.cfg @@ -584,6 +611,9 @@ build_flags = -DMOD_EMERGENCY -DMOD_HALL +lib_deps = + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f YardForce/util/stlink-gd.cfg @@ -617,6 +647,9 @@ build_flags = -DMOD_HALL -DMOD_STOP +lib_deps = + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f YardForce/util/stlink-gd.cfg @@ -649,6 +682,9 @@ build_flags = -DMOD_EMERGENCY -DMOD_STOP +lib_deps = + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f YardForce/util/stlink-gd.cfg @@ -687,7 +723,9 @@ build_flags = -DLV_LVGL_H_INCLUDE_SIMPLE -IYardForce ; Required by LVGL to find his lv_conf.h -lib_deps = lvgl/lvgl@^8.3.9 +lib_deps = + lvgl/lvgl@^8.3.9 + etlcpp/Embedded Template Library @ ^20.39.4 debug_build_flags = -O0 -g2 -ggdb2 @@ -715,7 +753,9 @@ build_flags = -DLV_LVGL_H_INCLUDE_SIMPLE -IYardForce ; Required by LVGL to find his lv_conf.h -lib_deps = lvgl/lvgl@^8.3.9 +lib_deps = + lvgl/lvgl@^8.3.9 + etlcpp/Embedded Template Library @ ^20.39.4 debug_build_flags = -O0 -g2 -ggdb2 @@ -744,7 +784,9 @@ build_flags = -DLV_LVGL_H_INCLUDE_SIMPLE -IYardForce ; Required by LVGL to find his lv_conf.h -lib_deps = lvgl/lvgl@^8.3.9 +lib_deps = + lvgl/lvgl@^8.3.9 + etlcpp/Embedded Template Library @ ^20.39.4 debug_build_flags = -O0 -g2 -ggdb2 @@ -772,7 +814,9 @@ build_flags = -DLV_LVGL_H_INCLUDE_SIMPLE -IYardForce ; Required by LVGL to find his lv_conf.h -lib_deps = lvgl/lvgl@^8.3.9 +lib_deps = + lvgl/lvgl@^8.3.9 + etlcpp/Embedded Template Library @ ^20.39.4 debug_build_flags = -O0 -g2 -ggdb2 @@ -804,7 +848,10 @@ build_flags = -DLV_LVGL_H_INCLUDE_SIMPLE -IYardForce ; Required by LVGL to find his lv_conf.h -lib_deps = lvgl/lvgl@^8.3.9 +lib_deps = + lvgl/lvgl@^8.3.9 + etlcpp/Embedded Template Library @ ^20.39.4 + upload_flags = -f, target/stm32f0x.cfg upload_command = openocd -f interface/stlink.cfg -c "transport select hla_swd" $UPLOAD_FLAGS -c "init; reset halt; stm32f0x unlock 0; reset run" -c "program {$SOURCE} verify reset; shutdown;"