📺 Fix and enhance FTDI EVE Touch UI (#22047)

This commit is contained in:
Marcio T 2021-06-04 23:35:05 -06:00 committed by Scott Lahteine
parent b4b607681c
commit f5f999d7bf
14 changed files with 86 additions and 132 deletions

View file

@ -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;

View file

@ -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);}

View file

@ -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

View file

@ -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

View file

@ -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;}

View file

@ -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.

View file

@ -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;
@ -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);
}
}

View file

@ -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);
}

View file

@ -138,6 +138,7 @@
*/
void FTDI::load_utf8_bitmaps(CommandProcessor &cmd) {
cmd.cmd(SAVE_CONTEXT());
#ifdef TOUCH_UI_UTF8_CYRILLIC_CHARSET
CyrillicCharSet::load_bitmaps(cmd);
#endif
@ -145,6 +146,7 @@
WesternCharSet::load_bitmaps(cmd);
#endif
StandardCharSet::load_bitmaps(cmd);
cmd.cmd(RESTORE_CONTEXT());
}
/**

View file

@ -1,108 +0,0 @@
#!/usr/bin/python
# Written By Marcio Teixeira 2019 - Aleph Objects, Inc.
#
# 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.
#
# To view a copy of the GNU General Public License, go to the following
# location: <https://www.gnu.org/licenses/>.
from __future__ import print_function
from PIL import Image
import argparse
import textwrap
def pack_rle(data):
"""Use run-length encoding to pack the bytes"""
rle = []
value = data[0]
count = 0
for i in data:
if i != value or count == 255:
rle.append(count)
rle.append(value)
value = i
count = 1
else:
count += 1
rle.append(count)
rle.append(value)
return rle
class WriteSource:
def __init__(self, lines_in_blocks):
self.blocks = []
self.values = []
self.block_size = lines_in_blocks
self.rows = 0
def add_pixel(self, value):
self.values.append(value)
def convert_to_4bpp(self, data, chunk_size = 0):
# Invert the image
data = list(map(lambda i: 255 - i, data))
# Quanitize 8-bit values into 4-bits
data = list(map(lambda i: i >> 4, data))
# Make sure there is an even number of elements
if (len(data) & 1) == 1:
data.append(0)
# Combine each two adjacent values into one
i = iter(data)
data = list(map(lambda a, b: a << 4 | b, i ,i))
# Pack the data
data = pack_rle(data)
# Convert values into hex strings
return list(map(lambda a: "0x" + format(a, '02x'), data))
def end_row(self, y):
# Pad each row into even number of values
if len(self.values) & 1:
self.values.append(0)
self.rows += 1
if self.block_size and (self.rows % self.block_size) == 0:
self.blocks.append(self.values)
self.values = []
def write(self):
if len(self.values):
self.blocks.append(self.values)
block_strs = [];
for b in self.blocks:
data = self.convert_to_4bpp(b)
data = ', '.join(data)
data = textwrap.fill(data, 75, initial_indent = ' ', subsequent_indent = ' ')
block_strs.append(data)
print("const unsigned char font[] PROGMEM = {")
for i, b in enumerate(block_strs):
if i:
print(',')
print('\n /* {} */'.format(i))
print(b, end='')
print("\n};")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Converts a grayscale bitmap into a 16-level RLE packed C array for use as font data')
parser.add_argument("input")
parser.add_argument('--char_height', help='Adds a separator every so many lines', type=int)
args = parser.parse_args()
writer = WriteSource(args.char_height)
img = Image.open(args.input).convert('L')
for y in range(img.height):
for x in range(img.width):
writer.add_pixel(img.getpixel((x,y)))
writer.end_row(y)
writer.write()

View file

@ -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,
@ -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)

View file

@ -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;
float r = 0, b = 0;
if (sq_min != sq_max) {
if (VALUE(x, y) < 0)
r = val_dev / sq_min * 0xFF;
r = val_dev / sq_min;
else
b = val_dev / sq_max * 0xFF;
cmd.cmd(COLOR_RGB(0xFF - b, 0xFF - b - r, 0xFF - r));
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))));
}

View file

@ -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);
@ -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);
@ -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);
}

View file

@ -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();