niofis / display-hat-mini-node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

display-hat-mini-node

This library is a wrapper for the display-hat-mini-driver, that allows the use of the Pimoroni Display HAT Mini.

To install and build, please install the latest Rust language version. Which is required by Neon, the bindings library used to enable access to display-hat-mini-driver from node.js.

Usage

This is a simple example on how to use this library:

const dhtm = require('display-hat-mini-node');
const width = dhtm.width();
const height = dhtm.height();
const data = new Uint8Array(width * height * 3);

dhtm.init(); //this is always needed

for (let i = 0; i < height; i++) {
    for (let j = 0; j < width; j++) {
        let offset = (i * width + j) * 3;
        data[offset] = i; //red
        data[offset + 1] = j; //green
        data[offset + 2] = 0; //blue
    }
}

const buffer = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
dhtm.display(buffer);

Features

Bitmap drawing

display(Buffer)

Call this function to draw a bitmap in the display. This bitmap should have 320x240 pixels where each pixel is 3 bytes, i.e. RGB24.

VSync

setVSync(Boolean)

Instructs the driver to wait for the tear effect pin to become high before writing the bitmap data. It does not totally eliminate image tearing while drawing.

Button states

readButtons()

The return value of this function is a flags byte indicating the state of the hardward buttons. For more information refer to this explanation.

RGB LED

setLED(red, green, blue)

Simply call this function to show the RGB in the integrated RGB LED.

About


Languages

Language:Rust 100.0%