Drop the accessor form for LCD value editing

This commit is contained in:
Scott Lahteine 2017-04-21 22:30:36 -05:00
parent 10da175be5
commit ccda63c473
4 changed files with 25 additions and 67 deletions

View file

@ -8858,7 +8858,7 @@ inline void gcode_M503() {
stepper.synchronize(); stepper.synchronize();
const float newK = code_seen('K') ? code_value_float() : -1; const float newK = code_seen('K') ? code_value_float() : -1;
if (newK >= 0) planner.set_extruder_advance_k(newK); if (newK >= 0) planner.extruder_advance_k = newK;
float newR = code_seen('R') ? code_value_float() : -1; float newR = code_seen('R') ? code_value_float() : -1;
if (newR < 0) { if (newR < 0) {
@ -8868,12 +8868,12 @@ inline void gcode_M503() {
if (newD >= 0 && newW >= 0 && newH >= 0) if (newD >= 0 && newW >= 0 && newH >= 0)
newR = newD ? (newW * newH) / (sq(newD * 0.5) * M_PI) : 0; newR = newD ? (newW * newH) / (sq(newD * 0.5) * M_PI) : 0;
} }
if (newR >= 0) planner.set_advance_ed_ratio(newR); if (newR >= 0) planner.advance_ed_ratio = newR;
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOPAIR("Advance K=", planner.get_extruder_advance_k()); SERIAL_ECHOPAIR("Advance K=", planner.extruder_advance_k);
SERIAL_ECHOPGM(" E/D="); SERIAL_ECHOPGM(" E/D=");
const float ratio = planner.get_advance_ed_ratio(); const float ratio = planner.advance_ed_ratio;
ratio ? SERIAL_ECHO(ratio) : SERIAL_ECHOPGM("Auto"); ratio ? SERIAL_ECHO(ratio) : SERIAL_ECHOPGM("Auto");
SERIAL_EOL; SERIAL_EOL;
} }

View file

