Selaa lähdekoodia

Correct range of LCD axis step editing (#13727)

Marcio Teixeira 6 vuotta sitten
vanhempi
commit
866e2d41dc

+ 7
- 7
Marlin/src/core/utility.cpp Näytä tiedosto

@@ -264,15 +264,15 @@ void safe_delay(millis_t ms) {
264 264
     return conv;
265 265
   }
266 266
 
267
-  // Convert unsigned float to string with 1234.56 format omitting trailing zeros
268
-  char* ftostr62rj(const float &f) {
269
-    const long i = ((f < 0 ? -f : f) * 1000 + 5) / 10;
270
-    conv[0] = RJDIGIT(i, 100000);
267
+  // Convert unsigned float to string with 1234.5 format omitting trailing zeros
268
+  char* ftostr51rj(const float &f) {
269
+    const long i = ((f < 0 ? -f : f) * 100 + 5) / 10;
270
+    conv[0] = ' ';
271 271
     conv[1] = RJDIGIT(i, 10000);
272 272
     conv[2] = RJDIGIT(i, 1000);
273
-    conv[3] = DIGIMOD(i, 100);
274
-    conv[4] = '.';
275
-    conv[5] = DIGIMOD(i, 10);
273
+    conv[3] = RJDIGIT(i, 100);
274
+    conv[4] = DIGIMOD(i, 10);
275
+    conv[5] = '.';
276 276
     conv[6] = DIGIMOD(i, 1);
277 277
     return conv;
278 278
   }

+ 2
- 2
Marlin/src/core/utility.h Näytä tiedosto

@@ -106,8 +106,8 @@ inline void serial_delay(const millis_t ms) {
106 106
   // Convert signed float to string with +123.45 format
107 107
   char* ftostr52sign(const float &x);
108 108
 
109
-  // Convert unsigned float to string with 1234.56 format omitting trailing zeros
110
-  char* ftostr62rj(const float &x);
109
+  // Convert unsigned float to string with 1234.5 format omitting trailing zeros
110
+  char* ftostr51rj(const float &x);
111 111
 
112 112
   // Convert float to rj string with 123 or -12 format
113 113
   FORCE_INLINE char* ftostr3(const float &x) { return i16tostr3(int16_t(x + (x < 0 ? -0.5f : 0.5f))); }

+ 2
- 2
Marlin/src/lcd/menu/menu.cpp Näytä tiedosto

@@ -167,9 +167,9 @@ DEFINE_MENU_EDIT_ITEM(float3);      // 123        right-justified
167 167
 DEFINE_MENU_EDIT_ITEM(float52);     // 123.45
168 168
 DEFINE_MENU_EDIT_ITEM(float43);     // 1.234
169 169
 DEFINE_MENU_EDIT_ITEM(float5);      // 12345      right-justified
170
-DEFINE_MENU_EDIT_ITEM(float51);     // +1234.5
170
+DEFINE_MENU_EDIT_ITEM(float51);     // 1234.5     right-justified
171
+DEFINE_MENU_EDIT_ITEM(float51sign); // +1234.5
171 172
 DEFINE_MENU_EDIT_ITEM(float52sign); // +123.45
172
-DEFINE_MENU_EDIT_ITEM(float62);     // 1234.56    right-justified
173 173
 DEFINE_MENU_EDIT_ITEM(long5);       // 12345      right-justified
174 174
 
175 175
 void MenuItem_bool::action_edit(PGM_P pstr, bool *ptr, screenFunc_t callback) {

+ 11
- 7
Marlin/src/lcd/menu/menu.h Näytä tiedosto

@@ -24,6 +24,8 @@
24 24
 #include "../ultralcd.h"
25 25
 #include "../../inc/MarlinConfig.h"
26 26
 
27
+#include "limits.h"
28
+
27 29
 extern int8_t encoderLine, encoderTopLine, screen_items;
28 30
 extern bool screen_changed;
29 31
 
@@ -54,9 +56,9 @@ DECLARE_MENU_EDIT_TYPE(float,    float3,      ftostr3,         1     );   // 123
54 56
 DECLARE_MENU_EDIT_TYPE(float,    float52,     ftostr52,      100     );   // 123.45
55 57
 DECLARE_MENU_EDIT_TYPE(float,    float43,     ftostr43sign, 1000     );   // 1.234
56 58
 DECLARE_MENU_EDIT_TYPE(float,    float5,      ftostr5rj,       0.01f );   // 12345      right-justified
57
-DECLARE_MENU_EDIT_TYPE(float,    float51,     ftostr51sign,   10     );   // +1234.5
59
+DECLARE_MENU_EDIT_TYPE(float,    float51,     ftostr51rj,     10     );   // 1234.5     right-justified
60
+DECLARE_MENU_EDIT_TYPE(float,    float51sign, ftostr51sign,   10     );   // +1234.5
58 61
 DECLARE_MENU_EDIT_TYPE(float,    float52sign, ftostr52sign,  100     );   // +123.45
59
-DECLARE_MENU_EDIT_TYPE(float,    float62,     ftostr62rj,    100     );   // 1234.56    right-justified
60 62
 DECLARE_MENU_EDIT_TYPE(uint32_t, long5,       ftostr5rj,       0.01f );   // 12345      right-justified
61 63
 
62 64
 ////////////////////////////////////////////
@@ -119,9 +121,9 @@ DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float3);           // 123        right-justif
119 121
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float52);          // 123.45
120 122
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float43);          // 1.234
121 123
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float5);           // 12345      right-justified
122
-DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float51);          // +1234.5
124
+DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float51);          // 1234.5     right-justified
125
+DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float51sign);      // +1234.5
123 126
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float52sign);      // +123.45
124
-DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float62);          // 1234.56    right-justified
125 127
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(long5);            // 12345      right-justified
126 128
 
