2020-07-30 06:43:19 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (c) 2020 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/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if HAS_GRAPHICAL_TFT
|
|
|
|
|
|
|
|
#include "tft_string.h"
|
|
|
|
#include "../fontutils.h"
|
|
|
|
|
|
|
|
//#define DEBUG_TFT_FONT
|
|
|
|
#define DEBUG_OUT ENABLED(DEBUG_TFT_FONT)
|
|
|
|
#include "../../core/debug_out.h"
|
|
|
|
|
|
|
|
glyph_t *TFT_String::glyphs[256];
|
|
|
|
font_t *TFT_String::font_header;
|
|
|
|
|
|
|
|
uint8_t TFT_String::data[];
|
|
|
|
uint16_t TFT_String::span;
|
|
|
|
uint16_t TFT_String::length;
|
|
|
|
|
|
|
|
void TFT_String::set_font(const uint8_t *font) {
|
|
|
|
font_header = (font_t *)font;
|
|
|
|
uint32_t glyph;
|
|
|
|
|
2020-10-24 22:13:10 +00:00
|
|
|
for (glyph = 0; glyph < 256; glyph++) glyphs[glyph] = nullptr;
|
2020-07-30 06:43:19 +00:00
|
|
|
|
2020-11-07 03:07:15 +00:00
|
|
|
DEBUG_ECHOLNPAIR("Format: ", font_header->Format);
|
|
|
|
DEBUG_ECHOLNPAIR("BBXWidth: ", font_header->BBXWidth);
|
|
|
|
DEBUG_ECHOLNPAIR("BBXHeight: ", font_header->BBXHeight);
|
|
|
|
DEBUG_ECHOLNPAIR("BBXOffsetX: ", font_header->BBXOffsetX);
|
|
|
|
DEBUG_ECHOLNPAIR("BBXOffsetY: ", font_header->BBXOffsetY);
|
|
|
|
DEBUG_ECHOLNPAIR("CapitalAHeight: ", font_header->CapitalAHeight);
|
|
|
|
DEBUG_ECHOLNPAIR("Encoding65Pos: ", font_header->Encoding65Pos);
|
|
|
|
DEBUG_ECHOLNPAIR("Encoding97Pos: ", font_header->Encoding97Pos);
|
2020-07-30 06:43:19 +00:00
|
|
|
DEBUG_ECHOLNPAIR("FontStartEncoding: ", font_header->FontStartEncoding);
|
2020-11-07 03:07:15 +00:00
|
|
|
DEBUG_ECHOLNPAIR("FontEndEncoding: ", font_header->FontEndEncoding);
|
|
|
|
DEBUG_ECHOLNPAIR("LowerGDescent: ", font_header->LowerGDescent);
|
|
|
|
DEBUG_ECHOLNPAIR("FontAscent: ", font_header->FontAscent);
|
|
|
|
DEBUG_ECHOLNPAIR("FontDescent: ", font_header->FontDescent);
|
|
|
|
DEBUG_ECHOLNPAIR("FontXAscent: ", font_header->FontXAscent);
|
|
|
|
DEBUG_ECHOLNPAIR("FontXDescent: ", font_header->FontXDescent);
|
2020-07-30 06:43:19 +00:00
|
|
|
|
|
|
|
add_glyphs(font);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFT_String::add_glyphs(const uint8_t *font) {
|
|
|
|
uint32_t glyph;
|
|
|
|
uint8_t *pointer = (uint8_t *)font + sizeof(font_t);
|
|
|
|
|
|
|
|
for (glyph = ((font_t *)font)->FontStartEncoding; glyph <= ((font_t *)font)->FontEndEncoding; glyph++) {
|
|
|
|
if (*pointer != NO_GLYPH) {
|
|
|
|
glyphs[glyph] = (glyph_t *)pointer;
|
|
|
|
pointer += sizeof(glyph_t) + ((glyph_t *)pointer)->DataSize;
|
|
|
|
}
|
2020-11-07 03:07:15 +00:00
|
|
|
else
|
2020-07-30 06:43:19 +00:00
|
|
|
pointer++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFT_String::set() {
|
|
|
|
*data = 0x00;
|
|
|
|
span = 0;
|
|
|
|
length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t read_byte(uint8_t *byte) { return *byte; }
|
|
|
|
|
2020-11-07 03:07:15 +00:00
|
|
|
/**
|
|
|
|
* Add a string, applying substitutions for the following characters:
|
|
|
|
*
|
|
|
|
* = displays '0'....'10' for indexes 0 - 10
|
|
|
|
* ~ displays '1'....'11' for indexes 0 - 10
|
|
|
|
* * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL)
|
|
|
|
*/
|
2020-08-12 21:46:51 +00:00
|
|
|
void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString) {
|
2020-07-30 06:43:19 +00:00
|
|
|
wchar_t wchar;
|
|
|
|
|
|
|
|
while (*string) {
|
|
|
|
string = get_utf8_value_cb(string, read_byte, &wchar);
|
2020-08-12 21:46:51 +00:00
|
|
|
if (wchar > 255) wchar |= 0x0080;
|
|
|
|
uint8_t ch = uint8_t(wchar & 0x00FF);
|
2020-07-30 06:43:19 +00:00
|
|
|
|
2020-08-12 21:46:51 +00:00
|
|
|
if (ch == '=' || ch == '~' || ch == '*') {
|
2020-07-30 06:43:19 +00:00
|
|
|
if (index >= 0) {
|
2020-08-12 21:46:51 +00:00
|
|
|
int8_t inum = index + ((ch == '=') ? 0 : LCD_FIRST_TOOL);
|
|
|
|
if (ch == '*') add_character('E');
|
|
|
|
if (inum >= 10) { add_character('0' + (inum / 10)); inum %= 10; }
|
|
|
|
add_character('0' + inum);
|
2020-07-30 06:43:19 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
add(index == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED));
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-12 21:46:51 +00:00
|
|
|
else if (ch == '$' && itemString) {
|
2020-07-30 06:43:19 +00:00
|
|
|
add(itemString);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-08-12 21:46:51 +00:00
|
|
|
add_character(ch);
|
2020-07-30 06:43:19 +00:00
|
|
|
}
|
|
|
|
eol();
|
|
|
|
}
|
|
|
|
|
2020-10-12 23:01:03 +00:00
|
|
|
void TFT_String::add(uint8_t *string) {
|
|
|
|
wchar_t wchar;
|
|
|
|
while (*string) {
|
|
|
|
string = get_utf8_value_cb(string, read_byte, &wchar);
|
|
|
|
if (wchar > 255) wchar |= 0x0080;
|
|
|
|
uint8_t ch = uint8_t(wchar & 0x00FF);
|
|
|
|
add_character(ch);
|
|
|
|
}
|
|
|
|
eol();
|
|
|
|
}
|
|
|
|
|
2020-07-30 06:43:19 +00:00
|
|
|
void TFT_String::add_character(uint8_t character) {
|
|
|
|
if (length < MAX_STRING_LENGTH) {
|
|
|
|
data[length] = character;
|
|
|
|
length++;
|
|
|
|
span += glyph(character)->DWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFT_String::rtrim(uint8_t character) {
|
|
|
|
while (length) {
|
|
|
|
if (data[length - 1] == 0x20 || data[length - 1] == character) {
|
|
|
|
length--;
|
|
|
|
span -= glyph(data[length])->DWidth;
|
|
|
|
eol();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFT_String::ltrim(uint8_t character) {
|
|
|
|
uint16_t i, j;
|
|
|
|
for (i = 0; (i < length) && (data[i] == 0x20 || data[i] == character); i++) {
|
|
|
|
span -= glyph(data[i])->DWidth;
|
|
|
|
}
|
|
|
|
if (i == 0) return;
|
|
|
|
for (j = 0; i < length; data[j++] = data[i++]);
|
|
|
|
length = j;
|
|
|
|
eol();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFT_String::trim(uint8_t character) {
|
|
|
|
rtrim(character);
|
|
|
|
ltrim(character);
|
|
|
|
}
|
|
|
|
|
|
|
|
TFT_String tft_string;
|
|
|
|
|
|
|
|
#endif // HAS_GRAPHICAL_TFT
|