1.0.4 • Published 7 years ago

epaper v1.0.4

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

epaper

Coming soon: support for displaying images (from SD card)

Node.js library for the 4.3 Inch E-Paper display by Waveshare

e-paper Display Sample

Install

This project uses serialport, before you install this libary, please have a look at this section of the serialport readme: https://www.npmjs.com/package/serialport#installation-instructions

Installing epaper module:

npm install epaper

Sample Code

Assuming you have the e-paper displayed connected to /dev/cu.usbserial:

const Display = require('epaper').Display;
const display = new Display('/dev/cu.usbserial', true);
 
display.handshake()
    .then(() => display.setColor(Display.BLACK, Display.WHITE))
    .then(display.clear)
    .then(() => display.setFont(Display.ASCII64))
    .then(() => display.displayString('Hello World!', 50, 100))
    .then(() => display.setFont(Display.ASCII48))
    .then(() => display.displayString('github.com/steamedcotton', 50, 180))
    .then(() => display.drawCircle(75, 350, 50))
    .then(() => display.drawFilledCircle(75, 350, 25))
    .then(() => display.drawTriangle(150, 300, 150, 400, 200, 400))
    .then(() => display.drawFillTriangle(150, 300, 200, 300, 200, 400))
    .then(() => display.drawRect(250, 300, 350, 400))
    .then(() => display.drawFilledRect(375, 300, 475, 400))
    .then(() => display.drawLine(50, 420, 475, 420))
    .then(display.update)
    .catch((err) => console.log('Error:', err));

Methods

Utilities

Handshake

After the epaper has powered up, you can send the handshake command to make sure whether the terminal is ready and able to receive commands or data.

handshake()

Clear

Clears the screen using the background color

clear()

Update

Used to refresh and update the display (clears then displays). All the commands sent in the session will be displayed.

update()

Set Color

Sets the foreground and background color of the drawing. The foreground color is used in the display the basic drawings and text. The background color is used for the cleared screen.

setColor(<FORGROUND COLOR>, <BACKGROUND COLOR>)

Colors

The colors can be referenced as static variables on the Display object.

  • Display.WHITE
  • Display.GRAY
  • Display.DARK_GRAY
  • Display.BLACK

Draw

Pixel

drawPixel(<X -> Int>, <Y -> Int>)

Line

Draws a line with the 2 given points (X1, Y1 > X2, Y2).

drawLine(<X1 -> Int>, <Y1 -> Int>, <X2 -> Int>, <Y2 -> Int>)

Rectangle

Draws a rectangle with the two given points (opposite corners)

drawRect(<X1 -> Int>, <Y1 -> Int>, <X2 -> Int>, <Y2 -> Int>)

Filled Rectangle

drawFilledRect(<X1 -> Int>, <Y1 -> Int>, <X2 -> Int>, <Y2 -> Int>)

Circle

Draws a circle with the given point (X, Y) being the center and the third parameter being the radius.

drawCircle(<X1 -> Int>, <Y1 -> Int>, <RADIUS -> Int>) 

Filled Circle

drawFilledCircle(<X1 -> Int>, <Y1 -> Int>, <RADIUS -> Int>) 

Trangle

Draws a triangle using the three points given.

drawTrangle(<X1 -> Int>, <Y1 -> Int>, <X2 -> Int>, <Y2 -> Int>, <X3 -> Int>, <Y3 -> Int>) 

Filled Triangle

drawFilledTriangle(<X1 -> Int>, <Y1 -> Int>, <X2 -> Int>, <Y2 -> Int>, <X3 -> Int>, <Y3 -> Int>) 

Text

Set Font

setFont(<FONT>)

Fonts

The fonts can be referenced as static varibles on the Display object.

English:

  • ASCII32
  • ASCII48
  • ASCII64

Chinese

  • GBK32
  • GBK48
  • GBK64

Display Text

Displays a provided string at the given location using the current forground color and font. Maximum lentgh is 1020 bytes.

displayText(<X -> Int>, <Y -> Int>, <Text -> Sting>);

Resources