初始化提交
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2021 by M5Stack
|
||||
* Equipped with M5Core2 sample source code
|
||||
* 配套 M5Core2 示例源代码
|
||||
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
|
||||
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
|
||||
*
|
||||
* describe: Display_Unicode. Unicode显示
|
||||
* date: 2021/7/23
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/*---PLEASE SEE THE README----
|
||||
------请在使用前看README文件----*/
|
||||
#include <M5Core2.h>
|
||||
#include "CUF_24px.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
M5.begin(); //Init M5Stack. 初始化M5Core2
|
||||
M5.Lcd.setFreeFont(&unicode_24px); //Set the GFX font to use. 设置要使用的GFX字体
|
||||
M5.Lcd.setTextDatum(TC_DATUM); //Set text alignment to center-up alignment. 设置文本对齐方式为居中向上对齐
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
M5.Lcd.fillScreen(0);
|
||||
M5.Lcd.drawString("Hello world", 160, 60, 1); //Hello world is displayed in font 1 on (1600.60).
|
||||
M5.Lcd.drawString("你好 世界", 160, 90, 1); //在(160,60)处以字体1显示hello world
|
||||
M5.Lcd.drawString("Здравствуй мир", 160, 120, 1);
|
||||
M5.Lcd.drawString("こんにちは せかい", 160, 150, 1);
|
||||
delay(3000);
|
||||
|
||||
M5.Lcd.fillScreen(0); //Fill the screen with black (used to clear the screen) is equivalent to clear (). 使屏幕充满黑色(用来清屏)等同于clear()
|
||||
M5.Lcd.setCursor(0, 30); // Set the text cursor 0,30 position. 设置文本光标在(0,30)处
|
||||
M5.Lcd.printf("☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓☔☕☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☸☹☺☻☼☽☾☿♀♁♂♃♄♅♆♇♈♉♊♋♌♍♎♏♐♑♒♓♔♕♖♗♘♙♚♛♜♝♞♟♠♡♢♣♤♥♦♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚇⚈⚉⚊⚋⚌⚍⚎⚏⚐⚑⚒⚓⚔⚕⚖⚗⚘⚙⚚⚛⚜⚝⚞⚟A⚠⚡⚢⚣⚤⚥⚦⚧⚨⚩⚪⚫⚬⚭⚮⚯B⚰⚱⚲⚳⚴⚵⚶⚷⚸⚹⚺⚻⚼⚽⚾⚿C⛀⛁⛂⛃⛄⛅⛆⛇⛈⛉⛊⛋⛌⛍⛎⛏D⛐⛑⛒⛓⛔⛕⛖⛗⛘⛙⛚⛛⛜⛝⛞⛟E⛠⛡⛢");
|
||||
delay(3000);
|
||||
|
||||
M5.Lcd.fillScreen(0);
|
||||
M5.Lcd.setCursor(0, 30);
|
||||
M5.Lcd.printf("⛣⛤⛥⛦⛧⛨⛩⛪⛫⛬⛭⛮⛯F⛰⛱⛲⛳⛴⛵⛶⛷⛸⛹⛺⛻⛼⛽⛾⛿✀✁✂✃✄✅✆✇✈✉✊✋✌✍✎✏✐✑✒✓✔✕✖✗✘✙✚✛✜✝✞✟✠✡✢✣✤✥✦✧✨✩✪✫✬✭✮✯✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞❟❠❡❢❣❤❥❦❧❨❩❪❫❬❭❮❯❰❱❲❳❴❵❶❷❸❹❺❻❼❽❾❿➀➁➂➃➄➅➆➇➈➉➊➋➌➍➎➏➐➑➒➓➔➕➖➗➘➙➚➛➜➝➞➟A➠➡➢➣➤➥➦➧➨➩➪➫➬➭➮➯B➰➱➲➳➴➵➶➷➸➹➺➻➼➽➾➿");
|
||||
delay(3000);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
Please modify <m5stack path>/src/utility/In_eSPI_Setup.h, At the end of the file add "#define USE_M5_FONT_CREATOR"
|
||||
|
||||
if use PlatformIO, need add "board_build.partitions = no_ota.csv" in platformio.ini
|
||||
|
||||
if want get customize unicode, try use https://github.com/m5stack/FontCreator, create font file
|
||||
|
||||
if add "#define USE_M5_FONT_CREATOR" and want to use standard gfx font, need modify font file
|
||||
#ifdef USE_M5_FONT_CREATOR
|
||||
0, 0,
|
||||
#endif
|
||||
like:
|
||||
|
||||
``` cpp
|
||||
const GFXfont FreeMono12pt7b PROGMEM = {
|
||||
(uint8_t *)FreeMono12pt7bBitmaps,
|
||||
(GFXglyph *)FreeMono12pt7bGlyphs,
|
||||
0x20, 0x7E, 24,
|
||||
#ifdef USE_M5_FONT_CREATOR
|
||||
0, 0,
|
||||
#endif
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
zh:
|
||||
如果编译过程中出现错误,请在<m5stack path>/src/utility/In_eSPI_Setup.h 中最后一行添加#define USE_M5_FONT_CREATOR
|
||||
|
||||
如果你使用platformIO,需要在platformio.ini中添加board_build.partitions = no_ota.csv
|
||||
|
||||
如果你想自定义unicode,请尝试使用https://github.com/m5stack/FontCreator 去创建相关字体文件
|
||||
|
||||
如果添加了“#define USE_M5_FONT_CREATOR”,并且想使用标准的gfx字体,需要修改CUF_24px.h文件
|
||||
|
||||
|
||||
```cpp
|
||||
#ifdef USE_M5_FONT_CREATOR
|
||||
#define _unicode_24px_H_
|
||||
const GFXfont FreeMono12pt7b PROGMEM = {
|
||||
(uint8_t *)FreeMono12pt7bBitmaps,
|
||||
(GFXglyph *)FreeMono12pt7bGlyphs,
|
||||
0x20, 0x7E, 24,
|
||||
};
|
||||
|
||||
#endif
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2021 by M5Stack
|
||||
* Equipped with M5Core2 sample source code
|
||||
* 配套 M5Core2 示例源代码
|
||||
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
|
||||
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
|
||||
*
|
||||
* describe: Character library. 字库
|
||||
* date: 2021/7/28
|
||||
*******************************************************************************
|
||||
|
||||
-----PLEASE SEE THE README----
|
||||
------请在使用前看README文件----*/
|
||||
|
||||
#include <M5Core2.h>
|
||||
#include "display_ch.h"
|
||||
#include "str.h"
|
||||
|
||||
DisplayCh displaych;
|
||||
void setup() {
|
||||
M5.begin(); // Init M5Stack. 初始化M5Stack
|
||||
displaych.loadHzk16(); //Load the Chinese character library (be sure to load before using the Chinese character library). 加载汉字库(务必在使用汉字库前加载)
|
||||
displaych.setTextColor(WHITE, BLACK); //Set the text color to white and the text background color to black (mandatory). 设置文字颜色为白色,文字背景颜色为黑色(必加)
|
||||
// Set text with red highlight color
|
||||
displaych.setHighlightColor(RED); //Set the text highlight color to red. 设置文字高亮颜色为红色
|
||||
displaych.setTextSize(1); //Set text size to 1. 设置字号大小为1 Set text size to 1(必加)
|
||||
}
|
||||
|
||||
void loop() {
|
||||
displaych.setCursor(0,0,1); //Set the cursor at (0,0) and the size to 1(mandatory). 将光标设置在(0,0)处,并设置字号为1(必加)
|
||||
displaych.writeHzk(AscStr); //Display the contents of AscStr here (which can be changed in str.h). 在此处显示AscStr中的内容(可在str.h中更改)
|
||||
delay(1000); //delay 1000ms. 延迟1000ms
|
||||
displaych.setCursor(0,45);
|
||||
displaych.writeHzk(GbkStr); //Display the contents of GbkStr here (which can be changed in str.h). 在此处显示GbkStr中的内容(可在str.h中更改)
|
||||
delay(1000);
|
||||
//Highlight the text. 高亮显示文本
|
||||
displaych.highlight(true); //Turn on highlight. 开启高亮显示
|
||||
displaych.setCursor(0,65);
|
||||
displaych.writeHzk(GbkStr);
|
||||
delay(1000);
|
||||
displaych.fillScreen(BLACK); //Fill the screen with black color, equivalent to empty the screen. 填充屏幕颜色为黑色,等效于清空屏幕
|
||||
displaych.highlight(false); //Turn off highlight. 关闭高亮显示
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
HZK16 is the GB2312 Chinese encoding format font, so it is normal that GbkStr is displayed as garbled in the src.h file
|
||||
To display Chinese normally, notepad++ or other software (UTF-8 for Arduino IDE) should be used to open str.h with encoding GB2312
|
||||
Modify the content in GbkStr to replace it with the character you want to display
|
||||
|
||||
HZK16为GB2312中文编码格式字库, 故在 src.h 文件中 GbkStr 显示为乱码为正常现象
|
||||
若要正常显示中文应使用notepad++或其它软件(Arduino IDE 为UTF-8)使用编码GB2312打开str.h
|
||||
修改GbkStr里的内容即可更换为想要显示的字符
|
||||
@@ -0,0 +1,611 @@
|
||||
#include "display_ch.h"
|
||||
//#define _ASC16_
|
||||
//#define _HZK16_
|
||||
DisplayCh::DisplayCh(){
|
||||
// Set default highlight color
|
||||
highlightcolor = RED;
|
||||
highlighted = false;
|
||||
|
||||
// HZK16 is not used by default
|
||||
hzk16Used = false;
|
||||
hzk16Type = DontUsedHzk16;
|
||||
//pHzk16File = nullptr;
|
||||
//pAsc16File = nullptr;
|
||||
|
||||
textwrap = true;
|
||||
|
||||
_width = 320;
|
||||
_height = 240;
|
||||
}
|
||||
/***************************************************************************************
|
||||
|
||||
** Function name: setTextWrap
|
||||
|
||||
** Description: Define if text should wrap at end of line
|
||||
|
||||
***************************************************************************************/
|
||||
|
||||
void DisplayCh::setTextWrap(boolean w) { textwrap = w; }
|
||||
/***************************************************************************************
|
||||
|
||||
** Function name: setTextSize
|
||||
|
||||
** Description: Set the text size multiplier
|
||||
|
||||
***************************************************************************************/
|
||||
|
||||
void DisplayCh::setTextSize(uint8_t s) {
|
||||
|
||||
if (s > 7)
|
||||
|
||||
s = 7; // Limit the maximum size multiplier so byte variables can be used
|
||||
|
||||
// for rendering
|
||||
|
||||
textsize = (s > 0) ? s : 1; // Don't allow font size 0
|
||||
|
||||
|
||||
// Calculate the text width and height.
|
||||
|
||||
// It's 8 pixels wide and 16 pixels high in for ASCII characters,
|
||||
|
||||
// and 16 pixels both wide and high for GBK characters in HZK16 mode.
|
||||
|
||||
ascCharWidth = 8 * textsize;
|
||||
|
||||
ascCharHeigth = 16 * textsize;
|
||||
|
||||
gbkCharWidth = ascCharHeigth;
|
||||
|
||||
gbkCharHeight = gbkCharWidth;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
|
||||
** Function name: setCursor
|
||||
|
||||
** Description: Set the text cursor x,y position
|
||||
|
||||
***************************************************************************************/
|
||||
|
||||
void DisplayCh::setCursor(int16_t x, int16_t y) {
|
||||
|
||||
cursor_x = x;
|
||||
|
||||
cursor_y = y;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
|
||||
** Function name: setCursor
|
||||
|
||||
** Description: Set the text cursor x,y position and font
|
||||
|
||||
***************************************************************************************/
|
||||
|
||||
void DisplayCh::setCursor(int16_t x, int16_t y, uint8_t font) {
|
||||
|
||||
textfont = font;
|
||||
|
||||
cursor_x = x;
|
||||
|
||||
cursor_y = y;
|
||||
|
||||
}
|
||||
/***************************************************************************************
|
||||
|
||||
** Function name: setTextColor
|
||||
|
||||
** Description: Set the font foreground colour (background is
|
||||
|
||||
*transparent)
|
||||
|
||||
***************************************************************************************/
|
||||
|
||||
void DisplayCh::setTextColor(uint16_t c) {
|
||||
|
||||
// For 'transparent' background, we'll set the bg
|
||||
|
||||
// to the same as fg instead of using a flag
|
||||
|
||||
textcolor = textbgcolor = c;
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************
|
||||
|
||||
** Function name: fillScreen
|
||||
|
||||
** Description: Clear the screen to defined colour
|
||||
|
||||
***************************************************************************************/
|
||||
|
||||
void DisplayCh::fillScreen(uint32_t color) {
|
||||
|
||||
M5.Lcd.fillRect(0, 0, _width, _height, color);
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************
|
||||
|
||||
** Function name: setTextColor
|
||||
|
||||
** Description: Set the font foreground and background colour
|
||||
|
||||
***************************************************************************************/
|
||||
|
||||
void DisplayCh::setTextColor(uint16_t c, uint16_t b) {
|
||||
|
||||
textcolor = c;
|
||||
|
||||
textbgcolor = b;
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************
|
||||
|
||||
** Function name: loadHzk16
|
||||
|
||||
** Description: loadHzk16 fonts
|
||||
|
||||
** Params:
|
||||
|
||||
** HZK16Path: HZK16 file path on TF card. e.g. /HZK16, means file on the
|
||||
|
||||
*root dir of TF card. * ASC16Path: ASC16 file path on TF card.
|
||||
|
||||
***************************************************************************************/
|
||||
|
||||
void DisplayCh::loadHzk16(Hzk16Types hzkTypes,const char *HZK16Path, const char *ASC16Path) {
|
||||
|
||||
if (hzk16Used)
|
||||
|
||||
return;
|
||||
|
||||
|
||||
//Hzk16Types hzkTypes = InternalHzk16
|
||||
if(hzkTypes == InternalHzk16){
|
||||
//#if defined(_ASC16_) && defined(_HZK16_)
|
||||
|
||||
pAscCharMatrix = (uint8_t *)&ASC16[0];
|
||||
|
||||
pGbkCharMatrix = (uint8_t *)&HZK16[0];
|
||||
|
||||
Serial.println("HZK16 path: Internal");
|
||||
|
||||
Serial.println("ASC16 path: Internal");
|
||||
|
||||
hzk16Used = initHzk16(true, nullptr, nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
pAscCharMatrix = NULL;
|
||||
|
||||
pGbkCharMatrix = NULL;
|
||||
|
||||
|
||||
|
||||
Serial.print("HZK16 path: /SD");
|
||||
|
||||
Serial.println(HZK16Path);
|
||||
|
||||
Serial.print("ASC16 path: /SD");
|
||||
|
||||
Serial.println(ASC16Path);
|
||||
|
||||
hzk16Used = initHzk16(true, HZK16Path, ASC16Path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Serial.print("HZK16 init result: ");
|
||||
|
||||
Serial.println(isHzk16Used());
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************************
|
||||
|
||||
** Function name: disableHzk16
|
||||
|
||||
** Description: disable Hzk16 fonts
|
||||
|
||||
** Params:
|
||||
|
||||
***************************************************************************************/
|
||||
|
||||
void DisplayCh::disableHzk16() {
|
||||
|
||||
if (hzk16Used) {
|
||||
|
||||
hzk16Used = initHzk16(false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool DisplayCh::initHzk16(boolean use, const char *HZK16Path,
|
||||
const char *ASC16Path) {
|
||||
|
||||
bool result = false;
|
||||
|
||||
if (use == false) { // Do not use HZK16 and ASC16 fonts
|
||||
|
||||
hzk16Type = DontUsedHzk16;
|
||||
|
||||
Serial.println("Use default font.");
|
||||
|
||||
} else if (pAscCharMatrix == NULL ||
|
||||
|
||||
pGbkCharMatrix ==
|
||||
|
||||
NULL) { // Use external HZK16 and ASC16 font on TF card.
|
||||
|
||||
|
||||
|
||||
// Check if HZK16 and ASC16 files exist on TF card.
|
||||
|
||||
if (SD.exists(HZK16Path) && SD.exists(ASC16Path)) { // Exists
|
||||
|
||||
hzk16Type = ExternalHzk16;
|
||||
|
||||
Serial.println("Use external HZK16 and ASC16 font.");
|
||||
|
||||
} else { // Not exists
|
||||
|
||||
hzk16Type = DontUsedHzk16;
|
||||
|
||||
Serial.println("External font file HZK16/ASC16 lost, use default font.");
|
||||
|
||||
}
|
||||
|
||||
} else { // Use internal HZK16 and ASC16 fonts
|
||||
|
||||
hzk16Type = InternalHzk16;
|
||||
|
||||
Serial.println("Use internal HZK16 and ASC16 font.");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch (hzk16Type) {
|
||||
|
||||
case ExternalHzk16: {
|
||||
|
||||
if (pHzk16File == NULL) {
|
||||
|
||||
Hzk16File = SD.open(HZK16Path);
|
||||
|
||||
pHzk16File = &Hzk16File;
|
||||
|
||||
}
|
||||
|
||||
if (pAsc16File == NULL) {
|
||||
|
||||
Asc16File = SD.open(ASC16Path);
|
||||
|
||||
pAsc16File = &Asc16File;
|
||||
|
||||
}
|
||||
|
||||
hzkBufCount = 0;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case InternalHzk16: {
|
||||
|
||||
if (pAscCharMatrix == NULL || pGbkCharMatrix == NULL) {
|
||||
|
||||
hzk16Type = DontUsedHzk16;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (pHzk16File != NULL) {
|
||||
|
||||
pHzk16File->close();
|
||||
|
||||
pHzk16File = NULL;
|
||||
|
||||
}
|
||||
|
||||
if (pAsc16File != NULL) {
|
||||
|
||||
pAsc16File->close();
|
||||
|
||||
pAsc16File = NULL;
|
||||
|
||||
}
|
||||
|
||||
hzkBufCount = 0;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case DontUsedHzk16: {
|
||||
|
||||
if (pHzk16File != NULL) {
|
||||
|
||||
pHzk16File->close();
|
||||
|
||||
pHzk16File = NULL;
|
||||
|
||||
}
|
||||
|
||||
if (pAsc16File != NULL) {
|
||||
|
||||
pAsc16File->close();
|
||||
|
||||
pAsc16File = NULL;
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return hzk16Type != DontUsedHzk16;
|
||||
|
||||
}
|
||||
void DisplayCh::writeHzkAsc(const char c) {
|
||||
|
||||
if (c == '\n') {
|
||||
|
||||
cursor_x = 0;
|
||||
|
||||
cursor_y += ascCharHeigth;
|
||||
|
||||
} else if (c != '\r') {
|
||||
|
||||
uint32_t offset;
|
||||
|
||||
uint8_t mask;
|
||||
|
||||
uint16_t posX = cursor_x, posY = cursor_y;
|
||||
|
||||
uint8_t charMatrix[16];
|
||||
|
||||
uint8_t *pCharMatrix;
|
||||
|
||||
|
||||
|
||||
offset = (uint32_t)c * 16;
|
||||
|
||||
|
||||
|
||||
if (hzk16Type == ExternalHzk16) {
|
||||
|
||||
pAsc16File->seek(offset, SeekSet);
|
||||
|
||||
pAsc16File->readBytes((char *)&charMatrix[0], 16);
|
||||
|
||||
pCharMatrix = &charMatrix[0];
|
||||
|
||||
} else {
|
||||
|
||||
if (pAscCharMatrix == NULL) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
pCharMatrix = pAscCharMatrix + offset;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// startWrite();
|
||||
|
||||
|
||||
|
||||
if (highlighted) {
|
||||
|
||||
M5.Lcd.fillRect(cursor_x, cursor_y, ascCharWidth, ascCharHeigth, highlightcolor);
|
||||
|
||||
} else if (istransparent == false) {
|
||||
|
||||
M5.Lcd.fillRect(cursor_x, cursor_y, ascCharWidth, ascCharHeigth, textbgcolor);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (uint8_t row = 0; row < 16; row++) {
|
||||
|
||||
mask = 0x80;
|
||||
|
||||
posX = cursor_x;
|
||||
|
||||
for (uint8_t col = 0; col < 8; col++) {
|
||||
|
||||
if ((*pCharMatrix & mask) != 0) {
|
||||
|
||||
if (textsize == 1) {
|
||||
|
||||
M5.Lcd.drawPixel(posX, posY, textcolor);
|
||||
|
||||
} else {
|
||||
|
||||
M5.Lcd.fillRect(posX, posY, textsize, textsize, textcolor);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
posX += textsize;
|
||||
|
||||
mask >>= 1;
|
||||
|
||||
}
|
||||
|
||||
posY += textsize;
|
||||
|
||||
pCharMatrix++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// endWrite();
|
||||
|
||||
|
||||
|
||||
cursor_x += ascCharWidth;
|
||||
|
||||
if (textwrap && ((cursor_x + ascCharWidth) > _width)) {
|
||||
|
||||
cursor_x = 0;
|
||||
|
||||
cursor_y += ascCharHeigth;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DisplayCh::writeHzk(char* c){
|
||||
|
||||
char *ret = c;
|
||||
if(ret == NULL) return;
|
||||
while(*ret != '\0'){
|
||||
while(*ret <= 0xA0){
|
||||
if(*ret == '\0') return;
|
||||
writeHzkAsc(*ret);
|
||||
ret++;
|
||||
}
|
||||
writeHzkGbk(ret);
|
||||
ret++;
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DisplayCh::writeHzkGbk(const char *c) {
|
||||
|
||||
uint32_t offset;
|
||||
|
||||
uint8_t mask;
|
||||
|
||||
uint16_t posX = cursor_x, posY = cursor_y;
|
||||
|
||||
uint8_t charMatrix[32];
|
||||
|
||||
uint8_t *pCharMatrix;
|
||||
|
||||
|
||||
|
||||
offset = (uint32_t)(94 * (uint32_t)(c[0] - 0xA1) + (uint32_t)(c[1] - 0xA1)) * 32;
|
||||
|
||||
if (hzk16Type == ExternalHzk16) {
|
||||
|
||||
pHzk16File->seek(offset, SeekSet);
|
||||
|
||||
pHzk16File->readBytes((char *)&charMatrix[0], 32);
|
||||
|
||||
pCharMatrix = &charMatrix[0];
|
||||
|
||||
} else {
|
||||
|
||||
if (pGbkCharMatrix == NULL) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
pCharMatrix = pGbkCharMatrix + offset;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// startWrite();
|
||||
|
||||
|
||||
|
||||
if (highlighted) {
|
||||
|
||||
M5.Lcd.fillRect(cursor_x, cursor_y, gbkCharWidth, gbkCharHeight, highlightcolor);
|
||||
|
||||
} else if (istransparent == false) {
|
||||
|
||||
M5.Lcd.fillRect(cursor_x, cursor_y, gbkCharWidth, gbkCharHeight, textbgcolor);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (uint8_t row = 0; row < 16; row++) {
|
||||
|
||||
posX = cursor_x;
|
||||
|
||||
mask = 0x80;
|
||||
|
||||
for (uint8_t col = 0; col < 8; col++) {
|
||||
|
||||
if ((*pCharMatrix & mask) != 0) {
|
||||
|
||||
if (textsize == 1) {
|
||||
|
||||
M5.Lcd.drawPixel(posX, posY, textcolor);
|
||||
|
||||
} else {
|
||||
|
||||
M5.Lcd.fillRect(posX, posY, textsize, textsize, textcolor);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ((*(pCharMatrix + 1) & mask) != 0) {
|
||||
|
||||
if (textsize == 1) {
|
||||
|
||||
M5.Lcd.drawPixel(posX + ascCharWidth, posY, textcolor);
|
||||
|
||||
} else {
|
||||
|
||||
M5.Lcd.fillRect(posX + ascCharWidth, posY, textsize, textsize, textcolor);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mask >>= 1;
|
||||
|
||||
posX += textsize;
|
||||
|
||||
}
|
||||
|
||||
posY += textsize;
|
||||
|
||||
pCharMatrix += 2;
|
||||
|
||||
}
|
||||
|
||||
// endWrite();
|
||||
|
||||
cursor_x += gbkCharWidth;
|
||||
|
||||
if (textwrap && ((cursor_x + gbkCharWidth) > _width)) {
|
||||
|
||||
cursor_x = 0;
|
||||
|
||||
cursor_y += gbkCharHeight;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#ifndef __DISPLAY_CH_H_
|
||||
#define __DISPLAY_CH_H_
|
||||
#include <M5Core2.h>
|
||||
#include "Fonts/HZK16.h"
|
||||
#include "Fonts/ASC16.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DontUsedHzk16,
|
||||
InternalHzk16,
|
||||
ExternalHzk16
|
||||
}Hzk16Types;
|
||||
|
||||
class DisplayCh {
|
||||
public:
|
||||
DisplayCh();
|
||||
/**************************************************************************
|
||||
**
|
||||
** GBK character support
|
||||
**
|
||||
**************************************************************************/
|
||||
void loadHzk16(Hzk16Types hzkTypes = InternalHzk16,const char* HZK16Path = "/HZK16", const char* ASC16Path = "/ASC16");
|
||||
void disableHzk16();
|
||||
|
||||
void setTextColor(uint16_t c);
|
||||
void setTextColor(uint16_t c, uint16_t b);
|
||||
void setCursor(int16_t x, int16_t y);
|
||||
void setCursor(int16_t x, int16_t y, uint8_t font);
|
||||
void setTextSize(uint8_t size);
|
||||
void fillScreen(uint32_t color);
|
||||
|
||||
// Highlight the text (Once set to be true, the text background will not be transparent any more)
|
||||
inline void highlight(bool isHighlight) { highlighted = isHighlight; }
|
||||
// Set highlight color
|
||||
inline void setHighlightColor(uint16_t color) { highlightcolor = color; istransparent = false; }
|
||||
|
||||
|
||||
|
||||
void writeHzk(char* c);
|
||||
|
||||
|
||||
private:
|
||||
inline void setTransparentBgColor(bool isTransparent) { istransparent = isTransparent; }
|
||||
inline bool isTransparentBg(){return istransparent;}
|
||||
bool initHzk16(boolean use, const char* HZK16Path = nullptr, const char* ASC16Path = nullptr);
|
||||
inline bool isHzk16Used(){return hzk16Used;}
|
||||
void setTextWrap(boolean wrap);
|
||||
void writeHzkAsc(const char c);
|
||||
void writeHzkGbk(const char* c);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
uint8_t hzkBufCount,hzkBuf[2];
|
||||
boolean hzk16Used,istransparent,
|
||||
highlighted;
|
||||
Hzk16Types hzk16Type; // Use of HZK16 and ASC16 font.
|
||||
File
|
||||
Asc16File, Hzk16File, // Font file
|
||||
*pAsc16File, *pHzk16File; // Font file pointer
|
||||
|
||||
uint8_t *pAscCharMatrix, *pGbkCharMatrix;
|
||||
uint16_t
|
||||
highlightcolor,
|
||||
ascCharWidth,
|
||||
ascCharHeigth,
|
||||
gbkCharWidth,
|
||||
gbkCharHeight;
|
||||
uint32_t textcolor,textbgcolor;
|
||||
int32_t cursor_x, cursor_y;
|
||||
uint8_t textfont,textsize;
|
||||
uint32_t _width, _height; // Display w/h as modified by current rotation
|
||||
boolean textwrap; // If set, 'wrap' text at right edge of display
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef _STR_H_
|
||||
#define _STR_H_
|
||||
|
||||
char* AscStr="ASCII: ABCDEFG1234567";
|
||||
char* GbkStr="Tao yuanming:寡蒋叫千和 こんにちは";
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2021 by M5Stack
|
||||
* Equipped with M5Core2 sample source code
|
||||
* 配套 M5Core2 示例源代码
|
||||
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
|
||||
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
|
||||
*
|
||||
* describe: Ellipse drawing. 椭圆绘制
|
||||
* date: 2021/7/26
|
||||
*******************************************************************************/
|
||||
|
||||
#include <M5Core2.h>
|
||||
|
||||
void setup(void) {
|
||||
M5.begin(); //Init M5Core2. 初始化M5Core2
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Draw some random ellipses. 绘制一些随机形状的椭圆
|
||||
for (int i = 0; i < 40; i++)
|
||||
{
|
||||
int rx = random(60);
|
||||
int ry = random(60);
|
||||
int x = rx + random(320 - rx - rx);
|
||||
int y = ry + random(240 - ry - ry);
|
||||
M5.Lcd.fillEllipse(x, y, rx, ry, random(0xFFFF)); //At (x, y), draw a filled ellipse with random width and height of rx, ry with random color random (0xFFFF). 在(x,y)处以随机颜色random(0xFFFF),绘制一个随机宽高为rx,ry的填充椭圆
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
M5.Lcd.clear(); //清空屏幕
|
||||
|
||||
for (int i = 0; i < 40; i++)
|
||||
{
|
||||
int rx = random(60);
|
||||
int ry = random(60);
|
||||
int x = rx + random(320 - rx - rx);
|
||||
int y = ry + random(240 - ry - ry);
|
||||
M5.Lcd.drawEllipse(x, y, rx, ry, random(0xFFFF));//At (x, y), draw an elliptical wire frame with a random width and height of rx, ry in a random color (0xFFFF). 在(x,y)处以随机颜色random(0xFFFF),绘制一个随机宽高为rx,ry的椭圆线框
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user