Merge pull request #104 from suchmememanyskill/dev

Clear memory before doing OTA
This commit is contained in:
Sims
2024-05-28 22:15:23 +02:00
committed by GitHub
5 changed files with 42 additions and 17 deletions

View File

@@ -9,9 +9,8 @@
// Always has +1 entry with a null'd name // Always has +1 entry with a null'd name
FILESYSTEM_FILE* last_query = NULL; FILESYSTEM_FILE* last_query = NULL;
FILESYSTEM_FILE* get_files(int limit){ void clear_files()
freeze_request_thread(); {
if (last_query != NULL){ if (last_query != NULL){
FILESYSTEM_FILE* current = last_query; FILESYSTEM_FILE* current = last_query;
@@ -21,7 +20,14 @@ FILESYSTEM_FILE* get_files(int limit){
} }
free(last_query); 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()); Serial.printf("Heap space pre-file-parse: %d bytes\n", esp_get_free_heap_size());
std::list<FILESYSTEM_FILE> files; std::list<FILESYSTEM_FILE> files;

View File

@@ -20,3 +20,4 @@ typedef struct _FILESYSTEM_FILE {
} FILESYSTEM_FILE; } FILESYSTEM_FILE;
FILESYSTEM_FILE* get_files(int limit); FILESYSTEM_FILE* get_files(int limit);
void clear_files();

View File

@@ -12,6 +12,15 @@ static char* power_devices[16] = {0};
static bool power_device_states[16] = {0}; static bool power_device_states[16] = {0};
static unsigned int stored_power_devices_count = 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) MACROSQUERY macros_query(PRINTER_CONFIG * config)
{ {
HTTPClient client; HTTPClient client;
@@ -24,11 +33,7 @@ MACROSQUERY macros_query(PRINTER_CONFIG * config)
deserializeJson(doc, client.getStream()); deserializeJson(doc, client.getStream());
auto result = doc["result"].as<JsonObject>(); auto result = doc["result"].as<JsonObject>();
for (int i = 0; i < macros_count; i++){ macros_clear();
free(macros[i]);
}
macros_count = 0;
for (JsonPair i : result){ for (JsonPair i : result){
const char *key = i.key().c_str(); const char *key = i.key().c_str();
@@ -85,6 +90,15 @@ unsigned int macro_count()
return macro_count(get_current_printer_config()); 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) POWERQUERY power_devices_query(PRINTER_CONFIG * config)
{ {
HTTPClient client; HTTPClient client;
@@ -97,11 +111,7 @@ POWERQUERY power_devices_query(PRINTER_CONFIG * config)
deserializeJson(doc, client.getStream()); deserializeJson(doc, client.getStream());
auto result = doc["result"]["devices"].as<JsonArray>(); auto result = doc["result"]["devices"].as<JsonArray>();
for (int i = 0; i < stored_power_devices_count; i++){ power_devices_clear();
free(power_devices[i]);
}
stored_power_devices_count = 0;
for (auto i : result){ for (auto i : result){
const char * device_name = i["device"]; const char * device_name = i["device"];
@@ -154,8 +164,6 @@ unsigned int power_devices_count()
return power_devices_count(get_current_printer_config()); return power_devices_count(get_current_printer_config());
} }
bool set_power_state(const char* device_name, bool state, PRINTER_CONFIG * config) bool set_power_state(const char* device_name, bool state, PRINTER_CONFIG * config)
{ {
HTTPClient client; HTTPClient client;

View File

@@ -23,3 +23,5 @@ unsigned int power_devices_count(PRINTER_CONFIG * config);
unsigned int power_devices_count(); 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, 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();

View File

@@ -5,6 +5,9 @@
#include "../core/data_setup.h" #include "../core/data_setup.h"
#include "../conf/global_config.h" #include "../conf/global_config.h"
#include "ota_setup.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://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 const char *ota_url = "https://suchmememanyskill.github.io/CYD-Klipper/OTA.json"; // Prod url
@@ -74,6 +77,11 @@ void ota_do_update(bool variant_automatic)
lv_timer_handler(); lv_timer_handler();
lv_task_handler(); lv_task_handler();
macros_clear();
power_devices_clear();
clear_files();
clear_img_mem();
ota_pull.SetCallback(do_update_callback); ota_pull.SetCallback(do_update_callback);
ota_pull.CheckForOTAUpdate(ota_url, REPO_VERSION, ESP32OTAPull::ActionType::UPDATE_AND_BOOT); ota_pull.CheckForOTAUpdate(ota_url, REPO_VERSION, ESP32OTAPull::ActionType::UPDATE_AND_BOOT);
} }