2020-11-05 11:39:06 +08:00
# E-Ink
2020-12-03 12:00:42 +08:00
?>Before using the E-Ink screen operation function, you need to create an instance and pass in the screen driver address. Call `M5.M5Ink.isInit()` and initialize with `M5.M5Ink.clear();` .
2020-11-05 11:39:06 +08:00
2021-02-26 17:27:20 +08:00
```clike
2020-11-05 11:39:06 +08:00
#include "M5CoreInk.h"
2020-12-03 12:00:42 +08:00
2020-11-05 11:39:06 +08:00
Ink_Sprite InkPageSprite(&M5.M5Ink);
2020-12-03 12:00:42 +08:00
void setup()
{
M5.begin();
digitalWrite(LED_EXT_PIN,LOW);
if( !M5.M5Ink.isInit())
{
Serial.printf("Ink Init faild");
while (1) delay(100);
}
M5.M5Ink.clear();
}
2020-11-05 11:39:06 +08:00
```
## creatSprite
**Syntax:**
`int creatSprite(uint16_t posX,
uint16_t posY,
uint16_t width = 200,
uint16_t height = 200,
bool copyFromMem = true);
`
**Description: create image area, configure whether to get image data buff from screen driver (default is to save true)** .
2020-11-25 16:54:10 +08:00
?>The `x` coordinate of the >create image area must be an integer multiple of 8. (eg: 0 , 8 , 16...) Otherwise, the display will not work properly.
2020-11-05 11:39:06 +08:00
**Example:**
2021-02-26 17:27:20 +08:00
```clike
2020-11-05 11:39:06 +08:00
if( InkPageSprite.creatSprite(0,0,200,200,true) != 0 )
{
Serial.printf"Ink Sprite creat faild");
}
Serial.printf("Ink Sprite creat successful");
```
## clear
**Syntax:**
`void clear( int cleanFlag = CLEAR_DRAWBUFF );`
**Description: Clear the content of the image area, CLEAR_DRAWBUFF (clear the image data that has not yet been pushed) CLEAR_LASTBUFF (clear the cache area of ​ ​ the image data refreshed last time, and refresh the screen completely when it is pushed again)**
**Example:**
2021-02-26 17:27:20 +08:00
```clike
2020-11-05 11:39:06 +08:00
InkPageSprite.clear();
```
## deleteSprite
**Syntax:**
`int deleteSprite();`
**Description: Release the created image area**
**Example:**
2021-02-26 17:27:20 +08:00
```clike
2020-11-05 11:39:06 +08:00
2020-12-03 12:00:42 +08:00
InkPageSprite.deleteSprite();
2020-11-05 11:39:06 +08:00
```
## pushSprite
**Syntax:**
`int pushSprite();`
**Description: Push the edited image data to the image area (after using the drawing API to operate, you need to push to refresh the screen)**
**Example:**
2021-02-26 17:27:20 +08:00
```clike
2020-11-05 11:39:06 +08:00
InkPageSprite.drawString(10,50,"Hello World!",&AsciiFont8x16);
InkPageSprite.pushSprite();
```
## drawPix
**Syntax:**
`void drawPix(uint16_t posX,uint16_t posY,uint8_t pixBit);`
**Description: draw a single pixel(the parameter pixBit is black when 0 is passed in, and white when 1 is passed in)**
**Example:**
2021-02-26 17:27:20 +08:00
```clike
2020-11-05 11:39:06 +08:00
InkPageSprite.drawPix(100,100,0);
InkPageSprite.pushSprite();
```
## FillRect
**Syntax:**
`void FillRect(uint16_t posX,
uint16_t posY,
uint16_t width,
uint16_t height,
uint8_t pixBit);`
**Description: draw a rectangle (the parameter pixBit is black when 0 is passed in, and white when 1 is passed in)**
**Example:**
2021-02-26 17:27:20 +08:00
```clike
2020-11-05 11:39:06 +08:00
InkPageSprite.FillRect(0,0,100,100,0);
InkPageSprite.pushSprite();
```
## drawFullBuff
**Syntax:**
`void drawFullBuff(uint8_t* buff, bool bitMode = true);`
` void drawBuff(uint16_t posX,
uint16_t posY,
uint16_t width,
uint16_t height,
uint8_t* imageDataptr);`
**Description: To draw the entire page, you need to pass in the complete page Buff**
## drawChar
**Syntax:**
`void drawChar(uint16_t posX,uint16_t posY,char charData,Ink_eSPI_font_t* fontPtr);`
**Description: draw characters**
**Example:**
2021-02-26 17:27:20 +08:00
```clike
2020-11-05 11:39:06 +08:00
InkPageSprite.drawChar(35,50,'M');
InkPageSprite.pushSprite();
```
## drawString
**Syntax:**
`void drawString(uint16_t posX,uint16_t posY,const char* charData,Ink_eSPI_font_t* fontPtr = &AsciiFont8x16);`
**Description: draw string**
**Example:**
2021-02-26 17:27:20 +08:00
```clike
2020-11-05 11:39:06 +08:00
InkPageSprite.drawString(35,50,"Hello World!");
InkPageSprite.pushSprite();
```
## getSpritePtr
**Syntax:**
**Description: Get image buff data**
`uint8_t* getSpritePtr(){ return _spriteBuff;}`
**Description: Get image width coordinate data**
`uint16_t width(){ return _width;}`
**Description: Get image height coordinate data**
`uint16_t height(){ return _height;}`
**Description: Get image X coordinate data**
`uint16_t posX(){ return _posX;}`
**Description: Get Y coordinate data of image area**
`uint16_t posY(){ return _posY;}`