Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* 00002 main.c 00003 Main demo file. Using conio functions to display demo userinterface. 00004 Part of MicroVGA CONIO library / demo project 00005 Copyright (c) 2008-9 SECONS s.r.o., http://www.MicroVGA.com 00006 00007 This program is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include "conio.h" 00022 #include "kbd.h" 00023 #include "ui.h" 00024 00025 #ifdef AVR_MCU //WinAvr - AVR MCU - has to be defined in project settings 00026 #define LOWMEM 1 00027 #endif 00028 00029 #ifdef __ICC78K__ 00030 #define LOWMEM 1 00031 #endif 00032 00033 #if RENESAS_C //Renessa High performance Emb. Workshop- has to be defined in project settings 00034 #define LOWMEM 1 00035 #endif 00036 00037 #ifndef LOWMEM 00038 #include "aa.c" //ascii art 00039 #endif 00040 00041 extern void MCU_Init(void); 00042 00043 00044 /*const static char *nc_fkeys[10] = 00045 {"Help","Menu","View","Edit","Copy","RenMov","Mkdir","Delete","Setup","Quit"}; 00046 */ 00047 00048 ROMDEF static char *memview_fkeys[10] = 00049 {"Help",0,0,0,"DynMem",0,0,0,0,"Quit"}; 00050 00051 ROMDEF static char *mainmenu[] = 00052 { 00053 "Memory viewer", 00054 "Console debug demo", 00055 "Speed test", 00056 "Test sub menu", 00057 "Command line interface", 00058 "ASCII-Art test", 00059 "Input dialog test", 00060 0 00061 }; 00062 00063 ROMDEF static char *submenu1[] = 00064 //far const rom char *submenu1[] = 00065 { 00066 "Menu item number 1", 00067 "Menu item number 2", 00068 "Some other menu", 00069 "And finally last menu item", 00070 0 00071 }; 00072 00073 const static char hexchars[] = "0123456789ABCDEF"; 00074 00075 void drawmem(const unsigned char *mem) 00076 { 00077 const unsigned char *mptr; 00078 int i,j; 00079 00080 00081 textbackground(BLUE); 00082 for (i=0;i<23 && !_kbhit();i++) { 00083 mptr = &mem[i*16]; 00084 gotoxy(1,i+2); 00085 textcolor(YELLOW); 00086 j = 8; 00087 do { 00088 j--; 00089 _putch(hexchars[ (((int)mptr)>>(j*4)) &0xF] ); 00090 } while (j>0); 00091 _cputs(": "); 00092 textcolor(WHITE); 00093 00094 for (j=0;j<16;j++) { 00095 _putch(hexchars[*mptr>>4]); 00096 _putch(hexchars[*mptr&0xF]); 00097 mptr++; 00098 _putch(' '); 00099 if (j == 7) { 00100 _putch('-'); 00101 _putch(' '); 00102 } 00103 } 00104 00105 _putch(179); 00106 _putch(' '); 00107 00108 mptr = &mem[i*16]; 00109 for (j=0;j<16;j++) { 00110 if (*mptr >= ' ') 00111 _putch(*mptr); 00112 else _putch('.'); 00113 mptr++; 00114 } 00115 00116 clreol(); 00117 } 00118 } 00119 00120 00121 void memviewer(void *start) 00122 { 00123 #ifndef LOWMEM 00124 int key; 00125 const unsigned char *mem; 00126 00127 textattr(LIGHTGRAY | BLUE <<4); 00128 clrscr(); 00129 textcolor(BLACK); 00130 textbackground(CYAN); 00131 _cputs("Memory viewer"); 00132 clreol(); 00133 00134 cursoroff(); 00135 drawfkeys(memview_fkeys); 00136 00137 mem=(const unsigned char *)start; 00138 for (;;) { 00139 drawmem(mem); 00140 00141 if (_kbhit()) { 00142 key = _getch(); 00143 switch(key) { 00144 case KB_LEFT: if ((int)mem > 0 ) (int)mem--; break; 00145 case KB_RIGHT: mem++; break; 00146 case KB_UP: if (mem >= (unsigned char const *)16) mem-=16; break; 00147 case KB_DOWN: mem+=16; break; 00148 case KB_PGUP: if (mem >= (unsigned char const *)(16*23)) mem-=16*23; break; 00149 case KB_PGDN: mem+=16*23; break; 00150 case KB_F10: cursoron(); return ; 00151 } 00152 } 00153 00154 } 00155 #else 00156 textattr(LIGHTGRAY); 00157 clrscr(); 00158 _cputs("Not enought memory for this feature"); 00159 00160 while (_getch() != KB_ESC); 00161 #endif 00162 } 00163 00164 void debugdemo() 00165 { 00166 int key; 00167 00168 textattr(LIGHTGRAY); 00169 clrscr(); 00170 00171 while (1) { 00172 _cputs("Debug line 1\r\n"); 00173 if (_kbhit()) { 00174 key = _getch(); 00175 _cputs("You have pressed key"); 00176 _putch(key); 00177 _cputs("\r\n"); 00178 if (key == KB_ESC) 00179 return ; 00180 } 00181 } 00182 } 00183 00184 00185 void cli() 00186 { 00187 char buffer[40]; 00188 char * out; 00189 00190 textattr(LIGHTGRAY); 00191 00192 clrscr(); 00193 00194 while (1) { 00195 //read data 00196 buffer[0]=40; 00197 00198 textattr(YELLOW); 00199 _cputs("uVGA> "); 00200 textattr(LIGHTGRAY); 00201 out=_cgets(buffer); 00202 00203 if (out != 0 && out[0] == 'q' && out[1] == 0) 00204 return ; 00205 00206 textattr(WHITE); 00207 _cputs("\r\nUnsupported command. Only "); 00208 textattr(LIGHTRED); 00209 _cputs("q"); 00210 textattr(WHITE); 00211 _cputs(" (exit) is supported.\r\n"); 00212 } 00213 } 00214 00215 00216 void speedtest(void) 00217 { 00218 unsigned int i; 00219 00220 gotoxy(1,1); 00221 textattr(GREEN<<4 | YELLOW); 00222 00223 for (i=0;i<50000;i++) { 00224 _cputs("TEST50=>"); 00225 _putch(((i/10000)%10) + '0'); 00226 _putch(((i/1000)%10) + '0'); 00227 _cputs("\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08"); 00228 } 00229 } 00230 00231 00232 void submenutest() 00233 { 00234 int item; 00235 00236 item = 0; 00237 00238 while (1) { 00239 00240 item = runmenu(8,10, submenu1, item); 00241 switch (item) { 00242 case 0: return ; 00243 } 00244 } 00245 } 00246 00247 00248 void ascii_art() 00249 { 00250 #ifndef LOWMEM 00251 textattr(LIGHTGRAY); 00252 clrscr(); 00253 00254 // _cputs((const char *)ascii_art_str); 00255 00256 while (_getch() != KB_ESC); 00257 #else 00258 textattr(LIGHTGRAY); 00259 clrscr(); 00260 _cputs("Not enought memory for this feature"); 00261 00262 while (_getch() != KB_ESC); 00263 #endif 00264 } 00265 00266 void testCGetS() 00267 { 00268 char buffer[40]; 00269 char * out; 00270 int i; 00271 00272 //draw input dialog (frame) 00273 drawframe(10, 10, 40, 9, WHITE | RED <<4); 00274 gotoxy(12,12); 00275 _cputs("Enter your name:"); 00276 gotoxy(12,14); 00277 textattr(WHITE | BLACK <<4); 00278 for (i=0;i<40;i++) 00279 _putch(' '); 00280 00281 //read data 00282 gotoxy(12,14); 00283 buffer[0]=40; 00284 00285 out=_cgets(buffer); 00286 00287 //write read data 00288 gotoxy(12,16); 00289 if (buffer[1]==0) 00290 { 00291 textattr((WHITE | RED <<4)|BLINK); 00292 _cputs("You didn't enter your name!"); 00293 } 00294 else 00295 { 00296 textattr((WHITE | RED <<4)); 00297 _cputs("Your name is:\n"); 00298 gotoxy(12,17); 00299 _cputs(out); 00300 } 00301 cursoroff(); 00302 00303 gotoxy(23,19); 00304 textattr((WHITE | RED <<4)|BLINK); 00305 _cputs("PRESS ESC TO EXIT"); 00306 00307 //wait for ESC press 00308 while (_getch() != KB_ESC); 00309 } 00310 00311 #ifndef LOWMEM 00312 static ROMDEF char *uvga_logo= 00313 " ## ## #### # " 00314 " ## ## ## ## ### " 00315 " ## ## ## # ## ## " 00316 " ## ## ## ## ## ## ##" 00317 " ## ## ## ## ## ## ##" 00318 " ## ## ## ## ## #### #######" 00319 " ## ## ## ## ## ## ## ##" 00320 " ## ## ## ## ## ## ## ##" 00321 " ##### #### ## ## ## ##" 00322 " ## ## ### # ## ##" 00323 " ## MicroVGA demo application" 00324 "## " 00325 "www.MicroVGA.com, www.secons.com"; 00326 #endif 00327 00328 void main() 00329 { 00330 int i,j; 00331 int item; 00332 00333 //////////// Main routine 00334 00335 MCU_Init(); 00336 00337 00338 item = 0; 00339 00340 while (1) { 00341 00342 textbackground(BLUE); 00343 clrscr(); 00344 textcolor(BLACK); 00345 textbackground(CYAN); 00346 _cputs("MicroVGA demo app"); 00347 00348 clreol(); 00349 textbackground(BLUE); 00350 textcolor(GREEN); 00351 00352 00353 #ifndef LOWMEM 00354 // draw "logo" 00355 for (i=0;i<13;i++) { 00356 gotoxy(46,12+i); 00357 for (j=0;j<32;j++) { 00358 if (uvga_logo[i*32+ j] == '#') 00359 _putch(219); 00360 else _putch(uvga_logo[i*32+ j]); 00361 } 00362 } 00363 #endif 00364 00365 00366 item = runmenu(5,5, mainmenu, item); 00367 switch (item) { 00368 case 1: memviewer(0); break; 00369 case 2: debugdemo(); break; 00370 case 3: speedtest(); break; 00371 case 4: submenutest(); break; 00372 case 5: cli(); break; 00373 case 6: ascii_art(); break; 00374 case 7: testCGetS(); break; 00375 00376 } 00377 } 00378 }
Generated on Thu Jul 14 2022 01:28:10 by
1.7.2