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"
|
|
35
|
|
36 #define OCGAS_STANDARD (0)
|
|
37 #define OCGAS_BAILOUT_INACTIVE (1)
|
|
38 #define OCGAS_BAILOUT_ACTIVE (2)
|
|
39 #define CCGAS_STANDARD (0)
|
|
40
|
|
41 /* Private function prototypes -----------------------------------------------*/
|
|
42 uint8_t write_gas(char *text, uint8_t oxygen, uint8_t helium);
|
|
43 void tMG_refresh(uint8_t line, char *text, uint16_t *tab, char *subtext, uint8_t start, uint8_t gasMode);
|
|
44
|
|
45 /* Exported functions --------------------------------------------------------*/
|
|
46
|
|
47 uint32_t tMOG_refresh(uint8_t line, char *text, uint16_t *tab, char *subtext)
|
|
48 {
|
|
49 uint8_t gas_mode;
|
|
50
|
|
51 if((actual_menu_content == MENU_SURFACE) || (stateUsed->diveSettings.ccrOption == 0))
|
|
52 {
|
|
53 gas_mode = OCGAS_STANDARD;
|
|
54 }
|
|
55 else
|
|
56 {
|
|
57 if (stateUsed->diveSettings.diveMode == DIVEMODE_CCR)
|
|
58 gas_mode = OCGAS_BAILOUT_INACTIVE;
|
|
59 else
|
|
60 gas_mode = OCGAS_BAILOUT_ACTIVE;
|
|
61 }
|
|
62
|
|
63 tMG_refresh(line, text, tab, subtext, 0, gas_mode);
|
|
64 return StMOG;
|
|
65 }
|
|
66
|
|
67 uint32_t tMCG_refresh(uint8_t line, char *text, uint16_t *tab, char *subtext)
|
|
68 {
|
|
69 tMG_refresh(line, text, tab, subtext, NUM_OFFSET_DILUENT, CCGAS_STANDARD);
|
|
70 return StMCG;
|
|
71 }
|
|
72
|
|
73 void tMG_refresh(uint8_t line, char *text, uint16_t *tab, char *subtext, uint8_t start, uint8_t gasMode)
|
|
74 {
|
|
75 const SGasLine * pGasLine;
|
|
76
|
|
77 uint8_t gasId, oxygen, helium, depthUp, active, first, typeDeco, wirelessId;
|
|
78 float fPpO2limitHigh = 0;
|
|
79 float fPpO2ofGasAtThisDepth = 0;
|
|
80 //uint8_t senderCode, depthDown,;
|
|
81 //uint16_t bar;
|
|
82 uint16_t textPointer, mod, ltr;
|
|
83
|
|
84 if(actual_menu_content == MENU_SURFACE)
|
|
85 {
|
|
86 pGasLine = settingsGetPointer()->gas;
|
|
87 }
|
|
88 else
|
|
89 {
|
|
90 pGasLine = stateUsed->diveSettings.gas;
|
|
91 if(actualLeftMaxDepth(stateUsed))
|
|
92 fPpO2limitHigh = (float)(settingsGetPointer()->ppO2_max_deco) / 100;
|
|
93 else
|
|
94 fPpO2limitHigh = (float)(settingsGetPointer()->ppO2_max_std) / 100;
|
|
95 }
|
|
96 textPointer = 0;
|
|
97 *tab = 158;
|
|
98
|
|
99 /*
|
|
100 if((line == 0) && (actual_menu_content == MENU_SURFACE))
|
|
101 {
|
|
102 strcpy(subtext,
|
|
103 "\022"
|
|
104 // " Travel Deco MOD Bottle"
|
|
105 " First MOD Deco Bottle"
|
|
106 );
|
|
107 }
|
|
108 */
|
|
109
|
|
110 gasId = start;
|
|
111 for(int count=1;count<=NUM_GASES;count++)
|
|
112 {
|
|
113 gasId++;
|
|
114 if(line && (line != count))
|
|
115 {
|
|
116 first = pGasLine[gasId].note.ub.first;
|
|
117 if(first == 0)
|
|
118 {
|
|
119 strcpy(&text[textPointer],
|
|
120 "\t"
|
|
121 "\177"
|
|
122 "*"
|
|
123 "\n\r"
|
|
124 );
|
|
125 textPointer += 5;
|
|
126 }
|
|
127 else
|
|
128 {
|
|
129 strcpy(&text[textPointer],"\n\r");
|
|
130 textPointer += 2;
|
|
131 }
|
|
132 }
|
|
133 else
|
|
134 {
|
|
135 oxygen = pGasLine[gasId].oxygen_percentage;
|
|
136 helium = pGasLine[gasId].helium_percentage;
|
|
137 depthUp = pGasLine[gasId].depth_meter;
|
|
138 //depthDown = pGasLine[gasId].depth_meter_travel;
|
|
139 //senderCode = pGasLine[gasId].note.ub.senderCode;
|
|
140 active = pGasLine[gasId].note.ub.active;
|
|
141 first = pGasLine[gasId].note.ub.first;
|
|
142 typeDeco = pGasLine[gasId].note.ub.deco;
|
|
143 mod = calc_MOD(gasId);
|
|
144 ltr = pGasLine[gasId].bottle_size_liter;
|
|
145 wirelessId = pGasLine[gasId].bottle_wireless_id;
|
|
146 //bar = stateUsed->lifeData.bottle_bar[gasId];
|
|
147
|
|
148 if(active)
|
|
149 {
|
|
150 if(actual_menu_content == MENU_SURFACE)
|
|
151 strcpy(&text[textPointer++],"\020");
|
|
152 else
|
|
153 {
|
|
154 fPpO2ofGasAtThisDepth = (stateUsed->lifeData.pressure_ambient_bar - WATER_VAPOUR_PRESSURE) * pGasLine[gasId].oxygen_percentage / 100;
|
|
155 if(fPpO2ofGasAtThisDepth > fPpO2limitHigh)
|
|
156 strcpy(&text[textPointer++],"\025");
|
|
157 else
|
|
158 strcpy(&text[textPointer++],"\020");
|
|
159 }
|
|
160 }
|
|
161 else
|
|
162 strcpy(&text[textPointer++],"\021");
|
|
163
|
|
164 textPointer += write_gas(&text[textPointer], oxygen, helium);
|
|
165
|
|
166 strcpy(&text[textPointer++],"\t");
|
|
167
|
|
168 if(gasMode == OCGAS_BAILOUT_INACTIVE)
|
|
169 {
|
|
170 textPointer += snprintf(&text[textPointer], 59,\
|
|
171 "\024"
|
|
172 " Bailout"
|
|
173 "\021"
|
|
174 "\034"
|
|
175 " %3u"
|
|
176 "\016\016"
|
|
177 " %c%c"
|
|
178 "\017"
|
|
179 "\035"
|
|
180 "\n\r",
|
|
181 unit_depth_integer(mod),
|
|
182 unit_depth_char1(),
|
|
183 unit_depth_char2()
|
|
184 );
|
|
185 /*
|
|
186 textPointer += snprintf(&text[textPointer], 57,\
|
|
187 "\024"
|
|
188 " Bailout"
|
|
189 "\021"
|
|
190 "\034"
|
|
191 " %3u"
|
|
192 "\016\016"
|
|
193 "m"
|
|
194 "\017"
|
|
195 " %2u"
|
|
196 "\016\016"
|
|
197 "ltr"
|
|
198 "\017"
|
|
199 " %3u"
|
|
200 "\016\016"
|
|
201 "bar"
|
|
202 "\017"
|
|
203 "\035"
|
|
204 "\n\r",
|
|
205 mod, ltr, bar
|
|
206 );
|
|
207 */
|
|
208 }
|
|
209 else
|
|
210 {
|
|
211 if(first == 0)
|
|
212 strcpy(&text[textPointer++],"\177");
|
|
213
|
|
214 /* color active / inactive for gas changes */
|
|
215 char color[5] = {'\021','\021','\021','\021','\021'};
|
|
216 if(active)
|
|
217 {
|
|
218 /* mod */
|
|
219 color[0] = '\023';
|
|
220 /* deco */
|
|
221 if(typeDeco && depthUp)
|
|
222 color[1] = '\020';
|
|
223 /* ltr */
|
|
224 if(ltr)
|
|
225 color[2] = '\020';
|
|
226 /* bar */
|
|
227 if(wirelessId)
|
|
228 color[3] = '\020';
|
|
229 /* wireless */
|
|
230 if(wirelessId)
|
|
231 color[4] = '\020';
|
|
232 /* ltr, bar */
|
|
233
|
|
234 if(mod < depthUp)
|
|
235 {
|
|
236 color[0] = '\025';
|
|
237 color[1] = '\025';
|
|
238 }
|
|
239 if(typeDeco && !depthUp)
|
|
240 {
|
|
241 color[1] = '\025';
|
|
242 }
|
|
243 }
|
|
244
|
|
245 /* output */
|
|
246 /* MOD */
|
|
247 textPointer += snprintf(&text[textPointer], 14,\
|
|
248 "*"
|
|
249 " "
|
|
250 "\034"
|
|
251 "%c"
|
|
252 "%3u"
|
|
253 "\016\016"
|
|
254 " %c%c"
|
|
255 "\017",
|
|
256 color[0],
|
|
257 unit_depth_integer(mod),
|
|
258 unit_depth_char1(),
|
|
259 unit_depth_char2()
|
|
260 );
|
|
261
|
|
262 /* deco */
|
|
263 if(typeDeco)
|
|
264 {
|
|
265 textPointer += snprintf(&text[textPointer], 14,\
|
|
266 "%c"
|
|
267 "%3u"
|
|
268 "\016\016"
|
|
269 " %c%c"
|
|
270 "\017",
|
|
271 color[1],
|
|
272 unit_depth_integer(depthUp),
|
|
273 unit_depth_char1(),
|
|
274 unit_depth_char2()
|
|
275 );
|
|
276 }
|
|
277 else
|
|
278 {
|
|
279 text[textPointer++] = '\x7F';
|
|
280 text[textPointer++] = '\x7F';
|
|
281 text[textPointer++] = 3*25 + 20;
|
|
282 }
|
|
283 /* liter */
|
|
284 /*
|
|
285 textPointer += snprintf(&text[textPointer], 12,\
|
|
286 "%c"
|
|
287 " %2u"
|
|
288 "\016\016"
|
|
289 "ltr"
|
|
290 "\017"
|
|
291 , color[2],ltr
|
|
292 );
|
|
293 */
|
|
294 /* bar */
|
|
295 /*
|
|
296 textPointer += snprintf(&text[textPointer], 12,\
|
|
297 "%c"
|
|
298 " %3u"
|
|
299 "\016\016"
|
|
300 "bar"
|
|
301 "\017",
|
|
302 color[3], bar
|
|
303 );
|
|
304 */
|
|
305 /* wireless */
|
|
306 /*
|
|
307 if(wirelessId)
|
|
308 {
|
|
309 textPointer += snprintf(&text[textPointer], 8,\
|
|
310 "%c"
|
|
311 " *"
|
|
312 "%u",
|
|
313 color[4], (wirelessId%0x0F)
|
|
314 );
|
|
315 }
|
|
316 */
|
|
317 text[textPointer++] = '\035';
|
|
318 text[textPointer++] = '\n';
|
|
319 text[textPointer++] = '\r';
|
|
320 text[textPointer] = 0;
|
|
321 }
|
|
322 }
|
|
323 }
|
|
324
|
|
325 /* special gas number #6 in dive mode*/
|
|
326 if(((line == 0) || (line == 6)) && (actual_menu_content != MENU_SURFACE))
|
|
327 {
|
|
328 text[textPointer++] = '\020';
|
|
329 text[textPointer++] = TXT_2BYTE;
|
|
330 if(start == NUM_OFFSET_DILUENT)
|
|
331 text[textPointer++] = TXT2BYTE_SpecialDiveGasMenuCCR;
|
|
332 else
|
|
333 text[textPointer++] = TXT2BYTE_SpecialDiveGasMenu;
|
|
334 text[textPointer++] = '\n';
|
|
335 text[textPointer++] = '\r';
|
|
336 text[textPointer++] = 0;
|
|
337 }
|
|
338 }
|
|
339
|
|
340
|
|
341 /* Private functions ---------------------------------------------------------*/
|
|
342
|
|
343 /* write_gas() is used in t7.c
|
|
344 */
|
|
345 uint8_t write_gas(char *text, uint8_t oxygen, uint8_t helium)
|
|
346 {
|
|
347 uint8_t length;
|
|
348
|
|
349 if((oxygen == 21) && (helium == 0))
|
|
350 {
|
|
351 strcpy(text,"Air");
|
|
352 length = 3;
|
|
353 }
|
|
354 else if(oxygen == 100)
|
|
355 {
|
|
356 strcpy(text,"Oxy");
|
|
357 length = 3;
|
|
358 }
|
|
359 else if(helium == 0)
|
|
360 {
|
|
361 length = snprintf(text, 7,"NX%u",oxygen);
|
|
362 }
|
|
363 else if((oxygen + helium) == 100)
|
|
364 {
|
|
365 length = snprintf(text, 7,"HX%u",oxygen);
|
|
366 }
|
|
367 else
|
|
368 {
|
|
369 length = snprintf(text, 7,"%u/%u",oxygen,helium);
|
|
370 }
|
|
371
|
|
372 if(length > 6)
|
|
373 {
|
|
374 strcpy(text,"error");
|
|
375 length = 5;
|
|
376 }
|
|
377
|
|
378 return length;
|
|
379 }
|