test program for my vt100 library. tested on FRDM-KL25Z. this may work with other mbed platform with stdout.
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 プラットフォームでも動くのではないかと思います。 (動くといいな~)
Diff: main.cpp
- Revision:
- 0:53ff82c87c14
- Child:
- 1:21fe79ead178
diff -r 000000000000 -r 53ff82c87c14 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Dec 01 12:59:29 2014 +0000 @@ -0,0 +1,89 @@ +#include "mbed.h" +#include "vt100.h" + +vt100 tty ; + +int left = 2 ; +int top = 2 ; +int right = 78 ; +int bottom = 23 ; +int h_center = 40 ; +int v_center = 12 ; + +void drawFrame(void) +{ + tty.frame(left, top, right, bottom) ; + tty.line(left+1, v_center, right-1, v_center, '-') ; + tty.line(h_center, top+1, h_center, bottom-1, '|') ; + tty.putChar(h_center, v_center, '+') ; +} + +int clip(int y) +{ + if (y > bottom) { + y = bottom ; + } else if (y < top) { + y = top ; + } + return( y ) ; +} + +void drawYeqX(void) +{ + int x, y ; + drawFrame() ; + for (x = left+1 ; x < right ; x++ ) { + y = v_center - (x - h_center) / 4 ; + tty.putChar(x, y, '*') ; + } + tty.locate(left + 2, top + 2) ; + printf("Y = X\n\r") ; +} + +void drawYeqXX(void) +{ + int x, y ; + drawFrame() ; + for (x = left+1 ; x < right ; x++ ) { + y = clip( bottom - 1 - ((x - h_center)*(x - h_center) / 80)) ; + tty.putChar(x, y, '*') ; + } + tty.locate(left + 2, top + 2) ; + printf("Y = X^2 - 1\n\r") ; +} + +void drawYeqXXX(void) +{ + int x, y ; + drawFrame() ; + for (x = left+1 ; x < right ; x++ ) { + y = clip(v_center - ((x - h_center)*(x - h_center)*(x - h_center) / 3200)) ; + tty.putChar(x, y, '*') ; + } + tty.locate(left + 2, top + 2) ; + printf("Y = X^3\n\r") ; +} + +void drawCircle(void) +{ + drawFrame() ; + tty.circle(h_center, v_center, 8) ; + tty.locate(left + 2, top + 2) ; + printf("Y^2 + X^2 = 1\n\r") ; +} + +int main() { + int count = 0 ; + while(1) { + tty.cls() ; + drawFrame() ; + switch(count++) { + case 0: drawYeqX() ; break ; + case 1: drawYeqXX() ; break ; + case 2: drawYeqXXX() ; break ; + case 3: drawCircle() ; break ; + default: count = 0 ; continue ; + } + wait(4.0) ; + } +}