Skip to content

Commit

Permalink
Merge pull request #307 from XPila/RELEASE-4.0.5
Browse files Browse the repository at this point in the history
Release 4.0.5
  • Loading branch information
XPila authored Mar 20, 2020
2 parents bf8f1c2 + 1dcd8fe commit 9702ced
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 36 deletions.
10 changes: 1 addition & 9 deletions src/common/appmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,7 @@ extern IWDG_HandleTypeDef hiwdg; //watchdog handle
void app_setup(void) {
setup();

// variables from eeprom - temporary solution
probe_offset.z = eeprom_get_var(EEVAR_ZOFFSET).flt;
Temperature::temp_bed.pid.Kp = eeprom_get_var(EEVAR_PID_BED_P).flt;
Temperature::temp_bed.pid.Ki = eeprom_get_var(EEVAR_PID_BED_I).flt;
Temperature::temp_bed.pid.Kd = eeprom_get_var(EEVAR_PID_BED_D).flt;
Temperature::temp_hotend[0].pid.Kp = eeprom_get_var(EEVAR_PID_NOZ_P).flt;
Temperature::temp_hotend[0].pid.Ki = eeprom_get_var(EEVAR_PID_NOZ_I).flt;
Temperature::temp_hotend[0].pid.Kd = eeprom_get_var(EEVAR_PID_NOZ_D).flt;
thermalManager.updatePID();
marlin_server_settings_load(); // load marlin variables from eeprom

init_tmc();
//DBG("after init_tmc (%ld ms)", HAL_GetTick());
Expand Down
20 changes: 18 additions & 2 deletions src/common/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "cmsis_os.h"
#include "ff.h"
#include "crc32.h"
#include "version.h"

#define EEPROM_VARCOUNT (sizeof(eeprom_map) / sizeof(eeprom_entry_t))
#define EEPROM_DATASIZE sizeof(eeprom_vars_t)
Expand Down Expand Up @@ -110,8 +111,8 @@ static const eeprom_vars_t eeprom_var_defaults = {
EEPROM_VERSION, // EEVAR_VERSION
EEPROM_FEATURES, // EEVAR_FEATURES
EEPROM_DATASIZE, // EEVAR_DATASIZE
0, // EEVAR_FW_VERSION TODO: default value
0, // EEVAR_FW_BUILD TODO: default value
0, // EEVAR_FW_VERSION
0, // EEVAR_FW_BUILD
0, // EEVAR_FILAMENT_TYPE
0, // EEVAR_FILAMENT_COLOR
1, // EEVAR_RUN_SELFTEST
Expand Down Expand Up @@ -163,6 +164,8 @@ static int eeprom_convert_from(uint16_t version, uint16_t features);
static int eeprom_check_crc32(void);
static void eeprom_update_crc32(uint16_t addr, uint16_t size);

static uint16_t eeprom_fwversion_ui16(void);

// public functions - described in header

uint8_t eeprom_init(void) {
Expand Down Expand Up @@ -196,6 +199,8 @@ uint8_t eeprom_init(void) {

void eeprom_defaults(void) {
eeprom_vars_t vars = eeprom_var_defaults;
vars.FWBUILD = project_build_number;
vars.FWVERSION = eeprom_fwversion_ui16();
eeprom_lock();
// calculate crc32
vars.CRC32 = crc32_calc((uint32_t *)(&vars), (EEPROM_DATASIZE - 4) / 4);
Expand Down Expand Up @@ -344,6 +349,8 @@ static void eeprom_print_vars(void) {
// conversion function for old version 2 format (marlin eeprom)
static int eeprom_convert_from_v2(void) {
eeprom_vars_t vars = eeprom_var_defaults;
vars.FWBUILD = project_build_number;
vars.FWVERSION = eeprom_fwversion_ui16();
// read FILAMENT_TYPE (uint8_t)
st25dv64k_user_read_bytes(ADDR_V2_FILAMENT_TYPE, &(vars.FILAMENT_TYPE), sizeof(uint8_t));
// initialize to zero, maybe not necessary
Expand Down Expand Up @@ -414,6 +421,15 @@ static void eeprom_update_crc32(uint16_t addr, uint16_t size) {
#endif
}

static uint16_t eeprom_fwversion_ui16(void) {
int maj = 0;
int min = 0;
int sub = 0;
if (sscanf(project_version, "%d.%d.%d", &maj, &min, &sub) == 3)
return sub + 10 * (min + 10 * maj);
return 0;
}

int8_t eeprom_test_PUT(const unsigned int bytes) {
unsigned int i;
char line[16] = "abcdefghijklmno";
Expand Down
12 changes: 10 additions & 2 deletions src/common/marlin_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,23 @@ void marlin_settings_save(void) {
marlin_client_t *client = _client_ptr();
if (client == 0)
return;
_send_request_to_server(client->id, "!save");
_send_request_to_server(client->id, "!cfg_save");
_wait_ack_from_server(client->id);
}

void marlin_settings_load(void) {
marlin_client_t *client = _client_ptr();
if (client == 0)
return;
_send_request_to_server(client->id, "!load");
_send_request_to_server(client->id, "!cfg_load");
_wait_ack_from_server(client->id);
}

void marlin_settings_reset(void) {
marlin_client_t *client = _client_ptr();
if (client == 0)
return;
_send_request_to_server(client->id, "!cfg_reset");
_wait_ack_from_server(client->id);
}

Expand Down
2 changes: 2 additions & 0 deletions src/common/marlin_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ extern void marlin_settings_save(void);

extern void marlin_settings_load(void);

extern void marlin_settings_reset(void);

extern void marlin_manage_heater(void);

extern void marlin_quick_stop(void);
Expand Down
29 changes: 25 additions & 4 deletions src/common/marlin_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,29 @@ int marlin_server_inject_gcode(const char *gcode) {
}

void marlin_server_settings_save(void) {
(void)settings.save();
eeprom_set_var(EEVAR_ZOFFSET, variant8_flt(probe_offset.z));
eeprom_set_var(EEVAR_PID_BED_P, variant8_flt(Temperature::temp_bed.pid.Kp));
eeprom_set_var(EEVAR_PID_BED_I, variant8_flt(Temperature::temp_bed.pid.Ki));
eeprom_set_var(EEVAR_PID_BED_D, variant8_flt(Temperature::temp_bed.pid.Kd));
eeprom_set_var(EEVAR_PID_NOZ_P, variant8_flt(Temperature::temp_hotend[0].pid.Kp));
eeprom_set_var(EEVAR_PID_NOZ_I, variant8_flt(Temperature::temp_hotend[0].pid.Ki));
eeprom_set_var(EEVAR_PID_NOZ_D, variant8_flt(Temperature::temp_hotend[0].pid.Kd));
}

void marlin_server_settings_load(void) {
(void)settings.load();
(void)settings.reset();
probe_offset.z = eeprom_get_var(EEVAR_ZOFFSET).flt;
Temperature::temp_bed.pid.Kp = eeprom_get_var(EEVAR_PID_BED_P).flt;
Temperature::temp_bed.pid.Ki = eeprom_get_var(EEVAR_PID_BED_I).flt;
Temperature::temp_bed.pid.Kd = eeprom_get_var(EEVAR_PID_BED_D).flt;
Temperature::temp_hotend[0].pid.Kp = eeprom_get_var(EEVAR_PID_NOZ_P).flt;
Temperature::temp_hotend[0].pid.Ki = eeprom_get_var(EEVAR_PID_NOZ_I).flt;
Temperature::temp_hotend[0].pid.Kd = eeprom_get_var(EEVAR_PID_NOZ_D).flt;
thermalManager.updatePID();
}

void marlin_server_settings_reset(void) {
(void)settings.reset();
}

void marlin_server_manage_heater(void) {
Expand Down Expand Up @@ -835,12 +853,15 @@ int _process_server_request(char *request) {
} else if (sscanf(request, "!babystep_Z %f", &offs) == 1) {
marlin_server_do_babystep_Z(offs);
processed = 1;
} else if (strcmp("!save", request) == 0) {
} else if (strcmp("!cfg_save", request) == 0) {
marlin_server_settings_save();
processed = 1;
} else if (strcmp("!load", request) == 0) {
} else if (strcmp("!cfg_load", request) == 0) {
marlin_server_settings_load();
processed = 1;
} else if (strcmp("!cfg_reset", request) == 0) {
marlin_server_settings_reset();
processed = 1;
} else if (strcmp("!updt", request) == 0) {
marlin_server_manage_heater();
processed = 1;
Expand Down
3 changes: 3 additions & 0 deletions src/common/marlin_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ extern void marlin_server_settings_save(void);
// direct call of settings.load()
extern void marlin_server_settings_load(void);

// direct call of settings.reset()
extern void marlin_server_settings_reset(void);

// direct call of thermalManager.manage_heater()
extern void marlin_server_manage_heater(void);

Expand Down
12 changes: 9 additions & 3 deletions src/gui/screen_PID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ int screen_PID_event(screen_t *screen, window_t *window, uint8_t event, void *pa
eeprom_set_var(EEVAR_PID_NOZ_P, variant8_flt(Temperature::temp_hotend[0].pid.Kp));
eeprom_set_var(EEVAR_PID_NOZ_I, variant8_flt(Temperature::temp_hotend[0].pid.Ki));
eeprom_set_var(EEVAR_PID_NOZ_D, variant8_flt(Temperature::temp_hotend[0].pid.Kd));
// marlin_gcode("M500"); //store to eeprom
}
break;
case TAG_AUTOTUNE_APPLY_B:
Expand All @@ -393,7 +392,6 @@ int screen_PID_event(screen_t *screen, window_t *window, uint8_t event, void *pa
eeprom_set_var(EEVAR_PID_BED_P, variant8_flt(Temperature::temp_bed.pid.Kp));
eeprom_set_var(EEVAR_PID_BED_I, variant8_flt(Temperature::temp_bed.pid.Ki));
eeprom_set_var(EEVAR_PID_BED_D, variant8_flt(Temperature::temp_bed.pid.Kd));
// marlin_gcode("M500"); //store to eeprom
}
break;
case TAG_CHANGE_VAL_E:
Expand Down Expand Up @@ -560,7 +558,15 @@ void _PID_copy_and_scale_PID_d(_PID_t *ths) {

void _PID_autotune(_PID_t *ths) {
marlin_gcode_printf("M303 U1 E%i S%i", ths->ID, int(*ths->autotune_temp));
// marlin_gcode("M500");
if (ths->ID >= 0) {
eeprom_set_var(EEVAR_PID_NOZ_P, variant8_flt(Temperature::temp_hotend[0].pid.Kp));
eeprom_set_var(EEVAR_PID_NOZ_I, variant8_flt(Temperature::temp_hotend[0].pid.Ki));
eeprom_set_var(EEVAR_PID_NOZ_D, variant8_flt(Temperature::temp_hotend[0].pid.Kd));
} else {
eeprom_set_var(EEVAR_PID_BED_P, variant8_flt(Temperature::temp_bed.pid.Kp));
eeprom_set_var(EEVAR_PID_BED_I, variant8_flt(Temperature::temp_bed.pid.Ki));
eeprom_set_var(EEVAR_PID_BED_D, variant8_flt(Temperature::temp_bed.pid.Kd));
}
}

//0 the contents of both memory blocks are equal
Expand Down
3 changes: 2 additions & 1 deletion src/gui/screen_menu_tune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "marlin_client.h"
#include "filament.h"
#include "menu_vars.h"
#include "eeprom.h"

#ifdef _DEBUG
extern screen_t screen_test;
Expand Down Expand Up @@ -133,7 +134,7 @@ int screen_menu_tune_event(screen_t *screen, window_t *window,
break;
case MI_BABYSTEP:
marlin_set_z_offset(psmd->items[MI_BABYSTEP].item.wi_spin_fl.value);
marlin_settings_save();
eeprom_set_var(EEVAR_ZOFFSET, marlin_get_var(MARLIN_VAR_Z_OFFSET));
break;
}
} else if (event == WINDOW_EVENT_CLICK) {
Expand Down
1 change: 0 additions & 1 deletion src/gui/wizard/firstlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ int wizard_firstlay_print(int16_t id_body, firstlay_screen_t *p_screen, firstlay
window_invalidate(p_screen->term.win.id);
#endif
p_data->state_print = _TEST_PASSED;
//marlin_settings_save();
p_screen->Z_offset_request = 0;
return 100;
}
Expand Down
6 changes: 3 additions & 3 deletions src/gui/wizard/screen_wizard.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ int screen_wizard_event(screen_t *screen, window_t *window, uint8_t event, void

if (wizard_msgbox(buff, MSGBOX_BTN_YESNO, 0) == MSGBOX_RES_NO) {
marlin_set_z_offset(z_offset_def);
marlin_gcode("M500"); //store to eeprom
eeprom_set_var(EEVAR_ZOFFSET, variant8_flt(z_offset_def));
}
}

Expand Down Expand Up @@ -429,7 +429,7 @@ int screen_wizard_event(screen_t *screen, window_t *window, uint8_t event, void
== MSGBOX_RES_NO) {
pd->state = _STATE_FINISH;
marlin_set_z_offset(p_firstlay_screen->Z_offset);
marlin_gcode("M500"); //store to eeprom
eeprom_set_var(EEVAR_ZOFFSET, variant8_flt(p_firstlay_screen->Z_offset));
eeprom_set_var(EEVAR_RUN_FIRSTLAY, variant8_ui8(0)); // clear first layer flag
wizard_done_screen(screen);
} else {
Expand All @@ -455,7 +455,7 @@ int screen_wizard_event(screen_t *screen, window_t *window, uint8_t event, void
}
}
marlin_set_z_offset(z_val_to_store);
marlin_gcode("M500"); //store to eeprom
eeprom_set_var(EEVAR_ZOFFSET, variant8_flt(z_val_to_store));
}
break;
case _STATE_FIRSTLAY_FAIL:
Expand Down
6 changes: 1 addition & 5 deletions src/gui/wizard/selftest_cool.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ int wizard_selftest_cool(int16_t id_body, selftest_cool_screen_t *p_screen, self
hwio_fan_set_pwm(0, 0);
hwio_fan_set_pwm(1, 0);
marlin_start_processing();
marlin_event_clr(MARLIN_EVT_LoadSettings);
marlin_event_clr(MARLIN_EVT_FactoryReset);
// marlin_gcode("M501"); //restore settings
// while (!marlin_event_clr(MARLIN_EVT_LoadSettings) && !marlin_event_clr(MARLIN_EVT_FactoryReset)) //wait for M501 done
// gui_loop();
marlin_settings_load();
}
//-------------------------------------

Expand Down
7 changes: 1 addition & 6 deletions src/gui/wizard/wizard_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "resource.h"
#include "stm32f4xx_hal.h" //HAL_GetTick
#include "marlin_client.h" //HAL_GetTick
#include "marlin_server.h" //marlin_server_settings_load

uint16_t wizard_get_test_icon_resource(uint8_t state) {
switch (state) {
Expand Down Expand Up @@ -91,11 +90,7 @@ int wizard_timer(uint32_t *p_timer, uint32_t delay_ms, _TEST_STATE_t *pstate, _W
static void _wizard_init_test() {
if (!marlin_processing())
marlin_start_processing();
marlin_event_clr(MARLIN_EVT_LoadSettings);
marlin_event_clr(MARLIN_EVT_FactoryReset);
// marlin_gcode("M501"); //restore settings
// while (!marlin_event_clr(MARLIN_EVT_LoadSettings) && !marlin_event_clr(MARLIN_EVT_FactoryReset)) //wait for M501 done
// gui_loop();
marlin_settings_load();
}

static void _disable_PID() {
Expand Down

0 comments on commit 9702ced

Please sign in to comment.