Merge branch 'MK3' into MK3-new_lang

This commit is contained in:
XPila 2018-06-08 14:38:00 +02:00 committed by GitHub
commit 739de5224e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 2720 additions and 112 deletions

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
.settings
.project
.cproject
Debug
Firmware/Configuration_prusa.h
Firmware/Doc

View file

@ -170,9 +170,15 @@
#define EEPROM_TMC2130_Z_MRES (EEPROM_TMC2130_Y_MRES - 1) // uint8 #define EEPROM_TMC2130_Z_MRES (EEPROM_TMC2130_Y_MRES - 1) // uint8
#define EEPROM_TMC2130_E_MRES (EEPROM_TMC2130_Z_MRES - 1) // uint8 #define EEPROM_TMC2130_E_MRES (EEPROM_TMC2130_Z_MRES - 1) // uint8
// HW
#define EEPROM_PRINTER_TYPE (EEPROM_TMC2130_E_MRES - 2) // uint16 #define EEPROM_PRINTER_TYPE (EEPROM_TMC2130_E_MRES - 2) // uint16
#define EEPROM_BOARD_TYPE (EEPROM_PRINTER_TYPE - 2) // uint16 #define EEPROM_BOARD_TYPE (EEPROM_PRINTER_TYPE - 2) // uint16
// Extruder multiplier for power panic
#define EEPROM_EXTRUDER_MULTIPLIER_0 (EEPROM_BOARD_TYPE - 4) //float
#define EEPROM_EXTRUDER_MULTIPLIER_1 (EEPROM_EXTRUDER_MULTIPLIER_0 - 4) //float
#define EEPROM_EXTRUDER_MULTIPLIER_2 (EEPROM_EXTRUDER_MULTIPLIER_1 - 4) //float
//TMC2130 configuration //TMC2130 configuration
#define EEPROM_TMC_AXIS_SIZE //axis configuration block size #define EEPROM_TMC_AXIS_SIZE //axis configuration block size
#define EEPROM_TMC_X (EEPROM_TMC + 0 * EEPROM_TMC_AXIS_SIZE) //X axis configuration blok #define EEPROM_TMC_X (EEPROM_TMC + 0 * EEPROM_TMC_AXIS_SIZE) //X axis configuration blok

View file

