-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.cpp
142 lines (121 loc) · 3.46 KB
/
GUI.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
sht21.c
Created on: 23.05.2018
Author: HaagS
*/
#include "GUI.h"
#include "itoa.h"
extern LCD_LAUNCHPAD lcd;
//**********************************************************************************
// Prints a 32-bit float value on the display.
//
// input: floatValue Float value that should be printed on display
//
// output: none
//
// return: none
//**********************************************************************************
void GUI::printFloat(float floatValue) {
char intStr[10];
uint8_t i;
uint8_t numberLength;
uint8_t position;
uint16_t integerValue = (uint16_t)(floatValue * 100);
itoa(integerValue, intStr, 10);
lcd.clear();
lcd.showSymbol(LCD_SEG_DOT3, true);
if(floatValue < 100) {
numberLength = 4;
position = 1;
}
else if(floatValue < 10) {
numberLength = 3;
position = 2;
}
else {
numberLength = 5;
position = 0;
}
for(i=0; i<numberLength; i++) {
lcd.showChar(intStr[i], position+i);
}
}
//**********************************************************************************
// Prints a 16-bit integer value on the display.
//
// input: integerValue Integer value that should be printed on display
//
// output: none
//
// return: none
//**********************************************************************************
void GUI::printInteger(uint16_t integerValue) {
char intStr[10];
uint8_t numberLength;
uint8_t position;
itoa(integerValue, intStr, 10);
lcd.clear();
if(integerValue < 1000) {
numberLength = 3;
position = 2;
}
else if(integerValue < 10000) {
numberLength = 4;
position = 1;
}
else if(integerValue >= 10000) {
numberLength = 5;
position = 0;
}
for(uint8_t i = 0; i < numberLength; i++) {
lcd.showChar(intStr[i], position + i);
}
}
//**********************************************************************************
// Prints a 16-bit integer CO2 value on the display and turns on
// the related display segments.
//
// input: co2 CO2 integer value that should be printed on display
//
// output: none
//
// return: none
//**********************************************************************************
void GUI::showCO2(uint16_t co2) {
lcd.clear();
printInteger(co2);
lcd.showSymbol(LCD_SEG_BAT0, true);
lcd.showSymbol(LCD_SEG_BAT1, true);
}
//**********************************************************************************
// Prints a 32-bit float temperature value on the display and turns on
// the related display segments.
//
// input: temperature Temperature float value that should be printed on display
//
// output: none
//
// return: none
//**********************************************************************************
void GUI::showTemperature(float temperature) {
lcd.clear();
printFloat(temperature);
lcd.showSymbol(LCD_SEG_BAT2, true);
lcd.showSymbol(LCD_SEG_BAT3, true);
}
//**********************************************************************************
// Prints a 32-bit float relativ humidity value on the display and turns on
// the related display segments.
//
// input: humidity Humidity float value that should be printed on display
//
// output: none
//
// return: none
//**********************************************************************************
void GUI::showHumidity(float humidity) {
lcd.clear();
printFloat(humidity);
lcd.showSymbol(LCD_SEG_BAT4, true);
lcd.showSymbol(LCD_SEG_BAT5, true);
}