Skip to content

Commit

Permalink
Color UI Move Screen for 320x240 TFT (MarlinFirmware#21708)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtgbe authored Apr 28, 2021
1 parent f7f88b7 commit 2e0a1f1
Show file tree
Hide file tree
Showing 11 changed files with 526 additions and 96 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/feature/dac/stepper_dac.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class StepperDAC {
static void set_current_value(const uint8_t channel, uint16_t val);
static void print_values();
static void commit_eeprom();
static uint8_t get_current_percent(AxisEnum axis);
static uint8_t get_current_percent(const AxisEnum axis);
static void set_current_percents(xyze_uint8_t &pct);
};

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ void MarlinUI::quick_feedback(const bool clear_buttons/*=true*/) {
//
// Tell ui.update() to start a move to current_position after a short delay.
//
void ManualMove::soon(AxisEnum move_axis
void ManualMove::soon(const AxisEnum move_axis
#if MULTI_MANUAL
, const int8_t eindex/*=-1*/
#endif
Expand Down
23 changes: 22 additions & 1 deletion Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,34 @@
current_position.set(dest);
#endif
}
float axis_value(const AxisEnum axis) {
return NATIVE_TO_LOGICAL(processing ? destination[axis] : SUM_TERN(IS_KINEMATIC, current_position[axis], offset), axis);
}
bool apply_diff(const AxisEnum axis, const_float_t diff, const_float_t min, const_float_t max) {
#if IS_KINEMATIC
float &valref = offset;
const float rmin = min - current_position[axis], rmax = max - current_position[axis];
#else
float &valref = current_position[axis];
const float rmin = min, rmax = max;
#endif
valref += diff;
const float pre = valref;
if (min != max) {
if (diff < 0)
NOLESS(valref, rmin);
else
NOMORE(valref, rmax);
}
return pre != valref;
}
#if IS_KINEMATIC
static bool processing;
#else
static bool constexpr processing = false;
#endif
static void task();
static void soon(AxisEnum axis
static void soon(const AxisEnum axis
#if MULTI_MANUAL
, const int8_t eindex=-1
#endif
Expand Down
20 changes: 2 additions & 18 deletions Marlin/src/lcd/menu/menu_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,13 @@ static void _lcd_move_xyz(PGM_P const name, const AxisEnum axis) {

// Get the new position
const float diff = float(int32_t(ui.encoderPosition)) * ui.manual_move.menu_scale;
#if IS_KINEMATIC
ui.manual_move.offset += diff;
if (int32_t(ui.encoderPosition) < 0)
NOLESS(ui.manual_move.offset, min - current_position[axis]);
else
NOMORE(ui.manual_move.offset, max - current_position[axis]);
#else
current_position[axis] += diff;
if (int32_t(ui.encoderPosition) < 0)
NOLESS(current_position[axis], min);
else
NOMORE(current_position[axis], max);
#endif

(void)ui.manual_move.apply_diff(axis, diff, min, max);
ui.manual_move.soon(axis);
ui.refresh(LCDVIEW_REDRAW_NOW);
}
ui.encoderPosition = 0;
if (ui.should_draw()) {
const float pos = NATIVE_TO_LOGICAL(
ui.manual_move.processing ? destination[axis] : SUM_TERN(IS_KINEMATIC, current_position[axis], ui.manual_move.offset),
axis
);
const float pos = ui.manual_move.axis_value(axis);
if (parser.using_inch_units()) {
const float imp_pos = LINEAR_UNIT(pos);
MenuEditItemBase::draw_edit_screen(name, ftostr63(imp_pos));
Expand Down
Binary file added Marlin/src/lcd/tft/bitmaps/btn_42x39_rounded.bmp
Binary file not shown.
69 changes: 69 additions & 0 deletions Marlin/src/lcd/tft/images/btn_rounded_42x39x4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 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 <https://www.gnu.org/licenses/>.
*
*/

#include "../../../inc/MarlinConfigPre.h"

#if HAS_GRAPHICAL_TFT

extern const uint8_t btn_rounded_42x39x4[819] = {
0x87, 0x87, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x78, 0x78,
0x87, 0x77, 0xab, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xb9, 0x77, 0x78,
0x87, 0x8e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd7, 0x68,
0x87, 0xff, 0x84, 0x32, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x37, 0xff, 0x57,
0x7b, 0xf6, 0x34, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x43, 0x6f, 0x95,
0x7d, 0xc3, 0x45, 0x56, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x4d, 0xc4,
0x7e, 0xc3, 0x56, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x6d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7e, 0xc3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x7d, 0xd3,
0x7d, 0xd3, 0x57, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x77, 0x7e, 0xc3,
0x88, 0xfa, 0x56, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0xcf, 0x64,
0x86, 0xbf, 0xdb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xce, 0xfb, 0x34,
0x87, 0x57, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x74, 0x45,
0x87, 0x75, 0x33, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x33, 0x34, 0x56,
0x87, 0x77, 0x65, 0x54, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x55, 0x67,
0x87, 0x87, 0x77, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x67, 0x78
};

#endif // HAS_GRAPHICAL_TFT
2 changes: 2 additions & 0 deletions Marlin/src/lcd/tft/tft_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const tImage Fan_Fast1_64x64x4 = { (void *)fan_fast1_64x64x4, 64, 64, GREYS
const tImage SD_64x64x4 = { (void *)sd_64x64x4, 64, 64, GREYSCALE4 };
const tImage Home_64x64x4 = { (void *)home_64x64x4, 64, 64, GREYSCALE4 };
const tImage BtnRounded_64x52x4 = { (void *)btn_rounded_64x52x4, 64, 52, GREYSCALE4 };
const tImage BtnRounded_42x39x4 = { (void *)btn_rounded_42x39x4, 42, 39, GREYSCALE4 };
const tImage Menu_64x64x4 = { (void *)menu_64x64x4, 64, 64, GREYSCALE4 };
const tImage Settings_64x64x4 = { (void *)settings_64x64x4, 64, 64, GREYSCALE4 };
const tImage Confirm_64x64x4 = { (void *)confirm_64x64x4, 64, 64, GREYSCALE4 };
Expand Down Expand Up @@ -106,6 +107,7 @@ const tImage Images[imgCount] = {
Slider8x16x4,
Home_64x64x4,
BtnRounded_64x52x4,
BtnRounded_42x39x4,
};

#endif // HAS_GRAPHICAL_TFT
3 changes: 3 additions & 0 deletions Marlin/src/lcd/tft/tft_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern const uint8_t fan_fast0_64x64x4[], fan_fast1_64x64x4[];
extern const uint8_t sd_64x64x4[];
extern const uint8_t home_64x64x4[];
extern const uint8_t btn_rounded_64x52x4[];
extern const uint8_t btn_rounded_42x39x4[];
extern const uint8_t menu_64x64x4[];
extern const uint8_t settings_64x64x4[];
extern const uint8_t confirm_64x64x4[];
Expand Down Expand Up @@ -95,6 +96,7 @@ enum MarlinImage : uint8_t {
imgSlider,
imgHome,
imgBtn52Rounded,
imgBtn39Rounded,
imgCount,
noImage = imgCount,
imgPageUp = imgLeft,
Expand Down Expand Up @@ -145,6 +147,7 @@ extern const tImage Fan_Fast1_64x64x4;
extern const tImage SD_64x64x4;
extern const tImage Home_64x64x4;
extern const tImage BtnRounded_64x52x4;
extern const tImage BtnRounded_42x39x4;
extern const tImage Menu_64x64x4;
extern const tImage Settings_64x64x4;
extern const tImage Confirm_64x64x4;
Expand Down
49 changes: 19 additions & 30 deletions Marlin/src/lcd/tft/ui_1024x600.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) {
image = targetTemperature > 0 ? imgChamberHeated : imgChamber;
}
#endif
#if HAS_TEMP_COOLER
else if (Heater == H_COOLER) {
if (currentTemperature <= 26) Color = COLOR_COLD;
if (currentTemperature > 26) Color = COLOR_RED;
image = targetTemperature > 26 ? imgCoolerHot : imgCooler;
}
#endif

tft.add_image(8, 28, image, Color);

Expand Down Expand Up @@ -229,6 +236,9 @@ void MarlinUI::draw_status_screen() {
#ifdef ITEM_CHAMBER
case ITEM_CHAMBER: draw_heater_status(x, y, H_CHAMBER); break;
#endif
#ifdef ITEM_COOLER
case ITEM_COOLER: draw_heater_status(x, y, H_COOLER); break;
#endif
#ifdef ITEM_FAN
case ITEM_FAN: draw_fan_status(x, y, blink); break;
#endif
Expand Down Expand Up @@ -551,7 +561,6 @@ struct MotionAxisState {
float currentStepSize = 10.0;
int z_selection = Z_SELECTION_Z;
uint8_t e_selection = 0;
bool homming = false;
bool blocked = false;
char message[32];
};
Expand Down Expand Up @@ -616,16 +625,11 @@ static void drawMessage(const char *msg) {
tft.add_text(0, 0, COLOR_YELLOW, msg);
}

static void drawAxisValue(AxisEnum axis) {
const float value =
#if HAS_BED_PROBE
axis == Z_AXIS && motionAxisState.z_selection == Z_SELECTION_Z_PROBE ?
probe.offset.z :
#endif
NATIVE_TO_LOGICAL(
ui.manual_move.processing ? destination[axis] : current_position[axis] + TERN0(IS_KINEMATIC, ui.manual_move.offset),
axis
);
static void drawAxisValue(const AxisEnum axis) {
const float value = (
TERN_(HAS_BED_PROBE, axis == Z_AXIS && motionAxisState.z_selection == Z_SELECTION_Z_PROBE ? probe.offset.z :)
ui.manual_move.axis_value(axis)
);
xy_int_t pos;
uint16_t color;
switch (axis) {
Expand All @@ -641,7 +645,7 @@ static void drawAxisValue(AxisEnum axis) {
tft.add_text(0, 0, color, tft_string);
}

static void moveAxis(AxisEnum axis, const int8_t direction) {
static void moveAxis(const AxisEnum axis, const int8_t direction) {
quick_feedback();

if (axis == E_AXIS && thermalManager.tooColdToExtrude(motionAxisState.e_selection)) {
Expand Down Expand Up @@ -707,23 +711,11 @@ static void moveAxis(AxisEnum axis, const int8_t direction) {
#endif

// Get the new position
const bool limited = ui.manual_move.apply_diff(axis, diff, min, max);
#if IS_KINEMATIC
ui.manual_move.offset += diff;
if (direction < 0)
NOLESS(ui.manual_move.offset, min - current_position[axis]);
else
NOMORE(ui.manual_move.offset, max - current_position[axis]);
UNUSED(limited);
#else
current_position[axis] += diff;
const char *msg = NUL_STR; // clear the error
if (direction < 0 && current_position[axis] < min) {
current_position[axis] = min;
msg = GET_TEXT(MSG_LCD_SOFT_ENDSTOPS);
}
else if (direction > 0 && current_position[axis] > max) {
current_position[axis] = max;
msg = GET_TEXT(MSG_LCD_SOFT_ENDSTOPS);
}
PGM_P const msg = limited ? GET_TEXT(MSG_LCD_SOFT_ENDSTOPS) : NUL_STR;
drawMessage(msg);
#endif

Expand Down Expand Up @@ -921,7 +913,4 @@ void MarlinUI::move_axis_screen() {
TERN_(HAS_TFT_XPT2046, add_control(TFT_WIDTH - X_MARGIN - BTN_WIDTH, y, BACK, imgBack));
}

#undef BTN_WIDTH
#undef BTN_HEIGHT

#endif // HAS_UI_480x320
Loading

0 comments on commit 2e0a1f1

Please sign in to comment.