Skip to content

Commit

Permalink
Code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiao-H95 committed Sep 23, 2019
1 parent 02c901e commit d675e40
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 457 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
216 changes: 74 additions & 142 deletions examples/e_ink/e_ink.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*
This is a simple example show the e-ink
by Aaron.Lee from HelTec AutoMation, ChengDu, China
成都惠利特自动化科技有限公司
www.heltec.cn
*/
/*This Code applicable to e-ink(1.54/2.13/2.90) driven by HelTec AutoMation WiFi_Kit_Series Development Board.
Simple e-ink Display example
1.54--200 x 200 IMAGE_DATA 1,2
2.13--104 x 212 IMAGE_RED IMAGE_BLACK
2.90--128 x 296 IMAGE 1,2,3,4,5
*/

#include <SPI.h>
#include "e_ink.h"
#include "e_ink_display.h"
Expand All @@ -12,161 +13,92 @@
#define COLORED 0
#define UNCOLORED 1


#if defined( USE_154 )
unsigned char image[1024];
Paint paint(image, 0, 0); // width should be the multiple of 8
Epd epd;

void setup() {
/*Please select screen size in <e-ink.h>*/

void setup()
{
pinMode(12,OUTPUT);
digitalWrite(12,HIGH);
epd.Init(lut_full_update);
Display_clear();
#if defined(USE_154)
Display_picture(IMAGE_DATA2);
Display_clear();
Display_picture(IMAGE_DATA);
Display_clear();
Display_picture(IMAGE_DATA1);
Display_String(30,170,20,8,"E-INK-1.54",&Font20,30,15);
#elif defined(USE_213)
Display_Color_picture(IMAGE_BLACK,IMAGE_RED);
#elif defined(USE_290)
Display_picture(IMAGE2);
Display_clear();
Display_picture(IMAGE1);
Display_clear();
Display_picture(IMAGE);
Display_String(24,128,10,8,"E-INK-2.90",&Font16,50,90);
#endif
}

Serial.begin(9600);
#if defined( ESP32 )
SPI.begin(SCK,MISO,MOSI,SS);
void loop()
{

}

#elif defined( ESP8266 )
SPI.pins(SCK,MISO,MOSI,SS);
SPI.begin();
#endif
if (epd.Init(lut_full_update) != 0) {
Serial.print("e-Paper init failed");
return;
}
void Display_clear()
{
#if defined(USE_213)
epd.ClearFrame();
//epd.DisplayFrame();
#elif defined(USE_154) || defined(USE_290)
epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
epd.DisplayFrame();
epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
epd.DisplayFrame();
delay(1000);


paint.SetWidth(30);
paint.SetHeight(196);
paint.SetRotate(ROTATE_270);
paint.Clear(UNCOLORED);
paint.DrawStringAt(40, 10, "Hello world!", &Font16, COLORED);
epd.SetFrameMemory(paint.GetImage(),70, 5, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame();
delay(1000);

epd.SetFrameMemory(IMAGE_DATA2);
epd.DisplayFrame();
epd.SetFrameMemory(IMAGE_DATA2);
epd.DisplayFrame();
delay(2000);

epd.SetFrameMemory(IMAGE_DATA);
epd.DisplayFrame();
epd.SetFrameMemory(IMAGE_DATA);
epd.DisplayFrame();
delay(2000);

epd.SetFrameMemory(IMAGE_DATA1);
epd.DisplayFrame();
epd.SetFrameMemory(IMAGE_DATA1);
epd.DisplayFrame();
delay(2000);

// epd.SetFrameMemory(IMAGE_DATA1);
// epd.DisplayFrame();
// epd.SetFrameMemory(IMAGE_DATA1);
// epd.DisplayFrame();

#endif
}

void loop()
#if defined(USE_213)
void Display_Color_picture(const unsigned char* IMAGE_BLACK,const unsigned char* IMAGE_RED)
{
paint.SetWidth(30); /*设置区域的大小*/
paint.SetHeight(170);
paint.SetRotate(ROTATE_270); /*旋转文字的方向*/

paint.Clear(COLORED); /*将区域显示为黑色*/
paint.DrawStringAt(20,8, "E-INK-1.54", &Font20, UNCOLORED);
epd.SetFrameMemory(paint.GetImage(), 30, 15, paint.GetWidth(), paint.GetHeight()); /*设置区域的位置*/
epd.DisplayFrame();
delay(3000);

}

#elif defined( USE_213 )

Epd epd;
void setup() {
Serial.begin(9600);
#if defined( USE_ESP32 )
SPI.begin(SCK,MISO,MOSI,SS);
#elif defined( USE_ESP8266 )
SPI.pins(SCK,MISO,MOSI,SS);
SPI.begin();
#endif
if (epd.Init() != 0) {
Serial.print("e-Paper init failed");
return;
}

epd.ClearFrame();
epd.DisplayFrame(IMAGE_BLACK, IMAGE_RED);

/*
paint.Clear(COLORED);
paint.DrawStringAt(8, 2, "Hello world", &Font12, UNCOLORED);
epd.SetPartialWindowRed(paint.GetImage(), 0, 24, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame();
*/
}

void loop() {
// put your main code here, to run repeatedly:
epd.DisplayFrame(IMAGE_BLACK, IMAGE_RED);
}

#elif defined( USE_290 )

unsigned char image[1024];
Paint paint(image, 0, 0); // width should be the multiple of 8
Epd epd;

void setup() {
Serial.begin(9600);
#if defined( USE_ESP32 )
SPI.begin(SCK,MISO,MOSI,SS);
#elif defined( USE_ESP8266 )
SPI.pins(SCK,MISO,MOSI,SS);
SPI.begin();
#endif
if (epd.Init(lut_full_update) != 0)
{
Serial.print("e-Paper init failed");
return;
}
epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
#elif defined(USE_154) || defined(USE_290)
void Display_picture(const unsigned char* IMAGE_BUFFER)
{
epd.SetFrameMemory(IMAGE_BUFFER);
epd.DisplayFrame();
epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
epd.SetFrameMemory(IMAGE_BUFFER);
epd.DisplayFrame();
delay(2000);
}
#endif

epd.SetFrameMemory(IMAGE);
epd.DisplayFrame();
epd.SetFrameMemory(IMAGE);
/*width,Heigh显示区域的快读和高度
TextX,TextY在显示区域中字符的起始位置
text为显示内容
font为显示字体:font8、font12、font16、font20、font24
areaX,areaY显示区域相对于屏的起始位置,右上角为(0,0)
*/
void Display_String(int width, int Heigh, int TextX, int TextY, const char* text, sFONT* font, int areaX,int aeraY )
{
paint.Clear(COLORED);
paint.SetWidth(width); /*设置区域的大小*/
paint.SetHeight(Heigh);
paint.SetRotate(ROTATE_270); /*旋转文字的方向*/
paint.DrawStringAt(TextX, TextY, text, font, UNCOLORED);

#if defined(USE_213)
//epd.SetPartialWindowBlack(paint.GetImage(), areaX, aeraY, paint.GetWidth(), paint.GetHeight());
epd.SetPartialWindowRed(paint.GetImage(), areaX, aeraY, paint.GetWidth(), paint.GetHeight());
#elif defined(USE_154) || defined(USE_290)
epd.SetFrameMemory(paint.GetImage(), areaX,aeraY, paint.GetWidth(), paint.GetHeight());
#endif
epd.DisplayFrame();
delay(1000);

if (epd.Init(lut_partial_update) != 0) {
Serial.print("e-Paper init failed");
return;
}
}

void loop() {




//paint.SetWidth(24); /*设置区域的大小*/
// paint.SetHeight(128);
//paint.SetRotate(ROTATE_270); /*旋转文字的方向*/
// paint.Clear(COLORED); /*将区域显示为黑色*/
// paint.DrawStringAt(10,8, "E-INK-2.90", &Font16, UNCOLORED); /*设置文字的位置*/
//epd.SetFrameMemory(paint.GetImage(), 50,90, paint.GetWidth(), paint.GetHeight()); /*设置区域的位置*/
// epd.DisplayFrame();
// delay(1000);
}
#endif
48 changes: 40 additions & 8 deletions src/e_ink.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <stdlib.h>
#include "e_ink.h"
#include "imagedata.h"

#if defined( USE_154 )
Epd::~Epd() {
Expand All @@ -17,8 +16,17 @@ Epd::Epd() {

int Epd::Init(const unsigned char* lut) {
/* this calls the peripheral hardware interface, see epdif */
Serial.begin(9600);
#if defined( USE_ESP32 )
SPI.begin(SCK,MISO,MOSI,SS);

#elif defined( USE_ESP8266 )
SPI.pins(SCK,MISO,MOSI,SS);
SPI.begin();
#endif
if (IfInit() != 0) {
return -1;
Serial.print("e-Paper init failed");
}
/* EPD hardware init start */
this->lut = lut;
Expand All @@ -41,6 +49,7 @@ int Epd::Init(const unsigned char* lut) {
SendData(0x03); // X increment; Y increment
SetLut(this->lut);
/* EPD hardware init end */
Serial.print("e-Paper init OK");
return 0;
}

Expand Down Expand Up @@ -264,9 +273,18 @@ Epd::Epd() {
height = EPD_HEIGHT;
};

int Epd::Init(void) {
int Epd::Init(const unsigned char* lut) {
/* this calls the peripheral hardware interface, see epdif */
Serial.begin(9600);
#if defined( USE_ESP32 )
SPI.begin(SCK,MISO,MOSI,SS);

#elif defined( USE_ESP8266 )
SPI.pins(SCK,MISO,MOSI,SS);
SPI.begin();
#endif
if (IfInit() != 0) {
Serial.print("e-Paper init failed");
return -1;
}
/* EPD hardware init start */
Expand All @@ -284,10 +302,16 @@ int Epd::Init(void) {
SendData(0x00);
SendData(0xD4); // height: 212
/* EPD hardware init end */
Serial.print("e-Paper init OK");
return 0;

}

const unsigned char lut_full_update[] =
{

};

/**
* @brief: basic function for sending commands
*/
Expand Down Expand Up @@ -464,8 +488,18 @@ Epd::Epd() {
};

int Epd::Init(const unsigned char* lut) {

Serial.begin(9600);
#if defined( USE_ESP32 )
SPI.begin(SCK,MISO,MOSI,SS);

#elif defined( USE_ESP8266 )
SPI.pins(SCK,MISO,MOSI,SS);
SPI.begin();
#endif

if (IfInit() != 0) {
Serial.print("e-Paper init failed");
return -1;
}

Expand All @@ -480,18 +514,16 @@ int Epd::Init(const unsigned char* lut) {
SendData(0xD6);
SendData(0x9D);
SendCommand(WRITE_VCOM_REGISTER); //0X2C
SendData(0xA8); // VCOM 7C
//SendData(0X9A); // VCOM 7C
SendData(0xA8); //9A // VCOM 7C
SendCommand(SET_DUMMY_LINE_PERIOD); //0X3A
SendData(0x1A); // 4 dummy lines per gate
SendCommand(SET_GATE_TIME); //0X3B
SendData(0x08); // 2us per line
SendCommand(DATA_ENTRY_MODE_SETTING); //0X11
//SendData(0x01); // X increment; Y increment
SendData(0x03); // X increment; Y increment
SendData(0x03); //SendData(0x03); // X increment; Y increment
SetLut(this->lut);
/* EPD hardware init end */
Serial.print("e-Paper init OK");
return 0;
}

Expand Down
10 changes: 9 additions & 1 deletion src/e_ink.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#ifndef E_INK_H
#define E_INK_H

#include <Arduino.h>
#include "epdif.h"
#include <Wire.h>
#include <SPI.h>
#include "imagedata.h"

/*Select screen size*/
#define USE_290 /*USE_154、USE213、USE_290*/

#if defined( USE_154 )
// Display resolution
Expand Down Expand Up @@ -116,14 +122,16 @@ class Epd : EpdIf {
#define READ_OTP_DATA 0xA2
#define POWER_SAVING 0xE3

extern const unsigned char lut_full_update[];

class Epd : EpdIf {
public:
int width;
int height;

Epd();
~Epd();
int Init(void);
int Init(const unsigned char* lut);
void SendCommand(unsigned char command);
void SendData(unsigned char data);
void SetPartialWindow(const unsigned char* buffer_black, const unsigned char* buffer_red, int x, int y, int w, int l);
Expand Down
Loading

0 comments on commit d675e40

Please sign in to comment.