GithubHelp home page GithubHelp logo

esp-glib's Introduction

esp-glib

WIP 2D graphics / FB library for ESP8266 with NONOS SDK.

Included are right now:

  • Bitmap-to-4bit greyscale converter (see tools/)

  • Font-renderer with

    • textbox support
    • line-break on words
    • multiple fonts / sizes
    • backspace support
    • UTF-8 support (escape with 'u+xxxx' or 'U+xxxxxxxx')...
  • Some simple animations

  • Some primitives

  • driver for SSD1322. SPI is done with MetalPhreak's SPI driver.

Usage:

#include "esp-glib.h"
// user_init:
glib_init();

// example: print to a screen
glib_clear_fb(GLIB_OS_ALL);         // clear everything in framebuffer
glib_set_textbox(NULL);             // set current textbox to whole screen
glib_clear_tb_txt_state();          // clear current text positioning information
glib_set_font(A_FONT_YOU_CONVERTED);// select font (as well as font size)
glib_set_mode(GLIB_DM_FREE);        // set draw mode to free mode
glib_print("ESP8266 here!",         // zero-terminated uint8_t array; utf8 escape: u+xxxx
           0,                       // x-coordinate (origin: top left)
           0,                       // y-coordinate (char origin: baseline *)
           GLIB_TP_TOPMOST | GLIB_TP_CENTER_X, /* glib_txt_position: 
                                       auto handle y coordinate & center horizontically*/
           GLIB_DA_NONE,            /* glib_draw_args: mainly for drawing bitmaps
                                       (e.g. flip, invert, switch endianness...) */
           NULL,                    
           NULL);                   // returns coordinates of end of string
           
glib_fb2gram();                     // push framebuffer to display graphics RAM (slow)

* see https://en.wikipedia.org/wiki/Typeface#Font_metrics

Fonts and assets (bitmaps) can be created with a bitmap font converter such as andryblack's fontbuilder* and converted to greyscale via 'png2gs.py' in tools/.

* I added the option to specify the freetype hinting algorithm ("Smoothing" box). Try "LCD horizontal" or "LCD vertical"; both look distinctively better than the standard option on a small LCD screen like the one we're using.

Sample project using this library/driver

png2gs

  • Install pypng: pip3 install pypng
  • To convert assets/bitmaps: ./png2gs -nf resources/myassets/* -a 4 -d 4
  • To convert fonts: ./png2gs -f resources/myfonts/* -a 4 -d 4,

where the -d switch selects target bit depth (16 shades of grey in this example for SSD1322) and -a can be used to align data by that many bytes (for ESP8266 data in flash must be 4 byte aligned).

For additional options call png2gs without arguments.

Take a look at the headers created for means of accessing the data once written to flash.

esp-glib's People

Contributors

r-or avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

stegophone

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.