Pretty up EEPROM port args

This commit is contained in:
Scott Lahteine 2018-03-14 22:44:07 -05:00
parent 51bf3c9503
commit 4aebe3d82e
2 changed files with 40 additions and 94 deletions

View File

@ -45,6 +45,17 @@
//#define DEBUG_EEPROM_READWRITE
#include "configuration_store.h"
#if ADD_PORT_ARG
#define PORTARG_SOLO const int8_t port
#define PORTARG_AFTER ,const int8_t port
#define PORTVAR_SOLO port
#else
#define PORTARG_SOLO
#define PORTARG_AFTER
#define PORTVAR_SOLO
#endif
#include "endstops.h"
#include "planner.h"
#include "stepper.h"
@ -345,11 +356,7 @@ void MarlinSettings::postprocess() {
bool MarlinSettings::eeprom_error, MarlinSettings::validating;
bool MarlinSettings::size_error(const uint16_t size
#if ADD_PORT_ARG
, const int8_t port/*=-1*/
#endif
) {
bool MarlinSettings::size_error(const uint16_t size PORTARG_AFTER) {
if (size != datasize()) {
#if ENABLED(EEPROM_CHITCHAT)
SERIAL_ERROR_START_P(port);
@ -363,11 +370,7 @@ void MarlinSettings::postprocess() {
/**
* M500 - Store Configuration
*/
bool MarlinSettings::save(
#if ADD_PORT_ARG
const int8_t port/*=-1*/
#endif
) {
bool MarlinSettings::save(PORTARG_SOLO) {
float dummy = 0.0f;
char ver[4] = "ERR";
@ -853,11 +856,7 @@ void MarlinSettings::postprocess() {
/**
* M501 - Retrieve Configuration
*/
bool MarlinSettings::_load(
#if ADD_PORT_ARG
const int8_t port/*=-1*/
#endif
) {
bool MarlinSettings::_load(PORTARG_SOLO) {
uint16_t working_crc = 0;
EEPROM_START();
@ -1431,46 +1430,22 @@ void MarlinSettings::postprocess() {
}
#if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
if (!validating) report(
#if ADD_PORT_ARG
port
#endif
);
if (!validating) report(PORTVAR_SOLO);
#endif
EEPROM_FINISH();
return !eeprom_error;
}
bool MarlinSettings::validate(
#if ADD_PORT_ARG
const int8_t port/*=-1*/
#endif
) {
bool MarlinSettings::validate(PORTARG_SOLO) {
validating = true;
const bool success = _load(
#if ADD_PORT_ARG
port
#endif
);
const bool success = _load(PORTVAR_SOLO);
validating = false;
return success;
}
bool MarlinSettings::load(
#if ADD_PORT_ARG
const int8_t port/*=-1*/
#endif
) {
if (validate(
#if ADD_PORT_ARG
port
#endif
)) return _load(
#if ADD_PORT_ARG
port
#endif
);
bool MarlinSettings::load(PORTARG_SOLO) {
if (validate(PORTVAR_SOLO)) return _load(PORTVAR_SOLO);
reset();
return true;
}
@ -1581,11 +1556,7 @@ void MarlinSettings::postprocess() {
#else // !EEPROM_SETTINGS
bool MarlinSettings::save(
#if ADD_PORT_ARG
const int8_t port/*=-1*/
#endif
) {
bool MarlinSettings::save(PORTARG_SOLO) {
#if ENABLED(EEPROM_CHITCHAT)
SERIAL_ERROR_START_P(port);
SERIAL_ERRORLNPGM_P(port, "EEPROM disabled");
@ -1598,11 +1569,7 @@ void MarlinSettings::postprocess() {
/**
* M502 - Reset Configuration
*/
void MarlinSettings::reset(
#if ADD_PORT_ARG
const int8_t port/*=-1*/
#endif
) {
void MarlinSettings::reset(PORTARG_SOLO) {
static const float tmp1[] PROGMEM = DEFAULT_AXIS_STEPS_PER_UNIT, tmp2[] PROGMEM = DEFAULT_MAX_FEEDRATE;
static const uint32_t tmp3[] PROGMEM = DEFAULT_MAX_ACCELERATION;
LOOP_XYZE_N(i) {
@ -1860,11 +1827,7 @@ void MarlinSettings::reset(
#if DISABLED(DISABLE_M503)
#if ADD_PORT_ARG
#define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START_P(port); }while(0)
#else
#define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START(); }while(0)
#endif
#define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START_P(PORTVAR_SOLO); }while(0)
/**
* M503 - Report current settings in RAM
@ -2129,11 +2092,7 @@ void MarlinSettings::reset(
SERIAL_ECHOLNPGM_P(port, " meshes.\n");
}
ubl.report_current_mesh(
#if ADD_PORT_ARG
port
#endif
);
ubl.report_current_mesh(PORTVAR_SOLO);
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)

View File

@ -27,22 +27,22 @@
#define ADD_PORT_ARG ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
#if ADD_PORT_ARG
#define PORTINIT_SOLO const int8_t port=-1
#define PORTINIT_AFTER ,const int8_t port=-1
#else
#define PORTINIT_SOLO
#define PORTINIT_AFTER
#endif
class MarlinSettings {
public:
MarlinSettings() { }
static uint16_t datasize();
static void reset(
#if ADD_PORT_ARG
const int8_t port=-1
#endif
);
static bool save(
#if ADD_PORT_ARG
const int8_t port=-1
#endif
); // Return 'true' if data was saved
static void reset(PORTINIT_SOLO);
static bool save(PORTINIT_SOLO); // Return 'true' if data was saved
FORCE_INLINE static bool init_eeprom() {
bool success = true;
@ -57,16 +57,8 @@ class MarlinSettings {
}
#if ENABLED(EEPROM_SETTINGS)
static bool load(
#if ADD_PORT_ARG
const int8_t port=-1
#endif
); // Return 'true' if data was loaded ok
static bool validate(
#if ADD_PORT_ARG
const int8_t port=-1
#endif
); // Return 'true' if EEPROM data is ok
static bool load(PORTINIT_SOLO); // Return 'true' if data was loaded ok
static bool validate(PORTINIT_SOLO); // Return 'true' if EEPROM data is ok
#if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
// That can store is enabled
@ -110,19 +102,14 @@ class MarlinSettings {
#endif
static bool _load(
#if ADD_PORT_ARG
const int8_t port=-1
#endif
);
static bool size_error(const uint16_t size
#if ADD_PORT_ARG
, const int8_t port=-1
#endif
);
static bool _load(PORTINIT_SOLO);
static bool size_error(const uint16_t size PORTINIT_AFTER);
#endif
};
extern MarlinSettings settings;
#undef PORTINIT_SOLO
#undef PORTINIT_AFTER
#endif // CONFIGURATION_STORE_H