Skip to content

Commit

Permalink
Merge pull request #104 from suchmememanyskill/dev
Browse files Browse the repository at this point in the history
Clear memory before doing OTA
  • Loading branch information
suchmememanyskill committed May 28, 2024
2 parents 98c7364 + d22a9e1 commit c640d7f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
12 changes: 9 additions & 3 deletions CYD-Klipper/src/core/files_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
// Always has +1 entry with a null'd name
FILESYSTEM_FILE* last_query = NULL;

FILESYSTEM_FILE* get_files(int limit){
freeze_request_thread();

void clear_files()
{
if (last_query != NULL){
FILESYSTEM_FILE* current = last_query;

Expand All @@ -21,7 +20,14 @@ FILESYSTEM_FILE* get_files(int limit){
}

free(last_query);
last_query = NULL;
}
}

FILESYSTEM_FILE* get_files(int limit)
{
freeze_request_thread();
clear_files();

Serial.printf("Heap space pre-file-parse: %d bytes\n", esp_get_free_heap_size());
std::list<FILESYSTEM_FILE> files;
Expand Down
3 changes: 2 additions & 1 deletion CYD-Klipper/src/core/files_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ typedef struct _FILESYSTEM_FILE {
float modified;
} FILESYSTEM_FILE;

FILESYSTEM_FILE* get_files(int limit);
FILESYSTEM_FILE* get_files(int limit);
void clear_files();
32 changes: 20 additions & 12 deletions CYD-Klipper/src/core/macros_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ static char* power_devices[16] = {0};
static bool power_device_states[16] = {0};
static unsigned int stored_power_devices_count = 0;

void macros_clear()
{
for (int i = 0; i < macros_count; i++){
free(macros[i]);
}

macros_count = 0;
}

MACROSQUERY macros_query(PRINTER_CONFIG * config)
{
HTTPClient client;
Expand All @@ -24,11 +33,7 @@ MACROSQUERY macros_query(PRINTER_CONFIG * config)
deserializeJson(doc, client.getStream());
auto result = doc["result"].as<JsonObject>();

for (int i = 0; i < macros_count; i++){
free(macros[i]);
}

macros_count = 0;
macros_clear();

for (JsonPair i : result){
const char *key = i.key().c_str();
Expand Down Expand Up @@ -85,6 +90,15 @@ unsigned int macro_count()
return macro_count(get_current_printer_config());
}

void power_devices_clear()
{
for (int i = 0; i < stored_power_devices_count; i++){
free(power_devices[i]);
}

stored_power_devices_count = 0;
}

POWERQUERY power_devices_query(PRINTER_CONFIG * config)
{
HTTPClient client;
Expand All @@ -97,11 +111,7 @@ POWERQUERY power_devices_query(PRINTER_CONFIG * config)
deserializeJson(doc, client.getStream());
auto result = doc["result"]["devices"].as<JsonArray>();

for (int i = 0; i < stored_power_devices_count; i++){
free(power_devices[i]);
}

stored_power_devices_count = 0;
power_devices_clear();

for (auto i : result){
const char * device_name = i["device"];
Expand Down Expand Up @@ -154,8 +164,6 @@ unsigned int power_devices_count()
return power_devices_count(get_current_printer_config());
}



bool set_power_state(const char* device_name, bool state, PRINTER_CONFIG * config)
{
HTTPClient client;
Expand Down
4 changes: 3 additions & 1 deletion CYD-Klipper/src/core/macros_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ POWERQUERY power_devices_query();
unsigned int power_devices_count(PRINTER_CONFIG * config);
unsigned int power_devices_count();
bool set_power_state(const char* device_name, bool state, PRINTER_CONFIG * config);
bool set_power_state(const char* device_name, bool state);
bool set_power_state(const char* device_name, bool state);
void macros_clear();
void power_devices_clear();
8 changes: 8 additions & 0 deletions CYD-Klipper/src/ui/ota_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "../core/data_setup.h"
#include "../conf/global_config.h"
#include "ota_setup.h"
#include "../core/macros_query.h"
#include "../core/files_query.h"
#include "gcode_img.h"

//const char *ota_url = "https://gist.githubusercontent.com/suchmememanyskill/ece418fe199e155340de6c224a0badf2/raw/0d6762d68bc807cbecc71e40d55b76692397a7b3/update.json"; // Test url
const char *ota_url = "https://suchmememanyskill.github.io/CYD-Klipper/OTA.json"; // Prod url
Expand Down Expand Up @@ -74,6 +77,11 @@ void ota_do_update(bool variant_automatic)
lv_timer_handler();
lv_task_handler();

macros_clear();
power_devices_clear();
clear_files();
clear_img_mem();

ota_pull.SetCallback(do_update_callback);
ota_pull.CheckForOTAUpdate(ota_url, REPO_VERSION, ESP32OTAPull::ActionType::UPDATE_AND_BOOT);
}
Expand Down

0 comments on commit c640d7f

Please sign in to comment.