Commit Graph

36 Commits

Author SHA1 Message Date
3d-gussner 52ba1b534d Add HOST power panic auto recovery option
Change `PRINT_TYPE_USB` to `PRINT_TYPE_HOST`

Fix more rebase issues

Fix rebase issue again
2024-01-29 13:07:48 +01:00
gudnimg 9bd043c83b Move restore_file_from_sd out of power panic file
This function is not specific to power panic. Some printer models
do not have power panic enabled.

This change fixes a build failure

No change in memory
2023-12-30 12:19:51 +00:00
gudnimg 02c5da198d Enable EEPROM_UVLO flag for host prints
Change in memory:
Flash: -30 bytes
SRAM: 0 bytes
2023-12-01 16:16:39 +01:00
gudnimg 67c7ad1c99 power panic: improve file position recovery
- Only queue M26 for SD prints
- Add M110 to set gcode_LastN for host prints
- Remove one debug log to save resource (52 bytes)

Change in memory:
Flash: -14 bytes
SRAM: 0 bytes
2023-12-01 16:16:39 +01:00
gudnimg e2d0e9a2ee power panic: remove redundant lcd update calls
lcd_show_fullscreen_message_yes_no_and_wait_P will
enable LCD update upon exit.

Change in memory:
Flash: -24 bytes
SRAM: 0 bytes
2023-12-01 16:16:39 +01:00
3d-gussner 9fd478c9c2
Merge pull request #4173 from gudnimg/disable-heaters-gudni
optimisation: use `disable_heater()` in more places
2023-11-20 07:01:05 +01:00
gudnimg dc280b0d9e power panic: support any valid DOS 8.3 extension
When a SD file is selected to print
save the DOS 8.3 extension into EEPROM.

After a power outage, the correct file extension is then
selected instead of always assuming it's ".gco"

This allows users to recover ".g" files.

Change in memory:
Flash: +104 bytes
SRAM: 0 bytes
2023-11-05 16:46:54 +00:00
gudnimg 4c52d92d16 power panic: read whole directory name block from EEPROM
There is no need to read one byte at a time. We can simply
read the whole block in one go. This saves some flash memory.

Change in memory:
Flash: -18 bytes
SRAM: 0 bytes
2023-11-05 16:46:54 +00:00
gudnimg 21d0130626 power panic: simplify recovering SD filename
We can just read the whole EEPROM block since short filenames
are always null terminated. strcat_P will then apply the file extension
at the correct position.

Change in memory:
Flash: -24 bytes
SRAM: 0 bytes
2023-11-05 16:46:54 +00:00
Guðni Már Gilbert 82cece95aa power panic: read EEPROM_FILENAME until \0 is seen
Also removed debug logs
2023-11-05 16:46:14 +00:00
Guðni Már Gilbert 977792961c power panic: only send M23 for SD prints
If the saved printing type was USB, then EEPROM_FILENAME
does not contain anything. The firmware should also
not be trying to open a file on a SD card which is maybe
not even mounted.

Change in memory:
Flash: +12 bytes
SRAM: 0 bytes
2023-11-05 16:46:13 +00:00
gudnimg 3eaca29b0b PFW-1543 Move printing types into enum
Also add power panic namespace
2023-10-01 12:57:25 +00:00
gudnimg fcd61a378d power panic: save print type in EEPROM
The printer should know whether it is recovering a SD print
or a USB print

PFW-1543
2023-10-01 12:44:49 +00:00
Guðni Már Gilbert 6187b7eecf optimisation: use disable_heater() in more places
Change in memory:
Flash: -84 bytes
SRAM: 0 bytes
2023-09-16 14:26:09 +00:00
Guðni Már Gilbert 02332018ec tmc2130: Fix bug with vSense bit and current values
If vSense changes at runtime due to Run current
being changed. Then we must always shift the Hold current
correctly. Whether the vSense is changing 1 -> 0 or 0 ->1

Change in memory (with TMC2130_SERVICE_CODES_M910_M918):
Flash: +76 bytes
SRAM: 0 bytes
2023-08-05 10:41:21 +02:00
Guðni Már Gilbert 21faa52aab Rename axis_steps_per_unit to axis_steps_per_mm 2023-07-25 17:10:44 +02:00
Guðni Már Gilbert 3819f7a473 tmc2130: Refactor code for setting/changing currents
- Always re-calculate the Vsense flag when the currents are changed
- Make sure Hold current is not larger than Run current
- Added SetCurrents() function from MMU FW
- Added MotorCurrents structure from MMU FW
- Various code size optimisations e.g. in power panic

