Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Octoprint support + configurable gcode file comment parsing + bugfixes + cleanup #2241

Merged
merged 1 commit into from
Nov 25, 2021

Conversation

digant73
Copy link
Contributor

@digant73 digant73 commented Nov 11, 2021

IMPROVEMENTS:
*Configurable Gcode file comment parsing feature: This previously hidden feature can now be enabled/disabled in config.ini (with param name "file_comment_parsing") and also in Feature menu. This gives visibility/control of the feature so it can be used according to the used slicer (e.g. Cura) and/or user preference.
If enabled, the current implementation parses and processes print time and print layer information from the G-code file (nothing else).
If disabled, the "layer_disp_type" setting provided in "UI Settings" section in config.ini becomes redundant.
*Optimized loopPrintFromTFT function in Printing.c API: The parsing of each line in the gcode file is now split in order to speed up both the gcode parsing and the comment (if any) parsing
*Added error handling and error notification in loopPrintFromTFT function in Printing.c API: The error handling function handleDiskError currently implemented forces a device re-initialization for a maximum number of retry attempts. If maximum number of retry is reached a print abort is forced. Previously, in case of error the file position (infoPrinting.cur) was never updated causing an infinite print loop (the print could never reach the end due to a permanent error reading from file)
*Unified name for Controller Fan Active: Id for Active PWD in config.ini (CtL) was not matching the Id displayed in the menus (CtS) and its meaning (Active). The name was unified to CtA on both config.ini and menus
*Implemented Octoprint support: It resolves #2180 and #438
*Some cleanup

BUG FIXES:
*Fixed wrong stringify expansion for icon names: In boot.c a double macro expansion was used causing a macro value expansion (in case of an existing macro definition) instead of macro name. The fix will avoid further issues such as happened with #2237. Previous definitions (LANGUAGE and ONBOARD_SD) have been restored
*Fixed TFT freeze due to permanent read/write error printing from SD slot: functions disk_read / disk_write in diskio.c performed a loop invoking SD_Init function. The loop was never terminated in case of a persistent error. That bug could be the main reason for the freeze reported in #2231
*Fixed MinX/MinY Leveling Distance: The origin of the bed is never less than 0. A negative minX/minY indicates the distance of the bed from endstops and must not be considered to determine the four leveling edges in Manual Leveling menu and Leveling Corner menu. It fixes #2246

INTEGRATION WITH OCTOPRINT / OCTOPRINT TRIGGERING COMMANDS:
Octoprint can optionally trigger some actions to the TFT sending specific gcodes. The following actions and the related triggering gcodes are currently supported by the TFT fw:

start:
M118 A1 P0 action:print_start

end:
M118 A1 P0 action:print_end

cancel:
M118 A1 P0 action:cancel

pause:
M118 A1 P0 action:pause

resume:
M118 A1 P0 action:resume

time remaining progress:
M118 A1 P0 action:notification Time Left <XX>h<YY>m<ZZ>s (e.g. 02h04m06s)
or
M117 Time Left <XX>h<YY>m<ZZ>s

file data progress:
M118 A1 P0 action:notification Data Left <XXXX>/<YYYY> (e.g. 123/12345)
or
M117 Data Left <XXXX>/<YYYY>

When the trigger "print_start" is received, the TFT switches to Printing menu.
Once on Printing menu, the "pause", "resume" and "stop" buttons on the menu will be disabled.
That means only Octoprint will control the print.
Only on print end or cancel the TFT Printing menu is finalized (statistics available etc...) and unlocked (it can be closed).

NOTE: A new plugin on Octoprint implementing the above protocol should be the preferable way (available to everyone)

resolves #2180
resolves #438
fixes #2246
could fix (#2231) (to be confirmed)
fixes #2255
fixes #2216

PR STATE: Ready to merge. It adds 560 bytes to program size

@kisslorand
Copy link
Contributor

kisslorand commented Nov 11, 2021

While you're at it please set setM73_presence back to setM73R_presence. I don't know who changed it and why.
Thx.

@digant73
Copy link
Contributor Author

@kisslorand done

TFT/src/User/API/boot.h Outdated Show resolved Hide resolved
@digant73 digant73 changed the title Fixed wrong stringify expansion for icon names + cleanup Octoprint support + configurable gcode file comment parsing + bugfixes + cleanup Nov 16, 2021
@kisslorand
Copy link
Contributor

kisslorand commented Nov 18, 2021

@digant73
You might want to take a look in "print.c -> menuPrintFromSource()" where bool type update variable is used.
In menuPrintFromSource() the update variable gets other values than true or false (0 and 2). This was introduced in your PR #2233.

Maybe something like:
uint8_t update = 1; // {0 - no update, 1 - update with title bar, 2 - update without title bar}
...and update = true and update = false replaced by update = 1 and update = 0

@digant73
Copy link
Contributor Author

@kisslorand added the comment on variable definition. I don't see any reference to update = true/false (it is already 0/1).
I replaced "if (update)" with "if (update != 0)"

@kisslorand
Copy link
Contributor

Sorry, I was checking the current master. Alles ist in Ordnung!

@sarvenn
Copy link

sarvenn commented Nov 18, 2021

Hello @digant73 ,
Could you please explain this feature for a basic user? I could not get what is it for and how should I used or adjust it.
For example I'm using PrusaSlicer currently. What should be done in my slicer SW and config.ini files?

*Configurable Gcode file comment parsing feature: This previously hidden feature can now be enabled/disabled in config.ini (with param name "file_comment_parsing") and also in Feature menu. This gives visibility/control of the feature so it can be used according to the used slicer (e.g. Cura) and/or user preference.

@digant73
Copy link
Contributor Author

digant73 commented Nov 18, 2021

@savenn
The TFT parses and processes extra information provided by the slicer as comments in the G-code file.
If enabled, the current implementation parses and processes print time and print layer information from the G-code file (nothing else).
If disabled, the "layer_disp_type" setting provided in "UI Settings" section in config.ini becomes redundant.

@Hitamku
Copy link

Hitamku commented Nov 22, 2021

@digant73
This popped up after I updated the latest file. Line Number is not Last Line Number+1, Last Line: 0
What error is that?

@digant73
Copy link
Contributor Author

that was a bug caused by #2250 and fixed by this PR (as reported in #2255)

@CRCinAU
Copy link

CRCinAU commented Nov 23, 2021

that was a bug caused by #2250 and fixed by this PR (as reported in #2255)

I came hunting for this after wondering WTF had happened to my TFT35 ;)

For the moment, I just rolled back a build and its all good for now.... Thanks for fixing these...

@ETE-Design
Copy link

@digant73 If the OctoPrint part a default setting in OctoPrint, or do you have to add the functions somehow?

@CRCinAU
Copy link

CRCinAU commented Nov 23, 2021

You can likely add them in Octoprint Settings -> GCode Scripts...

bigtreetech added a commit that referenced this pull request Nov 25, 2021
@digant73
Copy link
Contributor Author

digant73 commented Nov 29, 2021

@Guilouz Strange you needed to provide P0. P0 should be the default value in case Pn is omitted. However, I edited the commands above providing also the "P0" option.
Hmm no, I think it isn't worth it to provide a translation for "Remote printing...". There are also many other hard coded strings not translated.

@inigoml
Copy link

inigoml commented Nov 30, 2021

M118 is an alternative to M117. So, if M117 is supported (e.g. by Cura or some Octoprint plugins) you don't need M118 at all

Hi guys. Fantastic upgrade. I've also gotten almost the same functionality from Octoprint that locally from SD.
Regarding this issue, I was using my customized Cura post processing script to insert an M118 A1 P2 in order to notifiy progress to my printer via "action:notification". However, now, since I send command action:print_start, there is no notification available. Messages arrives to TFT (it sounds) but there is no message screen.

@digant73
Copy link
Contributor Author

@inigoml you should see the Printing menu is open

@inigoml
Copy link

inigoml commented Nov 30, 2021

Hi @digant73, what do you want to say with "printing menu is open"?
By the way, I've modified Cura postscript in order to accommodate print progress % for printing menu. Now it`s updated properly with M118 command.
Only Time Left is not visible.

@inigoml
Copy link

inigoml commented Nov 30, 2021

DisplayProgressOnLCD.zip

@inigoml
Copy link

inigoml commented Nov 30, 2021

PXL_20211130_181225850

@inigoml
Copy link

inigoml commented Nov 30, 2021

PR for cura plugin already created. Will be in next version or not! :)

@digant73
Copy link
Contributor Author

digant73 commented Nov 30, 2021

@inigoml I meant that sending "M118 A1 P0 action:print_start" should trigger the TFT to open the Printing menu. But as I see in your picture, the Printing menu is now properly open.
The Time Left should be already supported in Cura (both M118 and M117).
I had a look to your PR, but also action:print_start and action:print_end must be supported. I don't see them

@inigoml
Copy link

inigoml commented Nov 30, 2021

Hi @digant73. The problem is that after print has started, no ETA is displayed on screen because message box for notifications is not available.
That is, ETA messages are received (Time Left XXhXXmXXs) but no message box is available in order to be displayed.

M118 A1 P0 action:notification Time Left 1h2m3s has no way to be displayed. ;)

@Guilouz
Copy link
Contributor

Guilouz commented Nov 30, 2021

Just try, I have elapsed time, time remaining, percentage, layer height in their respective case but not number of layers (just show ---)

@inigoml You use 'M118 A1 P0 action:notification Data Left' in your script as percentage right ? It's not supposed to be used for number of layers ?

