Skip to content

Commit

Permalink
🚸 ColorUI Touch Calibrate in CW order
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 21, 2023
1 parent 6bc4230 commit a0e3dea
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 44 deletions.
6 changes: 3 additions & 3 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@
FORCE_INLINE constexpr T operator|(T x, T y) { return static_cast<T>(static_cast<int>(x) | static_cast<int>(y)); } \
FORCE_INLINE constexpr T operator^(T x, T y) { return static_cast<T>(static_cast<int>(x) ^ static_cast<int>(y)); } \
FORCE_INLINE constexpr T operator~(T x) { return static_cast<T>(~static_cast<int>(x)); } \
FORCE_INLINE T & operator&=(T &x, T y) { return x &= y; } \
FORCE_INLINE T & operator|=(T &x, T y) { return x |= y; } \
FORCE_INLINE T & operator^=(T &x, T y) { return x ^= y; }
FORCE_INLINE T & operator&=(T &x, T y) { x = x & y; return x; } \
FORCE_INLINE T & operator|=(T &x, T y) { x = x | y; return x; } \
FORCE_INLINE T & operator^=(T &x, T y) { x = x ^ y; return x; }

// C++11 solution that is standard compliant. <type_traits> is not available on all platform
namespace Private {
Expand Down
12 changes: 7 additions & 5 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -1782,20 +1782,22 @@
#define HAS_UI_1024x600 1
#endif

// Number of text lines the screen can display (may depend on font used)
// Touch screens leave space for extra buttons at the bottom
#if ANY(HAS_UI_320x240, HAS_UI_480x272)
#if ENABLED(TFT_COLOR_UI_PORTRAIT)
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 8, 9) // Fewer lines with touch buttons onscreen
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 8, 9)
#else
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) // Fewer lines with touch buttons onscreen
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
#endif
#elif HAS_UI_480x320
#if ENABLED(TFT_COLOR_UI_PORTRAIT)
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 9, 10) // Fewer lines with touch buttons onscreen
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 9, 10)
#else
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) // Fewer lines with touch buttons onscreen
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
#endif
#elif HAS_UI_1024x600
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 12, 13) // Fewer lines with touch buttons onscreen
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 12, 13)
#endif

// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ void MarlinUI::draw_status_message(const bool blink) {
}

#if HAS_PRINT_PROGRESS

#define TPOFFSET (LCD_WIDTH - 1)
static uint8_t timepos = TPOFFSET - 6;
static char buffer[8];
Expand Down Expand Up @@ -837,6 +838,7 @@ void MarlinUI::draw_status_message(const bool blink) {
}
}
#endif

#endif // HAS_PRINT_PROGRESS

