Merge branch 'master' of github.com:m5stack/m5-docs

This commit is contained in:
ali-admin
2021-01-27 14:15:07 +08:00
6 changed files with 327 additions and 6 deletions
+1 -1
View File
@@ -29,7 +29,7 @@
<script>
const quickstart = {
'title':"Quick Start",
'title':"Quick Start/Development environment setup tutorial",
'item':{
'BASIC / M5GO / FIRE / FACES':'#/en/arduino/arduino_development',
'M5StickC':'#/en/arduino/arduino_development',
+1 -1
View File
@@ -243,7 +243,7 @@
"Accessories": {
"Servos": [
{"a":"/#/en/accessory/sg90_servo", "img":"https://static-cdn.m5stack.com/image/m5-docs_homepage/accessory/servo_01.webp", "p":"SG90 servo", "sku":"A076" ,"kw":"180 SERVO", "category":"Servos"},
{"a":"/#/en/accessory/servo_kit", "img":"https://static-cdn.m5stack.com/image/m5-docs_homepage/accessory/servo_kit_01.webp", "p":"Servo Kit 180°/360°", "sku":"A076-B&C" ,"kw":"180 360 SERVO Kit"}
{"a":"/#/en/accessory/servo_kit", "img":"https://static-cdn.m5stack.com/image/m5-docs_homepage/accessory/servo_kit_01.webp", "p":"Servo Kit 180°/360°", "sku":"A076-B&A076-C" ,"kw":"180 360 SERVO Kit"}
],
"Cables": [
{"a":"/#/en/accessory/cable/24awg_cable", "img":"https://static-cdn.m5stack.com/image/m5-docs_homepage/accessory/24awg_cable_01.webp", "p":"Shielded twisted pair", "sku":"A088" ,"kw":"cable rs485 can uart", "category":"Cables"},
+170
View File
@@ -0,0 +1,170 @@
# System & Speaker & AXP192 & RTC
## begin()
**函数原型:**
`void begin(bool LCDEnable = true, bool SDEnable = true, bool SerialEnable = true, bool I2CEnable = false);`
**功能:初始化触摸屏 TF Card , UART I2C**
**例程**
```arduino
#include <M5Tough.h>
void setup() {
M5.begin(true,true,true,true);
}
```
## Speaker类
**功能:驱动I2S扬声器**
**函数原型:**
`int playMidi(const uint8_t *data);`
**功能:播放Midi文件**
**例程:**
```arduino
if( M5.BtnL.wasPressed())
{
Serial.printf("BtnL wasPressed!");
}
M5.update();
```
## update()
**函数原型:**
`void update();`
**功能:刷新设备触屏状态**
## RTC
>在`M5.begin()`初始化中,默认调用`Rtc.begin();`对RTC进行了初始化. 你可以用该实例中的API设置和读取RTC时钟数据。
```
typedef struct
{
uint8_t Hours;
uint8_t Minutes;
uint8_t Seconds;
}RTC_TimeTypeDef;
typedef struct
{
uint8_t WeekDay;
uint8_t Month;
uint8_t Date;
uint16_t Year;
}RTC_DateTypeDef;
```
## SetTime()
**函数原型:**
`void SetTime(RTC_TimeTypeDef* RTC_TimeStruct);`
**函数参数:**
设置结构体变量时间
## GetTime()
**函数原型:**
`void GetTime(RTC_TimeTypeDef* RTC_TimeStruct);`
**函数参数:**
获取结构体时间
## SetData()
**函数原型:**
`void SetData(RTC_DateTypeDef* RTC_DateStruct);`
**函数参数:**
设置结构体变量日期
## GetData()
**函数原型:**
`vvoid GetData(RTC_DateTypeDef* RTC_DateStruct); `
**函数参数:**
获取结构体变量日期
**使用示例:**
```
#include <M5EPD.h>
M5EPD_Canvas canvas(&M5.EPD);
rtc_time_t RTCtime;
rtc_date_t RTCDate;
char timeStrbuff[64];
void flushTime(){
M5.RTC.getTime(&RTCtime);
M5.RTC.getDate(&RTCDate);
sprintf(timeStrbuff,"%d/%02d/%02d %02d:%02d:%02d",
RTCDate.year,RTCDate.mon,RTCDate.day,
RTCtime.hour,RTCtime.min,RTCtime.sec);
canvas.drawString(timeStrbuff, 0, 0);
canvas.pushCanvas(100,200,UPDATE_MODE_DU4);
}
void setupTime(){
RTCtime.hour = 23;
RTCtime.min = 33;
RTCtime.sec = 33;
M5.RTC.setTime(&RTCtime);
RTCDate.year = 2020;
RTCDate.mon = 11;
RTCDate.day = 27;
M5.RTC.setDate(&RTCDate);
}
void setup() {
M5.begin();
M5.EPD.SetRotation(90);
M5.EPD.Clear(true);
M5.RTC.begin();
canvas.createCanvas(400, 300);
canvas.setTextSize(3);
setupTime();
}
void loop() {
flushTime();
delay(1000);
}
```
+153 -2
View File
@@ -1,5 +1,156 @@
# TOUCH-GT911
# TOUCH
>这是M5Stack Tough触摸屏库
>TOUGH正面提供了一块2英寸的电阻式触摸屏,驱动芯片为NS2009,在M5Tough库中,我们提供了一系列的API能够用于触摸交互检测,详情如下
## Touch类
>在`M5.begin()`初始化中,已经创建了实例`touch`并进行了初始化. 你可以用该实例中的API获取触摸交互信息。
- **功能:初始化触摸屏,在M5.begin中将默认调用该函数初始化触摸屏**
- `void begin(bool EEPROMEnabled = true);`
- **功能:进行屏幕触摸校准(校准数据将保存至EEPROM),已经校准则返回True, 否则进入校准页面,用户需要根据屏幕提示依次触摸指定位置**
- `bool calibrationTouch(TFT_eSPI *fb);`
**例程:**
```
#include <M5Tough.h>
void setup()
{
M5.begin(true, true, true, true);
while (!M5.touch.calibrationTouch(&M5.Lcd));
M5.Lcd.fillScreen(TFT_BLACK);
M5.Lcd.print("Calibration Successfully");
}
void loop()
{
}
```
- **功能:读取触摸数据**
- `void read();`
- **功能:读取触摸手指X坐标**
- `int GetTouchX();`
- **功能:读取触摸手指Y坐标**
- `int GetTouchY();`
- **功能:检测触摸手指按压**
- `bool isPressed();`
- **功能:检测触摸手指释放**
- `bool isRelease();`
- **功能:检测触摸手指移动**
- `bool isMoving();`
- **功能:等待触摸手指释放**
- `bool WaitRelease();`
- **功能:等待触摸手指释放,并设置超时时间**
- `bool WaitRelease(uint64_t AutoReleseTime);`
- **功能:读取触摸点信息,返回一个TouchPoint结构体,其中包含X,Y坐标信息,并且内部实现运算符重载,支持对TouchPoint类型的结构进行直接赋值与比较**
- `TouchPoint getPoint();`
## TouchPoint
>通过调用getPoint方法,能够获取到一个TouchPoint结构体类型的数据。其内部包含的成员与方法如下。
```
class TouchPoint
{
public:
TouchPoint(int16_t x_ = -1, int16_t y_ = -1);
bool operator==(const TouchPoint &p);
bool operator!=(const TouchPoint &p);
bool operator=(const TouchPoint &p);
bool Equals(const TouchPoint &p);
void set(int16_t x_ = -1, int16_t y_ = -1);
bool vaild();
int16_t x, y;
};
```
>用户可以通过创建TouchZoon结构体实例的方式,创建了一个屏幕区域,使用内置的`contains`方法,能够判断TouchPoint是否包含在该区域中。
## TouchZone
```
typedef struct TouchZone
{
uint16_t x;
uint16_t y;
uint16_t w;
uint16_t h;
TouchZone() : x(-1), y(-1), w(0), h(0) {}
TouchZone(uint16_t _x, uint16_t _y, uint16_t _w, uint16_t _h) : x(_x), y(_y), w(_w), h(_h){};
bool contains(const TouchPoint &p)
{
if ((this->x == -1) || (this->y == -1) || (this->w == 0) || (this->h == 0))
return false;
if ((p.x >= this->x) && (p.x <= (this->x + this->w)) &&
(p.y >= this->y) && (p.y <= (this->y + this->h)))
{
return true;
}
return false;
}
} TouchZone_t;
```
?>动态读取触摸数据时,需要将`void update();`添加至循环中用于刷新触摸数据。
**例程:**
```arduino
#include <M5Tough.h>
TouchZone clearBtn(0,0,50,50);
void setup()
{
M5.begin(true, true, true, true);
while (!M5.touch.calibrationTouch(&M5.Lcd));
M5.lcd.drawString("CLEAR",5,5,3);
}
void loop()
{
M5.update();
if(M5.touch.isPressed()){
TouchPoint Point = M5.touch.getPoint();
if(M5.touch.isMoving()){
char buffer[24];
sprintf(buffer, "X: %3d, Y: %3d", Point.x, Point.y);
M5.Lcd.drawPixel(Point.x, Point.y ,TFT_GREEN);
Serial.println(buffer);
}
if(clearBtn.contains(Point)){
M5.lcd.fillScreen(TFT_BLACK);
M5.lcd.drawString("CLEAR",5,5,3);
}
}
}
```
## 更多有关Touch API内容,请参考[M5Tough-Github]()源码
+1 -1
View File
@@ -29,7 +29,7 @@
<script>
const quickstart = {
'title':"快速上手",
'title':"快速上手/开发环境搭建教程",
'item':{
'BASIC / M5GO / FIRE / FACES':'#/zh_CN/arduino/arduino_development',
'M5StickC':'#/zh_CN/arduino/arduino_development',
+1 -1
View File
@@ -243,7 +243,7 @@
"配件": {
"舵机": [
{"a":"/#/zh_CN/accessory/sg90_servo", "img":"https://static-cdn.m5stack.com/image/m5-docs_homepage/accessory/servo_01.webp", "p":"SG90 servo", "sku":"A076" ,"kw":"180 SERVO", "category":"舵机"},
{"a":"/#/zh_CN/accessory/servo_kit", "img":"https://static-cdn.m5stack.com/image/m5-docs_homepage/accessory/servo_kit_01.webp", "p":"Servo Kit 180°/360°", "sku":"A076-B&C" ,"kw":"180 360 SERVO Kit"}
{"a":"/#/zh_CN/accessory/servo_kit", "img":"https://static-cdn.m5stack.com/image/m5-docs_homepage/accessory/servo_kit_01.webp", "p":"Servo Kit 180°/360°", "sku":"A076-B&A076-C" ,"kw":"180 360 SERVO Kit"}
],
"线材": [
{"a":"/#/zh_CN/accessory/cable/24awg_cable", "img":"https://static-cdn.m5stack.com/image/m5-docs_homepage/accessory/24awg_cable_01.webp", "p":"Shielded twisted pair", "sku":"A088" ,"kw":"cable rs485 can uart", "category":"线材"},