Another little issue, percentage are not the same on octoprint and on the screen (example : 35% on screen, 37.6% on octoprint)

@digant73
Copy link
Contributor Author

digant73 commented Dec 1, 2021

@inigoml the Time Left notification is displayed directly in the Printing menu (you will see the time elapsed and below the time remaining). The notification is not saved in the Notification box
@Guilouz for printing layer you should enable "File comment parsing" in Feature menu. Print layer info must be supported by the slicer

@inigoml
Copy link

inigoml commented Dec 1, 2021

@inigoml You use 'M118 A1 P0 action:notification Data Left' in your script as percentage right ? It's not supposed to be used for number of layers ?

It depends. You can modify behavior in config.ini.

Options: [Percentage & Elapsed time: 0, Percentage & Remaining time: 1, Elapsed time & Remaining time: 2]

Basically, I'm emulating M73 command via M118.

Another little issue, percentage are not the same on octoprint and on the screen (example : 35% on screen, 37.6% on octoprint)

Octoprint has it's own calculation algorithm while Cura has another. In this case, since the script is for Cura, it's normal to have minor discrepancies. If an Octoprint plugin manages this instead of Cura, both could be equal. But no plugin is yet available for Octoprint (if I find myself strong, I could take a look about how to create an Octoprint plugin).

@inigoml
Copy link

inigoml commented Dec 1, 2021

@inigoml the Time Left notification is displayed directly in the Printing menu (you will see the time elapsed and below the

Thank you @digant73. I will check config again. I'm almost sure I have prog_disp_type:2 set, but behavior is like if I had prog_disp_type:0. Perhaps it's not being properly parsed due to some error at script level.

@inigoml
Copy link

inigoml commented Dec 1, 2021

At Gcode level I think it's everthing OK...

M118 A1 P0 action:notification Data Left 0/100
M118 A1 P0 action:notification Time Left 2h29m56s

@Guilouz
Copy link
Contributor

Guilouz commented Dec 1, 2021

@inigoml yes you can switch time info (percentage, time remaining, elapsed time) by clicking on the time box, no problem for that I have all info.

What I mean is that normally 'M118 A1 P0 action:notification Data Left' must be used to display number of layers (example : layer 127/528) and not and not a percentage out of 100, no ?

@inigoml
Copy link

inigoml commented Dec 1, 2021

OMG.... You are right! :-) Everything working properly.

Since I've reused same calculation at plugin level that was used for M73 command, I applied the same percentage. Just that.
If it was not accurate for M73, it's not either for M118.

@Guilouz
Copy link
Contributor

Guilouz commented Dec 1, 2021

@inigoml To summarize, we have all the info except the number of layers (displayed as '---'), and all without notifications, all info are in boxes. Click on layer box you will see that.

@inigoml
Copy link

inigoml commented Dec 1, 2021

For layer, we need a parser at TFT level in order to process specific message via M118. @digant73 could add it and we can include it at Cura script level or eventually at script level.
So, we cannot add layer number until digant prepares the parser for it. ;) Let fill a FR!

@digant73
Copy link
Contributor Author

digant73 commented Dec 1, 2021

the layer number is already supported by the TFT. You must enable "File comment parsing" in Feature menu. Maybe you must enable something on Cura/Prusa slicer to provide that info as comment in the gcode file

@inigoml
Copy link

inigoml commented Dec 1, 2021

@digant73, would this file comment parsing work also from Octoprint?
Since in this case GCODE does not arrive at TFT, we need to notify TFT controller some way layer number, isn't it?
;LAYER comment at Gcode never arrives at TFT and so must be notified some way (M118 A1 P0 action:notification "message")
Would M118 A1 P0 action:notification ";LAYER:12" work?

@Guilouz
Copy link
Contributor

Guilouz commented Dec 1, 2021

@digant73 yes working when printing from TFT ports but not in remote printing.

@inigoml
Copy link

inigoml commented Dec 1, 2021

Understood.

@digant73
Copy link
Contributor Author

digant73 commented Dec 1, 2021

yes, Octoprint should provide the info (the notification you reported should be ok) and then I would add a support to that new notification in a similar way as the File comment parsing feature already implemented on TFT (used when printing from TFT).

@inigoml
Copy link

inigoml commented Dec 3, 2021

Adapting octoprint_detailedprogress plugin for TFT BTREETECH should be easy.... Will take a look.

@Eddiiie
Copy link

Eddiiie commented Feb 25, 2022

I added these lines to Octoprint GCODES and it works great.
I can't find where to put the time remaining and filedata GCODEs; I use Prusa Slicer... ? @inigoml can your Python script be run from slicer post processor?

@inigoml
Copy link

inigoml commented Feb 25, 2022 via email

@Eddiiie
Copy link

Eddiiie commented Feb 25, 2022

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet