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