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