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 0:ae5037e3d6e0, committed 2010-11-15
- Comitter:
- hlipka
- Date:
- Mon Nov 15 22:37:30 2010 +0000
- Child:
- 1:65f72ed914fa
- Commit message:
- add support for KS0108-based graphical displays
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dogm_spi.cpp Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,69 @@ +/* + * 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 "dogm_spi.h" + +#include "SPI.h" +#include "DigitalOut.h" +#include "wait_api.h" + +DogmLCDSPI::DogmLCDSPI +(unsigned int width, unsigned int height, SPI *spi, PinName enable, PinName rs) +:SPILCDBase(width,height,spi,enable,rs) +{ +} + +void DogmLCDSPI::init() +{ + unsigned char initCmd[10]={0x38,0x39,0x14,0x55,0x6d,0x78,0x38,0x0c,0x01,0x06}; + + _enable->write(1); + wait_ms(80); + + for (int i=0;i<sizeof(initCmd);i++) + { + sendCmd(initCmd[i]); + wait_ms(4); + } +} + +void DogmLCDSPI::writeText(unsigned int line, unsigned int pos, char text[]) +{ + int address=(line)*0x40+(pos); + sendCmd((char)address|0x80); + wait_ms(1); + + int i=0; + while(text[i]!=0) + { + sendData(text[i]); + wait_ms(1); + i++; + } +} + +void DogmLCDSPI::clear() +{ + sendCmd(1); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dogm_spi.h Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,53 @@ +/* + * 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 DOGM_SPI_H_ +#define DOGM_SPI_H_ + +#include "lcd_spi.h" + +#include "DigitalOut.h" +#include "SPI.h" + +using namespace mbed; + +/** + * class for connecting a DOGM16x LCD display, from electronic assembly (www.lcd-module.com ) +*/ +class DogmLCDSPI: public SPILCDBase +{ + public: + /** + * @param width number of chars per line + * @param height 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); + virtual void init(); + virtual void writeText(unsigned int line, unsigned int pos, char text[]); + virtual void clear(); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/font.h Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hd44780_8bit.cpp Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,87 @@ +/* + * 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 "hd44780_8bit.h" + +#include "BusOut.h" +#include "DigitalOut.h" +#include "wait_api.h" + + +void HD44780LCD8bit::writeText(unsigned int line, unsigned int pos, char text[]) { +// printf("print to %d,%d {%s}\n",line,pos,text); + int address=line*0x40+pos; + sendCmd((unsigned char)address|0x80); + wait_us(30); + + int i=0; + while (text[i]!=0) { + sendData(text[i]); + wait_us(30); + i++; + } +} + +void HD44780LCD8bit::clear() { + sendCmd(1); +} + +void HD44780LCD8bit::sendCmd(unsigned char cmd) { + _rs->write(0); + wait_us(1); + sendByte(cmd); +} + +void HD44780LCD8bit::sendData(unsigned char cmd) { + _rs->write(1); + wait_us(1); + sendByte(cmd); +} + +HD44780LCD8bit::HD44780LCD8bit +(unsigned int width, unsigned int height, BusOut *data, PinName enable, PinName rs) + :TextLCDBase(width, height) + { + _data=data; + _rs=new DigitalOut(rs); + _enable=new DigitalOut(enable); + _enable->write(0); + wait_ms(80); +} + +void HD44780LCD8bit::init() { + unsigned char initCmd[5]={0x38,0x08,0x01,0x06,0x0c}; + for (int i=0;i<sizeof(initCmd);i++) { + sendCmd(initCmd[i]); + wait_ms(50); + } +} + +void HD44780LCD8bit::sendByte(unsigned char byte) { + _data->write(byte); + _enable->write(1); + wait_us(2); + _enable->write(0); + wait_us(30); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hd44780_8bit.h Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,63 @@ +/* + * 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 HD44780_8BIT_H_ +#define HD44780_8BIT_H_ + +#include "lcd.h" + +#include "BusOut.h" +#include "DigitalOut.h" + +using namespace mbed; + +/** + * class for connecting HD44780-based LCD-Display (or using similiar controllers) + * displays are connected in 8bit-mode + * currently only 1 or 2 lines are supported +*/ +class HD44780LCD8bit: public TextLCDBase +{ + public: + /** + * @param width number of chars per line + * @param height number of lines (currently only 1 and 2 work) + * @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) + */ + HD44780LCD8bit(unsigned int width, unsigned int height, BusOut *data, PinName enable, PinName rs); + virtual void init(); + virtual void writeText(unsigned int line, unsigned int pos, char text[]); + virtual void clear(); + + protected: + void sendCmd(unsigned char byte); + void sendData(unsigned char byte); + + void sendByte(unsigned char byte); + + BusOut* _data; + DigitalOut *_enable, *_rs; +}; +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ks0108_8bit.cpp Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,155 @@ +/* + * 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 "ks0108_8bit.h" + +#include "BusOut.h" +#include "DigitalOut.h" +#include "wait_api.h" +#include "font.h" + +#define ENABLE 1 + +void KS0108LCD8bit::writeText(unsigned int line, unsigned int pos, char text[]) { + printf("print to %d,%d {%s}\n",line,pos,text); + int i=0; + while (text[i]!=0) { + setChar(line, pos+i,text[i]); + i++; + } +} + +void KS0108LCD8bit::clear() { + clearHalf(_left); + if (NULL!=_right) + clearHalf(_right); +} + +void KS0108LCD8bit::clearHalf(DigitalOut* cs) { + for (int x=0;x<8;x++) + { + for (int y=0;y<64;y++) + { + sendCmd(0xb8|x,cs); + wait_us(1); + sendCmd(0x40|y,cs); + wait_us(1); + sendData(0,cs); + wait_us(1); + } + } +} + +void KS0108LCD8bit::setChar(unsigned int line, unsigned int pos, char c) { + DigitalOut* cs=NULL; + if (pos>7) + { + cs=_right; + pos-=8; + } + else + { + cs=_left; + } + if (NULL==cs) + return; + + sendCmd(0xb8|line,cs); // set x page + + unsigned int y=pos*8; + sendCmd(0x40|y,cs); // set start line + + // send character data + for (int i=0;i<8;i++) + { + sendData(font_data[c][i],cs); + } + +} + +KS0108LCD8bit::KS0108LCD8bit +(unsigned int width, unsigned int height, BusOut *data, PinName enable, PinName rs, PinName leftCS, PinName rightCS) + :TextLCDBase(width, height) { + _data=data; + _rs=new DigitalOut(rs); + _enable=new DigitalOut(enable); + _left=new DigitalOut(leftCS); + _left->write(1-ENABLE); + if (NC!=rightCS) + { + _right=new DigitalOut(rightCS); + _right->write(1-ENABLE); + } + else + _right=NULL; + _enable->write(0); + wait_ms(80); +} + +void KS0108LCD8bit::init() { + sendCmd(0x3f, _left); + wait_ms(10); + sendCmd(0xc0, _left); + + if (NULL!=_right) + { + sendCmd(0x3f, _right); + wait_ms(10); + sendCmd(0xc0, _right); + } + printf("left vs. right: %d / %d\n",_left,_right); + wait_ms(50); + clear(); +} + +void KS0108LCD8bit::sendCmd(unsigned char cmd, DigitalOut *cs) { + _rs->write(0); + wait_us(1); + sendByte(cmd, cs); + wait_us(10); +} + +void KS0108LCD8bit::sendData(unsigned char cmd, DigitalOut *cs) { + _rs->write(1); + wait_us(1); + sendByte(cmd, cs); + wait_us(10); +} + +void KS0108LCD8bit::sendByte(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); + + wait_us(2); + _enable->write(1); + + // display reads data with falling flank of E + wait_us(2); + _enable->write(0); + + wait_us(30); + cs->write(1-ENABLE); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ks0108_8bit.h Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,69 @@ +/* + * 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(unsigned int width, unsigned int height, BusOut *data, PinName enable, PinName rs, PinName leftCS, PinName rightCS); + virtual void init(); + virtual void writeText(unsigned int line, unsigned int pos, char text[]); + virtual void clear(); + + protected: + void clearHalf(DigitalOut *cs); + + void sendCmd(unsigned char byte, DigitalOut *cs); + void sendData(unsigned char byte, DigitalOut *cs); + + void sendByte(unsigned char byte, DigitalOut *cs); + + void setChar(unsigned int line, unsigned int pos, char c); + + BusOut* _data; + DigitalOut *_enable, *_rs, *_left, *_right; +}; +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lcd.h Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,49 @@ +/* + * 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 LCD_H_ +#define LCD_H_ + +#include "window.h" + +/** + * base class for all (text based) LCD displays +*/ +class TextLCDBase: public Window +{ + public: + /** + * this is the only function added to the Window interface + * 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;}; + protected: + const unsigned int _width, _height; + TextLCDBase(unsigned int width, unsigned int height):_width(width),_height(height) + { + } +}; + +#endif /*LCD_H_*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lcd_spi.cpp Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,66 @@ +/* + * 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 "lcd_spi.h" + +#include "SPI.h" +#include "DigitalOut.h" +#include "wait_api.h" + +SPILCDBase::SPILCDBase +(unsigned int width, unsigned int height, SPI *spi, PinName enable, PinName rs) +:TextLCDBase(width,height) +{ + _spi=spi; + _enable=new DigitalOut(enable); + _rs=new DigitalOut(rs); + _enable->write(1); + _spi->format(8,3); // 8 bits, cpol=1, cpha=1 (should be mode 2, but phase seems inverted) + // set SPI frequency at 0.1 MHz + _spi->frequency(100000); +} + +void SPILCDBase::sendByte(unsigned char byte) +{ + _enable->write(0); // enable transfer + wait_us(1); + _spi->write(byte); // send byte over wire + wait_us(20); + _enable->write(1); +} + +void SPILCDBase::sendCmd(unsigned char cmd) +{ + _rs->write(0); + wait_us(1); + sendByte(cmd); + wait_us(1); + _rs->write(1); +} + +void SPILCDBase::sendData(unsigned char cmd) +{ + _rs->write(1); + wait_us(1); + sendByte(cmd); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lcd_spi.h Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,53 @@ +/* + * 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 LCD_SPI_H_ +#define LCD_SPI_H_ + +#include "lcd.h" + +#include "DigitalOut.h" +#include "SPI.h" + +using namespace mbed; + +/** + * base class for all SPI based LCD displays. + * Provides methods for sending commands and data to the display. +*/ +class SPILCDBase: public TextLCDBase +{ + public: + SPILCDBase(unsigned int width, unsigned int height, SPI *spi, PinName enable, PinName rs); + + protected: + void sendCmd(unsigned char byte); + void sendData(unsigned char byte); + + void sendByte(unsigned char byte); + + SPI* _spi; + DigitalOut *_enable, *_rs; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/multiwindow.cpp Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,53 @@ +/* + * 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 "multiwindow.h" + +MultiWindow::MultiWindow(vector<Window*> lcds) { + _lcds=lcds; + int len=_lcds.size(); + _height=0; + for (int i=0;i<len;i++) { + _height+=_lcds[i]->getHeight(); + } + _width=_lcds[0]->getWidth(); +} + +void MultiWindow::writeText(unsigned int line, unsigned int pos, char text[]) { + 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); + } + lines+=height; + } +} + +void MultiWindow::clear() { + int len=_lcds.size(); + for (int i=0;i<len;i++) { + _lcds[i]->clear(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/multiwindow.h Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,59 @@ +/* + * 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 MULTIWINDOW_H_ +#define MULTIWINDOW_H_ + +#include "window.h" + +#include "vector" + +using namespace std; + +/** + * Class for combining multiple windows into a single one (by stacking them on top of each other). + * It is assumed that all windows are of the same width (but they might be of different height). +*/ +class MultiWindow: public Window +{ + public: + /** + * @param lcds the vector of windows to stack. Aggregated height is calculated as sum of all heights + */ + MultiWindow(vector<Window*> lcds); + /** + * writes text to the parent window which contains the given line + */ + virtual void writeText(unsigned int line, unsigned int pos, char text[]); + virtual int getHeight(){return _height;}; + virtual int getWidth(){return _width;}; + /** + * clears all parent windows + */ + virtual void clear(); + private: + vector<Window*> _lcds; + int _height,_width; +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/subwindow.cpp Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,62 @@ +/* + * 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 "subwindow.h" + +#include "string.h" + +SubWindow::SubWindow(Window* lcd, unsigned int offsetX, unsigned int offsetY, unsigned int width, unsigned int height) { + _lcd=lcd; + _offsetX=offsetX; + _offsetY=offsetY; + _width=width; + _height=height; + +} + +void SubWindow::writeText(unsigned int line, unsigned int pos, char* text) { + if (line>_height) + return; + + char* text2=new char[_width-pos+1]; + int i=0; + while (i<_width-pos+1) { + text2[i]=text[i]; + if (text[i]=='\0') + break; + i++; + } + text2[_width-pos]='\0'; + + _lcd->writeText(line+_offsetY, pos+_offsetX, 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); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/subwindow.h Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,57 @@ +/* + * 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 SUBWINDOW_H_ +#define SUBWINDOW_H_ + +#include "window.h" + +/** + * A window class using only a part of a parent window for output. + * It is assumed that the sub window fill fit into the parent. +*/ +class SubWindow: public Window +{ + public: + /** + * 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 + */ + SubWindow(Window* lcd, unsigned int offsetX, unsigned int offsetY, unsigned int width, unsigned int height); + virtual void writeText(unsigned int line, unsigned int pos, char text[]); + virtual int getHeight(){return _height;}; + virtual int getWidth(){return _width;}; + /** + * clear the part of the parent window which is spanned by the sub window. + */ + virtual void clear(); + private: + Window* _lcd; + unsigned int _offsetX, _offsetY, _width, _height; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teewindow.cpp Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,45 @@ +/* + * 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 "teewindow.h" + +TeeWindow::TeeWindow(vector<Window*> lcds) { + _lcds=lcds; + int len=_lcds.size(); + _height=_lcds[0]->getHeight(); + _width=_lcds[0]->getWidth(); +} + +void TeeWindow::writeText(unsigned int line, unsigned int pos, char text[]) { + int len=_lcds.size(); + for (int i=0;i<len;i++) { + _lcds[i]->writeText(line,pos,text); + } +} + +void TeeWindow::clear() { + int len=_lcds.size(); + for (int i=0;i<len;i++) { + _lcds[i]->clear();; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teewindow.h Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,58 @@ +/* + * 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 TEEWINDOW_H_ +#define TEEWINDOW_H_ + +#include "window.h" +#include "vector" + +using namespace std; + +/** + * A window class duplicating all writes into all given parent windows (like the Unix 'tee' command). + * It is assumed that all given windows are of the same size. +*/ +class TeeWindow: public Window +{ + public: + /** + * @param lcds the vector of windows to write into + */ + TeeWindow(vector<Window*> lcds); + /** + * writes the text to all parent windows + */ + virtual void writeText(unsigned int line, unsigned int pos, char text[]); + virtual int getHeight(){return _height;}; + virtual int getWidth(){return _width;}; + /** + * clears all parent windows + */ + virtual void clear(); + private: + vector<Window*> _lcds; + int _height,_width; +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/terminal.cpp Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,76 @@ +/* + * 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 "terminal.h" +#include "string.h" + +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(); + } +} + +char* Terminal::createLine() +{ + char* text=new char[_width+1]; + memset(text,32,_width); + text[_width]=0; + return text; +} + +void Terminal::writeText(unsigned int line, unsigned int pos, 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::addText(char text[]) { + delete [] _lines[0]; + for (int i=0;i<_height-1;i++) { + _lines[i]=_lines[i+1]; + } + _lines[_height-1]=createLine(); + memset(_lines[_height-1],32,_width); + int min=strlen(text); + if (min>_width) + min=_width; + for (int i=0;i<min;i++) { + _lines[_height-1][i]=text[i]; // copy text into proper line + } + clear(); + for (int i=0;i<_height;i++) { + _window->writeText(i,0,_lines[i]); + } +} + +void Terminal::clear() { + _window->clear(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/terminal.h Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,60 @@ +/* + * 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 TERMINAL_H_ +#define TERMINAL_H_ + +#include "window.h" + +/** + * A windows class which uses an internal buffer to provide automatic scrolling. + * The buffer is initially filled with spaces. +*/ +class Terminal: public Window +{ + public: + /** + * @param window the parent window + */ + Terminal(Window* window); + /** + * 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(unsigned int line, unsigned int pos, char text[]); + /** + * write the given text into the last line (at the first position) + * @param text the text to write + */ + virtual void addText(char text[]); + virtual int getHeight(){return _height;}; + virtual int getWidth(){return _width;}; + virtual void clear(); + private: + Window* _window; + char** _lines; + int _height, _width; + char* createLine(); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/window.h Mon Nov 15 22:37:30 2010 +0000 @@ -0,0 +1,55 @@ +/* + * 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 WINDOW_H_ +#define WINDOW_H_ + +/** + * 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(unsigned int line, unsigned int pos, 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; +}; + +#endif /*WINDOW_H_*/