Move screen for Color UI (#19386)

This commit is contained in:
Victor Oliveira
2020-09-17 08:52:21 -03:00
committed by GitHub
parent 62206c0386
commit 5b56d6698a
15 changed files with 662 additions and 6 deletions

View File

@@ -291,6 +291,7 @@ void MarlinUI::draw_status_screen() {
offset += 32 - tft_string.width();
}
tft.add_text(455 - tft_string.width() - offset, 3, is_homed ? COLOR_AXIS_HOMED : COLOR_AXIS_NOT_HOMED, tft_string);
TERN_(TOUCH_SCREEN, touch.add_control(MOVE_AXIS, 4, 132, TFT_WIDTH - 8, 34));
// feed rate
tft.canvas(96, 180, 100, 32);
@@ -654,4 +655,438 @@ void menu_item(const uint8_t row, bool sel ) {
TERN_(TOUCH_SCREEN, touch.add_control(sel ? CLICK : MENU_ITEM, 0, 4 + 45 * row, TFT_WIDTH, 43, encoderTopLine + row));
}
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
#include "../../feature/babystep.h"
#endif
#if HAS_BED_PROBE
#include "../../module/probe.h"
#endif
#define Z_SELECTION_Z 1
#define Z_SELECTION_Z_PROBE -1
struct MotionAxisState {
xy_int_t xValuePos, yValuePos, zValuePos, eValuePos, stepValuePos, zTypePos, eNamePos;
float currentStepSize = 10.0;
int z_selection = Z_SELECTION_Z;
uint8_t e_selection = 0;
bool homming = false;
bool blocked = false;
char message[32];
};
MotionAxisState motionAxisState;
#define E_BTN_COLOR COLOR_YELLOW
#define X_BTN_COLOR COLOR_CORAL_RED
#define Y_BTN_COLOR COLOR_VIVID_GREEN
#define Z_BTN_COLOR COLOR_LIGHT_BLUE
#define BTN_WIDTH 64
#define BTN_HEIGHT 52
#define X_MARGIN 20
#define Y_MARGIN 15
static void quick_feedback() {
#if HAS_CHIRP
ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
#if BOTH(HAS_LCD_MENU, USE_BEEPER)
for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
#elif HAS_LCD_MENU
delay(10);
#endif
#endif
}
#define CUR_STEP_VALUE_WIDTH 104
static void drawCurStepValue() {
tft_string.set((uint8_t *)ftostr52sp(motionAxisState.currentStepSize));
tft_string.add("mm");
tft.canvas(motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
tft.add_text(tft_string.center(CUR_STEP_VALUE_WIDTH), 0, COLOR_AXIS_HOMED, tft_string);
}
static void drawCurZSelection() {
tft_string.set("Z");
tft.canvas(motionAxisState.zTypePos.x, motionAxisState.zTypePos.y, tft_string.width(), 34);
tft.set_background(COLOR_BACKGROUND);
tft.add_text(0, 0, Z_BTN_COLOR, tft_string);
tft.queue.sync();
tft_string.set("Offset");
tft.canvas(motionAxisState.zTypePos.x, motionAxisState.zTypePos.y + 34, tft_string.width(), 34);
tft.set_background(COLOR_BACKGROUND);
if (motionAxisState.z_selection == Z_SELECTION_Z_PROBE) {
tft.add_text(0, 0, Z_BTN_COLOR, tft_string);
}
}
static void drawCurESelection() {
tft.canvas(motionAxisState.eNamePos.x, motionAxisState.eNamePos.y, BTN_WIDTH, BTN_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
tft_string.set("E");
tft.add_text(0, 0, E_BTN_COLOR , tft_string);
tft.add_text(tft_string.width(), 0, E_BTN_COLOR, ui8tostr3rj(motionAxisState.e_selection));
}
static void drawMessage(const char *msg) {
tft.canvas(X_MARGIN, TFT_HEIGHT - Y_MARGIN - 34, TFT_HEIGHT / 2, 34);
tft.set_background(COLOR_BACKGROUND);
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
);
xy_int_t pos;
uint16_t color;
switch (axis) {
case X_AXIS: pos = motionAxisState.xValuePos; color = X_BTN_COLOR; break;
case Y_AXIS: pos = motionAxisState.yValuePos; color = Y_BTN_COLOR; break;
case Z_AXIS: pos = motionAxisState.zValuePos; color = Z_BTN_COLOR; break;
case E_AXIS: pos = motionAxisState.eValuePos; color = E_BTN_COLOR; break;
default: return;
}
tft.canvas(pos.x, pos.y, BTN_WIDTH + X_MARGIN, BTN_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
tft_string.set(ftostr52sp(value));
tft.add_text(0, 0, color, tft_string);
}
static void moveAxis(AxisEnum axis, const int8_t direction) {
quick_feedback();
if (axis == E_AXIS && thermalManager.temp_hotend[motionAxisState.e_selection].celsius < EXTRUDE_MINTEMP) {
drawMessage("Too cold");
return;
}
const float diff = motionAxisState.currentStepSize * direction;
if (axis == Z_AXIS && motionAxisState.z_selection == Z_SELECTION_Z_PROBE) {
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
const int16_t babystep_increment = direction * BABYSTEP_SIZE_Z;
const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || active_extruder == 0;
const float bsDiff = planner.steps_to_mm[Z_AXIS] * babystep_increment,
new_probe_offset = probe.offset.z + bsDiff,
new_offs = TERN(BABYSTEP_HOTEND_Z_OFFSET
, do_probe ? new_probe_offset : hotend_offset[active_extruder].z - bsDiff
, new_probe_offset
);
if (WITHIN(new_offs, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
babystep.add_steps(Z_AXIS, babystep_increment);
if (do_probe)
probe.offset.z = new_offs;
else
TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[active_extruder].z = new_offs, NOOP);
drawMessage(""); // clear the error
drawAxisValue(axis);
}
else {
drawMessage(GET_TEXT(MSG_LCD_SOFT_ENDSTOPS));
}
#elif HAS_BED_PROBE
// only change probe.offset.z
probe.offset.z += diff;
if (direction < 0 && current_position[axis] < Z_PROBE_OFFSET_RANGE_MIN) {
current_position[axis] = Z_PROBE_OFFSET_RANGE_MIN;
drawMessage(GET_TEXT(MSG_LCD_SOFT_ENDSTOPS));
}
else if (direction > 0 && current_position[axis] > Z_PROBE_OFFSET_RANGE_MAX) {
current_position[axis] = Z_PROBE_OFFSET_RANGE_MAX;
drawMessage(GET_TEXT(MSG_LCD_SOFT_ENDSTOPS));
}
else {
drawMessage(""); // clear the error
}
drawAxisValue(axis);
#endif
return;
}
if (!ui.manual_move.processing) {
// Start with no limits to movement
float min = current_position[axis] - 1000,
max = current_position[axis] + 1000;
// Limit to software endstops, if enabled
#if HAS_SOFTWARE_ENDSTOPS
if (soft_endstops_enabled) switch (axis) {
case X_AXIS:
TERN_(MIN_SOFTWARE_ENDSTOP_X, min = soft_endstop.min.x);
TERN_(MAX_SOFTWARE_ENDSTOP_X, max = soft_endstop.max.x);
break;
case Y_AXIS:
TERN_(MIN_SOFTWARE_ENDSTOP_Y, min = soft_endstop.min.y);
TERN_(MAX_SOFTWARE_ENDSTOP_Y, max = soft_endstop.max.y);
break;
case Z_AXIS:
TERN_(MIN_SOFTWARE_ENDSTOP_Z, min = soft_endstop.min.z);
TERN_(MAX_SOFTWARE_ENDSTOP_Z, max = soft_endstop.max.z);
default: break;
}
#endif // HAS_SOFTWARE_ENDSTOPS
// Delta limits XY based on the current offset from center
// This assumes the center is 0,0
#if ENABLED(DELTA)
if (axis != Z_AXIS && axis != E_AXIS) {
max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis
min = -max;
}
#endif
// Get the new position
#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]);
#else
current_position[axis] += diff;
if (direction < 0 && current_position[axis] < min) {
current_position[axis] = min;
drawMessage(GET_TEXT(MSG_LCD_SOFT_ENDSTOPS));
}
else if (direction > 0 && current_position[axis] > max) {
current_position[axis] = max;
drawMessage(GET_TEXT(MSG_LCD_SOFT_ENDSTOPS));
}
else {
drawMessage(""); // clear the error
}
#endif
ui.manual_move.soon(axis
#if MULTI_MANUAL
, motionAxisState.e_selection
#endif
);
}
drawAxisValue(axis);
}
static void e_plus() {
moveAxis(E_AXIS, 1);
}
static void e_minus() {
moveAxis(E_AXIS, -1);
}
static void x_minus() {
moveAxis(X_AXIS, -1);
}
static void x_plus() {
moveAxis(X_AXIS, 1);
}
static void y_plus() {
moveAxis(Y_AXIS, 1);
}
static void y_minus() {
moveAxis(Y_AXIS, -1);
}
static void z_plus() {
moveAxis(Z_AXIS, 1);
}
static void z_minus() {
moveAxis(Z_AXIS, -1);
}
static void e_select() {
motionAxisState.e_selection++;
if (motionAxisState.e_selection >= EXTRUDERS) {
motionAxisState.e_selection = 0;
}
quick_feedback();
drawCurESelection();
drawAxisValue(E_AXIS);
}
static void do_home() {
quick_feedback();
drawMessage(GET_TEXT(MSG_LEVEL_BED_HOMING));
queue.inject_P(G28_STR);
// Disable touch until home is done
touch.disable();
drawAxisValue(E_AXIS);
drawAxisValue(X_AXIS);
drawAxisValue(Y_AXIS);
drawAxisValue(Z_AXIS);
}
static void step_size() {
motionAxisState.currentStepSize = motionAxisState.currentStepSize / 10.0;
if (motionAxisState.currentStepSize < 0.0015) motionAxisState.currentStepSize = 10.0;
quick_feedback();
drawCurStepValue();
}
#if HAS_BED_PROBE
static void z_select() {
motionAxisState.z_selection *= -1;
quick_feedback();
drawCurZSelection();
drawAxisValue(Z_AXIS);
}
#endif
static void disable_steppers() {
quick_feedback();
queue.inject_P(PSTR("M84"));
}
static void drawBtn(int x, int y, const char* label, int32_t data, MarlinImage img, uint16_t bgColor, bool enabled = true) {
uint16_t width = Images[imgBtn52Rounded].width;
uint16_t height = Images[imgBtn52Rounded].height;
tft.queue.sync(); //need sync to change font
if (!enabled) bgColor = COLOR_CONTROL_DISABLED;
tft.canvas(x, y, width, height);
tft.set_background(COLOR_BACKGROUND);
tft.add_image(0, 0, imgBtn52Rounded, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY);
if (label != NULL) {
tft.set_font(Helvetica12Bold);
tft_string.set_font(Helvetica12Bold);
tft_string.set(label);
tft_string.trim();
tft.add_text(tft_string.center(width), height / 2 - tft_string.font_height() / 2, bgColor, tft_string);
tft.queue.sync();
tft_string.set_font(Helvetica18);
tft.set_font(Helvetica18);
}
else {
tft.add_image(0, 0, img, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY);
}
if (enabled) touch.add_control(BUTTON, x, y, width, height, data);
}
void MarlinUI::move_axis_screen() {
// Reset
motionAxisState.blocked = false;
touch.enable();
ui.clear_lcd();
TERN_(TOUCH_SCREEN, touch.clear());
const bool busy = printingIsActive();
// if we have baby step and we are printing, select baby step
if (busy && ENABLED(BABYSTEP_ZPROBE_OFFSET)) motionAxisState.z_selection = Z_SELECTION_Z_PROBE;
// ROW 1 -> E- Y- CurY Z+
int x = X_MARGIN, y = Y_MARGIN, spacing = 0;
drawBtn(x, y, "E+", (int32_t)e_plus, imgUp, E_BTN_COLOR, !busy);
spacing = (TFT_WIDTH - X_MARGIN * 2 - 3 * BTN_WIDTH) / 2;
x += BTN_WIDTH + spacing;
drawBtn(x, y, "Y+", (int32_t)y_plus, imgUp, Y_BTN_COLOR, !busy);
// Cur Y
x += BTN_WIDTH;
motionAxisState.yValuePos.x = x + 2;
motionAxisState.yValuePos.y = y;
drawAxisValue(Y_AXIS);
x += spacing;
drawBtn(x, y, "Z+", (int32_t)z_plus, imgUp, Z_BTN_COLOR, !busy || ENABLED(BABYSTEP_ZPROBE_OFFSET)); //only enabled when not busy or have baby step
// ROW 2 -> "Ex" X- HOME X+ "Z"
y += BTN_HEIGHT + (TFT_HEIGHT - Y_MARGIN * 2 - 4 * BTN_HEIGHT) / 3;
x = X_MARGIN;
spacing = (TFT_WIDTH - X_MARGIN * 2 - 5 * BTN_WIDTH) / 4;
motionAxisState.eNamePos.x = x;
motionAxisState.eNamePos.y = y;
drawCurESelection();
if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, (int32_t)e_select);
x += BTN_WIDTH + spacing;
drawBtn(x, y, "X-", (int32_t)x_minus, imgLeft, X_BTN_COLOR, !busy);
x += BTN_WIDTH + spacing; //imgHome is 64x64
add_control(TFT_WIDTH / 2 - Images[imgHome].width / 2, y - (Images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, (int32_t)do_home, imgHome, !busy);
x += BTN_WIDTH + spacing;
uint16_t xplus_x = x;
drawBtn(x, y, "X+", (int32_t)x_plus, imgRight, X_BTN_COLOR, !busy);
x += BTN_WIDTH + spacing;
motionAxisState.zTypePos.x = x;
motionAxisState.zTypePos.y = y;
drawCurZSelection();
#if HAS_BED_PROBE
if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, 34 * 2, (int32_t)z_select);
#endif
// ROW 3 -> E- CurX Y- Z-
y += BTN_HEIGHT + (TFT_HEIGHT - Y_MARGIN * 2 - 4 * BTN_HEIGHT) / 3;
x = X_MARGIN;
spacing = (TFT_WIDTH - X_MARGIN * 2 - 3 * BTN_WIDTH) / 2;
drawBtn(x, y, "E-", (int32_t)e_minus, imgDown, E_BTN_COLOR, !busy);
// Cur E
motionAxisState.eValuePos.x = x;
motionAxisState.eValuePos.y = y + BTN_HEIGHT + 2;
drawAxisValue(E_AXIS);
// Cur X
motionAxisState.xValuePos.x = BTN_WIDTH + (TFT_WIDTH - X_MARGIN * 2 - 5 * BTN_WIDTH) / 4; //X- pos
motionAxisState.xValuePos.y = y - 10;
drawAxisValue(X_AXIS);
x += BTN_WIDTH + spacing;
drawBtn(x, y, "Y-", (int32_t)y_minus, imgDown, Y_BTN_COLOR, !busy);
x += BTN_WIDTH + spacing;
drawBtn(x, y, "Z-", (int32_t)z_minus, imgDown, Z_BTN_COLOR, !busy || ENABLED(BABYSTEP_ZPROBE_OFFSET)); //only enabled when not busy or have baby step
// Cur Z
motionAxisState.zValuePos.x = x;
motionAxisState.zValuePos.y = y + BTN_HEIGHT + 2;
drawAxisValue(Z_AXIS);
// ROW 4 -> step_size disable steppers back
y = TFT_HEIGHT - Y_MARGIN - 32; //
x = TFT_WIDTH / 2 - CUR_STEP_VALUE_WIDTH / 2;
motionAxisState.stepValuePos.x = x;
motionAxisState.stepValuePos.y = y;
if (!busy) {
drawCurStepValue();
touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (int32_t)step_size);
}
// alinged with x+
drawBtn(xplus_x, TFT_HEIGHT - Y_MARGIN - BTN_HEIGHT, "off", (int32_t)disable_steppers, imgCancel, COLOR_WHITE, !busy);
add_control(TFT_WIDTH - X_MARGIN - BTN_WIDTH, y, BACK, imgBack);
}
#undef BTN_WIDTH
#undef BTN_HEIGHT
#endif // HAS_UI_480x320