Mercurial > public > hwos_code
annotate src/gaslist.asm @ 605:5ce603c29750
gas color coding fixed
author | heinrichsweikamp |
---|---|
date | Sun, 25 Nov 2018 13:21:52 +0100 |
parents | ca4556fb60b9 |
children | c40025d8e750 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
604 | 3 ; File gaslist.asm REFACTORED VERSION V2.99e |
0 | 4 ; |
275 | 5 ; Managing OSTC gas list |
0 | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-08-11 : [jDG] Creation. | |
11 | |
604 | 12 #include "hwos.inc" ; mandatory header |
582 | 13 #include "convert.inc" |
14 #include "math.inc" ; div16x16 for MOD calculations | |
15 #include "strings.inc" | |
16 #include "tft.inc" | |
17 #include "tft_outputs.inc" | |
18 #include "shared_definitions.h" | |
604 | 19 #include "wait.inc" |
20 | |
21 IFDEF _rx_functions | |
22 #include "rx_ops.inc" | |
23 ENDIF | |
0 | 24 |
582 | 25 extern convert_mbar_to_feet |
26 extern customview_show_mix | |
604 | 27 extern tSetup_GasDepth |
582 | 28 extern tGasDisabled |
29 extern tDilDisabled | |
604 | 30 extern tLiter |
31 extern tbar10 | |
582 | 32 extern tbar |
0 | 33 |
604 | 34 gaslist CODE |
0 | 35 |
36 ;============================================================================= | |
604 | 37 ; Helper Functions for divemenu_tree.asm |
38 ; | |
39 ; They need to be put in a different file than | |
40 ; where the MENU_DYNAMIC macros uses them. | |
41 | |
42 global do_toggle_gf_label | |
43 do_toggle_gf_label: | |
44 movff char_I_deco_model,WREG ; 0 = ZH-L16, 1 = ZH-L16-GF | |
45 decfsz WREG,W ; toggle GF only in GF modes - in GF mode? | |
46 bra do_toggle_gf_label_1 ; NO - print in disabled color | |
47 movff opt_enable_aGF,WREG ; =1: aGF can be selected underwater | |
48 decfsz WREG,W ; aGF enabled? | |
49 bra do_toggle_gf_label_1 ; NO - print in disabled color | |
50 bra do_toggle_gf_label_2 ; YES to both - print in standard color | |
51 do_toggle_gf_label_1: | |
52 call TFT_disabled_color | |
53 do_toggle_gf_label_2: | |
54 STRCAT_TEXT tDivemenu_ToggleGF | |
55 return | |
56 | |
57 | |
58 IFDEF _cave_mode | |
59 global do_turn_dive_label | |
60 do_turn_dive_label: | |
61 btfss FLAG_cave_mode ; in cave mode? | |
62 call TFT_disabled_color ; NO - print in disabled color | |
63 btfsc FLAG_dive_turned ; dive already turned? | |
64 call TFT_attention_color ; YES - print in attention color | |
65 STRCAT_TEXT tDivemenu_TurnDive ; output label | |
66 return | |
67 ENDIF | |
68 | |
69 | |
70 global do_toggle_max_pres_diff_label | |
71 do_toggle_max_pres_diff_label: | |
72 movff opt_TR_mode,WREG ; get TR mode | |
73 xorlw .2 ; compare with 2 (ind.double) | |
74 tstfsz WREG ; equal? | |
75 call TFT_disabled_color ; NO - print in disabled color | |
76 STRCAT_TEXT tTrMaxDeltaP ; output label | |
77 movff char_I_max_pres_diff,lo | |
78 output_99 | |
79 STRCAT_TEXT tbar ; " bar" | |
80 return | |
81 | |
82 global gaslist_copy_dil_to_oc | |
83 gaslist_copy_dil_to_oc: | |
84 ; | |
85 ; Memory Map: | |
86 ; ----------------------------------------- | |
87 ; opt_gas_O2_ratio res 5 | |
88 ; opt_dil_O2_ratio res 5 | |
89 ; opt_gas_He_ratio res 5 | |
90 ; opt_dil_He_ratio res 5 | |
91 ; opt_gas_type res 5 | |
92 ; opt_dil_type res 5 | |
93 ; opt_gas_change res 5 | |
94 ; opt_dil_change res 5 | |
95 ; | |
96 ; char_I_tank_size res 10 | |
97 ; char_I_tank_pres_fill res 10 | |
98 ; | |
99 bcf aux_flag ; clear aux_flag by default | |
100 movf gaslist_gas,W ; copy current gas or diluent number to WREG | |
101 btfss FLAG_diluent_setup ; in CCR menus? | |
102 bra gaslist_copy_dil_to_oc_1 ; NO - gaslist_gas is already pointing to an OC gas | |
103 addlw -.5 ; YES - subtract offset between diluents and gases | |
104 movwf gaslist_gas ; - let gaslist_gas point to the corresponding OC gas | |
105 bsf aux_flag ; - remember we came from a CCR menu | |
106 bcf FLAG_diluent_setup ; - pretend we came from an OC gas menu | |
107 gaslist_copy_dil_to_oc_1: | |
108 lfsr FSR0,opt_dil_O2_ratio ; load base address of diluents settings, ASM variables | |
109 lfsr FSR1,opt_gas_O2_ratio ; load base address of gas settings, ASM variables | |
110 movff PLUSW0,PLUSW1 ; copy O2 ratio | |
111 addlw .10 ; add offset from O2 ratios to He ratios | |
112 movff PLUSW0,PLUSW1 ; copy He ratio | |
113 addlw .10 ; add offset from He ratios to types | |
114 movff PLUSW0,PLUSW1 ; copy type | |
115 addlw .10 ; add offset from type to change depth | |
116 movff PLUSW0,PLUSW1 ; copy change depth | |
117 addlw -.30 ; wind back to initial gas number | |
118 lfsr FSR0,char_I_tank_size+5 ; load base address of diluents settings, shared variables | |
119 lfsr FSR1,char_I_tank_size+0 ; load base address of gas settings, shared variables | |
120 movff PLUSW0,PLUSW1 ; copy tank size | |
121 addlw .10 ; add offset from tank sizes to pressure budget | |
122 movff PLUSW0,PLUSW1 ; copy pressure budget | |
123 call gaslist_cleanup_list ; make sure that there will be just one first gas | |
124 btfss aux_flag ; did we came from a CCR menu? | |
125 return ; NO - done | |
126 bsf FLAG_diluent_setup ; YES - restore proper origin again | |
127 movlw .5 ; - offset between OC gases and diluents | |
128 addwf gaslist_gas,F ; - let gaslist_gas point to the diluent again | |
129 WIN_BOX_BLACK .30,.239,.0,.159 ; - create some visual effect to show activity | |
130 WAITMS .200 ; - pause for 200 ms | |
131 return ; - done | |
132 | |
133 | |
134 ;============================================================================= | |
135 ; Append gas description to current string | |
136 ; | |
582 | 137 ; Input: PRODL : gas number (0..4) |
604 | 138 ; FSR2 : Current string position |
139 ; Output: Text appended into buffer pointed by FSR2 | |
582 | 140 |
141 global gaslist_strcat_gas | |
604 | 142 global gaslist_strcat_gas_WREG |
143 gaslist_strcat_gas: ; entry point with gas/dil in PRODL (0-4) and FLAG_diluent_setup | |
144 movff PRODL,gaslist_gas ; get current menu item (0-4) | |
145 movlw .5 ; offset between gases and diluents | |
146 btfsc FLAG_diluent_setup ; in CCR menus? | |
147 addwf gaslist_gas,F ; YES - add the offset | |
148 movf gaslist_gas,W ; copy to WREG | |
149 gaslist_strcat_gas_WREG: ; entry point with gas/dil in WREG (0-9) | |
150 lfsr FSR1,opt_gas_O2_ratio ; load base address of opt_gas_O2_ratio | |
151 movff PLUSW1,lo ; read O2 ratio | |
152 lfsr FSR1,opt_gas_He_ratio ; load base address of opt_gas_He_ratio | |
153 movff PLUSW1,hi ; read He ratio | |
154 goto customview_show_mix ; put "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2, and RETURN | |
0 | 155 |
156 ;============================================================================= | |
604 | 157 ; Append current mix to current string (for divemode) |
158 ; | |
159 ; Input: FSR2 : Current string position | |
160 ; Output: Text appended into buffer pointed by FSR2 | |
161 | |
582 | 162 global gaslist_strcat_gas6 |
604 | 163 gaslist_strcat_gas6: ; show current O2/He mix |
582 | 164 STRCAT_TEXT tGas |
165 STRCAT ": " | |
604 | 166 movff gas6_O2_ratio,hi ; TFT_color_code_gaslist needs O2 ratio in hi |
167 call TFT_color_code_gaslist ; color-code according to O2 ratio and depth | |
168 movff gas6_O2_ratio,lo ; customview_show_mix needs O2 ratio in lo | |
169 movff gas6_He_ratio,hi ; ... and He ratio in hi | |
170 goto customview_show_mix ; put "Nxlo", "Txlo/hi", "Air" or "O2" into Postinc2, and return | |
171 ;============================================================================= | |
172 ; Helper functions for menu_tree | |
0 | 173 |
604 | 174 global gaslist_GasDepth |
175 gaslist_GasDepth: | |
176 movf gaslist_gas,W ; load gas/dil index into WREG (0-9) | |
177 lfsr FSR1,opt_gas_change ; load base address of change depths | |
178 tstfsz PLUSW1 ; change depth = 0 ? | |
179 bra gaslist_GasDepth_1 ; NO | |
180 lfsr FSR1,opt_gas_type ; YES - load base address of opt_gas_type | |
181 tstfsz PLUSW1 ; - type = disabled ? | |
182 call TFT_attention_color ; NO - print in attention color (yellow) | |
183 gaslist_GasDepth_1: | |
184 STRCAT_TEXT tSetup_GasDepth | |
185 return | |
582 | 186 |
187 global gaslist_show_type | |
0 | 188 gaslist_show_type: |
582 | 189 movf gaslist_gas,W |
604 | 190 lfsr FSR1,opt_gas_type ; load base address of opt_gas_type |
191 movff PLUSW1,lo ; read gas type | |
582 | 192 STRCAT_TEXT tType |
604 | 193 lfsr FSR1,tGasDisabled ; load base address of gas type labels |
194 btfsc FLAG_diluent_setup ; in CCR setup? | |
195 lfsr FSR1,tDilDisabled ; YES - load base address of diluent type labels | |
582 | 196 movff lo,WREG ; 0-3 |
197 rlncf WREG ; x2 | |
604 | 198 addwf FSR1L,F ; adjust address pointer to required text |
582 | 199 movlw .0 |
200 addwfc FSR1H,F | |
604 | 201 call strcat_text ; copy label text |
582 | 202 return |
0 | 203 |
604 | 204 |
582 | 205 global gaslist_toggle_type |
0 | 206 gaslist_toggle_type: |
582 | 207 movf gaslist_gas,W |
604 | 208 lfsr FSR1,opt_gas_type ; load base address of opt_gas_type |
209 movff PLUSW1,lo ; read gas type | |
210 incf lo,F ; increment type | |
211 btfsc FLAG_diluent_setup ; in CCR setup? | |
212 bra gaslist_toggle_type2 ; YES - diluents | |
213 btfsc lo,2 ; NO - gases, type index > 3 ? | |
214 clrf lo ; YES - clear to zero | |
215 movff lo,PLUSW1 ; - copy back result | |
582 | 216 return |
0 | 217 gaslist_toggle_type2: |
582 | 218 movlw .3 |
604 | 219 cpfslt lo ; index > 2 ? |
220 clrf lo ; YES - clear to zero | |
221 movf gaslist_gas,W ; restore gaslist_gas in WREG | |
222 movff lo,PLUSW1 ; copy back result | |
582 | 223 return |
0 | 224 |
582 | 225 |
226 global gaslist_strcat_setpoint | |
227 global gaslist_strcat_setpoint_0 | |
604 | 228 gaslist_strcat_setpoint: ; entry point with setpoint index in PRODL |
229 movff PRODL,gaslist_gas ; get current menu item (0-4) | |
230 gaslist_strcat_setpoint_0: ; entry point with setpoint index in gaslist_gas | |
582 | 231 bsf leftbind |
604 | 232 btfsc short_gas_decriptions ; shall use short versions of gaslist_strcat_setpoint? |
233 bra gaslist_strcat_setpoint2 ; YES - use short version | |
234 STRCAT_TEXT tSP ; "SP" | |
235 incf gaslist_gas,W ; (0-4) -> (1-5) into WREG | |
582 | 236 movwf lo |
604 | 237 output_8 ; print SP number |
582 | 238 bcf leftbind |
239 PUTC ":" | |
604 | 240 gaslist_strcat_setpoint2: ; short version |
582 | 241 btfsc divemode |
242 bra gaslist_strcat_setpoint4 ; no "*" in divemode | |
604 | 243 movf gaslist_gas,W ; (0-4) into WREG |
244 bnz gaslist_strcat_setpoint3 ; SP index = 0 ? | |
245 PUTC "*" ; YES - print * | |
246 bra gaslist_strcat_setpoint4 ; - continue with cbar value | |
247 gaslist_strcat_setpoint3: ; NO | |
248 PUTC " " ; - print a space | |
0 | 249 gaslist_strcat_setpoint4: |
604 | 250 movf gaslist_gas,W ; (0-4) into WREG |
251 lfsr FSR1,char_I_setpoint_cbar ; load base address of setpoint cbar values | |
252 movf PLUSW1,W ; read cbar value | |
582 | 253 movwf lo |
254 clrf hi | |
255 bsf leftbind | |
604 | 256 output_16dp d'3' ; print as X.XX |
257 btfsc divemode ; in divemode? | |
258 bra gaslist_strcat_setpoint5 ; YES - skip text in divemode | |
259 STRCAT_TEXT tbar ; NO - print "bar" | |
0 | 260 gaslist_strcat_setpoint5: |
604 | 261 PUTC " " ; print a space |
262 movf gaslist_gas,W ; (0-4) into WREG | |
263 lfsr FSR1,char_I_setpoint_change ; load base address of switch depths | |
264 movff PLUSW1,lo ; read switch depth into lo | |
265 bra gaslist_strcat_depth ; print depth in meters or ft | |
582 | 266 |
0 | 267 |
268 ;---------------------------------------------------------------------------- | |
604 | 269 ; Append gas description to current string |
270 ; | |
271 ; Prints gas number, * if first, = if deco gas, gas composition and change depth, | |
272 ; including fancy color-coding | |
0 | 273 ; |
604 | 274 ; Input: PRODL gas number (0..4) |
275 ; FSR2 current string position | |
276 ; Output: text appended to buffer pointed by FSR2 | |
277 ; | |
278 ; NOTE: used in the menu-tree for the MENU_CALLBACK entry | |
0 | 279 |
604 | 280 global gaslist_strcat_gas_cd |
582 | 281 global gaslist_gastitle |
604 | 282 gaslist_strcat_gas_cd: ; entry point with gas in PRODL (0-4) and usage of FLAG_diluent_setup |
283 movff PRODL,gaslist_gas ; get current menu item (0-4) | |
284 movlw .5 ; offset between gases and diluents | |
285 btfsc FLAG_diluent_setup ; in diluent menus? | |
286 addwf gaslist_gas,F ; YES - add the offset | |
287 gaslist_gastitle: ; entry point with gas/dil in gaslist_gas (0-4 for gases, 5-9 for diluents) | |
288 bcf win_invert ; clear flag for inverted output by default | |
289 btfsc short_gas_decriptions ; shall use short versions of gaslist_strcat_gas_cd? | |
290 bra gaslist_gastitle1 ; YES - use short version | |
291 incf gaslist_gas,W ; (0-9) -> (1-10) into WREG | |
582 | 292 movwf lo |
604 | 293 movlw .6 ; diluents start with 6 |
294 cpfslt lo ; gas number < 6 ? | |
295 bra gaslist_gastitle_dil ; NO - it's a diluent | |
296 STRCAT_TEXT tGas ; YES - it's a gas | |
297 bra gaslist_gastitle0 | |
298 gaslist_gastitle_dil: | |
299 STRCAT_TEXT tDil | |
300 movlw .5 ; offset between gases and diluents | |
301 subwf lo,F ; subtract offset from diluent number (6-10) -> (1-5) | |
582 | 302 gaslist_gastitle0: |
303 bsf leftbind | |
604 | 304 output_8 ; print gas/dil number (1-5) |
582 | 305 bcf leftbind |
306 PUTC ":" | |
604 | 307 gaslist_gastitle1: ; short version of gaslist_strcat_gas_cd |
308 btfsc divemode ; in divemode? | |
309 bra gaslist_gastitle3 ; YES - no "*" and "=" in front of gas composition, no highlighting for transmitters paired | |
310 | |
311 IFDEF _rx_functions | |
312 btfss FLAG_tr_enabled ; NO - TR functions enabled? | |
313 bra gaslist_gastitle2 ; NO - continue with gas type | |
314 lfsr FSR1,opt_transmitter_id_1 ; YES - load base address of transmitter ID table | |
315 movf gaslist_gas,W ; - (0-4 for OC/Bailout, 5-9 for Diluents) | |
316 rlncf WREG,W ; - index x2 because IDs are 2 byte | |
317 tstfsz PLUSW1 ; - transmitter ID low byte <> 0 ? | |
318 bsf win_invert ; YES - flag transmitter paired by inverting output | |
319 incf WREG,W ; - increment index | |
320 tstfsz PLUSW1 ; - transmitter ID high byte <> 0 ? | |
321 bsf win_invert ; YES - flag transmitter paired by inverting output | |
322 ENDIF | |
323 | |
582 | 324 gaslist_gastitle2: |
604 | 325 rcall gaslist_strcat_gas_type ; print "*" for first gas/dil, "=" for a deco gas or " " else |
582 | 326 gaslist_gastitle3: |
327 call TFT_standard_color | |
604 | 328 btfsc divemode ; in divemode? |
329 rcall gaslist_strcat_gas_better ; YES - check if this is a "better gas" | |
330 lfsr FSR1,opt_gas_type ; load base address of gas types | |
331 movf gaslist_gas,W ; load index into WREG (0-4 for gases, 5-9 for diluents) | |
332 movf PLUSW1,W ; read gas/dil type into WREG | |
333 bnz gaslist_gastitle4 ; type = disabled? NO - keep color | |
334 call TFT_disabled_color ; YES - switch color to disabled | |
335 bra gaslist_gastitle5 ; - skip ppO2 check for disabled gases | |
336 gaslist_gastitle4: | |
337 btfss divemode ; in divemode? | |
338 bra gaslist_gastitle5 ; NO - no ppO2 check if not in divemode | |
339 lfsr FSR1,opt_gas_O2_ratio ; YES - load base address of opt_gas_O2_ratio | |
340 movf gaslist_gas,W ; - load index into WREG (0-4 for gases, 5-9 for diluents) | |
341 movff PLUSW1,hi ; - read O2 ratio into hi | |
342 call TFT_color_code_gaslist ; - set color according to ppO2 limits | |
343 gaslist_gastitle5: | |
344 movf gaslist_gas,W ; copy gas/dil index to WREG (0-9) | |
345 rcall gaslist_strcat_gas_WREG ; print gas composition | |
346 btfss divemode ; in divemode? | |
347 bra gaslist_gastitle6 ; NO - continue printing a space | |
348 rcall gaslist_strcat_gas_type ; YES - print "*" for first gas/dil, "=" for a deco gas, or a space else | |
349 bra gaslist_gastitle7 ; - continue with change depth | |
350 gaslist_gastitle6: | |
351 PUTC " " ; print a space | |
352 gaslist_gastitle7: | |
353 lfsr FSR1,opt_gas_change ; load base address of change depths | |
354 movf gaslist_gas,W ; load gas/dil index into WREG (0-9) | |
355 movff PLUSW1,lo ; read change depth into lo | |
356 gaslist_strcat_depth: ; entry point for general printing of depths with value in meters in lo | |
357 TSTOSS opt_units ; check depth units | |
358 bra gaslist_strcat_depth_metric ; 0 - use Meters | |
359 gaslist_strcat_depth_imperial: ; 1 - use Feet | |
582 | 360 movf lo,W |
361 mullw .100 ; convert meters to mbar | |
362 movff PRODL,lo | |
363 movff PRODH,hi | |
364 call convert_mbar_to_feet ; convert value in lo:hi from mbar to feet | |
604 | 365 ;bsf leftbind |
366 output_16_3 ; limit to 999 and display only 0-999 | |
367 STRCAT_TEXT tFeets ; append "ft" REMARK: still one char to long for space available in divemode menu! | |
368 return | |
369 gaslist_strcat_depth_metric: | |
370 PUTC " " ; print a space | |
371 output_99 | |
372 STRCAT_TEXT tMeters ; "m" | |
582 | 373 return |
604 | 374 |
375 gaslist_strcat_gas_better: ; color-code output if this is the best gas/diluent | |
376 btfss better_gas_hint ; shall better gas hints be given? | |
377 return ; NO - return | |
378 movf best_gas_number,W ; get best gas number into WREG | |
379 btfsc FLAG_diluent_setup ; in CCR (pSCR) menus? | |
380 movf best_dil_number,W ; YES - overwrite with best diluent number | |
381 tstfsz WREG ; is a best gas/dil available? | |
382 bra gaslist_strcat_gas_better1 ; YES - proceed | |
383 return ; NO - return | |
384 gaslist_strcat_gas_better1: | |
385 decf WREG,W ; (1-5) -> (0-4) | |
386 btfsc FLAG_diluent_setup ; in diluent menus? | |
387 addlw .5 ; YES - add offset between gases and diluents (0-4) -> (5-9) | |
388 cpfseq gaslist_gas ; compare with given gas/dil (0-4 for OC bailout gases, 5-9 for diluents) | |
389 return ; not equal - return | |
390 bsf win_invert ; equal - invert | |
391 movlw color_green ; - select green color (gas is something "good") | |
392 goto TFT_set_color ; - activate color and return | |
393 | |
394 gaslist_strcat_gas_type: | |
395 lfsr FSR1,opt_gas_type ; load base address of gas types | |
396 movf gaslist_gas,W ; load index to WREG (0-4 for gases, 5-9 for diluents) | |
397 decf PLUSW1,W ; read gas/dil type into WREG and... | |
398 ; ...decrement by 1 (-1 for disabled, 0 for first, 1 for travel/normal, 2 for deco) | |
399 bnz gaslist_strcat_gas_type_1 ; type = first? NO - continue with checking for deco gas | |
400 PUTC "*" ; YES - print "*" for first | |
401 return ; - done | |
402 gaslist_strcat_gas_type_1: | |
403 decf WREG,W ; decrement gas type (-2 for disabled, -1 for first, 0 for travel/normal, 1 for deco) | |
404 decf WREG,W ; decrement gas type (-3 for disabled, -2 for first, -1 for travel/normal, 0 for deco) | |
405 bnz gaslist_strcat_gas_type_2 ; type = deco? NO - neither first nor deco | |
406 PUTC "=" ; YES - print "=" for a deco gas | |
407 return ; - done | |
408 gaslist_strcat_gas_type_2: | |
409 PUTC " " ; neither first nor deco, print a space | |
582 | 410 return |
0 | 411 |
412 ;---------------------------------------------------------------------------- | |
604 | 413 ; Housekeeping for the gas/dil settings, e.g. making sure there is one FIRST only |
414 ; | |
415 ; Input: gaslist_gas last edited gas/dil (0-9) | |
416 | |
417 global gaslist_cleanup_list | |
418 gaslist_cleanup_list: | |
419 lfsr FSR1,opt_gas_type ; load base address of opt_gas_type | |
420 movlw .5 ; offset between gases and diluents | |
421 btfsc FLAG_diluent_setup ; in CCR-Menu? | |
422 subwf gaslist_gas,F ; YES - subtract offset from gaslist_gas: (5-9) -> (0-4) | |
423 gaslist_cleanup_list0: | |
424 bcf ignore_last_edited_gas | |
425 gaslist_cleanup_list1: | |
426 clrf lo ; counter for number of "firsts" found | |
427 movlw .5 ; initialize hi as loop counter for checking 5 gases/diluents | |
428 movwf hi | |
429 gaslist_cleanup_list2: ; loop body | |
430 decf hi,W ; WREG = current gas/dil (0-4) | |
431 btfsc FLAG_diluent_setup ; in CCR-Menu? | |
432 addlw .5 ; YES - add offset from gases to diluents -> (5-9) | |
433 movff PLUSW1,WREG ; read type into WREG | |
434 decfsz WREG ; is type = first (ex type code 1)? | |
435 bra gaslist_cleanup_list3 ; NO - done with this gas/dil | |
436 incf lo,F ; YES - increment number of "firsts" found | |
437 btfss ignore_last_edited_gas ; - shall we ignore the last edited gas/dil? | |
438 bra gaslist_cleanup_list2b ; NO - continue remembering the "last first" gas/dil (do a shortcut) | |
439 decf hi,W ; YES - get the current gas/dil as (0-4) | |
440 cpfseq gaslist_gas ; - is this the last edited gas/dil? | |
441 gaslist_cleanup_list2b: | |
442 movff hi,up ; (NO) - remember the last "first gas" found | |
443 gaslist_cleanup_list3: | |
444 decfsz hi,F ; decrement loop counter | |
445 bra gaslist_cleanup_list2 ; loop counter became 0 ? NO - loop | |
446 tstfsz lo ; YES - any first gas/dil at all? | |
447 bra gaslist_cleanup_list4 ; YES - at least one first gas/dil existing | |
448 btfsc FLAG_diluent_setup ; NO - in CCR-Menu? | |
449 lfsr FSR1,opt_dil_type ; YES - load base address of opt_gas_type | |
450 movlw .1 ; - load coding for first gas | |
451 movwf INDF1 ; - make gas/dil 1 the first gas | |
452 return ; - done | |
453 gaslist_cleanup_list4: | |
454 movlw .1 | |
455 cpfsgt lo ; more then one "first gas" found? | |
456 return ; NO - done | |
457 decf up,W ; YES - WREG = last found "first gas" - 1 (0-4) | |
458 cpfseq gaslist_gas ; - is this the last edited gas/dil? | |
459 bra gaslist_cleanup_list4b ; NO - disable it | |
460 bsf ignore_last_edited_gas ; YES - do not disable last edited gas, search again but ignore the last edited gas | |
461 bra gaslist_cleanup_list1 ; - loop until only one "first" is left over | |
462 gaslist_cleanup_list4b: | |
463 btfsc FLAG_diluent_setup ; in CCR-Menu? | |
464 addlw .5 ; YES - adjust offset | |
465 clrf PLUSW1 ; disable gas | |
466 bra gaslist_cleanup_list0 ; redo from start until only one "first" is left over | |
467 return | |
468 | |
469 ;---------------------------------------------------------------------------- | |
470 ; Tank Settings | |
471 ; | |
472 ; Inputs: char_I_tank_size size of the tank, using unit text tLiter ("l") | |
473 ; char_I_tank_pres_fill fill pressure in multiples of 10 bar, using unit text tbar10 ("0 bar") | |
582 | 474 |
604 | 475 global gaslist_tank_size_pres |
476 gaslist_tank_size_pres: ; dynamic title: xx l, xx0 bar | |
477 lfsr FSR1,char_I_tank_size ; load base address of char_I_tank_size | |
478 movf gaslist_gas,W ; load index (0-9) | |
479 movff PLUSW1,lo ; read char_I_tank_size[WREG] into lo | |
480 lfsr FSR1,char_I_tank_pres_fill ; load base address of char_I_tank_pres_fill | |
481 movff PLUSW1,hi ; read char_I_tank_pres_fill[WREG] into hi | |
482 STRCAT " " ; print 5 leading spaces for alignment | |
483 output_8 ; print tank size | |
484 STRCAT_TEXT tLiter ; print unit (" l") | |
485 movff hi,lo ; copy fill pressure into lo | |
486 output_8 ; print fill pressure (it is stored in multiples of 10 bar) | |
487 STRCAT_TEXT tbar10 ; print unit ("0 bar") | |
488 return | |
489 | |
490 global gaslist_tank_size | |
491 gaslist_tank_size: ; adjust char_I_tank_size between min_tank_size and max_tank_size | |
492 lfsr FSR1,char_I_tank_size ; load base address of char_I_tank_size | |
493 movf gaslist_gas,W ; load index (0-9) | |
494 movff PLUSW1,lo ; read char_I_tank_size[WREG] into lo | |
495 incf lo,F ; increment tank size by 1 liter | |
496 movlw max_tank_size ; load max. allowed value into WREG | |
497 cpfsgt lo ; tank size <= max value? | |
498 bra gaslist_tank_size_1 ; YES - new value can be used | |
499 movlw min_tank_size ; NO - wrap-around to min value | |
500 movwf lo ; - and write to lo | |
501 gaslist_tank_size_1: | |
502 movf gaslist_gas,W ; re-load index | |
503 movff lo,PLUSW1 ; write back tank size to char_I_tank_size[WREG] | |
504 return | |
505 | |
506 global gaslist_tank_pres | |
507 gaslist_tank_pres: ; adjust char_I_tank_pres_fill between 5(0) and 29(0) bar | |
508 lfsr FSR1,char_I_tank_pres_fill ; load base address of char_I_tank_pres_fill | |
509 movf gaslist_gas,W ; load index (0-9) | |
510 movff PLUSW1,lo ; read char_I_tank_pres_fill[WREG] into lo | |
511 incf lo,F ; increment fill press by by 1(0) bar | |
512 movlw max_fill_press ; load max. allowed value into WREG | |
513 cpfsgt lo ; press <= max value? | |
514 bra gaslist_tank_pres_1 ; YES - new value can be used | |
515 movlw min_fill_press ; NO - wrap-around to min value | |
516 movwf lo ; - and write to lo | |
517 gaslist_tank_pres_1: | |
518 movf gaslist_gas,W ; re-load index | |
519 movff lo,PLUSW1 ; write back tank size to char_I_tank_pres_fill[WREG] | |
520 return | |
521 | |
522 ;---------------------------------------------------------------------------- | |
523 ; Transmitter functions | |
524 | |
525 IFDEF _rx_functions | |
526 | |
527 global gaslist_tank_id_pres | |
528 gaslist_tank_id_pres: ; dynamic title: shows ID and pressure from transmitter with ID opt_transmitter_id[gaslist_gas] | |
529 ; When changing layout, adapt output position TFT_menu_tank_pres! | |
530 STRCAT " ID: " ; print header | |
531 ; get ID ; | |
532 lfsr FSR1,opt_transmitter_id_1 ; load base address of opt_transmitter_id | |
533 movf gaslist_gas,W ; load index (0-9) | |
534 rlncf WREG,W ; multiply by 2 because IDs are 2 byte in size | |
535 movff PLUSW1,lo ; copy opt_transmitter_id+0[gaslist_gas] to lo | |
536 incf WREG,W ; increment index | |
537 movff PLUSW1,hi ; copy opt_transmitter_id+1[gaslist_gas] to hi | |
538 ; check if a transmitter is paired to this tank | |
539 tstfsz hi ; high byte of ID <> 0 ? | |
540 bra gaslist_tank_id_pres_1 ; YES - a transmitter is paired to the tank | |
541 tstfsz lo ; low byte of ID <> 0 ? | |
542 bra gaslist_tank_id_pres_1 ; YES - a transmitter is paired to the tank | |
543 ; no transmitter paired | |
544 STRCAT "----" ; | |
545 bcf menu_update_tank_pres ; stop imprinting of tank pressure updates | |
546 return | |
547 gaslist_tank_id_pres_1: | |
548 ; show ID | |
549 movf hi,W ; copy high byte of ID to WREG | |
550 output_hex ; print it | |
551 movf lo,W ; copy low byte of ID to WREG | |
552 output_hex ; print it | |
553 bsf menu_update_tank_pres ; start imprinting of tank pressure updates | |
582 | 554 return |
0 | 555 |
556 | |
604 | 557 global gaslist_tank_pairing |
558 gaslist_tank_pairing: | |
559 incf pairing_slot,F ; goto next RX data slot | |
560 btfsc pairing_slot,3 ; slot = 8? | |
561 bra gaslist_tank_pairing_none ; YES - offer unpairing | |
562 movf pairing_slot,W ; NO - copy slot to WREG | |
563 call get_transmitter_id_by_slot ; WREG = slot (0-7) -> hi:lo = transmitter ID | |
564 tstfsz hi ; transmitter found (probe on high byte)? | |
565 bra gaslist_tank_pairing_common ; YES - select this transmitter | |
566 tstfsz hi ; transmitter found (probe on low byte)? | |
567 bra gaslist_tank_pairing_common ; YES - select this transmitter | |
568 bra gaslist_tank_pairing ; NO - try next slot | |
569 gaslist_tank_pairing_common: | |
570 lfsr FSR1,opt_transmitter_id_1 ; load base address of opt_transmitter_id | |
571 movf gaslist_gas,W ; load index into WREG (0-9) | |
572 rlncf WREG,W ; multiply by 2 because IDs are 2 byte in size | |
573 movff lo,PLUSW1 ; copy lo to opt_transmitter_id+0[gaslist_gas] | |
574 incf WREG,W ; increment index | |
575 movff hi,PLUSW1 ; copy hi to opt_transmitter_id+1[gaslist_gas] | |
576 return ; done | |
577 gaslist_tank_pairing_none: | |
578 setf pairing_slot ; prime slot number with 255 aka -1 | |
579 clrf hi ; adjust "no transmitter" ID | |
580 clrf lo ; adjust "no transmitter" ID | |
581 bra gaslist_tank_pairing_common ; continue with common part | |
582 | |
583 ENDIF | |
0 | 584 |
585 ;---------------------------------------------------------------------------- | |
586 ; Increment/Decrement O2 ratio | |
582 | 587 |
588 global gaslist_pO2 | |
0 | 589 gaslist_pO2: |
604 | 590 movf gaslist_gas,W ; load index (0-9) |
591 lfsr FSR1,opt_gas_He_ratio ; load base address of opt_gas_He_ratio | |
592 movff PLUSW1,hi ; read He ratio into hi | |
593 lfsr FSR1,opt_gas_O2_ratio ; load base address of opt_gas_O2_ratio | |
594 movff PLUSW1,lo ; read O2 ratio into lo | |
0 | 595 |
582 | 596 incf lo,F ; O2++ |
597 movf hi,W ; get He ratio into WREG | |
598 addwf lo,W ; add O2 ratio to WREG | |
599 movwf up ; move sum He + O2 to up | |
600 movlw .101 ; | |
601 cpfslt up ; O2 + He < 101? | |
602 decf lo,F ; O2-- (revoke ++) | |
604 | 603 movf gaslist_gas,W ; re-load index |
582 | 604 movff lo,PLUSW1 ; write back O2 ratio to opt_gas_O2_ratio[WREG] |
605 return | |
606 | |
607 global gaslist_mO2 | |
0 | 608 gaslist_mO2: |
604 | 609 movf gaslist_gas,W ; load index (0-9) |
610 lfsr FSR1,opt_gas_O2_ratio ; load base address of opt_gas_O2_ratio | |
611 movff PLUSW1,lo ; read O2 ratio into lo | |
0 | 612 |
582 | 613 decf lo,F ; O2-- |
614 movlw gaslist_min_o2 ; get minimum allowed O2 ratio | |
615 cpfslt lo ; current O2 ratio below allowed minimum? | |
616 bra gaslist_mO2_1 ; NO | |
604 | 617 movwf lo ; YES - copy minimum O2 ratio to lo |
0 | 618 gaslist_mO2_1: |
604 | 619 movf gaslist_gas,W ; re-load index |
582 | 620 movff lo,PLUSW1 ; write back O2 ratio to opt_gas_O2_ratio[WREG] |
621 return | |
0 | 622 |
623 ;---------------------------------------------------------------------------- | |
624 ; Increment/Decrement He ratio | |
582 | 625 |
626 global gaslist_pHe | |
0 | 627 gaslist_pHe: |
604 | 628 movf gaslist_gas,W ; load index (0-9) |
629 lfsr FSR1,opt_gas_O2_ratio ; load base address of opt_gas_O2_ratio | |
630 movff PLUSW1,lo ; read O2 ratio into lo | |
631 lfsr FSR1,opt_gas_He_ratio ; load base address of opt_gas_He_ratio | |
632 movff PLUSW1,hi ; read He ratio into hi | |
0 | 633 |
582 | 634 incf hi,F ; He++ |
635 movf hi,W ; get He ratio into WREG | |
636 addwf lo,W ; add O2 ratio to WREG | |
637 movwf up ; move sum He + O2 to up | |
638 movlw .101 ; | |
639 cpfslt up ; O2 + He < 101? | |
640 decf hi,F ; He-- (revoke ++) | |
604 | 641 movf gaslist_gas,W ; re-load index |
582 | 642 movff hi,PLUSW1 ; write back He ratio to opt_gas_He_ratio[WREG] |
643 return | |
0 | 644 |
582 | 645 global gaslist_mHe |
0 | 646 gaslist_mHe: |
604 | 647 movf gaslist_gas,W ; load index (0-9) |
648 lfsr FSR1,opt_gas_He_ratio ; load base address of opt_gas_He_ratio | |
649 movff PLUSW1,hi ; read He ratio into hi | |
0 | 650 |
582 | 651 decf hi,F ; He-- |
652 bnn gaslist_mHe_1 ; He ratio negative? | |
604 | 653 clrf hi ; YES - set He ratio to 0 |
0 | 654 gaslist_mHe_1: |
604 | 655 movf gaslist_gas,W ; re-load index |
582 | 656 movff hi,PLUSW1 ; write back He ratio to opt_gas_He_ratio[WREG] |
657 return | |
0 | 658 |
659 ;---------------------------------------------------------------------------- | |
660 ; Increment/Decrement switch depth | |
661 | |
582 | 662 global gaslist_pDepth |
663 gaslist_pDepth: | |
604 | 664 lfsr FSR1,opt_gas_change ; load base address of opt_gas_change |
665 movf gaslist_gas,W ; load index (0-4) | |
666 movff PLUSW1,lo ; read switch depth into lo | |
667 incf lo,F ; increment switch depth | |
668 movlw gaslist_max_change_depth ; get max change depth | |
669 cpfsgt lo ; above max change depth? | |
670 bra gaslist_pDepth_1 ; NO | |
671 movwf lo ; YES - revert to max change depth | |
0 | 672 gaslist_pDepth_1: |
604 | 673 movf gaslist_gas,W ; re-load index |
674 movff lo,PLUSW1 ; write back switch depth | |
582 | 675 return |
676 | |
677 global gaslist_mDepth | |
0 | 678 gaslist_mDepth: |
604 | 679 lfsr FSR1,opt_gas_change ; load base address of opt_gas_change |
680 movf gaslist_gas,W ; load index (0-4) | |
681 movff PLUSW1,lo ; read switch depth into lo | |
682 decf lo,F ; decrement switch depth | |
683 btfsc STATUS,N ; did depth became negative? | |
684 clrf lo ; YES - reset to zero | |
685 movff lo,PLUSW1 ; write back switch depth | |
582 | 686 return |
0 | 687 |
582 | 688 global gaslist_spplus |
0 | 689 gaslist_spplus: |
582 | 690 movf gaslist_gas,W |
691 lfsr FSR1,char_I_setpoint_cbar | |
604 | 692 movff PLUSW1,lo ; read setpoint |
582 | 693 movlw gaslist_sp_stepsize |
694 addwf lo,F | |
695 movlw gaslist_sp_max | |
696 cpfsgt lo | |
697 bra gaslist_spplus2 | |
698 movlw gaslist_sp_min | |
699 movwf lo | |
0 | 700 gaslist_spplus2: |
582 | 701 movf gaslist_gas,W |
604 | 702 movff lo,PLUSW1 ; write back setpoint |
582 | 703 return |
704 | |
705 global gaslist_spdepthplus | |
0 | 706 gaslist_spdepthplus: |
604 | 707 movf gaslist_gas,W ; get setpoint number (0-4) |
708 bz gaslist_spdepthplus2 ; setpoint number = 0? YES - force depth to always be 0m | |
709 lfsr FSR1,char_I_setpoint_change ; load base address of char_I_setpoint_change | |
710 movff PLUSW1,lo ; read setpoint depth into lo | |
711 incf lo,F ; increment depth | |
712 movlw gaslist_max_change_depth ; get max. depth | |
713 cpfsgt lo ; switch depth > max. depth? | |
714 bra gaslist_spdepthplus_1 ; NO | |
715 movwf lo ; YES - copy to lo | |
0 | 716 gaslist_spdepthplus_1: |
604 | 717 movf gaslist_gas,W ; re-load index |
718 movff lo,PLUSW1 ; write back setpoint depth | |
582 | 719 return |
0 | 720 |
582 | 721 global gaslist_spdepthminus |
0 | 722 gaslist_spdepthminus: |
604 | 723 movf gaslist_gas,W ; get setpoint number (0-4) |
724 bz gaslist_spdepthminus2 ; setpoint number = 0? YES - force depth to always be 0m | |
725 lfsr FSR1,char_I_setpoint_change ; load base address of char_I_setpoint_change | |
726 movff PLUSW1,lo ; read setpoint depth into lo | |
727 decf lo,F ; decrement switch depth | |
728 btfsc STATUS,N ; did depth became negative? | |
729 clrf lo ; YES - reset to zero | |
730 movff lo,PLUSW1 ; write back setpoint depth | |
582 | 731 return |
0 | 732 |
604 | 733 gaslist_spdepthplus2: |
734 gaslist_spdepthminus2: | |
735 movlw .0 | |
736 movff WREG,char_I_setpoint_change+0 ; hard reset to 0m | |
737 return | |
738 | |
739 | |
0 | 740 ;---------------------------------------------------------------------------- |
604 | 741 ; Compute MOD from char_I_ppO2_max/char_I_ppO2_max_deco and current O2 ratio |
0 | 742 ; |
582 | 743 ; Input: gaslist_gas = current gas index. |
0 | 744 ; opt_gas_O2_ratio[gaslist_gas] = current O2 ratio |
582 | 745 ; Output: WREG = MOD [m] |
0 | 746 ; |
747 gaslist_calc_mod: | |
604 | 748 movf gaslist_gas,W ; load index (0...9) |
749 lfsr FSR1,opt_gas_O2_ratio ; load base address of opt_gas_O2_ratio | |
750 movff PLUSW1,xB+0 ; read O2 ratio into xB+0 | |
751 lfsr FSR1,opt_gas_type ; load base address of opt_gas_type | |
752 movff PLUSW1,xA+0 ; read gas/dil type into xA+0 (used as temp here) | |
753 movff char_I_ppO2_max_deco,xB+1 ; get max ppO2 for deco into xB+1 (used as temp here) | |
754 movlw .3 ; type code for deco gases | |
755 cpfseq xA+0 ; is it a deco gas? | |
756 movff char_I_ppO2_max,xB+1 ; NO - overwrite ppO2 max with none-deco max | |
757 movf xB+1,W ; copy resulting ppO2 max into WREG | |
758 clrf xB+1 ; clear xB+1 for div16x16 operation | |
759 mullw .10 ; multiply ppO2 max value with 10 | |
760 movff PRODL,xA+0 ; copy result to xA | |
582 | 761 movff PRODH,xA+1 |
604 | 762 call div16x16 ; xC = xA / xB with xA as remainder |
763 movf xC+0,W ; copy result to WREG | |
764 addlw -.10 ; subtract 10 cbar | |
765 return ; return with final result in WREG | |
582 | 766 |
0 | 767 ;---------------------------------------------------------------------------- |
154
afa31c815f24
NEW: Show ppO2 for change depth during gas setup
heinrichsweikamp
parents:
97
diff
changeset
|
768 |
582 | 769 global gaslist_ppo2 |
154
afa31c815f24
NEW: Show ppO2 for change depth during gas setup
heinrichsweikamp
parents:
97
diff
changeset
|
770 gaslist_ppo2: |
582 | 771 STRCAT_TEXT tppO2 ; ppO2: |
604 | 772 lfsr FSR1,opt_gas_change ; load base address of opt_gas_change |
773 movf gaslist_gas,W ; load index (0-9) | |
774 movf PLUSW1,W ; read change depth into WREG | |
775 mullw .10 ; PROD = depth in mbar/10 (100 = 1.00 bar) | |
776 movlw .100 ; add 1 bar | |
582 | 777 addwf PRODL,F |
778 movlw .0 | |
604 | 779 addwfc PRODH,F |
780 movff PRODL,xA+0 ; copy result to xA | |
582 | 781 movff PRODH,xA+1 |
604 | 782 lfsr FSR1,opt_gas_O2_ratio ; load base address of opt_gas_O2_ratio |
783 movf gaslist_gas,W ; load index (0-9) | |
784 movff PLUSW1,xB+0 ; read O2 ratio into xB+0 | |
785 clrf xB+1 ; clear xB+1 | |
786 call mult16x16 ; calculate char_I_O2_ratio * (p_amb/10) | |
787 movff xC+0,xA+0 ; copy result to xA | |
582 | 788 movff xC+1,xA+1 |
604 | 789 movlw d'100' ; load 100 to xB |
582 | 790 movwf xB+0 |
791 clrf xB+1 | |
604 | 792 call div16x16 ; xC = xA / xB = (char_I_O2_ratio * p_amb/10)/100 |
793 ; check for very high ppO2 | |
794 tstfsz xC+2 ; xC+2 remains from mult16x16, xC+2 > 0 (-> ppO2 is > 6.55 bar) ? | |
795 bra gaslist_ppo2_1 ; YES - display a fixed max value | |
796 movff xC+0,lo ; copy result to lo, hi | |
582 | 797 movff xC+1,hi |
798 bcf ignore_digit4 | |
799 bsf leftbind | |
604 | 800 output_16dp d'3' ; print ppO2 as x.xx |
801 STRCAT_TEXT tbar ; print "bar" | |
582 | 802 return |
604 | 803 gaslist_ppo2_1: |
582 | 804 STRCAT ">6.6" |
805 return | |
154
afa31c815f24
NEW: Show ppO2 for change depth during gas setup
heinrichsweikamp
parents:
97
diff
changeset
|
806 |
582 | 807 global gaslist_MOD_END |
0 | 808 gaslist_MOD_END: |
604 | 809 STRCAT_TEXT tMOD ; print "MOD:" |
810 rcall gaslist_calc_mod ; compute MOD into WREG | |
811 movwf lo ; copy result to lo | |
812 call gaslist_strcat_depth ; print depth in meters or feet as configured | |
813 PUTC "/" ; print "/" | |
814 STRCAT_TEXT tEND ; print "END:" | |
815 rcall gaslist_calc_mod ; compute MOD into WREG | |
816 addlw .10 ; compute MOD = MOD + 10m | |
582 | 817 movwf xB+0 |
818 clrf xB+1 | |
819 movlw d'100' | |
820 movwf xA+0 | |
604 | 821 lfsr FSR1,opt_gas_He_ratio ; load base address of opt_gas_He_ratio |
822 movf gaslist_gas,W ; load index (0...9) | |
823 movf PLUSW1,W ; read He ration into WREG | |
824 subwf xA+0,F ; xA+0 = 100 - He ratio in % | |
582 | 825 clrf xA+1 |
826 call mult16x16 ; xA*xB=xC | |
827 movff xC+0,xA+0 | |
828 movff xC+1,xA+1 | |
829 movlw d'100' | |
830 movwf xB+0 | |
831 clrf xB+1 | |
604 | 832 call div16x16 ; xC = xA / xB with xA as remainder |
582 | 833 ; ; xC:2 = ((MOD+10) * 100 - HE Value in %) / 100 |
604 | 834 movlw d'10' ; subtract 10 m |
835 subwf xC+0,F ; ... | |
836 movff xC+0,lo ; copy result to lo | |
837 bra gaslist_strcat_depth ; print depth in meters or feet as configured and return | |
838 | |
839 | |
840 global gaslist_reset_mod_title | |
841 gaslist_reset_mod_title: | |
842 STRCAT_TEXT tDepthReset | |
843 rcall gaslist_calc_mod ; compute MOD into WREG | |
844 movwf lo ; copy result to lo | |
845 lfsr FSR1,opt_gas_change ; load base address of opt_gas_change | |
846 movf gaslist_gas,W ; load index (0-9) | |
847 movf PLUSW1,W ; read change depth into WREG | |
848 cpfslt lo ; change depth > MOD ? | |
849 bra gaslist_strcat_depth ; NO - return | |
850 call TFT_warnings_color ; YES - use red color | |
851 bra gaslist_strcat_depth ; - return | |
852 | |
853 | |
854 global gaslist_reset_mod | |
855 gaslist_reset_mod: | |
856 rcall gaslist_calc_mod ; compute MOD into WREG | |
857 movwf lo ; copy result to lo | |
858 lfsr FSR1,opt_gas_change ; load base address of opt_gas_change | |
859 movf gaslist_gas,W ; load index (0-9) | |
860 movff lo,PLUSW1 ; write back new change depth | |
582 | 861 return |
0 | 862 |
863 ;---------------------------------------------------------------------------- | |
582 | 864 END |