test
Dependencies: ad5422_arduino mbed LT1446 ADS1248-1 LM35-1 Flash FT813 PGA280_ADS1259
TFT/display.StringsTransforming.cpp@7:c364201bc3ed, 2020-09-01 (annotated)
- Committer:
- nikmaos
- Date:
- Tue Sep 01 10:52:34 2020 +0000
- Revision:
- 7:c364201bc3ed
- Parent:
- 3:d4b106bf3a32
1.09.2020;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikmaos | 3:d4b106bf3a32 | 1 | #include "display.h" |
nikmaos | 3:d4b106bf3a32 | 2 | |
nikmaos | 3:d4b106bf3a32 | 3 | /************************************************************************************************************************** |
nikmaos | 3:d4b106bf3a32 | 4 | ************************** Transform humiditity / temperature float value to string *************************************** |
nikmaos | 3:d4b106bf3a32 | 5 | **************************************************************************************************************************/ |
nikmaos | 3:d4b106bf3a32 | 6 | // If isTemp = 0, string includes |
nikmaos | 3:d4b106bf3a32 | 7 | // 1. current humididty |
nikmaos | 3:d4b106bf3a32 | 8 | // 3. " %" |
nikmaos | 3:d4b106bf3a32 | 9 | |
nikmaos | 3:d4b106bf3a32 | 10 | // If isTemp = 1, string includes |
nikmaos | 3:d4b106bf3a32 | 11 | // 1. "-" (optional), |
nikmaos | 3:d4b106bf3a32 | 12 | // 2. current temperature with decimal mark |
nikmaos | 3:d4b106bf3a32 | 13 | // 3. " С" |
nikmaos | 3:d4b106bf3a32 | 14 | void Display::CreateStringTempHum(char *str, float number, bool isTemp) |
nikmaos | 3:d4b106bf3a32 | 15 | { |
nikmaos | 3:d4b106bf3a32 | 16 | short int multipedNumber = (short int)(number * 100); |
nikmaos | 3:d4b106bf3a32 | 17 | char strCnt = 0; |
nikmaos | 3:d4b106bf3a32 | 18 | if (isTemp) { |
nikmaos | 3:d4b106bf3a32 | 19 | if (multipedNumber < 0) { |
nikmaos | 3:d4b106bf3a32 | 20 | multipedNumber = -multipedNumber; |
nikmaos | 3:d4b106bf3a32 | 21 | str[strCnt] = '-'; |
nikmaos | 3:d4b106bf3a32 | 22 | strCnt++; |
nikmaos | 3:d4b106bf3a32 | 23 | } |
nikmaos | 3:d4b106bf3a32 | 24 | } |
nikmaos | 3:d4b106bf3a32 | 25 | if (multipedNumber >= 10000) { |
nikmaos | 3:d4b106bf3a32 | 26 | str[strCnt] = '0' + (multipedNumber % 100000) / 10000; |
nikmaos | 3:d4b106bf3a32 | 27 | strCnt++; |
nikmaos | 3:d4b106bf3a32 | 28 | } |
nikmaos | 3:d4b106bf3a32 | 29 | if (multipedNumber >= 1000) { |
nikmaos | 3:d4b106bf3a32 | 30 | str[strCnt] = '0' + (multipedNumber % 10000) / 1000; |
nikmaos | 3:d4b106bf3a32 | 31 | strCnt++; |
nikmaos | 3:d4b106bf3a32 | 32 | } |
nikmaos | 3:d4b106bf3a32 | 33 | if (multipedNumber >= 100) { |
nikmaos | 3:d4b106bf3a32 | 34 | str[strCnt] = '0' + (multipedNumber % 1000) / 100; |
nikmaos | 3:d4b106bf3a32 | 35 | strCnt++; |
nikmaos | 3:d4b106bf3a32 | 36 | } |
nikmaos | 3:d4b106bf3a32 | 37 | if (isTemp) { |
nikmaos | 3:d4b106bf3a32 | 38 | str[strCnt] = '.'; |
nikmaos | 3:d4b106bf3a32 | 39 | strCnt++; |
nikmaos | 3:d4b106bf3a32 | 40 | str[strCnt] = '0' + (multipedNumber % 100) / 10; |
nikmaos | 3:d4b106bf3a32 | 41 | strCnt++; |
nikmaos | 3:d4b106bf3a32 | 42 | str[strCnt] = ' '; |
nikmaos | 3:d4b106bf3a32 | 43 | strCnt++; |
nikmaos | 3:d4b106bf3a32 | 44 | str[strCnt] = 'C'; |
nikmaos | 3:d4b106bf3a32 | 45 | strCnt++; |
nikmaos | 3:d4b106bf3a32 | 46 | } else { |
nikmaos | 3:d4b106bf3a32 | 47 | str[strCnt] = '%'; |
nikmaos | 3:d4b106bf3a32 | 48 | strCnt++; |
nikmaos | 3:d4b106bf3a32 | 49 | } |
nikmaos | 3:d4b106bf3a32 | 50 | str[strCnt] = 0; |
nikmaos | 3:d4b106bf3a32 | 51 | } |