Update and fix POWER_MONITOR (#18561)

This commit is contained in:
ellensp 2020-07-07 11:53:26 +12:00 committed by GitHub
parent ea8c3a9388
commit 12e7106a8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 20 deletions

View file

@ -28,6 +28,7 @@
#include "../lcd/ultralcd.h" #include "../lcd/ultralcd.h"
#include "../lcd/lcdprint.h" #include "../lcd/lcdprint.h"
#include "../libs/numtostr.h"
uint8_t PowerMonitor::flags; // = 0 uint8_t PowerMonitor::flags; // = 0
@ -48,7 +49,7 @@ PowerMonitor power_monitor; // Single instance - this calls the constructor
#if ENABLED(POWER_MONITOR_CURRENT) #if ENABLED(POWER_MONITOR_CURRENT)
void PowerMonitor::draw_current() { void PowerMonitor::draw_current() {
const float amps = getAmps(); const float amps = getAmps();
lcd_put_u8str(amps < 100 ? ftostr21ns(amps) : ui16tostr4((uint16_t)amps)); lcd_put_u8str(amps < 100 ? ftostr31ns(amps) : ui16tostr4rj((uint16_t)amps));
lcd_put_wchar('A'); lcd_put_wchar('A');
} }
#endif #endif
@ -56,7 +57,7 @@ PowerMonitor power_monitor; // Single instance - this calls the constructor
#if HAS_POWER_MONITOR_VREF #if HAS_POWER_MONITOR_VREF
void PowerMonitor::draw_voltage() { void PowerMonitor::draw_voltage() {
const float volts = getVolts(); const float volts = getVolts();
lcd_put_u8str(volts < 100 ? ftostr21ns(volts) : ui16tostr4((uint16_t)volts)); lcd_put_u8str(volts < 100 ? ftostr31ns(volts) : ui16tostr4rj((uint16_t)volts));
lcd_put_wchar('V'); lcd_put_wchar('V');
} }
#endif #endif
@ -64,7 +65,7 @@ PowerMonitor power_monitor; // Single instance - this calls the constructor
#if HAS_POWER_MONITOR_WATTS #if HAS_POWER_MONITOR_WATTS
void PowerMonitor::draw_power() { void PowerMonitor::draw_power() {
const float power = getPower(); const float power = getPower();
lcd_put_u8str(power < 100 ? ftostr21ns(power) : ui16tostr4((uint16_t)power)); lcd_put_u8str(power < 100 ? ftostr31ns(power) : ui16tostr4rj((uint16_t)power));
lcd_put_wchar('W'); lcd_put_wchar('W');
} }
#endif #endif

View file

@ -100,13 +100,13 @@ public:
static void draw_voltage(); static void draw_voltage();
FORCE_INLINE static bool voltage_display_enabled() { return TEST(flags, PM_DISP_BIT_V); } FORCE_INLINE static bool voltage_display_enabled() { return TEST(flags, PM_DISP_BIT_V); }
FORCE_INLINE static void set_voltage_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_V, b); } FORCE_INLINE static void set_voltage_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_V, b); }
FORCE_INLINE static void toggle_voltage_display() { TBI(flags, PM_DISP_BIT_I); } FORCE_INLINE static void toggle_voltage_display() { TBI(flags, PM_DISP_BIT_V); }
#endif #endif
#if HAS_POWER_MONITOR_WATTS #if HAS_POWER_MONITOR_WATTS
static void draw_power(); static void draw_power();
FORCE_INLINE static bool power_display_enabled() { return TEST(flags, PM_DISP_BIT_P); } FORCE_INLINE static bool power_display_enabled() { return TEST(flags, PM_DISP_BIT_P); }
FORCE_INLINE static void set_power_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_P, b); } FORCE_INLINE static void set_power_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_P, b); }
FORCE_INLINE static void toggle_power_display() { TBI(flags, PM_DISP_BIT_I); } FORCE_INLINE static void toggle_power_display() { TBI(flags, PM_DISP_BIT_P); }
#endif #endif
#endif #endif

