From 339d2a7bf39da3b1990bdd6431b46a55e3fabc0b Mon Sep 17 00:00:00 2001 From: lost-hope Date: Thu, 23 Feb 2023 19:47:27 +0100 Subject: [PATCH] Added spreading from center and fixed the enable --- .../usermod_v2_klipper_percentage/readme.md | 2 + .../usermod_v2_klipper_percentage.h | 63 +++++++++++-------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/usermods/usermod_v2_klipper_percentage/readme.md b/usermods/usermod_v2_klipper_percentage/readme.md index a1581cf2..0619bf85 100644 --- a/usermods/usermod_v2_klipper_percentage/readme.md +++ b/usermods/usermod_v2_klipper_percentage/readme.md @@ -30,6 +30,8 @@ IP adress of your Klipper instance you want to poll. ESP has to be restarted aft 1 = reversed +2 = center + ----- Author: diff --git a/usermods/usermod_v2_klipper_percentage/usermod_v2_klipper_percentage.h b/usermods/usermod_v2_klipper_percentage/usermod_v2_klipper_percentage.h index 0bd798d5..0e19cc80 100644 --- a/usermods/usermod_v2_klipper_percentage/usermod_v2_klipper_percentage.h +++ b/usermods/usermod_v2_klipper_percentage/usermod_v2_klipper_percentage.h @@ -70,34 +70,36 @@ public: void loop() { - - if (WLED_CONNECTED) + if (enabled) { - if (millis() - lastTime > 10000) + if (WLED_CONNECTED) { - httpGet(wifiClient, errorMessage); - if (strcmp(errorMessage, "") == 0) + if (millis() - lastTime > 10000) { - PSRAMDynamicJsonDocument klipperDoc(4096); // in practive about 2673 - DeserializationError error = deserializeJson(klipperDoc, wifiClient); - if (error) + httpGet(wifiClient, errorMessage); + if (strcmp(errorMessage, "") == 0) { - strcat(errorMessage, PSTR("deserializeJson() failed: ")); - strcat(errorMessage, error.c_str()); - } - printPercent = (int)(klipperDoc["result"]["status"]["virtual_sdcard"]["progress"].as() * 100); + PSRAMDynamicJsonDocument klipperDoc(4096); // in practive about 2673 + DeserializationError error = deserializeJson(klipperDoc, wifiClient); + if (error) + { + strcat(errorMessage, PSTR("deserializeJson() failed: ")); + strcat(errorMessage, error.c_str()); + } + printPercent = (int)(klipperDoc["result"]["status"]["virtual_sdcard"]["progress"].as() * 100); - DEBUG_PRINT("Percent: "); - DEBUG_PRINTLN((int)(klipperDoc["result"]["status"]["virtual_sdcard"]["progress"].as() * 100)); - DEBUG_PRINT("LEDs: "); - DEBUG_PRINTLN(strip.getLengthTotal() * printPercent / 100); + DEBUG_PRINT("Percent: "); + DEBUG_PRINTLN((int)(klipperDoc["result"]["status"]["virtual_sdcard"]["progress"].as() * 100)); + DEBUG_PRINT("LEDs: "); + DEBUG_PRINTLN(direction == 2 ? (strip.getLengthTotal() / 2) * printPercent / 100 : strip.getLengthTotal() * printPercent / 100); + } + else + { + DEBUG_PRINTLN(errorMessage); + DEBUG_PRINTLN(ip); + } + lastTime = millis(); } - else - { - DEBUG_PRINTLN(errorMessage); - DEBUG_PRINTLN(ip); - } - lastTime = millis(); } } } @@ -129,7 +131,6 @@ public: * Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI. * Below it is shown how this could be used for e.g. a light sensor */ - /* TODO: NOT WORKING YET void addToJsonInfo(JsonObject &root) { JsonObject user = root["u"]; @@ -149,7 +150,6 @@ public: infoArr.add(uiDomString); } - void addToJsonState(JsonObject &root) { JsonObject usermod = root[FPSTR(_name)]; @@ -170,7 +170,6 @@ public: } } } - */ /* * handleOverlayDraw() is called just before every show() (LED strip update frame) after effects have set the colors. @@ -188,13 +187,25 @@ public: strip.setPixelColor(i, strip.getSegment(0).colors[1]); } } - else // reversed + else if (direction == 1) // reversed { for (int i = 0; i < strip.getLengthTotal() * printPercent / 100; i++) { strip.setPixelColor(strip.getLengthTotal() - i, strip.getSegment(0).colors[1]); } } + else if (direction == 2) // center + { + for (int i = 0; i < (strip.getLengthTotal() / 2) * printPercent / 100; i++) + { + strip.setPixelColor((strip.getLengthTotal() / 2) + i, strip.getSegment(0).colors[1]); + strip.setPixelColor((strip.getLengthTotal() / 2) - i, strip.getSegment(0).colors[1]); + } + } + else + { + direction = 0; + } } }