From 9552e51d866ded9920101e1651eb1b1353766851 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Thu, 19 Mar 2020 13:13:17 +0100 Subject: [PATCH 01/13] Version changed (4.0.5) --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index c5106e6d13..7636e75650 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -4.0.4 +4.0.5 From 3bd6b0173e26ed74b7361b4edfd75eab75652705 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Thu, 19 Mar 2020 13:34:54 +0100 Subject: [PATCH 02/13] fix - prevent recursion of marlin_server_cycle --- src/common/marlin_server.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/marlin_server.cpp b/src/common/marlin_server.cpp index e5213948ef..78e0f5bd37 100644 --- a/src/common/marlin_server.cpp +++ b/src/common/marlin_server.cpp @@ -217,6 +217,10 @@ static void print_Z_probe_cnt() { #endif int marlin_server_cycle(void) { + static int processing = 0; + if (processing) return 0; + processing = 1; + print_fan_spd(); #ifdef MINDA_BROKEN_CABLE_DETECTION print_Z_probe_cnt(); @@ -287,6 +291,7 @@ int marlin_server_cycle(void) { if ((marlin_server.flags & MARLIN_SFLG_PROCESS) == 0) HAL_IWDG_Refresh(&hiwdg); // this prevents iwdg reset while processing disabled #endif //_DEBUG + processing = 0; return count; } From 67fd04eeb0207ef9c772bb28fad1fbe3abd1fd82 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Thu, 19 Mar 2020 13:37:35 +0100 Subject: [PATCH 03/13] fix - stop print, park_head - starting coordinate allways from stepper menu_vars - extern const axis_steps_per_unit --- src/common/marlin_server.cpp | 17 ++++++++++------- src/gui/menu_vars.h | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/common/marlin_server.cpp b/src/common/marlin_server.cpp index 78e0f5bd37..4da2802f13 100644 --- a/src/common/marlin_server.cpp +++ b/src/common/marlin_server.cpp @@ -37,6 +37,8 @@ #include "lcdsim.h" #endif // LCDSIM +#include "menu_vars.h" + #define DBG _dbg1 //enabled level 1 //#define DBG(...) @@ -405,14 +407,7 @@ void marlin_server_quick_stop(void) { } void marlin_server_print_abort(void) { - wait_for_heatup = wait_for_user = false; card.flag.abort_sd_printing = true; - print_job_timer.stop(); - queue.clear(); - // planner.quick_stop(); - // marlin_server_park_head(); - // planner.synchronize(); - // queue.inject_P("M125"); } void marlin_server_print_pause(void) { @@ -430,6 +425,14 @@ void marlin_server_print_resume(void) { void marlin_server_park_head(void) { //homed check if (all_axes_homed() && all_axes_known()) { + float x = ((float)stepper.position(X_AXIS)) / axis_steps_per_unit[X_AXIS]; + float y = ((float)stepper.position(Y_AXIS)) / axis_steps_per_unit[Y_AXIS]; + float z = ((float)stepper.position(Z_AXIS)) / axis_steps_per_unit[Z_AXIS]; + current_position.x = x; + current_position.y = y; + current_position.z = z; + current_position.e = 0; + planner.set_position_mm(x, y, z, 0); xyz_pos_t park_point = NOZZLE_PARK_POINT; nozzle.park(2, park_point); } diff --git a/src/gui/menu_vars.h b/src/gui/menu_vars.h index bec99ee0e3..1ed0763db2 100644 --- a/src/gui/menu_vars.h +++ b/src/gui/menu_vars.h @@ -21,6 +21,8 @@ extern const int z_axis_len; extern const int len_tol_abs; // length absolute tolerance (+-5mm) extern const int len_tol_rev; // length tolerance in reversed direction (3mm) +extern const int axis_steps_per_unit[]; + extern const float nozzle_to_probe[3]; extern const float z_offset_step; From 77650962b01e2a851d9ca8ceda733f1a3c96737d Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Thu, 19 Mar 2020 14:11:45 +0100 Subject: [PATCH 04/13] clang-format --- src/common/marlin_server.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/marlin_server.cpp b/src/common/marlin_server.cpp index 4da2802f13..9e9734e512 100644 --- a/src/common/marlin_server.cpp +++ b/src/common/marlin_server.cpp @@ -220,7 +220,8 @@ static void print_Z_probe_cnt() { int marlin_server_cycle(void) { static int processing = 0; - if (processing) return 0; + if (processing) + return 0; processing = 1; print_fan_spd(); From 887b4ef497119f2fddc456f77ff2cdbb991dc599 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Mar 2020 00:24:29 +0100 Subject: [PATCH 05/13] MarlinAPI update/fix - new function marlin_settings_reset + fixed settings load/save + renamed commands 'load' and 'save' to 'cfg_load' and 'cfg_save' for better readability + eeprom variable initialization in appmain simplified/finalized --- src/common/appmain.cpp | 10 +--------- src/common/marlin_client.c | 12 ++++++++++-- src/common/marlin_client.h | 2 ++ src/common/marlin_server.cpp | 29 +++++++++++++++++++++++++---- src/common/marlin_server.h | 3 +++ 5 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/common/appmain.cpp b/src/common/appmain.cpp index b7e20c2e61..d3469adf59 100644 --- a/src/common/appmain.cpp +++ b/src/common/appmain.cpp @@ -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()); diff --git a/src/common/marlin_client.c b/src/common/marlin_client.c index 352b3e4a5e..53161d9303 100644 --- a/src/common/marlin_client.c +++ b/src/common/marlin_client.c @@ -511,7 +511,7 @@ 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); } @@ -519,7 +519,15 @@ 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); } diff --git a/src/common/marlin_client.h b/src/common/marlin_client.h index b3f647004d..c4a98f8e06 100644 --- a/src/common/marlin_client.h +++ b/src/common/marlin_client.h @@ -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); diff --git a/src/common/marlin_server.cpp b/src/common/marlin_server.cpp index 9e9734e512..34a04bc7c6 100644 --- a/src/common/marlin_server.cpp +++ b/src/common/marlin_server.cpp @@ -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) { @@ -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; diff --git a/src/common/marlin_server.h b/src/common/marlin_server.h index 42a093c0d3..c5726d232e 100644 --- a/src/common/marlin_server.h +++ b/src/common/marlin_server.h @@ -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); From b8e4b88d70a1da060eb480eabc7c2a29d6bc34ba Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Mar 2020 00:27:48 +0100 Subject: [PATCH 06/13] wizard_ui - fixed _wizard_init_test init original solution M501, new solution marlin_settings_load + removed unused code --- src/gui/wizard/wizard_ui.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/gui/wizard/wizard_ui.c b/src/gui/wizard/wizard_ui.c index bfd724078a..626643d512 100644 --- a/src/gui/wizard/wizard_ui.c +++ b/src/gui/wizard/wizard_ui.c @@ -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) { @@ -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() { From 5a330bda1c901cb459bfe5bb9fe0b8e49f501eee Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Mar 2020 00:29:36 +0100 Subject: [PATCH 07/13] selftest_cool fix - M501 replaced with marlin_settings_load --- src/gui/wizard/selftest_cool.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/gui/wizard/selftest_cool.c b/src/gui/wizard/selftest_cool.c index 796f21edc1..75d7e58205 100644 --- a/src/gui/wizard/selftest_cool.c +++ b/src/gui/wizard/selftest_cool.c @@ -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(); } //------------------------------------- From 27d638bc50284c7aa1f049bc149db78f5ce84f62 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Mar 2020 00:30:34 +0100 Subject: [PATCH 08/13] screen_wizard fix - M500 for Z-offset replaced with eeprom_set_var --- src/gui/wizard/screen_wizard.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/wizard/screen_wizard.c b/src/gui/wizard/screen_wizard.c index 4de5f59685..4792adf8be 100644 --- a/src/gui/wizard/screen_wizard.c +++ b/src/gui/wizard/screen_wizard.c @@ -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)); } } @@ -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: From 0c31310d0b1b31214ac075d855ed512269c01ed3 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Mar 2020 00:31:02 +0100 Subject: [PATCH 09/13] wizard/firstlay - removed unused code --- src/gui/wizard/firstlay.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/wizard/firstlay.c b/src/gui/wizard/firstlay.c index 4756d4690b..781a09683f 100644 --- a/src/gui/wizard/firstlay.c +++ b/src/gui/wizard/firstlay.c @@ -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; } From 2b766fdf2eb2473b6c40814897e108f62e99ef9c Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Mar 2020 00:32:19 +0100 Subject: [PATCH 10/13] screen_menu_tune fix - marlin_settings_save replaced with eeprom_set_var --- src/gui/screen_menu_tune.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/screen_menu_tune.cpp b/src/gui/screen_menu_tune.cpp index 86f4012ea3..0211aec7a3 100644 --- a/src/gui/screen_menu_tune.cpp +++ b/src/gui/screen_menu_tune.cpp @@ -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; @@ -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) { From cfef18ccbba5ae187ba199ff764bd0b07cfa2bf5 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Mar 2020 01:18:22 +0100 Subject: [PATCH 11/13] screen_PID - fixed eeprom handling after autotune, removed unused code --- src/gui/screen_PID.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gui/screen_PID.cpp b/src/gui/screen_PID.cpp index 34f1115325..205f19b6b1 100644 --- a/src/gui/screen_PID.cpp +++ b/src/gui/screen_PID.cpp @@ -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: @@ -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: @@ -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 From 536edb1e5a85e6642806d2f976fff3923fceb47b Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Mar 2020 11:56:50 +0100 Subject: [PATCH 12/13] screen_wizard - fix - M500 replaced with eeprom_set_var(EEVAR_ZOFFSET --- src/gui/wizard/screen_wizard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/wizard/screen_wizard.c b/src/gui/wizard/screen_wizard.c index 4792adf8be..1a0a8f75ed 100644 --- a/src/gui/wizard/screen_wizard.c +++ b/src/gui/wizard/screen_wizard.c @@ -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 { From 1dcd8fe0112590af9b2caac4d85c6da958ced8f9 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Mar 2020 14:35:19 +0100 Subject: [PATCH 13/13] eeprom - fw_version and fw_build --- src/common/eeprom.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/common/eeprom.c b/src/common/eeprom.c index a583cb5f78..45a98f0adc 100644 --- a/src/common/eeprom.c +++ b/src/common/eeprom.c @@ -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) @@ -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 @@ -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) { @@ -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); @@ -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 @@ -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";