@ -1,30 +1,46 @@
/* -*- c++ -*- */ /* -*- c++ -*- */
/**
/* * @file
Reprap firmware based on Sprinter and grbl.
Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/* /**
This firmware is a mashup between Sprinter and grbl. * @mainpage Reprap 3D printer firmware based on Sprinter and grbl.
(https://github.com/kliment/Sprinter) *
(https://github.com/simen/grbl/tree) * @section intro_sec Introduction
*
It has preliminary support for Matthew Roberts advance algorithm * This firmware is a mashup between Sprinter and grbl.
http://reprap.org/pipermail/reprap-dev/2011-May/003323.html * https://github.com/kliment/Sprinter
* https://github.com/simen/grbl/tree
*
* It has preliminary support for Matthew Roberts advance algorithm
* http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
*
* Prusa Research s.r.o. https://www.prusa3d.cz
*
* @section copyright_sec Copyright
*
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @section notes_sec Notes
*
* * Do not create static objects in global functions.
* Otherwise constructor guard against concurrent calls is generated costing
* about 8B RAM and 14B flash.
*
*
*/ */
#include "Marlin.h" #include "Marlin.h"
@ -119,6 +135,9 @@
//Macro for print fan speed //Macro for print fan speed
#define FAN_PULSE_WIDTH_LIMIT ((fanSpeed > 100) ? 3 : 4) //time in ms #define FAN_PULSE_WIDTH_LIMIT ((fanSpeed > 100) ? 3 : 4) //time in ms
#define PRINTING_TYPE_SD 0
#define PRINTING_TYPE_USB 1
// look here for descriptions of G-codes: http://linuxcnc.org/handbook/gcode/g-code.html // look here for descriptions of G-codes: http://linuxcnc.org/handbook/gcode/g-code.html
// http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes // http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes
@ -305,6 +324,7 @@ float pause_lastpos[4];
unsigned long pause_time = 0; unsigned long pause_time = 0;
unsigned long start_pause_print = millis(); unsigned long start_pause_print = millis();
unsigned long t_fan_rising_edge = millis(); unsigned long t_fan_rising_edge = millis();
static LongTimer safetyTimer;
//unsigned long load_filament_time; //unsigned long load_filament_time;
@ -486,6 +506,7 @@ boolean chdkActive = false;
// save/restore printing // save/restore printing
static uint32_t saved_sdpos = 0; static uint32_t saved_sdpos = 0;
static uint8_t saved_printing_type = PRINTING_TYPE_SD;
static float saved_pos[4] = { 0, 0, 0, 0 }; static float saved_pos[4] = { 0, 0, 0, 0 };
// Feedrate hopefully derived from an active block of the planner at the time the print has been canceled, in mm/min. // Feedrate hopefully derived from an active block of the planner at the time the print has been canceled, in mm/min.
static float saved_feedrate2 = 0; static float saved_feedrate2 = 0;
@ -629,12 +650,12 @@ void crashdet_disable()
void crashdet_stop_and_save_print() void crashdet_stop_and_save_print()
{ {
stop_and_save_print_to_ram(10, 0); //XY - no change, Z 10mm up, E - no change stop_and_save_print_to_ram(10, -2); //XY - no change, Z 10mm up, E -2mm retract
} }
void crashdet_restore_print_and_continue() void crashdet_restore_print_and_continue()
{ {
restore_print_from_ram_and_continue(0); //XYZ = orig, E - no change restore_print_from_ram_and_continue(2); //XYZ = orig, E +2mm unretract
// babystep_apply(); // babystep_apply();
} }
@ -1780,7 +1801,15 @@ void loop()
planner_add_sd_length(sdlen.value); planner_add_sd_length(sdlen.value);
sei(); sei();
} }
} }
else if((*ptr == CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR) && !IS_SD_PRINTING){
cli();
*ptr ++ = CMDBUFFER_CURRENT_TYPE_TO_BE_REMOVED;
// and one for each command to previous block in the planner queue.
planner_add_sd_length(1);
sei();
}
// Now it is safe to release the already processed command block. If interrupted by the power panic now, // Now it is safe to release the already processed command block. If interrupted by the power panic now,
// this block's SD card length will not be counted twice as its command type has been replaced // this block's SD card length will not be counted twice as its command type has been replaced
// by CMDBUFFER_CURRENT_TYPE_TO_BE_REMOVED. // by CMDBUFFER_CURRENT_TYPE_TO_BE_REMOVED.
@ -2936,7 +2965,7 @@ static void gcode_PRUSA_SN()
selectedSerialPort = 0; selectedSerialPort = 0;
MSerial.write(";S"); MSerial.write(";S");
int numbersRead = 0; int numbersRead = 0;
Timer timeout; ShortTimer timeout;
timeout.start(); timeout.start();
while (numbersRead < 19) { while (numbersRead < 19) {
@ -2947,7 +2976,7 @@ static void gcode_PRUSA_SN()
numbersRead++; numbersRead++;
selectedSerialPort = 0; selectedSerialPort = 0;
} }
if (timeout.expired(100)) break; if (timeout.expired(100u)) break;
} }
selectedSerialPort = 1; selectedSerialPort = 1;
MSerial.write('\n'); MSerial.write('\n');
@ -3310,10 +3339,10 @@ void process_commands()
if( !(code_seen('X') || code_seen('Y') || code_seen('Z')) && code_seen('E')) { if( !(code_seen('X') || code_seen('Y') || code_seen('Z')) && code_seen('E')) {
float echange=destination[E_AXIS]-current_position[E_AXIS]; float echange=destination[E_AXIS]-current_position[E_AXIS];
if((echange<-MIN_RETRACT && !retracted) || (echange>MIN_RETRACT && retracted)) { //move appears to be an attempt to retract or recover if((echange<-MIN_RETRACT && !retracted[active_extruder]) || (echange>MIN_RETRACT && retracted[active_extruder])) { //move appears to be an attempt to retract or recover
current_position[E_AXIS] = destination[E_AXIS]; //hide the slicer-generated retract/recover from calculations current_position[E_AXIS] = destination[E_AXIS]; //hide the slicer-generated retract/recover from calculations
plan_set_e_position(current_position[E_AXIS]); //AND from the planner plan_set_e_position(current_position[E_AXIS]); //AND from the planner
retract(!retracted); retract(!retracted[active_extruder]);
return; return;
} }
@ -6437,10 +6466,10 @@ Sigma_Exit:
#ifdef PINDA_THERMISTOR #ifdef PINDA_THERMISTOR
case 860: // M860 - Wait for PINDA thermistor to reach target temperature. case 860: // M860 - Wait for PINDA thermistor to reach target temperature.
{ {
int setTargetPinda = 0; int set_target_pinda = 0;
if (code_seen('S')) { if (code_seen('S')) {
setTargetPinda = code_value(); set_target_pinda = code_value();
} }
else { else {
break; break;
@ -6449,19 +6478,24 @@ Sigma_Exit:
LCD_MESSAGERPGM(_T(MSG_PLEASE_WAIT)); LCD_MESSAGERPGM(_T(MSG_PLEASE_WAIT));
SERIAL_PROTOCOLPGM("Wait for PINDA target temperature:"); SERIAL_PROTOCOLPGM("Wait for PINDA target temperature:");
SERIAL_PROTOCOL(setTargetPinda); SERIAL_PROTOCOL(set_target_pinda);
SERIAL_PROTOCOLLN(""); SERIAL_PROTOCOLLN("");
codenum = millis(); codenum = millis();
cancel_heatup = false; cancel_heatup = false;
while ((!cancel_heatup) && current_temperature_pinda < setTargetPinda) { bool is_pinda_cooling = false;
if ((degTargetBed() == 0) && (degTargetHotend(0) == 0)) {
is_pinda_cooling = true;
}
while ( ((!is_pinda_cooling) && (!cancel_heatup) && (current_temperature_pinda < set_target_pinda)) || (is_pinda_cooling && (current_temperature_pinda > set_target_pinda)) ) {
if ((millis() - codenum) > 1000) //Print Temp Reading every 1 second while waiting. if ((millis() - codenum) > 1000) //Print Temp Reading every 1 second while waiting.
{ {
SERIAL_PROTOCOLPGM("P:"); SERIAL_PROTOCOLPGM("P:");
SERIAL_PROTOCOL_F(current_temperature_pinda, 1); SERIAL_PROTOCOL_F(current_temperature_pinda, 1);
SERIAL_PROTOCOLPGM("/"); SERIAL_PROTOCOLPGM("/");
SERIAL_PROTOCOL(setTargetPinda); SERIAL_PROTOCOL(set_target_pinda);
SERIAL_PROTOCOLLN(""); SERIAL_PROTOCOLLN("");
codenum = millis(); codenum = millis();
} }
@ -6473,6 +6507,7 @@ Sigma_Exit:
break; break;
} }
case 861: // M861 - Set/Read PINDA temperature compensation offsets case 861: // M861 - Set/Read PINDA temperature compensation offsets
if (code_seen('?')) { // ? - Print out current EEPROM offset values if (code_seen('?')) { // ? - Print out current EEPROM offset values
uint8_t cal_status = calibration_status_pinda(); uint8_t cal_status = calibration_status_pinda();
@ -6981,7 +7016,7 @@ void FlushSerialRequestResend()
void ClearToSend() void ClearToSend()
{ {
previous_millis_cmd = millis(); previous_millis_cmd = millis();
if (CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB) if ((CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB) || (CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR))
SERIAL_PROTOCOLLNRPGM(_T(MSG_OK)); SERIAL_PROTOCOLLNRPGM(_T(MSG_OK));
} }
@ -7277,7 +7312,6 @@ static void handleSafetyTimer()
#if (EXTRUDERS > 1) #if (EXTRUDERS > 1)
#error Implemented only for one extruder. #error Implemented only for one extruder.
#endif //(EXTRUDERS > 1) #endif //(EXTRUDERS > 1)
static Timer safetyTimer;
if (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == 4) || saved_printing if (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == 4) || saved_printing
|| (lcd_commands_type == LCD_COMMAND_V2_CAL) || (!degTargetBed() && !degTargetHotend(0))) || (lcd_commands_type == LCD_COMMAND_V2_CAL) || (!degTargetBed() && !degTargetHotend(0)))
{ {
@ -8142,7 +8176,6 @@ void uvlo_()
// Conserve power as soon as possible. // Conserve power as soon as possible.
disable_x(); disable_x();
disable_y(); disable_y();
disable_e0();
#ifdef TMC2130 #ifdef TMC2130
tmc2130_set_current_h(Z_AXIS, 20); tmc2130_set_current_h(Z_AXIS, 20);
@ -8242,11 +8275,19 @@ void uvlo_()
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position[X_AXIS]); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position[X_AXIS]);
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position[Y_AXIS]); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position[Y_AXIS]);
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z), current_position[Z_AXIS]); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z), current_position[Z_AXIS]);
// Store the current feed rate, temperatures and fan speed. // Store the current feed rate, temperatures, fan speed and extruder multipliers (flow rates)
EEPROM_save_B(EEPROM_UVLO_FEEDRATE, &feedrate_bckp); EEPROM_save_B(EEPROM_UVLO_FEEDRATE, &feedrate_bckp);
eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, target_temperature[active_extruder]); eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, target_temperature[active_extruder]);
eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_BED, target_temperature_bed); eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_BED, target_temperature_bed);
eeprom_update_byte((uint8_t*)EEPROM_UVLO_FAN_SPEED, fanSpeed); eeprom_update_byte((uint8_t*)EEPROM_UVLO_FAN_SPEED, fanSpeed);
eeprom_update_float((float*)(EEPROM_EXTRUDER_MULTIPLIER_0), extruder_multiplier[0]);
#if EXTRUDERS > 1
eeprom_update_float((float*)(EEPROM_EXTRUDER_MULTIPLIER_1), extruder_multiplier[1]);
#if EXTRUDERS > 2
eeprom_update_float((float*)(EEPROM_EXTRUDER_MULTIPLIER_2), extruder_multiplier[2]);
#endif
#endif
// Finaly store the "power outage" flag. // Finaly store the "power outage" flag.
if(sd_print) eeprom_update_byte((uint8_t*)EEPROM_UVLO, 1); if(sd_print) eeprom_update_byte((uint8_t*)EEPROM_UVLO, 1);
@ -8350,13 +8391,7 @@ void recover_print(uint8_t automatic) {
lcd_update(2); lcd_update(2);
lcd_setstatuspgm(_i("Recovering print "));////MSG_RECOVERING_PRINT c=20 r=1 lcd_setstatuspgm(_i("Recovering print "));////MSG_RECOVERING_PRINT c=20 r=1
recover_machine_state_after_power_panic(); recover_machine_state_after_power_panic(); //recover position, temperatures and extrude_multipliers
// Set the target bed and nozzle temperatures.
sprintf_P(cmd, PSTR("M104 S%d"), target_temperature[active_extruder]);
enquecommand(cmd);
sprintf_P(cmd, PSTR("M140 S%d"), target_temperature_bed);
enquecommand(cmd);
// Lift the print head, so one may remove the excess priming material. // Lift the print head, so one may remove the excess priming material.
if (current_position[Z_AXIS] < 25) if (current_position[Z_AXIS] < 25)
@ -8458,6 +8493,16 @@ void recover_machine_state_after_power_panic()
// 7) Recover the target temperatures. // 7) Recover the target temperatures.
target_temperature[active_extruder] = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND); target_temperature[active_extruder] = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND);
target_temperature_bed = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED); target_temperature_bed = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED);
// 8) Recover extruder multipilers
extruder_multiplier[0] = eeprom_read_float((float*)(EEPROM_EXTRUDER_MULTIPLIER_0));
#if EXTRUDERS > 1
extruder_multiplier[1] = eeprom_read_float((float*)(EEPROM_EXTRUDER_MULTIPLIER_1));
#if EXTRUDERS > 2
extruder_multiplier[2] = eeprom_read_float((float*)(EEPROM_EXTRUDER_MULTIPLIER_2));
#endif
#endif
} }
void restore_print_from_eeprom() { void restore_print_from_eeprom() {
@ -8544,13 +8589,34 @@ void restore_print_from_eeprom() {
void stop_and_save_print_to_ram(float z_move, float e_move) void stop_and_save_print_to_ram(float z_move, float e_move)
{ {
if (saved_printing) return; if (saved_printing) return;
unsigned char nplanner_blocks;
unsigned char nlines;
uint16_t sdlen_planner;
uint16_t sdlen_cmdqueue;
cli(); cli();
unsigned char nplanner_blocks = number_of_blocks(); if (card.sdprinting) {
saved_sdpos = sdpos_atomic; //atomic sd position of last command added in queue nplanner_blocks = number_of_blocks();
uint16_t sdlen_planner = planner_calc_sd_length(); //length of sd commands in planner saved_sdpos = sdpos_atomic; //atomic sd position of last command added in queue
saved_sdpos -= sdlen_planner; sdlen_planner = planner_calc_sd_length(); //length of sd commands in planner
uint16_t sdlen_cmdqueue = cmdqueue_calc_sd_length(); //length of sd commands in cmdqueue saved_sdpos -= sdlen_planner;
saved_sdpos -= sdlen_cmdqueue; sdlen_cmdqueue = cmdqueue_calc_sd_length(); //length of sd commands in cmdqueue
saved_sdpos -= sdlen_cmdqueue;
saved_printing_type = PRINTING_TYPE_SD;
}
else if (is_usb_printing) { //reuse saved_sdpos for storing line number
saved_sdpos = gcode_LastN; //start with line number of command added recently to cmd queue
//reuse planner_calc_sd_length function for getting number of lines of commands in planner:
nlines = planner_calc_sd_length(); //number of lines of commands in planner
saved_sdpos -= nlines;
saved_sdpos -= buflen; //number of blocks in cmd buffer
saved_printing_type = PRINTING_TYPE_USB;
}
else {
//not sd printing nor usb printing
}
#if 0 #if 0
SERIAL_ECHOPGM("SDPOS_ATOMIC="); MYSERIAL.println(sdpos_atomic, DEC); SERIAL_ECHOPGM("SDPOS_ATOMIC="); MYSERIAL.println(sdpos_atomic, DEC);
@ -8559,7 +8625,8 @@ void stop_and_save_print_to_ram(float z_move, float e_move)
SERIAL_ECHOPGM("SDLEN_CMDQ="); MYSERIAL.println(sdlen_cmdqueue, DEC); SERIAL_ECHOPGM("SDLEN_CMDQ="); MYSERIAL.println(sdlen_cmdqueue, DEC);
SERIAL_ECHOPGM("PLANNERBLOCKS="); MYSERIAL.println(int(nplanner_blocks), DEC); SERIAL_ECHOPGM("PLANNERBLOCKS="); MYSERIAL.println(int(nplanner_blocks), DEC);
SERIAL_ECHOPGM("SDSAVED="); MYSERIAL.println(saved_sdpos, DEC); SERIAL_ECHOPGM("SDSAVED="); MYSERIAL.println(saved_sdpos, DEC);
SERIAL_ECHOPGM("SDFILELEN="); MYSERIAL.println(card.fileSize(), DEC); //SERIAL_ECHOPGM("SDFILELEN="); MYSERIAL.println(card.fileSize(), DEC);
{ {
card.setIndex(saved_sdpos); card.setIndex(saved_sdpos);
@ -8571,7 +8638,6 @@ void stop_and_save_print_to_ram(float z_move, float e_move)
MYSERIAL.print(char(card.get())); MYSERIAL.print(char(card.get()));
SERIAL_ECHOLNPGM("End of command buffer"); SERIAL_ECHOLNPGM("End of command buffer");
} }
{ {
// Print the content of the planner buffer, line by line: // Print the content of the planner buffer, line by line:
card.setIndex(saved_sdpos); card.setIndex(saved_sdpos);
@ -8666,11 +8732,17 @@ void stop_and_save_print_to_ram(float z_move, float e_move)
#if 1 #if 1
// Rather than calling plan_buffer_line directly, push the move into the command queue, // Rather than calling plan_buffer_line directly, push the move into the command queue,
char buf[48]; char buf[48];
// First unretract (relative extrusion)
strcpy_P(buf, PSTR("G1 E"));
dtostrf(e_move, 6, 3, buf + strlen(buf));
strcat_P(buf, PSTR(" F"));
dtostrf(retract_feedrate*60, 8, 3, buf + strlen(buf));
enquecommand(buf, false);
// Then lift Z axis
strcpy_P(buf, PSTR("G1 Z")); strcpy_P(buf, PSTR("G1 Z"));
dtostrf(saved_pos[Z_AXIS] + z_move, 8, 3, buf + strlen(buf)); dtostrf(saved_pos[Z_AXIS] + z_move, 8, 3, buf + strlen(buf));
strcat_P(buf, PSTR(" E"));
// Relative extrusion
dtostrf(e_move, 6, 3, buf + strlen(buf));
strcat_P(buf, PSTR(" F")); strcat_P(buf, PSTR(" F"));
dtostrf(homing_feedrate[Z_AXIS], 8, 3, buf + strlen(buf)); dtostrf(homing_feedrate[Z_AXIS], 8, 3, buf + strlen(buf));
// At this point the command queue is empty. // At this point the command queue is empty.
@ -8697,14 +8769,23 @@ void restore_print_from_ram_and_continue(float e_move)
float e = saved_pos[E_AXIS] - e_move; float e = saved_pos[E_AXIS] - e_move;
plan_set_e_position(e); plan_set_e_position(e);
plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS], saved_pos[E_AXIS], homing_feedrate[Z_AXIS]/13, active_extruder); plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS], saved_pos[E_AXIS], homing_feedrate[Z_AXIS]/13, active_extruder);
st_synchronize(); st_synchronize();
memcpy(current_position, saved_pos, sizeof(saved_pos)); memcpy(current_position, saved_pos, sizeof(saved_pos));
memcpy(destination, current_position, sizeof(destination)); memcpy(destination, current_position, sizeof(destination));
card.setIndex(saved_sdpos); if (saved_printing_type == PRINTING_TYPE_SD) { //was sd printing
sdpos_atomic = saved_sdpos; card.setIndex(saved_sdpos);
card.sdprinting = true; sdpos_atomic = saved_sdpos;
card.sdprinting = true;
}
else if (saved_printing_type == PRINTING_TYPE_USB) { //was usb printing
gcode_LastN = saved_sdpos; //saved_sdpos was reused for storing line number when usb printing
FlushSerialRequestResend();
}
else {
//not sd printing nor usb printing
}
saved_printing = false; saved_printing = false;
printf_P(PSTR("ok\n")); //dummy response because of octoprint is waiting for this
} }
void print_world_coordinates() void print_world_coordinates()

View file

@ -12,14 +12,16 @@
* It is guaranteed, that construction is equivalent with zeroing all members. * It is guaranteed, that construction is equivalent with zeroing all members.
* This property can be exploited in MenuData union. * This property can be exploited in MenuData union.
*/ */
Timer::Timer() : m_isRunning(false), m_started() template<typename T>
Timer<T>::Timer() : m_isRunning(false), m_started()
{ {
} }
/** /**
* @brief Start timer * @brief Start timer
*/ */
void Timer::start() template<typename T>
void Timer<T>::start()
{ {
m_started = millis(); m_started = millis();
m_isRunning = true; m_isRunning = true;
@ -29,19 +31,21 @@ void Timer::start()
* @brief Timer has expired * @brief Timer has expired
* *
* Timer is considered expired after msPeriod has passed from time the timer was started. * Timer is considered expired after msPeriod has passed from time the timer was started.
* This function must be called at least each (unsigned long maximum value - msPeriod) milliseconds to be sure to * Timer is stopped after expiration.
* This function must be called at least each (T maximum value - msPeriod) milliseconds to be sure to
* catch first expiration. * catch first expiration.
* This function is expected to handle wrap around of time register well. * This function is expected to handle wrap around of time register well.
* *
* @param msPeriod Time interval in milliseconds. * @param msPeriod Time interval in milliseconds. Do not omit "ul" when using constant literal with LongTimer.
* @retval true Timer has expired * @retval true Timer has expired
* @retval false Timer not expired yet, or is not running, or time window in which is timer considered expired passed. * @retval false Timer not expired yet, or is not running, or time window in which is timer considered expired passed.
*/ */
bool Timer::expired(unsigned long msPeriod) template<typename T>
bool Timer<T>::expired(T msPeriod)
{ {
if (!m_isRunning) return false; if (!m_isRunning) return false;
bool expired = false; bool expired = false;
const unsigned long now = millis(); const T now = millis();
if (m_started <= m_started + msPeriod) if (m_started <= m_started + msPeriod)
{ {
if ((now >= m_started + msPeriod) || (now < m_started)) if ((now >= m_started + msPeriod) || (now < m_started))
@ -59,3 +63,6 @@ bool Timer::expired(unsigned long msPeriod)
if (expired) m_isRunning = false; if (expired) m_isRunning = false;
return expired; return expired;
} }
template class Timer<unsigned long>;
template class Timer<unsigned short>;

View file

@ -1,4 +1,4 @@
/* /**
* @file * @file
* @author Marek Bel * @author Marek Bel
*/ */
@ -10,10 +10,10 @@
* @brief simple timer * @brief simple timer
* *
* Simple and memory saving implementation. Should handle timer register wrap around well. * Simple and memory saving implementation. Should handle timer register wrap around well.
* Maximum period is at least 49 days. Resolution is one millisecond. To save memory, doesn't store timer period. * Resolution is one millisecond. To save memory, doesn't store timer period.
* If you wish timer which is storing period, derive from this. If you need time intervals smaller than 65 seconds * If you wish timer which is storing period, derive from this.
* consider implementing timer with smaller underlying type.
*/ */
template <class T>
class Timer class Timer
{ {
public: public:
@ -21,10 +21,31 @@ public:
void start(); void start();
void stop(){m_isRunning = false;} void stop(){m_isRunning = false;}
bool running(){return m_isRunning;} bool running(){return m_isRunning;}
bool expired(unsigned long msPeriod); bool expired(T msPeriod);
private: private:
bool m_isRunning; bool m_isRunning;
unsigned long m_started; T m_started;
}; };
/**
* @brief Timer unsigned long specialization
*
* Maximum period is at least 49 days.
*/
#if __cplusplus>=201103L
using LongTimer = Timer<unsigned long>;
#else
typedef Timer<unsigned long> LongTimer;
#endif
/**
* @brief Timer unsigned short specialization
*
* Maximum period is at least 65 seconds.
*/
#if __cplusplus>=201103L
using ShortTimer = Timer<unsigned short>;
#else
typedef Timer<unsigned short> ShortTimer;
#endif
#endif /* TIMER_H */ #endif /* TIMER_H */

View file

@ -413,6 +413,9 @@ void get_command()
} }
cmdbuffer[bufindw+serial_count+CMDHDRSIZE] = 0; //terminate string cmdbuffer[bufindw+serial_count+CMDHDRSIZE] = 0; //terminate string
if(!comment_mode){ if(!comment_mode){
gcode_N = 0;
// Line numbers must be first in buffer // Line numbers must be first in buffer
if ((strstr(cmdbuffer+bufindw+CMDHDRSIZE, "PRUSA") == NULL) && if ((strstr(cmdbuffer+bufindw+CMDHDRSIZE, "PRUSA") == NULL) &&
@ -494,7 +497,8 @@ void get_command()
kill("", 2); kill("", 2);
// Store the current line into buffer, move to the next line. // Store the current line into buffer, move to the next line.
cmdbuffer[bufindw] = CMDBUFFER_CURRENT_TYPE_USB; // Store type of entry
cmdbuffer[bufindw] = gcode_N ? CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR : CMDBUFFER_CURRENT_TYPE_USB;
#ifdef CMDBUFFER_DEBUG #ifdef CMDBUFFER_DEBUG
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOPGM("Storing a command line to buffer: "); SERIAL_ECHOPGM("Storing a command line to buffer: ");

View file

@ -22,6 +22,8 @@
// to the planner queue, but not yet removed from the cmdqueue. // to the planner queue, but not yet removed from the cmdqueue.
// This is a temporary state to reduce stepper interrupt locking time. // This is a temporary state to reduce stepper interrupt locking time.
#define CMDBUFFER_CURRENT_TYPE_TO_BE_REMOVED 5 #define CMDBUFFER_CURRENT_TYPE_TO_BE_REMOVED 5
//Command in cmdbuffer was sent over USB and contains line number
#define CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR 6
// How much space to reserve for the chained commands // How much space to reserve for the chained commands
// of type CMDBUFFER_CURRENT_TYPE_CHAINED, // of type CMDBUFFER_CURRENT_TYPE_CHAINED,

2494
Firmware/doxyfile Normal file

File diff suppressed because it is too large Load diff

View file

@ -111,7 +111,7 @@ union MenuData
struct AutoLoadFilamentMenu struct AutoLoadFilamentMenu
{ {
//Timer timer; //ShortTimer timer;
char dummy; char dummy;
} autoLoadFilamentMenu; } autoLoadFilamentMenu;
struct _Lcd_moveMenu struct _Lcd_moveMenu
@ -168,14 +168,13 @@ uint8_t farm_mode = 0;
int farm_no = 0; int farm_no = 0;
int farm_timer = 8; int farm_timer = 8;
int farm_status = 0; int farm_status = 0;
unsigned long allert_timer = millis();
bool printer_connected = true; bool printer_connected = true;
unsigned long display_time; //just timer for showing pid finished message on lcd; unsigned long display_time; //just timer for showing pid finished message on lcd;
float pid_temp = DEFAULT_PID_TEMP; float pid_temp = DEFAULT_PID_TEMP;
bool long_press_active = false; bool long_press_active = false;
long long_press_timer = millis(); static ShortTimer longPressTimer;
unsigned long button_blanking_time = millis(); unsigned long button_blanking_time = millis();
bool button_pressed = false; bool button_pressed = false;
@ -1607,7 +1606,7 @@ static void lcd_menu_fails_stats_total()
uint16_t filam = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); 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 crashX = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT);
uint16_t crashY = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_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); 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);
if (lcd_clicked()) if (lcd_clicked())
{ {
lcd_quick_feedback(); lcd_quick_feedback();
@ -1627,7 +1626,7 @@ static void lcd_menu_fails_stats_print()
uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT); 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 crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X);
uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y); 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); 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);
if (lcd_clicked()) if (lcd_clicked())
{ {
lcd_quick_feedback(); lcd_quick_feedback();
@ -1669,7 +1668,7 @@ static void lcd_menu_fails_stats()
{ {
uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT); uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
uint16_t filamentTotal = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); 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); 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);
if (lcd_clicked()) if (lcd_clicked())
{ {
menu_action_back(); menu_action_back();
@ -1688,7 +1687,7 @@ extern char* __malloc_heap_end;
static void lcd_menu_debug() static void lcd_menu_debug()
{ {
#ifdef DEBUG_STACK_MONITOR #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); 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);
#endif //DEBUG_STACK_MONITOR #endif //DEBUG_STACK_MONITOR
if (lcd_clicked()) if (lcd_clicked())
@ -1701,11 +1700,11 @@ static void lcd_menu_debug()
static void lcd_menu_temperatures() 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'); 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');
#ifdef AMBIENT_THERMISTOR #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'); 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');
#else //AMBIENT_THERMISTOR #else //AMBIENT_THERMISTOR
fprintf_P(lcdout, PSTR(ESC_H(1,2)"PINDA: %d%c"), (int)current_temperature_pinda, '\x01'); fprintf_P(lcdout, PSTR(ESC_H(1,2) "PINDA: %d%c"), (int)current_temperature_pinda, '\x01');
#endif //AMBIENT_THERMISTOR #endif //AMBIENT_THERMISTOR
if (lcd_clicked()) if (lcd_clicked())
@ -2090,7 +2089,7 @@ static void lcd_menu_AutoLoadFilament()
} }
else else
{ {
Timer* ptimer = (Timer*)&(menuData.autoLoadFilamentMenu.dummy); ShortTimer* ptimer = (ShortTimer*)&(menuData.autoLoadFilamentMenu.dummy);
if (!ptimer->running()) ptimer->start(); if (!ptimer->running()) ptimer->start();
lcd.setCursor(0, 0); lcd.setCursor(0, 0);
lcd_printPGM(_T(MSG_ERROR)); lcd_printPGM(_T(MSG_ERROR));
@ -2675,7 +2674,7 @@ bool lcd_wait_for_pinda(float temp) {
lcd_set_custom_characters_degree(); lcd_set_custom_characters_degree();
setTargetHotend(0, 0); setTargetHotend(0, 0);
setTargetBed(0); setTargetBed(0);
Timer pinda_timeout; LongTimer pinda_timeout;
pinda_timeout.start(); pinda_timeout.start();
bool target_temp_reached = true; bool target_temp_reached = true;
@ -5104,20 +5103,6 @@ static void lcd_disable_farm_mode() {
} }
static void lcd_ping_allert() {
if ((abs(millis() - allert_timer)*0.001) > PING_ALLERT_PERIOD) {
allert_timer = millis();
SET_OUTPUT(BEEPER);
for (int i = 0; i < 2; i++) {
WRITE(BEEPER, HIGH);
delay(50);
WRITE(BEEPER, LOW);
delay(100);
}
}
};
#ifdef SNMM #ifdef SNMM
@ -7725,7 +7710,6 @@ void lcd_ping() { //chceck if printer is connected to monitoring when in farm mo
//if there are comamnds in buffer, some long gcodes can delay execution of ping command //if there are comamnds in buffer, some long gcodes can delay execution of ping command
//therefore longer period is used //therefore longer period is used
printer_connected = false; printer_connected = false;
//lcd_ping_allert(); //acustic signals
} }
else { else {
lcd_printer_connected(); lcd_printer_connected();
@ -7816,12 +7800,11 @@ void lcd_buttons_update()
if (millis() > button_blanking_time) { if (millis() > button_blanking_time) {
button_blanking_time = millis() + BUTTON_BLANKING_TIME; button_blanking_time = millis() + BUTTON_BLANKING_TIME;
if (button_pressed == false && long_press_active == false) { if (button_pressed == false && long_press_active == false) {
long_press_timer = millis(); longPressTimer.start();
button_pressed = true; button_pressed = true;
} }
else { else {
if (millis() - long_press_timer > LONG_PRESS_TIME) { //long press activated if (longPressTimer.expired(LONG_PRESS_TIME)) {
long_press_active = true; long_press_active = true;
move_menu_scale = 1.0; move_menu_scale = 1.0;
menu_action_submenu(lcd_move_z); menu_action_submenu(lcd_move_z);

View file

@ -263,7 +263,6 @@ static float count_e(float layer_heigth, float extrusion_width, float extrusion_
static void lcd_babystep_z(); static void lcd_babystep_z();
void stack_error(); void stack_error();
static void lcd_ping_allert();
void lcd_printer_connected(); void lcd_printer_connected();
void lcd_ping(); void lcd_ping();

View file

@ -830,8 +830,12 @@ if (print_sd_status)
#endif #endif
} }
#ifdef CMD_DIAGNOSTICS
lcd.setCursor(LCD_WIDTH - 8 -1, 2);
lcd_printPGM(PSTR(" C"));
lcd.print(buflen); // number of commands in cmd buffer
if (buflen < 9) lcd_printPGM(" ");
#else
//Print time elapsed //Print time elapsed
lcd.setCursor(LCD_WIDTH - 8 -1, 2); lcd.setCursor(LCD_WIDTH - 8 -1, 2);
lcd_printPGM(PSTR(" ")); lcd_printPGM(PSTR(" "));
@ -846,6 +850,7 @@ if (print_sd_status)
lcd_printPGM(PSTR("--:--")); lcd_printPGM(PSTR("--:--"));
} }
lcd_printPGM(PSTR(" ")); lcd_printPGM(PSTR(" "));
#endif //CMD_DIAGNOSTICS
#ifdef DEBUG_DISABLE_LCD_STATUS_LINE #ifdef DEBUG_DISABLE_LCD_STATUS_LINE
return; return;