Brad Smith / Mbed 2 deprecated rtcController

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers terminal.cpp Source File

terminal.cpp

00001 #include "mbed.h"
00002 #include "terminal.h"
00003 
00004 Serial *pPCTerminal;
00005 void initializePCTerminal(Serial *p)
00006 {
00007     pPCTerminal = p;
00008 }
00009 
00010 
00011 void clearScreen() 
00012 {
00013     pPCTerminal->printf("\033[2J");
00014 }
00015 
00016 void locateCursor(int column, int row) 
00017 {
00018     // Cursor Home    <ESC>[{ROW};{COLUMN}H
00019     pPCTerminal->printf("\033[%d;%dH", row + 1, column + 1);
00020 }
00021 
00022 int rgb888tobgr111(int colour) 
00023 {
00024     int r = (colour >> 23) & 1;
00025     int g = (colour >> 15) & 1;
00026     int b = (colour >> 7) & 1;
00027     return (b << 2) | (g << 1) | (r << 0);
00028 }
00029 
00030 void setForeground(int colour) 
00031 {
00032     // Set Attribute Mode    <ESC>[{n}m
00033     // Foreground Colours : 30 + bgr
00034     int c = 30 + rgb888tobgr111(colour);
00035     pPCTerminal->printf("\033[%dm", c);
00036 }
00037 
00038 void setbBackground(int colour) 
00039 {
00040     // Set Attribute Mode    <ESC>[{n}m
00041     // Background Colours : 40 + bgr
00042     int c = 40 + rgb888tobgr111(colour);
00043     pPCTerminal->printf("\033[%dm", c);
00044 }
00045 
00046 void drawBox(int width, int height)
00047 {
00048     pPCTerminal->printf("\0154");
00049     for(int i = 1; i < (width - 2); i++)pPCTerminal->printf("%c",157);
00050     pPCTerminal->printf("\0153 \n\r");
00051     
00052     for(int row = 1; row < (height - 2); row++)
00053         { 
00054         pPCTerminal->printf("\0170");
00055         for(int i = 1; i < (width - 2); i++)pPCTerminal->printf(" ");
00056         pPCTerminal->printf("\0170\n\r");
00057         }
00058    
00059     
00060     pPCTerminal->printf("\0155");
00061     for(int i = 1; i < (width - 2); i++)pPCTerminal->printf("\0163");
00062     pPCTerminal->printf("\052");
00063 
00064 }