8-bit proposed changes

The status line code is not nice, but we need to work around it
so the status line rendering works correctly

This commit mostly reapplies the code
from 3.13.2

Also fixes compiler warnings
This commit is contained in:
gudnimg 2023-09-16 13:30:56 +00:00 committed by DRracer
parent ea01012026
commit 4134bf4f40
2 changed files with 17 additions and 30 deletions

View File

@ -301,17 +301,20 @@ TryLoadUnloadReporter::TryLoadUnloadReporter(float delta_mm)
, lcd_cursor_col(0) , lcd_cursor_col(0)
, pixel_per_mm(0.5F * float(LCD_WIDTH) / (delta_mm)) , pixel_per_mm(0.5F * float(LCD_WIDTH) / (delta_mm))
{ {
// Clear the status line lcd_clearstatus();
lcd_set_cursor(0, 3); }
lcd_space(LCD_WIDTH);
static_assert(LCD_WIDTH < 32); // for progress bits TryLoadUnloadReporter::~TryLoadUnloadReporter() {
// Delay the next status message just so
// the user can see the results clearly
lcd_reset_status_message_timeout();
} }
void TryLoadUnloadReporter::Render(uint8_t col, bool sensorState) { void TryLoadUnloadReporter::Render(uint8_t col, bool sensorState) {
// Set the cursor position each time in case some other // Set the cursor position each time in case some other
// part of the firmware changes the cursor position // part of the firmware changes the cursor position
lcd_putc_at(col, 3, sensorState ? '-' : LCD_STR_SOLID_BLOCK[0]); lcd_insert_char_into_status(col, sensorState ? LCD_STR_SOLID_BLOCK[0] : '-');
lcd_reset_status_message_timeout(); if (!lcd_update_enabled) lcdui_print_status_line();
} }
void TryLoadUnloadReporter::Progress(bool sensorState){ void TryLoadUnloadReporter::Progress(bool sensorState){
@ -321,22 +324,16 @@ void TryLoadUnloadReporter::Progress(bool sensorState){
dpixel0 = dpixel1; dpixel0 = dpixel1;
if (lcd_cursor_col > (LCD_WIDTH - 1)) lcd_cursor_col = LCD_WIDTH - 1; if (lcd_cursor_col > (LCD_WIDTH - 1)) lcd_cursor_col = LCD_WIDTH - 1;
Render(lcd_cursor_col++, sensorState); Render(lcd_cursor_col++, sensorState);
progress.dw <<= 1;
if(sensorState){
progress.bytes[0] |= 1;
}
} }
} }
void TryLoadUnloadReporter::DumpToSerial(){ void TryLoadUnloadReporter::DumpToSerial(){
char buf[LCD_WIDTH + 1]; char buf[LCD_WIDTH + 1];
PU tmpProgress { progress.dw }; // avoid storing the shifted progress back into the memory - saves 4 instructions ;) lcd_getstatus(buf);
for (uint8_t i = 0; i < sizeof(buf); i++) {
// fill the buffer from the back - the last recorded fs state shall be printed as the last character // 0xFF is -1 when converting from unsigned to signed char
// i < 0xff means we go from LCD_WIDTH-1 down to zero included (LCD_WIDTH-1 is less than 0xff) // If the number is negative, that means filament is present
for (uint8_t i = LCD_WIDTH - 1; i < 0xff; --i) { buf[i] = (buf[i] < 0) ? '1' : '0';
buf[i] = (tmpProgress.bytes[0] & 1) + '0';
tmpProgress.dw >>= 1;
} }
buf[LCD_WIDTH] = 0; buf[LCD_WIDTH] = 0;
MMU2_ECHO_MSGLN(buf); MMU2_ECHO_MSGLN(buf);

View File

@ -49,6 +49,7 @@ void ReportProgressHook(CommandInProgress cip, ProgressCode ec);
struct TryLoadUnloadReporter { struct TryLoadUnloadReporter {
TryLoadUnloadReporter(float delta_mm); TryLoadUnloadReporter(float delta_mm);
~TryLoadUnloadReporter();
void Progress(bool sensorState); void Progress(bool sensorState);
void DumpToSerial(); void DumpToSerial();
@ -58,24 +59,13 @@ private:
/// @param sensorState if true, filament is not present, else filament is present. This controls which character to render /// @param sensorState if true, filament is not present, else filament is present. This controls which character to render
void Render(uint8_t col, bool sensorState); void Render(uint8_t col, bool sensorState);
uint8_t dpixel1;
uint8_t dpixel0; uint8_t dpixel0;
uint8_t dpixel1;
uint8_t lcd_cursor_col;
// The total length is twice delta_mm. Divide that length by number of pixels // The total length is twice delta_mm. Divide that length by number of pixels
// available to get length per pixel. // available to get length per pixel.
// Note: Below is the reciprocal of (2 * delta_mm) / LCD_WIDTH [mm/pixel] // Note: Below is the reciprocal of (2 * delta_mm) / LCD_WIDTH [mm/pixel]
float pixel_per_mm; 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. /// Remders the sensor status line. Also used by the "resume temperature" screen.