🚸 Optional Cutter/Laser status for HD44780 (#25003)

This commit is contained in:
Thomas Buck
2022-11-27 01:59:13 +01:00
committed by GitHub
parent 8f9d989378
commit 50e3e4d862
19 changed files with 178 additions and 124 deletions

View File

@@ -56,9 +56,9 @@ typedef struct _hd44780_charmap_t {
} hd44780_charmap_t;
#ifdef __AVR__
#define IV(a) U##a
#define IV(a) lchar_t(U##a)
#else
#define IV(a) L##a
#define IV(a) lchar_t(L##a)
#endif
static const hd44780_charmap_t g_hd44780_charmap_device[] PROGMEM = {

View File

@@ -58,6 +58,10 @@
#include "../../feature/bedlevel/bedlevel.h"
#endif
#if HAS_CUTTER
#include "../../feature/spindle_laser.h"
#endif
//
// Create LCD instance and chipset-specific information
//
@@ -406,7 +410,7 @@ void MarlinUI::clear_lcd() { lcd.clear(); }
void lcd_erase_line(const lcd_uint_t line) {
lcd_moveto(0, line);
for (uint8_t i = LCD_WIDTH + 1; --i;)
lcd_put_lchar(' ');
lcd_put_u8str(F(" "));
}
// Scroll the PSTR 'text' in a 'len' wide field for 'time' milliseconds at position col,line
@@ -414,7 +418,7 @@ void MarlinUI::clear_lcd() { lcd.clear(); }
uint8_t slen = utf8_strlen(ftxt);
if (slen < len) {
lcd_put_u8str_max(col, line, ftxt, len);
for (; slen < len; ++slen) lcd_put_lchar(' ');
for (; slen < len; ++slen) lcd_put_u8str(F(" "));
safe_delay(time);
}
else {
@@ -426,7 +430,7 @@ void MarlinUI::clear_lcd() { lcd.clear(); }
lcd_put_u8str_max_P(col, line, p, len);
// Fill with spaces
for (uint8_t ix = slen - i; ix < len; ++ix) lcd_put_lchar(' ');
for (uint8_t ix = slen - i; ix < len; ++ix) lcd_put_u8str(F(" "));
// Delay
safe_delay(dly);
@@ -440,9 +444,9 @@ void MarlinUI::clear_lcd() { lcd.clear(); }
static void logo_lines(FSTR_P const extra) {
int16_t indent = (LCD_WIDTH - 8 - utf8_strlen(extra)) / 2;
lcd_put_lchar(indent, 0, '\x00'); lcd_put_u8str(F( "------" )); lcd_put_lchar('\x01');
lcd_put_lchar(indent, 0, '\x00'); lcd_put_u8str(F( "------" )); lcd_put_u8str(F("\x01"));
lcd_put_u8str(indent, 1, F("|Marlin|")); lcd_put_u8str(extra);
lcd_put_lchar(indent, 2, '\x02'); lcd_put_u8str(F( "------" )); lcd_put_lchar('\x03');
lcd_put_lchar(indent, 2, '\x02'); lcd_put_u8str(F( "------" )); lcd_put_u8str(F("\x03"));
}
void MarlinUI::show_bootscreen() {
@@ -522,7 +526,15 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
lcd_put_u8str(value);
}
/**
* @brief Draw current and target for a heater/cooler
* @details Print at the current LCD position the current/target for a single heater,
* blinking the target temperature of an idle heater has timed out.
*
* @param heater_id The heater ID, such as 0, 1, ..., H_BED, H_CHAMBER, etc.
* @param prefix A char to draw in front (e.g., a thermometer or icon)
* @param blink Flag to show the blink state instead of the regular state
*/
FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char prefix, const bool blink) {
#if HAS_HEATED_BED
const bool isBed = TERN(HAS_HEATED_CHAMBER, heater_id == H_BED, heater_id < 0);
@@ -535,75 +547,74 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char pr
if (prefix >= 0) lcd_put_lchar(prefix);
lcd_put_u8str(t1 < 0 ? "err" : i16tostr3rj(t1));
lcd_put_lchar('/');
lcd_put_u8str(F("/"));
#if !HEATER_IDLE_HANDLER
UNUSED(blink);
#else
if (!blink && thermalManager.heater_idle[thermalManager.idle_index_for_id(heater_id)].timed_out) {
lcd_put_lchar(' ');
if (t2 >= 10) lcd_put_lchar(' ');
if (t2 >= 100) lcd_put_lchar(' ');
}
if (!blink && thermalManager.heater_idle[thermalManager.idle_index_for_id(heater_id)].timed_out)
lcd_put_u8str(F(" "));
else
#endif
lcd_put_u8str(i16tostr3left(t2));
if (prefix >= 0) {
lcd_put_lchar(LCD_STR_DEGREE[0]);
lcd_put_lchar(' ');
if (t2 < 10) lcd_put_lchar(' ');
lcd_put_u8str(F(" "));
if (t2 < 10) lcd_put_u8str(F(" "));
}
}
#if HAS_COOLER
FORCE_INLINE void _draw_cooler_status(const char prefix, const bool blink) {
const celsius_t t2 = thermalManager.degTargetCooler();
if (prefix >= 0) lcd_put_lchar(prefix);
FORCE_INLINE void _draw_cooler_status(const char prefix, const bool blink) {
const celsius_t t2 = thermalManager.degTargetCooler();
lcd_put_u8str(i16tostr3rj(thermalManager.wholeDegCooler()));
lcd_put_lchar('/');
if (prefix >= 0) lcd_put_lchar(prefix);
#if !HEATER_IDLE_HANDLER
UNUSED(blink);
#else
if (!blink && thermalManager.heater_idle[thermalManager.idle_index_for_id(heater_id)].timed_out) {
lcd_put_lchar(' ');
if (t2 >= 10) lcd_put_lchar(' ');
if (t2 >= 100) lcd_put_lchar(' ');
lcd_put_u8str(i16tostr3rj(thermalManager.wholeDegCooler()));
lcd_put_u8str(F("/"));
#if !HEATER_IDLE_HANDLER
UNUSED(blink);
#else
if (!blink && thermalManager.heater_idle[thermalManager.idle_index_for_id(heater_id)].timed_out) {
lcd_put_u8str(F(" "));
if (t2 >= 10) lcd_put_u8str(F(" "));
if (t2 >= 100) lcd_put_u8str(F(" "));
}
else
#endif
lcd_put_u8str(i16tostr3left(t2));
if (prefix >= 0) {
lcd_put_lchar(LCD_STR_DEGREE[0]);
lcd_put_u8str(F(" "));
if (t2 < 10) lcd_put_u8str(F(" "));
}
else
#endif
lcd_put_u8str(i16tostr3left(t2));
if (prefix >= 0) {
lcd_put_lchar(LCD_STR_DEGREE[0]);
lcd_put_lchar(' ');
if (t2 < 10) lcd_put_lchar(' ');
}
}
#endif
#endif // HAS_COOLER
#if ENABLED(LASER_COOLANT_FLOW_METER)
FORCE_INLINE void _draw_flowmeter_status() {
lcd_put_u8str("~");
lcd_put_u8str(F("~"));
lcd_put_u8str(ftostr11ns(cooler.flowrate));
lcd_put_lchar('L');
lcd_put_u8str(F("L"));
}
#endif
#if ENABLED(I2C_AMMETER)
FORCE_INLINE void _draw_ammeter_status() {
lcd_put_u8str(" ");
lcd_put_u8str(F(" "));
ammeter.read();
if (ammeter.current <= 0.999f) {
lcd_put_u8str(ui16tostr3rj(uint16_t(ammeter.current * 1000 + 0.5f)));
lcd_put_u8str("mA");
lcd_put_u8str(F("mA"));
}
else {
lcd_put_u8str(ftostr12ns(ammeter.current));
lcd_put_lchar('A');
lcd_put_u8str(F("A"));
}
}
#endif
@@ -612,6 +623,36 @@ FORCE_INLINE void _draw_bed_status(const bool blink) {
_draw_heater_status(H_BED, TERN0(HAS_LEVELING, blink && planner.leveling_active) ? '_' : LCD_STR_BEDTEMP[0], blink);
}
#if HAS_CUTTER
FORCE_INLINE void _draw_cutter_status() {
lcd_put_u8str(TERN(LASER_FEATURE, GET_TEXT_F(MSG_LASER), GET_TEXT_F(MSG_CUTTER)));
lcd_put_u8str(F(": "));
#if CUTTER_UNIT_IS(RPM)
lcd_put_u8str(ftostr61rj(float(cutter.unitPower) / 1000));
lcd_put_u8str(F("K"));
#else
lcd_put_u8str(cutter_power2str(cutter.unitPower));
#if CUTTER_UNIT_IS(PERCENT)
lcd_put_u8str(F("%"));
#endif
#endif
lcd_put_u8str(F(" "));
lcd_put_u8str(cutter.enabled() ? GET_TEXT_F(MSG_LCD_ON) : GET_TEXT_F(MSG_LCD_OFF));
lcd_put_u8str(F(" "));
switch (cutter.cutter_mode) {
case CUTTER_MODE_STANDARD: lcd_put_u8str(F("S")); break;
case CUTTER_MODE_CONTINUOUS: lcd_put_u8str(F("C")); break;
case CUTTER_MODE_DYNAMIC: lcd_put_u8str(F("D")); break;
case CUTTER_MODE_ERROR: lcd_put_u8str(F("!")); break;
}
}
#endif // HAS_CUTTER
#if ENABLED(LCD_PROGRESS_BAR)
void MarlinUI::draw_progress_bar(const uint8_t percent) {
@@ -654,7 +695,7 @@ void MarlinUI::draw_status_message(const bool blink) {
lcd_put_u8str(ftostr12ns(filwidth.measured_mm));
lcd_put_u8str(F(" V"));
lcd_put_u8str(i16tostr3rj(planner.volumetric_percent(parser.volumetric_enabled)));
lcd_put_lchar('%');
lcd_put_u8str(F("%"));
return;
}
@@ -673,7 +714,7 @@ void MarlinUI::draw_status_message(const bool blink) {
lcd_put_u8str(status_message);
// Fill the rest with spaces
while (slen < LCD_WIDTH) { lcd_put_lchar(' '); ++slen; }
while (slen < LCD_WIDTH) { lcd_put_u8str(F(" ")); ++slen; }
}
else {
// String is larger than the available space in screen.
@@ -687,11 +728,11 @@ void MarlinUI::draw_status_message(const bool blink) {
// If the remaining string doesn't completely fill the screen
if (rlen < LCD_WIDTH) {
uint8_t chars = LCD_WIDTH - rlen; // Amount of space left in characters
lcd_put_lchar(' '); // Always at 1+ spaces left, draw a space
lcd_put_u8str(F(" ")); // Always at 1+ spaces left, draw a space
if (--chars) { // Draw a second space if there's room
lcd_put_lchar(' ');
lcd_put_u8str(F(" "));
if (--chars) { // Draw a third space if there's room
lcd_put_lchar(' ');
lcd_put_u8str(F(" "));
if (--chars)
lcd_put_u8str_max(status_message, chars); // Print a second copy of the message
}
@@ -712,10 +753,7 @@ void MarlinUI::draw_status_message(const bool blink) {
lcd_put_u8str_max(status_message, LCD_WIDTH);
// Fill the rest with spaces if there are missing spaces
while (slen < LCD_WIDTH) {
lcd_put_lchar(' ');
++slen;
}
for (; slen < LCD_WIDTH; ++slen) lcd_put_u8str(F(" "));
#endif
}
@@ -732,7 +770,7 @@ void MarlinUI::draw_status_message(const bool blink) {
lcd_moveto(pc, pr);
lcd_put_u8str(F(TERN(IS_SD_PRINTING, "SD", "P:")));
lcd_put_u8str(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(ui.get_progress_permyriad()), ui8tostr3rj(progress)));
lcd_put_lchar('%');
lcd_put_u8str(F("%"));
}
}
#endif
@@ -828,6 +866,15 @@ void MarlinUI::draw_status_screen() {
lcd_moveto(8, 0);
_draw_bed_status(blink);
#endif
#elif HAS_CUTTER
//
// Cutter Status
//
lcd_moveto(0, 0);
_draw_cutter_status();
#endif
#else // LCD_WIDTH >= 20
@@ -848,6 +895,15 @@ void MarlinUI::draw_status_screen() {
lcd_moveto(10, 0);
_draw_bed_status(blink);
#endif
#elif HAS_CUTTER
//
// Cutter Status
//
lcd_moveto(0, 0);
_draw_cutter_status();
#endif
TERN_(HAS_COOLER, _draw_cooler_status('*', blink));
@@ -920,7 +976,7 @@ void MarlinUI::draw_status_screen() {
else {
const xy_pos_t lpos = current_position.asLogical();
_draw_axis_value(X_AXIS, ftostr4sign(lpos.x), blink);
lcd_put_lchar(' ');
lcd_put_u8str(F(" "));
_draw_axis_value(Y_AXIS, ftostr4sign(lpos.y), blink);
}
@@ -945,7 +1001,7 @@ void MarlinUI::draw_status_screen() {
lcd_put_lchar(0, 2, LCD_STR_FEEDRATE[0]);
lcd_put_u8str(i16tostr3rj(feedrate_percentage));
lcd_put_lchar('%');
lcd_put_u8str(F("%"));
#if LCD_WIDTH >= 20
@@ -978,7 +1034,7 @@ void MarlinUI::draw_status_screen() {
}
lcd_put_lchar(c);
lcd_put_u8str(i16tostr3rj(per));
lcd_put_lchar('%');
lcd_put_u8str(F("%"));
#endif
#endif
@@ -1017,7 +1073,7 @@ void MarlinUI::draw_status_screen() {
lcd_put_lchar(LCD_WIDTH - 9, 1, LCD_STR_FEEDRATE[0]);
lcd_put_u8str(i16tostr3rj(feedrate_percentage));
lcd_put_lchar('%');
lcd_put_u8str(F("%"));
// ========== Line 3 ==========
@@ -1075,18 +1131,18 @@ void MarlinUI::draw_status_screen() {
vlen = vstr ? utf8_strlen(vstr) : 0;
if (style & SS_CENTER) {
int8_t pad = (LCD_WIDTH - plen - vlen) / 2;
while (--pad >= 0) { lcd_put_lchar(' '); n--; }
while (--pad >= 0) { lcd_put_u8str(F(" ")); n--; }
}
if (plen) n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
if (vlen) n -= lcd_put_u8str_max(vstr, n);
for (; n > 0; --n) lcd_put_lchar(' ');
for (; n > 0; --n) lcd_put_u8str(F(" "));
}
// Draw a generic menu item with pre_char (if selected) and post_char
void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char pre_char, const char post_char) {
lcd_put_lchar(0, row, sel ? pre_char : ' ');
uint8_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2);
for (; n; --n) lcd_put_lchar(' ');
for (; n; --n) lcd_put_u8str(F(" "));
lcd_put_lchar(post_char);
}
@@ -1096,8 +1152,8 @@ void MarlinUI::draw_status_screen() {
lcd_put_lchar(0, row, sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
uint8_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2 - vlen);
if (vlen) {
lcd_put_lchar(':');
for (; n; --n) lcd_put_lchar(' ');
lcd_put_u8str(F(":"));
for (; n; --n) lcd_put_u8str(F(" "));
if (pgm) lcd_put_u8str_P(inStr); else lcd_put_u8str(inStr);
}
}
@@ -1107,7 +1163,7 @@ void MarlinUI::draw_status_screen() {
ui.encoder_direction_normal();
uint8_t n = lcd_put_u8str(0, 1, ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 1);
if (value) {
lcd_put_lchar(':'); n--;
lcd_put_u8str(F(":")); n--;
const uint8_t len = utf8_strlen(value) + 1; // Plus one for a leading space
const lcd_uint_t valrow = n < len ? 2 : 1; // Value on the next row if it won't fit
lcd_put_lchar(LCD_WIDTH - len, valrow, ' '); // Right-justified, padded, leading space
@@ -1134,7 +1190,7 @@ void MarlinUI::draw_status_screen() {
lcd_put_lchar(0, row, sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
constexpr uint8_t maxlen = LCD_WIDTH - 2;
uint8_t n = maxlen - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, row, sel), maxlen);
for (; n; --n) lcd_put_lchar(' ');
for (; n; --n) lcd_put_u8str(F(" "));
lcd_put_lchar(isDir ? LCD_STR_FOLDER[0] : ' ');
}
@@ -1466,9 +1522,9 @@ void MarlinUI::draw_status_screen() {
*/
lcd_put_lchar(_LCD_W_POS, 0, '(');
lcd_put_u8str(ui8tostr3rj(x_plot));
lcd_put_lchar(',');
lcd_put_u8str(F(","));
lcd_put_u8str(ui8tostr3rj(y_plot));
lcd_put_lchar(')');
lcd_put_u8str(F(")"));
#if LCD_HEIGHT <= 3 // 16x2 or 20x2 display