Temperature monitor for PC, uses the SPI driven TFT and also the Mod Serial library to receive temperature data from a PC over the USB-Serial port and plot it on a display

Dependencies:   mbed Touch_tft TFT_fonts_old

Committer:
Mephi
Date:
Wed Jan 18 20:40:29 2012 +0000
Revision:
0:8e8c90cd559b
First publish, as I think I\ve got everything working for the temperature monitoring

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mephi 0:8e8c90cd559b 1 /*
Mephi 0:8e8c90cd559b 2 Required input format
Mephi 0:8e8c90cd559b 3 For Temps:
Mephi 0:8e8c90cd559b 4 temp GPU:55 CPU:45 SYS:35
Mephi 0:8e8c90cd559b 5
Mephi 0:8e8c90cd559b 6
Mephi 0:8e8c90cd559b 7 numbers MUST be two digit, 01-99, anything over 99 is shown as 99.
Mephi 0:8e8c90cd559b 8 */
Mephi 0:8e8c90cd559b 9
Mephi 0:8e8c90cd559b 10
Mephi 0:8e8c90cd559b 11 #include "mbed.h"
Mephi 0:8e8c90cd559b 12 #define MODSERIAL_DEFAULT_RX_BUFFER_SIZE 512 // Setting to default so it can be referenced/changed later
Mephi 0:8e8c90cd559b 13 #include "MODSERIAL.h"
Mephi 0:8e8c90cd559b 14 #include "SPI_TFT.h"
Mephi 0:8e8c90cd559b 15 #include "Arial12x12.h"
Mephi 0:8e8c90cd559b 16 #include "Arial28x28.h"
Mephi 0:8e8c90cd559b 17 #include "touch_tft.h"
Mephi 0:8e8c90cd559b 18
Mephi 0:8e8c90cd559b 19 DigitalOut myled(LED1);
Mephi 0:8e8c90cd559b 20
Mephi 0:8e8c90cd559b 21 //Serial Variables
Mephi 0:8e8c90cd559b 22 MODSERIAL pc(USBTX, USBRX); // tx, rx
Mephi 0:8e8c90cd559b 23 bool newline_detected = false;
Mephi 0:8e8c90cd559b 24 char messageBufferIncoming[MODSERIAL_DEFAULT_RX_BUFFER_SIZE];
Mephi 0:8e8c90cd559b 25
Mephi 0:8e8c90cd559b 26 //Screen Variables
Mephi 0:8e8c90cd559b 27 touch_tft tt(p19,p20,p16,p17,p11, p12, p13, p14, p15,"TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset
Mephi 0:8e8c90cd559b 28
Mephi 0:8e8c90cd559b 29 //Other Program Variables
Mephi 0:8e8c90cd559b 30 const int GraphWidth = 320;
Mephi 0:8e8c90cd559b 31 const int ScreenWidth = 295;
Mephi 0:8e8c90cd559b 32 const int ScreenHeight = 195;
Mephi 0:8e8c90cd559b 33 uint8_t GPUtemp[GraphWidth] = { 0 };
Mephi 0:8e8c90cd559b 34 uint8_t CPUtemp[GraphWidth] = { 0 };
Mephi 0:8e8c90cd559b 35 uint8_t SYStemp[GraphWidth] = { 0 };
Mephi 0:8e8c90cd559b 36
Mephi 0:8e8c90cd559b 37 int currentGPUtemp = 0;
Mephi 0:8e8c90cd559b 38 int currentCPUtemp = 0;
Mephi 0:8e8c90cd559b 39 int currentSYStemp = 0;
Mephi 0:8e8c90cd559b 40 int GraphLocation = GraphWidth;
Mephi 0:8e8c90cd559b 41
Mephi 0:8e8c90cd559b 42 int i;
Mephi 0:8e8c90cd559b 43
Mephi 0:8e8c90cd559b 44 void rxCallback(MODSERIAL_IRQ_INFO *q) {
Mephi 0:8e8c90cd559b 45 MODSERIAL *serial = q->serial;
Mephi 0:8e8c90cd559b 46 if ( serial->rxGetLastChar() == '\n') {
Mephi 0:8e8c90cd559b 47 newline_detected = true;
Mephi 0:8e8c90cd559b 48 }
Mephi 0:8e8c90cd559b 49 }
Mephi 0:8e8c90cd559b 50
Mephi 0:8e8c90cd559b 51 void AddNewTemp(int inGPUtemp, int inCPUtemp, int inSYStemp) {
Mephi 0:8e8c90cd559b 52 GPUtemp[GraphWidth - 1] = inGPUtemp;
Mephi 0:8e8c90cd559b 53 CPUtemp[GraphWidth - 1] = inCPUtemp;
Mephi 0:8e8c90cd559b 54 SYStemp[GraphWidth - 1] = inSYStemp;
Mephi 0:8e8c90cd559b 55 }
Mephi 0:8e8c90cd559b 56
Mephi 0:8e8c90cd559b 57 void MoveOnGraph(void) {
Mephi 0:8e8c90cd559b 58 for(i = 0; i < GraphWidth; i++) {
Mephi 0:8e8c90cd559b 59 GPUtemp[i] = GPUtemp[i + 1];
Mephi 0:8e8c90cd559b 60 CPUtemp[i] = CPUtemp[i + 1];
Mephi 0:8e8c90cd559b 61 SYStemp[i] = SYStemp[i + 1];
Mephi 0:8e8c90cd559b 62 }
Mephi 0:8e8c90cd559b 63 }
Mephi 0:8e8c90cd559b 64
Mephi 0:8e8c90cd559b 65 void setTemps(char* inTemps) {
Mephi 0:8e8c90cd559b 66 char temp1[3];
Mephi 0:8e8c90cd559b 67 char temp2[3];
Mephi 0:8e8c90cd559b 68 char temp3[3];
Mephi 0:8e8c90cd559b 69 temp1[0] = inTemps[9];
Mephi 0:8e8c90cd559b 70 temp1[1] = inTemps[10];
Mephi 0:8e8c90cd559b 71 temp1[2] = '\0';
Mephi 0:8e8c90cd559b 72 temp2[0] = inTemps[16];
Mephi 0:8e8c90cd559b 73 temp2[1] = inTemps[17];
Mephi 0:8e8c90cd559b 74 temp1[2] = '\0';
Mephi 0:8e8c90cd559b 75 temp3[0] = inTemps[23];
Mephi 0:8e8c90cd559b 76 temp3[1] = inTemps[24];
Mephi 0:8e8c90cd559b 77 temp1[2] = '\0';
Mephi 0:8e8c90cd559b 78 AddNewTemp(atoi(temp1), atoi(temp2), atoi(temp3));
Mephi 0:8e8c90cd559b 79 }
Mephi 0:8e8c90cd559b 80
Mephi 0:8e8c90cd559b 81 void DrawGraphOutline(void) {
Mephi 0:8e8c90cd559b 82 tt.line(0,220,319,220,White); // Graph Line Across
Mephi 0:8e8c90cd559b 83 tt.line(25,25,25,239,White); // Graph Line Down
Mephi 0:8e8c90cd559b 84
Mephi 0:8e8c90cd559b 85 tt.locate(3,3);
Mephi 0:8e8c90cd559b 86 printf("Temps");
Mephi 0:8e8c90cd559b 87
Mephi 0:8e8c90cd559b 88 tt.locate(260,222); // X axis labels
Mephi 0:8e8c90cd559b 89 printf("1");
Mephi 0:8e8c90cd559b 90 tt.locate(200,222);
Mephi 0:8e8c90cd559b 91 printf("2");
Mephi 0:8e8c90cd559b 92 tt.locate(140,222);
Mephi 0:8e8c90cd559b 93 printf("3");
Mephi 0:8e8c90cd559b 94 tt.locate(80,222);
Mephi 0:8e8c90cd559b 95 printf("4");
Mephi 0:8e8c90cd559b 96
Mephi 0:8e8c90cd559b 97 tt.locate(1,170); // Y axis labels
Mephi 0:8e8c90cd559b 98 printf("25");
Mephi 0:8e8c90cd559b 99 tt.locate(1,120);
Mephi 0:8e8c90cd559b 100 printf("50");
Mephi 0:8e8c90cd559b 101 tt.locate(1,70);
Mephi 0:8e8c90cd559b 102 printf("75");
Mephi 0:8e8c90cd559b 103
Mephi 0:8e8c90cd559b 104 }
Mephi 0:8e8c90cd559b 105
Mephi 0:8e8c90cd559b 106 void DrawGraph(void) {
Mephi 0:8e8c90cd559b 107 int pix;
Mephi 0:8e8c90cd559b 108 int tempDiff;
Mephi 0:8e8c90cd559b 109 int width = GraphWidth - ScreenWidth;
Mephi 0:8e8c90cd559b 110 for(pix = GraphWidth; pix > width ; pix--){
Mephi 0:8e8c90cd559b 111 if((GPUtemp[pix] > 0)/* && (GPUtemp[pix - 1] != GPUtemp[pix])*/){
Mephi 0:8e8c90cd559b 112 if(GPUtemp[pix -1] > 0){tt.pixel(pix, 220 - (GPUtemp[pix - 1] * 2), Black);}
Mephi 0:8e8c90cd559b 113 tt.pixel(pix, 220 - (GPUtemp[pix] * 2), Green);
Mephi 0:8e8c90cd559b 114 }
Mephi 0:8e8c90cd559b 115 if((CPUtemp[pix] > 0)/* && (CPUtemp[pix - 1] != CPUtemp[pix])*/){
Mephi 0:8e8c90cd559b 116 if(CPUtemp[pix -1] > 0){tt.pixel(pix, 220 - (CPUtemp[pix - 1] * 2), Black);}
Mephi 0:8e8c90cd559b 117 tt.pixel(pix, 220 - (CPUtemp[pix] * 2), Blue);
Mephi 0:8e8c90cd559b 118 }
Mephi 0:8e8c90cd559b 119 if((SYStemp[pix] > 0) /*&& (SYStemp[pix - 1] != SYStemp[pix])*/){
Mephi 0:8e8c90cd559b 120 if(SYStemp[pix -1] > 0){tt.pixel(pix, 220 - (SYStemp[pix - 1] * 2), Black);}
Mephi 0:8e8c90cd559b 121 tt.pixel(pix, 220 - (SYStemp[pix] * 2), Red);
Mephi 0:8e8c90cd559b 122 }
Mephi 0:8e8c90cd559b 123 }
Mephi 0:8e8c90cd559b 124 tt.locate(30,30);
Mephi 0:8e8c90cd559b 125 printf("GPU: %i", GPUtemp[GraphWidth - 1]);
Mephi 0:8e8c90cd559b 126 tt.locate(30,45);
Mephi 0:8e8c90cd559b 127 printf("CPU: %i", CPUtemp[GraphWidth - 1]);
Mephi 0:8e8c90cd559b 128 tt.locate(30,60);
Mephi 0:8e8c90cd559b 129 printf("SYS: %i", SYStemp[GraphWidth - 1]);
Mephi 0:8e8c90cd559b 130 }
Mephi 0:8e8c90cd559b 131
Mephi 0:8e8c90cd559b 132 int main() {
Mephi 0:8e8c90cd559b 133 pc.attach(&rxCallback, MODSERIAL::RxIrq); //Setup USB Serial connection
Mephi 0:8e8c90cd559b 134
Mephi 0:8e8c90cd559b 135 tt.claim(stdout); // send stdout to the TFT display
Mephi 0:8e8c90cd559b 136 tt.background(Black); // set background to black
Mephi 0:8e8c90cd559b 137 tt.foreground(White); // set chars to white
Mephi 0:8e8c90cd559b 138 tt.cls(); // clear the screen
Mephi 0:8e8c90cd559b 139 tt.set_font((unsigned char*) Arial12x12); // select the font
Mephi 0:8e8c90cd559b 140 tt.set_orientation(1);
Mephi 0:8e8c90cd559b 141
Mephi 0:8e8c90cd559b 142 tt.line(0,25,319,25,White); // Line Across
Mephi 0:8e8c90cd559b 143 tt.line(80,0,80,24,White); // Line Down 1
Mephi 0:8e8c90cd559b 144 tt.line(160,0,160,24,White); // Line Down 2
Mephi 0:8e8c90cd559b 145 tt.line(240,0,240,24,White); // Line Down 3
Mephi 0:8e8c90cd559b 146
Mephi 0:8e8c90cd559b 147 DrawGraphOutline();
Mephi 0:8e8c90cd559b 148
Mephi 0:8e8c90cd559b 149 while(1) {
Mephi 0:8e8c90cd559b 150 while (! newline_detected ) ;
Mephi 0:8e8c90cd559b 151 pc.move(messageBufferIncoming, MODSERIAL_DEFAULT_RX_BUFFER_SIZE);
Mephi 0:8e8c90cd559b 152 newline_detected = false;
Mephi 0:8e8c90cd559b 153 if(strncmp(messageBufferIncoming,"temp",4) == 0) {
Mephi 0:8e8c90cd559b 154 setTemps(messageBufferIncoming);
Mephi 0:8e8c90cd559b 155 DrawGraph();
Mephi 0:8e8c90cd559b 156 MoveOnGraph();
Mephi 0:8e8c90cd559b 157 }
Mephi 0:8e8c90cd559b 158 }
Mephi 0:8e8c90cd559b 159 }