HYT humidity & temp sensor polling / showing received data at TFT with capacitive touchscreen

Dependencies:   FT800_2 HYT mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers display.StringsTransform.cpp Source File

display.StringsTransform.cpp

00001 #include "display.h"
00002 
00003 /**************************************************************************************************************************
00004 ************************** Transform humiditity / temperature float value to string ***************************************
00005 **************************************************************************************************************************/
00006 // If isTemp = 0, resulting string includes
00007 // 1. current humididty
00008 // 3. " %"
00009 
00010 // If isTemp = 1, resulting string includes
00011 // 1. "-" (optional),
00012 // 2. current temperature with decimal mark
00013 // 3. " С"
00014 
00015 // Returns offset using for placing degree sign
00016 char Display::CreateStringTempHum(char *str, float number, bool isTemp)
00017 {
00018     char offsetForDegreeSign;
00019     short int multipedNumber = (short int)(number * 100);
00020     char strCnt = 0;
00021     if (isTemp) {
00022         if (multipedNumber < 0) {
00023             multipedNumber = -multipedNumber;
00024             str[strCnt] = '-';
00025             strCnt++;
00026         }
00027     }
00028     if (multipedNumber >= 10000) {
00029         str[strCnt] = '0' + (multipedNumber % 100000) / 10000;
00030         strCnt++;
00031     }
00032     if (multipedNumber >= 1000) {
00033         str[strCnt] = '0' + (multipedNumber % 10000) / 1000;
00034         strCnt++;
00035     }
00036     if (multipedNumber >= 100) {
00037         str[strCnt] = '0' + (multipedNumber % 1000) / 100;
00038         strCnt++;
00039     }
00040     if (isTemp) {
00041         str[strCnt] = '.';
00042         strCnt++;
00043         str[strCnt] = '0' + (multipedNumber % 100) / 10;
00044         strCnt++;
00045         str[strCnt] = ' ';
00046         strCnt++;
00047         offsetForDegreeSign = strCnt;
00048         str[strCnt] = 'C';
00049         strCnt++;
00050     } else {
00051         str[strCnt] = '%';
00052         strCnt++;
00053     }
00054     str[strCnt] = 0;
00055     
00056     return offsetForDegreeSign;
00057 }
00058 
00059 
00060 /**************************************************************************************************************************
00061 ************************** Transform multiplied temperature value to string ***********************************************
00062 **************************************************************************************************************************/
00063 // Resulting string includes
00064 // 1. "-" (optional),
00065 // 2. current temperature with decimal mark
00066 void Display::CreateStringMultipliedTemp(char *str, short int number)
00067 {
00068     char strCnt = 0;
00069     if (number < 0) {
00070         number = -number;
00071         str[strCnt] = '-';
00072         strCnt++;
00073     }
00074     if (number >= 1000) {
00075         str[strCnt] = '0' + (number % 10000) / 1000;
00076         strCnt++;
00077     }
00078     if (number >= 100) {
00079         str[strCnt] = '0' + (number % 1000) / 100;
00080         strCnt++;
00081     }
00082     if (number >= 10) {
00083         str[strCnt] = '0' + (number % 100) / 10;
00084         strCnt++;
00085     }
00086     str[strCnt] = '.';
00087     strCnt++;
00088     str[strCnt] = '0' + (number % 100) / 10;
00089     strCnt++;
00090     str[strCnt] = 0;
00091 }
00092 
00093 
00094 /**************************************************************************************************************************
00095 ************************** Transform number of seconds to HH:MM:SS string *************************************************
00096 **************************************************************************************************************************/
00097 void Display::CreateStringTime(char *str, uint32_t numberOfSeconds)
00098 {
00099     char hrs = (numberOfSeconds / 3600);
00100     if (hrs < 10) {
00101         str[0] = '0';
00102     } else {
00103         str[0] = '0' + hrs / 10;
00104     }
00105     str[1] = '0' + hrs % 10;
00106     str[2] = ':';
00107     char minutes = (numberOfSeconds / 60) % 60;
00108     if (minutes < 10) {
00109         str[3] = '0';
00110     } else {
00111         str[3] = '0' + minutes / 10;
00112     }
00113     str[4] = '0' + minutes % 10;
00114     str[5] = ':';
00115     char sec = numberOfSeconds % 60;
00116     if (sec < 10) {
00117         str[6] = '0';
00118     } else {
00119         str[6] = '0' + sec / 10;
00120     }
00121     str[7] = '0' + sec % 10;
00122     str[8] = 0;
00123 }