diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index e6c5685d0..6797b954b 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -275,6 +275,17 @@ FORCE_INLINE unsigned long millis_nc() { void setPwmFrequency(uint8_t pin, int val); #endif +enum class HeatingStatus : uint8_t +{ + NO_HEATING = 0, + EXTRUDER_HEATING = 1, + EXTRUDER_HEATING_COMPLETE = 2, + BED_HEATING = 3, + BED_HEATING_COMPLETE = 4, +}; + +extern HeatingStatus heating_status; + extern bool fans_check_enabled; extern float homing_feedrate[]; extern uint8_t axis_relative_modes; @@ -319,18 +330,13 @@ extern int bowden_length[4]; extern bool is_usb_printing; extern bool homing_flag; extern bool loading_flag; -extern unsigned int usb_printing_counter; - -extern unsigned long kicktime; - +extern uint8_t usb_printing_counter; extern unsigned long total_filament_used; void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time); -extern unsigned int heating_status; extern unsigned int status_number; -extern unsigned int heating_status_counter; +extern uint8_t heating_status_counter; extern char snmm_filaments_used; extern unsigned long PingTime; -extern unsigned long NcTime; extern bool no_response; extern uint8_t important_status; extern uint8_t saved_filament_type; diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 284262d6a..4b8dd2d1a 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -161,7 +161,6 @@ CardReader card; #endif unsigned long PingTime = _millis(); -unsigned long NcTime; uint8_t mbl_z_probe_nr = 3; //numer of Z measurements for each point in mesh bed leveling calibration @@ -196,9 +195,7 @@ int bowden_length[4] = {385, 385, 385, 385}; bool is_usb_printing = false; bool homing_flag = false; -unsigned long kicktime = _millis()+100000; - -unsigned int usb_printing_counter; +uint8_t usb_printing_counter; int8_t lcd_change_fil_state = 0; @@ -206,7 +203,7 @@ unsigned long pause_time = 0; unsigned long start_pause_print = _millis(); unsigned long t_fan_rising_edge = _millis(); LongTimer safetyTimer; -static LongTimer crashDetTimer; +static ShortTimer crashDetTimer; //unsigned long load_filament_time; @@ -220,8 +217,8 @@ bool prusa_sd_card_upload = false; unsigned int status_number = 0; unsigned long total_filament_used; -unsigned int heating_status; -unsigned int heating_status_counter; +HeatingStatus heating_status; +uint8_t heating_status_counter; bool loading_flag = false; #define XY_NO_RESTORE_FLAG (mesh_bed_leveling_flag || homing_flag) @@ -357,14 +354,14 @@ const int8_t sensitive_pins[] PROGMEM = SENSITIVE_PINS; // Sensitive pin list fo //static float bt = 0; //Inactivity shutdown variables -static unsigned long previous_millis_cmd = 0; +static LongTimer previous_millis_cmd; unsigned long max_inactive_time = 0; static unsigned long stepper_inactive_time = DEFAULT_STEPPER_DEACTIVE_TIME*1000l; static unsigned long safetytimer_inactive_time = DEFAULT_SAFETYTIMER_TIME_MINS*60*1000ul; unsigned long starttime=0; unsigned long stoptime=0; -unsigned long _usb_timer = 0; +ShortTimer _usb_timer; bool Stopped=false; @@ -1894,11 +1891,11 @@ void loop() { KEEPALIVE_STATE(NOT_BUSY); - if ((usb_printing_counter > 0) && ((_millis()-_usb_timer) > 1000)) + if ((usb_printing_counter > 0) && _usb_timer.expired(1000)) { is_usb_printing = true; usb_printing_counter--; - _usb_timer = _millis(); + _usb_timer.start(); // reset timer } if (usb_printing_counter == 0) { @@ -2060,7 +2057,7 @@ static int setup_for_endstop_move(bool enable_endstops_now = true) { saved_feedrate = feedrate; int l_feedmultiply = feedmultiply; feedmultiply = 100; - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); enable_endstops(enable_endstops_now); return l_feedmultiply; @@ -2074,7 +2071,7 @@ static void clean_up_after_endstop_move(int original_feedmultiply) { feedrate = saved_feedrate; feedmultiply = original_feedmultiply; - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); } @@ -2518,7 +2515,7 @@ void home_xy() void refresh_cmd_timeout(void) { - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); } #ifdef FWRETRACT @@ -2820,14 +2817,9 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon if (home_z) babystep_undo(); - saved_feedrate = feedrate; - int l_feedmultiply = feedmultiply; - feedmultiply = 100; - previous_millis_cmd = _millis(); + int l_feedmultiply = setup_for_endstop_move(); - enable_endstops(true); - - memcpy(destination, current_position, sizeof(destination)); + set_destination_to_current(); feedrate = 0.0; #if Z_HOME_DIR > 0 // If homing away from BED do Z first @@ -3000,13 +2992,7 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon // contains the machine coordinates. plan_set_position_curposXYZE(); - #ifdef ENDSTOPS_ONLY_FOR_HOMING - enable_endstops(false); - #endif - - feedrate = saved_feedrate; - feedmultiply = l_feedmultiply; - previous_millis_cmd = _millis(); + clean_up_after_endstop_move(l_feedmultiply); endstops_hit_on_purpose(); #ifndef MESH_BED_LEVELING //-// Oct 2019 :: this part of code is (from) now probably un-compilable @@ -3121,7 +3107,7 @@ static void gcode_G80() #endif //PINDA_THERMISTOR // Save custom message state, set a new custom message state to display: Calibrating point 9. CustomMsg custom_message_type_old = custom_message_type; - unsigned int custom_message_state_old = custom_message_state; + uint8_t custom_message_state_old = custom_message_state; custom_message_type = CustomMsg::MeshBedLeveling; custom_message_state = (nMeasPoints * nMeasPoints) + 10; lcd_update(1); @@ -3850,7 +3836,7 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float plan_set_e_position(lastpos[E_AXIS]); memcpy(current_position, lastpos, sizeof(lastpos)); - memcpy(destination, current_position, sizeof(current_position)); + set_destination_to_current(); //Recover feed rate feedmultiply = feedmultiplyBckp; @@ -4359,7 +4345,7 @@ void process_commands() } lcd_ignore_click(); //call lcd_ignore_click also for else ??? st_synchronize(); - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); if (codenum > 0 ) { codenum += _millis(); // keep track of when we started waiting KEEPALIVE_STATE(PAUSED_FOR_USER); @@ -4493,7 +4479,7 @@ void process_commands() Set of internal PRUSA commands #### Usage - PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ] + PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | FR ] #### Parameters - `Ping` @@ -4511,7 +4497,6 @@ void process_commands() - `Rev`- Prints filament size, elelectronics, nozzle type - `Lang` - Reset the language - `Lz` - - `Beat` - Kick farm link timer - `FR` - Full factory reset - `nozzle set ` - set nozzle diameter (farm mode only), e.g. `PRUSA nozzle set 0.4` - `nozzle D` - check the nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle D0.4` @@ -4601,10 +4586,6 @@ void process_commands() } else if(code_seen_P(PSTR("Lz"))) { // PRUSA Lz eeprom_update_word(reinterpret_cast(&(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)),0); - } else if(code_seen_P(PSTR("Beat"))) { // PRUSA Beat - // Kick farm link timer - kicktime = _millis(); - } else if(code_seen_P(PSTR("FR"))) { // PRUSA FR // Factory full reset factory_reset(0); @@ -4987,7 +4968,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) if(codenum != 0) LCD_MESSAGERPGM(_n("Sleep..."));////MSG_DWELL st_synchronize(); codenum += _millis(); // keep track of when we started waiting - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); while(_millis() < codenum) { manage_heater(); manage_inactivity(); @@ -5644,8 +5625,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) SERIAL_PROTOCOLPGM("\nZ search height: "); SERIAL_PROTOCOL(MESH_HOME_Z_SEARCH); SERIAL_PROTOCOLLNPGM("\nMeasured points:"); - for (int y = MESH_NUM_Y_POINTS-1; y >= 0; y--) { - for (int x = 0; x < MESH_NUM_X_POINTS; x++) { + for (uint8_t y = MESH_NUM_Y_POINTS-1; y >= 0; y--) { + for (uint8_t x = 0; x < MESH_NUM_X_POINTS; x++) { SERIAL_PROTOCOLPGM(" "); SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5); } @@ -6684,7 +6665,7 @@ Sigma_Exit: break; } LCD_MESSAGERPGM(_T(MSG_HEATING)); - heating_status = 1; + heating_status = HeatingStatus::EXTRUDER_HEATING; if (farm_mode) { prusa_statistics(1); }; #ifdef AUTOTEMP @@ -6718,11 +6699,11 @@ Sigma_Exit: LCD_MESSAGERPGM(_T(MSG_HEATING_COMPLETE)); KEEPALIVE_STATE(IN_HANDLER); - heating_status = 2; + heating_status = HeatingStatus::EXTRUDER_HEATING_COMPLETE; if (farm_mode) { prusa_statistics(2); }; //starttime=_millis(); - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); } break; @@ -6744,7 +6725,7 @@ Sigma_Exit: { bool CooldownNoWait = false; LCD_MESSAGERPGM(_T(MSG_BED_HEATING)); - heating_status = 3; + heating_status = HeatingStatus::BED_HEATING; if (farm_mode) { prusa_statistics(1); }; if (code_seen('S')) { @@ -6784,9 +6765,9 @@ Sigma_Exit: } LCD_MESSAGERPGM(_T(MSG_BED_DONE)); KEEPALIVE_STATE(IN_HANDLER); - heating_status = 4; + heating_status = HeatingStatus::BED_HEATING_COMPLETE; - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); } #endif break; @@ -9115,7 +9096,7 @@ Sigma_Exit: #if EXTRUDERS > 1 if (tmp_extruder != active_extruder) { // Save current position to return to after applying extruder offset - memcpy(destination, current_position, sizeof(destination)); + set_destination_to_current(); // Offset extruder (only by XY) int i; for (i = 0; i < 2; i++) { @@ -9565,7 +9546,7 @@ void FlushSerialRequestResend() // Execution of a command from a SD card will not be confirmed. void ClearToSend() { - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); if (buflen && ((CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB) || (CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR))) SERIAL_PROTOCOLLNRPGM(MSG_OK); } @@ -9741,7 +9722,7 @@ void mesh_plan_buffer_line(const float &x, const float &y, const float &z, const void prepare_move() { clamp_to_software_endstops(destination); - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); // Do not use feedmultiply for E or Z only moves if( (current_position[X_AXIS] == destination [X_AXIS]) && (current_position[Y_AXIS] == destination [Y_AXIS])) { @@ -9767,10 +9748,9 @@ void prepare_arc_move(char isclockwise) { // As far as the parser is concerned, the position is now == target. In reality the // motion control system might still be processing the action and the real tool position // in any intermediate location. - for(int8_t i=0; i < NUM_AXIS; i++) { - current_position[i] = destination[i]; - } - previous_millis_cmd = _millis(); + set_current_to_destination(); + + previous_millis_cmd.start(); } #if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1 @@ -10027,11 +10007,11 @@ if(0) get_command(); } - if( (_millis() - previous_millis_cmd) > max_inactive_time ) + if(previous_millis_cmd.expired(max_inactive_time)) if(max_inactive_time) kill(_n("Inactivity Shutdown"), 4); if(stepper_inactive_time) { - if( (_millis() - previous_millis_cmd) > stepper_inactive_time ) + if(previous_millis_cmd.expired(stepper_inactive_time)) { if(blocks_queued() == false && ignore_stepper_queue == false) { disable_x(); @@ -10078,7 +10058,7 @@ if(0) controllerFan(); //Check if fan should be turned on to cool stepper drivers down #endif #ifdef EXTRUDER_RUNOUT_PREVENT - if( (_millis() - previous_millis_cmd) > EXTRUDER_RUNOUT_SECONDS*1000 ) + if(previous_millis_cmd.expired(EXTRUDER_RUNOUT_SECONDS*1000)) if(degHotend(active_extruder)>EXTRUDER_RUNOUT_MINTEMP) { bool oldstatus=READ(E0_ENABLE_PIN); @@ -10091,7 +10071,7 @@ if(0) current_position[E_AXIS]=oldepos; destination[E_AXIS]=oldedes; plan_set_e_position(oldepos); - previous_millis_cmd=_millis(); + previous_millis_cmd.start(); st_synchronize(); WRITE(E0_ENABLE_PIN,oldstatus); } @@ -11442,7 +11422,7 @@ bool recover_machine_state_after_power_panic() // 5) Set the physical positions from the logical positions using the world2machine transformation // This is only done to inizialize Z/E axes with physical locations, since X/Y are unknown. clamp_to_software_endstops(current_position); - memcpy(destination, current_position, sizeof(destination)); + set_destination_to_current(); plan_set_position_curposXYZE(); SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial "); print_world_coordinates(); @@ -11775,7 +11755,7 @@ void stop_and_save_print_to_ram(float z_move, float e_move) plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS] + z_move, saved_pos[E_AXIS] + e_move, homing_feedrate[Z_AXIS], active_extruder); st_synchronize(); //wait moving memcpy(current_position, saved_pos, sizeof(saved_pos)); - memcpy(destination, current_position, sizeof(destination)); + set_destination_to_current(); #endif waiting_inside_plan_buffer_line_print_aborted = true; //unroll the stack } @@ -11807,9 +11787,9 @@ void restore_print_from_ram_and_continue(float e_move) if (degTargetHotend(saved_active_extruder) != saved_extruder_temperature) { setTargetHotendSafe(saved_extruder_temperature, saved_active_extruder); - heating_status = 1; + heating_status = HeatingStatus::EXTRUDER_HEATING; wait_for_heater(_millis(), saved_active_extruder); - heating_status = 2; + heating_status = HeatingStatus::EXTRUDER_HEATING_COMPLETE; } axis_relative_modes ^= (-saved_extruder_relative_mode ^ axis_relative_modes) & E_AXIS_MASK; float e = saved_pos[E_AXIS] - e_move; @@ -11843,7 +11823,7 @@ void restore_print_from_ram_and_continue(float e_move) feedmultiply = saved_feedmultiply2; memcpy(current_position, saved_pos, sizeof(saved_pos)); - memcpy(destination, current_position, sizeof(destination)); + set_destination_to_current(); if (saved_printing_type == PRINTING_TYPE_SD) { //was sd printing card.setIndex(saved_sdpos); sdpos_atomic = saved_sdpos; diff --git a/Firmware/Sd2Card.h b/Firmware/Sd2Card.h index 6fb700e70..ae78f6d7b 100644 --- a/Firmware/Sd2Card.h +++ b/Firmware/Sd2Card.h @@ -160,9 +160,9 @@ class Sd2Card { /** * \return error code for last error. See Sd2Card.h for a list of error codes. */ - int errorCode() const {return errorCode_;} + uint8_t errorCode() const {return errorCode_;} /** \return error data for last error. */ - int errorData() const {return status_;} + uint8_t errorData() const {return status_;} /** * Initialize an SD flash memory card with default clock rate and chip * select pin. See sd2Card::init(uint8_t sckRateID). diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index d4fd92ed1..c23559c98 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -25,7 +25,6 @@ CardReader::CardReader() cardOK = false; saving = false; logging = false; - autostart_atmillis=0; workDirDepth = 0; file_subcall_ctr=0; memset(workDirParents, 0, sizeof(workDirParents)); @@ -39,7 +38,7 @@ CardReader::CardReader() WRITE(SDPOWER,HIGH); #endif //SDPOWER - autostart_atmillis=_millis()+5000; + autostart_atmillis.start(); // reset timer } char *createFilename(char *buffer,const dir_t &p) //buffer>12characters @@ -619,7 +618,7 @@ void CardReader::checkautostart(bool force) { if(!autostart_stilltocheck) return; - if(autostart_atmillis<_millis()) + if(autostart_atmillis.expired(5000)) return; } autostart_stilltocheck=false; diff --git a/Firmware/cardreader.h b/Firmware/cardreader.h index 32a024529..d13caa08b 100644 --- a/Firmware/cardreader.h +++ b/Firmware/cardreader.h @@ -130,7 +130,7 @@ private: char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH]; uint32_t filesize; //int16_t n; - unsigned long autostart_atmillis; + ShortTimer autostart_atmillis; uint32_t sdpos ; bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware. diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index 7cd0c4635..a48fcdb5c 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -443,7 +443,7 @@ void get_command() char *p = cmdbuffer+bufindw+CMDHDRSIZE; while (p != strchr_pointer) checksum = checksum^(*p++); - if (int(strtol(strchr_pointer+1, NULL, 10)) != int(checksum)) { + if (code_value_short() != (int16_t)checksum) { SERIAL_ERROR_START; SERIAL_ERRORRPGM(_n("checksum mismatch, Last Line: "));////MSG_ERR_CHECKSUM_MISMATCH SERIAL_ERRORLN(gcode_LastN); @@ -486,8 +486,7 @@ void get_command() is_usb_printing = true; } if (Stopped == true) { - int gcode = strtol(strchr_pointer+1, NULL, 10); - if (gcode >= 0 && gcode <= 3) { + if (code_value_uint8() <= 3) { SERIAL_ERRORLNRPGM(MSG_ERR_STOPPED); LCD_MESSAGERPGM(_T(MSG_STOPPED)); } diff --git a/Firmware/lcd.cpp b/Firmware/lcd.cpp index 024f973f9..bee207493 100644 --- a/Firmware/lcd.cpp +++ b/Firmware/lcd.cpp @@ -331,7 +331,7 @@ void lcd_no_autoscroll(void) void lcd_set_cursor(uint8_t col, uint8_t row) { - int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; + uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; if (row >= LCD_HEIGHT) row = LCD_HEIGHT - 1; // we count rows starting w/0 lcd_currline = row; diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index fe58686cf..32efbcd0b 100755 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -152,9 +152,7 @@ void menu_submenu_no_reset(menu_func_t submenu) uint8_t menu_item_ret(void) { - lcd_beeper_quick_feedback(); - lcd_draw_update = 2; - lcd_button_pressed = false; + lcd_quick_feedback(); return 1; } diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index f97851059..23d7c8736 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -2852,7 +2852,7 @@ bool sample_mesh_and_store_reference() current_position[Y_AXIS] = BED_Y0; world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]); go_to_current(homing_feedrate[X_AXIS]/60); - memcpy(destination, current_position, sizeof(destination)); + set_destination_to_current(); enable_endstops(true); homeaxis(Z_AXIS); diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 89aeea3e6..0d6ebe4c2 100755 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -70,14 +70,14 @@ uint8_t mmu_extruder = MMU_FILAMENT_UNKNOWN; uint8_t tmp_extruder = MMU_FILAMENT_UNKNOWN; int8_t mmu_finda = -1; -uint32_t mmu_last_finda_response = 0; int16_t mmu_version = -1; int16_t mmu_buildnr = -1; -uint32_t mmu_last_request = 0; -uint32_t mmu_last_response = 0; +ShortTimer mmu_last_request; +ShortTimer mmu_last_response; +ShortTimer mmu_last_finda_response; MmuCmd mmu_last_cmd = MmuCmd::None; uint16_t mmu_power_failures = 0; @@ -113,7 +113,7 @@ int mmu_puts_P(const char* str) { mmu_clr_rx_buf(); //clear rx buffer int r = fputs_P(str, uart2io); //send command - mmu_last_request = _millis(); + mmu_last_request.start(); return r; } @@ -125,7 +125,7 @@ int mmu_printf_P(const char* format, ...) mmu_clr_rx_buf(); //clear rx buffer int r = vfprintf_P(uart2io, format, args); //send command va_end(args); - mmu_last_request = _millis(); + mmu_last_request.start(); return r; } @@ -133,7 +133,7 @@ int mmu_printf_P(const char* format, ...) int8_t mmu_rx_ok(void) { int8_t res = uart2_rx_str_P(PSTR("ok\n")); - if (res == 1) mmu_last_response = _millis(); + if (res == 1) mmu_last_response.start(); return res; } @@ -141,7 +141,7 @@ int8_t mmu_rx_ok(void) int8_t mmu_rx_start(void) { int8_t res = uart2_rx_str_P(PSTR("start\n")); - if (res == 1) mmu_last_response = _millis(); + if (res == 1) mmu_last_response.start(); return res; } @@ -265,7 +265,7 @@ void mmu_loop(void) if (mmu_rx_ok() > 0) { fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer - mmu_last_finda_response = _millis(); + mmu_last_finda_response.start(); FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda); puts_P(PSTR("MMU - ENABLED")); mmu_enabled = true; @@ -350,7 +350,7 @@ void mmu_loop(void) mmu_printf_P(PSTR("M%d\n"), SilentModeMenu_MMU); mmu_state = S::SwitchMode; } - else if ((mmu_last_response + 300) < _millis()) //request every 300ms + else if (mmu_last_response.expired(300)) //request every 300ms { #ifndef IR_SENSOR if(check_for_ir_sensor()) ir_sensor_detected = true; @@ -378,7 +378,7 @@ void mmu_loop(void) if (mmu_rx_ok() > 0) { fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer - mmu_last_finda_response = _millis(); + mmu_last_finda_response.start(); FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda); //printf_P(PSTR("Eact: %d\n"), int(e_active())); if (!mmu_finda && CHECK_FSENSOR && fsensor_enabled) { @@ -398,7 +398,7 @@ void mmu_loop(void) if (mmu_cmd == MmuCmd::None) mmu_ready = true; } - else if ((mmu_last_request + MMU_P0_TIMEOUT) < _millis()) + else if (mmu_last_request.expired(MMU_P0_TIMEOUT)) { //resend request after timeout (30s) mmu_state = S::Idle; } @@ -424,7 +424,7 @@ void mmu_loop(void) mmu_ready = true; mmu_state = S::Idle; } - else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis()) + else if (mmu_last_request.expired(MMU_CMD_TIMEOUT)) { //resend request after timeout (5 min) if (mmu_last_cmd != MmuCmd::None) { @@ -467,7 +467,7 @@ void mmu_loop(void) mmu_ready = true; mmu_state = S::Idle; } - else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis()) + else if (mmu_last_request.expired(MMU_CMD_TIMEOUT)) { //timeout 45 s mmu_state = S::Idle; } @@ -479,7 +479,7 @@ void mmu_loop(void) eeprom_update_byte((uint8_t*)EEPROM_MMU_STEALTH, SilentModeMenu_MMU); mmu_state = S::Idle; } - else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis()) + else if (mmu_last_request.expired(MMU_CMD_TIMEOUT)) { //timeout 45 s mmu_state = S::Idle; } diff --git a/Firmware/mmu.h b/Firmware/mmu.h index 30b8e1af9..40a6dc727 100644 --- a/Firmware/mmu.h +++ b/Firmware/mmu.h @@ -4,6 +4,7 @@ #define MMU_H #include +#include "Timer.h" extern bool mmu_enabled; @@ -14,7 +15,7 @@ extern uint8_t mmu_extruder; extern uint8_t tmp_extruder; extern int8_t mmu_finda; -extern uint32_t mmu_last_finda_response; +extern ShortTimer mmu_last_finda_response; extern bool ir_sensor_detected; extern int16_t mmu_version; diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 3361e1a17..2b77c58e3 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -459,10 +459,7 @@ void plan_init() { #ifdef LIN_ADVANCE memset(position_float, 0, sizeof(position_float)); // clear position #endif - previous_speed[0] = 0.0; - previous_speed[1] = 0.0; - previous_speed[2] = 0.0; - previous_speed[3] = 0.0; + memset(previous_speed, 0, sizeof(previous_speed)); previous_nominal_speed = 0.0; plan_reset_next_e_queue = false; plan_reset_next_e_sched = false; @@ -678,10 +675,7 @@ void planner_abort_hard() #endif // Resets planner junction speeds. Assumes start from rest. previous_nominal_speed = 0.0; - previous_speed[0] = 0.0; - previous_speed[1] = 0.0; - previous_speed[2] = 0.0; - previous_speed[3] = 0.0; + memset(previous_speed, 0, sizeof(previous_speed)); plan_reset_next_e_queue = false; plan_reset_next_e_sched = false; @@ -1412,10 +1406,7 @@ void plan_set_position(float x, float y, float z, const float &e) #endif st_set_position(position[X_AXIS], position[Y_AXIS], position[Z_AXIS], position[E_AXIS]); previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest. - previous_speed[0] = 0.0; - previous_speed[1] = 0.0; - previous_speed[2] = 0.0; - previous_speed[3] = 0.0; + memset(previous_speed, 0, sizeof(previous_speed)); } // Only useful in the bed leveling routine, when the mesh bed leveling is off. diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 7730be05d..788d42acc 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -615,7 +615,7 @@ void fanSpeedError(unsigned char _fan) { if (get_message_level() != 0 && isPrintPaused) return; //to ensure that target temp. is not set to zero in case that we are resuming print if (card.sdprinting || is_usb_printing) { - if (heating_status != 0) { + if (heating_status != HeatingStatus::NO_HEATING) { lcd_print_stop(); } else { @@ -625,7 +625,7 @@ void fanSpeedError(unsigned char _fan) { else { // SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED); //Why pause octoprint? is_usb_printing would be true in that case, so there is no need for this. setTargetHotend0(0); - heating_status = 0; + heating_status = HeatingStatus::NO_HEATING; fan_check_error = EFCE_REPORTED; } switch (_fan) { diff --git a/Firmware/temperature.h b/Firmware/temperature.h index 2941e6306..f03ea6201 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -168,7 +168,7 @@ static inline void setTargetHotendSafe(const float &celsius, uint8_t extruder) // Doesn't save FLASH when not inlined. static inline void setAllTargetHotends(const float &celsius) { - for(int i=0;iactive_sheet)); const int8_t nextSheet = eeprom_next_initialized_sheet(sheetNR); @@ -575,7 +574,7 @@ void lcdui_print_time(void) //! @Brief Print status line on status screen void lcdui_print_status_line(void) { - if (heating_status) { // If heating flag, show progress of heating + if (heating_status != HeatingStatus::NO_HEATING) { // If heating flag, show progress of heating heating_status_counter++; if (heating_status_counter > 13) { heating_status_counter = 0; @@ -583,24 +582,24 @@ void lcdui_print_status_line(void) lcd_set_cursor(7, 3); lcd_space(13); - for (unsigned int dots = 0; dots < heating_status_counter; dots++) { + for (uint8_t dots = 0; dots < heating_status_counter; dots++) { lcd_putc_at(7 + dots, 3, '.'); } switch (heating_status) { - case 1: + case HeatingStatus::EXTRUDER_HEATING: lcd_puts_at_P(0, 3, _T(MSG_HEATING)); break; - case 2: + case HeatingStatus::EXTRUDER_HEATING_COMPLETE: lcd_puts_at_P(0, 3, _T(MSG_HEATING_COMPLETE)); - heating_status = 0; + heating_status = HeatingStatus::NO_HEATING; heating_status_counter = 0; break; - case 3: + case HeatingStatus::BED_HEATING: lcd_puts_at_P(0, 3, _T(MSG_BED_HEATING)); break; - case 4: + case HeatingStatus::BED_HEATING_COMPLETE: lcd_puts_at_P(0, 3, _T(MSG_BED_DONE)); - heating_status = 0; + heating_status = HeatingStatus::NO_HEATING; heating_status_counter = 0; break; default: @@ -1344,10 +1343,10 @@ void lcd_commands() else { SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM."); } - display_time = _millis(); + display_time.start(); lcd_commands_step = 1; } - if ((lcd_commands_step == 1) && ((_millis()- display_time)>2000)) { //calibration finished message + if ((lcd_commands_step == 1) && display_time.expired(2000)) { //calibration finished message lcd_setstatuspgm(_T(WELCOME_MSG)); custom_message_type = CustomMsg::Status; pid_temp = DEFAULT_PID_TEMP; @@ -1385,8 +1384,6 @@ void lcd_pause_usb_print() SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSE); } - -float move_menu_scale; static void lcd_move_menu_axis(); @@ -2763,7 +2760,7 @@ static void _lcd_move(const char *name, uint8_t axis, int min, int max) refresh_cmd_timeout(); if (! planner_queue_full()) { - current_position[axis] += float((int)lcd_encoder) * move_menu_scale; + current_position[axis] += float((int)lcd_encoder); if (min_software_endstops && current_position[axis] < min) current_position[axis] = min; if (max_software_endstops && current_position[axis] > max) current_position[axis] = max; lcd_encoder = 0; @@ -2791,7 +2788,7 @@ void lcd_move_e() refresh_cmd_timeout(); if (! planner_queue_full()) { - current_position[E_AXIS] += float((int)lcd_encoder) * move_menu_scale; + current_position[E_AXIS] += float((int)lcd_encoder); lcd_encoder = 0; plan_buffer_line_curposXYZE(manual_feedrate[E_AXIS] / 60); lcd_draw_update = 1; @@ -3839,7 +3836,7 @@ static void lcd_show_sensors_state() uint8_t idler_state = STATE_NA; pinda_state = READ(Z_MIN_PIN); - if (mmu_enabled && ((_millis() - mmu_last_finda_response) < 1000ul) ) + if (mmu_enabled && mmu_last_finda_response.expired(1000)) { finda_state = mmu_finda; } @@ -4235,13 +4232,6 @@ void lcd_move_menu_axis() MENU_END(); } -static void lcd_move_menu_1mm() -{ - move_menu_scale = 1.0; - lcd_move_menu_axis(); -} - - void EEPROM_save(int pos, uint8_t* value, uint8_t size) { do @@ -5672,7 +5662,7 @@ static void lcd_settings_menu() if (!PRINTER_ACTIVE || isPrintPaused) { - MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS c=18 + MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_axis);////MSG_MOVE_AXIS c=18 MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=18 } @@ -8705,10 +8695,10 @@ void lcd_printer_connected() { } static void lcd_send_status() { - if (farm_mode && no_response && ((_millis() - NcTime) > (NC_TIME * 1000))) { + if (farm_mode && no_response && (NcTime.expired(NC_TIME * 1000))) { //send important status messages periodicaly prusa_statistics(important_status, saved_filament_type); - NcTime = _millis(); + NcTime.start(); #ifdef FARM_CONNECT_MESSAGE lcd_connect_printer(); #endif //FARM_CONNECT_MESSAGE @@ -8880,7 +8870,6 @@ void menu_lcd_longpress_func(void) #endif || menu_menu == lcd_support_menu ){ - move_menu_scale = 1.0; menu_submenu(lcd_move_z); } else { // otherwise consume the long press as normal click diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 06763556b..0ea53bd6c 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -121,11 +121,9 @@ enum class CustomMsg : uint_least8_t }; extern CustomMsg custom_message_type; -extern unsigned int custom_message_state; +extern uint8_t custom_message_state; extern uint8_t farm_mode; -extern int farm_timer; -extern uint8_t farm_status; extern bool UserECoolEnabled(); extern bool FarmOrUserECool();