lib/unigraphic/TextDisplay.cpp

Sun, 25 Oct 2020 17:02:53 +0100

author
David Douard <david.douard@sdf3.org>
date
Sun, 25 Oct 2020 17:02:53 +0100
changeset 30
71be284c66b3
parent 5
f1c85c2500f2
permissions
-rw-r--r--

Update the custom target HP34970_FP_303RD

update the platformio.ini:
remove unused flags, and configure so it uses includes from the project's root
directory (in TARGET_HP34970_FP_F303RD) so these .h/.c files do not conflict
when compiling for other targets.

Add a TARGET_HP34970_FR_F303RD/ for target specific headers/linker files.
Add a src/TARGET_HP34970_FR_F303RD/ for c files (protected by '#if defined'
statments).

5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 /* mbed TextDisplay Display Library Base Class
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2 * Copyright (c) 2007-2009 sford
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 * Released under the MIT License: http://mbed.org/license/mit
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6 #include "TextDisplay.h"
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 TextDisplay::TextDisplay(const char *name) : Stream(name){
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9 _row = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 _column = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11 if (name == NULL) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
12 _path = NULL;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13 } else {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14 _path = new char[strlen(name) + 2];
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
15 sprintf(_path, "/%s", name);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
16 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
18
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19 int TextDisplay::_putc(int value) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
20 if(value == '\n') {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
21 _column = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
22 _row++;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
23 if(_row >= rows()) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
24 _row = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26 } else {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 character(_column, _row, value);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28 _column++;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29 if(_column >= columns()) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
30 _column = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
31 _row++;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
32 if(_row >= rows()) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
33 _row = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
34 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
36 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
37 return value;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
38 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
39
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
40 // crude cls implementation, should generally be overwritten in derived class
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
41 void TextDisplay::cls() {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
42 locate(0, 0);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
43 for(int i=0; i<columns()*rows(); i++) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
44 putc(' ');
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
45 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
46 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
47
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
48 void TextDisplay::locate(int column, int row) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
49 _column = column;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
50 _row = row;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
51 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
52
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
53 int TextDisplay::_getc() {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
54 return -1;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
55 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
56
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
57 void TextDisplay::foreground(uint16_t colour) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
58 _foreground = colour;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
59 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
60
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
61 void TextDisplay::background(uint16_t colour) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
62 _background = colour;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
63 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
64
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
65 bool TextDisplay::claim (FILE *stream) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
66 if ( _path == NULL) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
67 fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n");
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
68 return false;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
69 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
70 if (freopen(_path, "w", stream) == NULL) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
71 // Failed, should not happen
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
72 return false;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
73 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
74 // make sure we use line buffering
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
75 setvbuf(stdout, NULL, _IOLBF, columns());
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
76 return true;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
77 }

mercurial