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)
, pixel_per_mm(0.5F * float(LCD_WIDTH) / (delta_mm))
{
// Clear the status line
lcd_set_cursor(0, 3);
lcd_space(LCD_WIDTH);
static_assert(LCD_WIDTH < 32); // for progress bits
lcd_clearstatus();
}
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) {
// Set the cursor position each time in case some other
// part of the firmware changes the cursor position
lcd_putc_at(col, 3, sensorState ? '-' : LCD_STR_SOLID_BLOCK[0]);
lcd_reset_status_message_timeout();
lcd_insert_char_into_status(col, sensorState ? LCD_STR_SOLID_BLOCK[0] : '-');
if (!lcd_update_enabled) lcdui_print_status_line();
}
void TryLoadUnloadReporter::Progress(bool sensorState){
@ -321,22 +324,16 @@ 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;
lcd_getstatus(buf);
for (uint8_t i = 0; i < sizeof(buf); i++) {
// 0xFF is -1 when converting from unsigned to signed char
// If the number is negative, that means filament is present
buf[i] = (buf[i] < 0) ? '1' : '0';
}
buf[LCD_WIDTH] = 0;
MMU2_ECHO_MSGLN(buf);

View File

@ -49,6 +49,7 @@ void ReportProgressHook(CommandInProgress cip, ProgressCode ec);
struct TryLoadUnloadReporter {
TryLoadUnloadReporter(float delta_mm);
~TryLoadUnloadReporter();
void Progress(bool sensorState);
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
void Render(uint8_t col, bool sensorState);
uint8_t dpixel1;
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
// available to get length per pixel.
// 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.