Power monitor and display (#17437)

This commit is contained in:
Scott Lahteine
2020-06-18 15:23:03 -05:00
committed by GitHub
parent c8e99d572c
commit 424569b4c4
32 changed files with 652 additions and 28 deletions

View File

@ -48,6 +48,10 @@
#include "../../feature/spindle_laser.h"
#endif
#if HAS_POWER_MONITOR
#include "../../feature/power_monitor.h"
#endif
#if ENABLED(SDSUPPORT)
#include "../../sd/cardreader.h"
#endif
@ -103,6 +107,59 @@
#define STATUS_HEATERS_BOT (STATUS_HEATERS_Y + STATUS_HEATERS_HEIGHT - 1)
#endif
#if HAS_POWER_MONITOR
void display_power_monitor(const uint8_t x, const uint8_t y) {
lcd_moveto(x, y);
#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 (ELAPSED(millis(), power_monitor.display_item_ms)) {
power_monitor.display_item_ms = millis() + 1000UL;
++power_monitor.display_item;
}
#endif
// ensure we have the right one selected for display
for (uint8_t i = 0; i < 3; i++) {
#if ENABLED(POWER_MONITOR_CURRENT)
if (power_monitor.display_item == 0 && !iflag) ++power_monitor.display_item;
#endif
#if HAS_POWER_MONITOR_VREF
if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item;
#endif
#if ENABLED(POWER_MONITOR_CURRENT)
if (power_monitor.display_item == 2 && !wflag) ++power_monitor.display_item;
#endif
if (power_monitor.display_item >= 3) power_monitor.display_item = 0;
}
switch (power_monitor.display_item) {
#if ENABLED(POWER_MONITOR_CURRENT) // Current
case 0: if (iflag) power_monitor.draw_current(); break;
#endif
#if HAS_POWER_MONITOR_VREF // Voltage
case 1: if (vflag) power_monitor.draw_voltage(); break;
#endif
#if HAS_POWER_MONITOR_WATTS // Power
case 2: if (wflag) power_monitor.draw_power(); break;
#endif
default: break;
}
}
#endif
#define PROGRESS_BAR_X 54
#define PROGRESS_BAR_Y (EXTRAS_BASELINE + 1)
#define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)
@ -787,16 +844,25 @@ void MarlinUI::draw_status_screen() {
void MarlinUI::draw_status_message(const bool blink) {
// Get the UTF8 character count of the string
uint8_t slen = utf8_strlen(status_message);
uint8_t lcd_width = LCD_WIDTH, pixel_width = LCD_PIXEL_WIDTH,
slen = utf8_strlen(status_message);
#if HAS_POWER_MONITOR
if (power_monitor.display_enabled()) {
// make room at the end of the status line for the power monitor reading
lcd_width -= 6;
pixel_width -= (MENU_FONT_WIDTH) * 6;
}
#endif
#if ENABLED(STATUS_MESSAGE_SCROLLING)
static bool last_blink = false;
if (slen <= LCD_WIDTH) {
if (slen <= lcd_width) {
// The string fits within the line. Print with no scrolling
lcd_put_u8str(status_message);
while (slen < LCD_WIDTH) { lcd_put_wchar(' '); ++slen; }
while (slen < lcd_width) { lcd_put_wchar(' '); ++slen; }
}
else {
// String is longer than the available space
@ -805,20 +871,21 @@ void MarlinUI::draw_status_message(const bool blink) {
// and the string remaining length
uint8_t rlen;
const char *stat = status_and_len(rlen);
lcd_put_u8str_max(stat, LCD_PIXEL_WIDTH);
lcd_put_u8str_max(stat, pixel_width);
// If the remaining string doesn't completely fill the screen
if (rlen < LCD_WIDTH) {
if (rlen < lcd_width) {
lcd_put_wchar('.'); // Always at 1+ spaces left, draw a dot
uint8_t chars = LCD_WIDTH - rlen; // Amount of space left in characters
uint8_t chars = lcd_width - rlen; // Amount of space left in characters
if (--chars) { // Draw a second dot if there's space
lcd_put_wchar('.');
if (--chars) { // Print a second copy of the message
lcd_put_u8str_max(status_message, LCD_PIXEL_WIDTH - (rlen + 2) * (MENU_FONT_WIDTH));
lcd_put_u8str_max(status_message, pixel_width - (rlen + 2) * (MENU_FONT_WIDTH));
lcd_put_wchar(' ');
}
}
}
if (last_blink != blink) {
last_blink = blink;
advance_status_scroll();
@ -830,12 +897,16 @@ void MarlinUI::draw_status_message(const bool blink) {
UNUSED(blink);
// Just print the string to the LCD
lcd_put_u8str_max(status_message, LCD_PIXEL_WIDTH);
lcd_put_u8str_max(status_message, pixel_width);
// Fill the rest with spaces
for (; slen < LCD_WIDTH; ++slen) lcd_put_wchar(' ');
for (; slen < lcd_width; ++slen) lcd_put_wchar(' ');
#endif // !STATUS_MESSAGE_SCROLLING
#if HAS_POWER_MONITOR
display_power_monitor(pixel_width + MENU_FONT_WIDTH, STATUS_BASELINE);
#endif
}
#endif // HAS_GRAPHICAL_LCD && !LIGHTWEIGHT_UI

View File

@ -340,6 +340,10 @@ namespace Language_en {
PROGMEM Language_Str MSG_INFO_SCREEN = _UxGT("Info Screen");
PROGMEM Language_Str MSG_PREPARE = _UxGT("Prepare");
PROGMEM Language_Str MSG_TUNE = _UxGT("Tune");
PROGMEM Language_Str MSG_POWER_MONITOR = _UxGT("Power monitor");
PROGMEM Language_Str MSG_CURRENT = _UxGT("Current");
PROGMEM Language_Str MSG_VOLTAGE = _UxGT("Voltage");
PROGMEM Language_Str MSG_POWER = _UxGT("Power");
PROGMEM Language_Str MSG_START_PRINT = _UxGT("Start Print");
PROGMEM Language_Str MSG_BUTTON_NEXT = _UxGT("Next");
PROGMEM Language_Str MSG_BUTTON_INIT = _UxGT("Init");

View File

@ -59,6 +59,14 @@ void menu_configuration();
void menu_user();
#endif
#if HAS_POWER_MONITOR
void menu_power_monitor();
#endif
#if ENABLED(MIXING_EXTRUDER)
void menu_mixer();
#endif
#if ENABLED(ADVANCED_PAUSE_FEATURE)
void _menu_temp_filament_op(const PauseMode, const int8_t);
void menu_change_filament();
@ -76,10 +84,6 @@ void menu_configuration();
void menu_spindle_laser();
#endif
#if ENABLED(MIXING_EXTRUDER)
void menu_mixer();
#endif
extern const char M21_STR[];
void menu_main() {
@ -155,6 +159,10 @@ void menu_main() {
SUBMENU(MSG_TEMPERATURE, menu_temperature);
#if HAS_POWER_MONITOR
MENU_ITEM(submenu, MSG_POWER_MONITOR, menu_power_monitor);
#endif
#if ENABLED(MIXING_EXTRUDER)
SUBMENU(MSG_MIXER, menu_mixer);
#endif

View File

@ -0,0 +1,62 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
//
// Power Monitor Menu
//
#include "../../inc/MarlinConfigPre.h"
#if HAS_LCD_MENU && HAS_POWER_MONITOR
#include "menu.h"
#include "../../feature/power_monitor.h"
void menu_power_monitor() {
START_MENU();
MENU_BACK(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);
}
#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);
}
#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);
}
#endif
END_MENU();
}
#endif // HAS_LCD_MENU && HAS_POWER_MONITOR

View File

@ -112,6 +112,10 @@ MarlinUI ui;
#include "../module/thermistor/thermistors.h"
#endif
#if HAS_POWER_MONITOR
#include "../feature/power_monitor.h"
#endif
#if HAS_ENCODER_ACTION
volatile uint8_t MarlinUI::buttons;
#if HAS_SLOW_BUTTONS
@ -533,7 +537,6 @@ void MarlinUI::status_screen() {
#endif // LCD_PROGRESS_BAR
#if HAS_LCD_MENU
if (use_click()) {
#if BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
next_filament_display = millis() + 5000UL; // Show status message for 5s