View file

@ -25,7 +25,7 @@
#if HAS_POWER_MONITOR #if HAS_POWER_MONITOR
#include "../../../feature/power_monitor.h" #include "../../../feature/power_monitor.h"
#include "../../../Marlin.h" #include "../../../MarlinCore.h"
#include "../../gcode.h" #include "../../gcode.h"
/** /**

View file

@ -356,7 +356,7 @@
#if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE) #if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
#define HAS_POWER_MONITOR 1 #define HAS_POWER_MONITOR 1
#endif #endif
#if ENABLED(POWER_MONITOR_VOLTAGE) || defined(POWER_MONITOR_FIXED_VOLTAGE) #if ENABLED(POWER_MONITOR_VOLTAGE) && defined(POWER_MONITOR_FIXED_VOLTAGE)
#define HAS_POWER_MONITOR_VREF 1 #define HAS_POWER_MONITOR_VREF 1
#endif #endif
#if BOTH(HAS_POWER_MONITOR_VREF, POWER_MONITOR_CURRENT) #if BOTH(HAS_POWER_MONITOR_VREF, POWER_MONITOR_CURRENT)

View file

@ -113,22 +113,26 @@
lcd_moveto(x, y); lcd_moveto(x, y);
#if HAS_POWER_MONITOR_WATTS
const bool wflag = power_monitor.power_display_enabled();
#endif
#if ENABLED(POWER_MONITOR_CURRENT) #if ENABLED(POWER_MONITOR_CURRENT)
const bool iflag = power_monitor.current_display_enabled(); const bool iflag = power_monitor.current_display_enabled();
#endif #endif
#if HAS_POWER_MONITOR_VREF #if HAS_POWER_MONITOR_VREF
const bool vflag = power_monitor.voltage_display_enabled(); const bool vflag = power_monitor.voltage_display_enabled();
#endif #endif
#if HAS_POWER_MONITOR_WATTS
const bool wflag = power_monitor.power_display_enabled();
#endif
#if ENABLED(POWER_MONITOR_CURRENT) || HAS_POWER_MONITOR_VREF #if HAS_POWER_MONITOR_WATTS
// cycle between current, voltage, and power // Cycle between current, voltage, and power
if (ELAPSED(millis(), power_monitor.display_item_ms)) { if (ELAPSED(millis(), power_monitor.display_item_ms)) {
power_monitor.display_item_ms = millis() + 1000UL; power_monitor.display_item_ms = millis() + 1000UL;
++power_monitor.display_item; ++power_monitor.display_item;
} }
#elif ENABLED(POWER_MONITOR_CURRENT)
power_monitor.display_item = 0;
#elif HAS_POWER_MONITOR_VREF
power_monitor.display_item = 1;
#endif #endif
// ensure we have the right one selected for display // ensure we have the right one selected for display
@ -139,7 +143,7 @@
#if HAS_POWER_MONITOR_VREF #if HAS_POWER_MONITOR_VREF
if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item; if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item;
#endif #endif
#if ENABLED(POWER_MONITOR_CURRENT) #if HAS_POWER_MONITOR_WATTS
if (power_monitor.display_item == 2 && !wflag) ++power_monitor.display_item; if (power_monitor.display_item == 2 && !wflag) ++power_monitor.display_item;
#endif #endif
if (power_monitor.display_item >= 3) power_monitor.display_item = 0; if (power_monitor.display_item >= 3) power_monitor.display_item = 0;

View file

@ -33,26 +33,26 @@
void menu_power_monitor() { void menu_power_monitor() {
START_MENU(); START_MENU();
MENU_BACK(MSG_MAIN); BACK_ITEM(MSG_MAIN);
#if ENABLED(POWER_MONITOR_CURRENT) #if ENABLED(POWER_MONITOR_CURRENT)
{ {
bool ena = power_monitor.current_display_enabled(); bool ena = power_monitor.current_display_enabled();
MENU_ITEM_EDIT_CALLBACK(bool, MSG_CURRENT, &ena, power_monitor.toggle_current_display); EDIT_ITEM(bool, MSG_CURRENT, &ena, power_monitor.toggle_current_display);
} }
#endif #endif
#if HAS_POWER_MONITOR_VREF #if HAS_POWER_MONITOR_VREF
{ {
bool ena = power_monitor.voltage_display_enabled(); bool ena = power_monitor.voltage_display_enabled();
MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLTAGE, &ena, power_monitor.toggle_voltage_display); EDIT_ITEM(bool, MSG_VOLTAGE, &ena, power_monitor.toggle_voltage_display);
} }
#endif #endif
#if HAS_POWER_MONITOR_WATTS #if HAS_POWER_MONITOR_WATTS
{ {
bool ena = power_monitor.power_display_enabled(); bool ena = power_monitor.power_display_enabled();
MENU_ITEM_EDIT_CALLBACK(bool, MSG_POWER, &ena, power_monitor.toggle_power_display); EDIT_ITEM(bool, MSG_POWER, &ena, power_monitor.toggle_power_display);
} }
#endif #endif

View file

@ -94,7 +94,7 @@
#include "../feature/powerloss.h" #include "../feature/powerloss.h"
#endif #endif
#if ENABLED(POWER_MONITOR) #if HAS_POWER_MONITOR
#include "../feature/power_monitor.h" #include "../feature/power_monitor.h"
#endif #endif

View file

@ -18,13 +18,16 @@ set -e
restore_configs restore_configs
opt_set LCD_LANGUAGE an opt_set LCD_LANGUAGE an
opt_enable SPINDLE_FEATURE ULTIMAKERCONTROLLER LCD_BED_LEVELING \ opt_enable SPINDLE_FEATURE ULTIMAKERCONTROLLER LCD_BED_LEVELING \
EEPROM_SETTINGS EEPROM_BOOT_SILENT EEPROM_AUTO_INIT \
SENSORLESS_BACKOFF_MM HOMING_BACKOFF_POST_MM HOME_Y_BEFORE_X CODEPENDENT_XY_HOMING \ SENSORLESS_BACKOFF_MM HOMING_BACKOFF_POST_MM HOME_Y_BEFORE_X CODEPENDENT_XY_HOMING \
MESH_BED_LEVELING ENABLE_LEVELING_FADE_HEIGHT MESH_G28_REST_ORIGIN \ MESH_BED_LEVELING ENABLE_LEVELING_FADE_HEIGHT MESH_G28_REST_ORIGIN \
G26_MESH_VALIDATION MESH_EDIT_MENU GCODE_QUOTED_STRINGS \ G26_MESH_VALIDATION MESH_EDIT_MENU GCODE_QUOTED_STRINGS \
EXTERNAL_CLOSED_LOOP_CONTROLLER EXTERNAL_CLOSED_LOOP_CONTROLLER POWER_MONITOR_CURRENT POWER_MONITOR_VOLTAGE
opt_set POWER_MONITOR_CURRENT_PIN 14
opt_set POWER_MONITOR_VOLTAGE_PIN 15
opt_set CLOSED_LOOP_ENABLE_PIN 44 opt_set CLOSED_LOOP_ENABLE_PIN 44
opt_set CLOSED_LOOP_MOVE_COMPLETE_PIN 45 opt_set CLOSED_LOOP_MOVE_COMPLETE_PIN 45
exec_test $1 $2 "Spindle, MESH_BED_LEVELING, closed loop, and LCD" exec_test $1 $2 "Spindle, MESH_BED_LEVELING, closed loop, Power Monitor, and LCD"
# #
# Test DUAL_X_CARRIAGE # Test DUAL_X_CARRIAGE