/**
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const

#endif // HAS_CUTTER


#if HAS_PRINT_PROGRESS // UNTESTED!!!

#define TPOFFSET (LCD_WIDTH - 1)
static uint8_t timepos = TPOFFSET - 6;

Expand Down Expand Up @@ -648,6 +648,7 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
}
}
#endif

#endif // HAS_PRINT_PROGRESS

#if ENABLED(LCD_PROGRESS_BAR)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/dogm/status_screen_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ void MarlinUI::draw_status_screen() {
u8g.drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, 2);

// Progress strings
if (PAGE_CONTAINS(EXTRAS_BASELINE - INFO_FONT_ASCENT, EXTRAS_BASELINE - 1)){
if (PAGE_CONTAINS(EXTRAS_BASELINE - INFO_FONT_ASCENT, EXTRAS_BASELINE - 1)) {
ui.rotate_progress();
lcd_put_u8str(PROGRESS_BAR_X, EXTRAS_BASELINE, bufferc);
}
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,19 +510,19 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT,
}
else {
// clear last cross
x = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_RIGHT)].x;
y = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_RIGHT)].y;
x = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_LEFT)].x;
y = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_LEFT)].y;
drawCross(x, y, TFT_MARLINBG_COLOR);
}

FSTR_P str = nullptr;
if (stage < CALIBRATION_SUCCESS) {
// handle current state
switch (stage) {
case CALIBRATION_TOP_LEFT: str = GET_TEXT_F(MSG_TOP_LEFT); break;
case CALIBRATION_BOTTOM_LEFT: str = GET_TEXT_F(MSG_BOTTOM_LEFT); break;
case CALIBRATION_TOP_RIGHT: str = GET_TEXT_F(MSG_TOP_RIGHT); break;
case CALIBRATION_TOP_LEFT: str = GET_TEXT_F(MSG_TOP_LEFT); break;
case CALIBRATION_TOP_RIGHT: str = GET_TEXT_F(MSG_TOP_RIGHT); break;
case CALIBRATION_BOTTOM_RIGHT: str = GET_TEXT_F(MSG_BOTTOM_RIGHT); break;
case CALIBRATION_BOTTOM_LEFT: str = GET_TEXT_F(MSG_BOTTOM_LEFT); break;
default: break;
}

Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra

case MLEVEL_BL:
if (draw)
drawMenuItem(row, ICON_AxisBL, F("Bottom Left"));
drawMenuItem(row, ICON_AxisBL, GET_TEXT_F(MSG_BOTTOM_LEFT));
else {
popupHandler(Popup_MoveWait);
if (use_probe) {
Expand All @@ -1443,7 +1443,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
break;
case MLEVEL_TL:
if (draw)
drawMenuItem(row, ICON_AxisTL, F("Top Left"));
drawMenuItem(row, ICON_AxisTL, GET_TEXT_F(MSG_TOP_LEFT));
else {
popupHandler(Popup_MoveWait);
if (use_probe) {
Expand All @@ -1466,7 +1466,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
break;
case MLEVEL_TR:
if (draw)
drawMenuItem(row, ICON_AxisTR, F("Top Right"));
drawMenuItem(row, ICON_AxisTR, GET_TEXT_F(MSG_TOP_RIGHT));
else {
popupHandler(Popup_MoveWait);
if (use_probe) {
Expand All @@ -1489,7 +1489,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
break;
case MLEVEL_BR:
if (draw)
drawMenuItem(row, ICON_AxisBR, F("Bottom Right"));
drawMenuItem(row, ICON_AxisBR, GET_TEXT_F(MSG_BOTTOM_RIGHT));
else {
popupHandler(Popup_MoveWait);
if (use_probe) {
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/anycubic_vyper/vyper_extui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ namespace ExtUI {
void onPrintTimerStopped() { dgus.timerEvent(AC_timer_stopped); }
void onPrintDone() {}

void onFilamentRunout(const extruder_t) { dgus.filamentRunout(); }
void onFilamentRunout(const extruder_t) { dgus.filamentRunout(); }

void onUserConfirmRequired(const char * const msg) { dgus.confirmationRequest(msg); }
void onStatusChanged(const char * const msg) { dgus.statusChange(msg); }
void onUserConfirmRequired(const char * const msg) { dgus.confirmationRequest(msg); }
void onStatusChanged(const char * const msg) { dgus.statusChange(msg); }

void onHomingStart() { dgus.homingStart(); }
void onHomingDone() { dgus.homingComplete(); }
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/mks_ui/draw_touch_calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ void lv_update_touch_calibration_screen() {
}
else {
// clear last cross
x = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_RIGHT)].x;
y = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_RIGHT)].y;
x = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_LEFT)].x;
y = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_LEFT)].y;
drawCross(x, y, LV_COLOR_BACKGROUND.full);
}

Expand All @@ -72,9 +72,9 @@ void lv_update_touch_calibration_screen() {
// handle current state
switch (stage) {
case CALIBRATION_TOP_LEFT: str = GET_TEXT(MSG_TOP_LEFT); break;
case CALIBRATION_BOTTOM_LEFT: str = GET_TEXT(MSG_BOTTOM_LEFT); break;
case CALIBRATION_TOP_RIGHT: str = GET_TEXT(MSG_TOP_RIGHT); break;
case CALIBRATION_BOTTOM_RIGHT: str = GET_TEXT(MSG_BOTTOM_RIGHT); break;
case CALIBRATION_BOTTOM_LEFT: str = GET_TEXT(MSG_BOTTOM_LEFT); break;
default: break;
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ static bool get_point(int16_t *x, int16_t *y) {

#if ENABLED(TOUCH_SCREEN_CALIBRATION)
const calibrationState state = touch_calibration.get_calibration_state();
if (state >= CALIBRATION_TOP_LEFT && state <= CALIBRATION_BOTTOM_RIGHT) {
if (WITHIN(state, CALIBRATION_TOP_LEFT, CALIBRATION_BOTTOM_LEFT)) {
if (touch_calibration.handleTouch(*x, *y)) lv_update_touch_calibration_screen();
return false;
}
Expand Down
5 changes: 4 additions & 1 deletion Marlin/src/lcd/tft/tft_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ class TFT_String {
static uint16_t *string() { return data; }
static uint16_t width() { return span; }
static uint16_t center(const uint16_t width) { return span > width ? 0 : (width - span) / 2; }
static uint16_t vcenter(const uint16_t height) { return (height + font_header->capitalAHeight + 1) / 2 > font_header->fontAscent ? (height + font_header->capitalAHeight + 1) / 2 - font_header->fontAscent : 0 ; }
static uint16_t vcenter(const uint16_t height) {
const uint16_t mid = (height + font_header->capitalAHeight + 1) / 2;
return mid > font_header->fontAscent ? mid - font_header->fontAscent : 0;
}
};

extern TFT_String tft_string;
10 changes: 5 additions & 5 deletions Marlin/src/lcd/tft/ui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ void MarlinUI::clear_lcd() {
stage = touch_calibration.calibration_start();
}
else {
x = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_RIGHT)].x;
y = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_RIGHT)].y;
x = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_LEFT)].x;
y = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_LEFT)].y;
tft.canvas(x - 15, y - 15, 31, 31);
tft.set_background(COLOR_BACKGROUND);
}
Expand All @@ -450,10 +450,10 @@ void MarlinUI::clear_lcd() {

if (stage < CALIBRATION_SUCCESS) {
switch (stage) {
case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break;
case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break;
case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break;
case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break;
case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break;
case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break;
case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break;
default: break;
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/tft/ui_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void disable_steppers();
bool lcd_sleep_task();
#endif

void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater);
void draw_heater_status(uint16_t x, uint16_t y, const int8_t heater);
void draw_fan_status(uint16_t x, uint16_t y, const bool blink);

void text_line(const uint16_t y, uint16_t color=COLOR_BACKGROUND);
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/tft_io/touch_calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ bool TouchCalibration::handleTouch(const uint16_t x, const uint16_t y) {
}

switch (calibration_state) {
case CALIBRATION_TOP_LEFT: calibration_state = CALIBRATION_BOTTOM_LEFT; break;
case CALIBRATION_BOTTOM_LEFT: calibration_state = CALIBRATION_TOP_RIGHT; break;
case CALIBRATION_TOP_LEFT: calibration_state = CALIBRATION_TOP_RIGHT; break;
case CALIBRATION_TOP_RIGHT: calibration_state = CALIBRATION_BOTTOM_RIGHT; break;
case CALIBRATION_BOTTOM_RIGHT: validate_calibration(); break;
case CALIBRATION_BOTTOM_RIGHT: calibration_state = CALIBRATION_BOTTOM_LEFT; break;
case CALIBRATION_BOTTOM_LEFT: validate_calibration(); break;
default: break;
}

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/tft_io/touch_calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ typedef struct __attribute__((__packed__)) {

enum calibrationState : uint8_t {
CALIBRATION_TOP_LEFT = 0x00,
CALIBRATION_BOTTOM_LEFT,
CALIBRATION_TOP_RIGHT,
CALIBRATION_BOTTOM_RIGHT,
CALIBRATION_BOTTOM_LEFT,
CALIBRATION_SUCCESS,
CALIBRATION_FAIL,
CALIBRATION_NONE,
Expand Down Expand Up @@ -73,12 +73,12 @@ class TouchCalibration {
calibration_state = CALIBRATION_TOP_LEFT;
calibration_points[CALIBRATION_TOP_LEFT].x = 30;
calibration_points[CALIBRATION_TOP_LEFT].y = 30;
calibration_points[CALIBRATION_BOTTOM_LEFT].x = 30;
calibration_points[CALIBRATION_BOTTOM_LEFT].y = TFT_HEIGHT - 31;
calibration_points[CALIBRATION_TOP_RIGHT].x = TFT_WIDTH - 31;
calibration_points[CALIBRATION_TOP_RIGHT].y = 30;
calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 31;
calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 31;
calibration_points[CALIBRATION_BOTTOM_LEFT].x = 30;
calibration_points[CALIBRATION_BOTTOM_LEFT].y = TFT_HEIGHT - 31;
failed_count = 0;
return calibration_state;
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/touch/touch_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ uint8_t TouchButtons::read_buttons() {

#if ENABLED(TOUCH_SCREEN_CALIBRATION)
const calibrationState state = touch_calibration.get_calibration_state();
if (WITHIN(state, CALIBRATION_TOP_LEFT, CALIBRATION_BOTTOM_RIGHT)) {
if (WITHIN(state, CALIBRATION_TOP_LEFT, CALIBRATION_BOTTOM_LEFT)) {
if (touch_calibration.handleTouch(x, y)) ui.refresh();
return 0;
}
Expand Down
10 changes: 6 additions & 4 deletions Marlin/src/libs/W25Qxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ void W25QXXFlash::init(uint8_t spiRate) {
* STM32F1 has 3 SPI ports, SPI1 in APB2, SPI2/SPI3 in APB1
* so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
*/
#if SPI_DEVICE == 1
#define SPI_CLOCK_MAX SPI_CLOCK_DIV4
#else
#define SPI_CLOCK_MAX SPI_CLOCK_DIV2
#ifndef SPI_CLOCK_MAX
#if SPI_DEVICE == 1
#define SPI_CLOCK_MAX SPI_CLOCK_DIV4
#else
#define SPI_CLOCK_MAX SPI_CLOCK_DIV2
#endif
#endif
uint8_t clock;
switch (spiRate) {
Expand Down

0 comments on commit a0e3dea

Please sign in to comment.