From 0cf7d12ae3177c550628413ab0da5c37a83a9fc9 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Sun, 10 Jun 2018 22:06:00 +0200 Subject: [PATCH] New ML support - lcd optimalization lcd_puts_P and lcd_printf_P functions LineFeed implemented in LiquidCrystal_Prusa --- Firmware/LiquidCrystal_Prusa.cpp | 10 ++++++++-- Firmware/Marlin_main.cpp | 7 ++++++- Firmware/ultralcd.cpp | 26 +++++++++++++++++++------- Firmware/ultralcd.h | 3 +++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Firmware/LiquidCrystal_Prusa.cpp b/Firmware/LiquidCrystal_Prusa.cpp index fe2c837a..b6149ee0 100644 --- a/Firmware/LiquidCrystal_Prusa.cpp +++ b/Firmware/LiquidCrystal_Prusa.cpp @@ -273,7 +273,7 @@ void LiquidCrystal_Prusa::setCursor(uint8_t col, uint8_t row) if ( row >= _numlines ) { row = _numlines-1; // we count rows starting w/0 } - + _currline = row; command(LCD_SETDDRAMADDR | (col + row_offsets[row])); } @@ -356,6 +356,12 @@ inline void LiquidCrystal_Prusa::command(uint8_t value) { } inline size_t LiquidCrystal_Prusa::write(uint8_t value) { + if (value == '\n') + { + if (_currline > 3) _currline = -1; + setCursor(0, _currline + 1); // LF + return 1; + } if (_escape[0] || (value == 0x1b)) return escape_write(value); send(value, HIGH); @@ -421,7 +427,7 @@ inline size_t LiquidCrystal_Prusa::escape_write(uint8_t chr) break; case '2': if (chr == 'J') // escape = "\x1b[2J" - { clear(); break; } // EraseScreen + { clear(); _currline = 0; break; } // EraseScreen default: if (e_2_is_num && // escape = "\x1b[%1d" ((chr == ';') || // escape = "\x1b[%1d;" diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 50bbd4ff..e8476279 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -903,14 +903,18 @@ int uart_putchar(char c, FILE *stream) return 0; } + void lcd_splash() { // lcd_print_at_PGM(0, 1, PSTR(" Original Prusa ")); // lcd_print_at_PGM(0, 2, PSTR(" 3D Printers ")); // lcd.print_P(PSTR("\x1b[1;3HOriginal Prusa\x1b[2;4H3D Printers")); - fputs_P(PSTR(ESC_2J ESC_H(1,1) "Original Prusa i3" ESC_H(3,2) "Prusa Research"), lcdout); +// fputs_P(PSTR(ESC_2J ESC_H(1,1) "Original Prusa i3" ESC_H(3,2) "Prusa Research"), lcdout); + lcd_puts_P(PSTR(ESC_2J ESC_H(1,1) "Original Prusa i3" ESC_H(3,2) "Prusa Research")); +// lcd_printf_P(_N(ESC_2J "x:%.3f\ny:%.3f\nz:%.3f\ne:%.3f"), _x, _y, _z, _e); } + void factory_reset() { KEEPALIVE_STATE(PAUSED_FOR_USER); @@ -1169,6 +1173,7 @@ void setup() SERIAL_ECHO_START; printf_P(PSTR(" " FW_VERSION_FULL "\n")); + #ifdef DEBUG_SEC_LANG lang_table_header_t header; uint32_t src_addr = 0x00000; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 11aa09a5..6287d5a9 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -26,7 +26,22 @@ #include "tmc2130.h" #endif //TMC2130 -#define _STRINGIFY(s) #s + +#include + +int lcd_puts_P(const char* str) +{ + return fputs_P(str, lcdout); +} + +int lcd_printf_P(const char* format, ...) +{ + va_list args; + va_start(args, format); + int ret = vfprintf_P(lcdout, format, args); + va_end(args); + return ret; +} int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */ @@ -4058,8 +4073,7 @@ void lcd_wizard(int state) { } } - SERIAL_ECHOPGM("State: "); - MYSERIAL.println(state); + printf_P(_N("State: %d\n"), state); switch (state) { //final message case 0: //user dont want to use wizard msg = _T(MSG_WIZARD_QUIT); @@ -6370,8 +6384,7 @@ static bool lcd_selfcheck_axis_sg(char axis) { //end of second measurement, now check for possible errors: for(int i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length - SERIAL_ECHOPGM("Measured axis length:"); - MYSERIAL.println(measured_axis_length[i]); + printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]); if (abs(measured_axis_length[i] - axis_length) > max_error_mm) { enable_endstops(false); @@ -6390,8 +6403,7 @@ static bool lcd_selfcheck_axis_sg(char axis) { } } - SERIAL_ECHOPGM("Axis length difference:"); - MYSERIAL.println(abs(measured_axis_length[0] - measured_axis_length[1])); + printf_P(_N("Axis length difference:%.3f\n"), abs(measured_axis_length[0] - measured_axis_length[1])); if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low //loose pulleys diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index c9d2864e..a03c5f1d 100644 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -4,6 +4,9 @@ #include "Marlin.h" #include "mesh_bed_calibration.h" +extern int lcd_puts_P(const char* str); +extern int lcd_printf_P(const char* format, ...); + #ifdef ULTRA_LCD static void lcd_language_menu();