Display text on LCD displays (even on multiple ones). Allow to create windows (frames) on display, and to combine them (split, add, duplicate, scroll). See http://mbed.org/users/hlipka/notebook/lcdwindow/ for more information.
Revision 2:5ac5bab7daaf, committed 2010-11-27
- Comitter:
- hlipka
- Date:
- Sat Nov 27 22:54:13 2010 +0000
- Parent:
- 1:65f72ed914fa
- Child:
- 3:e5d5e2fe4bf6
- Commit message:
- Moved to \"Stream\"-based API (like TextLCD) which allows the usage of printf
Changed in this revision
--- a/dogm_spi.cpp Tue Nov 16 20:49:18 2010 +0000 +++ b/dogm_spi.cpp Sat Nov 27 22:54:13 2010 +0000 @@ -28,8 +28,8 @@ #include "wait_api.h" DogmLCDSPI::DogmLCDSPI -(unsigned int width, unsigned int height, SPI *spi, PinName enable, PinName rs) -:SPILCDBase(width,height,spi,enable,rs) +(unsigned int columns, unsigned int rows, SPI *spi, PinName enable, PinName rs) +:SPILCDBase(columns,rows,spi,enable,rs) { } @@ -47,9 +47,18 @@ } } -void DogmLCDSPI::writeText(const unsigned int line, const unsigned int pos, const char text[]) +void DogmLCDSPI::character(int column, int row, int c) { - int address=(line)*0x40+(pos); + int address=(row)*0x40+(column); + sendCmd((char)address|0x80); + wait_ms(1); + sendData(c); + wait_ms(1); +} + +void DogmLCDSPI::writeText(const unsigned int column, const unsigned int row, const char text[]) +{ + int address=(row)*0x40+(column); sendCmd((char)address|0x80); wait_ms(1);
--- a/dogm_spi.h Tue Nov 16 20:49:18 2010 +0000 +++ b/dogm_spi.h Sat Nov 27 22:54:13 2010 +0000 @@ -38,16 +38,18 @@ { public: /** - * @param width number of chars per line - * @param height number of lines (currently only 1 and 2 work) + * @param columns number of chars per line + * @param rows number of lines (currently only 1 and 2 work) * @param the SPI object used for sending data (set to 1MHz) * @param enable the pin name for the enable line (0=active, connected to /CSB) * @param rs the pin name for the register select line (0=cmd, 1=data) */ - DogmLCDSPI(unsigned int width, unsigned int height, SPI *spi, PinName enable, PinName rs); + DogmLCDSPI(unsigned int columns, unsigned int rows, SPI *spi, PinName enable, PinName rs); virtual void init(); - virtual void writeText(const unsigned int line, const unsigned int pos, const char text[]); + virtual void writeText(const unsigned int column, const unsigned int row, const char text[]); virtual void clear(); + virtual void character(int column, int row, int c); + }; #endif \ No newline at end of file
--- a/font.h Tue Nov 16 20:49:18 2010 +0000 +++ b/font.h Sat Nov 27 22:54:13 2010 +0000 @@ -1,274 +1,274 @@ -/* -This font has been created by rotating the original 'vincent' font. -See below for the original copyright, or go to -http://forum.osdev.org/viewtopic.php?f=2&t=22033 -*/ -/* -Created Sunday, May 23, 2010 by Quinn Evans -Renamed and updated Monday 24, 2010 - -This font (Vincent) is released by me into the public domain. I claim no -copyright, and hereby make this software available to the public for any use, -at any time, free of restrictions, legal or otherwise. -*/ -#ifndef FONT_H -#define FONT_H 1 -unsigned char font_data[128][8] = { -//0x0=0 -{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,}, -//0x1=1 -{0x00,0x7c,0x82,0xaa,0xc2,0xaa,0x82,0x7c,}, -//0x2=2 -{0x00,0x7c,0xfe,0xd6,0xbe,0xd6,0xfe,0x7c,}, -//0x3=3 -{0x00,0x1c,0x3e,0x7c,0xf8,0x7c,0x3e,0x1c,}, -//0x4=4 -{0x00,0x10,0x38,0x7c,0xfe,0x7c,0x38,0x10,}, -//0x5=5 -{0x00,0x10,0x38,0x94,0xfe,0x94,0x38,0x10,}, -//0x6=6 -{0x00,0x10,0x38,0xbc,0xfe,0xbc,0x38,0x10,}, -//0x7=7 -{0x00,0x00,0x38,0x7c,0x7c,0x7c,0x38,0x00,}, -//0x8=8 -{0xff,0xff,0xc7,0x83,0x83,0x83,0xc7,0xff,}, -//0x9=9 -{0x00,0x00,0x38,0x44,0x44,0x44,0x38,0x00,}, -//0xa=10 -{0xff,0xff,0xc7,0xbb,0xbb,0xbb,0xc7,0xff,}, -//0xb=11 -{0x00,0x60,0x90,0x90,0x72,0x0a,0x06,0x1e,}, -//0xc=12 -{0x00,0x00,0x64,0x94,0x9e,0x94,0x64,0x00,}, -//0xd=13 -{0x00,0xc0,0xe0,0x7e,0x02,0x04,0x00,0x00,}, -//0xe=14 -{0x00,0xc0,0xe0,0x7c,0x06,0x62,0x72,0x3e,}, -//0xf=15 -{0x00,0x10,0x54,0x38,0xee,0x38,0x54,0x10,}, -//0x10=16 -{0x00,0xfe,0xfe,0x7c,0x7c,0x38,0x38,0x10,}, -//0x11=17 -{0x00,0x10,0x38,0x38,0x7c,0x7c,0xfe,0xfe,}, -//0x12=18 -{0x00,0x00,0x28,0x44,0xfe,0x44,0x28,0x00,}, -//0x13=19 -{0x00,0xde,0xde,0x00,0x00,0xde,0xde,0x00,}, -//0x14=20 -{0x00,0x0c,0x1e,0x12,0x12,0xfe,0x02,0xfe,}, -//0x15=21 -{0x00,0x48,0x94,0xa4,0x4a,0x52,0x24,0x00,}, -//0x16=22 -{0x00,0xe0,0xe0,0xe0,0xe0,0xe0,0xe0,0xe0,}, -//0x17=23 -{0x00,0x00,0xa8,0xc4,0xfe,0xc4,0xa8,0x00,}, -//0x18=24 -{0x00,0x10,0x18,0xfc,0xfe,0xfc,0x18,0x10,}, -//0x19=25 -{0x00,0x10,0x30,0x7e,0xfe,0x7e,0x30,0x10,}, -//0x1a=26 -{0x00,0x38,0x38,0x38,0xfe,0x7c,0x38,0x10,}, -//0x1b=27 -{0x00,0x10,0x38,0x7c,0xfe,0x38,0x38,0x38,}, -//0x1c=28 -{0x00,0xf8,0xf8,0xf8,0xc0,0xc0,0xc0,0xc0,}, -//0x1d=29 -{0x00,0x10,0x38,0x54,0x10,0x54,0x38,0x10,}, -//0x1e=30 -{0x00,0xc0,0xf0,0xfc,0xfe,0xfc,0xf0,0xc0,}, -//0x1f=31 -{0x00,0x06,0x1e,0x7e,0xfe,0x7e,0x1e,0x06,}, -//0x20=32 -{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,}, -//0x21=33 -{0x00,0x00,0x0c,0xbe,0xbe,0x0c,0x00,0x00,}, -//0x22=34 -{0x00,0x00,0x06,0x0e,0x00,0x0e,0x06,0x00,}, -//0x23=35 -{0x00,0x28,0xfe,0xfe,0x28,0xfe,0xfe,0x28,}, -//0x24=36 -{0x00,0x00,0x48,0x54,0xd6,0x54,0x24,0x00,}, -//0x25=37 -{0x00,0x46,0x66,0x30,0x18,0xcc,0xc4,0x00,}, -//0x26=38 -{0x00,0x64,0xfe,0x8a,0x9a,0xee,0xc4,0xa0,}, -//0x27=39 -{0x00,0x00,0x10,0x1e,0x0e,0x00,0x00,0x00,}, -//0x28=40 -{0x00,0x82,0xc6,0x7c,0x38,0x00,0x00,0x00,}, -//0x29=41 -{0x00,0x00,0x00,0x38,0x7c,0xc6,0x82,0x00,}, -//0x2a=42 -{0x00,0x10,0x54,0x7c,0x38,0x7c,0x54,0x10,}, -//0x2b=43 -{0x00,0x00,0x10,0x10,0x7c,0x10,0x10,0x00,}, -//0x2c=44 -{0x00,0x80,0xf0,0x70,0x00,0x00,0x00,0x00,}, -//0x2d=45 -{0x00,0x00,0x10,0x10,0x10,0x10,0x00,0x00,}, -//0x2e=46 -{0x00,0xc0,0xc0,0x00,0x00,0x00,0x00,0x00,}, -//0x2f=47 -{0x00,0x40,0x60,0x30,0x18,0x0c,0x04,0x00,}, -//0x30=48 -{0x00,0x7c,0xfe,0x92,0x8a,0xfe,0x7c,0x00,}, -//0x31=49 -{0x00,0x80,0x88,0xfe,0xfe,0x80,0x80,0x00,}, -//0x32=50 -{0x00,0xc4,0xe6,0xa2,0x92,0x9e,0x8c,0x00,}, -//0x33=51 -{0x00,0x44,0xc6,0x92,0x92,0xfe,0x6c,0x00,}, -//0x34=52 -{0x00,0x30,0x28,0x24,0xfe,0xfe,0x20,0x00,}, -//0x35=53 -{0x00,0x4e,0xce,0x8a,0x8a,0xfa,0x72,0x00,}, -//0x36=54 -{0x00,0x7c,0xfe,0x92,0x92,0xf6,0x64,0x00,}, -//0x37=55 -{0x00,0x06,0x06,0xe2,0xfa,0x1e,0x06,0x00,}, -//0x38=56 -{0x00,0x6c,0xfe,0x92,0x92,0xfe,0x6c,0x00,}, -//0x39=57 -{0x00,0x4c,0xde,0x92,0x92,0xfe,0x7c,0x00,}, -//0x3a=58 -{0x00,0x00,0x00,0x6c,0x6c,0x00,0x00,0x00,}, -//0x3b=59 -{0x00,0x00,0x80,0xec,0x6c,0x00,0x00,0x00,}, -//0x3c=60 -{0x00,0x00,0x10,0x38,0x6c,0xc6,0x82,0x00,}, -//0x3d=61 -{0x00,0x00,0x28,0x28,0x28,0x28,0x00,0x00,}, -//0x3e=62 -{0x00,0x82,0xc6,0x6c,0x38,0x10,0x00,0x00,}, -//0x3f=63 -{0x00,0x04,0x06,0xb2,0xb2,0x1e,0x0c,0x00,}, -//0x40=64 -{0x00,0x3c,0x42,0x5a,0x5a,0x4c,0x20,0x00,}, -//0x41=65 -{0x00,0xfc,0xfe,0x12,0x12,0xfe,0xfc,0x00,}, -//0x42=66 -{0x00,0xfe,0xfe,0x92,0x92,0xfe,0x6c,0x00,}, -//0x43=67 -{0x00,0x7c,0xfe,0x82,0x82,0xc6,0x44,0x00,}, -//0x44=68 -{0x00,0xfe,0xfe,0x82,0x82,0xfe,0x7c,0x00,}, -//0x45=69 -{0x00,0xfe,0xfe,0x92,0x92,0x92,0x82,0x00,}, -//0x46=70 -{0x00,0xfe,0xfe,0x12,0x12,0x12,0x02,0x00,}, -//0x47=71 -{0x00,0x7c,0xfe,0x82,0xa2,0xe6,0x64,0x00,}, -//0x48=72 -{0x00,0xfe,0xfe,0x10,0x10,0xfe,0xfe,0x00,}, -//0x49=73 -{0x00,0x00,0x82,0xfe,0xfe,0x82,0x00,0x00,}, -//0x4a=74 -{0x00,0x60,0xe0,0x82,0xfe,0x7e,0x02,0x00,}, -//0x4b=75 -{0x00,0xfe,0xfe,0x38,0x6c,0xc6,0x82,0x00,}, -//0x4c=76 -{0x00,0xfe,0xfe,0x80,0x80,0x80,0x80,0x00,}, -//0x4d=77 -{0x00,0xfe,0xfe,0x0c,0x18,0x0c,0xfe,0xfe,}, -//0x4e=78 -{0x00,0xfe,0xfe,0x0c,0x18,0x30,0xfe,0xfe,}, -//0x4f=79 -{0x00,0x7c,0xfe,0x82,0x82,0xfe,0x7c,0x00,}, -//0x50=80 -{0x00,0xfe,0xfe,0x22,0x22,0x3e,0x1c,0x00,}, -//0x51=81 -{0x00,0x3c,0x7e,0x42,0x62,0xfe,0xbc,0x00,}, -//0x52=82 -{0x00,0xfe,0xfe,0x32,0x72,0xde,0x8c,0x00,}, -//0x53=83 -{0x00,0x4c,0xde,0x92,0x92,0xf6,0x64,0x00,}, -//0x54=84 -{0x00,0x06,0x02,0xfe,0xfe,0x02,0x06,0x00,}, -//0x55=85 -{0x00,0x7e,0xfe,0x80,0x80,0xfe,0xfe,0x00,}, -//0x56=86 -{0x00,0x3e,0x7e,0xc0,0xc0,0x7e,0x3e,0x00,}, -//0x57=87 -{0x00,0xfe,0xfe,0x60,0x30,0x60,0xfe,0xfe,}, -//0x58=88 -{0x00,0xc6,0xee,0x38,0x10,0x38,0xee,0xc6,}, -//0x59=89 -{0x00,0x0e,0x1e,0xf0,0xf0,0x1e,0x0e,0x00,}, -//0x5a=90 -{0x00,0xc2,0xe2,0xb2,0x9a,0x8e,0x86,0x00,}, -//0x5b=91 -{0x00,0x00,0x00,0xfe,0xfe,0x82,0x82,0x00,}, -//0x5c=92 -{0x00,0x04,0x0c,0x18,0x30,0x60,0x40,0x00,}, -//0x5d=93 -{0x00,0x82,0x82,0xfe,0xfe,0x00,0x00,0x00,}, -//0x5e=94 -{0x00,0x10,0x08,0x04,0x02,0x04,0x08,0x10,}, -//0x5f=95 -{0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,}, -//0x60=96 -{0x00,0x00,0x00,0x00,0x06,0x0e,0x08,0x00,}, -//0x61=97 -{0x00,0x40,0xe8,0xa8,0xa8,0xf8,0xf0,0x00,}, -//0x62=98 -{0x00,0xfe,0xfe,0x90,0x90,0xf0,0x60,0x00,}, -//0x63=99 -{0x00,0x70,0xf8,0x88,0x88,0xd8,0x50,0x00,}, -//0x64=100 -{0x00,0x60,0xf0,0x90,0x90,0xfe,0xfe,0x00,}, -//0x65=101 -{0x00,0x70,0xf8,0xa8,0xa8,0xb8,0x30,0x00,}, -//0x66=102 -{0x00,0x20,0xfc,0xfe,0x22,0x26,0x04,0x00,}, -//0x67=103 -{0x00,0x18,0xbc,0xa4,0xa4,0xfc,0x7c,0x00,}, -//0x68=104 -{0x00,0xfe,0xfe,0x10,0x10,0xf0,0xe0,0x00,}, -//0x69=105 -{0x00,0x00,0x80,0xf4,0xf4,0x80,0x00,0x00,}, -//0x6a=106 -{0x00,0x60,0xe0,0x80,0xfa,0x7a,0x00,0x00,}, -//0x6b=107 -{0x00,0xfe,0xfe,0x20,0x70,0xd8,0x88,0x00,}, -//0x6c=108 -{0x00,0x00,0x00,0xfe,0xfe,0x00,0x00,0x00,}, -//0x6d=109 -{0x00,0xf8,0xf8,0x30,0xe0,0x30,0xf8,0xf8,}, -//0x6e=110 -{0x00,0xf8,0xf8,0x18,0x18,0xf8,0xf0,0x00,}, -//0x6f=111 -{0x00,0x70,0xf8,0x88,0x88,0xf8,0x70,0x00,}, -//0x70=112 -{0x00,0xfc,0xfc,0x24,0x24,0x3c,0x18,0x00,}, -//0x71=113 -{0x00,0x18,0x3c,0x24,0xfc,0xfc,0x80,0xc0,}, -//0x72=114 -{0x00,0xf8,0xf8,0x08,0x08,0x38,0x30,0x00,}, -//0x73=115 -{0x00,0x90,0xa8,0xa8,0xa8,0xa8,0x48,0x00,}, -//0x74=116 -{0x00,0x10,0x10,0xfc,0xfc,0x10,0x10,0x00,}, -//0x75=117 -{0x00,0x78,0xf8,0x80,0x80,0xf8,0xf8,0x00,}, -//0x76=118 -{0x00,0x30,0x70,0xc0,0xc0,0x70,0x30,0x00,}, -//0x77=119 -{0x00,0x78,0xf8,0x80,0xf0,0x80,0xf8,0x78,}, -//0x78=120 -{0x00,0x88,0xd8,0x70,0x70,0xd8,0x88,0x00,}, -//0x79=121 -{0x00,0x18,0xb8,0xa0,0xa0,0xf8,0x78,0x00,}, -//0x7a=122 -{0x00,0x00,0xc8,0xe8,0xb8,0x98,0x00,0x00,}, -//0x7b=123 -{0x00,0x00,0x10,0x7c,0xee,0x82,0x82,0x00,}, -//0x7c=124 -{0x00,0x00,0x00,0xee,0xee,0x00,0x00,0x00,}, -//0x7d=125 -{0x00,0x82,0x82,0xee,0x7c,0x10,0x00,0x00,}, -//0x7e=126 -{0x00,0x10,0x18,0x08,0x18,0x10,0x08,0x00,}, -//0x7f=127 -{0x00,0xf0,0x98,0x8c,0x86,0x8c,0x98,0xf0,}, -}; -#endif +/* +This font has been created by rotating the original 'vincent' font. +See below for the original copyright, or go to +http://forum.osdev.org/viewtopic.php?f=2&t=22033 +*/ +/* +Created Sunday, May 23, 2010 by Quinn Evans +Renamed and updated Monday 24, 2010 + +This font (Vincent) is released by me into the public domain. I claim no +copyright, and hereby make this software available to the public for any use, +at any time, free of restrictions, legal or otherwise. +*/ +#ifndef FONT_H +#define FONT_H 1 +unsigned char font_data[128][8] = { +//0x0=0 +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,}, +//0x1=1 +{0x00,0x7c,0x82,0xaa,0xc2,0xaa,0x82,0x7c,}, +//0x2=2 +{0x00,0x7c,0xfe,0xd6,0xbe,0xd6,0xfe,0x7c,}, +//0x3=3 +{0x00,0x1c,0x3e,0x7c,0xf8,0x7c,0x3e,0x1c,}, +//0x4=4 +{0x00,0x10,0x38,0x7c,0xfe,0x7c,0x38,0x10,}, +//0x5=5 +{0x00,0x10,0x38,0x94,0xfe,0x94,0x38,0x10,}, +//0x6=6 +{0x00,0x10,0x38,0xbc,0xfe,0xbc,0x38,0x10,}, +//0x7=7 +{0x00,0x00,0x38,0x7c,0x7c,0x7c,0x38,0x00,}, +//0x8=8 +{0xff,0xff,0xc7,0x83,0x83,0x83,0xc7,0xff,}, +//0x9=9 +{0x00,0x00,0x38,0x44,0x44,0x44,0x38,0x00,}, +//0xa=10 +{0xff,0xff,0xc7,0xbb,0xbb,0xbb,0xc7,0xff,}, +//0xb=11 +{0x00,0x60,0x90,0x90,0x72,0x0a,0x06,0x1e,}, +//0xc=12 +{0x00,0x00,0x64,0x94,0x9e,0x94,0x64,0x00,}, +//0xd=13 +{0x00,0xc0,0xe0,0x7e,0x02,0x04,0x00,0x00,}, +//0xe=14 +{0x00,0xc0,0xe0,0x7c,0x06,0x62,0x72,0x3e,}, +//0xf=15 +{0x00,0x10,0x54,0x38,0xee,0x38,0x54,0x10,}, +//0x10=16 +{0x00,0xfe,0xfe,0x7c,0x7c,0x38,0x38,0x10,}, +//0x11=17 +{0x00,0x10,0x38,0x38,0x7c,0x7c,0xfe,0xfe,}, +//0x12=18 +{0x00,0x00,0x28,0x44,0xfe,0x44,0x28,0x00,}, +//0x13=19 +{0x00,0xde,0xde,0x00,0x00,0xde,0xde,0x00,}, +//0x14=20 +{0x00,0x0c,0x1e,0x12,0x12,0xfe,0x02,0xfe,}, +//0x15=21 +{0x00,0x48,0x94,0xa4,0x4a,0x52,0x24,0x00,}, +//0x16=22 +{0x00,0xe0,0xe0,0xe0,0xe0,0xe0,0xe0,0xe0,}, +//0x17=23 +{0x00,0x00,0xa8,0xc4,0xfe,0xc4,0xa8,0x00,}, +//0x18=24 +{0x00,0x10,0x18,0xfc,0xfe,0xfc,0x18,0x10,}, +//0x19=25 +{0x00,0x10,0x30,0x7e,0xfe,0x7e,0x30,0x10,}, +//0x1a=26 +{0x00,0x38,0x38,0x38,0xfe,0x7c,0x38,0x10,}, +//0x1b=27 +{0x00,0x10,0x38,0x7c,0xfe,0x38,0x38,0x38,}, +//0x1c=28 +{0x00,0xf8,0xf8,0xf8,0xc0,0xc0,0xc0,0xc0,}, +//0x1d=29 +{0x00,0x10,0x38,0x54,0x10,0x54,0x38,0x10,}, +//0x1e=30 +{0x00,0xc0,0xf0,0xfc,0xfe,0xfc,0xf0,0xc0,}, +//0x1f=31 +{0x00,0x06,0x1e,0x7e,0xfe,0x7e,0x1e,0x06,}, +//0x20=32 +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,}, +//0x21=33 +{0x00,0x00,0x0c,0xbe,0xbe,0x0c,0x00,0x00,}, +//0x22=34 +{0x00,0x00,0x06,0x0e,0x00,0x0e,0x06,0x00,}, +//0x23=35 +{0x00,0x28,0xfe,0xfe,0x28,0xfe,0xfe,0x28,}, +//0x24=36 +{0x00,0x00,0x48,0x54,0xd6,0x54,0x24,0x00,}, +//0x25=37 +{0x00,0x46,0x66,0x30,0x18,0xcc,0xc4,0x00,}, +//0x26=38 +{0x00,0x64,0xfe,0x8a,0x9a,0xee,0xc4,0xa0,}, +//0x27=39 +{0x00,0x00,0x10,0x1e,0x0e,0x00,0x00,0x00,}, +//0x28=40 +{0x00,0x82,0xc6,0x7c,0x38,0x00,0x00,0x00,}, +//0x29=41 +{0x00,0x00,0x00,0x38,0x7c,0xc6,0x82,0x00,}, +//0x2a=42 +{0x00,0x10,0x54,0x7c,0x38,0x7c,0x54,0x10,}, +//0x2b=43 +{0x00,0x00,0x10,0x10,0x7c,0x10,0x10,0x00,}, +//0x2c=44 +{0x00,0x80,0xf0,0x70,0x00,0x00,0x00,0x00,}, +//0x2d=45 +{0x00,0x00,0x10,0x10,0x10,0x10,0x00,0x00,}, +//0x2e=46 +{0x00,0xc0,0xc0,0x00,0x00,0x00,0x00,0x00,}, +//0x2f=47 +{0x00,0x40,0x60,0x30,0x18,0x0c,0x04,0x00,}, +//0x30=48 +{0x00,0x7c,0xfe,0x92,0x8a,0xfe,0x7c,0x00,}, +//0x31=49 +{0x00,0x80,0x88,0xfe,0xfe,0x80,0x80,0x00,}, +//0x32=50 +{0x00,0xc4,0xe6,0xa2,0x92,0x9e,0x8c,0x00,}, +//0x33=51 +{0x00,0x44,0xc6,0x92,0x92,0xfe,0x6c,0x00,}, +//0x34=52 +{0x00,0x30,0x28,0x24,0xfe,0xfe,0x20,0x00,}, +//0x35=53 +{0x00,0x4e,0xce,0x8a,0x8a,0xfa,0x72,0x00,}, +//0x36=54 +{0x00,0x7c,0xfe,0x92,0x92,0xf6,0x64,0x00,}, +//0x37=55 +{0x00,0x06,0x06,0xe2,0xfa,0x1e,0x06,0x00,}, +//0x38=56 +{0x00,0x6c,0xfe,0x92,0x92,0xfe,0x6c,0x00,}, +//0x39=57 +{0x00,0x4c,0xde,0x92,0x92,0xfe,0x7c,0x00,}, +//0x3a=58 +{0x00,0x00,0x00,0x6c,0x6c,0x00,0x00,0x00,}, +//0x3b=59 +{0x00,0x00,0x80,0xec,0x6c,0x00,0x00,0x00,}, +//0x3c=60 +{0x00,0x00,0x10,0x38,0x6c,0xc6,0x82,0x00,}, +//0x3d=61 +{0x00,0x00,0x28,0x28,0x28,0x28,0x00,0x00,}, +//0x3e=62 +{0x00,0x82,0xc6,0x6c,0x38,0x10,0x00,0x00,}, +//0x3f=63 +{0x00,0x04,0x06,0xb2,0xb2,0x1e,0x0c,0x00,}, +//0x40=64 +{0x00,0x3c,0x42,0x5a,0x5a,0x4c,0x20,0x00,}, +//0x41=65 +{0x00,0xfc,0xfe,0x12,0x12,0xfe,0xfc,0x00,}, +//0x42=66 +{0x00,0xfe,0xfe,0x92,0x92,0xfe,0x6c,0x00,}, +//0x43=67 +{0x00,0x7c,0xfe,0x82,0x82,0xc6,0x44,0x00,}, +//0x44=68 +{0x00,0xfe,0xfe,0x82,0x82,0xfe,0x7c,0x00,}, +//0x45=69 +{0x00,0xfe,0xfe,0x92,0x92,0x92,0x82,0x00,}, +//0x46=70 +{0x00,0xfe,0xfe,0x12,0x12,0x12,0x02,0x00,}, +//0x47=71 +{0x00,0x7c,0xfe,0x82,0xa2,0xe6,0x64,0x00,}, +//0x48=72 +{0x00,0xfe,0xfe,0x10,0x10,0xfe,0xfe,0x00,}, +//0x49=73 +{0x00,0x00,0x82,0xfe,0xfe,0x82,0x00,0x00,}, +//0x4a=74 +{0x00,0x60,0xe0,0x82,0xfe,0x7e,0x02,0x00,}, +//0x4b=75 +{0x00,0xfe,0xfe,0x38,0x6c,0xc6,0x82,0x00,}, +//0x4c=76 +{0x00,0xfe,0xfe,0x80,0x80,0x80,0x80,0x00,}, +//0x4d=77 +{0x00,0xfe,0xfe,0x0c,0x18,0x0c,0xfe,0xfe,}, +//0x4e=78 +{0x00,0xfe,0xfe,0x0c,0x18,0x30,0xfe,0xfe,}, +//0x4f=79 +{0x00,0x7c,0xfe,0x82,0x82,0xfe,0x7c,0x00,}, +//0x50=80 +{0x00,0xfe,0xfe,0x22,0x22,0x3e,0x1c,0x00,}, +//0x51=81 +{0x00,0x3c,0x7e,0x42,0x62,0xfe,0xbc,0x00,}, +//0x52=82 +{0x00,0xfe,0xfe,0x32,0x72,0xde,0x8c,0x00,}, +//0x53=83 +{0x00,0x4c,0xde,0x92,0x92,0xf6,0x64,0x00,}, +//0x54=84 +{0x00,0x06,0x02,0xfe,0xfe,0x02,0x06,0x00,}, +//0x55=85 +{0x00,0x7e,0xfe,0x80,0x80,0xfe,0xfe,0x00,}, +//0x56=86 +{0x00,0x3e,0x7e,0xc0,0xc0,0x7e,0x3e,0x00,}, +//0x57=87 +{0x00,0xfe,0xfe,0x60,0x30,0x60,0xfe,0xfe,}, +//0x58=88 +{0x00,0xc6,0xee,0x38,0x10,0x38,0xee,0xc6,}, +//0x59=89 +{0x00,0x0e,0x1e,0xf0,0xf0,0x1e,0x0e,0x00,}, +//0x5a=90 +{0x00,0xc2,0xe2,0xb2,0x9a,0x8e,0x86,0x00,}, +//0x5b=91 +{0x00,0x00,0x00,0xfe,0xfe,0x82,0x82,0x00,}, +//0x5c=92 +{0x00,0x04,0x0c,0x18,0x30,0x60,0x40,0x00,}, +//0x5d=93 +{0x00,0x82,0x82,0xfe,0xfe,0x00,0x00,0x00,}, +//0x5e=94 +{0x00,0x10,0x08,0x04,0x02,0x04,0x08,0x10,}, +//0x5f=95 +{0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,}, +//0x60=96 +{0x00,0x00,0x00,0x00,0x06,0x0e,0x08,0x00,}, +//0x61=97 +{0x00,0x40,0xe8,0xa8,0xa8,0xf8,0xf0,0x00,}, +//0x62=98 +{0x00,0xfe,0xfe,0x90,0x90,0xf0,0x60,0x00,}, +//0x63=99 +{0x00,0x70,0xf8,0x88,0x88,0xd8,0x50,0x00,}, +//0x64=100 +{0x00,0x60,0xf0,0x90,0x90,0xfe,0xfe,0x00,}, +//0x65=101 +{0x00,0x70,0xf8,0xa8,0xa8,0xb8,0x30,0x00,}, +//0x66=102 +{0x00,0x20,0xfc,0xfe,0x22,0x26,0x04,0x00,}, +//0x67=103 +{0x00,0x18,0xbc,0xa4,0xa4,0xfc,0x7c,0x00,}, +//0x68=104 +{0x00,0xfe,0xfe,0x10,0x10,0xf0,0xe0,0x00,}, +//0x69=105 +{0x00,0x00,0x80,0xf4,0xf4,0x80,0x00,0x00,}, +//0x6a=106 +{0x00,0x60,0xe0,0x80,0xfa,0x7a,0x00,0x00,}, +//0x6b=107 +{0x00,0xfe,0xfe,0x20,0x70,0xd8,0x88,0x00,}, +//0x6c=108 +{0x00,0x00,0x00,0xfe,0xfe,0x00,0x00,0x00,}, +//0x6d=109 +{0x00,0xf8,0xf8,0x30,0xe0,0x30,0xf8,0xf8,}, +//0x6e=110 +{0x00,0xf8,0xf8,0x18,0x18,0xf8,0xf0,0x00,}, +//0x6f=111 +{0x00,0x70,0xf8,0x88,0x88,0xf8,0x70,0x00,}, +//0x70=112 +{0x00,0xfc,0xfc,0x24,0x24,0x3c,0x18,0x00,}, +//0x71=113 +{0x00,0x18,0x3c,0x24,0xfc,0xfc,0x80,0xc0,}, +//0x72=114 +{0x00,0xf8,0xf8,0x08,0x08,0x38,0x30,0x00,}, +//0x73=115 +{0x00,0x90,0xa8,0xa8,0xa8,0xa8,0x48,0x00,}, +//0x74=116 +{0x00,0x10,0x10,0xfc,0xfc,0x10,0x10,0x00,}, +//0x75=117 +{0x00,0x78,0xf8,0x80,0x80,0xf8,0xf8,0x00,}, +//0x76=118 +{0x00,0x30,0x70,0xc0,0xc0,0x70,0x30,0x00,}, +//0x77=119 +{0x00,0x78,0xf8,0x80,0xf0,0x80,0xf8,0x78,}, +//0x78=120 +{0x00,0x88,0xd8,0x70,0x70,0xd8,0x88,0x00,}, +//0x79=121 +{0x00,0x18,0xb8,0xa0,0xa0,0xf8,0x78,0x00,}, +//0x7a=122 +{0x00,0x00,0xc8,0xe8,0xb8,0x98,0x00,0x00,}, +//0x7b=123 +{0x00,0x00,0x10,0x7c,0xee,0x82,0x82,0x00,}, +//0x7c=124 +{0x00,0x00,0x00,0xee,0xee,0x00,0x00,0x00,}, +//0x7d=125 +{0x00,0x82,0x82,0xee,0x7c,0x10,0x00,0x00,}, +//0x7e=126 +{0x00,0x10,0x18,0x08,0x18,0x10,0x08,0x00,}, +//0x7f=127 +{0x00,0xf0,0x98,0x8c,0x86,0x8c,0x98,0xf0,}, +}; +#endif
--- a/hd44780_8bit.cpp Tue Nov 16 20:49:18 2010 +0000 +++ b/hd44780_8bit.cpp Sat Nov 27 22:54:13 2010 +0000 @@ -27,10 +27,19 @@ #include "DigitalOut.h" #include "wait_api.h" +void HD44780LCD8bit::character(int column, int row, int c) +{ + int address=(row)*0x40+(column); + sendCmd((unsigned char)address|0x80); + wait_us(30); + sendData(c); + wait_us(30); +} -void HD44780LCD8bit::writeText(const unsigned int line, const unsigned int pos, const char text[]) { + +void HD44780LCD8bit::writeText(const unsigned int column, const unsigned int row, const char text[]) { // printf("print to %d,%d {%s}\n",line,pos,text); - int address=line*0x40+pos; + int address=row*0x40+column; sendCmd((unsigned char)address|0x80); wait_us(30); @@ -59,8 +68,8 @@ } HD44780LCD8bit::HD44780LCD8bit -(unsigned int width, unsigned int height, BusOut *data, PinName enable, PinName rs) - :TextLCDBase(width, height) +(unsigned int columns, unsigned int rows, BusOut *data, PinName enable, PinName rs) + :TextLCDBase(columns, rows) { _data=data; _rs=new DigitalOut(rs);
--- a/hd44780_8bit.h Tue Nov 16 20:49:18 2010 +0000 +++ b/hd44780_8bit.h Sat Nov 27 22:54:13 2010 +0000 @@ -46,10 +46,11 @@ * @param enable the pin name for the enable line (1=active) * @param rs the pin name for the register select line (0=cmd, 1=data) */ - HD44780LCD8bit(unsigned int width, unsigned int height, BusOut *data, PinName enable, PinName rs); + HD44780LCD8bit(unsigned int columns, unsigned int rows, BusOut *data, PinName enable, PinName rs); virtual void init(); - virtual void writeText(const unsigned int line, const unsigned int pos, const char text[]); + virtual void writeText(const unsigned int column, const unsigned int row, const char text[]); virtual void clear(); + virtual void character(int column, int row, int c); protected: void sendCmd(const unsigned char byte);
--- a/ks0108_8bit.cpp Tue Nov 16 20:49:18 2010 +0000 +++ b/ks0108_8bit.cpp Sat Nov 27 22:54:13 2010 +0000 @@ -30,11 +30,10 @@ #define ENABLE 1 -void KS0108LCD8bit::writeText(const unsigned int line, const unsigned int pos, const char text[]) { - printf("print to %d,%d {%s}\n",line,pos,text); +void KS0108LCD8bit::writeText(const unsigned int column, const unsigned int row, const char text[]) { int i=0; while (text[i]!=0) { - setChar(line, pos+i,text[i]); + character(column+i, row,text[i]); i++; } } @@ -48,10 +47,10 @@ void KS0108LCD8bit::clearHalf(DigitalOut* cs) { for (int x=0;x<8;x++) { + sendCmd(0xb8|x,cs); + wait_us(1); for (int y=0;y<64;y++) { - sendCmd(0xb8|x,cs); - wait_us(1); sendCmd(0x40|y,cs); wait_us(1); sendData(0,cs); @@ -60,13 +59,13 @@ } } -void KS0108LCD8bit::setChar(const unsigned int line, const unsigned int pos, const char c) { +void KS0108LCD8bit::character(int column, int row, int c){ DigitalOut* cs=NULL; - int column=pos; - if (column>7) + int icolumn=column; + if (icolumn>7) { cs=_right; - column-=8; + icolumn-=8; } else { @@ -75,9 +74,9 @@ if (NULL==cs) return; - sendCmd(0xb8|line,cs); // set x page + sendCmd(0xb8|row,cs); // set x page - unsigned int y=column*8; + unsigned int y=icolumn*8; sendCmd(0x40|y,cs); // set start line // send character data @@ -89,8 +88,8 @@ } KS0108LCD8bit::KS0108LCD8bit -(const unsigned int width, const unsigned int height, BusOut *data, const PinName enable, const PinName rs, const PinName leftCS, const PinName rightCS) - :TextLCDBase(width, height) { +(const unsigned int columns, const unsigned int rows, BusOut *data, const PinName enable, const PinName rs, const PinName leftCS, const PinName rightCS) + :TextLCDBase(columns, rows) { _data=data; _rs=new DigitalOut(rs); _enable=new DigitalOut(enable); @@ -118,7 +117,6 @@ wait_ms(10); sendCmd(0xc0, _right); } - printf("left vs. right: %d / %d\n",_left,_right); wait_ms(50); clear(); } @@ -139,7 +137,6 @@ void KS0108LCD8bit::sendByte(const unsigned char byte, DigitalOut *cs) { // display reads flags with rising flank of E -// printf("send to %d\n",cs); _enable->write(0); cs->write(ENABLE); _data->write(byte);
--- a/ks0108_8bit.h Tue Nov 16 20:49:18 2010 +0000 +++ b/ks0108_8bit.h Sat Nov 27 22:54:13 2010 +0000 @@ -1,69 +1,68 @@ -/* - * mbed LCDWindow library -* Copyright (c) 2010 Hendrik Lipka -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#ifndef KS0108_8BIT_H_ -#define KS0108_8BIT_H_ - -#include "lcd.h" - -#include "BusOut.h" -#include "DigitalOut.h" - -using namespace mbed; - -/** - * class for connecting graphical KS0108-based LCD-Display (or using similiar controllers) - * displays are connected in 8bit-mode - * for displaying ASCII, the vincent font from http://forum.osdev.org/viewtopic.php?f=2&t=22033 is used (courtesy to Quinn Evans) -*/ -class KS0108LCD8bit: public TextLCDBase -{ - public: - /** - * @param width number of chars per line (using an 8x8 font) - * @param height number of lines (using an 8x8 font) - * @param data the bus object used for sending data (must be 8bit) - * @param enable the pin name for the enable line (1=active) - * @param rs the pin name for the register select line (0=cmd, 1=data) - * @param leftCS the pin name for the left display half (1=active) - * @param rightCS the pin name for the right display half (1=active, use NC for smaller displays) - */ - KS0108LCD8bit(const unsigned int width, const unsigned int height, BusOut *data, const PinName enable, const PinName rs, const PinName leftCS, const PinName rightCS); - virtual void init(); - virtual void writeText(const unsigned int line, const unsigned int pos, const char text[]); - virtual void clear(); - - protected: - void clearHalf(DigitalOut *cs); - - void sendCmd(const unsigned char byte, DigitalOut *cs); - void sendData(const unsigned char byte, DigitalOut *cs); - - void sendByte(const unsigned char byte, DigitalOut *cs); - - void setChar(const unsigned int line, const unsigned int pos, const char c); - - BusOut* _data; - DigitalOut *_enable, *_rs, *_left, *_right; -}; +/* + * mbed LCDWindow library +* Copyright (c) 2010 Hendrik Lipka +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef KS0108_8BIT_H_ +#define KS0108_8BIT_H_ + +#include "lcd.h" + +#include "BusOut.h" +#include "DigitalOut.h" + +using namespace mbed; + +/** + * class for connecting graphical KS0108-based LCD-Display (or using similiar controllers) + * displays are connected in 8bit-mode + * for displaying ASCII, the vincent font from http://forum.osdev.org/viewtopic.php?f=2&t=22033 is used (courtesy to Quinn Evans) +*/ +class KS0108LCD8bit: public TextLCDBase +{ + public: + /** + * @param columns number of chars per line (using an 8x8 font) + * @param rows number of lines (using an 8x8 font) + * @param data the bus object used for sending data (must be 8bit) + * @param enable the pin name for the enable line (1=active) + * @param rs the pin name for the register select line (0=cmd, 1=data) + * @param leftCS the pin name for the left display half (1=active) + * @param rightCS the pin name for the right display half (1=active, use NC for smaller displays) + */ + KS0108LCD8bit(const unsigned int columns, const unsigned int rows, BusOut *data, const PinName enable, const PinName rs, const PinName leftCS, const PinName rightCS); + virtual void init(); + virtual void writeText(const unsigned int column, const unsigned int row, const char text[]); + virtual void clear(); + virtual void character(int column, int row, int c); + + protected: + void clearHalf(DigitalOut *cs); + + void sendCmd(const unsigned char byte, DigitalOut *cs); + void sendData(const unsigned char byte, DigitalOut *cs); + + void sendByte(const unsigned char byte, DigitalOut *cs); + + BusOut* _data; + DigitalOut *_enable, *_rs, *_left, *_right; +}; #endif \ No newline at end of file
--- a/lcd.h Tue Nov 16 20:49:18 2010 +0000 +++ b/lcd.h Sat Nov 27 22:54:13 2010 +0000 @@ -37,11 +37,12 @@ * it must be called from the outside, and initializes the display. */ virtual void init()=0; - virtual int getHeight(){return _height;}; - virtual int getWidth(){return _width;}; + virtual int getRows(){return _rows;}; + virtual int getColumns(){return _columns;}; protected: - const unsigned int _width, _height; - TextLCDBase(unsigned int width, unsigned int height):_width(width),_height(height) + const unsigned int _columns; + const unsigned int _rows; + TextLCDBase(unsigned int columns, unsigned int rows):_columns(columns),_rows(rows) { } };
--- a/lcd_spi.cpp Tue Nov 16 20:49:18 2010 +0000 +++ b/lcd_spi.cpp Sat Nov 27 22:54:13 2010 +0000 @@ -28,8 +28,8 @@ #include "wait_api.h" SPILCDBase::SPILCDBase -(unsigned int width, unsigned int height, SPI *spi, PinName enable, PinName rs) -:TextLCDBase(width,height) +(unsigned int columns, unsigned int rows, SPI *spi, PinName enable, PinName rs) +:TextLCDBase(columns,rows) { _spi=spi; _enable=new DigitalOut(enable);
--- a/lcd_spi.h Tue Nov 16 20:49:18 2010 +0000 +++ b/lcd_spi.h Sat Nov 27 22:54:13 2010 +0000 @@ -38,7 +38,7 @@ class SPILCDBase: public TextLCDBase { public: - SPILCDBase(unsigned int width, unsigned int height, SPI *spi, PinName enable, PinName rs); + SPILCDBase(unsigned int columns, unsigned int rows, SPI *spi, PinName enable, PinName rs); protected: void sendCmd(const unsigned char byte);
--- a/multiwindow.cpp Tue Nov 16 20:49:18 2010 +0000 +++ b/multiwindow.cpp Sat Nov 27 22:54:13 2010 +0000 @@ -26,20 +26,36 @@ MultiWindow::MultiWindow(vector<Window*> lcds) { _lcds=lcds; int len=_lcds.size(); - _height=0; + _rows=0; for (int i=0;i<len;i++) { - _height+=_lcds[i]->getHeight(); + _rows+=_lcds[i]->getRows(); } - _width=_lcds[0]->getWidth(); + _columns=_lcds[0]->getColumns(); } -void MultiWindow::writeText(const unsigned int line, const unsigned int pos, const char text[]) { +void MultiWindow::character(int column, int row, int c) +{ int len=_lcds.size(); int lines=0; for (int i=0;i<len;i++) { - int height=_lcds[i]->getHeight(); - if (line>=lines && line <lines+height) { - _lcds[i]->writeText(line-lines,pos,text); + int height=_lcds[i]->getRows(); + if (row>=lines && row <lines+height) { + _lcds[i]->character(column,row-lines,c); + break; + } + lines+=height; + } +} + + +void MultiWindow::writeText(const unsigned int columns, const unsigned int row, const char text[]) { + int len=_lcds.size(); + int lines=0; + for (int i=0;i<len;i++) { + int height=_lcds[i]->getRows(); + if (row>=lines && row <lines+height) { + _lcds[i]->writeText(columns,row-lines,text); + break; } lines+=height; }
--- a/multiwindow.h Tue Nov 16 20:49:18 2010 +0000 +++ b/multiwindow.h Sat Nov 27 22:54:13 2010 +0000 @@ -44,16 +44,19 @@ /** * writes text to the parent window which contains the given line */ - virtual void writeText(const unsigned int line, const unsigned int pos, const char text[]); - virtual int getHeight(){return _height;}; - virtual int getWidth(){return _width;}; + virtual void writeText(const unsigned int column, const unsigned int row, const char text[]); + virtual int getColumns(){return _columns;}; + virtual int getRows(){return _rows;}; /** * clears all parent windows */ virtual void clear(); + virtual void character(int column, int row, int c); + private: vector<Window*> _lcds; - int _height,_width; + int _columns; + int _rows; }; #endif
--- a/subwindow.cpp Tue Nov 16 20:49:18 2010 +0000 +++ b/subwindow.cpp Sat Nov 27 22:54:13 2010 +0000 @@ -25,38 +25,46 @@ #include "string.h" -SubWindow::SubWindow(Window* lcd, const unsigned int offsetX, const unsigned int offsetY, const unsigned int width, const unsigned int height) { +SubWindow::SubWindow(Window* lcd, const unsigned int columnOffset, const unsigned int rowOffset, const unsigned int columns, const unsigned int rows) { _lcd=lcd; - _offsetX=offsetX; - _offsetY=offsetY; - _width=width; - _height=height; + _columnOffset=columnOffset; + _rowOffset=rowOffset; + _columns=columns; + _rows=rows; } -void SubWindow::writeText(const unsigned int line, const unsigned int pos, const char* text) { - if (line>_height) +void SubWindow::character(int column, int row, int c) +{ + if (column>_columns || row>_rows) return; - char* text2=new char[_width-pos+1]; + _lcd->character(column+_columnOffset, row+_rowOffset, c); +} + +void SubWindow::writeText(const unsigned int column, const unsigned int row, const char* text) { + if (row>_rows) + return; + + char* text2=new char[_columns-column+1]; int i=0; - while (i<_width-pos+1) { + while (i<_columns-column+1) { text2[i]=text[i]; if (text[i]=='\0') break; i++; } - text2[_width-pos]='\0'; + text2[_columns-column]='\0'; - _lcd->writeText(line+_offsetY, pos+_offsetX, text2); + _lcd->writeText(column+_columnOffset, row+_rowOffset, text2); delete [] text2; } void SubWindow::clear() { - char* spaces=new char[_width+1]; - memset(spaces,32,_width); - spaces[_width]=0; - for (int i=0;i<_height;i++) { - _lcd->writeText(i+_offsetY,_offsetX,spaces); + char* spaces=new char[_columns+1]; + memset(spaces,32,_columns); + spaces[_columns]=0; + for (int i=0;i<_rows;i++) { + _lcd->writeText(_columnOffset,_rowOffset+i,spaces); } } \ No newline at end of file
--- a/subwindow.h Tue Nov 16 20:49:18 2010 +0000 +++ b/subwindow.h Sat Nov 27 22:54:13 2010 +0000 @@ -36,22 +36,27 @@ /** * It is assumed that the sub window fill fit into the parent. * @param lcd the parent window - * @param offsetX in which column to start the sub window - * @param offsetY in which line to start the sub window - * @param width the width of the sub window - * @param height the height of the sub window + * @param columnOffset in which column to start the sub window + * @param rowOffset in which line to start the sub window + * @param columns the width of the sub window + * @param rows the height of the sub window */ - SubWindow(Window* lcd, const unsigned int offsetX, const unsigned int offsetY, const unsigned int width, const unsigned int height); - virtual void writeText(const unsigned int line, const unsigned int pos, const char text[]); - virtual int getHeight(){return _height;}; - virtual int getWidth(){return _width;}; + SubWindow(Window* lcd, const unsigned int columnOffset, const unsigned int rowOffset, const unsigned int columns, const unsigned int rows); + virtual void writeText(const unsigned int column, const unsigned int row, const char text[]); + virtual int getColumns(){return _columns;}; + virtual int getRows(){return _rows;}; /** * clear the part of the parent window which is spanned by the sub window. */ virtual void clear(); + virtual void character(int column, int row, int c); + private: Window* _lcd; - unsigned int _offsetX, _offsetY, _width, _height; + unsigned int _columnOffset; + unsigned int _rowOffset; + unsigned int _columns; + unsigned int _rows; }; #endif \ No newline at end of file
--- a/teewindow.cpp Tue Nov 16 20:49:18 2010 +0000 +++ b/teewindow.cpp Sat Nov 27 22:54:13 2010 +0000 @@ -26,14 +26,22 @@ TeeWindow::TeeWindow(vector<Window*> lcds) { _lcds=lcds; int len=_lcds.size(); - _height=_lcds[0]->getHeight(); - _width=_lcds[0]->getWidth(); + _columns=_lcds[0]->getColumns(); + _rows=_lcds[0]->getRows(); } -void TeeWindow::writeText(const unsigned int line, const unsigned int pos, const char text[]) { +void TeeWindow::character(int column, int row, int c) +{ int len=_lcds.size(); for (int i=0;i<len;i++) { - _lcds[i]->writeText(line,pos,text); + _lcds[i]->character(column,row,c); + } +} + +void TeeWindow::writeText(const unsigned int column, const unsigned int row, const char text[]) { + int len=_lcds.size(); + for (int i=0;i<len;i++) { + _lcds[i]->writeText(column,row,text); } }
--- a/teewindow.h Tue Nov 16 20:49:18 2010 +0000 +++ b/teewindow.h Sat Nov 27 22:54:13 2010 +0000 @@ -43,16 +43,19 @@ /** * writes the text to all parent windows */ - virtual void writeText(const unsigned int line, const unsigned int pos, const char text[]); - virtual int getHeight(){return _height;}; - virtual int getWidth(){return _width;}; + virtual void writeText(const unsigned int column, const unsigned int row, const char text[]); + virtual int getColumns(){return _columns;}; + virtual int getRows(){return _rows;}; /** * clears all parent windows */ virtual void clear(); + virtual void character(int column, int row, int c); + private: vector<Window*> _lcds; - int _height,_width; + unsigned int _columns; + unsigned int _rows; }; #endif
--- a/terminal.cpp Tue Nov 16 20:49:18 2010 +0000 +++ b/terminal.cpp Sat Nov 27 22:54:13 2010 +0000 @@ -1,17 +1,17 @@ /* * mbed LCDWindow library * Copyright (c) 2010 Hendrik Lipka -* +* * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: -* +* * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. -* +* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,51 +26,60 @@ Terminal::Terminal(Window* window) { _window=window; - _height=window->getHeight(); - _width=window->getWidth(); - _lines=new char*[_height]; - for (int i=0;i<_height;i++) { - _lines[i]=createLine(); - } + _columns=window->getColumns(); + _rows=window->getRows(); + _lineBuffer=new char*[_rows]; + clear(); } -char* Terminal::createLine() -{ - char* text=new char[_width+1]; - memset(text,32,_width); - text[_width]=0; +char* Terminal::createLine() { + char* text=new char[_columns+1]; + memset(text,32,_columns); + text[_columns]=0; return text; } -void Terminal::writeText(const unsigned int line, const unsigned int pos, const char text[]) { - _window->writeText(line,pos,text); - int min=pos+strlen(text); - if (min>_width) - min=_width; - for (int i=pos;i<min;i++) { - _lines[line][i]=text[i-pos]; // copy text into proper line +void Terminal::character(int column, int row, int c) { + if (column>_columns || row > _rows) { + return; + } + _lineBuffer[row][column]=c; + _window->character(column,row,c); + +} + +void Terminal::writeText(const unsigned int column, const unsigned int row, const char text[]) { + _window->writeText(column,row,text); + int min=column+strlen(text); + if (min>_columns) + min=_columns; + for (int i=column;i<min;i++) { + _lineBuffer[row][i]=text[i-column]; // copy text into proper line } } void Terminal::addText(const char text[]) { - delete [] _lines[0]; - for (int i=0;i<_height-1;i++) { - _lines[i]=_lines[i+1]; + delete [] _lineBuffer[0]; + for (int i=0;i<_rows-1;i++) { + _lineBuffer[i]=_lineBuffer[i+1]; } - _lines[_height-1]=createLine(); - memset(_lines[_height-1],32,_width); + _lineBuffer[_rows-1]=createLine(); + memset(_lineBuffer[_rows-1],32,_columns); int min=strlen(text); - if (min>_width) - min=_width; + if (min>_columns) + min=_columns; for (int i=0;i<min;i++) { - _lines[_height-1][i]=text[i]; // copy text into proper line + _lineBuffer[_rows-1][i]=text[i]; // copy text into proper line } - clear(); - for (int i=0;i<_height;i++) { - _window->writeText(i,0,_lines[i]); + _window->clear(); + for (int i=0;i<_rows;i++) { + _window->writeText(0,i,_lineBuffer[i]); } } void Terminal::clear() { + for (int i=0;i<_rows;i++) { + _lineBuffer[i]=createLine(); + } _window->clear(); }
--- a/terminal.h Tue Nov 16 20:49:18 2010 +0000 +++ b/terminal.h Sat Nov 27 22:54:13 2010 +0000 @@ -41,19 +41,22 @@ * works like the normal writeText method, * but also stores the written text into the internal buffer (which makes it subject to scrolling) */ - virtual void writeText(const unsigned int line, const unsigned int pos, const char text[]); + virtual void writeText(const unsigned int column, const unsigned int row, const char text[]); /** * write the given text into the last line (at the first position) * @param text the text to write */ virtual void addText(const char text[]); - virtual int getHeight(){return _height;}; - virtual int getWidth(){return _width;}; + virtual int getColumns(){return _columns;}; + virtual int getRows(){return _rows;}; virtual void clear(); + virtual void character(int column, int row, int c); + private: Window* _window; - char** _lines; - int _height, _width; + char** _lineBuffer; + unsigned int _columns; + unsigned int _rows; char* createLine(); };
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/window.cpp Sat Nov 27 22:54:13 2010 +0000 @@ -0,0 +1,50 @@ +/* + * mbed LCDWindow library +* Copyright (c) 2010 Hendrik Lipka +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "window.h" + +void Window::locate(int column, int row) { + _column = column; + _row = row; +} + +int Window::_putc(int value) { + if (value == '\n') { + _column = 0; + _row++; + if (_row >= getRows()) { + _row = 0; + } + } else { + character(_column, _row, value); + _column++; + if (_column >= getColumns()) { + _column = 0; + _row++; + if (_row >= getRows()) { + _row = 0; + } + } + } + return value; +} \ No newline at end of file
--- a/window.h Tue Nov 16 20:49:18 2010 +0000 +++ b/window.h Sat Nov 27 22:54:13 2010 +0000 @@ -1,17 +1,17 @@ /* * mbed LCDWindow library * Copyright (c) 2010 Hendrik Lipka -* +* * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: -* +* * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. -* +* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,32 +24,82 @@ #ifndef WINDOW_H_ #define WINDOW_H_ +#include "Stream.h" + +using namespace mbed; + /** * the base window class, which proves the interface for all common methods. */ -class Window -{ - public: - /** - * write text into the window, at the given position. - * Implementations should check for the length of the text and shorten it accordingly. - * @params line the line where to write - * @params pos the column where to write - * @params text the text to write - */ - virtual void writeText(const unsigned int line, const unsigned int pos, const char text[])=0; - /** - * @param returns the height of the window - */ - virtual int getHeight()=0; - /** - * @param returns the width of the window - */ - virtual int getWidth()=0; - /** - * clears the window - */ - virtual void clear()=0; +class Window : public Stream { +public: + /** + * write text into the window, at the given position. + * this doesn't change the internal cursor position + * Implementations should check for the length of the text and shorten it accordingly. + * @params columns the column where to write + * @params row the line where to write + * @params text the text to write + */ + virtual void writeText(const unsigned int column, const unsigned int row, const char text[])=0; + /** + * @param returns the height of the window + */ + virtual int getRows()=0; + /** + * @param returns the width of the window + */ + virtual int getColumns()=0; + /** + * clears the window + */ + virtual void clear()=0; + + /** + * set (internal) cursor to a screen column and row + * + * @param column The horizontal position from the left, indexed from 0 + * @param row The vertical position from the top, indexed from 0 + */ + virtual void locate(int column, int row); + + /** + * writes a character to the specified position + * must be public because it is used during delegation + * + * @param column The horizontal position from the left, indexed from 0 + * @param row The vertical position from the top, indexed from 0 + * @param c the character + */ + virtual void character(int column, int row, int c)=0; + +#if DOXYGEN_ONLY + /** + * Write a character to the LCD, on the position specified by the cursor + * sets the cursor to the next position, and wraps (from right to left, next line, and from bottom back to top) + * + * @param c The character to write to the display + */ + int putc(int c); + + /** + * Write a formated string to the LCD, on the position specified by the cursor + * does wrap around (as specified by putc) + * + * @param format A printf-style format string, followed by the + * variables to use in formating the string. + */ + int printf(const char* format, ...); +#endif +protected: + // Stream implementation functions + virtual int _putc(int value); + virtual int _getc() { + return -1; + }; + + int _column; + int _row; }; #endif /*WINDOW_H_*/