Skip to content

Commit

Permalink
Update and fix POWER_MONITOR (MarlinFirmware#18561)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellensp authored and Alexander Yasnogor committed Aug 7, 2020
1 parent cc69165 commit 9d25223
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 20 deletions.
7 changes: 4 additions & 3 deletions Marlin/src/feature/power_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "../lcd/ultralcd.h"
#include "../lcd/lcdprint.h"
#include "../libs/numtostr.h"

uint8_t PowerMonitor::flags; // = 0

Expand All @@ -48,23 +49,23 @@ PowerMonitor power_monitor; // Single instance - this calls the constructor
#if ENABLED(POWER_MONITOR_CURRENT)
void PowerMonitor::draw_current() {
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');
}
#endif

#if HAS_POWER_MONITOR_VREF
void PowerMonitor::draw_voltage() {
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');
}
#endif

#if HAS_POWER_MONITOR_WATTS
void PowerMonitor::draw_power() {
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');
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/power_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ class PowerMonitor {
static void draw_voltage();
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 toggle_voltage_display() { TBI(flags, PM_DISP_BIT_I); }
FORCE_INLINE static void toggle_voltage_display() { TBI(flags, PM_DISP_BIT_V); }
#endif
#if HAS_POWER_MONITOR_WATTS
static void draw_power();
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 toggle_power_display() { TBI(flags, PM_DISP_BIT_I); }
FORCE_INLINE static void toggle_power_display() { TBI(flags, PM_DISP_BIT_P); }
#endif
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/feature/power_monitor/M430.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#if HAS_POWER_MONITOR

#include "../../../feature/power_monitor.h"
#include "../../../Marlin.h"
#include "../../../MarlinCore.h"
#include "../../gcode.h"

/**
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
#if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
#define HAS_POWER_MONITOR 1
#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
#endif
#if BOTH(HAS_POWER_MONITOR_VREF, POWER_MONITOR_CURRENT)
Expand Down
16 changes: 10 additions & 6 deletions Marlin/src/lcd/dogm/status_screen_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,26 @@

lcd_moveto(x, y);

#if HAS_POWER_MONITOR_WATTS
const bool wflag = power_monitor.power_display_enabled();
#endif
#if ENABLED(POWER_MONITOR_CURRENT)
const bool iflag = power_monitor.current_display_enabled();
#endif
#if HAS_POWER_MONITOR_VREF
const bool vflag = power_monitor.voltage_display_enabled();
#endif
#if HAS_POWER_MONITOR_WATTS
const bool wflag = power_monitor.power_display_enabled();
#endif

#if ENABLED(POWER_MONITOR_CURRENT) || HAS_POWER_MONITOR_VREF
// cycle between current, voltage, and power
#if HAS_POWER_MONITOR_WATTS
// Cycle between current, voltage, and power
if (ELAPSED(millis(), power_monitor.display_item_ms)) {
power_monitor.display_item_ms = millis() + 1000UL;
++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

// ensure we have the right one selected for display
Expand All @@ -139,7 +143,7 @@
#if HAS_POWER_MONITOR_VREF
if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item;
#endif
#if ENABLED(POWER_MONITOR_CURRENT)
#if HAS_POWER_MONITOR_WATTS
if (power_monitor.display_item == 2 && !wflag) ++power_monitor.display_item;
#endif
if (power_monitor.display_item >= 3) power_monitor.display_item = 0;
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/menu/menu_power_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@

void menu_power_monitor() {
START_MENU();
MENU_BACK(MSG_MAIN);
BACK_ITEM(MSG_MAIN);

#if ENABLED(POWER_MONITOR_CURRENT)
{
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

#if HAS_POWER_MONITOR_VREF
{
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

#if HAS_POWER_MONITOR_WATTS
{
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

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/configuration_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
#include "../feature/powerloss.h"
#endif

#if ENABLED(POWER_MONITOR)
#if HAS_POWER_MONITOR
#include "../feature/power_monitor.h"
#endif

Expand Down
7 changes: 5 additions & 2 deletions buildroot/tests/mega1280-tests
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ set -e
restore_configs
opt_set LCD_LANGUAGE an
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 \
MESH_BED_LEVELING ENABLE_LEVELING_FADE_HEIGHT MESH_G28_REST_ORIGIN \
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_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
Expand Down

0 comments on commit 9d25223

Please sign in to comment.