Skip to content

virtual_sdcard: various additions - #3132

Merged
KevinOConnor merged 6 commits into
Klipper3d:masterfrom
Arksine:dev-virtual_sdcard
Aug 5, 2020
Merged

virtual_sdcard: various additions#3132
KevinOConnor merged 6 commits into
Klipper3d:masterfrom
Arksine:dev-virtual_sdcard

Conversation

@Arksine

@Arksine Arksine commented Jul 29, 2020

Copy link
Copy Markdown
Collaborator

This request proposes the following changes to the virtual_sdcard module:

  • Add a RESET_SD gcode. This allows users to clear the virtual_sdcard's state in the event that they want to cancel a print.
  • Walk through subdirectories when populating the file list, allowing Klipper to load these files via M23 subdir/myfile.gcode or M23 /subdir/myfile.gcode
  • Report print progress while the virtual_sdcard is paused. The current behavior resets progress to 0. In addition, report "is_active" and "file_position" via get_status()
  • Add a PrintStats class that tracks the total time elapsed since the print has started, the total time spent printing (not paused), and the total filament used based based on the gcode position. These stats, along with the currently loaded file's name, are reported via get_status().

This functionality is currently used by Moonraker/Mainsail, however it may also be useful for displays or gcode_macros.

Signed-off-by: Eric Callahan arksine.code@gmail.com

@KevinOConnor

Copy link
Copy Markdown
Collaborator

Thanks. I have some comments:

Add a RESET_SD gcode. This allows users to clear the virtual_sdcard's state in the event that they want to cancel a print.

Looks fine, but I'd suggest a more descriptive name - maybe SDCARD_RESET_FILE or SDCARD_CANCEL_PRINT or PRINT_FILE_CANCEL. Also, might be nice to add an internal _reset_file() helper function to reduce some code duplication.

Walk through subdirectories when populating the file list, allowing Klipper to load these files via M23 subdir/myfile.gcode or M23 /subdir/myfile.gcode

