diff --git a/Firmware/LiquidCrystal_Prusa.cpp b/Firmware/LiquidCrystal_Prusa.cpp index fe2c837a..e06f8fa2 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])); } @@ -344,9 +344,8 @@ void LiquidCrystal_Prusa::noAutoscroll(void) { void LiquidCrystal_Prusa::createChar(uint8_t location, uint8_t charmap[]) { location &= 0x7; // we only have 8 locations 0-7 command(LCD_SETCGRAMADDR | (location << 3)); - for (int i=0; i<8; i++) { - write(charmap[i]); - } + for (int i=0; i<8; i++) + send(charmap[i], HIGH); } /*********** mid level commands, for sending data/cmds */ @@ -356,6 +355,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 +426,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 a769536f..e8476279 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -371,7 +371,15 @@ float extruder_multiplier[EXTRUDERS] = {1.0 #endif #endif }; + float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 }; +//shortcuts for more readable code +#define _x current_position[X_AXIS] +#define _y current_position[Y_AXIS] +#define _z current_position[Z_AXIS] +#define _e current_position[E_AXIS] + + float add_homing[3]={0,0,0}; float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }; @@ -440,6 +448,7 @@ bool cancel_heatup = false ; #define KEEPALIVE_STATE(n); #endif + const char errormagic[] PROGMEM = "Error:"; const char echomagic[] PROGMEM = "echo:"; @@ -635,7 +644,6 @@ extern int8_t CrashDetectMenu; void crashdet_enable() { -// MYSERIAL.println("crashdet_enable"); tmc2130_sg_stop_on_crash = true; eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0xFF); CrashDetectMenu = 1; @@ -644,7 +652,6 @@ void crashdet_enable() void crashdet_disable() { -// MYSERIAL.println("crashdet_disable"); tmc2130_sg_stop_on_crash = false; tmc2130_sg_crash = 0; eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0x00); @@ -896,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); @@ -1162,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; @@ -1333,12 +1345,12 @@ void setup() if (crashdet && !farm_mode) { crashdet_enable(); - MYSERIAL.println("CrashDetect ENABLED!"); + puts_P(_N("CrashDetect ENABLED!")); } else { crashdet_disable(); - MYSERIAL.println("CrashDetect DISABLED"); + puts_P(_N("CrashDetect DISABLED")); } #ifdef TMC2130_LINEARITY_CORRECTION @@ -1406,7 +1418,6 @@ void setup() #ifdef TMC2130 if (1) { -/// SERIAL_ECHOPGM("initial zsteps on power up: "); MYSERIAL.println(tmc2130_rd_MSCNT(Z_AXIS)); // try to run to zero phase before powering the Z motor. // Move in negative direction WRITE(Z_DIR_PIN,INVERT_Z_DIR); @@ -1418,7 +1429,6 @@ void setup() WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN); delay(2); } -// SERIAL_ECHOPGM("initial zsteps after reset: "); MYSERIAL.println(tmc2130_rd_MSCNT(Z_AXIS)); } #endif //TMC2130 @@ -1688,21 +1698,17 @@ void setup() */ manage_heater(); // Update temperatures #ifdef DEBUG_UVLO_AUTOMATIC_RECOVER - MYSERIAL.println("Power panic detected!"); - MYSERIAL.print("Current bed temp:"); - MYSERIAL.println(degBed()); - MYSERIAL.print("Saved bed temp:"); - MYSERIAL.println((float)eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED)); + printf_P(_N("Power panic detected!\nCurrent bed temp:%d\nSaved bed temp:%d\n"), (int)degBed(), eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED)) #endif if ( degBed() > ( (float)eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED) - AUTOMATIC_UVLO_BED_TEMP_OFFSET) ){ #ifdef DEBUG_UVLO_AUTOMATIC_RECOVER - MYSERIAL.println("Automatic recovery!"); + puts_P(_N("Automatic recovery!")); #endif recover_print(1); } else{ #ifdef DEBUG_UVLO_AUTOMATIC_RECOVER - MYSERIAL.println("Normal recovery!"); + puts_P(_N("Normal recovery!")); #endif if ( lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_RECOVER_PRINT), false) ) recover_print(0); else { @@ -1726,7 +1732,7 @@ void setup() #ifdef PAT9125 void fsensor_init() { int pat9125 = pat9125_init(); - printf_P(PSTR("PAT9125_init:%d\n"), pat9125); + printf_P(_N("PAT9125_init:%d\n"), pat9125); uint8_t fsensor = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR); filament_autoload_enabled=eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED); if (!pat9125) @@ -3110,7 +3116,8 @@ static void gcode_PRUSA_SN() { if (farm_mode) { selectedSerialPort = 0; - MSerial.write(";S"); + putchar(';'); + putchar('S'); int numbersRead = 0; ShortTimer timeout; timeout.start(); @@ -3119,14 +3126,14 @@ static void gcode_PRUSA_SN() while (MSerial.available() > 0) { uint8_t serial_char = MSerial.read(); selectedSerialPort = 1; - MSerial.write(serial_char); + putchar(serial_char); numbersRead++; selectedSerialPort = 0; } if (timeout.expired(100u)) break; } selectedSerialPort = 1; - MSerial.write('\n'); + putchar('\n'); #if 0 for (int b = 0; b < 3; b++) { tone(BEEPER, 110); @@ -3136,7 +3143,7 @@ static void gcode_PRUSA_SN() } #endif } else { - MYSERIAL.println("Not in farm mode."); + puts_P(_N("Not in farm mode.")); } } @@ -3217,22 +3224,16 @@ void process_commands() } } else if (code_seen("PRN")) { - MYSERIAL.println(status_number); + printf_P(_N("%d"), status_number); }else if (code_seen("FAN")) { - MYSERIAL.print("E0:"); - MYSERIAL.print(60*fan_speed[0]); - MYSERIAL.println(" RPM"); - MYSERIAL.print("PRN0:"); - MYSERIAL.print(60*fan_speed[1]); - MYSERIAL.println(" RPM"); - - }else if (code_seen("fn")) { + printf_P(_N("E0:%d RPM\nPRN0:%d RPM\n"), 60*fan_speed[0], 60*fan_speed[1]); + }else if (code_seen("fn")) { if (farm_mode) { - MYSERIAL.println(farm_no); + printf_P(_N("%d"), farm_no); } else { - MYSERIAL.println("Not in farm mode."); + puts_P(_N("Not in farm mode.")); } } @@ -3736,14 +3737,9 @@ void process_commands() feedrate = homing_feedrate[Z_AXIS]; find_bed_induction_sensor_point_z(-10.f, 3); - SERIAL_PROTOCOLRPGM(_T(MSG_BED)); - SERIAL_PROTOCOLPGM(" X: "); - MYSERIAL.print(current_position[X_AXIS], 5); - SERIAL_PROTOCOLPGM(" Y: "); - MYSERIAL.print(current_position[Y_AXIS], 5); - SERIAL_PROTOCOLPGM(" Z: "); - MYSERIAL.print(current_position[Z_AXIS], 5); - SERIAL_PROTOCOLPGM("\n"); + + printf_P(_N("%S X: %.5f Y: %.5f Z: %.5f\n"), _T(MSG_BED), _x, _y, _z); + clean_up_after_endstop_move(); } break; @@ -3751,11 +3747,8 @@ void process_commands() case 75: { - for (int i = 40; i <= 110; i++) { - MYSERIAL.print(i); - MYSERIAL.print(" "); - MYSERIAL.println(temp_comp_interpolation(i));// / axis_steps_per_unit[Z_AXIS]); - } + for (int i = 40; i <= 110; i++) + printf_P(_N("%d %.2f"), i, temp_comp_interpolation(i)); } break; @@ -3818,8 +3811,7 @@ void process_commands() float start_temp = 5 * (int)(current_temperature_pinda / 5); if (start_temp < 35) start_temp = 35; if (start_temp < current_temperature_pinda) start_temp += 5; - SERIAL_ECHOPGM("start temperature: "); - MYSERIAL.println(start_temp); + printf_P(_N("start temperature: %.1f\n"), start_temp); // setTargetHotend(200, 0); setTargetBed(70 + (start_temp - 30)); @@ -3859,23 +3851,12 @@ void process_commands() } zero_z = current_position[Z_AXIS]; - //current_position[Z_AXIS] - SERIAL_ECHOLNPGM(""); - SERIAL_ECHOPGM("ZERO: "); - MYSERIAL.print(current_position[Z_AXIS]); - SERIAL_ECHOLNPGM(""); + printf_P(_N("\nZERO: %.3f\n"), current_position[Z_AXIS]); int i = -1; for (; i < 5; i++) { float temp = (40 + i * 5); - SERIAL_ECHOPGM("Step: "); - MYSERIAL.print(i + 2); - SERIAL_ECHOLNPGM("/6 (skipped)"); - SERIAL_ECHOPGM("PINDA temperature: "); - MYSERIAL.print((40 + i*5)); - SERIAL_ECHOPGM(" Z shift (mm):"); - MYSERIAL.print(0); - SERIAL_ECHOLNPGM(""); + printf_P(_N("\nStep: %d/6 (skipped)\nPINDA temperature: %d Z shift (mm):0\n"), i + 2, (40 + i*5)); if (i >= 0) EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &z_shift); if (start_temp <= temp) break; } @@ -3883,9 +3864,7 @@ void process_commands() for (i++; i < 5; i++) { float temp = (40 + i * 5); - SERIAL_ECHOPGM("Step: "); - MYSERIAL.print(i + 2); - SERIAL_ECHOLNPGM("/6"); + printf_P(_N("\nStep: %d/6\n"), i + 2); custom_message_state = i + 2; setTargetBed(50 + 10 * (temp - 30) / 5); // setTargetHotend(255, 0); @@ -3915,12 +3894,7 @@ void process_commands() } z_shift = (int)((current_position[Z_AXIS] - zero_z)*axis_steps_per_unit[Z_AXIS]); - SERIAL_ECHOLNPGM(""); - SERIAL_ECHOPGM("PINDA temperature: "); - MYSERIAL.print(current_temperature_pinda); - SERIAL_ECHOPGM(" Z shift (mm):"); - MYSERIAL.print(current_position[Z_AXIS] - zero_z); - SERIAL_ECHOLNPGM(""); + printf_P(_N("\nPINDA temperature: %.1f Z shift (mm): %.3f"), current_temperature_pinda, current_position[Z_AXIS] - zero_z); EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &z_shift); @@ -3944,7 +3918,7 @@ void process_commands() enquecommand_front_P((PSTR("G28 W0"))); break; } - SERIAL_ECHOLNPGM("PINDA probe calibration start"); + puts_P(_N("PINDA probe calibration start")); custom_message = true; custom_message_type = 4; custom_message_state = 1; @@ -3978,16 +3952,10 @@ void process_commands() find_bed_induction_sensor_point_z(-1.f); zero_z = current_position[Z_AXIS]; - //current_position[Z_AXIS] - SERIAL_ECHOLNPGM(""); - SERIAL_ECHOPGM("ZERO: "); - MYSERIAL.print(current_position[Z_AXIS]); - SERIAL_ECHOLNPGM(""); + printf_P(_N("\nZERO: %.3f\n"), current_position[Z_AXIS]); for (int i = 0; i<5; i++) { - SERIAL_ECHOPGM("Step: "); - MYSERIAL.print(i+2); - SERIAL_ECHOLNPGM("/6"); + printf_P(_N("\nStep: %d/6\n"), i + 2); custom_message_state = i + 2; t_c = 60 + i * 10; @@ -4014,12 +3982,7 @@ void process_commands() find_bed_induction_sensor_point_z(-1.f); z_shift = (int)((current_position[Z_AXIS] - zero_z)*axis_steps_per_unit[Z_AXIS]); - SERIAL_ECHOLNPGM(""); - SERIAL_ECHOPGM("Temperature: "); - MYSERIAL.print(t_c); - SERIAL_ECHOPGM(" Z shift (mm):"); - MYSERIAL.print(current_position[Z_AXIS] - zero_z); - SERIAL_ECHOLNPGM(""); + printf_P(_N("\nTemperature: %d Z shift (mm): %.3f\n"), t_c, current_position[Z_AXIS] - zero_z); EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + i*2, &z_shift); @@ -4029,7 +3992,7 @@ void process_commands() custom_message = false; eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); - SERIAL_ECHOLNPGM("Temperature calibration done. Continue with pressing the knob."); + puts_P(_N("Temperature calibration done.")); disable_x(); disable_y(); disable_z(); @@ -4087,7 +4050,7 @@ void process_commands() } fan_speed[1]; - MYSERIAL.print(i); SERIAL_ECHOPGM(": "); MYSERIAL.println(fan_speed[1]); + printf_P(_N("%d: %d\n"), i, fan_speed[1]); } }break; @@ -5143,15 +5106,11 @@ Sigma_Exit: if(code_seen('Q')) print_percent_done_silent = code_value(); if(code_seen('S')) print_time_remaining_silent = code_value(); - SERIAL_ECHOPGM("NORMAL MODE: Percent done: "); - MYSERIAL.print(int(print_percent_done_normal)); - SERIAL_ECHOPGM("; print time remaining in mins: "); - MYSERIAL.println(print_time_remaining_normal); - SERIAL_ECHOPGM("SILENT MODE: Percent done: "); - MYSERIAL.print(int(print_percent_done_silent)); - SERIAL_ECHOPGM("; print time remaining in mins: "); - MYSERIAL.println(print_time_remaining_silent); - + { + const char* _msg_mode_done_remain = _N("%S MODE: Percent done: %d; print time remaining in mins: %d\n"); + printf_P(_msg_mode_done_remain, _N("NORMAL"), int(print_percent_done_normal), print_time_remaining_normal); + printf_P(_msg_mode_done_remain, _N("SILENT"), int(print_percent_done_silent), print_time_remaining_silent); + } break; case 104: // M104 @@ -6819,14 +6778,8 @@ Sigma_Exit: if (code_seen('Y')) tmc2130_sg_thr[Y_AXIS] = code_value(); if (code_seen('Z')) tmc2130_sg_thr[Z_AXIS] = code_value(); if (code_seen('E')) tmc2130_sg_thr[E_AXIS] = code_value(); - MYSERIAL.print("tmc2130_sg_thr[X]="); - MYSERIAL.println(tmc2130_sg_thr[X_AXIS], DEC); - MYSERIAL.print("tmc2130_sg_thr[Y]="); - MYSERIAL.println(tmc2130_sg_thr[Y_AXIS], DEC); - MYSERIAL.print("tmc2130_sg_thr[Z]="); - MYSERIAL.println(tmc2130_sg_thr[Z_AXIS], DEC); - MYSERIAL.print("tmc2130_sg_thr[E]="); - MYSERIAL.println(tmc2130_sg_thr[E_AXIS], DEC); + for (uint8_t a = X_AXIS; a <= E_AXIS; a++) + printf_P(_N("tmc2130_sg_thr[%c]=%d\n"), "XYZE"[a], tmc2130_sg_thr[a]); } break; @@ -7157,10 +7110,7 @@ void FlushSerialRequestResend() { //char cmdbuffer[bufindr][100]="Resend:"; MYSERIAL.flush(); - SERIAL_PROTOCOLRPGM(_i("Resend: "));////MSG_RESEND c=0 r=0 - SERIAL_PROTOCOLLN(gcode_LastN + 1); - previous_millis_cmd = millis(); - SERIAL_PROTOCOLLNRPGM(_T(MSG_OK)); + printf_P(_N("%S: %ld\n%S\n"), _i("Resend"), gcode_LastN + 1, _T(MSG_OK)); } // Confirm the execution of a command, if sent from a serial line. @@ -7614,8 +7564,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s void kill(const char *full_screen_message, unsigned char id) { - SERIAL_ECHOPGM("KILL: "); - MYSERIAL.println(int(id)); + printf_P(_N("KILL: %d\n"), id); //return; cli(); // Stop interrupts disable_heater(); @@ -8176,9 +8125,7 @@ void temp_compensation_apply() { //interpolation z_shift_mm = temp_comp_interpolation(target_temperature_bed) / axis_steps_per_unit[Z_AXIS]; } - SERIAL_PROTOCOLPGM("\n"); - SERIAL_PROTOCOLPGM("Z shift applied:"); - MYSERIAL.print(z_shift_mm); + printf_P(_N("\nZ shift applied:%.3f\n"), z_shift_mm); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] - z_shift_mm, current_position[E_AXIS], homing_feedrate[Z_AXIS] / 40, active_extruder); st_synchronize(); plan_set_z_position(current_position[Z_AXIS]); @@ -8444,8 +8391,7 @@ void uvlo_() if(sd_print) eeprom_update_byte((uint8_t*)EEPROM_UVLO, 1); st_synchronize(); - SERIAL_ECHOPGM("stps"); - MYSERIAL.println(tmc2130_rd_MSCNT(Z_AXIS)); + printf_P(_N("stps%d\n"), tmc2130_rd_MSCNT(Z_AXIS)); disable_z(); @@ -8453,8 +8399,7 @@ void uvlo_() eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1); eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1); - SERIAL_ECHOLNPGM("UVLO - end"); - MYSERIAL.println(millis() - time_start); + printf_P(_N("UVLO - end %d\n"), millis() - time_start); #if 0 // Move the print head to the side of the print until all the power stored in the power supply capacitors is depleted. @@ -8568,19 +8513,13 @@ void recover_print(uint8_t automatic) { /*while ((abs(degHotend(0)- target_temperature[0])>5) || (abs(degBed() -target_temperature_bed)>3)) { //wait for heater and bed to reach target temp delay_keep_alive(1000); }*/ - SERIAL_ECHOPGM("After waiting for temp:"); - SERIAL_ECHOPGM("Current position X_AXIS:"); - MYSERIAL.println(current_position[X_AXIS]); - SERIAL_ECHOPGM("Current position Y_AXIS:"); - MYSERIAL.println(current_position[Y_AXIS]); + + printf_P(_N("After waiting for temp:\nCurrent pos X_AXIS:%.3f\nCurrent pos Y_AXIS:%.3f\n"), current_position[X_AXIS], current_position[Y_AXIS]); // Restart the print. restore_print_from_eeprom(); - SERIAL_ECHOPGM("current_position[Z_AXIS]:"); - MYSERIAL.print(current_position[Z_AXIS]); - SERIAL_ECHOPGM("current_position[E_AXIS]:"); - MYSERIAL.print(current_position[E_AXIS]); + printf_P(_N("Current pos Z_AXIS:%.3f\nCurrent pos E_AXIS:%.3f\n"), current_position[Z_AXIS], current_position[E_AXIS]); } void recover_machine_state_after_power_panic() @@ -8942,24 +8881,12 @@ void restore_print_from_ram_and_continue(float e_move) void print_world_coordinates() { - SERIAL_ECHOPGM("world coordinates: ("); - MYSERIAL.print(current_position[X_AXIS], 3); - SERIAL_ECHOPGM(", "); - MYSERIAL.print(current_position[Y_AXIS], 3); - SERIAL_ECHOPGM(", "); - MYSERIAL.print(current_position[Z_AXIS], 3); - SERIAL_ECHOLNPGM(")"); + printf_P(_N("world coordinates: (%.3f, %.3f, %.3f)\n"), current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]); } void print_physical_coordinates() { - SERIAL_ECHOPGM("physical coordinates: ("); - MYSERIAL.print(st_get_position_mm(X_AXIS), 3); - SERIAL_ECHOPGM(", "); - MYSERIAL.print(st_get_position_mm(Y_AXIS), 3); - SERIAL_ECHOPGM(", "); - MYSERIAL.print(st_get_position_mm(Z_AXIS), 3); - SERIAL_ECHOLNPGM(")"); + printf_P(_N("physical coordinates: (%.3f, %.3f, %.3f)\n"), st_get_position_mm[X_AXIS], st_get_position_mm[Y_AXIS], st_get_position_mm[Z_AXIS]); } void print_mesh_bed_leveling_table() diff --git a/Firmware/config.h b/Firmware/config.h index 43691453..a9172429 100644 --- a/Firmware/config.h +++ b/Firmware/config.h @@ -28,7 +28,7 @@ //LANG - Multi-language support //#define LANG_MODE 0 // primary language only -#define LANG_MODE 0 // sec. language support +#define LANG_MODE 1 // sec. language support #define LANG_SIZE_RESERVED 0x2700 // reserved space for secondary language (~10kb) //#define LANG_SIZE_RESERVED 0x1ef8 // reserved space for secondary language (~10kb) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index f45b6bb8..1a222803 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 */ @@ -1486,71 +1501,49 @@ void lcd_cooldown() static void lcd_menu_extruder_info() { +//|01234567890123456789| +//|Nozzle FAN: RPM| +//|Print FAN: RPM| +//|Fil. Xd: Yd: | +//|Int: Shut: | +//---------------------- int fan_speed_RPM[2]; - -#ifdef PAT9125 - pat9125_update(); -#endif //PAT9125 - - fan_speed_RPM[0] = 60*fan_speed[0]; + // Display Nozzle fan RPM + fan_speed_RPM[0] = 60*fan_speed[0]; fan_speed_RPM[1] = 60*fan_speed[1]; - // Display Nozzle fan RPM - - lcd.setCursor(0, 0); - lcd_printPGM(_i("Nozzle FAN:"));////MSG_INFO_NOZZLE_FAN c=11 r=1 - - lcd.setCursor(11, 0); - lcd.print(" "); - lcd.setCursor(12, 0); - lcd.print(itostr4(fan_speed_RPM[0])); - lcd.print(" RPM"); - - // Display Nozzle fan RPM - -#if (defined(TACH_1)) - lcd.setCursor(0, 1); - lcd_printPGM(_i("Print FAN: "));////MSG_INFO_PRINT_FAN c=11 r=1 - - lcd.setCursor(11, 1); - lcd.print(" "); - lcd.setCursor(12, 1); - lcd.print(itostr4(fan_speed_RPM[1])); - lcd.print(" RPM"); -#endif - #ifdef PAT9125 // Display X and Y difference from Filament sensor - lcd.setCursor(0, 2); - lcd.print("Fil. Xd:"); - lcd.print(itostr3(pat9125_x)); - lcd.print(" "); - lcd.setCursor(12, 2); - lcd.print("Yd:"); - lcd.print(itostr3(pat9125_y)); - // Display Light intensity from Filament sensor - /* Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This - value ranges from 0(darkest) to 255(brightest). */ - lcd.setCursor(0, 3); - - lcd.print("Int: "); - lcd.setCursor(5, 3); - lcd.print(itostr3(pat9125_b)); - + // Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This + // value ranges from 0(darkest) to 255(brightest). // Display LASER shutter time from Filament sensor - /* Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal - auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small. - When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to - 46. */ - - lcd.setCursor(10, 3); - - lcd.print("Shut: "); - lcd.setCursor(15, 3); - lcd.print(itostr3(pat9125_s)); + // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal + // auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small. + // When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to 46. + pat9125_update(); + lcd_printf_P(_N( + ESC_H(0,0) + "Nozzle FAN: %4d RPM\n" + "Print FAN: %4d RPM\n" + "Fil. Xd:%3d Yd:%3d\n" + "Int: %3d Shut: %3d\n" + ), + fan_speed_RPM[0], + fan_speed_RPM[1], + pat9125_x, pat9125_y, + pat9125_b, pat9125_s + ); +#else //PAT9125 + printf_P(_N( + ESC_H(0,0) + "Nozzle FAN: %4d RPM\n" + "Print FAN: %4d RPM\n" + ), + fan_speed_RPM[0], + fan_speed_RPM[1] + ); #endif //PAT9125 - if (lcd_clicked()) { @@ -1571,7 +1564,7 @@ static void lcd_menu_fails_stats_total() uint16_t filam = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); uint16_t crashX = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT); uint16_t crashY = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT); - fprintf_P(lcdout, PSTR(ESC_H(0,0) "Total failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY); + lcd_printf_P(PSTR(ESC_H(0,0) "Total failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY); if (lcd_clicked()) { lcd_quick_feedback(); @@ -1591,7 +1584,7 @@ static void lcd_menu_fails_stats_print() uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT); uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X); uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y); - fprintf_P(lcdout, PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY); + lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY); if (lcd_clicked()) { lcd_quick_feedback(); @@ -1633,7 +1626,7 @@ static void lcd_menu_fails_stats() { uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT); uint16_t filamentTotal = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); - fprintf_P(lcdout, PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Filam. runouts %-3d" ESC_H(0,2) "Total failures" ESC_H(1,3) "Filam. runouts %-3d"), filamentLast, filamentTotal); + lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Filam. runouts %-3d" ESC_H(0,2) "Total failures" ESC_H(1,3) "Filam. runouts %-3d"), filamentLast, filamentTotal); if (lcd_clicked()) { menu_action_back(); @@ -1652,7 +1645,7 @@ extern char* __malloc_heap_end; static void lcd_menu_debug() { #ifdef DEBUG_STACK_MONITOR - fprintf_P(lcdout, PSTR(ESC_H(1,1) "RAM statistics" ESC_H(5,1) "SP_min: 0x%04x" ESC_H(1,2) "heap_start: 0x%04x" ESC_H(3,3) "heap_end: 0x%04x"), SP_min, __malloc_heap_start, __malloc_heap_end); + lcd_printf_P(PSTR(ESC_H(1,1) "RAM statistics" ESC_H(5,1) "SP_min: 0x%04x" ESC_H(1,2) "heap_start: 0x%04x" ESC_H(3,3) "heap_end: 0x%04x"), SP_min, __malloc_heap_start, __malloc_heap_end); #endif //DEBUG_STACK_MONITOR if (lcd_clicked()) @@ -1665,11 +1658,11 @@ static void lcd_menu_debug() static void lcd_menu_temperatures() { - fprintf_P(lcdout, PSTR(ESC_H(1,0) "Nozzle: %d%c" ESC_H(1,1) "Bed: %d%c"), (int)current_temperature[0], '\x01', (int)current_temperature_bed, '\x01'); + lcd_printf_P(PSTR(ESC_H(1,0) "Nozzle: %d%c" ESC_H(1,1) "Bed: %d%c"), (int)current_temperature[0], '\x01', (int)current_temperature_bed, '\x01'); #ifdef AMBIENT_THERMISTOR - fprintf_P(lcdout, PSTR(ESC_H(1,2) "Ambient: %d%c" ESC_H(1,3) "PINDA: %d%c"), (int)current_temperature_ambient, '\x01', (int)current_temperature_pinda, '\x01'); + lcd_printf_P(PSTR(ESC_H(1,2) "Ambient: %d%c" ESC_H(1,3) "PINDA: %d%c"), (int)current_temperature_ambient, '\x01', (int)current_temperature_pinda, '\x01'); #else //AMBIENT_THERMISTOR - fprintf_P(lcdout, PSTR(ESC_H(1,2) "PINDA: %d%c"), (int)current_temperature_pinda, '\x01'); + lcd_printf_P(PSTR(ESC_H(1,2) "PINDA: %d%c"), (int)current_temperature_pinda, '\x01'); #endif //AMBIENT_THERMISTOR if (lcd_clicked()) @@ -1687,8 +1680,8 @@ static void lcd_menu_voltages() { float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC; // float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC; -// fprintf_P(lcdout, PSTR(ESC_H(1,1)"PWR: %d.%01dV" ESC_H(1,2)"BED: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed))); - fprintf_P(lcdout, PSTR( ESC_H(1,1)"PWR: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr))) ; +// lcd_printf_P(PSTR(ESC_H(1,1)"PWR: %d.%01dV" ESC_H(1,2)"BED: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed))); + lcd_printf_P(PSTR( ESC_H(1,1)"PWR: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr))) ; if (lcd_clicked()) { menu_action_back(); @@ -1699,7 +1692,7 @@ static void lcd_menu_voltages() #ifdef TMC2130 static void lcd_menu_belt_status() { - fprintf_P(lcdout, PSTR(ESC_H(1,0) "Belt status" ESC_H(2,1) "X %d" ESC_H(2,2) "Y %d" ), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y))); + lcd_printf_P(PSTR(ESC_H(1,0) "Belt status" ESC_H(2,1) "X %d" ESC_H(2,2) "Y %d" ), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y))); if (lcd_clicked()) { menu_action_back(); @@ -2091,103 +2084,68 @@ static void lcd_LoadFilament() void lcd_menu_statistics() { - if (IS_SD_PRINTING) { int _met = total_filament_used / 100000; - int _cm = (total_filament_used - (_met * 100000))/10; - + int _cm = (total_filament_used - (_met * 100000)) / 10; int _t = (millis() - starttime) / 1000; int _h = _t / 3600; int _m = (_t - (_h * 3600)) / 60; int _s = _t - ((_h * 3600) + (_m * 60)); - - lcd.setCursor(0, 0); - lcd_printPGM(_i("Filament used: "));////MSG_STATS_FILAMENTUSED c=20 r=0 - - lcd.setCursor(6, 1); - lcd.print(itostr3(_met)); - lcd.print("m "); - lcd.print(ftostr32ns(_cm)); - lcd.print("cm"); - - lcd.setCursor(0, 2); - lcd_printPGM(_i("Print time: "));////MSG_STATS_PRINTTIME c=20 r=0 - - lcd.setCursor(8, 3); - lcd.print(itostr2(_h)); - lcd.print("h "); - lcd.print(itostr2(_m)); - lcd.print("m "); - lcd.print(itostr2(_s)); - lcd.print("s"); - +//|01234567890123456789| +//|Filament used: | +//| 000m 00.000cm | +//|Print time: | +//| 00h 00m 00s | +//---------------------- + lcd_printf_P(_N( + ESC_2J + "%S:" + ESC_H(6,1) "%8.2f m\n" + "%S :" + ESC_H(8,3) "%2dh %02dm %02d" + ), + _i("Filament used"), + _met, _cm, + _i("Print time"), + _h, _m, _s + ); if (lcd_clicked()) { lcd_quick_feedback(); - menu_action_back(); + menu_action_back(); } } else { unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED); unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes - uint8_t _hours, _minutes; uint32_t _days; - - float _filament_m = (float)_filament; - int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0; - if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000); - + float _filament_m = (float)_filament/100; +// int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0; +// if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000); _days = _time / 1440; _hours = (_time - (_days * 1440)) / 60; _minutes = _time - ((_days * 1440) + (_hours * 60)); - - lcd_implementation_clear(); - - lcd.setCursor(0, 0); - lcd_printPGM(_i("Total filament :"));////MSG_STATS_TOTALFILAMENT c=20 r=0 - lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)), 1); - lcd.print(ftostr32ns(_filament_m)); - - if (_filament_km > 0) - { - lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 3, 1); - lcd.print("km"); - lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 8, 1); - lcd.print(itostr4(_filament_km)); - } - - - lcd.setCursor(18, 1); - lcd.print("m"); - - lcd.setCursor(0, 2); - lcd_printPGM(_i("Total print time :"));;////MSG_STATS_TOTALPRINTTIME c=20 r=0 - - lcd.setCursor(18, 3); - lcd.print("m"); - lcd.setCursor(14, 3); - lcd.print(itostr3(_minutes)); - - lcd.setCursor(14, 3); - lcd.print(":"); - - lcd.setCursor(12, 3); - lcd.print("h"); - lcd.setCursor(9, 3); - lcd.print(itostr3(_hours)); - - lcd.setCursor(9, 3); - lcd.print(":"); - - lcd.setCursor(7, 3); - lcd.print("d"); - lcd.setCursor(4, 3); - lcd.print(itostr3(_days)); - - +//|01234567890123456789| +//|Total filament : | +//| 000.00 m | +//|Total print time : | +//| 00d :00h :00 m | +//---------------------- + lcd_printf_P(_N( + ESC_2J + "%S :" + ESC_H(9,1) "%8.2f m\n" + "%S :\n" + "%7ldd :%2hhdh :%02hhd m" + ), + _i("Total filament"), + _filament_m, + _i("Total print time"), + _days, _hours, _minutes + ); KEEPALIVE_STATE(PAUSED_FOR_USER); while (!lcd_clicked()) { @@ -2196,9 +2154,8 @@ void lcd_menu_statistics() delay(100); } KEEPALIVE_STATE(NOT_BUSY); - lcd_quick_feedback(); - menu_action_back(); + menu_action_back(); } } @@ -2266,22 +2223,32 @@ static void lcd_move_e() */ static void lcd_menu_xyz_y_min() { - lcd.setCursor(0,0); - lcd_printPGM(_i("Y distance from min:"));////MSG_Y_DISTANCE_FROM_MIN c=20 r=1 - lcd_print_at_PGM(0, 1, separator); - lcd_print_at_PGM(0, 2, _i("Left:"));////MSG_LEFT c=12 r=1 - lcd_print_at_PGM(0, 3, _i("Right:"));////MSG_RIGHT c=12 r=1 - - float distanceMin[2]; +//|01234567890123456789| +//|Y distance from min:| +//|--------------------| +//|Left: N/A | +//|Right: N/A | +//---------------------- + float distanceMin[2]; count_xyz_details(distanceMin); - - for (int i = 0; i < 2; i++) { - if(distanceMin[i] < 200) { - lcd_print_at_PGM(11, i + 2, PSTR("")); - lcd.print(distanceMin[i]); - lcd_print_at_PGM((distanceMin[i] < 0) ? 17 : 16, i + 2, PSTR("mm")); - } else lcd_print_at_PGM(11, i + 2, PSTR("N/A")); - } + lcd_printf_P(_N( + ESC_H(0,0) + "%S:\n" + "%S\n" + "%S:\n" + "%S:" + ), + _i("Y distance from min"), + separator, + _i("Left"), + _i("Right") + ); + for (uint8_t i = 0; i < 2; i++) + { + lcd.setCursor(11,2+i); + if (distanceMin[i] >= 200) lcd_puts_P(_N("N/A")); + else lcd_printf_P(_N("%6.2fmm"), distanceMin[i]); + } if (lcd_clicked()) { lcd_goto_menu(lcd_menu_xyz_skew); @@ -2290,28 +2257,33 @@ static void lcd_menu_xyz_y_min() /** * @brief Show measured axis skewness */ +float _deg(float rad) +{ + return rad * 180 / M_PI; +} + static void lcd_menu_xyz_skew() { - float angleDiff; - angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW)); - - lcd.setCursor(0,0); - lcd_printPGM(_i("Measured skew:"));////MSG_MEASURED_SKEW c=15 r=1 - if (angleDiff < 100) { - lcd.setCursor(15, 0); - lcd.print(angleDiff * 180 / M_PI); - lcd.print(LCD_STR_DEGREE); - }else lcd_print_at_PGM(16, 0, PSTR("N/A")); - lcd_print_at_PGM(0, 1, separator); - lcd_print_at_PGM(0, 2, _i("Slight skew:"));////MSG_SLIGHT_SKEW c=15 r=1 - lcd_print_at_PGM(15, 2, PSTR("")); - lcd.print(bed_skew_angle_mild * 180 / M_PI); - lcd.print(LCD_STR_DEGREE); - lcd_print_at_PGM(0, 3, _i("Severe skew:"));////MSG_SEVERE_SKEW c=15 r=1 - lcd_print_at_PGM(15, 3, PSTR("")); - lcd.print(bed_skew_angle_extreme * 180 / M_PI); - lcd.print(LCD_STR_DEGREE); - +//|01234567890123456789| +//|Measured skew: N/A | +//|--------------------| +//|Slight skew: 0.12°| +//|Severe skew: 0.25°| +//---------------------- + float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW)); + lcd_printf_P(_N( + ESC_H(0,0) + "%S: N/A\n" + "%S\n" + "%S: %5.2f\x01\n" + "%S: %5.2f\x01" + ), + _i("Measured skew"), + separator, + _i("Slight skew"), _deg(bed_skew_angle_mild), + _i("Severe skew"), _deg(bed_skew_angle_extreme) + ); + if (angleDiff < 100) lcd_printf_P(_N(ESC_H(15,0)"%4.2f\x01"), _deg(angleDiff)); if (lcd_clicked()) { lcd_goto_menu(lcd_menu_xyz_offset); @@ -4058,8 +4030,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); @@ -5429,12 +5400,9 @@ void lcd_confirm_print() } -static void lcd_test_menu() +/*static void lcd_test_menu() { - lang_boot_update_start(3); - lcd_update_enable(true); - lcd_return_to_status(); -} +}*/ static void lcd_main_menu() { @@ -5605,7 +5573,7 @@ static void lcd_main_menu() #endif MENU_ITEM(submenu, _i("Support"), lcd_support_menu);////MSG_SUPPORT c=0 r=0 - MENU_ITEM(submenu, _i("Test"), lcd_test_menu);////MSG_SUPPORT c=0 r=0 +// MENU_ITEM(submenu, _i("Test"), lcd_test_menu);////MSG_SUPPORT c=0 r=0 END_MENU(); @@ -6373,8 +6341,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); @@ -6393,8 +6360,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();