From 9875e85e3130bf8d4725d4bcad49c595b0128597 Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Fri, 20 Feb 2026 17:39:49 +0100 Subject: [PATCH] feat: enhance weight handling and display feedback in API and NFC modules --- src/api.cpp | 24 +++++++++++++++++++++++- src/display.cpp | 13 +++++++++++++ src/display.h | 1 + src/main.cpp | 16 +++++++++------- src/nfc.cpp | 2 ++ 5 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/api.cpp b/src/api.cpp index 3a641f6..60fa076 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -105,8 +105,30 @@ bool sendWeight(int spoolId, String tagUuid, float measuredWeight) { String payload; serializeJson(doc, payload); int httpCode = http.POST(payload); + + if (httpCode == 200) { + String response = http.getString(); + JsonDocument responseDoc; + DeserializationError error = deserializeJson(responseDoc, response); + if (!error && responseDoc["remaining_weight_g"].is()) { + int remaining = (int)responseDoc["remaining_weight_g"].as(); + pauseMainTask = 1; + oledShowRemainingWeight(remaining); + vTaskDelay(pdMS_TO_TICKS(3000)); + pauseMainTask = 0; + } + http.end(); + return true; + } + else { + pauseMainTask = 1; + oledShowProgressBar(1, 1, "Failure", "API Error"); + vTaskDelay(pdMS_TO_TICKS(2000)); + pauseMainTask = 0; + } + http.end(); - return (httpCode == 200); + return false; } bool sendLocation(int spoolId, String spoolTagUuid, int locationId, String locationTagUuid) { diff --git a/src/display.cpp b/src/display.cpp index aadbbcc..663aee1 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -254,6 +254,19 @@ void oledShowWeight(uint16_t weight) { display.display(); } +void oledShowRemainingWeight(uint16_t remainingWeight) { + oledcleardata(); + display.setTextSize(1); + display.setCursor(oled_center_h("Weight sent, rest:"), OLED_DATA_START + 4); + display.print("Weight sent, rest:"); + + display.setTextSize(3); + String weightStr = String(remainingWeight) + " g"; + display.setCursor(oled_center_h(weightStr), OLED_DATA_START + 22); + display.print(weightStr); + display.display(); +} + void oledShowConnectionError(const char* error, const String& ip) { oledcleardata(); display.setTextSize(1); diff --git a/src/display.h b/src/display.h index 0bf736d..d2b60cd 100644 --- a/src/display.h +++ b/src/display.h @@ -19,6 +19,7 @@ int oled_center_v(const String &text); void oledShowProgressBar(const uint8_t step, const uint8_t numSteps, const char* largeText, const char* statusMessage); void oledShowWeight(uint16_t weight); +void oledShowRemainingWeight(uint16_t remainingWeight); void oledDisplayText(const String &message, uint8_t size = 2); void oledShowConnectionError(const char* error, const String& ip); void oledShowTopRow(); diff --git a/src/main.cpp b/src/main.cpp index afd28e2..7135bd1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -162,7 +162,7 @@ void loop() { { // Use filtered weight for smooth display, but still check API weight for significant changes int16_t displayWeight = getFilteredDisplayWeight(); - if (mainTaskWasPaused || (weight != lastWeight && nfcReaderState == NFC_IDLE)) + if (mainTaskWasPaused || (weight != lastWeight && (nfcReaderState == NFC_IDLE || tagProcessed))) { (displayWeight < 2) ? ((displayWeight < -2) ? oledDisplayText("!! -0") : oledShowWeight(0)) : oledShowWeight(displayWeight); } @@ -191,12 +191,6 @@ void loop() { } } - // reset weight counter after writing tag - if (currentMillis - lastWeightReadTime >= weightReadInterval && nfcReaderState != NFC_IDLE && nfcReaderState != NFC_READ_SUCCESS) - { - weightCounterToApi = 0; - } - lastWeight = weight; // Wenn ein Tag erkannt wurde und das Gewicht stabil ist, an FilaMan senden @@ -211,6 +205,10 @@ void loop() { sendWeightAsync(sId, activeTagUuid, weight); weightSend = 1; Serial.println("Weight queued for FilaMan"); + + // Feedback to user + pauseMainTask = 1; + oledShowProgressBar(3, 4, "Spool Tag", "Sending..."); } // Handle successful tag write @@ -221,6 +219,10 @@ void loop() { sendWeightAsync(sId, activeTagUuid, weight); weightSend = 1; Serial.println("Weight queued for FilaMan after tag write"); + + // Feedback to user + pauseMainTask = 1; + oledShowProgressBar(3, 4, "Tag written", "Sending..."); } } diff --git a/src/nfc.cpp b/src/nfc.cpp index 8549a59..ada1596 100644 --- a/src/nfc.cpp +++ b/src/nfc.cpp @@ -2025,6 +2025,7 @@ void scanRfidTask(void * parameter) { nfcJsonData = ""; activeSpoolId = ""; activeTagUuid = ""; + tagProcessed = false; oledShowWeight(weight); } @@ -2032,6 +2033,7 @@ void scanRfidTask(void * parameter) { else if (!success && nfcReaderState == NFC_READ_SUCCESS) { nfcReaderState = NFC_IDLE; + tagProcessed = false; Serial.println("Tag nach erfolgreichem Lesen entfernt - bereit für nächsten Tag"); }