checking temperature and display it on phant server.

Dependencies:   NetServices-Traffic mbed

Fork of Tweeting_Periodic_Room_Temperature by Priyanka Pashte

Committer:
rrajan8
Date:
Wed Mar 06 19:15:22 2013 +0000
Revision:
0:88e082c58797
This project utilizes mbed's networking features to display live traffic updates on the Nokia LCD using the MapQuest API's Traffic Web Service.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rrajan8 0:88e082c58797 1 /* mbed Nokia LCD Library
rrajan8 0:88e082c58797 2 * Copyright (c) 2007-2010, sford
rrajan8 0:88e082c58797 3 */
rrajan8 0:88e082c58797 4
rrajan8 0:88e082c58797 5 #include "NokiaLCD.h"
rrajan8 0:88e082c58797 6
rrajan8 0:88e082c58797 7 #include "mbed.h"
rrajan8 0:88e082c58797 8
rrajan8 0:88e082c58797 9 #define NOKIALCD_ROWS 16
rrajan8 0:88e082c58797 10 #define NOKIALCD_COLS 16
rrajan8 0:88e082c58797 11 #define NOKIALCD_WIDTH 130
rrajan8 0:88e082c58797 12 #define NOKIALCD_HEIGHT 132
rrajan8 0:88e082c58797 13 #define NOKIALCD_FREQUENCY 5000000
rrajan8 0:88e082c58797 14
rrajan8 0:88e082c58797 15 NokiaLCD::NokiaLCD(PinName mosi, PinName sclk, PinName cs, PinName rst, LCDType type)
rrajan8 0:88e082c58797 16 : _spi(mosi, NC, sclk)
rrajan8 0:88e082c58797 17 , _rst(rst)
rrajan8 0:88e082c58797 18 , _cs(cs) {
rrajan8 0:88e082c58797 19
rrajan8 0:88e082c58797 20 _type = type;
rrajan8 0:88e082c58797 21
rrajan8 0:88e082c58797 22 _row = 0;
rrajan8 0:88e082c58797 23 _column = 0;
rrajan8 0:88e082c58797 24 _foreground = 0x00FFFFFF;
rrajan8 0:88e082c58797 25 _background = 0x00000000;
rrajan8 0:88e082c58797 26
rrajan8 0:88e082c58797 27 reset();
rrajan8 0:88e082c58797 28 }
rrajan8 0:88e082c58797 29
rrajan8 0:88e082c58797 30 void NokiaLCD::reset() {
rrajan8 0:88e082c58797 31
rrajan8 0:88e082c58797 32 // setup the SPI interface and bring display out of reset
rrajan8 0:88e082c58797 33 _cs = 1;
rrajan8 0:88e082c58797 34 _rst = 0;
rrajan8 0:88e082c58797 35 _spi.format(9);
rrajan8 0:88e082c58797 36 _spi.frequency(NOKIALCD_FREQUENCY);
rrajan8 0:88e082c58797 37 wait_ms(1);
rrajan8 0:88e082c58797 38 _rst = 1;
rrajan8 0:88e082c58797 39 wait_ms(1);
rrajan8 0:88e082c58797 40
rrajan8 0:88e082c58797 41 _cs = 0;
rrajan8 0:88e082c58797 42
rrajan8 0:88e082c58797 43 switch (_type) {
rrajan8 0:88e082c58797 44 case LCD6100:
rrajan8 0:88e082c58797 45 command(0xCA); // display control
rrajan8 0:88e082c58797 46 data(0);
rrajan8 0:88e082c58797 47 data(32);
rrajan8 0:88e082c58797 48 data(0);
rrajan8 0:88e082c58797 49 command(0xBB);
rrajan8 0:88e082c58797 50 data(1);
rrajan8 0:88e082c58797 51 command(0xD1); // oscillator on
rrajan8 0:88e082c58797 52 command(0x94); // sleep out
rrajan8 0:88e082c58797 53 command(0x20); // power control
rrajan8 0:88e082c58797 54 data(0x0F);
rrajan8 0:88e082c58797 55 command(0xA7); // invert display
rrajan8 0:88e082c58797 56 command(0x81); // Voltage control
rrajan8 0:88e082c58797 57 data(39); // contrast setting: 0..63
rrajan8 0:88e082c58797 58 data(3); // resistance ratio
rrajan8 0:88e082c58797 59 wait_ms(1);
rrajan8 0:88e082c58797 60 command(0xBC);
rrajan8 0:88e082c58797 61 data(0);
rrajan8 0:88e082c58797 62 data(1);
rrajan8 0:88e082c58797 63 data(4);
rrajan8 0:88e082c58797 64 command(0xAF); // turn on the display
rrajan8 0:88e082c58797 65 break;
rrajan8 0:88e082c58797 66
rrajan8 0:88e082c58797 67 case LCD6610:
rrajan8 0:88e082c58797 68 command(0xCA); // display control
rrajan8 0:88e082c58797 69 data(0);
rrajan8 0:88e082c58797 70 data(32);
rrajan8 0:88e082c58797 71 data(0);
rrajan8 0:88e082c58797 72 command(0xBB);
rrajan8 0:88e082c58797 73 data(1);
rrajan8 0:88e082c58797 74 command(0xD1); // oscillator on
rrajan8 0:88e082c58797 75 command(0x94); // sleep out
rrajan8 0:88e082c58797 76 command(0x20); // power control
rrajan8 0:88e082c58797 77 data(0x0F);
rrajan8 0:88e082c58797 78 command(0xA7); // invert display
rrajan8 0:88e082c58797 79 command(0x81); // Voltage control
rrajan8 0:88e082c58797 80 data(39); // contrast setting: 0..63
rrajan8 0:88e082c58797 81 data(3); // resistance ratio
rrajan8 0:88e082c58797 82 wait_ms(1);
rrajan8 0:88e082c58797 83 command(0xBC);
rrajan8 0:88e082c58797 84 data(0);
rrajan8 0:88e082c58797 85 data(0);
rrajan8 0:88e082c58797 86 data(2);
rrajan8 0:88e082c58797 87 command(0xAF); // turn on the display
rrajan8 0:88e082c58797 88 break;
rrajan8 0:88e082c58797 89
rrajan8 0:88e082c58797 90 case PCF8833:
rrajan8 0:88e082c58797 91 command(0x11); // sleep out
rrajan8 0:88e082c58797 92 command(0x3A); // column mode
rrajan8 0:88e082c58797 93 data(0x05);
rrajan8 0:88e082c58797 94 command(0x36); // madctl
rrajan8 0:88e082c58797 95 data(0x60); // vertical RAM, flip x
rrajan8 0:88e082c58797 96 command(0x25); // setcon
rrajan8 0:88e082c58797 97 data(0x30);// contrast 0x30
rrajan8 0:88e082c58797 98 wait_ms(2);
rrajan8 0:88e082c58797 99 command(0x29);//DISPON
rrajan8 0:88e082c58797 100 command(0x03);//BSTRON
rrajan8 0:88e082c58797 101 break;
rrajan8 0:88e082c58797 102 }
rrajan8 0:88e082c58797 103
rrajan8 0:88e082c58797 104 _cs = 1;
rrajan8 0:88e082c58797 105
rrajan8 0:88e082c58797 106 cls();
rrajan8 0:88e082c58797 107 }
rrajan8 0:88e082c58797 108
rrajan8 0:88e082c58797 109 void NokiaLCD::command(int value) {
rrajan8 0:88e082c58797 110 _spi.write(value & 0xFF);
rrajan8 0:88e082c58797 111 }
rrajan8 0:88e082c58797 112
rrajan8 0:88e082c58797 113 void NokiaLCD::data(int value) {
rrajan8 0:88e082c58797 114 _spi.write(value | 0x100);
rrajan8 0:88e082c58797 115 }
rrajan8 0:88e082c58797 116
rrajan8 0:88e082c58797 117 void NokiaLCD::_window(int x, int y, int width, int height) {
rrajan8 0:88e082c58797 118 int x1 = x + 0;
rrajan8 0:88e082c58797 119 int y1 = y + 0;
rrajan8 0:88e082c58797 120 int x2 = x1 + width - 1;
rrajan8 0:88e082c58797 121 int y2 = y1 + height - 1;
rrajan8 0:88e082c58797 122
rrajan8 0:88e082c58797 123 switch (_type) {
rrajan8 0:88e082c58797 124 case LCD6100:
rrajan8 0:88e082c58797 125 case LCD6610:
rrajan8 0:88e082c58797 126 command(0x15); // column
rrajan8 0:88e082c58797 127 data(x1);
rrajan8 0:88e082c58797 128 data(x2);
rrajan8 0:88e082c58797 129 command(0x75); // row
rrajan8 0:88e082c58797 130 data(y1);
rrajan8 0:88e082c58797 131 data(y2);
rrajan8 0:88e082c58797 132 command(0x5C); // start write to ram
rrajan8 0:88e082c58797 133 break;
rrajan8 0:88e082c58797 134 case PCF8833:
rrajan8 0:88e082c58797 135 command(0x2A); // column
rrajan8 0:88e082c58797 136 data(x1);
rrajan8 0:88e082c58797 137 data(x2);
rrajan8 0:88e082c58797 138 command(0x2B); // row
rrajan8 0:88e082c58797 139 data(y1);
rrajan8 0:88e082c58797 140 data(y2);
rrajan8 0:88e082c58797 141 command(0x2C); // start write to ram
rrajan8 0:88e082c58797 142 break;
rrajan8 0:88e082c58797 143 }
rrajan8 0:88e082c58797 144 }
rrajan8 0:88e082c58797 145
rrajan8 0:88e082c58797 146 void NokiaLCD::_putp(int colour) {
rrajan8 0:88e082c58797 147 int gr = ((colour >> 20) & 0x0F)
rrajan8 0:88e082c58797 148 | ((colour >> 8 ) & 0xF0);
rrajan8 0:88e082c58797 149 int nb = ((colour >> 4 ) & 0x0F);
rrajan8 0:88e082c58797 150 data(nb);
rrajan8 0:88e082c58797 151 data(gr);
rrajan8 0:88e082c58797 152 }
rrajan8 0:88e082c58797 153
rrajan8 0:88e082c58797 154 const unsigned char FONT8x8[97][8] = {
rrajan8 0:88e082c58797 155 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char
rrajan8 0:88e082c58797 156 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20
rrajan8 0:88e082c58797 157 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // !
rrajan8 0:88e082c58797 158 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // "
rrajan8 0:88e082c58797 159 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // #
rrajan8 0:88e082c58797 160 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $
rrajan8 0:88e082c58797 161 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // %
rrajan8 0:88e082c58797 162 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // &
rrajan8 0:88e082c58797 163 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // '
rrajan8 0:88e082c58797 164 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // (
rrajan8 0:88e082c58797 165 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // )
rrajan8 0:88e082c58797 166 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // *
rrajan8 0:88e082c58797 167 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // +
rrajan8 0:88e082c58797 168 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // ,
rrajan8 0:88e082c58797 169 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // -
rrajan8 0:88e082c58797 170 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // .
rrajan8 0:88e082c58797 171 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash)
rrajan8 0:88e082c58797 172 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30
rrajan8 0:88e082c58797 173 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1
rrajan8 0:88e082c58797 174 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2
rrajan8 0:88e082c58797 175 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3
rrajan8 0:88e082c58797 176 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4
rrajan8 0:88e082c58797 177 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5
rrajan8 0:88e082c58797 178 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6
rrajan8 0:88e082c58797 179 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7
rrajan8 0:88e082c58797 180 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8
rrajan8 0:88e082c58797 181 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9
rrajan8 0:88e082c58797 182 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // :
rrajan8 0:88e082c58797 183 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ;
rrajan8 0:88e082c58797 184 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // <
rrajan8 0:88e082c58797 185 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // =
rrajan8 0:88e082c58797 186 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // >
rrajan8 0:88e082c58797 187 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ?
rrajan8 0:88e082c58797 188 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40
rrajan8 0:88e082c58797 189 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A
rrajan8 0:88e082c58797 190 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B
rrajan8 0:88e082c58797 191 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C
rrajan8 0:88e082c58797 192 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D
rrajan8 0:88e082c58797 193 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E
rrajan8 0:88e082c58797 194 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F
rrajan8 0:88e082c58797 195 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G
rrajan8 0:88e082c58797 196 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H
rrajan8 0:88e082c58797 197 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I
rrajan8 0:88e082c58797 198 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J
rrajan8 0:88e082c58797 199 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K
rrajan8 0:88e082c58797 200 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L
rrajan8 0:88e082c58797 201 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M
rrajan8 0:88e082c58797 202 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N
rrajan8 0:88e082c58797 203 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O
rrajan8 0:88e082c58797 204 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50
rrajan8 0:88e082c58797 205 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q
rrajan8 0:88e082c58797 206 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R
rrajan8 0:88e082c58797 207 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S
rrajan8 0:88e082c58797 208 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T
rrajan8 0:88e082c58797 209 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U
rrajan8 0:88e082c58797 210 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V
rrajan8 0:88e082c58797 211 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W
rrajan8 0:88e082c58797 212 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X
rrajan8 0:88e082c58797 213 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y
rrajan8 0:88e082c58797 214 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z
rrajan8 0:88e082c58797 215 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [
rrajan8 0:88e082c58797 216 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash)
rrajan8 0:88e082c58797 217 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ]
rrajan8 0:88e082c58797 218 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^
rrajan8 0:88e082c58797 219 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _
rrajan8 0:88e082c58797 220 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60
rrajan8 0:88e082c58797 221 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a
rrajan8 0:88e082c58797 222 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b
rrajan8 0:88e082c58797 223 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c
rrajan8 0:88e082c58797 224 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d
rrajan8 0:88e082c58797 225 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e
rrajan8 0:88e082c58797 226 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f
rrajan8 0:88e082c58797 227 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g
rrajan8 0:88e082c58797 228 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h
rrajan8 0:88e082c58797 229 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i
rrajan8 0:88e082c58797 230 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j
rrajan8 0:88e082c58797 231 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k
rrajan8 0:88e082c58797 232 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l
rrajan8 0:88e082c58797 233 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m
rrajan8 0:88e082c58797 234 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n
rrajan8 0:88e082c58797 235 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o
rrajan8 0:88e082c58797 236 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p
rrajan8 0:88e082c58797 237 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q
rrajan8 0:88e082c58797 238 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r
rrajan8 0:88e082c58797 239 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s
rrajan8 0:88e082c58797 240 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t
rrajan8 0:88e082c58797 241 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u
rrajan8 0:88e082c58797 242 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v
rrajan8 0:88e082c58797 243 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w
rrajan8 0:88e082c58797 244 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x
rrajan8 0:88e082c58797 245 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y
rrajan8 0:88e082c58797 246 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z
rrajan8 0:88e082c58797 247 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // {
rrajan8 0:88e082c58797 248 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // |
rrajan8 0:88e082c58797 249 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // }
rrajan8 0:88e082c58797 250 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~
rrajan8 0:88e082c58797 251 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00
rrajan8 0:88e082c58797 252 }; // DEL
rrajan8 0:88e082c58797 253
rrajan8 0:88e082c58797 254 void NokiaLCD::locate(int column, int row) {
rrajan8 0:88e082c58797 255 _column = column;
rrajan8 0:88e082c58797 256 _row = row;
rrajan8 0:88e082c58797 257 }
rrajan8 0:88e082c58797 258
rrajan8 0:88e082c58797 259 void NokiaLCD::newline() {
rrajan8 0:88e082c58797 260 _column = 0;
rrajan8 0:88e082c58797 261 _row++;
rrajan8 0:88e082c58797 262 if (_row >= _rows) {
rrajan8 0:88e082c58797 263 _row = 0;
rrajan8 0:88e082c58797 264 }
rrajan8 0:88e082c58797 265 }
rrajan8 0:88e082c58797 266
rrajan8 0:88e082c58797 267 int NokiaLCD::_putc(int value) {
rrajan8 0:88e082c58797 268 int x = _column * 8; // FIXME: Char sizes
rrajan8 0:88e082c58797 269 int y = _row * 8;
rrajan8 0:88e082c58797 270 bitblit(x + 1, y + 1, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
rrajan8 0:88e082c58797 271
rrajan8 0:88e082c58797 272 _column++;
rrajan8 0:88e082c58797 273
rrajan8 0:88e082c58797 274 if (_column >= NOKIALCD_COLS) {
rrajan8 0:88e082c58797 275 _row++;
rrajan8 0:88e082c58797 276 _column = 0;
rrajan8 0:88e082c58797 277 }
rrajan8 0:88e082c58797 278
rrajan8 0:88e082c58797 279 if (_row >= NOKIALCD_ROWS) {
rrajan8 0:88e082c58797 280 _row = 0;
rrajan8 0:88e082c58797 281 }
rrajan8 0:88e082c58797 282
rrajan8 0:88e082c58797 283 return value;
rrajan8 0:88e082c58797 284 }
rrajan8 0:88e082c58797 285
rrajan8 0:88e082c58797 286 void NokiaLCD::cls() {
rrajan8 0:88e082c58797 287 fill(0, 0, NOKIALCD_WIDTH, NOKIALCD_HEIGHT, _background);
rrajan8 0:88e082c58797 288 _row = 0;
rrajan8 0:88e082c58797 289 _column = 0;
rrajan8 0:88e082c58797 290 }
rrajan8 0:88e082c58797 291
rrajan8 0:88e082c58797 292
rrajan8 0:88e082c58797 293 void NokiaLCD::window(int x, int y, int width, int height) {
rrajan8 0:88e082c58797 294 _cs = 0;
rrajan8 0:88e082c58797 295 _window(x, y, width, height);
rrajan8 0:88e082c58797 296 _cs = 1;
rrajan8 0:88e082c58797 297 }
rrajan8 0:88e082c58797 298
rrajan8 0:88e082c58797 299 void NokiaLCD::putp(int colour) {
rrajan8 0:88e082c58797 300 _cs = 0;
rrajan8 0:88e082c58797 301 _putp(colour);
rrajan8 0:88e082c58797 302 _cs = 1;
rrajan8 0:88e082c58797 303 }
rrajan8 0:88e082c58797 304
rrajan8 0:88e082c58797 305 void NokiaLCD::pixel(int x, int y, int colour) {
rrajan8 0:88e082c58797 306 _cs = 0;
rrajan8 0:88e082c58797 307 _window(x, y, 1, 1);
rrajan8 0:88e082c58797 308 switch (_type) {
rrajan8 0:88e082c58797 309 case LCD6100:
rrajan8 0:88e082c58797 310 case PCF8833:
rrajan8 0:88e082c58797 311
rrajan8 0:88e082c58797 312 _putp(colour);
rrajan8 0:88e082c58797 313
rrajan8 0:88e082c58797 314 break;
rrajan8 0:88e082c58797 315 case LCD6610:
rrajan8 0:88e082c58797 316
rrajan8 0:88e082c58797 317 int r4 = (colour >> (16 + 4)) & 0xF;
rrajan8 0:88e082c58797 318 int g4 = (colour >> (8 + 4)) & 0xF;
rrajan8 0:88e082c58797 319 int b4 = (colour >> (0 + 4)) & 0xF;
rrajan8 0:88e082c58797 320 int d1 = (r4 << 4) | g4;
rrajan8 0:88e082c58797 321 int d2 = (b4 << 4) | r4;
rrajan8 0:88e082c58797 322 int d3 = (g4 << 4) | b4;
rrajan8 0:88e082c58797 323 data(d1);
rrajan8 0:88e082c58797 324 data(d2);
rrajan8 0:88e082c58797 325 data(d3);
rrajan8 0:88e082c58797 326
rrajan8 0:88e082c58797 327 break;
rrajan8 0:88e082c58797 328 }
rrajan8 0:88e082c58797 329 _cs = 1;
rrajan8 0:88e082c58797 330
rrajan8 0:88e082c58797 331 }
rrajan8 0:88e082c58797 332
rrajan8 0:88e082c58797 333 void NokiaLCD::fill(int x, int y, int width, int height, int colour) {
rrajan8 0:88e082c58797 334 _cs = 0;
rrajan8 0:88e082c58797 335 _window(x, y, width, height);
rrajan8 0:88e082c58797 336 switch (_type) {
rrajan8 0:88e082c58797 337 case LCD6100:
rrajan8 0:88e082c58797 338 case PCF8833:
rrajan8 0:88e082c58797 339 for (int i=0; i<width*height; i++) {
rrajan8 0:88e082c58797 340 _putp(colour);
rrajan8 0:88e082c58797 341 }
rrajan8 0:88e082c58797 342 break;
rrajan8 0:88e082c58797 343 case LCD6610:
rrajan8 0:88e082c58797 344 for (int i=0; i<width*height/2; i++) {
rrajan8 0:88e082c58797 345 int r4 = (colour >> (16 + 4)) & 0xF;
rrajan8 0:88e082c58797 346 int g4 = (colour >> (8 + 4)) & 0xF;
rrajan8 0:88e082c58797 347 int b4 = (colour >> (0 + 4)) & 0xF;
rrajan8 0:88e082c58797 348 int d1 = (r4 << 4) | g4;
rrajan8 0:88e082c58797 349 int d2 = (b4 << 4) | r4;
rrajan8 0:88e082c58797 350 int d3 = (g4 << 4) | b4;
rrajan8 0:88e082c58797 351 data(d1);
rrajan8 0:88e082c58797 352 data(d2);
rrajan8 0:88e082c58797 353 data(d3);
rrajan8 0:88e082c58797 354 }
rrajan8 0:88e082c58797 355 break;
rrajan8 0:88e082c58797 356 }
rrajan8 0:88e082c58797 357 _window(0, 0, NOKIALCD_WIDTH, NOKIALCD_HEIGHT);
rrajan8 0:88e082c58797 358 _cs = 1;
rrajan8 0:88e082c58797 359 }
rrajan8 0:88e082c58797 360
rrajan8 0:88e082c58797 361 void NokiaLCD::blit(int x, int y, int width, int height, const int* colour) {
rrajan8 0:88e082c58797 362 _cs = 0;
rrajan8 0:88e082c58797 363 _window(x, y, width, height);
rrajan8 0:88e082c58797 364
rrajan8 0:88e082c58797 365 switch (_type) {
rrajan8 0:88e082c58797 366 case LCD6100:
rrajan8 0:88e082c58797 367 case PCF8833:
rrajan8 0:88e082c58797 368 for (int i=0; i<width*height; i++) {
rrajan8 0:88e082c58797 369 _putp(colour[i]);
rrajan8 0:88e082c58797 370 }
rrajan8 0:88e082c58797 371 break;
rrajan8 0:88e082c58797 372 case LCD6610:
rrajan8 0:88e082c58797 373 for (int i=0; i<width*height/2; i++) {
rrajan8 0:88e082c58797 374 int r41 = (colour[i*2] >> (16 + 4)) & 0xF;
rrajan8 0:88e082c58797 375 int g41 = (colour[i*2] >> (8 + 4)) & 0xF;
rrajan8 0:88e082c58797 376 int b41 = (colour[i*2] >> (0 + 4)) & 0xF;
rrajan8 0:88e082c58797 377
rrajan8 0:88e082c58797 378 int r42 = (colour[i*2+1] >> (16 + 4)) & 0xF;
rrajan8 0:88e082c58797 379 int g42 = (colour[i*2+1] >> (8 + 4)) & 0xF;
rrajan8 0:88e082c58797 380 int b42 = (colour[i*2+1] >> (0 + 4)) & 0xF;
rrajan8 0:88e082c58797 381 int d1 = (r41 << 4) | g41;
rrajan8 0:88e082c58797 382 int d2 = (b41 << 4) | r42;
rrajan8 0:88e082c58797 383 int d3 = (g42 << 4) | b42;
rrajan8 0:88e082c58797 384 data(d1);
rrajan8 0:88e082c58797 385 data(d2);
rrajan8 0:88e082c58797 386 data(d3);
rrajan8 0:88e082c58797 387 }
rrajan8 0:88e082c58797 388 break;
rrajan8 0:88e082c58797 389 }
rrajan8 0:88e082c58797 390 _window(0, 0, NOKIALCD_WIDTH, NOKIALCD_HEIGHT);
rrajan8 0:88e082c58797 391 _cs = 1;
rrajan8 0:88e082c58797 392 }
rrajan8 0:88e082c58797 393
rrajan8 0:88e082c58797 394 void NokiaLCD::bitblit(int x, int y, int width, int height, const char* bitstream) {
rrajan8 0:88e082c58797 395 _cs = 0;
rrajan8 0:88e082c58797 396 _window(x, y, width, height);
rrajan8 0:88e082c58797 397
rrajan8 0:88e082c58797 398 switch (_type) {
rrajan8 0:88e082c58797 399 case LCD6100:
rrajan8 0:88e082c58797 400 case PCF8833:
rrajan8 0:88e082c58797 401 for (int i=0; i<height*width; i++) {
rrajan8 0:88e082c58797 402 int byte = i / 8;
rrajan8 0:88e082c58797 403 int bit = i % 8;
rrajan8 0:88e082c58797 404 int colour = ((bitstream[byte] << bit) & 0x80) ? _foreground : _background;
rrajan8 0:88e082c58797 405 _putp(colour);
rrajan8 0:88e082c58797 406 }
rrajan8 0:88e082c58797 407 break;
rrajan8 0:88e082c58797 408 case LCD6610:
rrajan8 0:88e082c58797 409 for (int i=0; i<height*width/2; i++) {
rrajan8 0:88e082c58797 410 int byte1 = (i*2) / 8;
rrajan8 0:88e082c58797 411 int bit1 = (i*2) % 8;
rrajan8 0:88e082c58797 412 int colour1 = ((bitstream[byte1] << bit1) & 0x80) ? _foreground : _background;
rrajan8 0:88e082c58797 413 int byte2 = (i*2+1) / 8;
rrajan8 0:88e082c58797 414 int bit2 = (i*2+1) % 8;
rrajan8 0:88e082c58797 415 int colour2 = ((bitstream[byte2] << bit2) & 0x80) ? _foreground : _background;
rrajan8 0:88e082c58797 416
rrajan8 0:88e082c58797 417 int r41 = (colour1 >> (16 + 4)) & 0xF;
rrajan8 0:88e082c58797 418 int g41 = (colour1 >> (8 + 4)) & 0xF;
rrajan8 0:88e082c58797 419 int b41 = (colour1 >> (0 + 4)) & 0xF;
rrajan8 0:88e082c58797 420
rrajan8 0:88e082c58797 421 int r42 = (colour2 >> (16 + 4)) & 0xF;
rrajan8 0:88e082c58797 422 int g42 = (colour2 >> (8 + 4)) & 0xF;
rrajan8 0:88e082c58797 423 int b42 = (colour2 >> (0 + 4)) & 0xF;
rrajan8 0:88e082c58797 424 int d1 = (r41 << 4) | g41;
rrajan8 0:88e082c58797 425 int d2 = (b41 << 4) | r42;
rrajan8 0:88e082c58797 426 int d3 = (g42 << 4) | b42;
rrajan8 0:88e082c58797 427 data(d1);
rrajan8 0:88e082c58797 428 data(d2);
rrajan8 0:88e082c58797 429 data(d3);
rrajan8 0:88e082c58797 430 }
rrajan8 0:88e082c58797 431 break;
rrajan8 0:88e082c58797 432 }
rrajan8 0:88e082c58797 433 _window(0, 0, _width, _height);
rrajan8 0:88e082c58797 434 _cs = 1;
rrajan8 0:88e082c58797 435 }
rrajan8 0:88e082c58797 436
rrajan8 0:88e082c58797 437 void NokiaLCD::foreground(int c) {
rrajan8 0:88e082c58797 438 _foreground = c;
rrajan8 0:88e082c58797 439 }
rrajan8 0:88e082c58797 440
rrajan8 0:88e082c58797 441 void NokiaLCD::background(int c) {
rrajan8 0:88e082c58797 442 _background = c;
rrajan8 0:88e082c58797 443 }
rrajan8 0:88e082c58797 444
rrajan8 0:88e082c58797 445 int NokiaLCD::width() {
rrajan8 0:88e082c58797 446 return NOKIALCD_WIDTH;
rrajan8 0:88e082c58797 447 }
rrajan8 0:88e082c58797 448
rrajan8 0:88e082c58797 449 int NokiaLCD::height() {
rrajan8 0:88e082c58797 450 return NOKIALCD_HEIGHT;
rrajan8 0:88e082c58797 451 }
rrajan8 0:88e082c58797 452
rrajan8 0:88e082c58797 453 int NokiaLCD::columns() {
rrajan8 0:88e082c58797 454 return NOKIALCD_COLS;
rrajan8 0:88e082c58797 455 }
rrajan8 0:88e082c58797 456
rrajan8 0:88e082c58797 457 int NokiaLCD::rows() {
rrajan8 0:88e082c58797 458 return NOKIALCD_ROWS;
rrajan8 0:88e082c58797 459 }