目录
书接上文 基于乐鑫 ESP32-PICO-D4 模块的墨水屏智能手表开源项目Watchy 完成了硬件&软件部分,接下来想自定义一个中文界面:
一 实现方式
【1】新建工程,并从其他例程中复制一个 settings.h 拖进工程:
【2】要实现中文显示,需要使用 U8g2_for_Adafruit_GFX 库:
【3】需用自定义代码覆盖 drawWatchFace() 方法,其次导入字体(u8g2_font_wqy14_t_chinese3):
#include <Watchy.h> //include the Watchy library
#include "settings.h" //same file as the one from 7_SEG example
#include <U8g2_for_Adafruit_GFX.h>
U8G2_FOR_ADAFRUIT_GFX u8g2Fonts; // 导入字体
class MyFirstWatchFace : public Watchy{ //inherit and extend Watchy class
public:
MyFirstWatchFace(const watchySettings& s) : Watchy(s) {}
void drawWatchFace(){ //override this method to customize how the watch face looks
u8g2Fonts.begin(display); //将u8g2过程连接到Adafruit GFX
u8g2Fonts.setFont(u8g2_font_wqy14_t_chinese3); // 设置文本字体
u8g2Fonts.setCursor(100, 100);
String content = "中文显示";
u8g2Fonts.println(content); // 显示文本
}
};
MyFirstWatchFace m(settings); //instantiate your watchface
void setup() {
m.init(); //call init in setup
}
void loop() {
// this should never run, Watchy deep sleeps after init();
}
其中提供的字体如下: