M166 Gradients, LCD Menu for 2-channel Mixer (Geeetech A10M/A20M) (#13022)

This commit is contained in:
Scott Lahteine
2019-02-10 04:54:23 -06:00
committed by GitHub
parent 7ee35c2611
commit 6de3d34378
114 changed files with 9901 additions and 61 deletions

View File

@ -832,11 +832,35 @@ void MarlinUI::draw_status_screen() {
#else // HOTENDS <= 2 && (HOTENDS <= 1 || !HAS_HEATED_BED)
_draw_axis_value(X_AXIS, ftostr4sign(LOGICAL_X_POSITION(current_position[X_AXIS])), blink);
#if DUAL_MIXING_EXTRUDER
lcd_put_wchar(' ');
// Two-component mix / gradient instead of XY
_draw_axis_value(Y_AXIS, ftostr4sign(LOGICAL_Y_POSITION(current_position[Y_AXIS])), blink);
char mixer_messages[12];
const char *mix_label;
#if ENABLED(GRADIENT_MIX)
if (mixer.gradient.enabled) {
mixer.update_mix_from_gradient();
mix_label = "Gr";
}
else
#endif
{
mixer.update_mix_from_vtool();
mix_label = "Mx";
}
sprintf_P(mixer_messages, PSTR("%s %d;%d%% "), mix_label, int(mixer.mix[0]), int(mixer.mix[1]));
lcd_put_u8str(mixer_messages);
#else
_draw_axis_value(X_AXIS, ftostr4sign(LOGICAL_X_POSITION(current_position[X_AXIS])), blink);
lcd_put_wchar(' ');
_draw_axis_value(Y_AXIS, ftostr4sign(LOGICAL_Y_POSITION(current_position[Y_AXIS])), blink);
#endif
#endif // HOTENDS <= 2 && (HOTENDS <= 1 || !HAS_HEATED_BED)

View File

@ -51,6 +51,10 @@
#include "../../module/printcounter.h"
#endif
#if DUAL_MIXING_EXTRUDER
#include "../../feature/mixing.h"
#endif
FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, const uint8_t ty) {
const char *str = i16tostr3(temp);
const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1;
@ -59,6 +63,9 @@ FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, cons
lcd_put_wchar(LCD_STR_DEGREE[0]);
}
#define X_LABEL_POS 3
#define X_VALUE_POS 11
#define XYZ_SPACING 37
#define XYZ_BASELINE (30 + INFO_FONT_ASCENT)
#define EXTRAS_BASELINE (40 + INFO_FONT_ASCENT)
#define STATUS_BASELINE (LCD_PIXEL_HEIGHT - INFO_FONT_DESCENT)
@ -209,6 +216,10 @@ FORCE_INLINE void _draw_heater_status(const int8_t heater, const bool blink) {
// Homed and known, display constantly.
//
FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink) {
const uint8_t offs = (XYZ_SPACING) * axis;
lcd_moveto(X_LABEL_POS + offs, XYZ_BASELINE);
lcd_put_wchar('X' + axis);
lcd_moveto(X_VALUE_POS + offs, XYZ_BASELINE);
if (blink)
lcd_put_u8str(value);
else {
@ -450,19 +461,35 @@ void MarlinUI::draw_status_screen() {
u8g.setColorIndex(0); // white on black
#endif
lcd_moveto(0 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
lcd_put_wchar('X');
lcd_moveto(0 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
_draw_axis_value(X_AXIS, xstring, blink);
#if DUAL_MIXING_EXTRUDER
lcd_moveto(1 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
lcd_put_wchar('Y');
lcd_moveto(1 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
_draw_axis_value(Y_AXIS, ystring, blink);
// Two-component mix / gradient instead of XY
lcd_moveto(X_LABEL_POS, XYZ_BASELINE);
char mixer_messages[12];
const char *mix_label;
#if ENABLED(GRADIENT_MIX)
if (mixer.gradient.enabled) {
mixer.update_mix_from_gradient();
mix_label = "Gr";
}
else
#endif
{
mixer.update_mix_from_vtool();
mix_label = "Mx";
}
sprintf_P(mixer_messages, PSTR("%s %d;%d%% "), mix_label, int(mixer.mix[0]), int(mixer.mix[1]));
lcd_put_u8str(mixer_messages);
#else
_draw_axis_value(X_AXIS, xstring, blink);
_draw_axis_value(Y_AXIS, ystring, blink);
#endif
lcd_moveto(2 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
lcd_put_wchar('Z');
lcd_moveto(2 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
_draw_axis_value(Z_AXIS, zstring, blink);
#if DISABLED(XYZ_HOLLOW_FRAME)

View File

@ -1205,6 +1205,61 @@
#define MSG_MMU2_EJECT_RECOVER _UxGT("Remove, click")
#endif
#ifndef MSG_MIX
#define MSG_MIX _UxGT("Mix")
#endif
#ifndef MSG_MIX_COMPONENT
#define MSG_MIX_COMPONENT _UxGT("Component")
#endif
#ifndef MSG_MIXER
#define MSG_MIXER _UxGT("Mixer")
#endif
#ifndef MSG_GRADIENT
#define MSG_GRADIENT _UxGT("Gradient")
#endif
#ifndef MSG_FULL_GRADIENT
#define MSG_FULL_GRADIENT _UxGT("Full gradient")
#endif
#ifndef MSG_TOGGLE_MIX
#define MSG_TOGGLE_MIX _UxGT("Toggle mix")
#endif
#ifndef MSG_CYCLE_MIX
#define MSG_CYCLE_MIX _UxGT("Cycle mix")
#endif
#ifndef MSG_GRADIENT_MIX
#define MSG_GRADIENT_MIX _UxGT("Gradient mix")
#endif
#ifndef MSG_REVERSE_GRADIENT
#define MSG_REVERSE_GRADIENT _UxGT("Reverse Gradient")
#endif
#ifndef MSG_ACTIVE_VTOOL
#define MSG_ACTIVE_VTOOL _UxGT("Active V-tool")
#endif
#ifndef MSG_START_VTOOL
#define MSG_START_VTOOL _UxGT("Start V-tool")
#endif
#ifndef MSG_END_VTOOL
#define MSG_END_VTOOL _UxGT(" End V-tool")
#endif
#ifndef MSG_GRADIENT_ALIAS
#define MSG_GRADIENT_ALIAS _UxGT("Alias V-tool")
#endif
#ifndef MSG_RESET_VTOOLS
#define MSG_RESET_VTOOLS _UxGT("Reset V-tools")
#endif
#ifndef MSG_COMMIT_VTOOL
#define MSG_COMMIT_VTOOL _UxGT("Commit V-tool Mix")
#endif
#ifndef MSG_VTOOLS_RESET
#define MSG_VTOOLS_RESET _UxGT("V-tools were reset")
#endif
#ifndef MSG_START_Z
#define MSG_START_Z _UxGT("Start Z")
#endif
#ifndef MSG_END_Z
#define MSG_END_Z _UxGT(" End Z")
#endif
//
// Filament Change screens show up to 3 lines on a 4-line display
// ...or up to 2 lines on a 3-line display

View File

@ -158,7 +158,7 @@ void MenuItemBase::init(PGM_P const el, void * const ev, const int32_t minv, con
liveEdit = le;
}
#define DEFINE_MENU_EDIT_ITEM(NAME) template class TMenuItem<MenuItemInfo_##NAME>;
#define DEFINE_MENU_EDIT_ITEM(NAME) template class TMenuItem<MenuItemInfo_##NAME>
DEFINE_MENU_EDIT_ITEM(int3); // 123, -12 right-justified
DEFINE_MENU_EDIT_ITEM(int4); // 1234, -123 right-justified

View File

@ -100,6 +100,10 @@ void menu_change_filament();
void menu_info();
void menu_led();
#if ENABLED(MIXING_EXTRUDER)
void menu_mixer();
#endif
void menu_main() {
START_MENU();
MENU_BACK(MSG_WATCH);
@ -153,6 +157,10 @@ void menu_main() {
MENU_ITEM(submenu, MSG_MOTION, menu_motion);
MENU_ITEM(submenu, MSG_TEMPERATURE, menu_temperature);
#if ENABLED(MIXING_EXTRUDER)
MENU_ITEM(submenu, MSG_MIXER, menu_mixer);
#endif
#if ENABLED(MMU2_MENUS)
MENU_ITEM(submenu, MSG_MMU2_MENU, menu_mmu2);
#endif

View File

@ -0,0 +1,314 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 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/>.
*
*/
//
// Mixer Menu
//
#include "../../inc/MarlinConfigPre.h"
#if HAS_LCD_MENU && ENABLED(MIXING_EXTRUDER)
#include "menu.h"
#include "../../feature/mixing.h"
#include "../dogm/ultralcd_DOGM.h"
#include "../ultralcd.h"
#include "../lcdprint.h"
#define CHANNEL_MIX_EDITING !DUAL_MIXING_EXTRUDER
#if ENABLED(GRADIENT_MIX)
void lcd_mixer_gradient_z_start_edit() {
ui.defer_status_screen(true);
ui.encoder_direction_normal();
ENCODER_RATE_MULTIPLY(true);
if (ui.encoderPosition != 0) {
mixer.gradient.start_z += float((int)ui.encoderPosition) * 0.1;
ui.encoderPosition = 0;
NOLESS(mixer.gradient.start_z, 0);
NOMORE(mixer.gradient.start_z, Z_MAX_POS);
}
if (ui.should_draw()) {
char tmp[21];
sprintf_P(tmp, PSTR(MSG_START_Z ": %4d.%d mm"), int(mixer.gradient.start_z), int(mixer.gradient.start_z * 10) % 10);
SETCURSOR(2, (LCD_HEIGHT - 1) / 2);
LCDPRINT(tmp);
}
if (ui.lcd_clicked) {
if (mixer.gradient.start_z > mixer.gradient.end_z)
mixer.gradient.end_z = mixer.gradient.start_z;
mixer.refresh_gradient();
ui.goto_previous_screen();
}
}
void lcd_mixer_gradient_z_end_edit() {
ui.defer_status_screen(true);
ui.encoder_direction_normal();
ENCODER_RATE_MULTIPLY(true);
if (ui.encoderPosition != 0) {
mixer.gradient.end_z += float((int)ui.encoderPosition) * 0.1;
ui.encoderPosition = 0;
NOLESS(mixer.gradient.end_z, 0);
NOMORE(mixer.gradient.end_z, Z_MAX_POS);
}
if (ui.should_draw()) {
char tmp[21];
sprintf_P(tmp, PSTR(MSG_END_Z ": %4d.%d mm"), int(mixer.gradient.end_z), int(mixer.gradient.end_z * 10) % 10);
SETCURSOR(2, (LCD_HEIGHT - 1) / 2);
LCDPRINT(tmp);
}
if (ui.lcd_clicked) {
if (mixer.gradient.end_z < mixer.gradient.start_z)
mixer.gradient.start_z = mixer.gradient.end_z;
mixer.refresh_gradient();
ui.goto_previous_screen();
}
}
void lcd_mixer_edit_gradient_menu() {
START_MENU();
MENU_BACK(MSG_MIXER);
MENU_ITEM_EDIT_CALLBACK(int8, MSG_START_VTOOL, &mixer.gradient.start_vtool, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
MENU_ITEM_EDIT_CALLBACK(int8, MSG_END_VTOOL, &mixer.gradient.end_vtool, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
#if ENABLED(GRADIENT_VTOOL)
MENU_ITEM_EDIT_CALLBACK(int8, MSG_GRADIENT_ALIAS, &mixer.gradient.vtool_index, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
#endif
char tmp[10];
MENU_ITEM(submenu, MSG_START_Z ":", lcd_mixer_gradient_z_start_edit);
MENU_ITEM_ADDON_START(9);
sprintf_P(tmp, PSTR("%4d.%d mm"), int(mixer.gradient.start_z), int(mixer.gradient.start_z * 10) % 10);
LCDPRINT(tmp);
MENU_ITEM_ADDON_END();
MENU_ITEM(submenu, MSG_END_Z ":", lcd_mixer_gradient_z_end_edit);
MENU_ITEM_ADDON_START(9);
sprintf_P(tmp, PSTR("%4d.%d mm"), int(mixer.gradient.end_z), int(mixer.gradient.end_z * 10) % 10);
LCDPRINT(tmp);
MENU_ITEM_ADDON_END();
END_MENU();
}
#endif // GRADIENT_MIX
static uint8_t v_index;
#if DUAL_MIXING_EXTRUDER
void _lcd_draw_mix(const uint8_t y) {
char tmp[21];
sprintf_P(tmp, PSTR(MSG_MIX ": %3d%% %3d%%"), int(mixer.mix[0]), int(mixer.mix[1]));
SETCURSOR(2, y);
LCDPRINT(tmp);
}
#endif
void _lcd_mixer_select_vtool() {
mixer.T(v_index);
#if DUAL_MIXING_EXTRUDER
_lcd_draw_mix(LCD_HEIGHT - 1);
#endif
}
#if CHANNEL_MIX_EDITING
void _lcd_mixer_cycle_mix() {
uint16_t bits = 0;
MIXER_STEPPER_LOOP(i) if (mixer.collector[i]) SBI(bits, i);
bits = (bits + 1) & (_BV(MIXING_STEPPERS) - 1);
if (!bits) ++bits;
MIXER_STEPPER_LOOP(i) mixer.collector[i] = TEST(bits, i) ? 10.0f : 0.0f;
ui.refresh();
}
void _lcd_mixer_commit_vtool() {
mixer.normalize();
ui.goto_previous_screen();
}
#endif
void lcd_mixer_mix_edit() {
#if CHANNEL_MIX_EDITING
#define EDIT_COLOR(N) MENU_MULTIPLIER_ITEM_EDIT(float52, MSG_MIX_COMPONENT " " STRINGIFY(N), &mixer.collector[N-1], 0, 10);
START_MENU();
MENU_BACK(MSG_MIXER);
EDIT_COLOR(1);
EDIT_COLOR(2);
#if MIXING_STEPPERS > 2
EDIT_COLOR(3);
#if MIXING_STEPPERS > 3
EDIT_COLOR(4);
#if MIXING_STEPPERS > 4
EDIT_COLOR(5);
#if MIXING_STEPPERS > 5
EDIT_COLOR(6);
#endif
#endif
#endif
#endif
MENU_ITEM(function, MSG_CYCLE_MIX, _lcd_mixer_cycle_mix);
MENU_ITEM(function, MSG_COMMIT_VTOOL, _lcd_mixer_commit_vtool);
END_MENU();
#elif DUAL_MIXING_EXTRUDER
if (ui.encoderPosition != 0) {
mixer.mix[0] += (int)ui.encoderPosition;
ui.encoderPosition = 0;
if (mixer.mix[0] < 0) mixer.mix[0] += 101;
if (mixer.mix[0] > 100) mixer.mix[0] -= 101;
mixer.mix[1] = 100 - mixer.mix[0];
}
_lcd_draw_mix((LCD_HEIGHT - 1) / 2);
if (ui.lcd_clicked) {
mixer.update_vtool_from_mix();
ui.goto_previous_screen();
}
#else
START_MENU();
MENU_BACK(MSG_MIXER);
END_MENU();
#endif
}
#if DUAL_MIXING_EXTRUDER
//
// Toggle Dual-Mix
//
inline void _lcd_mixer_toggle_mix() {
mixer.mix[0] = mixer.mix[0] == 100 ? 0 : 100;
mixer.mix[1] = 100 - mixer.mix[0];
mixer.update_vtool_from_mix();
ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
}
#endif
#if CHANNEL_MIX_EDITING
//
// Prepare and Edit Mix
//
inline void _lcd_goto_mix_edit() {
mixer.refresh_collector(10, v_index);
ui.goto_screen(lcd_mixer_mix_edit);
lcd_mixer_mix_edit();
}
#endif
#if ENABLED(GRADIENT_MIX)
//
// Reverse Gradient
//
inline void _lcd_mixer_reverse_gradient() {
const uint8_t sv = mixer.gradient.start_vtool;
mixer.gradient.start_vtool = mixer.gradient.end_vtool;
mixer.gradient.end_vtool = sv;
mixer.refresh_gradient();
ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
}
#endif
//
// Reset All V-Tools
//
inline void _lcd_reset_vtools() {
LCD_MESSAGEPGM(MSG_VTOOLS_RESET);
ui.return_to_status();
mixer.reset_vtools();
}
void menu_mixer_vtools_reset_confirm() {
START_MENU();
MENU_BACK(MSG_BACK);
MENU_ITEM(function, MSG_RESET_VTOOLS, _lcd_reset_vtools);
END_MENU();
}
void menu_mixer() {
START_MENU();
MENU_BACK(MSG_MAIN);
v_index = mixer.get_current_vtool();
MENU_ITEM_EDIT_CALLBACK(uint8, MSG_ACTIVE_VTOOL, &v_index, 0, MIXING_VIRTUAL_TOOLS - 1, _lcd_mixer_select_vtool
#if DUAL_MIXING_EXTRUDER
, true
#endif
);
MENU_ITEM(submenu, MSG_MIX,
#if CHANNEL_MIX_EDITING
_lcd_goto_mix_edit
#elif DUAL_MIXING_EXTRUDER
lcd_mixer_mix_edit
#endif
);
#if DUAL_MIXING_EXTRUDER
{
char tmp[10];
MENU_ITEM_ADDON_START(10);
mixer.update_mix_from_vtool();
sprintf_P(tmp, PSTR("%3d;%3d%%"), int(mixer.mix[0]), int(mixer.mix[1]));
LCDPRINT(tmp);
MENU_ITEM_ADDON_END();
MENU_ITEM(function, MSG_TOGGLE_MIX, _lcd_mixer_toggle_mix);
}
#endif
MENU_ITEM(submenu, MSG_RESET_VTOOLS, menu_mixer_vtools_reset_confirm);
#if ENABLED(GRADIENT_MIX)
{
char tmp[10];
MENU_ITEM(submenu, MSG_GRADIENT, lcd_mixer_edit_gradient_menu);
MENU_ITEM_ADDON_START(10);
sprintf_P(tmp, PSTR("T%i->T%i"), mixer.gradient.start_vtool, mixer.gradient.end_vtool);
LCDPRINT(tmp);
MENU_ITEM_ADDON_END();
MENU_ITEM(function, MSG_REVERSE_GRADIENT, _lcd_mixer_reverse_gradient);
}
#endif
END_MENU();
}
#endif // HAS_LCD_MENU && MIXING_EXTRUDER

View File

@ -53,9 +53,13 @@
#if HAS_GRAPHICAL_LCD
#define SETCURSOR(col, row) lcd_moveto(col * (MENU_FONT_WIDTH), (row + 1) * (MENU_FONT_HEIGHT))
#define SETCURSOR_RJ(len, row) lcd_moveto(LCD_PIXEL_WIDTH - len * (MENU_FONT_WIDTH), (row + 1) * (MENU_FONT_HEIGHT))
#define LCDPRINT(p) u8g.print(p)
#define LCDWRITE(c) u8g.print(c)
#else
#define SETCURSOR(col, row) lcd_moveto(col, row)
#define SETCURSOR_RJ(len, row) lcd_moveto(LCD_WIDTH - len, row)
#define LCDPRINT(p) lcd_put_u8str(p)
#define LCDWRITE(c) lcd_put_wchar(c)
#endif
#define LCD_UPDATE_INTERVAL 100