glk12232.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 30.06.2004                                              *
00003  *   Matthias Kranz (matthias.kranz@ifi.lmu.de)                            *
00004  *   Paul Holleis (paul.holleis@ifi.lmu.de)                                *
00005  *                                                                         *
00006  *   header file for the display GLK122323-25-SM                           *
00007  *   Last modified: 21.10.2004                                             *
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  *   This program is distributed in the hope that it will be useful,       *
00015  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017  *   GNU General Public License for more details.                          *
00018  *                                                                         *
00019  *   You should have received a copy of the GNU General Public License     *
00020  *   along with this program; if not, write to the                         *
00021  *   Free Software Foundation, Inc.,                                       *
00022  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00023  **************************************************************************/
00024 #ifndef __STD
00025   #include <std.h>
00026 #endif
00027 
00028 #ifndef GLK_RX_PIN
00029 
00030   #define GLK_RX_PIN PIN_B2
00031 #endif 
00032 
00033 #ifndef GLK_TX_PIN
00034 
00035   #define GLK_TX_PIN PIN_B1
00036 #endif
00037 
00039 #define GLKSTREAM_SPEED 19200
00040 
00042 #use rs232(baud=GLKSTREAM_SPEED,xmit=GLK_RX_PIN,rcv=GLK_TX_PIN, STREAM=GLKSTREAM)
00043 
00045 #define GLK_STD_FONT_CHARS_PER_LINE 17
00046 
00047 /******************************************************************************
00048  * structures
00049  *****************************************************************************/
00051 struct metrics{
00052         int8 left_margin;
00053         int8 top_margin;
00054         int8 x_space;
00055         int8 y_space;
00056         int8 scroll_row;
00057 };
00058 
00059 /******************************************************************************
00060  * function signatures
00061  *****************************************************************************/
00062 // MISCELLANEOUS
00063 void clear_display();
00064 
00065 // LIGHTNING AND CONTRAST
00066 void set_contrast(int8 contrast);
00067 void set_default_contrast(int8 contrast);
00068 void set_backlight_on(int8 minutes);
00069 void set_backlight_off();
00070 
00071 // INFORMATION GATHERING
00072 int8 get_module_type();
00073 char* module_type_to_text(int8 type);
00074 void set_serial(int8 serialnumber1, int8 serialnumber2);
00075 int16 get_serial();
00076 int8 get_version();
00077 
00078 // SPEED & TRANSFER
00079 void set_rs232_portspeed(int8 speed);
00080 void enter_flowcontrol(int8 full_mark, int8 empty_mark);
00081 void exit_flowcontrol();
00082 
00083 // TEXT FUNCTIONS
00084 void set_autoscroll(int1 on);
00085 void set_textinsertionpoint(int8 row, int8 col);
00086 void set_textinsertionpoint_topleft();
00087 
00088 // FONT FUNCTIONS
00089 void set_currentfont(int8 fontid);
00090 void set_fontmetrics(struct metrics fontmetrics);
00091 
00092 // GRAPHICS FUNCTIONS
00093 void set_drawingcolor(int8 color);
00094 void draw_line(int8 x1, int8 y1, int8 x2, int8 y2);
00095 void continue_line(int8 x, int8 y);
00096 void draw_pixel(int8 x, int8 y);
00097 void draw_rectangle_outlined(int8 color, int8 x1, int8 y1, int8 x2, int8 y2);
00098 void draw_rectangle_filled(int8 color, int8 x1, int8 y1, int8 x2, int8 y2);
00099 
00100 // BARGRAPH FUNCTIONS
00101 void bargraph_init(int8 ref, int8 type, int8 x1, int8 y1, int8 x2, int8 y2);
00102 void bargraph_write(int8 ref, int8 value);
00103 
00104 // BITMAP FUNCTIONS
00105 void display_bitmap(int8 ref, int8 x, int8 y);
00106 
00107 // FILE SYSTEM AND MEMORY FUNCTIONS
00108 void erase_file(int8 type, int8 ref);
00109 void purge_memory();
00110 void upload_bitmap(int8 ref, int16 size, char* data_ptr);
00111 void upload_font(int8 ref, int16 size, char *data_ptr);
00112 
00113 /******************************************************************************
00114  * Code
00115  *****************************************************************************/
00116 
00120 void clear_display()
00121 {
00122   fprintf(GLKSTREAM, "%c%c", 254, 88);
00123 }
00124 
00129 void set_contrast(int8 contrast)
00130 {
00131   fprintf(GLKSTREAM, "%c%c%c", 254, 80, contrast);
00132 }
00133 
00138 void set_default_contrast(int8 contrast)
00139 {
00140   fprintf(GLKSTREAM, "%c%c%c", 254, 91, contrast);
00141 }
00142 
00147 void set_backlight_on(int8 minutes)
00148 {
00149   fprintf(GLKSTREAM, "%c%c%c", 254, 66, minutes);
00150 }
00151 
00155 void set_backlight_off()
00156 {
00157   fprintf(GLKSTREAM, "%c%c", 254, 70);
00158 }
00159 
00164 int8 get_module_type()
00165 {
00166   int8 modtype;
00167   modtype = 0;
00168   
00169   fprintf(GLKSTREAM, "%c%c", 254, 55);
00170   if (kbhit())
00171   {
00172     modtype = getc();
00173   }
00174 
00175   return modtype;
00176 }
00177 
00185 void set_rs232_portspeed(int8 speed)
00186 {
00187         int8 recognized_speed = 0x0F;
00188         switch(speed) {
00189                 // 9600 baud
00190                 case 0x20: recognized_speed = 0x20; break; 
00191                 // 19200 baud
00192                 case 0x0f: recognized_speed = 0x0f; break;
00193                 // 57600 baud
00194                 case 0x95: recognized_speed = 0x95; break;
00195                 // 76800 baud
00196                 case 0x03: recognized_speed = 0x03; break;
00197                 // 115200 baud ?
00198                 case 0x8A: recognized_speed = 0x8A; break;
00199                 default: 
00200                 {
00201                         // failsafe default
00202                         recognized_speed = 0x0f;
00203                 }       
00204         }
00205         // sets the new speed
00206         fprintf(GLKSTREAM, "%c%c%c", 254, 57, recognized_speed);
00207         // defines the new stream
00208 
00209         switch(recognized_speed) {
00210                 // 9600 baud
00211                 case 0x20:
00212                 {
00213                   #use rs232(baud=9600,xmit=GLK_RX_PIN,rcv=GLK_TX_PIN, STREAM=GLKSTREAM)                        
00214                         break;  
00215                 }
00216                 // 19200 baud
00217                 case 0x0f: 
00218                 {
00219                   #use rs232(baud=19200,xmit=GLK_RX_PIN,rcv=GLK_TX_PIN, STREAM=GLKSTREAM)                       
00220                         break;  
00221                 }
00222                 // 57600 baud
00223                 case 0x95: 
00224                 {
00225                   #use rs232(baud=57600,xmit=GLK_RX_PIN,rcv=GLK_TX_PIN, STREAM=GLKSTREAM)                       
00226                         break;  
00227                 }
00228                 // 76800 baud
00229                 case 0x03:
00230                 {
00231                   #use rs232(baud=76800,xmit=GLK_RX_PIN,rcv=GLK_TX_PIN, STREAM=GLKSTREAM)                       
00232                         break;  
00233                 }
00234                 // 115200 baud ?
00235                 case 0x8A:
00236                 {
00237                   #use rs232(baud=115200,xmit=GLK_RX_PIN,rcv=GLK_TX_PIN, STREAM=GLKSTREAM)                      
00238                         break;  
00239                 }
00240                 default: 
00241                 {
00242                   #use rs232(baud=19200,xmit=GLK_RX_PIN,rcv=GLK_TX_PIN, STREAM=GLKSTREAM)                       
00243                 }       
00244         }       
00245 }
00246 
00254 void enter_flowcontrol(int8 full_mark, int8 empty_mark)
00255 {
00256   fprintf(GLKSTREAM, "%c%c", full_mark, empty_mark);
00257 }
00258 
00262 void exit_flowcontrol()
00263 {
00264   fprintf(GLKSTREAM, "%c%c", 254, 59);
00265 }
00266 
00274 void set_serial(int8 serialnumber1, int8 serialnumber2)
00275 {
00276   fprintf(GLKSTREAM, "%c%c%c%c", 254, 34, serialnumber1, serialnumber2);
00277 }
00278 
00287 int16 get_serial()
00288 {
00289         int8 serialnumber1; 
00290         int8 serialnumber2; 
00291         int16 serialnumber;
00292         serialnumber1 = 0;
00293         serialnumber2 = 0;
00294         serialnumber = 0;
00295   fprintf(GLKSTREAM, "%c%c", 254, 70);
00296   if (kbhit())
00297   {
00298     serialnumber1 = getc();
00299   }
00300   if (kbhit())
00301   {
00302     serialnumber2 = getc();
00303   }
00304         serialnumber = ( (serialnumber || serialnumber1) << 8) || serialnumber2;
00305         return serialnumber;
00306 }
00307 
00312 int8 get_version()
00313 {
00314   int8 version;
00315   version = 0;
00316   
00317   fprintf(GLKSTREAM, "%c%c", 254, 54);
00318   if (kbhit())
00319   {
00320     version = getc();
00321   }
00322 
00323   return version;
00324 }
00325 
00332 void set_autoscroll(int1 on)
00333 {
00334         if (on == 1) 
00335         {
00336                 fprintf(GLKSTREAM, "%c%c", 254, 81);
00337         }
00338         else if (on == 0)
00339         {
00340                 fprintf(GLKSTREAM, "%c%c", 254, 82);
00341         }
00342         else
00343         {
00344                 fprintf(GLKSTREAM, "%c%c", 254, 81);
00345         }       
00346 }
00347 
00353 void set_textinsertionpoint(int8 row, int8 col)
00354 {
00355   fprintf(GLKSTREAM, "%c%c%c%c", 254, 71, row, col);    
00356 }
00357 
00361 void set_textinsertionpoint_topleft()
00362 {
00363         fprintf(GLKSTREAM, "%c%c", 254, 72);    
00364 }
00365 
00372 void set_currentfont(int8 fontid)
00373 {
00374         fprintf(GLKSTREAM, "%c%c%c", 254, 49, fontid);  
00375 }       
00376         
00381 void set_fontmetrics(struct metrics fontmetrics)
00382 {
00383         /*
00384         struct metrics{
00385         int8 left_margin;
00386         int8 top_margin;
00387         int8 x_space;
00388         int8 y_space;
00389         int8 scroll_row;
00390         };
00391         */
00392         fprintf(GLKSTREAM, "%c%c%c%c%c%c%c", 254, 50,
00393          fontmetrics.left_margin,
00394          fontmetrics.top_margin,
00395          fontmetrics.x_space,
00396          fontmetrics.y_space,
00397          fontmetrics.scroll_row);
00398 }       
00399 
00404 void set_drawingcolor(int8 color)
00405 {
00406         fprintf(GLKSTREAM, "%c%c%c", 254, 99, color);           
00407 }
00408 
00417 void draw_line(int8 x1, int8 y1, int8 x2, int8 y2)
00418 {
00419         fprintf(GLKSTREAM, "%c%c%c%c%c%c", 254, 108, x1,y1,x2,y2);              
00420 }
00421 
00428 void continue_line(int8 x, int8 y)
00429 {
00430         fprintf(GLKSTREAM, "%c%c%c%c", 254, 108, x,y);          
00431 }
00432 
00439 void draw_pixel(int8 x, int8 y)
00440 {
00441         fprintf(GLKSTREAM, "%c%c%c%c", 254, 112, x,y);          
00442 }
00443 
00454 void draw_rectangle_outlined(int8 color, int8 x1, int8 y1, int8 x2, int8 y2)
00455 {
00456         fprintf(GLKSTREAM, "%c%c%c%c%c%c%c", 254, 114, color, x1,y1,x2,y2);             
00457 }
00458 
00469 void draw_rectangle_filled(int8 color, int8 x1, int8 y1, int8 x2, int8 y2)
00470 {
00471         fprintf(GLKSTREAM, "%c%c%c%c%c%c%c", 254, 120, color, x1,y1,x2,y2);             
00472 }
00473 
00486 void bargraph_init(int8 ref, int8 type, int8 x1, int8 y1, int8 x2, int8 y2)
00487 {
00488         fprintf(GLKSTREAM, "%c%c%c%c%c%c%c%c", 254, 103, ref, type, x1, y1, x2, y2);            
00489 }
00490 
00497 void bargraph_write(int8 ref, int8 value)
00498 {
00499         fprintf(GLKSTREAM, "%c%c%c%c", 254, 105, ref, value);           
00500 }
00501 
00509 void display_bitmap(int8 ref, int8 x, int8 y)
00510 {
00511         fprintf(GLKSTREAM, "%c%c%c%c%c", 254, 98, ref, x,y);            
00512 }
00513 
00519 void erase_file(int8 type, int8 ref)
00520 {
00521         fprintf(GLKSTREAM, "%c%c%c%c", 254, 45, type, ref);             
00522 }
00523 
00529 void purge_memory()
00530 {
00531         fprintf(GLKSTREAM, "%c%c%c%c", 254, 33, 89, 33);                
00532 }
00533 
00544 void upload_bitmap(int8 ref, int16 size, char* data_ptr)
00545 {
00546         int16 lower_byte, higher_byte;
00547         int16 bitmask1, bitmask2; //fontfilesize
00548 
00549   // bitmask for clearing the high byte 
00550   bitmask1 = 0x00FF;
00551   bitmask2 = 0xFF00;
00552   lower_byte = (size & bitmask1);
00553   higher_byte = (size & bitmask2);
00554         
00555   set_currentfont(1);
00556         
00557         fprintf(GLKSTREAM, "%c%c%c", 254,94,ref);
00558         // read confirmation byte for reference
00559   ref = fgetc(GLKSTREAM); 
00560   // send confirmation byte for correct received reference
00561   fprintf(GLKSTREAM, "%c", 0x01); 
00562         // send low size in16 (lower byte of file size)
00563   fprintf(GLKSTREAM, "%c", lower_byte);// 27 im testbeispiel
00564         // read confirmation byte for lower byte size
00565   ref = fgetc(GLKSTREAM); 
00566   // send confirmation byte for correct received lower byte size
00567   fprintf(GLKSTREAM, "%c", 0x01); 
00568         // send high size int16 ( higher byte of file size)
00569   fprintf(GLKSTREAM, "%c", higher_byte); // 0x00 im testbeispiel
00570         // read confirmation byte for higher byte size
00571   ref = fgetc(GLKSTREAM); 
00572         
00573         // read confirmation byte for "file fits into memory"
00574         ref = fgetc(GLKSTREAM); 
00575   // if file fits, ref = 0x01, else ref = 0x08
00576 
00577         for (lower_byte=0; lower_byte < size; lower_byte++) 
00578         {
00579                 // transmit one byte
00580                 fprintf(GLKSTREAM, "%c", data_ptr[lower_byte]);
00581                 // confirm correct transmission of one sent byte
00582                 ref = fgetc(GLKSTREAM); 
00583                 // confirm confirmation
00584                 fprintf(GLKSTREAM, "%c", 0x01);
00585         }
00586         
00587 }
00588 
00600 void upload_font(int8 ref, int16 size, char *data_ptr)
00601 {
00602         int16 lower_byte, higher_byte;
00603         int16 bitmask1, bitmask2; //fontfilesize
00604 
00605   // bitmask for clearing the high byte 
00606   bitmask1 = 0x00FF;
00607   bitmask2 = 0xFF00;
00608   lower_byte = (size & bitmask1);
00609   higher_byte = (size & bitmask2);
00610         
00611   set_currentfont(1);
00612         
00613         fprintf(GLKSTREAM, "%c%c%c", 254,36,ref);
00614         // read confirmation byte for reference
00615   ref = fgetc(GLKSTREAM); 
00616   // send confirmation byte for correct received reference
00617   fprintf(GLKSTREAM, "%c", 0x01); 
00618         // send low size in16 (lower byte of file size)
00619   fprintf(GLKSTREAM, "%c", lower_byte);// 27 im testbeispiel
00620         // read confirmation byte for lower byte size
00621   ref = fgetc(GLKSTREAM); 
00622   // send confirmation byte for correct received lower byte size
00623   fprintf(GLKSTREAM, "%c", 0x01); 
00624         // send high size int16 ( higher byte of file size)
00625   fprintf(GLKSTREAM, "%c", higher_byte); // 0x00 im testbeispiel
00626         // read confirmation byte for higher byte size
00627   ref = fgetc(GLKSTREAM); 
00628         
00629         // read confirmation byte for "file fits into memory"
00630         ref = fgetc(GLKSTREAM); 
00631   // if file fits, ref = 0x01, else ref = 0x08
00632 
00633         for (lower_byte=0; lower_byte < size; lower_byte++) 
00634         {
00635                 // transmit one byte
00636                 fprintf(GLKSTREAM, "%c", data_ptr[lower_byte]);
00637                 // confirm correct transmission of one sent byte
00638                 ref = fgetc(GLKSTREAM); 
00639                 // confirm confirmation
00640                 fprintf(GLKSTREAM, "%c", 0x01);
00641         }
00642         
00643 }
00644 
00649 char* module_type_to_text(int8 type)
00650 {
00651         char module_name[];
00652         char unknown[] = "unknown";
00653         char *names[28];
00654         char name1[] = "LCD0821";
00655         char name2[] = "LCD2021";
00656         char name3[] = "LCD1641";
00657         char name4[] = "LCD2041";
00658         char name5[] = "LCD4021";
00659         char name6[] = "LCD4041";
00660         char name7[] = "LK202-25";
00661         char name8[] = "LK204-25";
00662         char name9[] = "LK404-55";
00663         char name10[] = "VFD2021";
00664         char name11[] = "VFD2041";
00665         char name12[] = "VFD4021";
00666         char name13[] = "VK202-25";
00667         char name14[] = "VK204-25";
00668         char name15[] = "GLC12232";
00669         char name16[] = "GLC12864";
00670         char name17[] = "GLC128128";
00671         char name18[] = "GLC24064";
00672         char name19[] = "GLK12864-25";
00673         char name20[] = "GLK24064-25";
00674         char name21[] = "GLK128128-25";
00675         char name22[] = "GLK12232-25";
00676         char name23[] = "LK404-AT";
00677         char name24[] = "VFD1621";
00678         char name25[] = "LK402-12";
00679         char name26[] = "LK162-12";
00680         char name27[] = "LK204-25PC";
00681         char name28[] = "GLK12232-25-SM";
00682 
00683         names[0] = name1;
00684         names[1] = name2;
00685         names[2] = name3;
00686         names[3] = name4;
00687         names[4] = name5;
00688         names[5] = name6;
00689         names[6] = name7;
00690         names[7] = name8;
00691         names[8] = name9;
00692         names[9] = name10;
00693         names[10] = name11;
00694         names[11] = name12;
00695         names[12] = name13;
00696         names[13] = name14;
00697         names[14] = name15;
00698         names[15] = name16;
00699         names[16] = name17;
00700         names[17] = name18;
00701         names[18] = name19;                                                                                                                             
00702         names[19] = name20;
00703         names[20] = name21;
00704         names[21] = name22;
00705         names[22] = name23;
00706         names[23] = name24;
00707         names[24] = name25;
00708         names[25] = name26;
00709         names[26] = name27;
00710         names[27] = name28;
00711 
00712 
00713         switch (type)
00714         {
00715                 case 0x01:{                             module_name = name1;            }
00716                 case 0x03:{                             module_name = name2;            }
00717                 case 0x04:{                     module_name = name3;            }
00718                 case 0x05:{                             module_name = name4;            }
00719                 case 0x06:{                     module_name = name5;            }
00720                 case 0x07:{                     module_name = name6;            }
00721                 case 0x08:{                     module_name = name7;            }
00722                 case 0x09:{                             module_name = name8;    }
00723                 case 0x0A:{                             module_name = name9;            }
00724                 case 0x0B:{                             module_name = name10;           }
00725                 case 0x0C:{                             module_name = name11;           }
00726                 case 0x0D:{                             module_name = name12;           }
00727                 case 0x0E:{                     module_name = name13;           }
00728                 case 0x0F:{                     module_name = name14;           }
00729                 case 0x10:{                             module_name = name15;           }
00730                 case 0x11:{                             module_name = name16;           }
00731                 case 0x12:{                     module_name = name17;           }
00732                 case 0x13:{                             module_name = name18;           }
00733                 case 0x14:{                             module_name = name19;           }
00734                 case 0x15:{                             module_name = name20;           }
00735                 case 0x21:{                             module_name = name21;           }
00736                 case 0x22:{                             module_name = name22;           }
00737                 case 0x31:{                             module_name = name23;           }
00738                 case 0x32:{                             module_name = name24;           }
00739                 case 0x33:{                             module_name = name25;           }
00740                 case 0x34:{                             module_name = name26;           }
00741                 case 0x35:{                             module_name = name27;           }
00742         case 0x24:{                             module_name = name28;           }
00743                 default:
00744                 {
00745                         module_name = unknown;
00746                 }
00747         }
00748         return(module_name);
00749 }
00750 

Generated on Tue Nov 30 09:16:48 2004 for Smart-Its Headers by  doxygen 1.3.9.1