temp

Committer:
BenRJG
Date:
Thu Dec 06 15:38:09 2018 +0000
Revision:
0:2a4af0cb6e8d
Imported Code from Kiel; Added button functionality; Added set DateTime Functionality

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BenRJG 0:2a4af0cb6e8d 1 /*******************************************************************************
BenRJG 0:2a4af0cb6e8d 2 This cpp defines the functions for the terminal class which are used to
BenRJG 0:2a4af0cb6e8d 3 control the terminal, it also defines the TerminalThread function which
BenRJG 0:2a4af0cb6e8d 4 is ran in its own thread and controls the printing of DATA to the Terminal
BenRJG 0:2a4af0cb6e8d 5 *******************************************************************************/
BenRJG 0:2a4af0cb6e8d 6 #include "Terminal.hpp"
BenRJG 0:2a4af0cb6e8d 7
BenRJG 0:2a4af0cb6e8d 8 // Thread for handiling the terminal
BenRJG 0:2a4af0cb6e8d 9 void TerminalThread(void)
BenRJG 0:2a4af0cb6e8d 10 {
BenRJG 0:2a4af0cb6e8d 11 // Create Object PC of class Terminal with Set SERIAL_TX and SERIAL_RX pins
BenRJG 0:2a4af0cb6e8d 12 Terminal PC(SERIAL_TX, SERIAL_RX);
BenRJG 0:2a4af0cb6e8d 13 PC.init();
BenRJG 0:2a4af0cb6e8d 14 PC.DisplayCellIndex();
BenRJG 0:2a4af0cb6e8d 15 // Enter Forever loop
BenRJG 0:2a4af0cb6e8d 16 while(1)
BenRJG 0:2a4af0cb6e8d 17 {
BenRJG 0:2a4af0cb6e8d 18 // If signal from SD thread recieved print message to terminal
BenRJG 0:2a4af0cb6e8d 19 Thread::signal_wait(Signal_UnMount);
BenRJG 0:2a4af0cb6e8d 20 PC.PrintMSGS("UNMOUNTED SD");
BenRJG 0:2a4af0cb6e8d 21 }
BenRJG 0:2a4af0cb6e8d 22 }
BenRJG 0:2a4af0cb6e8d 23
BenRJG 0:2a4af0cb6e8d 24 void Terminal::init(void)
BenRJG 0:2a4af0cb6e8d 25 {
BenRJG 0:2a4af0cb6e8d 26 // Set baud rate for serial object pc
BenRJG 0:2a4af0cb6e8d 27 pc.baud (115200);
BenRJG 0:2a4af0cb6e8d 28
BenRJG 0:2a4af0cb6e8d 29 // Hide cursor, move to x 0 y 0 and change print colour to green
BenRJG 0:2a4af0cb6e8d 30 pc.printf("\x1b[?25l"); // Hides cursor
BenRJG 0:2a4af0cb6e8d 31 //pc.printf("\x1b[3j"); // Clear screen
BenRJG 0:2a4af0cb6e8d 32 Cursor(0,0);
BenRJG 0:2a4af0cb6e8d 33 Colour(ColourGREEN);
BenRJG 0:2a4af0cb6e8d 34
BenRJG 0:2a4af0cb6e8d 35 // Print DATA table to present data
BenRJG 0:2a4af0cb6e8d 36 pc.printf("* ELEC351 : Low Power Enviromental Sensor * Date and Time Here *\n\r"
BenRJG 0:2a4af0cb6e8d 37 "*********************************************************************\n\r"
BenRJG 0:2a4af0cb6e8d 38 "* TIME * TEMP (C) * PRESSURE (mbar)* LIGHT (LUX) *\n\r"
BenRJG 0:2a4af0cb6e8d 39 "*********************************************************************\n\r");
BenRJG 0:2a4af0cb6e8d 40 for(BYTE idx = 0; idx < Rows; idx++)
BenRJG 0:2a4af0cb6e8d 41 {
BenRJG 0:2a4af0cb6e8d 42 pc.printf("* * * * *\n\r");
BenRJG 0:2a4af0cb6e8d 43 }
BenRJG 0:2a4af0cb6e8d 44 pc.printf("*********************************************************************\n\r"
BenRJG 0:2a4af0cb6e8d 45 "* Debug * *");
BenRJG 0:2a4af0cb6e8d 46
BenRJG 0:2a4af0cb6e8d 47 // Position cursor in first cell of table
BenRJG 0:2a4af0cb6e8d 48 Cursor(3,3);
BenRJG 0:2a4af0cb6e8d 49 Colour(ColourRED);
BenRJG 0:2a4af0cb6e8d 50 }
BenRJG 0:2a4af0cb6e8d 51
BenRJG 0:2a4af0cb6e8d 52 // Move cursor of pc terminal to co-ordinates 'X' and 'Y' (between 0 and 255)
BenRJG 0:2a4af0cb6e8d 53 void Terminal::Cursor(BYTE X, BYTE Y)
BenRJG 0:2a4af0cb6e8d 54 {
BenRJG 0:2a4af0cb6e8d 55 pc.printf("\x1b[%d;%dH",Y,X);
BenRJG 0:2a4af0cb6e8d 56 }
BenRJG 0:2a4af0cb6e8d 57
BenRJG 0:2a4af0cb6e8d 58 // Change pc terminal print colour (8 bit colour) to colour defined by "COLOUR"
BenRJG 0:2a4af0cb6e8d 59 void Terminal::Colour(BYTE COLOUR)
BenRJG 0:2a4af0cb6e8d 60 {
BenRJG 0:2a4af0cb6e8d 61 pc.printf("\x1b[38;5;%dm",COLOUR);
BenRJG 0:2a4af0cb6e8d 62 }
BenRJG 0:2a4af0cb6e8d 63
BenRJG 0:2a4af0cb6e8d 64 // Prints data(STRING) to cell in table defined by IDX
BenRJG 0:2a4af0cb6e8d 65 void Terminal::PrintDATA(BYTE* STRING, BYTE IDX)
BenRJG 0:2a4af0cb6e8d 66 {
BenRJG 0:2a4af0cb6e8d 67 BYTE Y = (IDX/4)+5;
BenRJG 0:2a4af0cb6e8d 68 BYTE X = ((IDX%4)*17)+3;
BenRJG 0:2a4af0cb6e8d 69 Cursor(X,Y);
BenRJG 0:2a4af0cb6e8d 70 pc.printf("%s",STRING);
BenRJG 0:2a4af0cb6e8d 71 }
BenRJG 0:2a4af0cb6e8d 72
BenRJG 0:2a4af0cb6e8d 73 // Prints index of cells into each cell for debug purpose
BenRJG 0:2a4af0cb6e8d 74 void Terminal::DisplayCellIndex(void){
BenRJG 0:2a4af0cb6e8d 75 for(BYTE IDX = 0; IDX < MaxDATA; IDX++){
BenRJG 0:2a4af0cb6e8d 76 BYTE Y = (IDX/4)+5;
BenRJG 0:2a4af0cb6e8d 77 BYTE X = ((IDX%4)*17)+3;
BenRJG 0:2a4af0cb6e8d 78 Cursor(X,Y);
BenRJG 0:2a4af0cb6e8d 79 pc.printf("%d",IDX);
BenRJG 0:2a4af0cb6e8d 80 }
BenRJG 0:2a4af0cb6e8d 81 }
BenRJG 0:2a4af0cb6e8d 82
BenRJG 0:2a4af0cb6e8d 83 // Prints MSGS (String) to debug line of terminal
BenRJG 0:2a4af0cb6e8d 84 void Terminal::PrintMSGS(BYTE* STRING)
BenRJG 0:2a4af0cb6e8d 85 {
BenRJG 0:2a4af0cb6e8d 86 Cursor((11),(Rows+6));
BenRJG 0:2a4af0cb6e8d 87 pc.printf("%s",STRING);
BenRJG 0:2a4af0cb6e8d 88 }
BenRJG 0:2a4af0cb6e8d 89