Fork of Dimiter program. "Wait" commands adjusted and added Arial 10 font.

Fork of KS0108 by Dimiter K

Committer:
DimiterK
Date:
Tue Jan 04 18:35:28 2011 +0000
Revision:
0:135b9a0a816e
Child:
1:a368f2688222
First release.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DimiterK 0:135b9a0a816e 1 #include "KS0108.h"
DimiterK 0:135b9a0a816e 2 #include <math.h>
DimiterK 0:135b9a0a816e 3
DimiterK 0:135b9a0a816e 4 /*Constructor, initializes the lcd on the respective pins.
DimiterK 0:135b9a0a816e 5 *
DimiterK 0:135b9a0a816e 6 *@param pins
DimiterK 0:135b9a0a816e 7 *@param databus
DimiterK 0:135b9a0a816e 8 */
DimiterK 0:135b9a0a816e 9 KS0108::KS0108 (PinName _RST,PinName _DI, PinName _RW, PinName _E, PinName _CS2, PinName _CS1, PinName DB0, PinName DB1, PinName DB2, PinName DB3, PinName DB4, PinName DB5, PinName DB6, PinName DB7)
DimiterK 0:135b9a0a816e 10 : DB(DB0,DB1,DB2,DB3,DB4,DB5,DB6,DB7),RST (_RST),DI(_DI), RW(_RW), E(_E), CS2(_CS2), CS1(_CS1) {
DimiterK 0:135b9a0a816e 11
DimiterK 0:135b9a0a816e 12 DB.output();
DimiterK 0:135b9a0a816e 13 CS1.output(); CS2.output();
DimiterK 0:135b9a0a816e 14 RST.write(0);
DimiterK 0:135b9a0a816e 15 wait_us(10);
DimiterK 0:135b9a0a816e 16 RST.write(1); //reset screen
DimiterK 0:135b9a0a816e 17 E.write(0);
DimiterK 0:135b9a0a816e 18 ClearScreen(); //clear display
DimiterK 0:135b9a0a816e 19 WriteInstruction(LCD_ON, BOTH); //turn on lcd
DimiterK 0:135b9a0a816e 20 }
DimiterK 0:135b9a0a816e 21
DimiterK 0:135b9a0a816e 22
DimiterK 0:135b9a0a816e 23 /*Write instruction to the specific controller.
DimiterK 0:135b9a0a816e 24 *
DimiterK 0:135b9a0a816e 25 *@param Command command to send
DimiterK 0:135b9a0a816e 26 *@param side controller side can be LEFT or RIGHT
DimiterK 0:135b9a0a816e 27 *@return none
DimiterK 0:135b9a0a816e 28 *
DimiterK 0:135b9a0a816e 29 */
DimiterK 0:135b9a0a816e 30 void KS0108::WriteInstruction(unsigned int Command,unsigned int side){
DimiterK 0:135b9a0a816e 31 E.write(0);
DimiterK 0:135b9a0a816e 32 DI.write(0);
DimiterK 0:135b9a0a816e 33 RW.write(0);
DimiterK 0:135b9a0a816e 34
DimiterK 0:135b9a0a816e 35 SelectSide(side);
DimiterK 0:135b9a0a816e 36
DimiterK 0:135b9a0a816e 37 wait(0.0000003); // 300ns
DimiterK 0:135b9a0a816e 38 E.write(1);
DimiterK 0:135b9a0a816e 39 DB.output();
DimiterK 0:135b9a0a816e 40 DB.write(Command);
DimiterK 0:135b9a0a816e 41 wait(0.0000001);
DimiterK 0:135b9a0a816e 42 E.write(0);
DimiterK 0:135b9a0a816e 43 }
DimiterK 0:135b9a0a816e 44
DimiterK 0:135b9a0a816e 45 /*Write data to the controller.
DimiterK 0:135b9a0a816e 46 *
DimiterK 0:135b9a0a816e 47 *@param data data to send
DimiterK 0:135b9a0a816e 48 *@param side controller side can be LEFT or RIGHT
DimiterK 0:135b9a0a816e 49 *
DimiterK 0:135b9a0a816e 50 *@return none
DimiterK 0:135b9a0a816e 51 */
DimiterK 0:135b9a0a816e 52 void KS0108::WriteData(unsigned int data,unsigned char side){
DimiterK 0:135b9a0a816e 53 E.write(0);
DimiterK 0:135b9a0a816e 54 DI.write(1);
DimiterK 0:135b9a0a816e 55 RW.write(0);
DimiterK 0:135b9a0a816e 56
DimiterK 0:135b9a0a816e 57 SelectSide(side);
DimiterK 0:135b9a0a816e 58
DimiterK 0:135b9a0a816e 59 wait(0.0000003); // 300ns
DimiterK 0:135b9a0a816e 60 E = 1;
DimiterK 0:135b9a0a816e 61 DB.output();
DimiterK 0:135b9a0a816e 62 DB.write(data);
DimiterK 0:135b9a0a816e 63 wait(0.0000001);
DimiterK 0:135b9a0a816e 64 E = 0;
DimiterK 0:135b9a0a816e 65 }
DimiterK 0:135b9a0a816e 66
DimiterK 0:135b9a0a816e 67 /*Write data to the screen on specific page and column
DimiterK 0:135b9a0a816e 68 *
DimiterK 0:135b9a0a816e 69 *@param page page varies from0-7 for each side
DimiterK 0:135b9a0a816e 70 *@param col col varies from 0-64 for each side
DimiterK 0:135b9a0a816e 71 *@param data info to be written on given coordinates
DimiterK 0:135b9a0a816e 72 *@return none
DimiterK 0:135b9a0a816e 73 *
DimiterK 0:135b9a0a816e 74 */
DimiterK 0:135b9a0a816e 75 void KS0108::WriteDataColPag(unsigned int page, unsigned int col, unsigned int data){
DimiterK 0:135b9a0a816e 76
DimiterK 0:135b9a0a816e 77 SelectSide(NONE);
DimiterK 0:135b9a0a816e 78 col = col%SCREEN_WIDTH;
DimiterK 0:135b9a0a816e 79 page = page%8;
DimiterK 0:135b9a0a816e 80
DimiterK 0:135b9a0a816e 81 if(col<(SCREEN_WIDTH/2)){
DimiterK 0:135b9a0a816e 82 SelectSide(LEFT);
DimiterK 0:135b9a0a816e 83 WriteInstruction(LCD_SET_PAGE|page,LEFT);
DimiterK 0:135b9a0a816e 84 WriteInstruction(LCD_SET_ADD|col,LEFT); //set page and column position
DimiterK 0:135b9a0a816e 85 WriteData(data,LEFT); //output data to D0-D7
DimiterK 0:135b9a0a816e 86 }else{
DimiterK 0:135b9a0a816e 87
DimiterK 0:135b9a0a816e 88 SelectSide(RIGHT);
DimiterK 0:135b9a0a816e 89 col -= (SCREEN_WIDTH/2);
DimiterK 0:135b9a0a816e 90 WriteInstruction(LCD_SET_PAGE|page,RIGHT);
DimiterK 0:135b9a0a816e 91 WriteInstruction(LCD_SET_ADD|col,RIGHT); //set page and column position
DimiterK 0:135b9a0a816e 92 WriteData(data,RIGHT); //output data to D0-D7
DimiterK 0:135b9a0a816e 93 }
DimiterK 0:135b9a0a816e 94
DimiterK 0:135b9a0a816e 95 SelectSide(NONE);
DimiterK 0:135b9a0a816e 96 }
DimiterK 0:135b9a0a816e 97
DimiterK 0:135b9a0a816e 98 /*Read data from diplay
DimiterK 0:135b9a0a816e 99 *
DimiterK 0:135b9a0a816e 100 *@param none
DimiterK 0:135b9a0a816e 101 *@return data
DimiterK 0:135b9a0a816e 102 *
DimiterK 0:135b9a0a816e 103 */
DimiterK 0:135b9a0a816e 104 unsigned int KS0108::ReadData(){
DimiterK 0:135b9a0a816e 105 unsigned int data;
DimiterK 0:135b9a0a816e 106 DB.input();
DimiterK 0:135b9a0a816e 107 DI.write(1);
DimiterK 0:135b9a0a816e 108
DimiterK 0:135b9a0a816e 109 RW.write(1);
DimiterK 0:135b9a0a816e 110 E.write(1);
DimiterK 0:135b9a0a816e 111 wait(0.00000045);
DimiterK 0:135b9a0a816e 112
DimiterK 0:135b9a0a816e 113 data = DB.read();
DimiterK 0:135b9a0a816e 114 wait(0.0000001);
DimiterK 0:135b9a0a816e 115 E.write(0);
DimiterK 0:135b9a0a816e 116 DB.output();
DimiterK 0:135b9a0a816e 117
DimiterK 0:135b9a0a816e 118 return data;
DimiterK 0:135b9a0a816e 119 }
DimiterK 0:135b9a0a816e 120
DimiterK 0:135b9a0a816e 121 /*Read status of display , and check if it's busy
DimiterK 0:135b9a0a816e 122 *
DimiterK 0:135b9a0a816e 123 *@param none
DimiterK 0:135b9a0a816e 124 *@return status status of display
DimiterK 0:135b9a0a816e 125 *
DimiterK 0:135b9a0a816e 126 */
DimiterK 0:135b9a0a816e 127 unsigned int KS0108::ReadStatus(){
DimiterK 0:135b9a0a816e 128 unsigned int status;
DimiterK 0:135b9a0a816e 129 DB.input();
DimiterK 0:135b9a0a816e 130
DimiterK 0:135b9a0a816e 131 DI.write(0);
DimiterK 0:135b9a0a816e 132
DimiterK 0:135b9a0a816e 133 RW.write(1);
DimiterK 0:135b9a0a816e 134 E.write(1);
DimiterK 0:135b9a0a816e 135 wait(0.00000045);
DimiterK 0:135b9a0a816e 136
DimiterK 0:135b9a0a816e 137 status = DB.read();
DimiterK 0:135b9a0a816e 138 E.write(0);
DimiterK 0:135b9a0a816e 139 wait(0.0000001);
DimiterK 0:135b9a0a816e 140 DB.output();
DimiterK 0:135b9a0a816e 141
DimiterK 0:135b9a0a816e 142 return status;
DimiterK 0:135b9a0a816e 143 }
DimiterK 0:135b9a0a816e 144
DimiterK 0:135b9a0a816e 145 /*Read status of display
DimiterK 0:135b9a0a816e 146 *
DimiterK 0:135b9a0a816e 147 *@param side controller side can be LEFT or RIGHT
DimiterK 0:135b9a0a816e 148 *@return none
DimiterK 0:135b9a0a816e 149 *
DimiterK 0:135b9a0a816e 150 */
DimiterK 0:135b9a0a816e 151 void KS0108::SelectSide(unsigned char side){
DimiterK 0:135b9a0a816e 152 if(side==LEFT)
DimiterK 0:135b9a0a816e 153 {CS1.write(1);CS2.write(0);}
DimiterK 0:135b9a0a816e 154 else if(side==RIGHT)
DimiterK 0:135b9a0a816e 155 {CS1.write(0);CS2.write(1);}
DimiterK 0:135b9a0a816e 156 else if (side==BOTH)
DimiterK 0:135b9a0a816e 157 {CS1.write(1);CS2.write(1);}
DimiterK 0:135b9a0a816e 158 else if (side==NONE)
DimiterK 0:135b9a0a816e 159 {CS1.write(0);CS2.write(0);}
DimiterK 0:135b9a0a816e 160 }
DimiterK 0:135b9a0a816e 161
DimiterK 0:135b9a0a816e 162 /*Clears display
DimiterK 0:135b9a0a816e 163 *
DimiterK 0:135b9a0a816e 164 *@param none
DimiterK 0:135b9a0a816e 165 *@return none
DimiterK 0:135b9a0a816e 166 *
DimiterK 0:135b9a0a816e 167 */
DimiterK 0:135b9a0a816e 168 void KS0108::ClearScreen(){
DimiterK 0:135b9a0a816e 169 for (int col=0;col<128;col++) {
DimiterK 0:135b9a0a816e 170 for (int page=0;page<8;page++)
DimiterK 0:135b9a0a816e 171 {
DimiterK 0:135b9a0a816e 172 WriteDataColPag(page,col,WHITE);
DimiterK 0:135b9a0a816e 173 }
DimiterK 0:135b9a0a816e 174 }
DimiterK 0:135b9a0a816e 175 }
DimiterK 0:135b9a0a816e 176
DimiterK 0:135b9a0a816e 177
DimiterK 0:135b9a0a816e 178 /*******************************************************************************************/
DimiterK 0:135b9a0a816e 179
DimiterK 0:135b9a0a816e 180
DimiterK 0:135b9a0a816e 181 /*Set pixel to specific location on the screen.
DimiterK 0:135b9a0a816e 182 *@param x page varies from 0-128
DimiterK 0:135b9a0a816e 183 *@param y col varies from 0-64
DimiterK 0:135b9a0a816e 184 *@param color color of pixel, can be BLACK or WHITE
DimiterK 0:135b9a0a816e 185 *@return none
DimiterK 0:135b9a0a816e 186 *
DimiterK 0:135b9a0a816e 187 */
DimiterK 0:135b9a0a816e 188 void KS0108::SetPixel(unsigned int x, unsigned int y, unsigned int color){
DimiterK 0:135b9a0a816e 189
DimiterK 0:135b9a0a816e 190 unsigned int position;
DimiterK 0:135b9a0a816e 191
DimiterK 0:135b9a0a816e 192 SelectSide(NONE);
DimiterK 0:135b9a0a816e 193 WriteInstruction(LCD_SET_ADD,NONE);
DimiterK 0:135b9a0a816e 194
DimiterK 0:135b9a0a816e 195 if(x>=64){
DimiterK 0:135b9a0a816e 196 WriteInstruction(LCD_SET_PAGE|(y/8),RIGHT);
DimiterK 0:135b9a0a816e 197 WriteInstruction(LCD_SET_ADD|x,RIGHT);
DimiterK 0:135b9a0a816e 198 position = ReadData(); //dummy read
DimiterK 0:135b9a0a816e 199 position = ReadData(); //actual read
DimiterK 0:135b9a0a816e 200 WriteInstruction(LCD_SET_ADD|x,RIGHT);
DimiterK 0:135b9a0a816e 201 if(color==WHITE)
DimiterK 0:135b9a0a816e 202 WriteData(position&(~(1<<(y%8))),RIGHT); // draw a white pixel
DimiterK 0:135b9a0a816e 203 else
DimiterK 0:135b9a0a816e 204 WriteData(position|(1<<(y%8)),RIGHT);
DimiterK 0:135b9a0a816e 205 wait_us(450);
DimiterK 0:135b9a0a816e 206 }else{
DimiterK 0:135b9a0a816e 207 WriteInstruction(LCD_SET_PAGE|(y/8),LEFT);
DimiterK 0:135b9a0a816e 208 WriteInstruction(LCD_SET_ADD|x,LEFT);
DimiterK 0:135b9a0a816e 209 position = ReadData(); //dummy read
DimiterK 0:135b9a0a816e 210 position = ReadData(); //actual read
DimiterK 0:135b9a0a816e 211 WriteInstruction(LCD_SET_ADD|x,LEFT);
DimiterK 0:135b9a0a816e 212 if(color==WHITE)
DimiterK 0:135b9a0a816e 213 WriteData(position&(~(1<<(y%8))),LEFT);
DimiterK 0:135b9a0a816e 214 else
DimiterK 0:135b9a0a816e 215 WriteData(position|(1<<(y%8)),LEFT);
DimiterK 0:135b9a0a816e 216
DimiterK 0:135b9a0a816e 217 wait_us(450);
DimiterK 0:135b9a0a816e 218
DimiterK 0:135b9a0a816e 219 }
DimiterK 0:135b9a0a816e 220
DimiterK 0:135b9a0a816e 221 }
DimiterK 0:135b9a0a816e 222
DimiterK 0:135b9a0a816e 223
DimiterK 0:135b9a0a816e 224 /*Draw a filled reactangle
DimiterK 0:135b9a0a816e 225 *
DimiterK 0:135b9a0a816e 226 *@param Xaxis1
DimiterK 0:135b9a0a816e 227 *@param Yaxis1
DimiterK 0:135b9a0a816e 228 *@param Xaxis2
DimiterK 0:135b9a0a816e 229 *@param Yaxis2
DimiterK 0:135b9a0a816e 230 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 231 *@return none
DimiterK 0:135b9a0a816e 232 *
DimiterK 0:135b9a0a816e 233 */
DimiterK 0:135b9a0a816e 234 void KS0108::FullRectangle(unsigned int Xaxis1, unsigned int Yaxis1, unsigned int Xaxis2 ,unsigned int Yaxis2,unsigned int color){
DimiterK 0:135b9a0a816e 235
DimiterK 0:135b9a0a816e 236 for(unsigned int i=Xaxis1;i<=Xaxis2;i++){
DimiterK 0:135b9a0a816e 237 for(unsigned int j=Yaxis1;j<=Yaxis2;j++){
DimiterK 0:135b9a0a816e 238 SetPixel(i,j,color);
DimiterK 0:135b9a0a816e 239 }
DimiterK 0:135b9a0a816e 240 }
DimiterK 0:135b9a0a816e 241 }
DimiterK 0:135b9a0a816e 242
DimiterK 0:135b9a0a816e 243 /*Draw an empty rectangle
DimiterK 0:135b9a0a816e 244 *@param Xaxis1
DimiterK 0:135b9a0a816e 245 *@param Yaxis1
DimiterK 0:135b9a0a816e 246 *@param Xaxis2
DimiterK 0:135b9a0a816e 247 *@param Yaxis2
DimiterK 0:135b9a0a816e 248 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 249 *@return none
DimiterK 0:135b9a0a816e 250 *
DimiterK 0:135b9a0a816e 251 */
DimiterK 0:135b9a0a816e 252 void KS0108::EmptyRectangle(unsigned int Xaxis1,unsigned int Yaxis1, unsigned int Xaxis2,unsigned int Yaxis2,unsigned int color){
DimiterK 0:135b9a0a816e 253 unsigned int CurrentValue;
DimiterK 0:135b9a0a816e 254
DimiterK 0:135b9a0a816e 255 /* Draw the two horizontal lines */
DimiterK 0:135b9a0a816e 256 for (CurrentValue = 0; CurrentValue < Xaxis2 - Xaxis1+ 1; CurrentValue++)
DimiterK 0:135b9a0a816e 257 {
DimiterK 0:135b9a0a816e 258 SetPixel(Xaxis1 + CurrentValue, Yaxis1,color);
DimiterK 0:135b9a0a816e 259 SetPixel(Xaxis1 + CurrentValue, Yaxis2,color);
DimiterK 0:135b9a0a816e 260 }
DimiterK 0:135b9a0a816e 261
DimiterK 0:135b9a0a816e 262 /* draw the two vertical lines */
DimiterK 0:135b9a0a816e 263 for (CurrentValue = 0; CurrentValue < Yaxis2 - Yaxis1 + 1; CurrentValue++)
DimiterK 0:135b9a0a816e 264 {
DimiterK 0:135b9a0a816e 265 SetPixel(Xaxis1, Yaxis1 + CurrentValue,color);
DimiterK 0:135b9a0a816e 266 SetPixel(Xaxis2, Yaxis1 + CurrentValue,color);
DimiterK 0:135b9a0a816e 267 }
DimiterK 0:135b9a0a816e 268 }
DimiterK 0:135b9a0a816e 269
DimiterK 0:135b9a0a816e 270 /*Draw a rectangle with round corners
DimiterK 0:135b9a0a816e 271 *@param Xaxis1
DimiterK 0:135b9a0a816e 272 *@param Yaxis1
DimiterK 0:135b9a0a816e 273 *@param Xaxis2
DimiterK 0:135b9a0a816e 274 *@param Yaxis2
DimiterK 0:135b9a0a816e 275 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 276 *@return none
DimiterK 0:135b9a0a816e 277 *
DimiterK 0:135b9a0a816e 278 */
DimiterK 0:135b9a0a816e 279 void KS0108::RoundRectangle(unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int radius, unsigned int color) {
DimiterK 0:135b9a0a816e 280 int tSwitch, x1 = 0, y1 = radius;
DimiterK 0:135b9a0a816e 281 tSwitch = 3 - 2 * radius;
DimiterK 0:135b9a0a816e 282
DimiterK 0:135b9a0a816e 283 while (x1 <= y1) {
DimiterK 0:135b9a0a816e 284 SetPixel(x+radius - x1, y+radius - y1, color);
DimiterK 0:135b9a0a816e 285 SetPixel(x+radius - y1, y+radius - x1, color);
DimiterK 0:135b9a0a816e 286
DimiterK 0:135b9a0a816e 287 SetPixel(x+width-radius + x1, y+radius - y1, color);
DimiterK 0:135b9a0a816e 288 SetPixel(x+width-radius + y1, y+radius - x1, color);
DimiterK 0:135b9a0a816e 289
DimiterK 0:135b9a0a816e 290 SetPixel(x+width-radius + x1, y+height-radius + y1, color);
DimiterK 0:135b9a0a816e 291 SetPixel(x+width-radius + y1, y+height-radius + x1, color);
DimiterK 0:135b9a0a816e 292
DimiterK 0:135b9a0a816e 293 SetPixel(x+radius - x1, y+height-radius + y1, color);
DimiterK 0:135b9a0a816e 294 SetPixel(x+radius - y1, y+height-radius + x1, color);
DimiterK 0:135b9a0a816e 295
DimiterK 0:135b9a0a816e 296 if (tSwitch < 0) {
DimiterK 0:135b9a0a816e 297 tSwitch += (4 * x1 + 6);
DimiterK 0:135b9a0a816e 298 } else {
DimiterK 0:135b9a0a816e 299 tSwitch += (4 * (x1 - y1) + 10);
DimiterK 0:135b9a0a816e 300 y1--;
DimiterK 0:135b9a0a816e 301 }
DimiterK 0:135b9a0a816e 302 x1++;
DimiterK 0:135b9a0a816e 303 }
DimiterK 0:135b9a0a816e 304
DimiterK 0:135b9a0a816e 305 HLineShort(x+radius,y, width-(2*radius), color); // top
DimiterK 0:135b9a0a816e 306 HLineShort(x+radius,y+height, width-(2*radius), color); // bottom
DimiterK 0:135b9a0a816e 307 VLineShort(x,y+radius,height-(2*radius), color); // left
DimiterK 0:135b9a0a816e 308 VLineShort(x+width, y+radius,height-(2*radius), color); // right
DimiterK 0:135b9a0a816e 309 }
DimiterK 0:135b9a0a816e 310
DimiterK 0:135b9a0a816e 311 /*Draw a horizontal line
DimiterK 0:135b9a0a816e 312 *@param Xaxis1
DimiterK 0:135b9a0a816e 313 *@param Xaxis2
DimiterK 0:135b9a0a816e 314 *@param Yaxis
DimiterK 0:135b9a0a816e 315 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 316 *@return none
DimiterK 0:135b9a0a816e 317 *
DimiterK 0:135b9a0a816e 318 */
DimiterK 0:135b9a0a816e 319 void KS0108::HLine(unsigned int Xaxis1, unsigned int Xaxis2 ,unsigned int Yaxis,unsigned int color){
DimiterK 0:135b9a0a816e 320 FullRectangle(Xaxis1,Yaxis,Xaxis2,Yaxis,color);
DimiterK 0:135b9a0a816e 321
DimiterK 0:135b9a0a816e 322 }
DimiterK 0:135b9a0a816e 323
DimiterK 0:135b9a0a816e 324 /*Draw a horizontal line
DimiterK 0:135b9a0a816e 325 *@param Xaxis1
DimiterK 0:135b9a0a816e 326 *@param Xaxis2
DimiterK 0:135b9a0a816e 327 *@param Yaxis
DimiterK 0:135b9a0a816e 328 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 329 *@return none
DimiterK 0:135b9a0a816e 330 *
DimiterK 0:135b9a0a816e 331 */
DimiterK 0:135b9a0a816e 332 void KS0108::HLineShort(unsigned int Xaxis, unsigned int Yaxis,unsigned int width ,unsigned int color){
DimiterK 0:135b9a0a816e 333 FullRectangle(Xaxis,Yaxis,Xaxis+width,Yaxis,color);
DimiterK 0:135b9a0a816e 334
DimiterK 0:135b9a0a816e 335 }
DimiterK 0:135b9a0a816e 336
DimiterK 0:135b9a0a816e 337 /*Draw a horizontal line
DimiterK 0:135b9a0a816e 338 *@param Xaxis1
DimiterK 0:135b9a0a816e 339 *@param Xaxis2
DimiterK 0:135b9a0a816e 340 *@param Yaxis
DimiterK 0:135b9a0a816e 341 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 342 *@return none
DimiterK 0:135b9a0a816e 343 *
DimiterK 0:135b9a0a816e 344 */
DimiterK 0:135b9a0a816e 345 void KS0108::VLine(unsigned int Xaxis, unsigned int Yaxis1 ,unsigned int Yaxis2,unsigned int color){
DimiterK 0:135b9a0a816e 346 FullRectangle(Xaxis,Yaxis1,Xaxis,Yaxis2,color);
DimiterK 0:135b9a0a816e 347 }
DimiterK 0:135b9a0a816e 348
DimiterK 0:135b9a0a816e 349 /*Draw a horizontal line
DimiterK 0:135b9a0a816e 350 *@param Xaxis1
DimiterK 0:135b9a0a816e 351 *@param Xaxis2
DimiterK 0:135b9a0a816e 352 *@param Yaxis
DimiterK 0:135b9a0a816e 353 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 354 *@return none
DimiterK 0:135b9a0a816e 355 *
DimiterK 0:135b9a0a816e 356 */
DimiterK 0:135b9a0a816e 357 void KS0108::VLineShort(unsigned int Xaxis,unsigned int Yaxis, unsigned int height ,unsigned int color){
DimiterK 0:135b9a0a816e 358 FullRectangle(Xaxis,Yaxis,Xaxis,Yaxis+height,color);
DimiterK 0:135b9a0a816e 359
DimiterK 0:135b9a0a816e 360 }
DimiterK 0:135b9a0a816e 361
DimiterK 0:135b9a0a816e 362 /*
DimiterK 0:135b9a0a816e 363 *Draws a line from x,y at given degree from inner_radius to outer_radius.
DimiterK 0:135b9a0a816e 364 *@param Xaxis1
DimiterK 0:135b9a0a816e 365 *@param Xaxis2
DimiterK 0:135b9a0a816e 366 *@param Yaxis
DimiterK 0:135b9a0a816e 367 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 368 *@return none
DimiterK 0:135b9a0a816e 369 *
DimiterK 0:135b9a0a816e 370 */
DimiterK 0:135b9a0a816e 371 void KS0108::DegreeLine(unsigned int x, int y,unsigned int degree,unsigned int inner_radius,unsigned int outer_radius, unsigned int color){
DimiterK 0:135b9a0a816e 372 int fx,fy,tx,ty;
DimiterK 0:135b9a0a816e 373 fx = x + dfloor(inner_radius * sin(degree * 3.14 / 180));
DimiterK 0:135b9a0a816e 374 fy = y - dfloor(inner_radius * cos(degree * 3.14 / 180));
DimiterK 0:135b9a0a816e 375 tx = x + dfloor(outer_radius * sin(degree * 3.14 / 180));
DimiterK 0:135b9a0a816e 376 ty = y - dfloor(outer_radius * cos(degree * 3.14 / 180));
DimiterK 0:135b9a0a816e 377 SlantyLine(fx,fy,tx,ty,color);
DimiterK 0:135b9a0a816e 378 }
DimiterK 0:135b9a0a816e 379
DimiterK 0:135b9a0a816e 380 /*
DimiterK 0:135b9a0a816e 381 *Round a double
DimiterK 0:135b9a0a816e 382 *@param double
DimiterK 0:135b9a0a816e 383 *@return value
DimiterK 0:135b9a0a816e 384 *
DimiterK 0:135b9a0a816e 385 */
DimiterK 0:135b9a0a816e 386 double KS0108::dfloor( double value ) {
DimiterK 0:135b9a0a816e 387
DimiterK 0:135b9a0a816e 388 if (value < 0.0)
DimiterK 0:135b9a0a816e 389 return ceil( value );
DimiterK 0:135b9a0a816e 390 else
DimiterK 0:135b9a0a816e 391 return floor( value );
DimiterK 0:135b9a0a816e 392
DimiterK 0:135b9a0a816e 393 }
DimiterK 0:135b9a0a816e 394
DimiterK 0:135b9a0a816e 395 /*
DimiterK 0:135b9a0a816e 396 *Draws a line from x,y at given degree from inner_radius to outer_radius.
DimiterK 0:135b9a0a816e 397 *@param lX1 x coordinate of one side
DimiterK 0:135b9a0a816e 398 *@param lY1 y coordinate of one side
DimiterK 0:135b9a0a816e 399 *@param lX2 x coordinate of other side
DimiterK 0:135b9a0a816e 400 *@param lY2 y coordinate of other side
DimiterK 0:135b9a0a816e 401 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 402 *@return none
DimiterK 0:135b9a0a816e 403 *
DimiterK 0:135b9a0a816e 404 */
DimiterK 0:135b9a0a816e 405 void KS0108::SlantyLine(unsigned int lX1, unsigned int lY1, unsigned int lX2,unsigned int lY2,unsigned int color){
DimiterK 0:135b9a0a816e 406 long lError, lDeltaX, lDeltaY, lYStep, bSteep;
DimiterK 0:135b9a0a816e 407
DimiterK 0:135b9a0a816e 408 // A steep line has a bigger ordinate.
DimiterK 0:135b9a0a816e 409
DimiterK 0:135b9a0a816e 410 if(((lY2 > lY1) ? (lY2 - lY1) : (lY1 - lY2)) > ((lX2 > lX1) ? (lX2 - lX1) : (lX1 - lX2))){
DimiterK 0:135b9a0a816e 411 bSteep = 1;
DimiterK 0:135b9a0a816e 412 }else {
DimiterK 0:135b9a0a816e 413 bSteep = 0;
DimiterK 0:135b9a0a816e 414 }
DimiterK 0:135b9a0a816e 415
DimiterK 0:135b9a0a816e 416 // If line is steep, swap the X and Y coordinates.
DimiterK 0:135b9a0a816e 417 if(bSteep){
DimiterK 0:135b9a0a816e 418 lError = lX1;
DimiterK 0:135b9a0a816e 419 lX1 = lY1;
DimiterK 0:135b9a0a816e 420 lY1 = lError;
DimiterK 0:135b9a0a816e 421 lError = lX2;
DimiterK 0:135b9a0a816e 422 lX2 = lY2;
DimiterK 0:135b9a0a816e 423 lY2 = lError;
DimiterK 0:135b9a0a816e 424 }
DimiterK 0:135b9a0a816e 425
DimiterK 0:135b9a0a816e 426
DimiterK 0:135b9a0a816e 427 // If the starting X coordinate is larger than the ending X coordinate,
DimiterK 0:135b9a0a816e 428 // then swap the start and end coordinates.
DimiterK 0:135b9a0a816e 429 if(lX1 > lX2){
DimiterK 0:135b9a0a816e 430 lError = lX1;
DimiterK 0:135b9a0a816e 431 lX1 = lX2;
DimiterK 0:135b9a0a816e 432 lX2 = lError;
DimiterK 0:135b9a0a816e 433 lError = lY1;
DimiterK 0:135b9a0a816e 434 lY1 = lY2;
DimiterK 0:135b9a0a816e 435 lY2 = lError;
DimiterK 0:135b9a0a816e 436 }
DimiterK 0:135b9a0a816e 437
DimiterK 0:135b9a0a816e 438 // Compute the difference between the start and end coordinates in each axis.
DimiterK 0:135b9a0a816e 439 lDeltaX = lX2 - lX1;
DimiterK 0:135b9a0a816e 440 lDeltaY = (lY2 > lY1) ? (lY2 - lY1) : (lY1 - lY2);
DimiterK 0:135b9a0a816e 441
DimiterK 0:135b9a0a816e 442 lError = -lDeltaX / 2; // Initialize the error term to negative half the X delta.
DimiterK 0:135b9a0a816e 443
DimiterK 0:135b9a0a816e 444 if(lY1 < lY2){ // Determine the direction to step in the Y axis when required.
DimiterK 0:135b9a0a816e 445 lYStep = 1;
DimiterK 0:135b9a0a816e 446 }else{
DimiterK 0:135b9a0a816e 447 lYStep = -1;
DimiterK 0:135b9a0a816e 448 }
DimiterK 0:135b9a0a816e 449
DimiterK 0:135b9a0a816e 450 for(; lX1 <= lX2; lX1++){ // Loop through all the points along the X axis of the line.
DimiterK 0:135b9a0a816e 451
DimiterK 0:135b9a0a816e 452 // See if this is a steep line.
DimiterK 0:135b9a0a816e 453
DimiterK 0:135b9a0a816e 454 if(bSteep){
DimiterK 0:135b9a0a816e 455
DimiterK 0:135b9a0a816e 456 // Plot this point of the line, swapping the X and Y coordinates.
DimiterK 0:135b9a0a816e 457
DimiterK 0:135b9a0a816e 458 SetPixel(lY1, lX1,color);
DimiterK 0:135b9a0a816e 459 }
DimiterK 0:135b9a0a816e 460 else { // Plot this point of the line, using the coordinates as is.
DimiterK 0:135b9a0a816e 461 SetPixel(lX1, lY1,color);
DimiterK 0:135b9a0a816e 462 }
DimiterK 0:135b9a0a816e 463
DimiterK 0:135b9a0a816e 464 // Increment the error term by the Y delta.
DimiterK 0:135b9a0a816e 465
DimiterK 0:135b9a0a816e 466 lError += lDeltaY;
DimiterK 0:135b9a0a816e 467
DimiterK 0:135b9a0a816e 468 if(lError > 0){ // See if the error term is now greater than zero.
DimiterK 0:135b9a0a816e 469
DimiterK 0:135b9a0a816e 470 lY1 += lYStep; // Take a step in the Y axis.
DimiterK 0:135b9a0a816e 471
DimiterK 0:135b9a0a816e 472 lError -= lDeltaX; // Decrement the error term by the X delta.
DimiterK 0:135b9a0a816e 473 }
DimiterK 0:135b9a0a816e 474 }
DimiterK 0:135b9a0a816e 475 }
DimiterK 0:135b9a0a816e 476
DimiterK 0:135b9a0a816e 477
DimiterK 0:135b9a0a816e 478 /*
DimiterK 0:135b9a0a816e 479 *Draws a line from x1,y1 to x2,y2
DimiterK 0:135b9a0a816e 480 *@param lX1 x coordinate of one side
DimiterK 0:135b9a0a816e 481 *@param lY1 y coordinate of one side
DimiterK 0:135b9a0a816e 482 *@param lX2 x coordinate of other side
DimiterK 0:135b9a0a816e 483 *@param lY2 y coordinate of other side
DimiterK 0:135b9a0a816e 484 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 485 *@return none
DimiterK 0:135b9a0a816e 486 *
DimiterK 0:135b9a0a816e 487 */
DimiterK 0:135b9a0a816e 488 void KS0108::Line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int color){
DimiterK 0:135b9a0a816e 489 unsigned int deltax, deltay, x,y, steep;
DimiterK 0:135b9a0a816e 490 int lerror, ystep;
DimiterK 0:135b9a0a816e 491
DimiterK 0:135b9a0a816e 492 steep = absDiff(y1,y2) > absDiff(x1,x2); //check slope
DimiterK 0:135b9a0a816e 493
DimiterK 0:135b9a0a816e 494 if ( steep ){
DimiterK 0:135b9a0a816e 495 swap(x1, y1);
DimiterK 0:135b9a0a816e 496 swap(x2, y2);
DimiterK 0:135b9a0a816e 497 }
DimiterK 0:135b9a0a816e 498
DimiterK 0:135b9a0a816e 499 if (x1 > x2){
DimiterK 0:135b9a0a816e 500 swap(x1, x2);
DimiterK 0:135b9a0a816e 501 swap(y1, y2);
DimiterK 0:135b9a0a816e 502 }
DimiterK 0:135b9a0a816e 503
DimiterK 0:135b9a0a816e 504 deltax = x2 - x1;
DimiterK 0:135b9a0a816e 505 deltay = absDiff(y2,y1);
DimiterK 0:135b9a0a816e 506 lerror = deltax / 2;
DimiterK 0:135b9a0a816e 507 y = y1;
DimiterK 0:135b9a0a816e 508 if(y1 < y2) ystep = 1; else ystep = -1;
DimiterK 0:135b9a0a816e 509
DimiterK 0:135b9a0a816e 510 for(x = x1; x <= x2; x++){
DimiterK 0:135b9a0a816e 511 if (steep) SetPixel(y,x, color); else SetPixel(x,y, color);
DimiterK 0:135b9a0a816e 512 lerror -= deltay;
DimiterK 0:135b9a0a816e 513 if (lerror < 0){
DimiterK 0:135b9a0a816e 514 y = y + ystep;
DimiterK 0:135b9a0a816e 515 lerror += deltax;
DimiterK 0:135b9a0a816e 516 }
DimiterK 0:135b9a0a816e 517 }
DimiterK 0:135b9a0a816e 518 }
DimiterK 0:135b9a0a816e 519
DimiterK 0:135b9a0a816e 520 /*
DimiterK 0:135b9a0a816e 521 *Draws an empty circle centered a x,y with radius R and specific color.
DimiterK 0:135b9a0a816e 522 *@param lX1 x coordinate of one side
DimiterK 0:135b9a0a816e 523 *@param lY1 y coordinate of one side
DimiterK 0:135b9a0a816e 524 *@param lX2 x coordinate of other side
DimiterK 0:135b9a0a816e 525 *@param lY2 y coordinate of other side
DimiterK 0:135b9a0a816e 526 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 527 *@return none
DimiterK 0:135b9a0a816e 528 *
DimiterK 0:135b9a0a816e 529 */
DimiterK 0:135b9a0a816e 530 void KS0108::EmptyCircle(unsigned int CenterX, unsigned int CenterY, unsigned int Radius,unsigned int color){
DimiterK 0:135b9a0a816e 531 unsigned int y=0, x=0, d = 0;
DimiterK 0:135b9a0a816e 532 int part;
DimiterK 0:135b9a0a816e 533 d = CenterY - CenterX;
DimiterK 0:135b9a0a816e 534 y = Radius;
DimiterK 0:135b9a0a816e 535 part = 3 - 2 * Radius;
DimiterK 0:135b9a0a816e 536
DimiterK 0:135b9a0a816e 537 while (x <= y) {
DimiterK 0:135b9a0a816e 538 SetPixel(CenterX + x, CenterY + y,color);
DimiterK 0:135b9a0a816e 539 SetPixel(CenterX + x, CenterY - y,color);
DimiterK 0:135b9a0a816e 540 SetPixel(CenterX - x, CenterY + y,color);
DimiterK 0:135b9a0a816e 541 SetPixel(CenterX - x, CenterY - y,color);
DimiterK 0:135b9a0a816e 542 SetPixel(CenterY + y - d, CenterY + x,color);
DimiterK 0:135b9a0a816e 543 SetPixel(CenterY + y - d, CenterY - x,color);
DimiterK 0:135b9a0a816e 544 SetPixel(CenterY - y - d, CenterY + x,color);
DimiterK 0:135b9a0a816e 545 SetPixel(CenterY - y - d, CenterY - x,color);
DimiterK 0:135b9a0a816e 546
DimiterK 0:135b9a0a816e 547 if (part < 0) part += (4 * x + 6);
DimiterK 0:135b9a0a816e 548 else {
DimiterK 0:135b9a0a816e 549 part += (4 * (x - y) + 10);
DimiterK 0:135b9a0a816e 550 y--;
DimiterK 0:135b9a0a816e 551 }
DimiterK 0:135b9a0a816e 552 x++;
DimiterK 0:135b9a0a816e 553 }
DimiterK 0:135b9a0a816e 554
DimiterK 0:135b9a0a816e 555 }
DimiterK 0:135b9a0a816e 556
DimiterK 0:135b9a0a816e 557 /*
DimiterK 0:135b9a0a816e 558 * Circle fill Code is merely a modification of the midpoint
DimiterK 0:135b9a0a816e 559 * circle algorithem which is an adaption of Bresenham's line algorithm
DimiterK 0:135b9a0a816e 560 * http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
DimiterK 0:135b9a0a816e 561 * http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
DimiterK 0:135b9a0a816e 562 * Adapted from arduino lib
DimiterK 0:135b9a0a816e 563 *
DimiterK 0:135b9a0a816e 564 *@param CenterX
DimiterK 0:135b9a0a816e 565 *@param CenterY
DimiterK 0:135b9a0a816e 566 *@param Radius
DimiterK 0:135b9a0a816e 567 *@param color
DimiterK 0:135b9a0a816e 568 */
DimiterK 0:135b9a0a816e 569 void KS0108::FullCircle(unsigned int CenterX, unsigned int CenterY, unsigned int Radius,unsigned int color){
DimiterK 0:135b9a0a816e 570
DimiterK 0:135b9a0a816e 571 int f = 1 - Radius;
DimiterK 0:135b9a0a816e 572 int ddF_x = 1;
DimiterK 0:135b9a0a816e 573 int ddF_y = 2 * Radius; //changed sign of -2
DimiterK 0:135b9a0a816e 574 unsigned int x = 0;
DimiterK 0:135b9a0a816e 575 unsigned int y = Radius;
DimiterK 0:135b9a0a816e 576
DimiterK 0:135b9a0a816e 577 //Fill in the center between the two halves
DimiterK 0:135b9a0a816e 578
DimiterK 0:135b9a0a816e 579 Line(CenterX, CenterY-Radius, CenterX, CenterY+Radius, color);
DimiterK 0:135b9a0a816e 580
DimiterK 0:135b9a0a816e 581 while(x < y){
DimiterK 0:135b9a0a816e 582 if(f >= 0)
DimiterK 0:135b9a0a816e 583 {
DimiterK 0:135b9a0a816e 584 y--;
DimiterK 0:135b9a0a816e 585 ddF_y += 2;
DimiterK 0:135b9a0a816e 586 f += ddF_y;
DimiterK 0:135b9a0a816e 587 }
DimiterK 0:135b9a0a816e 588 x++;
DimiterK 0:135b9a0a816e 589 ddF_x += 2;
DimiterK 0:135b9a0a816e 590 f += ddF_x;
DimiterK 0:135b9a0a816e 591
DimiterK 0:135b9a0a816e 592 /*
DimiterK 0:135b9a0a816e 593 * Now draw vertical lines between the points on the circle rather than
DimiterK 0:135b9a0a816e 594 * draw the points of the circle. This draws lines between the
DimiterK 0:135b9a0a816e 595 * perimeter points on the upper and lower quadrants of the 2 halves of the circle.
DimiterK 0:135b9a0a816e 596 */
DimiterK 0:135b9a0a816e 597
DimiterK 0:135b9a0a816e 598 Line(CenterX+x, CenterY+y, CenterX+x, CenterY-y, color);
DimiterK 0:135b9a0a816e 599 Line(CenterX-x, CenterY+y, CenterX-x, CenterY-y, color);
DimiterK 0:135b9a0a816e 600 Line(CenterX+y, CenterY+x, y+CenterX, CenterY-x, color);
DimiterK 0:135b9a0a816e 601 Line(CenterX-y, CenterY+x, CenterX-y, CenterY-x, color);
DimiterK 0:135b9a0a816e 602 }
DimiterK 0:135b9a0a816e 603 }
DimiterK 0:135b9a0a816e 604
DimiterK 0:135b9a0a816e 605
DimiterK 0:135b9a0a816e 606 /*
DimiterK 0:135b9a0a816e 607 *Draws a line from x,y at given degree from inner_radius to outer_radius.
DimiterK 0:135b9a0a816e 608 *@param lX1 x coordinate of one side
DimiterK 0:135b9a0a816e 609 *@param lY1 y coordinate of one side
DimiterK 0:135b9a0a816e 610 *@param lX2 x coordinate of other side
DimiterK 0:135b9a0a816e 611 *@param lY2 y coordinate of other side
DimiterK 0:135b9a0a816e 612 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 613 *@return none
DimiterK 0:135b9a0a816e 614 *
DimiterK 0:135b9a0a816e 615 * Ported the algorithm found at http://homepage.smc.edu/kennedy_john/belipse.pdf
DimiterK 0:135b9a0a816e 616 *
DimiterK 0:135b9a0a816e 617 */
DimiterK 0:135b9a0a816e 618 void KS0108::PlotEllipse(long CX, long CY, long XRadius,long YRadius, int color) {
DimiterK 0:135b9a0a816e 619
DimiterK 0:135b9a0a816e 620
DimiterK 0:135b9a0a816e 621 long X, Y;
DimiterK 0:135b9a0a816e 622 long XChange, YChange;
DimiterK 0:135b9a0a816e 623 long EllipseError;
DimiterK 0:135b9a0a816e 624 long TwoASquare,TwoBSquare;
DimiterK 0:135b9a0a816e 625 long StoppingX, StoppingY;
DimiterK 0:135b9a0a816e 626 TwoASquare = 2*XRadius*XRadius;
DimiterK 0:135b9a0a816e 627 TwoBSquare = 2*YRadius*YRadius;
DimiterK 0:135b9a0a816e 628 X = XRadius;
DimiterK 0:135b9a0a816e 629 Y = 0;
DimiterK 0:135b9a0a816e 630 XChange = YRadius*YRadius*(1-2*XRadius);
DimiterK 0:135b9a0a816e 631 YChange = XRadius*XRadius;
DimiterK 0:135b9a0a816e 632 EllipseError = 0;
DimiterK 0:135b9a0a816e 633 StoppingX = TwoBSquare*XRadius;
DimiterK 0:135b9a0a816e 634 StoppingY = 0;
DimiterK 0:135b9a0a816e 635
DimiterK 0:135b9a0a816e 636 while ( StoppingX >=StoppingY ) //first set of points,y'>-1
DimiterK 0:135b9a0a816e 637 {
DimiterK 0:135b9a0a816e 638 Plot4EllipsePoints(CX,CY,X,Y,color);
DimiterK 0:135b9a0a816e 639 Y++;
DimiterK 0:135b9a0a816e 640 StoppingY=StoppingY+ TwoASquare;
DimiterK 0:135b9a0a816e 641 EllipseError = EllipseError+ YChange;
DimiterK 0:135b9a0a816e 642 YChange=YChange+TwoASquare;
DimiterK 0:135b9a0a816e 643 if ((2*EllipseError + XChange) > 0 ) {
DimiterK 0:135b9a0a816e 644 X--;
DimiterK 0:135b9a0a816e 645 StoppingX=StoppingX- TwoBSquare;
DimiterK 0:135b9a0a816e 646 EllipseError=EllipseError+ XChange;
DimiterK 0:135b9a0a816e 647 XChange=XChange+TwoBSquare;
DimiterK 0:135b9a0a816e 648 }
DimiterK 0:135b9a0a816e 649 }
DimiterK 0:135b9a0a816e 650
DimiterK 0:135b9a0a816e 651 Y = YRadius;
DimiterK 0:135b9a0a816e 652 X = 0;
DimiterK 0:135b9a0a816e 653 YChange = XRadius*XRadius*(1-2*YRadius);
DimiterK 0:135b9a0a816e 654 XChange = YRadius*YRadius;
DimiterK 0:135b9a0a816e 655 EllipseError = 0;
DimiterK 0:135b9a0a816e 656 StoppingY = TwoASquare*YRadius;
DimiterK 0:135b9a0a816e 657 StoppingX = 0;
DimiterK 0:135b9a0a816e 658
DimiterK 0:135b9a0a816e 659 while ( StoppingY >=StoppingX ) //{2nd set of points, y'< -1}
DimiterK 0:135b9a0a816e 660 {
DimiterK 0:135b9a0a816e 661 Plot4EllipsePoints(CX,CY,X,Y,color);
DimiterK 0:135b9a0a816e 662 X++;
DimiterK 0:135b9a0a816e 663 StoppingX=StoppingX + TwoBSquare;
DimiterK 0:135b9a0a816e 664 EllipseError=EllipseError+ XChange;
DimiterK 0:135b9a0a816e 665 XChange=XChange+TwoBSquare;
DimiterK 0:135b9a0a816e 666 if ((2*EllipseError + YChange) > 0 ) {
DimiterK 0:135b9a0a816e 667 Y--;
DimiterK 0:135b9a0a816e 668 StoppingY=StoppingY- TwoASquare;
DimiterK 0:135b9a0a816e 669 EllipseError=EllipseError+ YChange;
DimiterK 0:135b9a0a816e 670 YChange=YChange+TwoASquare;
DimiterK 0:135b9a0a816e 671 }
DimiterK 0:135b9a0a816e 672 }
DimiterK 0:135b9a0a816e 673 }
DimiterK 0:135b9a0a816e 674
DimiterK 0:135b9a0a816e 675
DimiterK 0:135b9a0a816e 676 /*
DimiterK 0:135b9a0a816e 677 *Helper function for drawing an ellipse.
DimiterK 0:135b9a0a816e 678 *@param CX x coordinate of one side
DimiterK 0:135b9a0a816e 679 *@param CY y coordinate of one side
DimiterK 0:135b9a0a816e 680 *@param X x coordinate of other side
DimiterK 0:135b9a0a816e 681 *@param Y y coordinate of other side
DimiterK 0:135b9a0a816e 682 *@param color can be BLACK or WHITE
DimiterK 0:135b9a0a816e 683 *@return none
DimiterK 0:135b9a0a816e 684 *
DimiterK 0:135b9a0a816e 685 * Portted the algorithm found at http://homepage.smc.edu/kennedy_john/belipse.pdf
DimiterK 0:135b9a0a816e 686 *
DimiterK 0:135b9a0a816e 687 */
DimiterK 0:135b9a0a816e 688 void KS0108::Plot4EllipsePoints(long CX,long CY, long X, long Y, int color){
DimiterK 0:135b9a0a816e 689 SetPixel(CX+X, CY+Y, color); //{point in quadrant 1}
DimiterK 0:135b9a0a816e 690 SetPixel(CX-X, CY+Y, color); //{point in quadrant 2}
DimiterK 0:135b9a0a816e 691 SetPixel(CX-X, CY-Y, color); //{point in quadrant 3}
DimiterK 0:135b9a0a816e 692 SetPixel(CX+X, CY-Y, color); //{point in quadrant 4}
DimiterK 0:135b9a0a816e 693 }
DimiterK 0:135b9a0a816e 694
DimiterK 0:135b9a0a816e 695 /***********************************************************************************/
DimiterK 0:135b9a0a816e 696
DimiterK 0:135b9a0a816e 697 /*
DimiterK 0:135b9a0a816e 698 *Draws an image on screen.
DimiterK 0:135b9a0a816e 699 *@param PictureData 128x64 image array
DimiterK 0:135b9a0a816e 700 *@return none
DimiterK 0:135b9a0a816e 701 *
DimiterK 0:135b9a0a816e 702 *
DimiterK 0:135b9a0a816e 703 */
DimiterK 0:135b9a0a816e 704 void KS0108::FullScreenBMP (unsigned char *PictureData){
DimiterK 0:135b9a0a816e 705 unsigned int Page=0;
DimiterK 0:135b9a0a816e 706 unsigned int Column=0;
DimiterK 0:135b9a0a816e 707
DimiterK 0:135b9a0a816e 708 // Draw left side of the picture
DimiterK 0:135b9a0a816e 709 SelectSide(LEFT);
DimiterK 0:135b9a0a816e 710 for (Page = 0; Page < 8; Page++){ /* loop on the 8 pages */
DimiterK 0:135b9a0a816e 711 WriteInstruction(LCD_SET_PAGE | Page,LEFT); /* Set the page */
DimiterK 0:135b9a0a816e 712 for (Column = 0; Column < 64; Column++)
DimiterK 0:135b9a0a816e 713 WriteData(PictureData[(128*Page)+Column],LEFT);
DimiterK 0:135b9a0a816e 714 }
DimiterK 0:135b9a0a816e 715
DimiterK 0:135b9a0a816e 716 // Draw right side of the picture
DimiterK 0:135b9a0a816e 717 SelectSide(RIGHT);
DimiterK 0:135b9a0a816e 718 for (Page = 0; Page < 8; Page++){ /* loop on the 8 pages */
DimiterK 0:135b9a0a816e 719
DimiterK 0:135b9a0a816e 720 WriteInstruction(LCD_SET_PAGE| Page,RIGHT); /* Set the page */
DimiterK 0:135b9a0a816e 721 for (Column = 64; Column < 128; Column++)
DimiterK 0:135b9a0a816e 722 WriteData(PictureData[(128*Page)+Column],RIGHT);
DimiterK 0:135b9a0a816e 723 }
DimiterK 0:135b9a0a816e 724 }
DimiterK 0:135b9a0a816e 725
DimiterK 0:135b9a0a816e 726
DimiterK 0:135b9a0a816e 727 /******************************************************************************************/
DimiterK 0:135b9a0a816e 728
DimiterK 0:135b9a0a816e 729 /*
DimiterK 0:135b9a0a816e 730 *Moves cursor to x,y.
DimiterK 0:135b9a0a816e 731 *@param x x coordinate
DimiterK 0:135b9a0a816e 732 *@param y y coordinate
DimiterK 0:135b9a0a816e 733 *@return none
DimiterK 0:135b9a0a816e 734 *
DimiterK 0:135b9a0a816e 735 */
DimiterK 0:135b9a0a816e 736 void KS0108::CursorXY(unsigned int x, unsigned int y){
DimiterK 0:135b9a0a816e 737 if( (x > SCREEN_WIDTH-1) || (y > SCREEN_HEIGHT-1) ) // exit if coordinates are not legal
DimiterK 0:135b9a0a816e 738 return;
DimiterK 0:135b9a0a816e 739
DimiterK 0:135b9a0a816e 740 if(y<(SCREEN_WIDTH/2)){
DimiterK 0:135b9a0a816e 741 SelectSide(LEFT);
DimiterK 0:135b9a0a816e 742 WriteInstruction(LCD_SET_PAGE|(y/8),RIGHT);
DimiterK 0:135b9a0a816e 743 WriteInstruction(LCD_SET_ADD|x,RIGHT);
DimiterK 0:135b9a0a816e 744 }else{
DimiterK 0:135b9a0a816e 745 SelectSide(RIGHT);
DimiterK 0:135b9a0a816e 746 WriteInstruction(LCD_SET_PAGE|(y/8),RIGHT);
DimiterK 0:135b9a0a816e 747 WriteInstruction(LCD_SET_ADD|x,RIGHT);
DimiterK 0:135b9a0a816e 748 }
DimiterK 0:135b9a0a816e 749 }
DimiterK 0:135b9a0a816e 750
DimiterK 0:135b9a0a816e 751 /*
DimiterK 0:135b9a0a816e 752 *Print a char on the specified coordinates
DimiterK 0:135b9a0a816e 753 *@param page row coordinate
DimiterK 0:135b9a0a816e 754 *@param col y coordinate
DimiterK 0:135b9a0a816e 755 *@param c character from systemfont
DimiterK 0:135b9a0a816e 756 *@return none
DimiterK 0:135b9a0a816e 757 *
DimiterK 0:135b9a0a816e 758 *
DimiterK 0:135b9a0a816e 759 */
DimiterK 0:135b9a0a816e 760 void KS0108::Putc (int page, int col,unsigned char c) {
DimiterK 0:135b9a0a816e 761 if (c>31 && c<127){
DimiterK 0:135b9a0a816e 762 for(int i=0;i<5;i++){
DimiterK 0:135b9a0a816e 763 WriteDataColPag(page,col+i,System5x7[((c-32)*5+i)+6]);
DimiterK 0:135b9a0a816e 764 }
DimiterK 0:135b9a0a816e 765 }
DimiterK 0:135b9a0a816e 766 }
DimiterK 0:135b9a0a816e 767
DimiterK 0:135b9a0a816e 768
DimiterK 0:135b9a0a816e 769 /*
DimiterK 0:135b9a0a816e 770 *Print a string on the specified coordinates.
DimiterK 0:135b9a0a816e 771 *@param x row coordinate
DimiterK 0:135b9a0a816e 772 *@param y y coordinate
DimiterK 0:135b9a0a816e 773 *@param str character string
DimiterK 0:135b9a0a816e 774 *@return none
DimiterK 0:135b9a0a816e 775 *
DimiterK 0:135b9a0a816e 776 *
DimiterK 0:135b9a0a816e 777 */
DimiterK 0:135b9a0a816e 778 void KS0108::PutString(unsigned int x, unsigned int y,char* str){
DimiterK 0:135b9a0a816e 779
DimiterK 0:135b9a0a816e 780 while(*str != 0){
DimiterK 0:135b9a0a816e 781 Putc(x,y,*str);
DimiterK 0:135b9a0a816e 782 str++;
DimiterK 0:135b9a0a816e 783 y+=System5x7[2];
DimiterK 0:135b9a0a816e 784 }
DimiterK 0:135b9a0a816e 785
DimiterK 0:135b9a0a816e 786 }
DimiterK 0:135b9a0a816e 787
DimiterK 0:135b9a0a816e 788
DimiterK 0:135b9a0a816e 789
DimiterK 0:135b9a0a816e 790 /*
DimiterK 0:135b9a0a816e 791 *Print a float on the specified coordiantes.
DimiterK 0:135b9a0a816e 792 *@param val float number
DimiterK 0:135b9a0a816e 793 *@param x row coordinate
DimiterK 0:135b9a0a816e 794 *@param y y coordinate
DimiterK 0:135b9a0a816e 795 *@return none
DimiterK 0:135b9a0a816e 796 *
DimiterK 0:135b9a0a816e 797 *
DimiterK 0:135b9a0a816e 798 */
DimiterK 0:135b9a0a816e 799 void KS0108::PrintFloat(float val, unsigned int x,unsigned int y){
DimiterK 0:135b9a0a816e 800 char buf[20] = {}; // prints up to 20 digits
DimiterK 0:135b9a0a816e 801 sprintf(buf,"%f",val);
DimiterK 0:135b9a0a816e 802 PutString(x,y,buf);
DimiterK 0:135b9a0a816e 803
DimiterK 0:135b9a0a816e 804 }
DimiterK 0:135b9a0a816e 805
DimiterK 0:135b9a0a816e 806 /*
DimiterK 0:135b9a0a816e 807 *Print an integer on th specified coordinates.
DimiterK 0:135b9a0a816e 808 *@param val integer number
DimiterK 0:135b9a0a816e 809 *@param x row coordinate
DimiterK 0:135b9a0a816e 810 *@param y column coordinate
DimiterK 0:135b9a0a816e 811 *@return none
DimiterK 0:135b9a0a816e 812 *
DimiterK 0:135b9a0a816e 813 */
DimiterK 0:135b9a0a816e 814 void KS0108::PrintInteger(int val,unsigned int x,unsigned int y){
DimiterK 0:135b9a0a816e 815 char buf[20] = {}; // prints up to 20 digits
DimiterK 0:135b9a0a816e 816 sprintf(buf,"%d",val);
DimiterK 0:135b9a0a816e 817 PutString(x,y,buf);
DimiterK 0:135b9a0a816e 818 }
DimiterK 0:135b9a0a816e 819
DimiterK 0:135b9a0a816e 820
DimiterK 0:135b9a0a816e 821
DimiterK 0:135b9a0a816e 822