Skip to content

Commit

Permalink
Fix #10
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Jan 6, 2024
1 parent 7c786d1 commit 91920a6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CYD-Klipper/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ lib_deps =
lvgl/lvgl@^8.3.9
https://github.com/Bodmer/TFT_eSPI.git
https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
bblanchon/ArduinoJson@^6.21.3
bblanchon/ArduinoJson@^7.0.0
monitor_filters = esp32_exception_decoder
build_flags =
-DLV_CONF_PATH="../../../../src/conf/lv_conf.h"
-DUSER_SETUP_LOADED=1
Expand Down
6 changes: 3 additions & 3 deletions CYD-Klipper/src/core/data_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ void fetch_printer_data()
char buff[256] = {};
sprintf(buff, "http://%s:%d/printer/objects/query?extruder&heater_bed&toolhead&gcode_move&virtual_sdcard&print_stats&webhooks", global_config.klipperHost, global_config.klipperPort);
HTTPClient client;
client.useHTTP10(true);
client.begin(buff);
int httpCode = client.GET();
if (httpCode == 200)
{
klipper_request_consecutive_fail_count = 0;
String payload = client.getString();
DynamicJsonDocument doc(4096);
deserializeJson(doc, payload);
JsonDocument doc;
deserializeJson(doc, client.getStream());
auto status = doc["result"]["status"];
bool emit_state_update = false;
int printer_state = printer.state;
Expand Down
15 changes: 10 additions & 5 deletions CYD-Klipper/src/core/files_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,28 @@ FILESYSTEM_FILE* get_files(){

free(last_query);
}

Serial.printf("Heap space pre-file-parse: %d bytes\n", esp_get_free_heap_size());
std::list<FILESYSTEM_FILE> files;
char buff[256] = {};
sprintf(buff, "http://%s:%d/server/files/list", global_config.klipperHost, global_config.klipperPort);
HTTPClient client;
client.useHTTP10(true);
client.begin(buff);
int httpCode = client.GET();
int count = 0;
if (httpCode == 200){
String payload = client.getString();
DynamicJsonDocument doc(60000);
auto a = deserializeJson(doc, payload);
Serial.printf("JSON PARSE: %s\n", a.c_str());
JsonDocument doc;
auto parseResult = deserializeJson(doc, client.getStream());
Serial.printf("Json parse: %s\n", parseResult.c_str());
auto result = doc["result"].as<JsonArray>();
for (auto file : result){
FILESYSTEM_FILE f = {0};
const char* path = file["path"];
f.name = (char*)malloc(strlen(path) + 1);
if (f.name == NULL){
Serial.println("Failed to allocate memory");
continue;
}
strcpy(f.name, path);
f.modified = file["modified"];
files.push_back(f);
Expand All @@ -62,6 +66,7 @@ FILESYSTEM_FILE* get_files(){
result += 1;
}

Serial.printf("Heap space post-file-parse: %d bytes\n", esp_get_free_heap_size());
unfreeze_request_thread();
return last_query;
}
6 changes: 3 additions & 3 deletions CYD-Klipper/src/core/macros_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ static void on_state_change(void * s, lv_msg_t * m) {

String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/printer/gcode/help";
HTTPClient client;
client.useHTTP10(true);
client.begin(url.c_str());
int httpCode = client.GET();
if (httpCode == 200){
String payload = client.getString();
DynamicJsonDocument doc(16384);
deserializeJson(doc, payload);
JsonDocument doc;
deserializeJson(doc, client.getStream());
auto result = doc["result"].as<JsonObject>();

for (int i = 0; i < macros_count; i++){
Expand Down

0 comments on commit 91920a6

Please sign in to comment.