127 129
 #define draw_menu_item_edit_bool(sel, row, pstr, pstr2, data, ...)           DRAW_BOOL_SETTING(sel, row, pstr, data)
@@ -179,8 +181,10 @@ class TMenuItem : MenuItemBase {
179 181
     static char* to_string(const int16_t value)       { return NAME::strfunc(unscale(value)); }
180 182
   public:
181 183
     static void action_edit(PGM_P const pstr, type_t * const ptr, const type_t minValue, const type_t maxValue, const screenFunc_t callback=NULL, const bool live=false) {
182
-      const int16_t minv = scale(minValue);
183
-      init(pstr, ptr, minv, int16_t(scale(maxValue)) - minv, int16_t(scale(*ptr)) - minv, edit, callback, live);
184
+      // Make sure minv and maxv fit within int16_t
185
+      const int16_t minv = MAX(scale(minValue), INT_MIN),
186
+                    maxv = MIN(scale(maxValue), INT_MAX);
187
+      init(pstr, ptr, minv, maxv - minv, scale(*ptr) - minv, edit, callback, live);
184 188
     }
185 189
     static void edit() { MenuItemBase::edit(to_string, load); }
186 190
 };
@@ -199,8 +203,8 @@ DECLARE_MENU_EDIT_ITEM(float52);
199 203
 DECLARE_MENU_EDIT_ITEM(float43);
200 204
 DECLARE_MENU_EDIT_ITEM(float5);
201 205
 DECLARE_MENU_EDIT_ITEM(float51);
206
+DECLARE_MENU_EDIT_ITEM(float51sign);
202 207
 DECLARE_MENU_EDIT_ITEM(float52sign);
203
-DECLARE_MENU_EDIT_ITEM(float62);
204 208
 DECLARE_MENU_EDIT_ITEM(long5);
205 209
 
206 210
 class MenuItem_bool {

+ 4
- 4
Marlin/src/lcd/menu/menu_advanced.cpp Näytä tiedosto

@@ -571,14 +571,14 @@ void menu_backlash();
571 571
     START_MENU();
572 572
     MENU_BACK(MSG_ADVANCED_SETTINGS);
573 573
 
574
-    #define EDIT_QSTEPS(Q) MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_##Q##STEPS, &planner.settings.axis_steps_per_mm[_AXIS(Q)], 5, 9999, _planner_refresh_positioning)
574
+    #define EDIT_QSTEPS(Q) MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float51, MSG_##Q##STEPS, &planner.settings.axis_steps_per_mm[_AXIS(Q)], 5, 9999, _planner_refresh_positioning)
575 575
     EDIT_QSTEPS(A);
576 576
     EDIT_QSTEPS(B);
577 577
     EDIT_QSTEPS(C);
578 578
 
579 579
     #if ENABLED(DISTINCT_E_FACTORS)
580
-      #define EDIT_ESTEPS(N,E) MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E##N##STEPS, &planner.settings.axis_steps_per_mm[E_AXIS_N(E)], 5, 9999, _planner_refresh_e##E##_positioning)
581
-      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.settings.axis_steps_per_mm[E_AXIS_N(active_extruder)], 5, 9999, _planner_refresh_positioning);
580
+      #define EDIT_ESTEPS(N,E) MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float51, MSG_E##N##STEPS, &planner.settings.axis_steps_per_mm[E_AXIS_N(E)], 5, 9999, _planner_refresh_e##E##_positioning)
581
+      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float51, MSG_ESTEPS, &planner.settings.axis_steps_per_mm[E_AXIS_N(active_extruder)], 5, 9999, _planner_refresh_positioning);
582 582
       EDIT_ESTEPS(1,0);
583 583
       EDIT_ESTEPS(2,1);
584 584
       #if E_STEPPERS > 2
@@ -594,7 +594,7 @@ void menu_backlash();
594 594
         #endif // E_STEPPERS > 3
595 595
       #endif // E_STEPPERS > 2
596 596
     #elif E_STEPPERS
597
-      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.settings.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
597
+      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float51, MSG_ESTEPS, &planner.settings.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
598 598
     #endif
599 599
 
600 600
     END_MENU();

Loading…
Peruuta
Tallenna