Fork of Silabs MemoryLCD library
Dependents: demoUI whrmDemoUI Host_Software_MAX32664GWEB_HR_EXTENDED Host_Software_MAX32664GWEC_SpO2_HR-_EXTE ... more
C++ library for Sharp Microelectronics 1.28 inch LCD TFT, LS013B7DH03, SPI bus. Forked from Silicon Labs MemoryLCD display driver.
TextDisplay.cpp@12:ca0bcb4777e9, 2019-01-02 (annotated)
- Committer:
- gmehmet
- Date:
- Wed Jan 02 13:20:35 2019 +0300
- Revision:
- 12:ca0bcb4777e9
- Parent:
- 11:0f8ae10b308d
adapt memorylcd code to use it with maxim boards
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Steven Cooreman |
0:a0faa86660d4 | 1 | /* mbed TextDisplay Display Library Base Class |
Steven Cooreman |
0:a0faa86660d4 | 2 | * Copyright (c) 2007-2009 sford |
Steven Cooreman |
0:a0faa86660d4 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
Steven Cooreman |
0:a0faa86660d4 | 4 | */ |
Steven Cooreman |
0:a0faa86660d4 | 5 | |
gmehmet | 12:ca0bcb4777e9 | 6 | #include "../screen/TextDisplay.h" |
gmehmet | 12:ca0bcb4777e9 | 7 | |
Steven Cooreman |
0:a0faa86660d4 | 8 | #include <cstdarg> |
Steven Cooreman |
0:a0faa86660d4 | 9 | |
Steven Cooreman |
0:a0faa86660d4 | 10 | TextDisplay::TextDisplay(const char *name){ |
Steven Cooreman |
0:a0faa86660d4 | 11 | _row = 0; |
Steven Cooreman |
0:a0faa86660d4 | 12 | _column = 0; |
Steven Cooreman |
0:a0faa86660d4 | 13 | |
Steven Cooreman |
0:a0faa86660d4 | 14 | if (name == NULL) { |
Steven Cooreman |
0:a0faa86660d4 | 15 | _path = NULL; |
Steven Cooreman |
0:a0faa86660d4 | 16 | } else { |
Steven Cooreman |
0:a0faa86660d4 | 17 | _path = new char[strlen(name) + 2]; |
Steven Cooreman |
0:a0faa86660d4 | 18 | sprintf(_path, "/%s", name); |
Steven Cooreman |
0:a0faa86660d4 | 19 | } |
Steven Cooreman |
0:a0faa86660d4 | 20 | } |
Steven Cooreman |
0:a0faa86660d4 | 21 | |
Steven Cooreman |
0:a0faa86660d4 | 22 | int TextDisplay::_putc(int value) { |
Steven Cooreman |
0:a0faa86660d4 | 23 | if(value == '\n') { |
Steven Cooreman |
0:a0faa86660d4 | 24 | _column = 0; |
Steven Cooreman |
0:a0faa86660d4 | 25 | _row++; |
Steven Cooreman |
0:a0faa86660d4 | 26 | if(_row >= rows()) { |
Steven Cooreman |
0:a0faa86660d4 | 27 | _row = 0; |
Steven Cooreman |
0:a0faa86660d4 | 28 | } |
Steven Cooreman |
0:a0faa86660d4 | 29 | } else { |
Steven Cooreman |
0:a0faa86660d4 | 30 | character(_column, _row, value); |
Steven Cooreman |
0:a0faa86660d4 | 31 | _column++; |
Steven Cooreman |
0:a0faa86660d4 | 32 | if(_column >= columns()) { |
Steven Cooreman |
0:a0faa86660d4 | 33 | _column = 0; |
Steven Cooreman |
0:a0faa86660d4 | 34 | _row++; |
Steven Cooreman |
0:a0faa86660d4 | 35 | if(_row >= rows()) { |
Steven Cooreman |
0:a0faa86660d4 | 36 | _row = 0; |
Steven Cooreman |
0:a0faa86660d4 | 37 | } |
Steven Cooreman |
0:a0faa86660d4 | 38 | } |
Steven Cooreman |
0:a0faa86660d4 | 39 | } |
Steven Cooreman |
0:a0faa86660d4 | 40 | return value; |
Steven Cooreman |
0:a0faa86660d4 | 41 | } |
Steven Cooreman |
0:a0faa86660d4 | 42 | |
Steven Cooreman |
0:a0faa86660d4 | 43 | // crude cls implementation, should generally be overwritten in derived class |
Steven Cooreman |
0:a0faa86660d4 | 44 | void TextDisplay::cls() { |
Steven Cooreman |
0:a0faa86660d4 | 45 | locate(0, 0); |
Steven Cooreman |
0:a0faa86660d4 | 46 | for(int i=0; i<columns()*rows(); i++) { |
Steven Cooreman |
0:a0faa86660d4 | 47 | _putc(' '); |
Steven Cooreman |
0:a0faa86660d4 | 48 | } |
Steven Cooreman |
0:a0faa86660d4 | 49 | } |
Steven Cooreman |
0:a0faa86660d4 | 50 | |
stevew817 | 11:0f8ae10b308d | 51 | void TextDisplay::set_font(const unsigned char * f) { |
stevew817 | 11:0f8ae10b308d | 52 | font = f; |
stevew817 | 11:0f8ae10b308d | 53 | if(font==NULL) { |
stevew817 | 11:0f8ae10b308d | 54 | externalfont = 0; // set display.font |
stevew817 | 11:0f8ae10b308d | 55 | locate(0, 0); |
stevew817 | 11:0f8ae10b308d | 56 | } |
stevew817 | 11:0f8ae10b308d | 57 | else{ |
stevew817 | 11:0f8ae10b308d | 58 | externalfont = 1; |
stevew817 | 11:0f8ae10b308d | 59 | locate(0, 0); |
stevew817 | 11:0f8ae10b308d | 60 | } |
stevew817 | 11:0f8ae10b308d | 61 | } |
stevew817 | 11:0f8ae10b308d | 62 | |
Steven Cooreman |
0:a0faa86660d4 | 63 | void TextDisplay::locate(int column, int row) { |
Steven Cooreman |
0:a0faa86660d4 | 64 | _column = column; |
Steven Cooreman |
0:a0faa86660d4 | 65 | _row = row; |
stevew817 | 11:0f8ae10b308d | 66 | char_x = column; |
stevew817 | 11:0f8ae10b308d | 67 | char_y = row; |
Steven Cooreman |
0:a0faa86660d4 | 68 | } |
Steven Cooreman |
0:a0faa86660d4 | 69 | |
Steven Cooreman |
0:a0faa86660d4 | 70 | int TextDisplay::_getc() { |
Steven Cooreman |
0:a0faa86660d4 | 71 | return -1; |
Steven Cooreman |
0:a0faa86660d4 | 72 | } |
Steven Cooreman |
0:a0faa86660d4 | 73 | |
Steven Cooreman |
0:a0faa86660d4 | 74 | void TextDisplay::foreground(uint16_t colour) { |
Steven Cooreman |
0:a0faa86660d4 | 75 | _foreground = colour; |
Steven Cooreman |
0:a0faa86660d4 | 76 | } |
Steven Cooreman |
0:a0faa86660d4 | 77 | |
Steven Cooreman |
0:a0faa86660d4 | 78 | void TextDisplay::background(uint16_t colour) { |
Steven Cooreman |
0:a0faa86660d4 | 79 | _background = colour; |
Steven Cooreman |
0:a0faa86660d4 | 80 | } |
Steven Cooreman |
0:a0faa86660d4 | 81 | |
Steven Cooreman |
0:a0faa86660d4 | 82 | void TextDisplay::printf(const char* format, ...) { |
Steven Cooreman |
0:a0faa86660d4 | 83 | char buffer[MAX_PRINTF_CHARS + 1] = { 0 }; |
Steven Cooreman |
0:a0faa86660d4 | 84 | uint32_t iterator = 0; |
Steven Cooreman |
0:a0faa86660d4 | 85 | va_list args; |
Steven Cooreman |
0:a0faa86660d4 | 86 | va_start(args, format); |
Steven Cooreman |
0:a0faa86660d4 | 87 | vsprintf(buffer, format, args); |
Steven Cooreman |
0:a0faa86660d4 | 88 | va_end(args); |
Steven Cooreman |
0:a0faa86660d4 | 89 | |
Steven Cooreman |
0:a0faa86660d4 | 90 | while((buffer[iterator] != 0) && (iterator < MAX_PRINTF_CHARS)) { |
Steven Cooreman |
0:a0faa86660d4 | 91 | _putc(buffer[iterator++]); |
Steven Cooreman |
0:a0faa86660d4 | 92 | } |
Steven Cooreman |
0:a0faa86660d4 | 93 | } |