test program for my vt100 library. tested on FRDM-KL25Z. this may work with other mbed platform with stdout.

Dependencies:   mbed vt100

A simple test program to test my vt100 library.

I have tested this with my FRDM-KL25Z. But hopefully it will work other platforms with "printf" function.

先にパブリッシュした vt100 ライブラリのテストプログラムです。 FRDM-KL25Z でテストしましたが、printf をサポートしている 他のmbed プラットフォームでも動くのではないかと思います。 (動くといいな~)

/media/uploads/Rhyme/line_pict.jpg

/media/uploads/Rhyme/circle_pict.jpg

Committer:
Rhyme
Date:
Mon Dec 01 13:08:21 2014 +0000
Revision:
1:21fe79ead178
Parent:
0:53ff82c87c14
minimum comment added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:53ff82c87c14 1 #include "mbed.h"
Rhyme 0:53ff82c87c14 2 #include "vt100.h"
Rhyme 0:53ff82c87c14 3
Rhyme 1:21fe79ead178 4 /** test_vt100
Rhyme 1:21fe79ead178 5 * test program for my vt100 library
Rhyme 1:21fe79ead178 6 *
Rhyme 1:21fe79ead178 7 * terminal program must be at least 80x25
Rhyme 1:21fe79ead178 8 * and needless to say, should supporting vt100 commands
Rhyme 1:21fe79ead178 9 */
Rhyme 1:21fe79ead178 10
Rhyme 0:53ff82c87c14 11 vt100 tty ;
Rhyme 0:53ff82c87c14 12
Rhyme 0:53ff82c87c14 13 int left = 2 ;
Rhyme 0:53ff82c87c14 14 int top = 2 ;
Rhyme 0:53ff82c87c14 15 int right = 78 ;
Rhyme 0:53ff82c87c14 16 int bottom = 23 ;
Rhyme 0:53ff82c87c14 17 int h_center = 40 ;
Rhyme 0:53ff82c87c14 18 int v_center = 12 ;
Rhyme 0:53ff82c87c14 19
Rhyme 0:53ff82c87c14 20 void drawFrame(void)
Rhyme 0:53ff82c87c14 21 {
Rhyme 0:53ff82c87c14 22 tty.frame(left, top, right, bottom) ;
Rhyme 0:53ff82c87c14 23 tty.line(left+1, v_center, right-1, v_center, '-') ;
Rhyme 0:53ff82c87c14 24 tty.line(h_center, top+1, h_center, bottom-1, '|') ;
Rhyme 0:53ff82c87c14 25 tty.putChar(h_center, v_center, '+') ;
Rhyme 0:53ff82c87c14 26 }
Rhyme 0:53ff82c87c14 27
Rhyme 0:53ff82c87c14 28 int clip(int y)
Rhyme 0:53ff82c87c14 29 {
Rhyme 0:53ff82c87c14 30 if (y > bottom) {
Rhyme 0:53ff82c87c14 31 y = bottom ;
Rhyme 0:53ff82c87c14 32 } else if (y < top) {
Rhyme 0:53ff82c87c14 33 y = top ;
Rhyme 0:53ff82c87c14 34 }
Rhyme 0:53ff82c87c14 35 return( y ) ;
Rhyme 0:53ff82c87c14 36 }
Rhyme 0:53ff82c87c14 37
Rhyme 0:53ff82c87c14 38 void drawYeqX(void)
Rhyme 0:53ff82c87c14 39 {
Rhyme 0:53ff82c87c14 40 int x, y ;
Rhyme 0:53ff82c87c14 41 drawFrame() ;
Rhyme 0:53ff82c87c14 42 for (x = left+1 ; x < right ; x++ ) {
Rhyme 0:53ff82c87c14 43 y = v_center - (x - h_center) / 4 ;
Rhyme 0:53ff82c87c14 44 tty.putChar(x, y, '*') ;
Rhyme 0:53ff82c87c14 45 }
Rhyme 0:53ff82c87c14 46 tty.locate(left + 2, top + 2) ;
Rhyme 0:53ff82c87c14 47 printf("Y = X\n\r") ;
Rhyme 0:53ff82c87c14 48 }
Rhyme 0:53ff82c87c14 49
Rhyme 0:53ff82c87c14 50 void drawYeqXX(void)
Rhyme 0:53ff82c87c14 51 {
Rhyme 0:53ff82c87c14 52 int x, y ;
Rhyme 0:53ff82c87c14 53 drawFrame() ;
Rhyme 0:53ff82c87c14 54 for (x = left+1 ; x < right ; x++ ) {
Rhyme 0:53ff82c87c14 55 y = clip( bottom - 1 - ((x - h_center)*(x - h_center) / 80)) ;
Rhyme 0:53ff82c87c14 56 tty.putChar(x, y, '*') ;
Rhyme 0:53ff82c87c14 57 }
Rhyme 0:53ff82c87c14 58 tty.locate(left + 2, top + 2) ;
Rhyme 0:53ff82c87c14 59 printf("Y = X^2 - 1\n\r") ;
Rhyme 0:53ff82c87c14 60 }
Rhyme 0:53ff82c87c14 61
Rhyme 0:53ff82c87c14 62 void drawYeqXXX(void)
Rhyme 0:53ff82c87c14 63 {
Rhyme 0:53ff82c87c14 64 int x, y ;
Rhyme 0:53ff82c87c14 65 drawFrame() ;
Rhyme 0:53ff82c87c14 66 for (x = left+1 ; x < right ; x++ ) {
Rhyme 0:53ff82c87c14 67 y = clip(v_center - ((x - h_center)*(x - h_center)*(x - h_center) / 3200)) ;
Rhyme 0:53ff82c87c14 68 tty.putChar(x, y, '*') ;
Rhyme 0:53ff82c87c14 69 }
Rhyme 0:53ff82c87c14 70 tty.locate(left + 2, top + 2) ;
Rhyme 0:53ff82c87c14 71 printf("Y = X^3\n\r") ;
Rhyme 0:53ff82c87c14 72 }
Rhyme 0:53ff82c87c14 73
Rhyme 0:53ff82c87c14 74 void drawCircle(void)
Rhyme 0:53ff82c87c14 75 {
Rhyme 0:53ff82c87c14 76 drawFrame() ;
Rhyme 0:53ff82c87c14 77 tty.circle(h_center, v_center, 8) ;
Rhyme 0:53ff82c87c14 78 tty.locate(left + 2, top + 2) ;
Rhyme 0:53ff82c87c14 79 printf("Y^2 + X^2 = 1\n\r") ;
Rhyme 0:53ff82c87c14 80 }
Rhyme 0:53ff82c87c14 81
Rhyme 0:53ff82c87c14 82 int main() {
Rhyme 0:53ff82c87c14 83 int count = 0 ;
Rhyme 0:53ff82c87c14 84 while(1) {
Rhyme 0:53ff82c87c14 85 tty.cls() ;
Rhyme 1:21fe79ead178 86 tty.locate(10, 1) ;
Rhyme 1:21fe79ead178 87 printf("<< vt100 library test program >>") ;
Rhyme 0:53ff82c87c14 88 drawFrame() ;
Rhyme 0:53ff82c87c14 89 switch(count++) {
Rhyme 0:53ff82c87c14 90 case 0: drawYeqX() ; break ;
Rhyme 0:53ff82c87c14 91 case 1: drawYeqXX() ; break ;
Rhyme 0:53ff82c87c14 92 case 2: drawYeqXXX() ; break ;
Rhyme 0:53ff82c87c14 93 case 3: drawCircle() ; break ;
Rhyme 0:53ff82c87c14 94 default: count = 0 ; continue ;
Rhyme 0:53ff82c87c14 95 }
Rhyme 0:53ff82c87c14 96 wait(4.0) ;
Rhyme 0:53ff82c87c14 97 }
Rhyme 0:53ff82c87c14 98 }