Merge pull request #11238 from xC0000005/MalyanLCDUpdate

[2.0.x] Malyan LCD Feedrate + Better Temp Handling
This commit is contained in:
Scott Lahteine 2018-07-17 21:06:52 -05:00 committed by GitHub
commit c83109c0ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 63 deletions

View file

@ -77,6 +77,9 @@
// Track incoming command bytes from the LCD // Track incoming command bytes from the LCD
int inbound_count; int inbound_count;
// For sending print completion messages
bool last_printing_status = false;
// Everything written needs the high bit set. // Everything written needs the high bit set.
void write_to_lcd_P(const char * const message) { void write_to_lcd_P(const char * const message) {
char encoded_message[MAX_CURLY_COMMAND]; char encoded_message[MAX_CURLY_COMMAND];
@ -106,22 +109,23 @@ void write_to_lcd(const char * const message) {
* {C:P050} * {C:P050}
* Set temp for bed to 50 * Set temp for bed to 50
* *
* {C:S09} set feedrate to 90 %.
* {C:S12} set feedrate to 120 %.
*
* the command portion begins after the : * the command portion begins after the :
*/ */
void process_lcd_c_command(const char* command) { void process_lcd_c_command(const char* command) {
switch (command[0]) { switch (command[0]) {
case 'T': { case 'C': {
// M104 S<temperature> int raw_feedrate = atoi(command + 1);
char cmd[20]; feedrate_percentage = raw_feedrate * 10;
sprintf_P(cmd, PSTR("M104 S%s"), command + 1); feedrate_percentage = constrain(feedrate_percentage, 10, 999);
enqueue_and_echo_command_now(cmd); } break;
case 'T': {
thermalManager.setTargetHotend(atoi(command + 1), 0);
} break; } break;
case 'P': { case 'P': {
// M140 S<temperature> thermalManager.setTargetBed(atoi(command + 1));
char cmd[20];
sprintf_P(cmd, PSTR("M140 S%s"), command + 1);
enqueue_and_echo_command_now(cmd);
} break; } break;
default: default:
@ -240,6 +244,7 @@ void process_lcd_p_command(const char* command) {
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
// cancel print // cancel print
write_to_lcd_P(PSTR("{SYS:CANCELING}")); write_to_lcd_P(PSTR("{SYS:CANCELING}"));
last_printing_status = false;
card.stopSDPrint( card.stopSDPrint(
#if SD_RESORT #if SD_RESORT
true true
@ -280,7 +285,7 @@ void process_lcd_p_command(const char* command) {
} }
else { else {
char message_buffer[MAX_CURLY_COMMAND]; char message_buffer[MAX_CURLY_COMMAND];
sprintf_P(message_buffer, PSTR("{PRINTFILE:%s}"), card.filename); sprintf_P(message_buffer, PSTR("{PRINTFILE:%s}"), card.longest_filename());
write_to_lcd(message_buffer); write_to_lcd(message_buffer);
write_to_lcd_P(PSTR("{SYS:BUILD}")); write_to_lcd_P(PSTR("{SYS:BUILD}"));
card.openAndPrintFile(card.filename); card.openAndPrintFile(card.filename);
@ -321,7 +326,7 @@ void process_lcd_s_command(const char* command) {
case 'H': case 'H':
// Home all axis // Home all axis
enqueue_and_echo_command("G28"); enqueue_and_echo_command("G28", false);
break; break;
case 'L': { case 'L': {
@ -338,7 +343,7 @@ void process_lcd_s_command(const char* command) {
uint16_t file_count = card.get_num_Files(); uint16_t file_count = card.get_num_Files();
for (uint16_t i = 0; i < file_count; i++) { for (uint16_t i = 0; i < file_count; i++) {
card.getfilename(i); card.getfilename(i);
sprintf_P(message_buffer, card.filenameIsDir ? PSTR("{DIR:%s}") : PSTR("{FILE:%s}"), card.filename); sprintf_P(message_buffer, card.filenameIsDir ? PSTR("{DIR:%s}") : PSTR("{FILE:%s}"), card.longest_filename());
write_to_lcd(message_buffer); write_to_lcd(message_buffer);
} }
@ -395,7 +400,7 @@ void process_lcd_command(const char* command) {
/** /**
* UC means connected. * UC means connected.
* UD means disconnected * UD means disconnected
* The stock firmware considers USB initialied as "connected." * The stock firmware considers USB initialized as "connected."
*/ */
void update_usb_status(const bool forceUpdate) { void update_usb_status(const bool forceUpdate) {
static bool last_usb_connected_status = false; static bool last_usb_connected_status = false;
@ -433,14 +438,21 @@ void lcd_update() {
} }
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
// If there's a print in progress, we need to emit the status as // The way last printing status works is simple:
// {TQ:<PERCENT>} // The UI needs to see at least one TQ which is not 100%
if (card.sdprinting) { // and then when the print is complete, one which is.
// We also need to send: T:-2538.0 E:0 static uint8_t last_percent_done = 100;
// I have no idea what this means.
// If there was a print in progress, we need to emit the final
// print status as {TQ:100}. Reset last percent done so a new print will
// issue a percent of 0.
const uint8_t percent_done = card.sdprinting ? card.percentDone() : last_printing_status ? 100 : 0;
if (percent_done != last_percent_done) {
char message_buffer[10]; char message_buffer[10];
sprintf_P(message_buffer, PSTR("{TQ:%03i}"), card.percentDone()); sprintf_P(message_buffer, PSTR("{TQ:%03i}"), percent_done);
write_to_lcd(message_buffer); write_to_lcd(message_buffer);
last_percent_done = percent_done;
last_printing_status = card.sdprinting;
} }
#endif #endif
} }

View file

@ -277,8 +277,8 @@ uint16_t max_display_update_time = 0;
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
void lcd_sdcard_menu(); void lcd_sdcard_menu();
void menu_action_sdfile(const char* filename, char* longFilename); void menu_action_sdfile(CardReader &theCard);
void menu_action_sddirectory(const char* filename, char* longFilename); void menu_action_sddirectory(CardReader &theCard);
#endif #endif
//////////////////////////////////////////// ////////////////////////////////////////////
@ -768,7 +768,7 @@ void lcd_reset_status() {
msg = paused; msg = paused;
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
else if (card.sdprinting) else if (card.sdprinting)
return lcd_setstatus(card.longFilename[0] ? card.longFilename : card.filename, true); return lcd_setstatus(card.longest_filename(), true);
#endif #endif
else if (print_job_timer.isRunning()) else if (print_job_timer.isRunning())
msg = printing; msg = printing;
@ -1002,9 +1002,9 @@ void lcd_quick_feedback(const bool clear_buttons) {
bar_percent = constrain(bar_percent, 0, 100); bar_percent = constrain(bar_percent, 0, 100);
encoderPosition = 0; encoderPosition = 0;
lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true); lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
lcd.setCursor((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2); lcd_moveto((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
lcd.print(itostr3(bar_percent)); lcd.write('%'); lcd_put_u8str(int(bar_percent)); lcd_put_wchar('%');
lcd.setCursor(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent); lcd_moveto(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
} }
void _progress_bar_test() { void _progress_bar_test() {
@ -2938,7 +2938,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
destination[manual_move_axis] += manual_move_offset; destination[manual_move_axis] += manual_move_offset;
// Reset for the next move // Reset for the next move
manual_move_offset = 0.0; manual_move_offset = 0;
manual_move_axis = (int8_t)NO_AXIS; manual_move_axis = (int8_t)NO_AXIS;
// DELTA and SCARA machines use segmented moves, which could fill the planner during the call to // DELTA and SCARA machines use segmented moves, which could fill the planner during the call to
@ -4042,9 +4042,9 @@ void lcd_quick_feedback(const bool clear_buttons) {
#endif #endif
if (card.filenameIsDir) if (card.filenameIsDir)
MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename); MENU_ITEM(sddirectory, MSG_CARD_MENU, card);
else else
MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename); MENU_ITEM(sdfile, MSG_CARD_MENU, card);
} }
else { else {
MENU_ITEM_DUMMY(); MENU_ITEM_DUMMY();
@ -4965,19 +4965,17 @@ void lcd_quick_feedback(const bool clear_buttons) {
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
void menu_action_sdfile(const char* filename, char* longFilename) { void menu_action_sdfile(CardReader &theCard) {
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE) #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
last_sdfile_encoderPosition = encoderPosition; // Save which file was selected for later use last_sdfile_encoderPosition = encoderPosition; // Save which file was selected for later use
#endif #endif
UNUSED(longFilename); card.openAndPrintFile(theCard.filename);
card.openAndPrintFile(filename);
lcd_return_to_status(); lcd_return_to_status();
lcd_reset_status(); lcd_reset_status();
} }
void menu_action_sddirectory(const char* filename, char* longFilename) { void menu_action_sddirectory(CardReader &theCard) {
UNUSED(longFilename); card.chdir(theCard.filename);
card.chdir(filename);
encoderTopLine = 0; encoderTopLine = 0;
encoderPosition = 2 * ENCODER_STEPS_PER_MENU_ITEM; encoderPosition = 2 * ENCODER_STEPS_PER_MENU_ITEM;
screen_changed = true; screen_changed = true;

View file

@ -518,7 +518,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, const char* filename, char* const longFilename, const bool isDir) { static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, CardReader &theCard, const bool isDir) {
UNUSED(pstr); UNUSED(pstr);
lcd_implementation_mark_as_selected(row, isSelected); lcd_implementation_mark_as_selected(row, isSelected);
@ -526,23 +526,23 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
if (!PAGE_CONTAINS(row_y1, row_y2)) return; if (!PAGE_CONTAINS(row_y1, row_y2)) return;
constexpr uint8_t maxlen = LCD_WIDTH - (START_COL) - 1; constexpr uint8_t maxlen = LCD_WIDTH - (START_COL) - 1;
const char *outstr = longFilename[0] ? longFilename : filename; const char *outstr = theCard.longest_filename();
if (longFilename[0]) { if (theCard.longFilename[0]) {
#if ENABLED(SCROLL_LONG_FILENAMES) #if ENABLED(SCROLL_LONG_FILENAMES)
if (isSelected) { if (isSelected) {
uint8_t name_hash = row; uint8_t name_hash = row;
for (uint8_t l = FILENAME_LENGTH; l--;) for (uint8_t l = FILENAME_LENGTH; l--;)
name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l]; // rotate, xor name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ theCard.filename[l]; // rotate, xor
if (filename_scroll_hash != name_hash) { // If the hash changed... if (filename_scroll_hash != name_hash) { // If the hash changed...
filename_scroll_hash = name_hash; // Save the new hash filename_scroll_hash = name_hash; // Save the new hash
filename_scroll_max = MAX(0, utf8_strlen(longFilename) - maxlen); // Update the scroll limit filename_scroll_max = MAX(0, utf8_strlen(theCard.longFilename) - maxlen); // Update the scroll limit
filename_scroll_pos = 0; // Reset scroll to the start filename_scroll_pos = 0; // Reset scroll to the start
lcd_status_update_delay = 8; // Don't scroll right away lcd_status_update_delay = 8; // Don't scroll right away
} }
outstr += filename_scroll_pos; outstr += filename_scroll_pos;
} }
#else #else
longFilename[maxlen] = '\0'; // cutoff at screen edge theCard.longFilename[maxlen] = '\0'; // cutoff at screen edge
#endif #endif
} }
@ -554,8 +554,8 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); } while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
} }
#define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false) #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, theCard) _drawmenu_sd(sel, row, pstr, theCard, false)
#define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, true) #define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, theCard) _drawmenu_sd(sel, row, pstr, theCard, true)
#endif // SDSUPPORT #endif // SDSUPPORT

View file

@ -926,29 +926,29 @@ static void lcd_implementation_status_screen() {
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
static void lcd_implementation_drawmenu_sd(const bool sel, const uint8_t row, const char* const pstr, const char* filename, char* const longFilename, const uint8_t concat, const char post_char) { static void lcd_implementation_drawmenu_sd(const bool sel, const uint8_t row, const char* const pstr, CardReader &theCard, const uint8_t concat, const char post_char) {
UNUSED(pstr); UNUSED(pstr);
lcd_moveto(0, row); lcd_moveto(0, row);
lcd_put_wchar(sel ? '>' : ' '); lcd_put_wchar(sel ? '>' : ' ');
uint8_t n = LCD_WIDTH - concat; uint8_t n = LCD_WIDTH - concat;
const char *outstr = longFilename[0] ? longFilename : filename; const char *outstr = theCard.longest_filename();
if (longFilename[0]) { if (theCard.longFilename[0]) {
#if ENABLED(SCROLL_LONG_FILENAMES) #if ENABLED(SCROLL_LONG_FILENAMES)
if (sel) { if (sel) {
uint8_t name_hash = row; uint8_t name_hash = row;
for (uint8_t l = FILENAME_LENGTH; l--;) for (uint8_t l = FILENAME_LENGTH; l--;)
name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l]; // rotate, xor name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ theCard.filename[l]; // rotate, xor
if (filename_scroll_hash != name_hash) { // If the hash changed... if (filename_scroll_hash != name_hash) { // If the hash changed...
filename_scroll_hash = name_hash; // Save the new hash filename_scroll_hash = name_hash; // Save the new hash
filename_scroll_max = MAX(0, utf8_strlen(longFilename) - n); // Update the scroll limit filename_scroll_max = MAX(0, utf8_strlen(theCard.longFilename) - n); // Update the scroll limit
filename_scroll_pos = 0; // Reset scroll to the start filename_scroll_pos = 0; // Reset scroll to the start
lcd_status_update_delay = 8; // Don't scroll right away lcd_status_update_delay = 8; // Don't scroll right away
} }
outstr += filename_scroll_pos; outstr += filename_scroll_pos;
} }
#else #else
longFilename[n] = '\0'; // cutoff at screen edge theCard.longFilename[n] = '\0'; // cutoff at screen edge
#endif #endif
} }
@ -960,12 +960,12 @@ static void lcd_implementation_status_screen() {
lcd_put_wchar(post_char); lcd_put_wchar(post_char);
} }
static void lcd_implementation_drawmenu_sdfile(const bool sel, const uint8_t row, const char* pstr, const char* filename, char* const longFilename) { static void lcd_implementation_drawmenu_sdfile(const bool sel, const uint8_t row, const char* pstr, CardReader &theCard) {
lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, ' '); lcd_implementation_drawmenu_sd(sel, row, pstr, theCard, 2, ' ');
} }
static void lcd_implementation_drawmenu_sddirectory(const bool sel, const uint8_t row, const char* pstr, const char* filename, char* const longFilename) { static void lcd_implementation_drawmenu_sddirectory(const bool sel, const uint8_t row, const char* pstr, CardReader &theCard) {
lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, LCD_STR_FOLDER[0]); lcd_implementation_drawmenu_sd(sel, row, pstr, theCard, 2, LCD_STR_FOLDER[0]);
} }
#endif // SDSUPPORT #endif // SDSUPPORT

View file

@ -43,8 +43,6 @@
#include <ctype.h> #include <ctype.h>
#define LONGEST_FILENAME (longFilename[0] ? longFilename : filename)
CardReader::CardReader() { CardReader::CardReader() {
#if ENABLED(SDCARD_SORT_ALPHA) #if ENABLED(SDCARD_SORT_ALPHA)
sort_count = 0; sort_count = 0;
@ -771,7 +769,7 @@ void CardReader::setroot() {
getfilename(i); getfilename(i);
#if ENABLED(SDSORT_DYNAMIC_RAM) #if ENABLED(SDSORT_DYNAMIC_RAM)
// Use dynamic method to copy long filename // Use dynamic method to copy long filename
sortnames[i] = strdup(LONGEST_FILENAME); sortnames[i] = strdup(longest_filename());
#if ENABLED(SDSORT_CACHE_NAMES) #if ENABLED(SDSORT_CACHE_NAMES)
// When caching also store the short name, since // When caching also store the short name, since
// we're replacing the getfilename() behavior. // we're replacing the getfilename() behavior.
@ -780,10 +778,10 @@ void CardReader::setroot() {
#else #else
// Copy filenames into the static array // Copy filenames into the static array
#if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN); strncpy(sortnames[i], longest_filename(), SORTED_LONGNAME_MAXLEN);
sortnames[i][SORTED_LONGNAME_MAXLEN - 1] = '\0'; sortnames[i][SORTED_LONGNAME_MAXLEN - 1] = '\0';
#else #else
strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN); strncpy(sortnames[i], longest_filename(), SORTED_LONGNAME_MAXLEN);
#endif #endif
#if ENABLED(SDSORT_CACHE_NAMES) #if ENABLED(SDSORT_CACHE_NAMES)
strcpy(sortshort[i], filename); strcpy(sortshort[i], filename);
@ -831,12 +829,12 @@ void CardReader::setroot() {
// throughout the loop. Slow if there are many. // throughout the loop. Slow if there are many.
#if DISABLED(SDSORT_USES_RAM) #if DISABLED(SDSORT_USES_RAM)
getfilename(o1); getfilename(o1);
strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it) strcpy(name1, longest_filename()); // save (or getfilename below will trounce it)
#if HAS_FOLDER_SORTING #if HAS_FOLDER_SORTING
bool dir1 = filenameIsDir; bool dir1 = filenameIsDir;
#endif #endif
getfilename(o2); getfilename(o2);
char *name2 = LONGEST_FILENAME; // use the string in-place char *name2 = longest_filename(); // use the string in-place
#endif // !SDSORT_USES_RAM #endif // !SDSORT_USES_RAM
// Sort the current pair according to settings. // Sort the current pair according to settings.
@ -874,7 +872,7 @@ void CardReader::setroot() {
getfilename(0); getfilename(0);
#if ENABLED(SDSORT_DYNAMIC_RAM) #if ENABLED(SDSORT_DYNAMIC_RAM)
sortnames = new char*[1]; sortnames = new char*[1];
sortnames[0] = strdup(LONGEST_FILENAME); // malloc sortnames[0] = strdup(longest_filename()); // malloc
#if ENABLED(SDSORT_CACHE_NAMES) #if ENABLED(SDSORT_CACHE_NAMES)
sortshort = new char*[1]; sortshort = new char*[1];
sortshort[0] = strdup(filename); // malloc sortshort[0] = strdup(filename); // malloc
@ -882,10 +880,10 @@ void CardReader::setroot() {
isDir = new uint8_t[1]; isDir = new uint8_t[1];
#else #else
#if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN); strncpy(sortnames[0], longest_filename(), SORTED_LONGNAME_MAXLEN);
sortnames[0][SORTED_LONGNAME_MAXLEN - 1] = '\0'; sortnames[0][SORTED_LONGNAME_MAXLEN - 1] = '\0';
#else #else
strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN); strncpy(sortnames[0], longest_filename(), SORTED_LONGNAME_MAXLEN);
#endif #endif
#if ENABLED(SDSORT_CACHE_NAMES) #if ENABLED(SDSORT_CACHE_NAMES)
strcpy(sortshort[0], filename); strcpy(sortshort[0], filename);

View file

@ -144,6 +144,8 @@ public:
} }
#endif #endif
FORCE_INLINE char* longest_filename() { return longFilename[0] ? longFilename : filename; }
public: public:
bool saving, logging, sdprinting, cardOK, filenameIsDir; bool saving, logging, sdprinting, cardOK, filenameIsDir;
char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH]; char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH];