Draw the character of the ASCII code.
Dependents: mbed-os_Watson-IoT_ZXing_sample mbed-os_Watson-IoT_ZXing_sample MovPlayer GR-PEACH_HVC-P2_sample_client ... more
Fork of AsciiFont by
AsciiFont
This is a library to draw the ASCII font characters.
Example
#include "mbed.h" #include "AsciiFont.h" #define WIDTH (12) #define HEIGHT (16) #define BYTE_PER_PIXEL (1u) #define STRIDE (((WIDTH * BYTE_PER_PIXEL) + 7u) & ~7u) //multiple of 8 uint8_t text_field[STRIDE * HEIGHT]; //for debug void print_text_field() { int idx = 0; for (int i = 0; i < HEIGHT; i++) { for (int j = 0; j < STRIDE; j++) { printf("%02x", text_field[idx++]); } printf("\r\n"); } printf("\r\n"); } int main() { AsciiFont ascii_font(text_field, WIDTH, HEIGHT, STRIDE, BYTE_PER_PIXEL); ascii_font.Erase(0xcc); ascii_font.DrawStr("AB", 0, 0, 0x11, 1); ascii_font.DrawChar('C', AsciiFont::CHAR_PIX_WIDTH, AsciiFont::CHAR_PIX_HEIGHT, 0x22, 1); print_text_field(); //debug print ascii_font.Erase(); ascii_font.DrawStr("D", 0, 0, 0xef, 2); print_text_field(); //debug print ascii_font.Erase(0x11, 6, 0, 6, 8); print_text_field(); //debug print }
API
Import library
Public Member Functions |
|
AsciiFont (uint8_t *p_buf, int width, int height, int stride, int byte_per_pixel, uint32_t const colour=0) | |
Constructor: Initializes
AsciiFont
.
|
|
void | Erase () |
Erase text field.
|
|
void | Erase (uint32_t const colour) |
Erase text field.
|
|
void | Erase (uint32_t const colour, int x, int y, int width, int height) |
Erase text field.
|
|
int | DrawStr (char *str, int x, int y, uint32_t const colour, int font_size=1, uint16_t const max_char_num=0xffff) |
Draw a string.
|
|
bool | DrawChar (char c, int x, int y, uint32_t const colour, int font_size=1) |
Draw a character.
|
|
Static Public Attributes |
|
static const int | CHAR_PIX_WIDTH = 6 |
The pixel width of a character.
|
|
static const int | CHAR_PIX_HEIGHT = 8 |
The pixel height of a character.
|
History
Added range check to Erase function.
2017-03-07, by dkato [Tue, 07 Mar 2017 05:04:28 +0000] rev 5
Added range check to Erase function.
Change argument of DrawStr.
2017-01-23, by dkato [Mon, 23 Jan 2017 06:20:37 +0000] rev 4
Change argument of DrawStr.
Change the API.
2016-10-03, by dkato [Mon, 03 Oct 2016 06:50:04 +0000] rev 3
Change the API.
Change the API.
2016-10-03, by dkato [Mon, 03 Oct 2016 06:33:40 +0000] rev 2
Change the API.
Update ascii.c.
2016-10-03, by dkato [Mon, 03 Oct 2016 02:20:49 +0000] rev 1
Update ascii.c.
first commit
2016-09-27, by dkato [Tue, 27 Sep 2016 07:03:20 +0000] rev 0
first commit