@ -578,16 +578,15 @@ void MarlinSettings::postprocess() {
// Linear Advance // Linear Advance
// //
float extruder_advance_k = 0.0f, advance_ed_ratio = 0.0f;
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
extruder_advance_k = planner.get_extruder_advance_k(); EEPROM_WRITE(planner.extruder_advance_k);
advance_ed_ratio = planner.get_advance_ed_ratio(); EEPROM_WRITE(planner.advance_ed_ratio);
#else
dummy = 0.0f;
EEPROM_WRITE(dummy);
EEPROM_WRITE(dummy);
#endif #endif
EEPROM_WRITE(extruder_advance_k);
EEPROM_WRITE(advance_ed_ratio);
if (!eeprom_write_error) { if (!eeprom_write_error) {
const uint16_t final_checksum = eeprom_checksum, const uint16_t final_checksum = eeprom_checksum,
@ -922,13 +921,12 @@ void MarlinSettings::postprocess() {
// Linear Advance // Linear Advance
// //
float extruder_advance_k, advance_ed_ratio;
EEPROM_READ(extruder_advance_k);
EEPROM_READ(advance_ed_ratio);
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
planner.set_extruder_advance_k(extruder_advance_k); EEPROM_READ(planner.extruder_advance_k);
planner.set_advance_ed_ratio(advance_ed_ratio); EEPROM_READ(planner.advance_ed_ratio);
#else
EEPROM_READ(dummy);
EEPROM_READ(dummy);
#endif #endif
if (eeprom_checksum == stored_checksum) { if (eeprom_checksum == stored_checksum) {
@ -1187,8 +1185,8 @@ void MarlinSettings::reset() {
#endif #endif
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
planner.set_extruder_advance_k(LIN_ADVANCE_K); planner.extruder_advance_k = LIN_ADVANCE_K;
planner.set_advance_ed_ratio(LIN_ADVANCE_E_D_RATIO); planner.advance_ed_ratio = LIN_ADVANCE_E_D_RATIO;
#endif #endif
postprocess(); postprocess();
@ -1658,8 +1656,8 @@ void MarlinSettings::reset() {
SERIAL_ECHOLNPGM("Linear Advance:"); SERIAL_ECHOLNPGM("Linear Advance:");
} }
CONFIG_ECHO_START; CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" M900 K", planner.get_extruder_advance_k()); SERIAL_ECHOPAIR(" M900 K", planner.extruder_advance_k);
SERIAL_ECHOLNPAIR(" R", planner.get_advance_ed_ratio()); SERIAL_ECHOLNPAIR(" R", planner.advance_ed_ratio);
#endif #endif
} }

View file

@ -168,6 +168,10 @@ class Planner {
static float z_fade_height, inverse_z_fade_height; static float z_fade_height, inverse_z_fade_height;
#endif #endif
#if ENABLED(LIN_ADVANCE)
static float extruder_advance_k, advance_ed_ratio;
#endif
private: private:
/** /**
@ -209,8 +213,6 @@ class Planner {
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
static float position_float[NUM_AXIS]; static float position_float[NUM_AXIS];
static float extruder_advance_k;
static float advance_ed_ratio;
#endif #endif
#if ENABLED(ULTRA_LCD) #if ENABLED(ULTRA_LCD)
@ -266,13 +268,6 @@ class Planner {
#endif #endif
#if ENABLED(LIN_ADVANCE)
static void set_extruder_advance_k(float k) { extruder_advance_k = k; };
static float get_extruder_advance_k() { return extruder_advance_k; };
static void set_advance_ed_ratio(float ratio) { advance_ed_ratio = ratio; };
static float get_advance_ed_ratio() { return advance_ed_ratio; };
#endif
/** /**
* Planner::_buffer_line * Planner::_buffer_line
* *

View file

@ -181,8 +181,6 @@ uint16_t max_display_update_time = 0;
void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \ void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \ void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback); \ void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback); \
void _menu_action_setting_edit_accessor_ ## _name(const char * const pstr, _type (*pget)(), void (*pset)(_type), const _type minValue, const _type maxValue); \
void menu_action_setting_edit_accessor_ ## _name(const char * const pstr, _type (*pget)(), void (*pset)(_type), const _type minValue, const _type maxValue); \
typedef void _name##_void typedef void _name##_void
DECLARE_MENU_EDIT_TYPE(int, int3); DECLARE_MENU_EDIT_TYPE(int, int3);
@ -197,7 +195,6 @@ uint16_t max_display_update_time = 0;
void menu_action_setting_edit_bool(const char* pstr, bool* ptr); void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc); void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
void menu_action_setting_edit_accessor_bool(const char* pstr, bool (*pget)(), void (*pset)(bool));
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
void lcd_sdcard_menu(); void lcd_sdcard_menu();
@ -300,15 +297,12 @@ uint16_t max_display_update_time = 0;
#define MENU_ITEM_DUMMY() do { _thisItemNr++; } while(0) #define MENU_ITEM_DUMMY() do { _thisItemNr++; } while(0)
#define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__) #define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
#define MENU_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__) #define MENU_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
#define MENU_ITEM_EDIT_ACCESSOR(type, label, ...) MENU_ITEM(setting_edit_accessor_ ## type, label, PSTR(label), ## __VA_ARGS__)
#if ENABLED(ENCODER_RATE_MULTIPLIER) #if ENABLED(ENCODER_RATE_MULTIPLIER)
#define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__) #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
#define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__) #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
#define MENU_MULTIPLIER_ITEM_EDIT_ACCESSOR(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_accessor_ ## type, label, PSTR(label), ## __VA_ARGS__)
#else //!ENCODER_RATE_MULTIPLIER #else //!ENCODER_RATE_MULTIPLIER
#define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__) #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
#define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__) #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
#define MENU_MULTIPLIER_ITEM_EDIT_ACCESSOR(type, label, ...) MENU_ITEM(setting_edit_accessor_ ## type, label, PSTR(label), ## __VA_ARGS__)
#endif //!ENCODER_RATE_MULTIPLIER #endif //!ENCODER_RATE_MULTIPLIER
/** /**
@ -421,7 +415,7 @@ uint16_t max_display_update_time = 0;
// Value Editing // Value Editing
const char *editLabel; const char *editLabel;
void *editValue, *editSetter; void *editValue;
int32_t minEditValue, maxEditValue; int32_t minEditValue, maxEditValue;
screenFunc_t callbackFunc; screenFunc_t callbackFunc;
@ -2571,7 +2565,7 @@ void kill_screen(const char* lcd_msg) {
MENU_BACK(MSG_CONTROL); MENU_BACK(MSG_CONTROL);
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
MENU_ITEM_EDIT_ACCESSOR(float3, MSG_ADVANCE_K, planner.get_extruder_advance_k, planner.set_extruder_advance_k, 0, 999); MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999);
#endif #endif
MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers); MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
@ -3128,8 +3122,6 @@ void kill_screen(const char* lcd_msg) {
* void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue); * void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
* void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue); * void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
* void menu_action_setting_edit_callback_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue, const screenFunc_t callback); // edit int with callback * void menu_action_setting_edit_callback_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue, const screenFunc_t callback); // edit int with callback
* void _menu_action_setting_edit_accessor_int3(const char * const pstr, int (*pget)(), void (*pset)(int), const int minValue, const int maxValue);
* void menu_action_setting_edit_accessor_int3(const char * const pstr, int (*pget)(), void (*pset)(int), const int minValue, const int maxValue); // edit int via pget and pset accessor functions
* *
* You can then use one of the menu macros to present the edit interface: * You can then use one of the menu macros to present the edit interface:
* MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999) * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
@ -3141,9 +3133,6 @@ void kill_screen(const char* lcd_msg) {
* Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
* *
* menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999) * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
*
* Values that are get/set via functions (As opposed to global variables) can use the accessor form:
* MENU_ITEM_EDIT_ACCESSOR(int3, MSG_SPEED, get_feedrate_percentage, set_feedrate_percentage, 10, 999)
*/ */
#define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \ #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
bool _menu_edit_ ## _name () { \ bool _menu_edit_ ## _name () { \
@ -3156,8 +3145,6 @@ void kill_screen(const char* lcd_msg) {
_type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \ _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
if (editValue != NULL) \ if (editValue != NULL) \
*((_type*)editValue) = value; \ *((_type*)editValue) = value; \
else if (editSetter != NULL) \
((void (*)(_type))editSetter)(value); \
lcd_goto_previous_menu(); \ lcd_goto_previous_menu(); \
} \ } \
return lcd_clicked; \ return lcd_clicked; \
@ -3171,7 +3158,6 @@ void kill_screen(const char* lcd_msg) {
\ \
editLabel = pstr; \ editLabel = pstr; \
editValue = ptr; \ editValue = ptr; \
editSetter = NULL; \
minEditValue = minValue * _scale; \ minEditValue = minValue * _scale; \
maxEditValue = maxValue * _scale - minEditValue; \ maxEditValue = maxValue * _scale - minEditValue; \
encoderPosition = (*ptr) * _scale - minEditValue; \ encoderPosition = (*ptr) * _scale - minEditValue; \
@ -3185,22 +3171,6 @@ void kill_screen(const char* lcd_msg) {
currentScreen = menu_edit_callback_ ## _name; \ currentScreen = menu_edit_callback_ ## _name; \
callbackFunc = callback; \ callbackFunc = callback; \
} \ } \
void _menu_action_setting_edit_accessor_ ## _name (const char * const pstr, _type (*pget)(), void (*pset)(_type), const _type minValue, const _type maxValue) { \
lcd_save_previous_screen(); \
\
lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
\
editLabel = pstr; \
editValue = NULL; \
editSetter = pset; \
minEditValue = minValue * _scale; \
maxEditValue = maxValue * _scale - minEditValue; \
encoderPosition = pget() * _scale - minEditValue; \
} \
void menu_action_setting_edit_accessor_ ## _name (const char * const pstr, _type (*pget)(), void (*pset)(_type), const _type minValue, const _type maxValue) { \
_menu_action_setting_edit_accessor_ ## _name(pstr, pget, pset, minValue, maxValue); \
currentScreen = menu_edit_ ## _name; \
} \
typedef void _name typedef void _name
DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1); DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1);
@ -3305,11 +3275,6 @@ void kill_screen(const char* lcd_msg) {
menu_action_setting_edit_bool(pstr, ptr); menu_action_setting_edit_bool(pstr, ptr);
(*callback)(); (*callback)();
} }
void menu_action_setting_edit_accessor_bool(const char* pstr, bool (*pget)(), void (*pset)(bool)) {
UNUSED(pstr);
pset(!pget());
lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
}
#endif // ULTIPANEL #endif // ULTIPANEL