Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ms523
Date:
Tue Feb 09 15:05:33 2010 +0000
Commit message:

Changed in this revision

Terminal.cpp Show annotated file Show diff for this revision Revisions of this file
Terminal.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r bd5143ec272b Terminal.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Terminal.cpp	Tue Feb 09 15:05:33 2010 +0000
@@ -0,0 +1,90 @@
+/* mbed ANSI/VT100 Terminal Library
+ * Copyright (c) 2007-2009 sford
+ * Released under the MIT License: http://mbed.org/license/mit
+ */
+
+#include "Terminal.h"
+#include "mbed.h"
+
+#define ASCII_BLOCK     219
+#define ASCII_BORDER_H  205
+#define ASCII_BORDER_V  186
+#define ASCII_BORDER_TL 201
+#define ASCII_BORDER_TR 187
+#define ASCII_BORDER_BL 200
+#define ASCII_BORDER_BR 188
+#define WIDTH 30
+
+Terminal::Terminal(PinName tx, PinName rx) : Serial(tx, rx) {}
+
+void Terminal::cls() {
+    this->printf("\033[2J");
+}
+
+void Terminal::locate(int column, int row) {
+    // Cursor Home    <ESC>[{ROW};{COLUMN}H
+    this->printf("\033[%d;%dH", row + 1, column + 1);
+}
+
+static int rgb888tobgr111(int colour) {
+    int r = (colour >> 23) & 1;
+    int g = (colour >> 15) & 1;
+    int b = (colour >> 7) & 1;
+    return (b << 2) | (g << 1) | (r << 0);
+}
+
+void Terminal::foreground(int colour) {
+    // Set Attribute Mode    <ESC>[{n}m
+    // Foreground Colours : 30 + bgr
+    int c = 30 + rgb888tobgr111(colour);
+    this->printf("\033[%dm", c);
+}
+
+void Terminal::background(int colour) {
+    // Set Attribute Mode    <ESC>[{n}m
+    // Background Colours : 40 + bgr
+    int c = 40 + rgb888tobgr111(colour);
+    this->printf("\033[%dm", c);
+}
+
+void Terminal::box(int x, int y, int w, int h) { 
+     // corners
+    locate(x, y);
+    putc(ASCII_BORDER_TL);
+    locate(x + w - 1, y);
+    putc(ASCII_BORDER_TR);
+    locate(x, y + h - 1);
+    putc(ASCII_BORDER_BL);
+    locate(x + w - 1, y + h - 1);
+    putc(ASCII_BORDER_BR);
+    
+    // top
+    locate(x + 1, y);
+    for(int i=0; i<(w-2); i++){
+        putc(ASCII_BORDER_H);
+    }
+    
+    // bottom
+    locate(x + 1, y + h - 1);
+    for(int i=0; i<(w-2); i++){
+        putc(ASCII_BORDER_H);
+    }
+    
+    // left
+    locate(x, y + 1);
+    for(int i=1; i<(h-1); i++){
+        putc(ASCII_BORDER_V);
+        printf("\n");
+        putc(0x08);
+    }
+    
+    // right
+    locate(x + w - 1, y + 1);
+    for(int i=1; i<(h-1); i++){
+        putc(ASCII_BORDER_V);
+        printf("\n");
+        putc(0x08);
+    }  
+} 
+
+
diff -r 000000000000 -r bd5143ec272b Terminal.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Terminal.h	Tue Feb 09 15:05:33 2010 +0000
@@ -0,0 +1,28 @@
+/* mbed Terminal TextDisplay Library
+ * Copyright (c) 2007-2009 sford
+ * Released under the MIT License: http://mbed.org/license/mit
+ *
+ * Implementation of ANSI/VT100 Terminal escape codes
+ * for use with e.g. Teraterm, Hyperterminal
+ */
+
+#include "mbed.h"
+
+#ifndef MBED_TERMINAL_H
+#define MBED_TERMINAL_H
+
+class Terminal : public Serial {
+public:
+
+    Terminal(PinName tx, PinName rx);
+
+    // printf(), put(), baud() etc - inherited from Serial
+
+    void cls();
+    void locate(int column, int row);
+    void foreground(int colour);
+    void background(int colour);
+    void box(int x, int y, int w, int h); 
+};
+
+#endif
diff -r 000000000000 -r bd5143ec272b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 09 15:05:33 2010 +0000
@@ -0,0 +1,33 @@
+#include "mbed.h"
+#include "Terminal.h"
+
+Terminal term(USBTX, USBRX);                         //Info transmitted to hypertermal via USB
+int Flag=0, Count=10;
+
+void Countdown(void){
+    if(Flag==1){
+        Count--;
+
+    if(Count<=0){
+        Flag=0;        //Turn off MoveFlag at the end of the move.  
+    }
+    term.locate(18,6);
+    term.printf("%d ",Count);
+    }
+}
+     
+int main() {
+    Ticker Timer_100ms;
+    Timer_100ms.attach(&Countdown, 0.1);             //Call Profile every 0.1 seconds
+
+    term.cls();                                           //Clear the screen (paint red)
+    term.locate(18,5);
+    term.printf("Count: %d ",Count);    
+     
+    while(1){                  
+        int Key=term.getc();                      //Get the keypad pressed
+        if(Key==0x0D){                        //See if it was ENTER
+            Flag=1;
+        }    
+    }       
+}
\ No newline at end of file
diff -r 000000000000 -r bd5143ec272b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 09 15:05:33 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0