mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-20 21:23:25 +00:00
Merge pull request #104 from suchmememanyskill/dev
Clear memory before doing OTA
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
@@ -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;
|
||||
@@ -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();
|
||||
@@ -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;
|
||||
@@ -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"];
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user