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

Fixes #64 [BUG] Crash and reboot after second time gcode preview. #84

Merged
4 changes: 1 addition & 3 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3417,11 +3417,9 @@
// Professional firmware features:
#define PROUI_EX 1 // Extended UI features (15152 bytes of flash)
#ifdef PROUI_EX
#define HAS_GCODE_PREVIEW 1
#define HAS_TOOLBAR 1
#else
#define HAS_GCODE_PREVIEW_NOPRO 1
#endif
#define HAS_GCODE_PREVIEW 1
#define DISABLE_TUNING_GRAPH 0// Temp plot graph - PID/MPC Tuning (1624 bytes of flash)
#define HAS_ESDIAG 1 // View End-stop switch continuity (560 bytes of flash)
#define HAS_CGCODE 1 // Extra Gcode options (3320 bytes of flash)
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/e3v2/proui/custom_gcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "custom_gcodes.h"

#if ALL(PROUI_EX, HAS_MEDIA)
#include "file_header.h"
#include "gcode_preview.h"
#endif

//=============================================================================
Expand Down Expand Up @@ -84,7 +84,7 @@ void C108() {
}

// Enable or disable preview screen
#if HAS_GCODE_PREVIEW || HAS_GCODE_PREVIEW_NOPRO
#if HAS_GCODE_PREVIEW
void C250() {
if (parser.seenval('P')) {
HMI_data.EnablePreview = !!parser.value_byte();
Expand Down Expand Up @@ -120,7 +120,7 @@ void custom_gcode(const int16_t codenum) {
case 35: C35(); break; // Launch bed tramming wizard
#endif
case 108: C108(); break; // Cancel a Wait for User without an Emergecy Parser
#if HAS_GCODE_PREVIEW || HAS_GCODE_PREVIEW_NOPRO
#if HAS_GCODE_PREVIEW
case 250: C250(); break; // Enable or disable preview screen
#endif
#if HAS_LOCKSCREEN
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/e3v2/proui/cv_laser_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "../../../inc/MarlinConfig.h"

#if HAS_MEDIA
#include "file_header.h"
#include "gcode_preview.h"
#define LASER_XMIN fileprop.minx
#define LASER_XMAX fileprop.maxx
#define LASER_YMIN fileprop.miny
Expand Down
38 changes: 13 additions & 25 deletions Marlin/src/lcd/e3v2/proui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#include "../../../feature/host_actions.h"
#endif

#if HAS_MESH || HAS_BED_PROBE
#if ANY(HAS_MESH, HAS_BED_PROBE)
#include "../../../feature/bedlevel/bedlevel.h"
#include "bedlevel_tools.h"
#endif
Expand Down Expand Up @@ -96,11 +96,8 @@
#include "../../../feature/tmc_util.h"
#endif

#if HAS_GCODE_PREVIEW
#include "file_header.h"
#if ANY(HAS_GCODE_PREVIEW, CV_LASER_MODULE)
#include "gcode_preview.h"
#elif HAS_GCODE_PREVIEW_NOPRO
#include "gcode_preview_nopro.h"
#endif

#if HAS_TOOLBAR
Expand Down Expand Up @@ -630,12 +627,6 @@ void Draw_PrintDone() {
DWINUI::ClearMainArea();
DWIN_Print_Header(nullptr);
#if HAS_GCODE_PREVIEW
const bool haspreview = Preview_Valid();
if (haspreview) {
Preview_Show();
DWINUI::Draw_Button(BTN_Continue, 86, 295, true);
}
#elif HAS_GCODE_PREVIEW_NOPRO
const bool haspreview = preview.valid();
if (haspreview) {
preview.show();
Expand Down Expand Up @@ -1843,14 +1834,13 @@ void DWIN_LevelingDone() {
// Started a Print Job
void DWIN_Print_Started() {
DEBUG_ECHOLNPGM("DWIN_Print_Started: ", SD_Printing());
TERN_(HAS_GCODE_PREVIEW, if (Host_Printing()) { Preview_Invalidate(); })
TERN_(HAS_GCODE_PREVIEW_NOPRO, if (Host_Printing()) { preview.invalidate(); })
TERN_(HAS_GCODE_PREVIEW, if (Host_Printing()) { preview.invalidate(); })
ui.progress_reset();
ui.reset_remaining_time();
HMI_flag.pause_flag = false;
HMI_flag.abort_flag = false;
select_print.reset();
#if PROUI_EX
#if PROUI_EX && HAS_GCODE_PREVIEW
if (!fileprop.isConfig) { Goto_PrintProcess(); }
#else
Goto_PrintProcess();
Expand All @@ -1876,7 +1866,7 @@ void DWIN_Print_Finished() {
HMI_flag.abort_flag = false;
HMI_flag.pause_flag = false;
wait_for_heatup = false;
#if PROUI_EX
#if PROUI_EX && HAS_GCODE_PREVIEW
if (!fileprop.isConfig) { Goto_PrintDone(); }
else { fileprop.isConfig = false; }
#else
Expand Down Expand Up @@ -2039,7 +2029,7 @@ void DWIN_SetDataDefaults() {
#endif
#endif
TERN_(ADAPTIVE_STEP_SMOOTHING, HMI_data.AdaptiveStepSmoothing = true;)
#if HAS_GCODE_PREVIEW || HAS_GCODE_PREVIEW_NOPRO
#if HAS_GCODE_PREVIEW
HMI_data.EnablePreview = true;
#endif
#if PROUI_EX
Expand Down Expand Up @@ -2279,7 +2269,7 @@ void DWIN_RedrawScreen() {

#endif // HAS_LOCKSCREEN

#if HAS_GCODE_PREVIEW || HAS_GCODE_PREVIEW_NOPRO
#if HAS_GCODE_PREVIEW

void SetPreview() { Toggle_Chkb_Line(HMI_data.EnablePreview); }

Expand All @@ -2297,11 +2287,11 @@ void DWIN_RedrawScreen() {
#endif

void Goto_ConfirmToPrint() {
#if PROUI_EX
fileprop.clear();
fileprop.setname(card.filename);
#if PROUI_EX && HAS_GCODE_PREVIEW
fileprop.clears();
fileprop.setnames(card.filename);
card.openFileRead(fileprop.name, 100);
getFileHeader();
//getFileHeader(); // no idea what this does
card.closefile();
if (fileprop.isConfig) return card.openAndPrintFile(card.filename);
#endif
Expand All @@ -2316,8 +2306,6 @@ void Goto_ConfirmToPrint() {
LaserOn(false); // If it is not laser file turn off laser mode
#endif
#if HAS_GCODE_PREVIEW
if (HMI_data.EnablePreview) return Goto_Popup(Preview_DrawFromSD, onClick_ConfirmToPrint);
#elif HAS_GCODE_PREVIEW_NOPRO
if (HMI_data.EnablePreview) return Goto_Popup(preview.drawFromSD, onClick_ConfirmToPrint);
#endif
card.openAndPrintFile(card.filename); // Direct print SD file
Expand Down Expand Up @@ -4520,7 +4508,7 @@ void Draw_AdvancedSettings_Menu() {
EDIT_ITEM(ICON_Sound, MSG_TICK, onDrawChkbMenu, SetEnableTick, &ui.tick_on);
EDIT_ITEM(ICON_Sound, MSG_SOUND, onDrawChkbMenu, SetEnableSound, &ui.sound_on);
#endif
#if HAS_GCODE_PREVIEW || HAS_GCODE_PREVIEW_NOPRO
#if HAS_GCODE_PREVIEW
EDIT_ITEM(ICON_File, MSG_HAS_PREVIEW, onDrawChkbMenu, SetPreview, &HMI_data.EnablePreview);
#endif
#if ENABLED(BAUD_RATE_GCODE)
Expand Down Expand Up @@ -4575,7 +4563,7 @@ void Draw_Advanced_Menu() { // From Control_Menu (Control) || Default-NP Advance
EDIT_ITEM(ICON_Sound, MSG_TICK, onDrawChkbMenu, SetEnableTick, &ui.tick_on);
EDIT_ITEM(ICON_Sound, MSG_SOUND, onDrawChkbMenu, SetEnableSound, &ui.sound_on);
#endif
#if HAS_GCODE_PREVIEW || HAS_GCODE_PREVIEW_NOPRO
#if HAS_GCODE_PREVIEW
EDIT_ITEM(ICON_File, MSG_HAS_PREVIEW, onDrawChkbMenu, SetPreview, &HMI_data.EnablePreview);
#endif
#if ENABLED(BAUD_RATE_GCODE)
Expand Down
53 changes: 0 additions & 53 deletions Marlin/src/lcd/e3v2/proui/file_header.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,41 @@

#include "../../../inc/MarlinConfigPre.h"

#if ALL(DWIN_LCD_PROUI, HAS_GCODE_PREVIEW_NOPRO)
#if ALL(DWIN_LCD_PROUI, HAS_GCODE_PREVIEW)

#include "gcode_preview_nopro.h"
#include "gcode_preview.h"

#include "../../../core/types.h"
#include "../../marlinui.h"
#include "../../../sd/cardreader.h"
#include "../../../MarlinCore.h" // for wait_for_user
#include "dwin.h"
#include "dwin_popup.h"
#include "base64.h"

#define THUMBWIDTH 200
#define THUMBHEIGHT 200

Preview preview;

typedef struct {
char name[13] = ""; // 8.3 + null
uint32_t thumbstart = 0;
int thumbsize = 0;
int thumbheight = 0, thumbwidth = 0;
float time = 0;
float filament = 0;
float layer = 0;
float width = 0, height = 0, length = 0;

void setname(const char * const fn) {
const uint8_t len = _MIN(sizeof(name) - 1, strlen(fn));
memcpy(name, fn, len);
name[len] = '\0';
}

void clear() {
name[0] = '\0';
thumbstart = 0;
thumbsize = 0;
thumbheight = thumbwidth = 0;
time = 0;
filament = 0;
layer = 0;
height = width = length = 0;
}
// When `getLine`, `getValue`, `getFileHeader` are enabled - uncomment this
// ??? what they do... Maybe Laser related?
//IF_DISABLED(PROUI_EX, fileprop_t fileprop;)
fileprop_t fileprop;

} fileprop_t;
void fileprop_t::setnames(const char * const fn) {
const uint8_t len = _MIN(sizeof(name) - 1, strlen(fn));
memcpy(name, fn, len);
name[len] = '\0';
}

fileprop_t fileprop;
void fileprop_t::clears() {
name[0] = '\0';
thumbstart = 0;
thumbsize = 0;
thumbheight = thumbwidth = 0;
time = 0;
filament = 0;
layer = 0;
height = width = length = 0;
}

void getValue(const char * const buf, PGM_P const key, float &value) {
if (value != 0.0f) return;
Expand All @@ -102,8 +90,8 @@ bool Preview::hasPreview() {
uint32_t indx = 0;
float tmp = 0;

fileprop.clear();
fileprop.setname(card.filename);
fileprop.clears();
fileprop.setnames(card.filename);

card.openFileRead(fileprop.name);

Expand Down Expand Up @@ -181,11 +169,7 @@ bool Preview::hasPreview() {
}

void Preview::drawFromSD() {
if (!hasPreview()) {
HMI_flag.select_flag = 1;
wait_for_user = false;
return;
}
hasPreview();

MString<45> buf;
DWIN_Draw_Rectangle(1, HMI_data.Background_Color, 0, 0, DWIN_WIDTH, STATUS_Y - 1);
Expand All @@ -205,10 +189,18 @@ void Preview::drawFromSD() {
buf.set(F("Volume: "), p_float_t(fileprop.width, 1), 'x', p_float_t(fileprop.length, 1), 'x', p_float_t(fileprop.height, 1), F(" mm"));
DWINUI::Draw_String(20, 70, &buf);
}

if (!fileprop.thumbsize) {
const uint8_t xpos = ((DWIN_WIDTH) / 2) - 55, // 55 = iconW/2
ypos = ((DWIN_HEIGHT) / 2) - 125;
DWINUI::Draw_Icon(ICON_Info_0, xpos, ypos);
buf.set(PSTR("No " STRINGIFY(THUMBWIDTH) "x" STRINGIFY(THUMBHEIGHT) " Thumbnail"));
DWINUI::Draw_CenteredString(false, (DWINUI::fontid*3), DWINUI::textcolor, DWINUI::backcolor, 0, DWIN_WIDTH, (DWIN_HEIGHT / 2), &buf);
}
DWINUI::Draw_Button(BTN_Print, 26, 290);
DWINUI::Draw_Button(BTN_Cancel, 146, 290);
show();
Draw_Select_Highlight(true, 290);
if (fileprop.thumbsize) show();
Draw_Select_Highlight(false, 290);
DWIN_UpdateLCD();
}

Expand Down
Loading
Loading