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,6 +28,7 @@
28 28
 
29 29
 #include "../lcd/ultralcd.h"
30 30
 #include "../lcd/lcdprint.h"
31
+#include "../libs/numtostr.h"
31 32
 
32 33
 uint8_t PowerMonitor::flags; // = 0
33 34
 
@@ -48,7 +49,7 @@ PowerMonitor power_monitor; // Single instance - this calls the constructor
48 49
   #if ENABLED(POWER_MONITOR_CURRENT)
49 50
     void PowerMonitor::draw_current() {
50 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 53
       lcd_put_wchar('A');
53 54
     }
54 55
   #endif
@@ -56,7 +57,7 @@ PowerMonitor power_monitor; // Single instance - this calls the constructor
56 57
   #if HAS_POWER_MONITOR_VREF
57 58
     void PowerMonitor::draw_voltage() {
58 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 61
       lcd_put_wchar('V');
61 62
     }
62 63
   #endif
@@ -64,7 +65,7 @@ PowerMonitor power_monitor; // Single instance - this calls the constructor
64 65
   #if HAS_POWER_MONITOR_WATTS
65 66
     void PowerMonitor::draw_power() {
66 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 69
       lcd_put_wchar('W');
69 70
     }
70 71
   #endif

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

@@ -100,13 +100,13 @@ public:
100 100
       static void draw_voltage();
101 101
       FORCE_INLINE static bool voltage_display_enabled() { return TEST(flags, PM_DISP_BIT_V); }
102 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 104
     #endif
105 105
     #if HAS_POWER_MONITOR_WATTS
106 106
       static void draw_power();
107 107
       FORCE_INLINE static bool power_display_enabled() { return TEST(flags, PM_DISP_BIT_P); }
108 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 110
     #endif
111 111
   #endif
112 112
 

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

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

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

@@ -356,7 +356,7 @@
356 356
 #if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
357 357
   #define HAS_POWER_MONITOR 1
358 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 360
   #define HAS_POWER_MONITOR_VREF 1
361 361
 #endif
362 362
 #if BOTH(HAS_POWER_MONITOR_VREF, POWER_MONITOR_CURRENT)

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

@@ -113,22 +113,26 @@
113 113
 
114 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 119
     #if ENABLED(POWER_MONITOR_CURRENT)
117 120
       const bool iflag = power_monitor.current_display_enabled();
118 121
     #endif
119 122
     #if HAS_POWER_MONITOR_VREF
120 123
       const bool vflag = power_monitor.voltage_display_enabled();
121 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 128
       if (ELAPSED(millis(), power_monitor.display_item_ms)) {
129 129
         power_monitor.display_item_ms = millis() + 1000UL;
130 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 136
     #endif
133 137
 
134 138
     // ensure we have the right one selected for display
@@ -139,7 +143,7 @@
139 143
       #if HAS_POWER_MONITOR_VREF
140 144
         if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item;
141 145
       #endif
142
-      #if ENABLED(POWER_MONITOR_CURRENT)
146
+      #if HAS_POWER_MONITOR_WATTS
143 147
         if (power_monitor.display_item == 2 && !wflag) ++power_monitor.display_item;
144 148
       #endif
145 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,26 +33,26 @@
33 33
 
34 34
 void menu_power_monitor() {
35 35
   START_MENU();
36
-  MENU_BACK(MSG_MAIN);
36
+  BACK_ITEM(MSG_MAIN);
37 37
 
38 38
   #if ENABLED(POWER_MONITOR_CURRENT)
39 39
   {
40 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 43
   #endif
44 44
 
45 45
   #if HAS_POWER_MONITOR_VREF
46 46
   {
47 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 50
   #endif
51 51
 
52 52
   #if HAS_POWER_MONITOR_WATTS
53 53
   {
54 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 57
   #endif
58 58
 

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

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

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

@@ -18,13 +18,16 @@ set -e
18 18
 restore_configs
19 19
 opt_set LCD_LANGUAGE an
20 20
 opt_enable SPINDLE_FEATURE ULTIMAKERCONTROLLER LCD_BED_LEVELING \
21
+           EEPROM_SETTINGS EEPROM_BOOT_SILENT EEPROM_AUTO_INIT \
21 22
            SENSORLESS_BACKOFF_MM HOMING_BACKOFF_POST_MM HOME_Y_BEFORE_X CODEPENDENT_XY_HOMING \
22 23
            MESH_BED_LEVELING ENABLE_LEVELING_FADE_HEIGHT MESH_G28_REST_ORIGIN \
23 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 28
 opt_set CLOSED_LOOP_ENABLE_PIN 44
26 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 33
 # Test DUAL_X_CARRIAGE

Loading…
Cancel
Save