Displays a large title and some small text with a blue rectangle Constantly refreshes 3 variable values on the screen. NO TOUCH SUPPORT AS OF YET

Dependencies:   mbed

Committer:
EmbeddedSam
Date:
Sat Dec 05 23:41:01 2015 +0000
Revision:
0:38cf064697d7
First commit, working with displaying messages; no touch support as of yet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EmbeddedSam 0:38cf064697d7 1 /* mbed GraphicsDisplay Display Library Base Class
EmbeddedSam 0:38cf064697d7 2 * Copyright (c) 2007-2009 sford
EmbeddedSam 0:38cf064697d7 3 * Released under the MIT License: http://mbed.org/license/mit
EmbeddedSam 0:38cf064697d7 4 */
EmbeddedSam 0:38cf064697d7 5
EmbeddedSam 0:38cf064697d7 6 #include "GraphicsDisplay.h"
EmbeddedSam 0:38cf064697d7 7
EmbeddedSam 0:38cf064697d7 8 const unsigned char FONT8x8[97][8] = {
EmbeddedSam 0:38cf064697d7 9 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char
EmbeddedSam 0:38cf064697d7 10 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20
EmbeddedSam 0:38cf064697d7 11 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // !
EmbeddedSam 0:38cf064697d7 12 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // "
EmbeddedSam 0:38cf064697d7 13 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // #
EmbeddedSam 0:38cf064697d7 14 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $
EmbeddedSam 0:38cf064697d7 15 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // %
EmbeddedSam 0:38cf064697d7 16 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // &
EmbeddedSam 0:38cf064697d7 17 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // '
EmbeddedSam 0:38cf064697d7 18 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // (
EmbeddedSam 0:38cf064697d7 19 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // )
EmbeddedSam 0:38cf064697d7 20 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // *
EmbeddedSam 0:38cf064697d7 21 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // +
EmbeddedSam 0:38cf064697d7 22 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // ,
EmbeddedSam 0:38cf064697d7 23 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // -
EmbeddedSam 0:38cf064697d7 24 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // .
EmbeddedSam 0:38cf064697d7 25 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash)
EmbeddedSam 0:38cf064697d7 26 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30
EmbeddedSam 0:38cf064697d7 27 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1
EmbeddedSam 0:38cf064697d7 28 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2
EmbeddedSam 0:38cf064697d7 29 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3
EmbeddedSam 0:38cf064697d7 30 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4
EmbeddedSam 0:38cf064697d7 31 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5
EmbeddedSam 0:38cf064697d7 32 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6
EmbeddedSam 0:38cf064697d7 33 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7
EmbeddedSam 0:38cf064697d7 34 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8
EmbeddedSam 0:38cf064697d7 35 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9
EmbeddedSam 0:38cf064697d7 36 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // :
EmbeddedSam 0:38cf064697d7 37 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ;
EmbeddedSam 0:38cf064697d7 38 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // <
EmbeddedSam 0:38cf064697d7 39 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // =
EmbeddedSam 0:38cf064697d7 40 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // >
EmbeddedSam 0:38cf064697d7 41 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ?
EmbeddedSam 0:38cf064697d7 42 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40
EmbeddedSam 0:38cf064697d7 43 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A
EmbeddedSam 0:38cf064697d7 44 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B
EmbeddedSam 0:38cf064697d7 45 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C
EmbeddedSam 0:38cf064697d7 46 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D
EmbeddedSam 0:38cf064697d7 47 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E
EmbeddedSam 0:38cf064697d7 48 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F
EmbeddedSam 0:38cf064697d7 49 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G
EmbeddedSam 0:38cf064697d7 50 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H
EmbeddedSam 0:38cf064697d7 51 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I
EmbeddedSam 0:38cf064697d7 52 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J
EmbeddedSam 0:38cf064697d7 53 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K
EmbeddedSam 0:38cf064697d7 54 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L
EmbeddedSam 0:38cf064697d7 55 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M
EmbeddedSam 0:38cf064697d7 56 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N
EmbeddedSam 0:38cf064697d7 57 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O
EmbeddedSam 0:38cf064697d7 58 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50
EmbeddedSam 0:38cf064697d7 59 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q
EmbeddedSam 0:38cf064697d7 60 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R
EmbeddedSam 0:38cf064697d7 61 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S
EmbeddedSam 0:38cf064697d7 62 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T
EmbeddedSam 0:38cf064697d7 63 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U
EmbeddedSam 0:38cf064697d7 64 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V
EmbeddedSam 0:38cf064697d7 65 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W
EmbeddedSam 0:38cf064697d7 66 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X
EmbeddedSam 0:38cf064697d7 67 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y
EmbeddedSam 0:38cf064697d7 68 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z
EmbeddedSam 0:38cf064697d7 69 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [
EmbeddedSam 0:38cf064697d7 70 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash)
EmbeddedSam 0:38cf064697d7 71 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ]
EmbeddedSam 0:38cf064697d7 72 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^
EmbeddedSam 0:38cf064697d7 73 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _
EmbeddedSam 0:38cf064697d7 74 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60
EmbeddedSam 0:38cf064697d7 75 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a
EmbeddedSam 0:38cf064697d7 76 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b
EmbeddedSam 0:38cf064697d7 77 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c
EmbeddedSam 0:38cf064697d7 78 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d
EmbeddedSam 0:38cf064697d7 79 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e
EmbeddedSam 0:38cf064697d7 80 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f
EmbeddedSam 0:38cf064697d7 81 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g
EmbeddedSam 0:38cf064697d7 82 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h
EmbeddedSam 0:38cf064697d7 83 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i
EmbeddedSam 0:38cf064697d7 84 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j
EmbeddedSam 0:38cf064697d7 85 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k
EmbeddedSam 0:38cf064697d7 86 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l
EmbeddedSam 0:38cf064697d7 87 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m
EmbeddedSam 0:38cf064697d7 88 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n
EmbeddedSam 0:38cf064697d7 89 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o
EmbeddedSam 0:38cf064697d7 90 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p
EmbeddedSam 0:38cf064697d7 91 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q
EmbeddedSam 0:38cf064697d7 92 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r
EmbeddedSam 0:38cf064697d7 93 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s
EmbeddedSam 0:38cf064697d7 94 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t
EmbeddedSam 0:38cf064697d7 95 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u
EmbeddedSam 0:38cf064697d7 96 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v
EmbeddedSam 0:38cf064697d7 97 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w
EmbeddedSam 0:38cf064697d7 98 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x
EmbeddedSam 0:38cf064697d7 99 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y
EmbeddedSam 0:38cf064697d7 100 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z
EmbeddedSam 0:38cf064697d7 101 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // {
EmbeddedSam 0:38cf064697d7 102 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // |
EmbeddedSam 0:38cf064697d7 103 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // }
EmbeddedSam 0:38cf064697d7 104 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~
EmbeddedSam 0:38cf064697d7 105 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL
EmbeddedSam 0:38cf064697d7 106
EmbeddedSam 0:38cf064697d7 107 GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) {
EmbeddedSam 0:38cf064697d7 108 foreground(0xFFFF);
EmbeddedSam 0:38cf064697d7 109 background(0x0000);
EmbeddedSam 0:38cf064697d7 110 }
EmbeddedSam 0:38cf064697d7 111
EmbeddedSam 0:38cf064697d7 112 void GraphicsDisplay::character(int column, int row, int value) {
EmbeddedSam 0:38cf064697d7 113 blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
EmbeddedSam 0:38cf064697d7 114 }
EmbeddedSam 0:38cf064697d7 115
EmbeddedSam 0:38cf064697d7 116 void GraphicsDisplay::window(unsigned int x,unsigned int y,unsigned int w,unsigned int h) {
EmbeddedSam 0:38cf064697d7 117 // current pixel location
EmbeddedSam 0:38cf064697d7 118 _x = x;
EmbeddedSam 0:38cf064697d7 119 _y = y;
EmbeddedSam 0:38cf064697d7 120 // window settings
EmbeddedSam 0:38cf064697d7 121 _x1 = x;
EmbeddedSam 0:38cf064697d7 122 _x2 = x + w - 1;
EmbeddedSam 0:38cf064697d7 123 _y1 = y;
EmbeddedSam 0:38cf064697d7 124 _y2 = y + h - 1;
EmbeddedSam 0:38cf064697d7 125 }
EmbeddedSam 0:38cf064697d7 126
EmbeddedSam 0:38cf064697d7 127 void GraphicsDisplay::putp(int colour) {
EmbeddedSam 0:38cf064697d7 128 // put pixel at current pixel location
EmbeddedSam 0:38cf064697d7 129 pixel(_x, _y, colour);
EmbeddedSam 0:38cf064697d7 130 // update pixel location based on window settings
EmbeddedSam 0:38cf064697d7 131 _x++;
EmbeddedSam 0:38cf064697d7 132 if(_x > _x2) {
EmbeddedSam 0:38cf064697d7 133 _x = _x1;
EmbeddedSam 0:38cf064697d7 134 _y++;
EmbeddedSam 0:38cf064697d7 135 if(_y > _y2) {
EmbeddedSam 0:38cf064697d7 136 _y = _y1;
EmbeddedSam 0:38cf064697d7 137 }
EmbeddedSam 0:38cf064697d7 138 }
EmbeddedSam 0:38cf064697d7 139 }
EmbeddedSam 0:38cf064697d7 140
EmbeddedSam 0:38cf064697d7 141 void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) {
EmbeddedSam 0:38cf064697d7 142 window(x, y, w, h);
EmbeddedSam 0:38cf064697d7 143 for(int i=0; i<w*h; i++) {
EmbeddedSam 0:38cf064697d7 144 putp(colour);
EmbeddedSam 0:38cf064697d7 145 }
EmbeddedSam 0:38cf064697d7 146 }
EmbeddedSam 0:38cf064697d7 147
EmbeddedSam 0:38cf064697d7 148 void GraphicsDisplay::cls() {
EmbeddedSam 0:38cf064697d7 149 fill(0, 0, width(), height(), _background);
EmbeddedSam 0:38cf064697d7 150 }
EmbeddedSam 0:38cf064697d7 151
EmbeddedSam 0:38cf064697d7 152 void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) {
EmbeddedSam 0:38cf064697d7 153 window(x, y, w, h);
EmbeddedSam 0:38cf064697d7 154 for(int i=0; i<w*h; i++) {
EmbeddedSam 0:38cf064697d7 155 putp(colour[i]);
EmbeddedSam 0:38cf064697d7 156 }
EmbeddedSam 0:38cf064697d7 157 }
EmbeddedSam 0:38cf064697d7 158
EmbeddedSam 0:38cf064697d7 159 void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) {
EmbeddedSam 0:38cf064697d7 160 window(x, y, w, h);
EmbeddedSam 0:38cf064697d7 161 for(int i = 0; i < w*h; i++) {
EmbeddedSam 0:38cf064697d7 162 char byte = colour[i >> 3];
EmbeddedSam 0:38cf064697d7 163 int offset = i & 0x7;
EmbeddedSam 0:38cf064697d7 164 int c = ((byte << offset) & 0x80) ? _foreground : _background;
EmbeddedSam 0:38cf064697d7 165 putp(c);
EmbeddedSam 0:38cf064697d7 166 }
EmbeddedSam 0:38cf064697d7 167 }
EmbeddedSam 0:38cf064697d7 168
EmbeddedSam 0:38cf064697d7 169 int GraphicsDisplay::columns() {
EmbeddedSam 0:38cf064697d7 170 return width() / 8;
EmbeddedSam 0:38cf064697d7 171 }
EmbeddedSam 0:38cf064697d7 172
EmbeddedSam 0:38cf064697d7 173 int GraphicsDisplay::rows() {
EmbeddedSam 0:38cf064697d7 174 return height() / 8;
EmbeddedSam 0:38cf064697d7 175 }
EmbeddedSam 0:38cf064697d7 176