Brad Smith
/
rtcController
Gets current time from the PC over a serial connection
Python script available on the wiki page
terminal.cpp@0:c8dd8b2c6942, 2015-11-12 (annotated)
- Committer:
- mbedDevLondon
- Date:
- Thu Nov 12 19:17:47 2015 +0000
- Revision:
- 0:c8dd8b2c6942
Converted to FRDM board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedDevLondon | 0:c8dd8b2c6942 | 1 | #include "mbed.h" |
mbedDevLondon | 0:c8dd8b2c6942 | 2 | #include "terminal.h" |
mbedDevLondon | 0:c8dd8b2c6942 | 3 | |
mbedDevLondon | 0:c8dd8b2c6942 | 4 | Serial *pPCTerminal; |
mbedDevLondon | 0:c8dd8b2c6942 | 5 | void initializePCTerminal(Serial *p) |
mbedDevLondon | 0:c8dd8b2c6942 | 6 | { |
mbedDevLondon | 0:c8dd8b2c6942 | 7 | pPCTerminal = p; |
mbedDevLondon | 0:c8dd8b2c6942 | 8 | } |
mbedDevLondon | 0:c8dd8b2c6942 | 9 | |
mbedDevLondon | 0:c8dd8b2c6942 | 10 | |
mbedDevLondon | 0:c8dd8b2c6942 | 11 | void clearScreen() |
mbedDevLondon | 0:c8dd8b2c6942 | 12 | { |
mbedDevLondon | 0:c8dd8b2c6942 | 13 | pPCTerminal->printf("\033[2J"); |
mbedDevLondon | 0:c8dd8b2c6942 | 14 | } |
mbedDevLondon | 0:c8dd8b2c6942 | 15 | |
mbedDevLondon | 0:c8dd8b2c6942 | 16 | void locateCursor(int column, int row) |
mbedDevLondon | 0:c8dd8b2c6942 | 17 | { |
mbedDevLondon | 0:c8dd8b2c6942 | 18 | // Cursor Home <ESC>[{ROW};{COLUMN}H |
mbedDevLondon | 0:c8dd8b2c6942 | 19 | pPCTerminal->printf("\033[%d;%dH", row + 1, column + 1); |
mbedDevLondon | 0:c8dd8b2c6942 | 20 | } |
mbedDevLondon | 0:c8dd8b2c6942 | 21 | |
mbedDevLondon | 0:c8dd8b2c6942 | 22 | int rgb888tobgr111(int colour) |
mbedDevLondon | 0:c8dd8b2c6942 | 23 | { |
mbedDevLondon | 0:c8dd8b2c6942 | 24 | int r = (colour >> 23) & 1; |
mbedDevLondon | 0:c8dd8b2c6942 | 25 | int g = (colour >> 15) & 1; |
mbedDevLondon | 0:c8dd8b2c6942 | 26 | int b = (colour >> 7) & 1; |
mbedDevLondon | 0:c8dd8b2c6942 | 27 | return (b << 2) | (g << 1) | (r << 0); |
mbedDevLondon | 0:c8dd8b2c6942 | 28 | } |
mbedDevLondon | 0:c8dd8b2c6942 | 29 | |
mbedDevLondon | 0:c8dd8b2c6942 | 30 | void setForeground(int colour) |
mbedDevLondon | 0:c8dd8b2c6942 | 31 | { |
mbedDevLondon | 0:c8dd8b2c6942 | 32 | // Set Attribute Mode <ESC>[{n}m |
mbedDevLondon | 0:c8dd8b2c6942 | 33 | // Foreground Colours : 30 + bgr |
mbedDevLondon | 0:c8dd8b2c6942 | 34 | int c = 30 + rgb888tobgr111(colour); |
mbedDevLondon | 0:c8dd8b2c6942 | 35 | pPCTerminal->printf("\033[%dm", c); |
mbedDevLondon | 0:c8dd8b2c6942 | 36 | } |
mbedDevLondon | 0:c8dd8b2c6942 | 37 | |
mbedDevLondon | 0:c8dd8b2c6942 | 38 | void setbBackground(int colour) |
mbedDevLondon | 0:c8dd8b2c6942 | 39 | { |
mbedDevLondon | 0:c8dd8b2c6942 | 40 | // Set Attribute Mode <ESC>[{n}m |
mbedDevLondon | 0:c8dd8b2c6942 | 41 | // Background Colours : 40 + bgr |
mbedDevLondon | 0:c8dd8b2c6942 | 42 | int c = 40 + rgb888tobgr111(colour); |
mbedDevLondon | 0:c8dd8b2c6942 | 43 | pPCTerminal->printf("\033[%dm", c); |
mbedDevLondon | 0:c8dd8b2c6942 | 44 | } |
mbedDevLondon | 0:c8dd8b2c6942 | 45 | |
mbedDevLondon | 0:c8dd8b2c6942 | 46 | void drawBox(int width, int height) |
mbedDevLondon | 0:c8dd8b2c6942 | 47 | { |
mbedDevLondon | 0:c8dd8b2c6942 | 48 | pPCTerminal->printf("\0154"); |
mbedDevLondon | 0:c8dd8b2c6942 | 49 | for(int i = 1; i < (width - 2); i++)pPCTerminal->printf("%c",157); |
mbedDevLondon | 0:c8dd8b2c6942 | 50 | pPCTerminal->printf("\0153 \n\r"); |
mbedDevLondon | 0:c8dd8b2c6942 | 51 | |
mbedDevLondon | 0:c8dd8b2c6942 | 52 | for(int row = 1; row < (height - 2); row++) |
mbedDevLondon | 0:c8dd8b2c6942 | 53 | { |
mbedDevLondon | 0:c8dd8b2c6942 | 54 | pPCTerminal->printf("\0170"); |
mbedDevLondon | 0:c8dd8b2c6942 | 55 | for(int i = 1; i < (width - 2); i++)pPCTerminal->printf(" "); |
mbedDevLondon | 0:c8dd8b2c6942 | 56 | pPCTerminal->printf("\0170\n\r"); |
mbedDevLondon | 0:c8dd8b2c6942 | 57 | } |
mbedDevLondon | 0:c8dd8b2c6942 | 58 | |
mbedDevLondon | 0:c8dd8b2c6942 | 59 | |
mbedDevLondon | 0:c8dd8b2c6942 | 60 | pPCTerminal->printf("\0155"); |
mbedDevLondon | 0:c8dd8b2c6942 | 61 | for(int i = 1; i < (width - 2); i++)pPCTerminal->printf("\0163"); |
mbedDevLondon | 0:c8dd8b2c6942 | 62 | pPCTerminal->printf("\052"); |
mbedDevLondon | 0:c8dd8b2c6942 | 63 | |
mbedDevLondon | 0:c8dd8b2c6942 | 64 | } |