Lightweight proportional text library for C12832 LCD. Easy to modify, fast, robust and compact. Nice font, good for text driven menus, messages, etc. Fell free to use and modify in any projects.
Documentation will be here later.
Usage sample:
Import programapp-board-lcd128
Sample usage of lightweight C12832 LCD library
Diff: lcd128lib.cpp
- Revision:
- 6:5cd32671a837
- Parent:
- 5:ff31feb7d966
- Child:
- 7:d73d65360196
--- a/lcd128lib.cpp Wed May 28 10:09:01 2014 +0000 +++ b/lcd128lib.cpp Tue Oct 07 20:50:41 2014 +0000 @@ -17,10 +17,10 @@ void lcd128::write(unsigned char data, bool cmd) { - a0 = cmd ? 0 : 1; - cs = 0; + a0 = cmd ? 0 : 1; + cs = 0; spi.write(data); - cs = 1; + cs = 1; } // Constructor, SPI setup and defaults @@ -32,12 +32,13 @@ spi.format(8, 3); spi.frequency(20000000); - // Setup default font + // Default font font.first_code = 32; - font.glyphs_total = 128 - 32; + font.glyphs_total = sizeof(lcd_font8p_widths) / sizeof(unsigned char); font.widths = lcd_font8p_widths; font.glyphs = lcd_font8p; + // Default drawing modes invert = false; bold = false; underline = false; @@ -142,12 +143,23 @@ if(row == -1) memset(buffer, 0, sizeof(buffer)); else { - if(row<0) row=0; - if(row>LCD_Y) row=0; - memset(buffer+row*LCD_X, 0, LCD_X); + if(row < 0) row = 0; + if(row >= LCD_Y) row = LCD_Y - 1; + memset(buffer + row*LCD_X, 0, LCD_X); } +} - Update(); +// Inverse all buffer or just one row + +void lcd128::InverseRow(int row, unsigned char mask) +{ + if(row == -1) + for(int i=0; i < LCD_X*LCD_Y; i++) buffer[i] ^= mask; + else { + if(row < 0) row = 0; + if(row >= LCD_Y) row = LCD_Y - 1; + for(int i=LCD_X*row; i < LCD_X*(row+1); i++) buffer[i] ^= mask; + } } // Change current output position @@ -269,24 +281,30 @@ } // Clear one line, -// then write string from it's begin +// then write string from it's begin. +// It can be inverted and aligned left, center and right -void lcd128::Row(int Y, char* str) +void lcd128::Row(int Y, char* str, bool inverse, int align) { Clear(Y); XY(0, Y); + switch(align) { + case 1: + XY((LCD_X/2)-StringWidth(str)/2,Y); + break; + case 2: + XY(LCD_X-StringWidth(str),Y); + break; + case 0: + default: + XY(0, Y); + break; + } + String(str); + if (inverse) InverseRow(Y); } -// Same, but center text - -void lcd128::RowCenter(int Y, char* str) -{ - Clear(Y); - XY((LCD_X/2)-StringWidth(str)/2,Y); - String(str); -} - // Draw progress bar // fill from 0.0f to 1.0f