Mercurial > public > ostc4
annotate Discovery/Src/tMenuGas.c @ 751:70e9c83ecf22
resolv merge
author | Ideenmodellierer |
---|---|
date | Mon, 13 Mar 2023 22:23:00 +0100 |
parents | 1b995079c045 |
children |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/tMenuGas.c | |
5 /// \brief Main Template file for Menu Page Gas, OC only at the moment | |
6 /// \author heinrichs weikamp gmbh | |
7 /// \date 30-April-2014 | |
8 /// | |
9 /// \details | |
10 /// | |
11 /// $Id$ | |
12 /////////////////////////////////////////////////////////////////////////////// | |
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
14 /// | |
15 /// This program is free software: you can redistribute it and/or modify | |
16 /// it under the terms of the GNU General Public License as published by | |
17 /// the Free Software Foundation, either version 3 of the License, or | |
18 /// (at your option) any later version. | |
19 /// | |
20 /// This program is distributed in the hope that it will be useful, | |
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 /// GNU General Public License for more details. | |
24 /// | |
25 /// You should have received a copy of the GNU General Public License | |
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 ////////////////////////////////////////////////////////////////////////////// | |
28 | |
29 /* Includes ------------------------------------------------------------------*/ | |
30 #include "tMenu.h" | |
31 #include "tMenuGas.h" | |
32 #include "check_warning.h" | |
33 #include "decom.h" | |
34 #include "unit.h" | |
528
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
35 #include "configuration.h" |
38 | 36 |
37 #define OCGAS_STANDARD (0) | |
38 #define OCGAS_BAILOUT_INACTIVE (1) | |
39 #define OCGAS_BAILOUT_ACTIVE (2) | |
647
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
40 #define CCGAS_STANDARD (3) |
38 | 41 |
42 /* Private function prototypes -----------------------------------------------*/ | |
43 uint8_t write_gas(char *text, uint8_t oxygen, uint8_t helium); | |
44 void tMG_refresh(uint8_t line, char *text, uint16_t *tab, char *subtext, uint8_t start, uint8_t gasMode); | |
45 | |
46 /* Exported functions --------------------------------------------------------*/ | |
47 | |
48 uint32_t tMOG_refresh(uint8_t line, char *text, uint16_t *tab, char *subtext) | |
49 { | |
50 uint8_t gas_mode; | |
51 | |
52 if((actual_menu_content == MENU_SURFACE) || (stateUsed->diveSettings.ccrOption == 0)) | |
53 { | |
54 gas_mode = OCGAS_STANDARD; | |
55 } | |
56 else | |
57 { | |
662 | 58 if (isLoopMode(stateUsed->diveSettings.diveMode)) |
38 | 59 gas_mode = OCGAS_BAILOUT_INACTIVE; |
60 else | |
61 gas_mode = OCGAS_BAILOUT_ACTIVE; | |
62 } | |
63 | |
64 tMG_refresh(line, text, tab, subtext, 0, gas_mode); | |
65 return StMOG; | |
66 } | |
67 | |
68 uint32_t tMCG_refresh(uint8_t line, char *text, uint16_t *tab, char *subtext) | |
69 { | |
70 tMG_refresh(line, text, tab, subtext, NUM_OFFSET_DILUENT, CCGAS_STANDARD); | |
71 return StMCG; | |
72 } | |
73 | |
74 void tMG_refresh(uint8_t line, char *text, uint16_t *tab, char *subtext, uint8_t start, uint8_t gasMode) | |
75 { | |
76 const SGasLine * pGasLine; | |
77 | |
344 | 78 uint8_t gasId, oxygen, helium, depthUp, active, first, typeDeco; |
38 | 79 float fPpO2limitHigh = 0; |
80 float fPpO2ofGasAtThisDepth = 0; | |
81 //uint8_t senderCode, depthDown,; | |
82 //uint16_t bar; | |
83 uint16_t textPointer, mod, ltr; | |
84 | |
85 if(actual_menu_content == MENU_SURFACE) | |
86 { | |
87 pGasLine = settingsGetPointer()->gas; | |
88 } | |
89 else | |
90 { | |
91 pGasLine = stateUsed->diveSettings.gas; | |
92 if(actualLeftMaxDepth(stateUsed)) | |
93 fPpO2limitHigh = (float)(settingsGetPointer()->ppO2_max_deco) / 100; | |
94 else | |
95 fPpO2limitHigh = (float)(settingsGetPointer()->ppO2_max_std) / 100; | |
96 } | |
97 textPointer = 0; | |
98 *tab = 158; | |
99 | |
100 /* | |
101 if((line == 0) && (actual_menu_content == MENU_SURFACE)) | |
102 { | |
103 strcpy(subtext, | |
104 "\022" | |
105 // " Travel Deco MOD Bottle" | |
106 " First MOD Deco Bottle" | |
107 ); | |
108 } | |
109 */ | |
110 | |
111 gasId = start; | |
112 for(int count=1;count<=NUM_GASES;count++) | |
113 { | |
114 gasId++; | |
115 if(line && (line != count)) | |
116 { | |
117 first = pGasLine[gasId].note.ub.first; | |
118 if(first == 0) | |
119 { | |
120 strcpy(&text[textPointer], | |
121 "\t" | |
122 "\177" | |
123 "*" | |
124 "\n\r" | |
125 ); | |
126 textPointer += 5; | |
127 } | |
128 else | |
129 { | |
130 strcpy(&text[textPointer],"\n\r"); | |
131 textPointer += 2; | |
132 } | |
133 } | |
134 else | |
135 { | |
136 oxygen = pGasLine[gasId].oxygen_percentage; | |
137 helium = pGasLine[gasId].helium_percentage; | |
138 depthUp = pGasLine[gasId].depth_meter; | |
139 //depthDown = pGasLine[gasId].depth_meter_travel; | |
140 //senderCode = pGasLine[gasId].note.ub.senderCode; | |
141 active = pGasLine[gasId].note.ub.active; | |
142 first = pGasLine[gasId].note.ub.first; | |
143 typeDeco = pGasLine[gasId].note.ub.deco; | |
144 mod = calc_MOD(gasId); | |
145 ltr = pGasLine[gasId].bottle_size_liter; | |
146 //bar = stateUsed->lifeData.bottle_bar[gasId]; | |
147 | |
528
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
148 #ifdef ENABLE_UNUSED_GAS_HIDING |
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
149 if(pGasLine[gasId].note.ub.off) |
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
150 { |
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
151 strcpy(&text[textPointer++],"\021"); |
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
152 } |
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
153 else |
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
154 #endif |
38 | 155 if(active) |
156 { | |
157 if(actual_menu_content == MENU_SURFACE) | |
158 strcpy(&text[textPointer++],"\020"); | |
159 else | |
160 { | |
161 fPpO2ofGasAtThisDepth = (stateUsed->lifeData.pressure_ambient_bar - WATER_VAPOUR_PRESSURE) * pGasLine[gasId].oxygen_percentage / 100; | |
162 if(fPpO2ofGasAtThisDepth > fPpO2limitHigh) | |
163 strcpy(&text[textPointer++],"\025"); | |
164 else | |
165 strcpy(&text[textPointer++],"\020"); | |
166 } | |
167 } | |
168 else | |
528
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
169 { |
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
170 strcpy(&text[textPointer++],"\031"); |
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
171 } |
38 | 172 textPointer += write_gas(&text[textPointer], oxygen, helium); |
173 | |
174 strcpy(&text[textPointer++],"\t"); | |
175 | |
176 if(gasMode == OCGAS_BAILOUT_INACTIVE) | |
177 { | |
178 textPointer += snprintf(&text[textPointer], 59,\ | |
179 "\024" | |
180 " Bailout" | |
528
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
181 "\031" |
38 | 182 "\034" |
183 " %3u" | |
184 "\016\016" | |
185 " %c%c" | |
186 "\017" | |
187 "\035" | |
188 "\n\r", | |
189 unit_depth_integer(mod), | |
190 unit_depth_char1(), | |
191 unit_depth_char2() | |
192 ); | |
193 /* | |
194 textPointer += snprintf(&text[textPointer], 57,\ | |
195 "\024" | |
196 " Bailout" | |
528
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
197 "\031" |
38 | 198 "\034" |
199 " %3u" | |
200 "\016\016" | |
201 "m" | |
202 "\017" | |
203 " %2u" | |
204 "\016\016" | |
205 "ltr" | |
206 "\017" | |
207 " %3u" | |
208 "\016\016" | |
209 "bar" | |
210 "\017" | |
211 "\035" | |
212 "\n\r", | |
213 mod, ltr, bar | |
214 ); | |
215 */ | |
216 } | |
217 else | |
218 { | |
219 if(first == 0) | |
220 strcpy(&text[textPointer++],"\177"); | |
221 | |
222 /* color active / inactive for gas changes */ | |
528
a9c195be907e
Added new option to gas configuration: "Off":
Ideenmodellierer
parents:
344
diff
changeset
|
223 char color[5] = {'\031','\031','\031','\031','\031'}; |
38 | 224 if(active) |
225 { | |
226 /* mod */ | |
227 color[0] = '\023'; | |
228 /* deco */ | |
229 if(typeDeco && depthUp) | |
230 color[1] = '\020'; | |
231 /* ltr */ | |
232 if(ltr) | |
233 color[2] = '\020'; | |
234 /* bar */ | |
235 | |
236 if(mod < depthUp) | |
237 { | |
238 color[0] = '\025'; | |
239 color[1] = '\025'; | |
240 } | |
241 if(typeDeco && !depthUp) | |
242 { | |
243 color[1] = '\025'; | |
244 } | |
245 } | |
246 | |
247 /* output */ | |
248 /* MOD */ | |
249 textPointer += snprintf(&text[textPointer], 14,\ | |
250 "*" | |
251 " " | |
252 "\034" | |
253 "%c" | |
254 "%3u" | |
255 "\016\016" | |
256 " %c%c" | |
257 "\017", | |
258 color[0], | |
259 unit_depth_integer(mod), | |
260 unit_depth_char1(), | |
261 unit_depth_char2() | |
262 ); | |
263 | |
264 /* deco */ | |
265 if(typeDeco) | |
266 { | |
267 textPointer += snprintf(&text[textPointer], 14,\ | |
268 "%c" | |
269 "%3u" | |
270 "\016\016" | |
271 " %c%c" | |
272 "\017", | |
273 color[1], | |
274 unit_depth_integer(depthUp), | |
275 unit_depth_char1(), | |
276 unit_depth_char2() | |
277 ); | |
278 } | |
279 else | |
280 { | |
281 text[textPointer++] = '\x7F'; | |
282 text[textPointer++] = '\x7F'; | |
283 text[textPointer++] = 3*25 + 20; | |
284 } | |
285 /* liter */ | |
286 /* | |
287 textPointer += snprintf(&text[textPointer], 12,\ | |
288 "%c" | |
289 " %2u" | |
290 "\016\016" | |
291 "ltr" | |
292 "\017" | |
293 , color[2],ltr | |
294 ); | |
295 */ | |
296 /* bar */ | |
297 /* | |
298 textPointer += snprintf(&text[textPointer], 12,\ | |
299 "%c" | |
300 " %3u" | |
301 "\016\016" | |
302 "bar" | |
303 "\017", | |
304 color[3], bar | |
305 ); | |
306 */ | |
307 text[textPointer++] = '\035'; | |
308 text[textPointer++] = '\n'; | |
309 text[textPointer++] = '\r'; | |
310 text[textPointer] = 0; | |
311 } | |
312 } | |
313 } | |
314 | |
315 /* special gas number #6 in dive mode*/ | |
647
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
316 if(((line == 0) || (line == 6))) |
38 | 317 { |
647
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
318 if(actual_menu_content != MENU_SURFACE) |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
319 { |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
320 text[textPointer++] = '\020'; |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
321 text[textPointer++] = TXT_2BYTE; |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
322 if(start == NUM_OFFSET_DILUENT) |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
323 text[textPointer++] = TXT2BYTE_SpecialDiveGasMenuCCR; |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
324 else |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
325 text[textPointer++] = TXT2BYTE_SpecialDiveGasMenu; |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
326 text[textPointer++] = '\n'; |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
327 text[textPointer++] = '\r'; |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
328 text[textPointer++] = 0; |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
329 } |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
330 else /* switch to bailout selection in surface mode */ |
662 | 331 if((isLoopMode(settingsGetPointer()->dive_mode)) || (stateUsed->diveSettings.ccrOption == 1)) |
647
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
332 { |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
333 text[textPointer++] = '\024'; |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
334 if(gasMode == CCGAS_STANDARD) |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
335 { |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
336 textPointer += snprintf(&text[textPointer], 14,"Bailout\n"); |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
337 } |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
338 else |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
339 { |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
340 textPointer += snprintf(&text[textPointer], 14,"Diluent\n"); |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
341 } |
15f6f0b5786c
Integrated selection of bailout in the diluent selection page:
Ideenmodellierer
parents:
528
diff
changeset
|
342 } |
38 | 343 } |
344 } | |
345 | |
346 | |
347 /* Private functions ---------------------------------------------------------*/ | |
348 | |
349 /* write_gas() is used in t7.c | |
350 */ | |
351 uint8_t write_gas(char *text, uint8_t oxygen, uint8_t helium) | |
352 { | |
353 uint8_t length; | |
354 | |
355 if((oxygen == 21) && (helium == 0)) | |
356 { | |
357 strcpy(text,"Air"); | |
358 length = 3; | |
359 } | |
360 else if(oxygen == 100) | |
361 { | |
362 strcpy(text,"Oxy"); | |
363 length = 3; | |
364 } | |
365 else if(helium == 0) | |
366 { | |
367 length = snprintf(text, 7,"NX%u",oxygen); | |
368 } | |
369 else if((oxygen + helium) == 100) | |
370 { | |
371 length = snprintf(text, 7,"HX%u",oxygen); | |
372 } | |
373 else | |
374 { | |
375 length = snprintf(text, 7,"%u/%u",oxygen,helium); | |
376 } | |
377 | |
378 if(length > 6) | |
379 { | |
380 strcpy(text,"error"); | |
381 length = 5; | |
382 } | |
383 | |
384 return length; | |
385 } |