Browse Source

Update and fix POWER_MONITOR (#18561)

ellensp 4 years ago
parent
commit
12e7106a8a
No account linked to committer's email address

+ 4
- 3
Marlin/src/feature/power_monitor.cpp View File

28
 
28
 
29
 #include "../lcd/ultralcd.h"
29
 #include "../lcd/ultralcd.h"
30
 #include "../lcd/lcdprint.h"
30
 #include "../lcd/lcdprint.h"
31
+#include "../libs/numtostr.h"
31
 
32
 
32
 uint8_t PowerMonitor::flags; // = 0
33
 uint8_t PowerMonitor::flags; // = 0
33
 
34
 
48
   #if ENABLED(POWER_MONITOR_CURRENT)
49
   #if ENABLED(POWER_MONITOR_CURRENT)
49
     void PowerMonitor::draw_current() {
50
     void PowerMonitor::draw_current() {
50
       const float amps = getAmps();
51
       const float amps = getAmps();
51
-      lcd_put_u8str(amps < 100 ? ftostr21ns(amps) : ui16tostr4((uint16_t)amps));
52
+      lcd_put_u8str(amps < 100 ? ftostr31ns(amps) : ui16tostr4rj((uint16_t)amps));
52
       lcd_put_wchar('A');
53
       lcd_put_wchar('A');
53
     }
54
     }
54
   #endif
55
   #endif
56
   #if HAS_POWER_MONITOR_VREF
57
   #if HAS_POWER_MONITOR_VREF
57
     void PowerMonitor::draw_voltage() {
58
     void PowerMonitor::draw_voltage() {
58
       const float volts = getVolts();
59
       const float volts = getVolts();
59
-      lcd_put_u8str(volts < 100 ? ftostr21ns(volts) : ui16tostr4((uint16_t)volts));
60
+      lcd_put_u8str(volts < 100 ? ftostr31ns(volts) : ui16tostr4rj((uint16_t)volts));
60
       lcd_put_wchar('V');
61
       lcd_put_wchar('V');
61
     }
62
     }
62
   #endif
63
   #endif
64
   #if HAS_POWER_MONITOR_WATTS
65
   #if HAS_POWER_MONITOR_WATTS
65
     void PowerMonitor::draw_power() {
66
     void PowerMonitor::draw_power() {
66
       const float power = getPower();
67
       const float power = getPower();
67
-      lcd_put_u8str(power < 100 ? ftostr21ns(power) : ui16tostr4((uint16_t)power));
68
+      lcd_put_u8str(power < 100 ? ftostr31ns(power) : ui16tostr4rj((uint16_t)power));
68
       lcd_put_wchar('W');
69
       lcd_put_wchar('W');
69
     }
70
     }
70
   #endif
71
   #endif

+ 2
- 2
Marlin/src/feature/power_monitor.h View File

100
       static void draw_voltage();
100
       static void draw_voltage();
101
       FORCE_INLINE static bool voltage_display_enabled() { return TEST(flags, PM_DISP_BIT_V); }
101
       FORCE_INLINE static bool voltage_display_enabled() { return TEST(flags, PM_DISP_BIT_V); }
102
       FORCE_INLINE static void set_voltage_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_V, b); }
102
       FORCE_INLINE static void set_voltage_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_V, b); }
103
-      FORCE_INLINE static void toggle_voltage_display() { TBI(flags, PM_DISP_BIT_I); }
103
+      FORCE_INLINE static void toggle_voltage_display() { TBI(flags, PM_DISP_BIT_V); }
104
     #endif
104
     #endif
105
     #if HAS_POWER_MONITOR_WATTS
105
     #if HAS_POWER_MONITOR_WATTS
106
       static void draw_power();
106
       static void draw_power();
107
       FORCE_INLINE static bool power_display_enabled() { return TEST(flags, PM_DISP_BIT_P); }
107
       FORCE_INLINE static bool power_display_enabled() { return TEST(flags, PM_DISP_BIT_P); }
108
       FORCE_INLINE static void set_power_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_P, b); }
108
       FORCE_INLINE static void set_power_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_P, b); }
109
-      FORCE_INLINE static void toggle_power_display() { TBI(flags, PM_DISP_BIT_I); }
109
+      FORCE_INLINE static void toggle_power_display() { TBI(flags, PM_DISP_BIT_P); }
110
     #endif
110
     #endif
111
   #endif
111
   #endif
112
 
112
 

+ 1
- 1
Marlin/src/gcode/feature/power_monitor/M430.cpp View File

25
 #if HAS_POWER_MONITOR
25
 #if HAS_POWER_MONITOR
26
 
26
 
27
 #include "../../../feature/power_monitor.h"
