Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and enhance FTDI EVE Touch UI #22047

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ namespace FTDI_FT810 {
namespace FTDI {
constexpr uint8_t ARGB1555 = 0;
constexpr uint8_t L1 = 1;
constexpr uint8_t L2 = 17;
constexpr uint8_t L4 = 2;
constexpr uint8_t L8 = 3;
constexpr uint8_t RGB332 = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ namespace FTDI {
inline uint32_t CLEAR_COLOR_A(uint8_t alpha) {return DL::CLEAR_COLOR_A|(alpha&255UL);}
inline uint32_t CLEAR_COLOR_RGB(uint8_t red, uint8_t green, uint8_t blue)
{return DL::CLEAR_COLOR_RGB|((red&255UL)<<16)|((green&255UL)<<8)|(blue&255UL);}
inline uint32_t CLEAR_COLOR_RGB(uint32_t rgb) {return DL::CLEAR_COLOR_RGB|rgb;}
inline uint32_t CLEAR_COLOR_RGB(uint32_t rgb) {return DL::CLEAR_COLOR_RGB|(rgb&0xFFFFFF);}
inline uint32_t CLEAR_STENCIL(uint8_t s) {return DL::CLEAR_STENCIL|(s&255UL);}
inline uint32_t CLEAR_TAG(uint8_t s) {return DL::CLEAR_TAG|(s&255UL);}
inline uint32_t COLOR_A(uint8_t alpha) {return DL::COLOR_A|(alpha&255UL);}
inline uint32_t COLOR_MASK(bool r, bool g, bool b, bool a) {return DL::COLOR_MASK|((r?1UL:0UL)<<3)|((g?1UL:0UL)<<2)|((b?1UL:0UL)<<1)|(a?1UL:0UL);}
inline uint32_t COLOR_RGB(uint8_t red,uint8_t green,uint8_t blue)
{return DL::COLOR_RGB|((red&255UL)<<16)|((green&255UL)<<8)|(blue&255UL);}
inline uint32_t COLOR_RGB(uint32_t rgb) {return DL::COLOR_RGB|rgb;}
inline uint32_t COLOR_RGB(uint32_t rgb) {return DL::COLOR_RGB|(rgb&0xFFFFFF);}
/* inline uint32_t DISPLAY() {return (0UL<<24)) */
inline uint32_t END() {return DL::END;}
inline uint32_t JUMP(uint16_t dest) {return DL::JUMP|(dest&65535UL);}
Expand Down
24 changes: 22 additions & 2 deletions Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,31 @@
#define pgm_read_ptr_far pgm_read_ptr
#endif

// Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
#define _NUM_ARGS(_,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
#define NUM_ARGS(V...) _NUM_ARGS(0,V,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)

// SERIAL_ECHOPAIR / SERIAL_ECHOPAIR_P is used to output a key value pair. The key must be a string and the value can be anything
// Print up to 12 pairs of values. Odd elements auto-wrapped in PSTR().
#define __SEP_N(N,V...) _SEP_##N(V)
#define _SEP_N(N,V...) __SEP_N(N,V)
#define _SEP_1(PRE) SERIAL_ECHOPGM(PRE)
#define _SEP_2(PRE,V) do{ Serial.print(F(PRE)); Serial.print(V); }while(0)
#define _SEP_3(a,b,c) do{ _SEP_2(a,b); SERIAL_ECHOPGM(c); }while(0)
#define _SEP_4(a,b,V...) do{ _SEP_2(a,b); _SEP_2(V); }while(0)

// Print up to 1 pairs of values followed by newline
#define __SELP_N(N,V...) _SELP_##N(V)
#define _SELP_N(N,V...) __SELP_N(N,V)
#define _SELP_1(PRE) SERIAL_ECHOLNPGM(PRE)
#define _SELP_2(PRE,V) do{ Serial.print(F(PRE)); Serial.println(V); }while(0)
#define _SELP_3(a,b,c) do{ _SEP_2(a,b); SERIAL_ECHOLNPGM(c); }while(0)
#define _SELP_4(a,b,V...) do{ _SEP_2(a,b); _SELP_2(V); }while(0)
#define SERIAL_ECHO_START()
#define SERIAL_ECHOLNPGM(str) Serial.println(F(str))
#define SERIAL_ECHOPGM(str) Serial.print(F(str))
#define SERIAL_ECHO_MSG(str) Serial.println(str)
#define SERIAL_ECHOLNPAIR(str, val) do{ Serial.print(F(str)); Serial.println(val); }while(0)
#define SERIAL_ECHO_MSG(V...) SERIAL_ECHOLNPAIR(V)
#define SERIAL_ECHOLNPAIR(V...) _SELP_N(NUM_ARGS(V),V)
#define SERIAL_ECHOPAIR(str, val) do{ Serial.print(F(str)); Serial.print(val); }while(0)

#define safe_delay delay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,16 @@
CommandProcessor::btn_style_func_t *CommandProcessor::_btn_style_callback = CommandProcessor::default_button_style_func;
bool CommandProcessor::is_tracking = false;

uint32_t CommandProcessor::memcrc(uint32_t ptr, uint32_t num) {
const uint16_t x = CLCD::mem_read_16(CLCD::REG::CMD_WRITE);
memcrc(ptr, num, 0);
wait();
return CLCD::mem_read_32(CLCD::MAP::RAM_CMD + x + 12);
}

bool CommandProcessor::wait() {
while (is_processing() && !has_fault()) { /* nada */ }
return !has_fault();
}

#endif // FTDI_EXTENDED
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ class CommandProcessor : public CLCD::CommandFifo {
return *this;
}

bool wait();
uint32_t memcrc(uint32_t ptr, uint32_t num);

// Wrap all the CommandFifo routines to allow method chaining

inline CommandProcessor& cmd (uint32_t cmd32) {CLCD::CommandFifo::cmd(cmd32); return *this;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,25 @@
#define MARGIN_DEFAULT 3
#endif

// EDGE_R adds some black space on the right edge of the display
// This shifts some of the screens left to visually center them.
// The EDGE variables adds some space on the edges of the display

#define EDGE_T 0
#define EDGE_B 0
#define EDGE_L 0
#define EDGE_R 0

// GRID_X and GRID_Y computes the positions of the divisions on
// the layout grid.
#define GRID_X(x) ((x)*(FTDI::display_width-EDGE_R)/GRID_COLS)
#define GRID_Y(y) ((y)*FTDI::display_height/GRID_ROWS)
#define GRID_X(x) ((x)*(FTDI::display_width-EDGE_R-EDGE_L)/GRID_COLS+EDGE_L)
#define GRID_Y(y) ((y)*(FTDI::display_height-EDGE_B-EDGE_T)/GRID_ROWS+EDGE_T)

// BTN_X, BTN_Y, BTN_W and BTN_X returns the top-left and width
// and height of a button, taking into account the button margins.

#define BTN_X(x) (GRID_X((x)-1) + MARGIN_L)
#define BTN_Y(y) (GRID_Y((y)-1) + MARGIN_T)
#define BTN_W(w) (GRID_X(w) - MARGIN_L - MARGIN_R)
#define BTN_H(h) (GRID_Y(h) - MARGIN_T - MARGIN_B)
#define BTN_W(w) (GRID_X(w) - GRID_X(0) - MARGIN_L - MARGIN_R)
#define BTN_H(h) (GRID_Y(h) - GRID_Y(0) - MARGIN_T - MARGIN_B)

// Abbreviations for common phrases, to allow a button to be
// defined in one line of source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ namespace FTDI {
if (font == 26) break;
}

const uint16_t dx = (options & OPT_RIGHTX) ? w : (options & OPT_CENTERX) ? w/2 : 0;
const uint16_t dy = (options & OPT_CENTERY) ? (h - box_height)/2 : 0;
const uint16_t dx = (options & OPT_RIGHTX) ? w :
(options & OPT_CENTERX) ? w/2 : 0;
const uint16_t dy = (options & OPT_BOTTOMY) ? (h - box_height) :
(options & OPT_CENTERY) ? (h - box_height)/2 : 0;

const char *line_start = str;
const char *line_end;
Expand All @@ -105,11 +107,11 @@ namespace FTDI {

#if ENABLED(TOUCH_UI_USE_UTF8)
if (has_utf8_chars(line)) {
draw_utf8_text(cmd, x + dx, y + dy, line, fm.fs, options & ~OPT_CENTERY);
draw_utf8_text(cmd, x + dx, y + dy, line, fm.fs, options & ~(OPT_CENTERY | OPT_BOTTOMY));
} else
#endif
{
cmd.CLCD::CommandFifo::text(x + dx, y + dy, font, options & ~OPT_CENTERY);
cmd.CLCD::CommandFifo::text(x + dx, y + dy, font, options & ~(OPT_CENTERY | OPT_BOTTOMY));
cmd.CLCD::CommandFifo::str(line);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* This function draws text inside a bounding box, doing word wrapping and using the largest font that will fit.
*/
namespace FTDI {
constexpr uint16_t OPT_BOTTOMY = 0x1000; // Non-standard

void draw_text_box(class CommandProcessor& cmd, int x, int y, int w, int h, progmem_str str, uint16_t options = 0, uint8_t font = 31);
void draw_text_box(class CommandProcessor& cmd, int x, int y, int w, int h, const char *str, uint16_t options = 0, uint8_t font = 31);
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@
*/

void FTDI::load_utf8_bitmaps(CommandProcessor &cmd) {
cmd.cmd(SAVE_CONTEXT());
#ifdef TOUCH_UI_UTF8_CYRILLIC_CHARSET
CyrillicCharSet::load_bitmaps(cmd);
#endif
#ifdef TOUCH_UI_UTF8_WESTERN_CHARSET
WesternCharSet::load_bitmaps(cmd);
#endif
StandardCharSet::load_bitmaps(cmd);
cmd.cmd(RESTORE_CONTEXT());
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ BaseNumericAdjustmentScreen::widgets_t::widgets_t(draw_mode_t what) : _what(what
.cmd(COLOR_RGB(bg_text_enabled))
.tag(0);
}
else
cmd.colors(normal_btn);

cmd.font(font_medium);
_button(cmd, 1,
Expand Down Expand Up @@ -319,7 +321,7 @@ void BaseNumericAdjustmentScreen::widgets_t::toggle(uint8_t tag, progmem_str lab
}

if (_what & FOREGROUND) {
_button_style(cmd, BTN_TOGGLE);
_button_style(cmd, is_enabled ? BTN_TOGGLE : BTN_DISABLED);
cmd.tag(is_enabled ? tag : 0)
.enabled(is_enabled)
.font(font_small)
Expand Down
19 changes: 12 additions & 7 deletions Marlin/src/lcd/extui/ftdi_eve_touch_ui/screens/bed_mesh_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,18 @@ void BedMeshBase::_drawMesh(CommandProcessor &cmd, int16_t x, int16_t y, int16_t
if (ISVAL(x,y)) {
if (opts & USE_COLORS) {
const float val_dev = sq(VALUE(x, y) - val_mean);
uint8_t r = 0, b = 0;
//*(VALUE(x, y) < 0 ? &r : &b) = val_dev / sq_min * 0xFF;
if (VALUE(x, y) < 0)
r = val_dev / sq_min * 0xFF;
else
b = val_dev / sq_max * 0xFF;
cmd.cmd(COLOR_RGB(0xFF - b, 0xFF - b - r, 0xFF - r));
float r = 0, b = 0;
if (sq_min != sq_max) {
if (VALUE(x, y) < 0)
r = val_dev / sq_min;
else
b = val_dev / sq_max;
}
#ifdef BED_MESH_POINTS_GRAY
cmd.cmd(COLOR_RGB((1.0f - b + r) * 0x7F, (1.0f - b - r) * 0x7F, (1.0f - r + b) * 0x7F));
#else
cmd.cmd(COLOR_RGB((1.0f - b) * 0xFF, (1.0f - b - r) * 0xFF, (1.0f - r) * 0xFF));
#endif
}
cmd.cmd(VERTEX2F(TRANSFORM(x, y, HEIGHT(x, y))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,17 @@ void BedMeshEditScreen::onEntry() {
mydata.zAdjustment = 0;
mydata.savedMeshLevelingState = ExtUI::getLevelingActive();
mydata.savedEndstopState = ExtUI::getSoftEndstopState();
makeMeshValid();
BaseScreen::onEntry();
}

void BedMeshEditScreen::makeMeshValid() {
bed_mesh_t &mesh = ExtUI::getMeshArray();
GRID_LOOP(x, y) {
if (isnan(mesh[x][y])) mesh[x][y] = 0;
}
}

void BedMeshEditScreen::onExit() {
ExtUI::setLevelingActive(mydata.savedMeshLevelingState);
ExtUI::setSoftEndstopState(mydata.savedEndstopState);
Expand Down Expand Up @@ -121,8 +129,9 @@ bool BedMeshEditScreen::changeHighlightedValue(uint8_t tag) {
void BedMeshEditScreen::drawHighlightedPointValue() {
CommandProcessor cmd;
cmd.font(Theme::font_medium)
.colors(normal_btn)
.cmd(COLOR_RGB(bg_text_enabled))
.text(Z_LABEL_POS, GET_TEXT_F(MSG_MESH_EDIT_Z))
.colors(normal_btn)
.font(font_small);
if (mydata.highlight.x != NONE)
draw_adjuster(cmd, Z_VALUE_POS, 3, getHighlightedValue(), GET_TEXT_F(MSG_UNITS_MM), 4, 3);
Expand Down Expand Up @@ -187,7 +196,8 @@ void BedMeshEditScreen::show() {
// After the spinner, go to this screen.
current_screen.forget();
PUSH_SCREEN(BedMeshEditScreen);
} else {
}
else {
injectCommands_P(PSTR("G29 S1"));
GOTO_SCREEN(BedMeshEditScreen);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct BedMeshEditScreenData {

class BedMeshEditScreen : public BedMeshBase, public CachedScreen<BED_MESH_EDIT_SCREEN_CACHE> {
private:
static void makeMeshValid();
static float getHighlightedValue();
static void setHighlightedValue(float value);
static void moveToHighlightedValue();
Expand Down