From a02ff0651c7b8044af9733358c0936abe639db8a Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Wed, 13 Sep 2023 07:45:11 +0200 Subject: [PATCH] Return try-load reporting to serial --- Firmware/mmu2.cpp | 2 +- Firmware/mmu2_reporting.cpp | 19 +++++++++++++++++++ Firmware/mmu2_reporting.h | 12 ++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index b46b51c3a..4d9c89063 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -300,7 +300,7 @@ bool MMU2::VerifyFilamentEnteredPTFE() { if (!filament_inserted) { IncrementLoadFails(); } - + tlur.DumpToSerial(); return filament_inserted; } diff --git a/Firmware/mmu2_reporting.cpp b/Firmware/mmu2_reporting.cpp index ac037aeb9..fd6a66b63 100644 --- a/Firmware/mmu2_reporting.cpp +++ b/Firmware/mmu2_reporting.cpp @@ -304,6 +304,7 @@ TryLoadUnloadReporter::TryLoadUnloadReporter(float delta_mm) // Clear the status line lcd_set_cursor(0, 3); lcd_space(LCD_WIDTH); + static_assert(LCD_WIDTH < 32); // for progress bits } void TryLoadUnloadReporter::Render(uint8_t col, bool sensorState) { @@ -320,9 +321,27 @@ void TryLoadUnloadReporter::Progress(bool sensorState){ dpixel0 = dpixel1; if (lcd_cursor_col > (LCD_WIDTH - 1)) lcd_cursor_col = LCD_WIDTH - 1; Render(lcd_cursor_col++, sensorState); + progress.dw <<= 1; + if(sensorState){ + progress.bytes[0] |= 1; + } } } +void TryLoadUnloadReporter::DumpToSerial(){ + char buf[LCD_WIDTH + 1]; + PU tmpProgress { progress.dw }; // avoid storing the shifted progress back into the memory - saves 4 instructions ;) + + // fill the buffer from the back - the last recorded fs state shall be printed as the last character + // i < 0xff means we go from LCD_WIDTH-1 down to zero included (LCD_WIDTH-1 is less than 0xff) + for (uint8_t i = LCD_WIDTH - 1; i < 0xff; --i) { + buf[i] = (tmpProgress.bytes[0] & 1) + '0'; + tmpProgress.dw >>= 1; + } + buf[LCD_WIDTH] = 0; + MMU2_ECHO_MSGLN(buf); +} + void IncrementLoadFails(){ eeprom_increment_byte((uint8_t *)EEPROM_MMU_LOAD_FAIL); eeprom_increment_word((uint16_t *)EEPROM_MMU_LOAD_FAIL_TOT); diff --git a/Firmware/mmu2_reporting.h b/Firmware/mmu2_reporting.h index 5705efc47..a5c3b6583 100644 --- a/Firmware/mmu2_reporting.h +++ b/Firmware/mmu2_reporting.h @@ -50,6 +50,7 @@ void ReportProgressHook(CommandInProgress cip, ProgressCode ec); struct TryLoadUnloadReporter { TryLoadUnloadReporter(float delta_mm); void Progress(bool sensorState); + void DumpToSerial(); private: /// @brief Add one block to the progress bar @@ -64,6 +65,17 @@ private: // Note: Below is the reciprocal of (2 * delta_mm) / LCD_WIDTH [mm/pixel] float pixel_per_mm; uint8_t lcd_cursor_col; + + // Beware: needs to be a union to optimize for the 8bit better + union __attribute__((packed)) PU { + uint32_t dw; + uint8_t bytes[4]; + constexpr PU() + : dw(0) {} + constexpr PU(uint32_t dw) + : dw(dw) {} + } progress; + static_assert(sizeof(PU) == 4); }; /// Remders the sensor status line. Also used by the "resume temperature" screen.