As near as I can tell, the M20 and M23 commands do not "normally" support directories (eg, https://www.reprap.org/wiki/G-code#M20:_List_SD_card ). Also, I'm not sure it's valid to limit the file extensions of the M20/M23 commands. I'm leery of "enhancing" the old g-code commands in "novel" ways. I'm fine with adding support for directories, but FWIW I'd prefer new commands like PRINT_FILE_START FILENAME=a/b/c.gcode.

Report print progress while the virtual_sdcard is paused. The current behavior resets progress to 0. In addition, report "is_active" and "file_position" via get_status()

Looks fine to me. It may be worthwhile to add a note to Config_Changes.md .

Add a PrintStats class that tracks the total time elapsed since the print has started, the total time spent printing (not paused), and the total filament used based based on the gcode position. These stats, along with the currently loaded file's name, are reported via get_status().

If I understand this correctly, it adds some useful statistics that are inferred from the print. I think that's fine, but I'd suggest adding it to its own top level "extra" module. (Or, perhaps add to the existing display_status.py module.) The virtual_sdcard.py module can auto-load the new module, so it can continue to unconditionally call its note_xxx() methods. I think a separate "extras" module may keep the low-level file code better separated from the high-level "stats interpretation" code.

Thanks again,
-Kevin

@Arksine

Arksine commented Jul 31, 2020

Copy link
Copy Markdown
Collaborator Author

Sounds good. I'll get to work on the suggested changes.

This allows the user to close a currently loaded file and reset the virtual_sdcard's state.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
@Arksine
Arksine force-pushed the dev-virtual_sdcard branch from aa5fd22 to e80988a Compare August 1, 2020 00:07
@Arksine

Arksine commented Aug 1, 2020

Copy link
Copy Markdown
Collaborator Author

Ok, I have made the following changes:

  • The PrintStats class is now in its own module, print_stats.py
  • Renamed RESET_SD to SDCARD_RESET_FILE
  • Added PRINT_FILE_START and GET_FILE_LIST gcodes.
  • Added _reset_file() and _load_file() helper functions
  • Updated gcodes.md and config_changes.md

I thought that GET_FILE_LIST would be useful for users that want to view all files that can printed via PRINT_FILE_START. Below is a sample of the output:

// Begin File List
// ****
// Name: BME_280_Back_0.2mm_PLA_Ender2_7m.gcode
// Size: 194631
// ****
// Name: Cura/Cura_Cube.gcode
// Size: 466257
// ****
// Name: IdeaMaker/ideamaker_cube.gcode
// Size: 202133
// ****
// Name: KissSlicer/KissSlicer_Cube.gcode
// Size: 657666
// ****
// End File List

Also, if you prefer I can separate the get_file_list() method into two different methods (perhaps get_file_list() and get_extended_file_list().

@KevinOConnor KevinOConnor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I have a couple of minor comments below.

-Kevin

Comment thread docs/G-Codes.md Outdated
Comment on lines +65 to +66
- List all gcode files (including those in subdirectories): `GET_FILE_LIST`
- Load a file and start SD print: `PRINT_FILE_START FILENAME=<filename>`
- Unload File and Clear SD state: `SDCARD_RESET_FILE`

@KevinOConnor KevinOConnor Aug 1, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be preferable if we could use a common prefix for all the commands of the module. For example, "SDCARD_LIST_FILES,SDCARD_PRINT_FILE,SDCARD_RESET_FILE" or "PRINT_FILE_LIST,PRINT_FILE_START,PRINT_FILE_RESET", or something similar.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will change to SDCARD_LIST_FILES and SDCARD_PRINT_FILE. I think that verbiage is most clear on what it does.

Comment thread klippy/extras/virtual_sdcard.py Outdated
Comment on lines +256 to +260
if self.current_file is not None:
self.print_stats.note_pause()
else:
self.file_position = self.file_size = 0
self.print_stats.reset()

@KevinOConnor KevinOConnor Aug 1, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this change. How could self.currentfile == None in this context?

EDIT: Oops - it can be assigned to None in the function itself. Shouldn't this call self._reset_file() though?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I should change that to use reset_file.

@Arksine
Arksine force-pushed the dev-virtual_sdcard branch from e80988a to 49177fe Compare August 1, 2020 11:34
@Arksine

Arksine commented Aug 1, 2020

Copy link
Copy Markdown
Collaborator Author

Suggested changes made. The virtual_sdcard's extended gcodes are now:
SDCARD_PRINT_FILE FILENAME=<filename>
SDCARD_GET_FILES
SDCARD_RESET_FILE

Thanks!

@KevinOConnor

Copy link
Copy Markdown
Collaborator

Thanks. Looks good to me. If there are no further comments, I'll commit in a couple of days.

-Kevin

@Arksine

Arksine commented Aug 3, 2020

Copy link
Copy Markdown
Collaborator Author

Hi Kevin, it recently occurred to me that if the print exits the timer due to an error there is currently to method of notifying clients than an error occured. What I thought I could is add a "state" value to the print_stats get_status() method. The state can be one of the following values: "printing", "paused", "error", "complete". When there is a gcode error I can call print_stats.note_error(message), and when the print is complete I can call print_stats.note_complete rather than _reset_file(). This allows clients to continue displaying print statistics after the print is complete. When a user wants to clear the stats they can either start a new print or call SDCARD_RESET_FILE. Does this sound like a reasonable approach to you? Thanks.

@KevinOConnor

Copy link
Copy Markdown
Collaborator

It sounds fine to me. Does that mean I should hold off on committing this series?

BTW, what's the value in the new SDCARD_GET_FILES command? Wouldn't it be simpler for a user to just list the directory using ls or some file management gui?

-Kevin

@Arksine

Arksine commented Aug 3, 2020

Copy link
Copy Markdown
Collaborator Author

Yes, please hold off. I'll push a commit, let you review it, then squash it back into the original series.

My thought was that SDCARD_GET_FILES would give Octoprint users (and the like) an easy way to list what files are available via the terminal. Now that you mention it, I suppose those users wouldn't use the extended command anyway. Would you like me to remove it?

@KevinOConnor

Copy link
Copy Markdown
Collaborator

Sounds good.

Now that you mention it, I suppose those users wouldn't use the extended command anyway. Would you like me to remove it?

The reason I asked was because it occurred to me that if the command iterates through sub-directories it may create a lot of data, which may overload the pseudo-terminal between Klipper and OctoPrint. So, I guess, if there isn't a defined use case, it may be better to not "open that can of worms".

Thanks,
-Kevin

@Arksine

Arksine commented Aug 3, 2020

Copy link
Copy Markdown
Collaborator Author

I think that makes sense. I just pushed a commit with the changes to print_stats. I'll remove SDCARD_GET_FILES shortly.

Arksine added 3 commits August 3, 2020 15:01
SDCARD_PRINT_FILE allows Klipper to load and start the print for any
gcode file within the virtual_sdcard path, including subdirectories.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Do not reset progress to zero while paused.  Report 'is_active' and 'file_position'.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
@Arksine
Arksine force-pushed the dev-virtual_sdcard branch from f4ba7eb to d31b7cc Compare August 3, 2020 20:53
Arksine added 2 commits August 3, 2020 17:10
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
@Arksine
Arksine force-pushed the dev-virtual_sdcard branch from d31b7cc to f275c19 Compare August 3, 2020 21:11
@KevinOConnor

Copy link
Copy Markdown
Collaborator

Thanks. I'm fine with merging. After the discussion in #3149 a question occurred to me - is SDCARD_RESET_FILE and SDCARD_PRINT_FILE primarily intended to be used by moonraker/mainsail? If so, would a webhook make more sense than a gcode command? The reason I ask is that the M24 and M25 commands are kinda goofy - it's unclear what they should do if they are contained in a gcode file, it's unclear what M24 should do if called when a print is already in progress, and error handling is difficult with them. I wonder if we'll look back and think SDCARD_RESET_FILE and SDCARD_PRINT_FILE are kinda goofy for similar reasons.

I'm fine with merging though. Just figured I'd ask.

Thanks again,
-Kevin

@Arksine

Arksine commented Aug 5, 2020

Copy link
Copy Markdown
Collaborator Author

I think SDCARD_RESET_FILE has to be a gcode, as I expect users to include it in their "CANCEL_PRINT" macro override. In fact, I should probably have cmd_CANCEL_PRINT() execute SDCARD_RESET_FILE by default if pause_resume detects a print from the virtual_sdcard.

SDCARD_PRINT_FILE could be a webhook. I added it as a gcode to give all users the option of launching from a subdirectory, but I'm unsure of how many users would find it useful. Perhaps the display "menu" could add support for subdirectories, which might make navigating a bit easier for users with a large number of gcode files in the the vsd path.

@KevinOConnor
KevinOConnor merged commit b9f48e6 into Klipper3d:master Aug 5, 2020
@KevinOConnor

Copy link
Copy Markdown
Collaborator

Sounds good. Thanks!

-Kevin

@Arksine
Arksine deleted the dev-virtual_sdcard branch August 5, 2020 17:50
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants