OcsStorage.cpp 3.32 KB
Newer Older
Markéta Jedličková's avatar
Markéta Jedličková committed
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <OcsStorage.h>

OcsStorage::OcsStorage(OcsGraphics& ocsDesignIn)
 : isInitalize(false),
   ocsDesign(ocsDesignIn)
{
}

float OcsStorage::getTemp()
{
	return this->actualData.temperature;
}

float OcsStorage::getMinTemp()
{
	return this->minData.temperature;
}

OcsStorage::message OcsStorage::getActualData()
{
	return this->actualData;
}

void OcsStorage::Update(message income, uint8_t screenNum)
{
	if(screenNum == 1)
	{
		if(this->isInitalize == false)
		{
			ocsDesign.drawMinTemp(income.temperature);
			ocsDesign.drawMaxTemp(income.temperature);
			ocsDesign.drawMinPress(income.pressure);
			ocsDesign.drawMaxPress(income.pressure);
			minData.temperature = income.temperature;
			maxData.temperature = income.temperature;
			minData.pressure = income.pressure;
			maxData.pressure = income.pressure;
			isInitalize = true;
		}

		checkTemperature(income.temperature);
		checkPressure(income.pressure);
		checkAltitude(income.altitude);
		checkHumidity(income.humidity_bme280);
		ocsDesign.drawMessageId(income.messageId);
	}
	else if(screenNum == 0)
	{
		String hour;
		String minute;
		String sec;

		if(income.hour < 10)
		{
			hour += "0";
		}

		if(income.minute < 10)
		{
			minute += "0";
		}

		if(income.sec < 10)
		{
			sec += "0";
		}

		hour += String(income.hour);
		minute += String(income.minute);
		sec += String(income.sec);

		String time = hour + ":" + minute  + ":" + sec;

		ocsDesign.drawTime(13, 47, time);
		ocsDesign.drawDate(income.day, income.month, income.year);

		ocsDesign.drawLongitude(income.longitude);
		ocsDesign.drawLatitude(income.latitude);
		ocsDesign.drawNumOfSat(income.num_of_satelites);

		float loadvoltage = income.voltage_bus + (income.voltage_shunt / 1000);
		float power = income.current_mA * loadvoltage;

		ocsDesign.drawPower(power);

	}else if(screenNum == 2)
	{

	}
}

// ToDo -10 value size is over the box
void OcsStorage::checkTemperature(float temp)
{
	if(temp > -40 and temp < 80)
	{
		if(actualData.temperature != temp)
		{
			this->actualData.temperature = temp;
			ocsDesign.drawTemp(temp);
		}

		if(temp < this->minData.temperature)
		{
			this->minData.temperature = temp;
			ocsDesign.drawMinTemp(temp);
		}

		if(temp > this->maxData.temperature)
		{
			this->maxData.temperature = temp;
			ocsDesign.drawMaxTemp(temp);
		}
	}
	else
	{
		// ToDo error handling
	}
}

void OcsStorage::checkPressure(float pressure)
{
	if(pressure > 30000 and pressure < 100000)
	{
		if(actualData.pressure != pressure)
		{
			this->actualData.pressure = pressure;
			ocsDesign.drawPress(pressure);
		}

		if(pressure < this->minData.pressure)
		{
			this->minData.pressure = pressure;
			ocsDesign.drawMinPress(pressure);
		}

		if(pressure > this->maxData.pressure)
		{
			this->maxData.pressure = pressure;
			ocsDesign.drawMaxPress(pressure);
		}
	}
	else
	{
		// ToDo error handling
	}
}

void OcsStorage::checkAltitude(float altitude)
{
	if(altitude > 0 and altitude < 5000)
	{
		if(this->actualData.altitude != altitude)
		{
			this->actualData.altitude = altitude;
			ocsDesign.drawAltitude(altitude);
		}
	}
	else
	{
		// ToDo error handling
	}
}

void OcsStorage::checkHumidity(float humidity)
{
	if(humidity > 0 and humidity < 100)
	{
		if(this->actualData.humidity_bme280 != humidity)
		{
			this->actualData.humidity_bme280 = humidity;
			ocsDesign.drawHumidity(humidity);
		}
	}
	else
	{
		// ToDo error handling
	}
}