Change in memory:
Flash: -10 bytes
SRAM: +4 bytes
2023-07-25 08:56:43 +02:00
Guðni Már Gilbert 03e7ff1983 power panic: optimise incrementing EEPROM statistics
Change in memory:
Flash: -26 bytes
SRAM: 0 bytes
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 2cd5ab2349 power panic: add readable flags and optimise ISR(INT4_vect)
Add more readable names for the EEPROM_UVLO values

Change in memory:
Flash: -14 bytes
SRAM: 0 bytes
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 4dc5d97ca9 power panic: remove unused EEPROM_UVLO_Z_MICROSTEPS
It isn't very helpful IMO to have unused code during power panic
it just complicates things.

Change in memory:
Flash: -32 bytes
SRAM: 0 bytes
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert d5125c6b1e power panic: refactor log output on recovery
Use M114 to print coordinates for all axis. We save
a lot of memory by reusing the M114 code

Change in memory:
Flash: -184 bytes
SRAM: 0 bytes
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 005f9f0d24 power panic: Fix an error in saved position
planner_abort_hard() calls planner_reset_position() which
will set current_position vector to the machine position.
We want to save this position when there is no position already saved
(i.e. when there is no partial back-up or a saved print in RAM)

When a power outage comes, the printer is in the middle of a gcode move.
And at the moment a gcode is executed by the planner, the planner will update
current_position vector to the final destination vector. This means current_position
vector is invalidated during a power outage and so we must check what the
actual machine position is instead and save it.

This was working correctly before, this commit only fixes the regression
in my pull request.

Change in memory:
Flash: -2 bytes
SRAM: 0 bytes
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 5ee7ba84e3 fix build 2023-07-18 11:29:03 +02:00
Guðni Már Gilbert fa843a4a9b power panic: implement partial back up in RAM
A partial backup is needed in scenarios where the extruder may be
parked after a print is saved. For example during a blocking wait for the user in M600
Or during a MMU error screen.

A sudden power panic at this point would previously save the parked position
into EEPROM. When the print is recovered it would print in mid air.
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 10ed195531 power panic: use saved position consistently
1) current_position[Z_AXIS] is not always correct. saved_pos[Z_AXIS]
    should always represent the correct resume position for the Z-axis
2) Use the saved position to fetch the Z-offset value from
    the mesh bed leveling grid. In case the extruder is parked during
    power panic, the previous code may extract the wrong mesh
    bed leveling offset (due to extruder being located at different
    X and Y axis coordinates)
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 392c46c7ad power panic: pull INT4 string into PROGMEM
Change in memory:
Flash: -4 bytes
SRAM 0 bytes
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 6d902d6437 power panic: store saved_fan_speed in EEPROM
fanSpeed may have an outdated value
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 44bedcd941 power panic: cleanup: remove commented code 2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 62a3d179f0 optimisation: read/write EEPROM_UVLO_SAVED_START_POSITION block
I verified via printf that sizeof(saved_start_position) = 16 (i.e. 4 float values)
We simply want to write 16 bytes to address
EEPROM_UVLO_SAVED_START_POSITION

Change in memory:
Flash: -160 bytes
SRAM: 0 bytes
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 6ccd12c7e8 power panic: re-use saved_pos
This allows us to restore the position of all axis saved in RAM

If the extruder had been parked to the side for example
due to filament runout. Then the original position (before parking)
should now be restored

Change in memory:
Flash: +40 bytes
SRAM: 0 bytes
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 97c27525d4 power panic: re-use saved_extruder_relative_mode
Change in memory:
Flash: +8 bytes
SRAM: 0 bytes
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert a2ac513794 power panic: re-use target temps from RAM
If a print has been saved to RAM such as during a filament runout,
do not overwrite these saved values if a sudden
power panic appears.

Additionally, change the saved types to be the same as power panic when saving to RAM:
- Bed target temperature is uint8_t (0 to 255) instead of float
- Extruder target temperature is uint16_t instead of float

Doing this change allows us to re-use the same global variables and
avoid creating local variables during power panic.

Change in memory:
Flash: -246 bytes
SRAM: -5 bytes
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert b65c500f25 power panic: Add comments about conserving power 2023-07-18 11:29:03 +02:00
Guðni Már Gilbert a45e432030 power panic: Re-use code to save feedrate, segment index, and start position
Saves ~80B of Flash
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 67403603ed power panic: Re-use saving print file state
This also adds the Gcode position into EEPROM
for Octoprint/PrusaLink prints.
Though the recovery part doesn't support that yet.
2023-07-18 11:29:03 +02:00
Guðni Már Gilbert 526a1dcc63 power panic: Move code into a separate file 2023-07-18 11:29:03 +02:00