Port to C027 (using AppShield and Ethernet)

Dependencies:   C12832 EthernetInterface LM75B MMA7660 MQTT mbed-rtos mbed

Fork of IBMIoTClientEthernetExample by IBM Watson IoT

Committer:
samdanbury
Date:
Wed Aug 20 12:45:14 2014 +0000
Revision:
6:37b6d0d56190
Code completely changed to improve the structure, flow and memory usage of the application

Who changed what in which revision?

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