jpcurti / ender3-v3-se-klipper-with-display

Modified klipper for ender3-v3 se with stock display support.
GNU General Public License v3.0
74 stars 11 forks source link

Large filename (gcode) crashes the plugin #32

Closed jpcurti closed 6 months ago

jpcurti commented 6 months ago

Wide names causes a crash on the file selection menu image WhatsApp Image 2024-06-02 at 12 23 16

only recoverable after a firmware restart: image

jpcurti commented 6 months ago

The maximum data payload for a data frame is 248 bytes (according to the T5L_TA instruction set): image. From the TJC module, the data sent to the display is :

        self.byte(self.cmd_draw_text) # 1 byte
        self.word(x) # 2 bytes
        self.word(y) # 2 bytes
        self.byte(0x00)  # font # 1 byte
        self.byte(0x02 | (show_background * 0x40))  # mode (bshow) # 1 byte
        self.byte(size)  # size # 1 byte
        self.word(font_color) # 2 bytes
        self.word(background_color) # 2 bytes
        self.string(string) # n bytes

This means that the string sent to the draw_string method should have a max length n of 248 - 12 = 238 bytes a.k.a a 238 char string would be the limit.

The crash, however, happens with the string "CE3V3SE_customizable-box-psu-power-adapter-holder_20240505-36-1c54hxf.gcode", which is 75 byte long. What can be wrong here?

  1. The T5L_TA Instruction set is not specifically for the TJC display on the E3V3SE. The payload can (and probably is) very smaller. If I truncate the string to the first 30 chars, it works normally. Where is the limit?

Solution: Check the maximum byte number that can be sent when writing text and truncate the string to it.

As anything bigger than 40 char cant be displayed in the screen size anyways, I will truncate the string to 40 bytes and call it a day.