[SIMPLE PROGRAM] 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.StringsTransforming.cpp Source File

display.StringsTransforming.cpp

00001 #include "display.h"
00002 
00003 /**************************************************************************************************************************
00004 ************************** Transform humiditity / temperature float value to string ***************************************
00005 **************************************************************************************************************************/
00006 // If isTemp = 0, string includes
00007 // 1. current humididty
00008 // 3. " %"
00009 
00010 // If isTemp = 1, string includes
00011 // 1. "-" (optional),
00012 // 2. current temperature with decimal mark
00013 // 3. " С"
00014 void Display::CreateStringTempHum(char *str, float number, bool isTemp)
00015 {
00016     short int multipedNumber = (short int)(number * 100);
00017     char strCnt = 0;
00018     if (isTemp) {
00019         if (multipedNumber < 0) {
00020             multipedNumber = -multipedNumber;
00021             str[strCnt] = '-';
00022             strCnt++;
00023         }
00024     }
00025     if (multipedNumber >= 10000) {
00026         str[strCnt] = '0' + (multipedNumber % 100000) / 10000;
00027         strCnt++;
00028     }
00029     if (multipedNumber >= 1000) {
00030         str[strCnt] = '0' + (multipedNumber % 10000) / 1000;
00031         strCnt++;
00032     }
00033     if (multipedNumber >= 100) {
00034         str[strCnt] = '0' + (multipedNumber % 1000) / 100;
00035         strCnt++;
00036     }
00037     if (isTemp) {
00038         str[strCnt] = '.';
00039         strCnt++;
00040         str[strCnt] = '0' + (multipedNumber % 100) / 10;
00041         strCnt++;
00042         str[strCnt] = ' ';
00043         strCnt++;
00044         str[strCnt] = 'C';
00045         strCnt++;
00046     } else {
00047         str[strCnt] = '%';
00048         strCnt++;
00049     }
00050     str[strCnt] = 0;
00051 }