27
 #include "../../../feature/power_monitor.h"
28
-#include "../../../Marlin.h"
28
+#include "../../../MarlinCore.h"
29
 #include "../../gcode.h"
29
 #include "../../gcode.h"
30
 
30
 
31
 /**
31
 /**

+ 1
- 1
Marlin/src/inc/Conditionals_adv.h View File

356
 #if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
356
 #if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
357
   #define HAS_POWER_MONITOR 1
357
   #define HAS_POWER_MONITOR 1
358
 #endif
358
 #endif
359
-#if ENABLED(POWER_MONITOR_VOLTAGE) || defined(POWER_MONITOR_FIXED_VOLTAGE)
359
+#if ENABLED(POWER_MONITOR_VOLTAGE) && defined(POWER_MONITOR_FIXED_VOLTAGE)
360
   #define HAS_POWER_MONITOR_VREF 1
360
   #define HAS_POWER_MONITOR_VREF 1
361
 #endif
361
 #endif
362
 #if BOTH(HAS_POWER_MONITOR_VREF, POWER_MONITOR_CURRENT)
362
 #if BOTH(HAS_POWER_MONITOR_VREF, POWER_MONITOR_CURRENT)

+ 10
- 6
Marlin/src/lcd/dogm/status_screen_DOGM.cpp View File

113
 
113
 
114
     lcd_moveto(x, y);
114
     lcd_moveto(x, y);
115
 
115
 
116
+    #if HAS_POWER_MONITOR_WATTS
117
+      const bool wflag = power_monitor.power_display_enabled();
118
+    #endif
116
     #if ENABLED(POWER_MONITOR_CURRENT)
119
     #if ENABLED(POWER_MONITOR_CURRENT)
117
       const bool iflag = power_monitor.current_display_enabled();
120
       const bool iflag = power_monitor.current_display_enabled();
118
     #endif
121
     #endif
119
     #if HAS_POWER_MONITOR_VREF
122
     #if HAS_POWER_MONITOR_VREF
120
       const bool vflag = power_monitor.voltage_display_enabled();
123
       const bool vflag = power_monitor.voltage_display_enabled();
121
     #endif
124
     #endif
122
-    #if HAS_POWER_MONITOR_WATTS
123
-      const bool wflag = power_monitor.power_display_enabled();
124
-    #endif
125
 
125
 
126
-    #if ENABLED(POWER_MONITOR_CURRENT) || HAS_POWER_MONITOR_VREF
127
-      // cycle between current, voltage, and power
126
+    #if HAS_POWER_MONITOR_WATTS
127
+      // Cycle between current, voltage, and power
128
       if (ELAPSED(millis(), power_monitor.display_item_ms)) {
128
       if (ELAPSED(millis(), power_monitor.display_item_ms)) {
129
         power_monitor.display_item_ms = millis() + 1000UL;
129
         power_monitor.display_item_ms = millis() + 1000UL;
130
         ++power_monitor.display_item;
130
         ++power_monitor.display_item;
131
       }
131
       }
132
+    #elif ENABLED(POWER_MONITOR_CURRENT)
133
+      power_monitor.display_item = 0;
134
+    #elif HAS_POWER_MONITOR_VREF
135
+      power_monitor.display_item = 1;
132
     #endif
136
     #endif
133
 
137
 
134
     // ensure we have the right one selected for display
138
     // ensure we have the right one selected for display
139
       #if HAS_POWER_MONITOR_VREF
143
       #if HAS_POWER_MONITOR_VREF
140
         if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item;
144
         if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item;
141
       #endif
145
       #endif
142
-      #if ENABLED(POWER_MONITOR_CURRENT)
146
+      #if HAS_POWER_MONITOR_WATTS
143
         if (power_monitor.display_item == 2 && !wflag) ++power_monitor.display_item;
147
         if (power_monitor.display_item == 2 && !wflag) ++power_monitor.display_item;
144
       #endif
148
       #endif
145
       if (power_monitor.display_item >= 3) power_monitor.display_item = 0;
149
       if (power_monitor.display_item >= 3) power_monitor.display_item = 0;

+ 4
- 4
Marlin/src/lcd/menu/menu_power_monitor.cpp View File

33
 
33
 
34
 void menu_power_monitor() {
34
 void menu_power_monitor() {
35
   START_MENU();
35
   START_MENU();
36
-  MENU_BACK(MSG_MAIN);
36
+  BACK_ITEM(MSG_MAIN);
37
 
37
 
38
   #if ENABLED(POWER_MONITOR_CURRENT)
38
   #if ENABLED(POWER_MONITOR_CURRENT)
39
   {
39
   {
40
     bool ena = power_monitor.current_display_enabled();
40
     bool ena = power_monitor.current_display_enabled();
41
-    MENU_ITEM_EDIT_CALLBACK(bool, MSG_CURRENT, &ena, power_monitor.toggle_current_display);
41
+    EDIT_ITEM(bool, MSG_CURRENT, &ena, power_monitor.toggle_current_display);
42
   }
42
   }
43
   #endif
43
   #endif
44
 
44
 
45
   #if HAS_POWER_MONITOR_VREF
45
   #if HAS_POWER_MONITOR_VREF
46
   {
46
   {
47
     bool ena = power_monitor.voltage_display_enabled();
47
     bool ena = power_monitor.voltage_display_enabled();
48
-    MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLTAGE, &ena, power_monitor.toggle_voltage_display);
48
+    EDIT_ITEM(bool, MSG_VOLTAGE, &ena, power_monitor.toggle_voltage_display);
49
   }
49
   }
50
   #endif
50
   #endif
51
 
51
 
52
   #if HAS_POWER_MONITOR_WATTS
52
   #if HAS_POWER_MONITOR_WATTS
53
   {
53
   {
54
     bool ena = power_monitor.power_display_enabled();
54
     bool ena = power_monitor.power_display_enabled();
55
-    MENU_ITEM_EDIT_CALLBACK(bool, MSG_POWER, &ena, power_monitor.toggle_power_display);
55
+    EDIT_ITEM(bool, MSG_POWER, &ena, power_monitor.toggle_power_display);
56
   }
56
   }
57
   #endif
57
   #endif
58
 
58
 

+ 1
- 1
Marlin/src/module/configuration_store.cpp View File

94
   #include "../feature/powerloss.h"
94
   #include "../feature/powerloss.h"
95
 #endif
95
 #endif
96
 
96
 
97
-#if ENABLED(POWER_MONITOR)
97
+#if HAS_POWER_MONITOR
98
   #include "../feature/power_monitor.h"
98
   #include "../feature/power_monitor.h"
99
 #endif
99
 #endif
100
 
100
 

+ 5
- 2
buildroot/tests/mega1280-tests View File

18
 restore_configs
18
 restore_configs
19
 opt_set LCD_LANGUAGE an
19
 opt_set LCD_LANGUAGE an
20
 opt_enable SPINDLE_FEATURE ULTIMAKERCONTROLLER LCD_BED_LEVELING \
20
 opt_enable SPINDLE_FEATURE ULTIMAKERCONTROLLER LCD_BED_LEVELING \
21
+           EEPROM_SETTINGS EEPROM_BOOT_SILENT EEPROM_AUTO_INIT \
21
            SENSORLESS_BACKOFF_MM HOMING_BACKOFF_POST_MM HOME_Y_BEFORE_X CODEPENDENT_XY_HOMING \
22
            SENSORLESS_BACKOFF_MM HOMING_BACKOFF_POST_MM HOME_Y_BEFORE_X CODEPENDENT_XY_HOMING \
22
            MESH_BED_LEVELING ENABLE_LEVELING_FADE_HEIGHT MESH_G28_REST_ORIGIN \
23
            MESH_BED_LEVELING ENABLE_LEVELING_FADE_HEIGHT MESH_G28_REST_ORIGIN \
23
            G26_MESH_VALIDATION MESH_EDIT_MENU GCODE_QUOTED_STRINGS \
24
            G26_MESH_VALIDATION MESH_EDIT_MENU GCODE_QUOTED_STRINGS \
24
-           EXTERNAL_CLOSED_LOOP_CONTROLLER
25
+           EXTERNAL_CLOSED_LOOP_CONTROLLER POWER_MONITOR_CURRENT POWER_MONITOR_VOLTAGE
26
+opt_set POWER_MONITOR_CURRENT_PIN 14
27
+opt_set POWER_MONITOR_VOLTAGE_PIN 15
25
 opt_set CLOSED_LOOP_ENABLE_PIN 44
28
 opt_set CLOSED_LOOP_ENABLE_PIN 44
26
 opt_set CLOSED_LOOP_MOVE_COMPLETE_PIN 45
29
 opt_set CLOSED_LOOP_MOVE_COMPLETE_PIN 45
27
-exec_test $1 $2 "Spindle, MESH_BED_LEVELING, closed loop, and LCD"
30
+exec_test $1 $2 "Spindle, MESH_BED_LEVELING, closed loop, Power Monitor, and LCD"
28
 
31
 
29
 #
32
 #
30
 # Test DUAL_X_CARRIAGE
33
 # Test DUAL_X_CARRIAGE

Loading…
Cancel
Save