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
344
+ − 77 uint8_t gasId, oxygen, helium, depthUp, active, first, typeDeco;
38
+ − 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 //bar = stateUsed->lifeData.bottle_bar[gasId];
+ − 146
+ − 147 if(active)
+ − 148 {
+ − 149 if(actual_menu_content == MENU_SURFACE)
+ − 150 strcpy(&text[textPointer++],"\020");
+ − 151 else
+ − 152 {
+ − 153 fPpO2ofGasAtThisDepth = (stateUsed->lifeData.pressure_ambient_bar - WATER_VAPOUR_PRESSURE) * pGasLine[gasId].oxygen_percentage / 100;
+ − 154 if(fPpO2ofGasAtThisDepth > fPpO2limitHigh)
+ − 155 strcpy(&text[textPointer++],"\025");
+ − 156 else
+ − 157 strcpy(&text[textPointer++],"\020");
+ − 158 }
+ − 159 }
+ − 160 else
+ − 161 strcpy(&text[textPointer++],"\021");
+ − 162
+ − 163 textPointer += write_gas(&text[textPointer], oxygen, helium);
+ − 164
+ − 165 strcpy(&text[textPointer++],"\t");
+ − 166
+ − 167 if(gasMode == OCGAS_BAILOUT_INACTIVE)
+ − 168 {
+ − 169 textPointer += snprintf(&text[textPointer], 59,\
+ − 170 "\024"
+ − 171 " Bailout"
+ − 172 "\021"
+ − 173 "\034"
+ − 174 " %3u"
+ − 175 "\016\016"
+ − 176 " %c%c"
+ − 177 "\017"
+ − 178 "\035"
+ − 179 "\n\r",
+ − 180 unit_depth_integer(mod),
+ − 181 unit_depth_char1(),
+ − 182 unit_depth_char2()
+ − 183 );
+ − 184 /*
+ − 185 textPointer += snprintf(&text[textPointer], 57,\
+ − 186 "\024"
+ − 187 " Bailout"
+ − 188 "\021"
+ − 189 "\034"
+ − 190 " %3u"
+ − 191 "\016\016"
+ − 192 "m"
+ − 193 "\017"
+ − 194 " %2u"
+ − 195 "\016\016"
+ − 196 "ltr"
+ − 197 "\017"
+ − 198 " %3u"
+ − 199 "\016\016"
+ − 200 "bar"
+ − 201 "\017"
+ − 202 "\035"
+ − 203 "\n\r",
+ − 204 mod, ltr, bar
+ − 205 );
+ − 206 */
+ − 207 }
+ − 208 else
+ − 209 {
+ − 210 if(first == 0)
+ − 211 strcpy(&text[textPointer++],"\177");
+ − 212
+ − 213 /* color active / inactive for gas changes */
+ − 214 char color[5] = {'\021','\021','\021','\021','\021'};
+ − 215 if(active)
+ − 216 {
+ − 217 /* mod */
+ − 218 color[0] = '\023';
+ − 219 /* deco */
+ − 220 if(typeDeco && depthUp)
+ − 221 color[1] = '\020';
+ − 222 /* ltr */
+ − 223 if(ltr)
+ − 224 color[2] = '\020';
+ − 225 /* bar */
+ − 226
+ − 227 if(mod < depthUp)
+ − 228 {
+ − 229 color[0] = '\025';
+ − 230 color[1] = '\025';
+ − 231 }
+ − 232 if(typeDeco && !depthUp)
+ − 233 {
+ − 234 color[1] = '\025';
+ − 235 }
+ − 236 }
+ − 237
+ − 238 /* output */
+ − 239 /* MOD */
+ − 240 textPointer += snprintf(&text[textPointer], 14,\
+ − 241 "*"
+ − 242 " "
+ − 243 "\034"
+ − 244 "%c"
+ − 245 "%3u"
+ − 246 "\016\016"
+ − 247 " %c%c"
+ − 248 "\017",
+ − 249 color[0],
+ − 250 unit_depth_integer(mod),
+ − 251 unit_depth_char1(),
+ − 252 unit_depth_char2()
+ − 253 );
+ − 254
+ − 255 /* deco */
+ − 256 if(typeDeco)
+ − 257 {
+ − 258 textPointer += snprintf(&text[textPointer], 14,\
+ − 259 "%c"
+ − 260 "%3u"
+ − 261 "\016\016"
+ − 262 " %c%c"
+ − 263 "\017",
+ − 264 color[1],
+ − 265 unit_depth_integer(depthUp),
+ − 266 unit_depth_char1(),
+ − 267 unit_depth_char2()
+ − 268 );
+ − 269 }
+ − 270 else
+ − 271 {
+ − 272 text[textPointer++] = '\x7F';
+ − 273 text[textPointer++] = '\x7F';
+ − 274 text[textPointer++] = 3*25 + 20;
+ − 275 }
+ − 276 /* liter */
+ − 277 /*
+ − 278 textPointer += snprintf(&text[textPointer], 12,\
+ − 279 "%c"
+ − 280 " %2u"
+ − 281 "\016\016"
+ − 282 "ltr"
+ − 283 "\017"
+ − 284 , color[2],ltr
+ − 285 );
+ − 286 */
+ − 287 /* bar */
+ − 288 /*
+ − 289 textPointer += snprintf(&text[textPointer], 12,\
+ − 290 "%c"
+ − 291 " %3u"
+ − 292 "\016\016"
+ − 293 "bar"
+ − 294 "\017",
+ − 295 color[3], bar
+ − 296 );
+ − 297 */
+ − 298 text[textPointer++] = '\035';
+ − 299 text[textPointer++] = '\n';
+ − 300 text[textPointer++] = '\r';
+ − 301 text[textPointer] = 0;
+ − 302 }
+ − 303 }
+ − 304 }
+ − 305
+ − 306 /* special gas number #6 in dive mode*/
+ − 307 if(((line == 0) || (line == 6)) && (actual_menu_content != MENU_SURFACE))
+ − 308 {
+ − 309 text[textPointer++] = '\020';
+ − 310 text[textPointer++] = TXT_2BYTE;
+ − 311 if(start == NUM_OFFSET_DILUENT)
+ − 312 text[textPointer++] = TXT2BYTE_SpecialDiveGasMenuCCR;
+ − 313 else
+ − 314 text[textPointer++] = TXT2BYTE_SpecialDiveGasMenu;
+ − 315 text[textPointer++] = '\n';
+ − 316 text[textPointer++] = '\r';
+ − 317 text[textPointer++] = 0;
+ − 318 }
+ − 319 }
+ − 320
+ − 321
+ − 322 /* Private functions ---------------------------------------------------------*/
+ − 323
+ − 324 /* write_gas() is used in t7.c
+ − 325 */
+ − 326 uint8_t write_gas(char *text, uint8_t oxygen, uint8_t helium)
+ − 327 {
+ − 328 uint8_t length;
+ − 329
+ − 330 if((oxygen == 21) && (helium == 0))
+ − 331 {
+ − 332 strcpy(text,"Air");
+ − 333 length = 3;
+ − 334 }
+ − 335 else if(oxygen == 100)
+ − 336 {
+ − 337 strcpy(text,"Oxy");
+ − 338 length = 3;
+ − 339 }
+ − 340 else if(helium == 0)
+ − 341 {
+ − 342 length = snprintf(text, 7,"NX%u",oxygen);
+ − 343 }
+ − 344 else if((oxygen + helium) == 100)
+ − 345 {
+ − 346 length = snprintf(text, 7,"HX%u",oxygen);
+ − 347 }
+ − 348 else
+ − 349 {
+ − 350 length = snprintf(text, 7,"%u/%u",oxygen,helium);
+ − 351 }
+ − 352
+ − 353 if(length > 6)
+ − 354 {
+ − 355 strcpy(text,"error");
+ − 356 length = 5;
+ − 357 }
+ − 358
+ − 359 return length;
+ − 360 }