TEST

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

Committer:
wwwarunraj
Date:
Sun Apr 19 11:19:57 2020 +0000
Revision:
4:291477e8690d
Parent:
1:f60eafbf009a
19/04

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gmehmet 1:f60eafbf009a 1 /* mbed TextDisplay Display Library Base Class
gmehmet 1:f60eafbf009a 2 * Copyright (c) 2007-2009 sford
gmehmet 1:f60eafbf009a 3 * Released under the MIT License: http://mbed.org/license/mit
gmehmet 1:f60eafbf009a 4 */
gmehmet 1:f60eafbf009a 5
gmehmet 1:f60eafbf009a 6 #include "TextDisplay.h"
gmehmet 1:f60eafbf009a 7 #include <cstdarg>
gmehmet 1:f60eafbf009a 8
gmehmet 1:f60eafbf009a 9 TextDisplay::TextDisplay(const char *name){
gmehmet 1:f60eafbf009a 10 _row = 0;
gmehmet 1:f60eafbf009a 11 _column = 0;
gmehmet 1:f60eafbf009a 12
gmehmet 1:f60eafbf009a 13 if (name == NULL) {
gmehmet 1:f60eafbf009a 14 _path = NULL;
gmehmet 1:f60eafbf009a 15 } else {
gmehmet 1:f60eafbf009a 16 _path = new char[strlen(name) + 2];
gmehmet 1:f60eafbf009a 17 sprintf(_path, "/%s", name);
gmehmet 1:f60eafbf009a 18 }
gmehmet 1:f60eafbf009a 19 }
gmehmet 1:f60eafbf009a 20
gmehmet 1:f60eafbf009a 21 int TextDisplay::_putc(int value) {
gmehmet 1:f60eafbf009a 22 if(value == '\n') {
gmehmet 1:f60eafbf009a 23 _column = 0;
gmehmet 1:f60eafbf009a 24 _row++;
gmehmet 1:f60eafbf009a 25 if(_row >= rows()) {
gmehmet 1:f60eafbf009a 26 _row = 0;
gmehmet 1:f60eafbf009a 27 }
gmehmet 1:f60eafbf009a 28 } else {
gmehmet 1:f60eafbf009a 29 character(_column, _row, value);
gmehmet 1:f60eafbf009a 30 _column++;
gmehmet 1:f60eafbf009a 31 if(_column >= columns()) {
gmehmet 1:f60eafbf009a 32 _column = 0;
gmehmet 1:f60eafbf009a 33 _row++;
gmehmet 1:f60eafbf009a 34 if(_row >= rows()) {
gmehmet 1:f60eafbf009a 35 _row = 0;
gmehmet 1:f60eafbf009a 36 }
gmehmet 1:f60eafbf009a 37 }
gmehmet 1:f60eafbf009a 38 }
gmehmet 1:f60eafbf009a 39 return value;
gmehmet 1:f60eafbf009a 40 }
gmehmet 1:f60eafbf009a 41
gmehmet 1:f60eafbf009a 42 // crude cls implementation, should generally be overwritten in derived class
gmehmet 1:f60eafbf009a 43 void TextDisplay::cls() {
gmehmet 1:f60eafbf009a 44 locate(0, 0);
gmehmet 1:f60eafbf009a 45 for(int i=0; i<columns()*rows(); i++) {
gmehmet 1:f60eafbf009a 46 _putc(' ');
gmehmet 1:f60eafbf009a 47 }
gmehmet 1:f60eafbf009a 48 }
gmehmet 1:f60eafbf009a 49
gmehmet 1:f60eafbf009a 50 void TextDisplay::set_font(const unsigned char * f) {
gmehmet 1:f60eafbf009a 51 font = f;
gmehmet 1:f60eafbf009a 52 if(font==NULL) {
gmehmet 1:f60eafbf009a 53 externalfont = 0; // set display.font
gmehmet 1:f60eafbf009a 54 locate(0, 0);
gmehmet 1:f60eafbf009a 55 }
gmehmet 1:f60eafbf009a 56 else{
gmehmet 1:f60eafbf009a 57 externalfont = 1;
gmehmet 1:f60eafbf009a 58 locate(0, 0);
gmehmet 1:f60eafbf009a 59 }
gmehmet 1:f60eafbf009a 60 }
gmehmet 1:f60eafbf009a 61
gmehmet 1:f60eafbf009a 62 void TextDisplay::locate(int column, int row) {
gmehmet 1:f60eafbf009a 63 _column = column;
gmehmet 1:f60eafbf009a 64 _row = row;
gmehmet 1:f60eafbf009a 65 char_x = column;
gmehmet 1:f60eafbf009a 66 char_y = row;
gmehmet 1:f60eafbf009a 67 }
gmehmet 1:f60eafbf009a 68
gmehmet 1:f60eafbf009a 69 int TextDisplay::_getc() {
gmehmet 1:f60eafbf009a 70 return -1;
gmehmet 1:f60eafbf009a 71 }
gmehmet 1:f60eafbf009a 72
gmehmet 1:f60eafbf009a 73 void TextDisplay::foreground(uint16_t colour) {
gmehmet 1:f60eafbf009a 74 _foreground = colour;
gmehmet 1:f60eafbf009a 75 }
gmehmet 1:f60eafbf009a 76
gmehmet 1:f60eafbf009a 77 void TextDisplay::background(uint16_t colour) {
gmehmet 1:f60eafbf009a 78 _background = colour;
gmehmet 1:f60eafbf009a 79 }
gmehmet 1:f60eafbf009a 80
gmehmet 1:f60eafbf009a 81 void TextDisplay::printf(const char* format, ...) {
gmehmet 1:f60eafbf009a 82 char buffer[MAX_PRINTF_CHARS + 1] = { 0 };
gmehmet 1:f60eafbf009a 83 uint32_t iterator = 0;
gmehmet 1:f60eafbf009a 84 va_list args;
gmehmet 1:f60eafbf009a 85 va_start(args, format);
gmehmet 1:f60eafbf009a 86 vsprintf(buffer, format, args);
gmehmet 1:f60eafbf009a 87 va_end(args);
gmehmet 1:f60eafbf009a 88
gmehmet 1:f60eafbf009a 89 while((buffer[iterator] != 0) && (iterator < MAX_PRINTF_CHARS)) {
gmehmet 1:f60eafbf009a 90 _putc(buffer[iterator++]);
gmehmet 1:f60eafbf009a 91 }
gmehmet 1:f60eafbf009a 92 }