Skip to content

Commit

Permalink
Fix heap overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehaenger committed Sep 30, 2024
1 parent 0efe317 commit a730298
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 25 deletions.
24 changes: 9 additions & 15 deletions Firmware/CoverUI/YardForce/Hatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Arduino.h>
// #include <stdint.h>
#include <list>
// #include "include/Hatch.hpp"
// #include "include/LEDcontrol.hpp"

#include "include/main.h"

/**
Expand All @@ -38,23 +35,20 @@ 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});
};

/**
* @brief Loop over fake_button_queue and process(send) ready ones
*/
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();
}
};
12 changes: 7 additions & 5 deletions Firmware/CoverUI/YardForce/include/Hatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Arduino.h>
#include <list>
#include <etl/queue.h>

#define FAKE_BUTTON_QUEUE_SIZE 10

class Hatch
{
Expand All @@ -33,7 +35,7 @@ class Hatch
void process_queued();

protected:
std::list<FakeButton> fake_button_queue;
etl::queue<FakeButton, FAKE_BUTTON_QUEUE_SIZE, etl::memory_model::MEMORY_MODEL_SMALL> fake_button_queue;
};

#endif // YARDFORCE_HATCH_HPP
57 changes: 52 additions & 5 deletions Firmware/CoverUI/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;"
Expand Down

0 comments on commit a730298

Please sign in to comment.