comparison src/divemode.asm @ 604:ca4556fb60b9

bump to 2.99beta, work on 3.00 stable
author heinrichsweikamp
date Thu, 22 Nov 2018 19:47:26 +0100
parents 08a0162d3ca1
children 5ce603c29750
comparison
equal deleted inserted replaced
603:00b24fb4324d 604:ca4556fb60b9
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File divemode.asm REFACTORED VERSION V2.98 3 ; File divemode.asm REFACTORED VERSION V2.99e
4 ; 4 ;
5 ; Divemode 5 ; Divemode
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
9 ; HISTORY 9 ; HISTORY
10 ; 2011-08-15 : [mH] moving from OSTC code 10 ; 2011-08-15 : [mH] moving from OSTC code
11 11
12 #include "hwos.inc" ; Mandatory header 12 #include "hwos.inc" ; mandatory header
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c 13 #include "shared_definitions.h" ; mailbox from/to p2_deco.c
14 #include "tft_outputs.inc" 14 #include "tft_outputs.inc"
15 #include "strings.inc" 15 #include "strings.inc"
16 #include "tft.inc" 16 #include "tft.inc"
17 #include "eeprom_rs232.inc" 17 #include "eeprom_rs232.inc"
18 #include "isr.inc" 18 #include "isr.inc"
24 #include "ghostwriter.inc" 24 #include "ghostwriter.inc"
25 #include "i2c.inc" 25 #include "i2c.inc"
26 #include "calibrate.inc" 26 #include "calibrate.inc"
27 #include "convert.inc" 27 #include "convert.inc"
28 28
29 IFDEF _rx_functions
30 #include "rx_ops.inc"
31 ENDIF
32
29 33
30 extern TFT_dive_compass_heading 34 extern TFT_dive_compass_heading
31 extern do_line_menu 35 extern do_line_menu
32 extern do_main_divemenu 36 extern do_main_divemenu
33 extern option_save_all 37 extern option_save_all
36 40
37 ;---- Private local variables ------------------------------------------------- 41 ;---- Private local variables -------------------------------------------------
38 42
39 CBLOCK local1 ; max size is 16 Byte !!! 43 CBLOCK local1 ; max size is 16 Byte !!!
40 apnoe_timeout_counter ; timeout counter for apnoe mode 44 apnoe_timeout_counter ; timeout counter for apnoe mode
41 average_depth_hold:4 ; used in calculation of the average depth
42 sensor_setpoint ; sensor ppo2 in 0.01bar for deco routine 45 sensor_setpoint ; sensor ppo2 in 0.01bar for deco routine
43 active_diluent ; backup of diluent gas for when switching back from bailout to CCR/pSCR loop 46 check_gas_num ; used in search for best gas/dil: current gas/dil number (1-5)
44 average_depth_hold_total:4 ; used to calculate the average depth 47 check_gas_depth ; used in search for best gas/dil: current gas/dil change depth
45 ENDC ; used: 11 byte, remaining: 5 byte 48 check_gas_type ; used in search for best gas/dil: current gas/dil type
46 49 check_gas_O2_ratio ; used in search for best gas/dil: current gas/dil O2 ratio
47 gui CODE 50 best_gas_num ; used in search for best gas/dil: best gas/dil number (1-5) CAUTION: there is also a variable named best_gas_number !
51 best_gas_depth ; used in search for best gas/dil: best gas/dil change depth
52 ppO2_min ; used in search for best gas/dil: minimum ppO2 required
53 ppO2_max ; used in search for best gas/dil: maximum ppO2 allowed
54 ENDC ; used: 10 byte, remaining: 6 byte
55
56 CBLOCK local2 ; max size is 16 Byte !!!
57 average_depth_hold:4 ; used to calculate the resettable average depth
58 average_depth_hold_total:4 ; used to calculate the absolute average depth
59 ENDC ; used: 8 byte, remaining: 8 byte
60
61 dmode CODE
48 62
49 ;============================================================================= 63 ;=============================================================================
50 64
51 global diveloop 65 global diveloop
52 diveloop: 66 diveloop:
53 banksel common 67 banksel common
54 call speed_normal 68 call speed_normal
55 call diveloop_boot ; Boot tasks for all modes 69 call diveloop_boot ; boot tasks for all modes
56 70
57 ; Startup Tasks for all modes 71 ; startup tasks for all modes
58 call TFT_boot ; Initialize TFT (includes clear screen) 72 call TFT_boot ; initialize TFT (includes clear screen)
59 bsf FLAG_TFT_divemode_mask ; Display mask 73 bsf FLAG_TFT_divemode_mask ; request display of dive mode mask
60 movff customview_divemode,menupos3; Reload last customview 74
61 call customview_mask ; Redraw last custom view 75 movff customview_divemode,menupos3; reload last custom view
76 bsf redraw_custview_mask ; request redraw of last custom view
62 77
63 btfsc FLAG_apnoe_mode 78 btfsc FLAG_apnoe_mode
64 bsf realdive ; Set Realdive flag in Apnoe mode 79 bsf realdive ; set realdive flag in apnoe mode
65 80
66 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode 81 btfsc FLAG_apnoe_mode ; done for apnoe or gauge mode
67 bra diveloop_loop_start 82 bra diveloop_loop_start
68 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode 83 btfsc FLAG_gauge_mode ; done for apnoe or gauge mode
69 bra diveloop_loop_start 84 bra diveloop_loop_start
70 85
71 bsf FLAG_TFT_display_ndl_mask ; display "NDL" 86 ; Deco modes
87 bsf FLAG_TFT_active_gas_divemode; request display of gas and setpoint
88 bsf FLAG_TFT_display_ndl_mask ; request display of "NDL"
72 89
73 ; +@5 init 90 ; +@5 init
74 clrf WREG ; WAIT marker: display "---" 91 clrf WREG ; WAIT marker: display "---"
75 movff WREG,char_I_sim_advance_time 92 movff WREG,char_I_sim_advance_time
76 movff WREG,int_O_alternate_ascenttime+0 93 movff WREG,int_O_alternate_ascenttime+0
77 bsf WREG,int_not_yet_computed 94 bsf WREG,int_not_yet_computed
78 bsf WREG,int_invalid_flag 95 bsf WREG,int_invalid_flag
79 movff WREG,int_O_alternate_ascenttime+1 96 movff WREG,int_O_alternate_ascenttime+1
80 97
81 diveloop_loop_start: 98 diveloop_loop_start:
99 btfsc FLAG_TFT_divemode_mask
100 call TFT_divemode_mask
82 btfsc FLAG_TFT_display_ndl_mask 101 btfsc FLAG_TFT_display_ndl_mask
83 call TFT_display_ndl_mask 102 call TFT_display_ndl_mask
84 103
85 104 diveloop_loop: ; the dive loop starts here
86 diveloop_loop: ; The diveloop starts here
87 btfss quarter_second_update 105 btfss quarter_second_update
88 bra diveloop_loop1 106 bra diveloop_loop1
89 107
90 ; tasks any 1/4 second, any mode 108 ; tasks any 1/4 second, any mode
91 bcf quarter_second_update ; clear flag 109 bcf quarter_second_update ; clear flag
92 110
93 movlw .6 111 btfsc alternative_divelayout ; in alternative layout?
94 cpfseq menupos3 ; in compass view? 112 bra diveloop_loop1 ; YES - no compass in alternative layout mode
95 bra diveloop_loop1 ; No, done. 113 movlw index_compass_dm ; NO - index of compass view
96 114 cpfseq menupos3 ; - in compass view?
97 btfsc alternative_divelayout ; In alternative layout mode? 115 bra diveloop_loop1 ; NO - done
98 bra diveloop_loop1 ; Yes, done. No Compass. 116 call TFT_dive_compass_heading ; YES - update compass heading value
99 117 bsf FLAG_TFT_temp_divemode ; - redraw temperature (is slightly affected from compass heading arrow)
100 ; TFT Output routines
101 call TFT_dive_compass_heading ; Yes, update compass heading value
102 bsf FLAG_TFT_temp_divemode ; Redraw temperature (is slightly affected from compass heading arrow)
103 ; TFT Output routines
104 118
105 diveloop_loop1: 119 diveloop_loop1:
106 btfss onesecupdate 120 btfss onesecupdate ; next second begun?
107 bra diveloop_loop3 121 bra diveloop_loop3 ; NO
108 122
109 ; tasks any new second... 123 ; tasks any new second...
110 bcf onesecupdate ; one seconds update, clear flag here in case it's set again in ISR before all tasks are done. 124 bcf onesecupdate ; one seconds update, clear flag here in case it's set again in ISR before all tasks are done.
111 125
112 ;bsf LEDg ; ### USE FOR DEBUG ONLY - RESETS RX CIRCUITRY ### 126 ; ###-- USE FOR DEBUG ONLY - RESETS RX CIRCUITRY --###
127 ; bsf LEDg
128 ; ###----------------------------------------------###
129
130 ; compute current depth in meters
131 SAFE_2BYTE_COPY rel_pressure,xA
132 movlw .100
133 movwf xB+0
134 clrf xB+1
135 call div16x16 ; xC = xA / xB, xC+0 now holds depth in full meters
136 movff xC+0,curr_depth ; store result in curr_depth
137
138 ; compute ambient pressure / 10, will be needed later
139 SAFE_2BYTE_COPY amb_pressure,xA
140 movlw .10
141 movwf xB+0
142 clrf xB+1
143 call div16x16 ; xC = xA / xB = p_amb / 10
144 movff xC+0,amb_press_10+0 ; store result for later use
145 movff xC+1,amb_press_10+1 ; ...
113 146
114 ; display depth based on full seconds interval (nicer blinking) 147 ; display depth based on full seconds interval (nicer blinking)
115 btfss alternative_divelayout 148 btfss alternative_divelayout
116 rcall TFT_output4_normal 149 rcall TFT_output4_normal
117 btfsc alternative_divelayout 150 btfsc alternative_divelayout
118 rcall TFT_output4_alternative 151 rcall TFT_output4_alternative
119 152
120 btfsc FLAG_apnoe_mode ; Only in apnoe mode 153 btfsc FLAG_apnoe_mode ; in Apnoe mode?
121 bra diveloop_loop1_nonedeco ; One Second Tasks in Apnoe mode 154 bra diveloop_loop1_nonedeco ; YES - do Apnoe mode every second tasks
122 155
123 ; tasks any new second - only for deco modes 156 ; tasks any new second - only for deco modes
124 diveloop_loop1_decomodes: 157 diveloop_loop1_deco:
125 bsf FLAG_TFT_divemins ; Display (new) divetime! 158 bsf FLAG_TFT_divemins ; display (new) dive time!
126 btfsc show_safety_stop ; Show the safety stop? 159 btfsc show_safety_stop ; show the safety stop?
127 bsf FLAG_TFT_show_safety_stop ; Yes, show/delete if done. 160 bsf FLAG_TFT_show_safety_stop ; YES - show/delete if done
128 161
129 btfss alternative_divelayout 162 btfss alternative_divelayout
130 rcall TFT_output1_normal 163 rcall TFT_output1_normal
131 btfsc alternative_divelayout 164 btfsc alternative_divelayout
132 rcall TFT_output1_alternative 165 rcall TFT_output1_alternative
133 166
134 btfsc FLAG_ccr_mode ; in CCR mode... 167 call divemode_check_for_warnings ; check for warnings
135 call check_dive_autosp ; ...check for Auto-SP 168
169 IFDEF _rx_functions
170 btfss FLAG_tr_enabled ; TR functions enabled?
171 bra diveloop_loop1_deco1 ; NO - skip pressure readings part
172 call get_pressure_readings ; YES - get pressure readings
173 call configure_sac_calculation ; - set up SAC calculation
174 diveloop_loop1_deco1:
175 ENDIF
136 176
137 call calc_deko_divemode ; calculate decompression and set resulting display flags 177 call calc_deko_divemode ; calculate decompression and set resulting display flags
138 178
139 btfss alternative_divelayout 179 btfss alternative_divelayout
140 rcall TFT_output2_normal 180 rcall TFT_output2_normal
141 btfsc alternative_divelayout 181 btfsc alternative_divelayout
142 rcall TFT_output2_alternative 182 rcall TFT_output2_alternative
143 183 bra diveloop_loop2 ; continue with common tasks
144 call divemode_check_for_warnings ; Check for any warnings
145
146 bra diveloop_loop2 ; Common Tasks
147
148 184
149 ; tasks any new second - only for apnoe mode 185 ; tasks any new second - only for apnoe mode
150 diveloop_loop1_nonedeco: 186 diveloop_loop1_nonedeco:
151 rcall divemode_apnoe_tasks ; 1 sec. Apnoe tasks 187 rcall divemode_apnoe_tasks ; 1 sec. apnoe tasks
152 call customview_second ; Do every-second tasks for the custom view area 188 call customview_second ; do every-second tasks for the custom view area
153 ;bra diveloop_loop2 ; Common Tasks 189 ;bra diveloop_loop2 ; common tasks
154 190
155 ; continue tasks any new second, any mode 191 ; continue tasks any new second, any mode
156 diveloop_loop2: 192 diveloop_loop2:
157 rcall timeout_divemode ; ** menu timeout? ** This routine sets the required flags 193 btfsc redraw_custview_mask ; shall we redraw the custom view mask?
194 call customview_mask ; YES - redraw custom view mask
195
196 rcall timeout_divemode ; ** menu timeout? ** - this routine sets the required flags
158 rcall set_dive_modes ; tests if depth > threshold 197 rcall set_dive_modes ; tests if depth > threshold
159 rcall set_min_temp ; store min. temp if required (Future hardware will need this to be checked 1/second...) 198 rcall set_min_temp ; store min. temp if required (future hardware will need this to be checked 1/second...)
160 199
161 btfsc oneminupdate ; one minute tasks 200 btfsc oneminupdate ; one minute tasks
162 rcall update_divemode60 ; Update clock, etc. 201 rcall update_divemode60 ; update clock, etc.
202
203 btfss FLAG_oc_mode ; are we in OC mode?
204 bsf FLAG_TFT_active_gas_divemode; NO - have the gas and setpoint redrawn on every second to update setpoint display, animate the blinking, etc.
163 205
164 btfss alternative_divelayout 206 btfss alternative_divelayout
165 rcall TFT_output3_normal 207 rcall TFT_output3_normal
166 btfsc alternative_divelayout 208 btfsc alternative_divelayout
167 rcall TFT_output3_alternative 209 rcall TFT_output3_alternative
168 210
169 ;bcf LEDg ; ### USE FOR DEBUG ONLY - RESETS RX CIRCUITRY ### 211 ; ###-- USE FOR DEBUG ONLY - RESETS RX CIRCUITRY --###
212 ; bcf LEDg
213 ; ###----------------------------------------------###
170 214
171 ; tasks any round, any mode 215 ; tasks any round, any mode
172 diveloop_loop3: 216 diveloop_loop3:
173 call test_switches_divemode ; Check switches in divemode 217 call test_switches_divemode ; check switches in dive mode
174 218
175 global diveloop_loop4 219 global diveloop_loop4
176 diveloop_loop4: ; Menu-Exit returns here... 220 diveloop_loop4: ; menu-exit returns here...
177 btfsc divemode_menu ; in the big divemode menu? 221 btfsc toggle_customview ; next view?
178 bra diveloop_loop4b ; YES - no space for CCR/pSCR info 222 call customview_toggle ; YES - show next custom view (and delete this flag)
179 btfsc menuview ; NO - in the small yellow menu? 223
180 bra diveloop_loop4b ; YES - no space for CCR/pSCR info 224 btfsc divemode_gaschange ; gas switch flag set?
181 btfsc alternative_divelayout ; NO - in the alternative layout?
182 bra diveloop_loop4b ; YES - no space for CCR/pSCR info
183 call TFT_show_mode_divemode ; NO - (re)write CCR/pSCR mode info to display
184 diveloop_loop4b:
185 btfsc toggle_customview ; Next view?
186 call customview_toggle ; Yes, show next customview (and delete this flag)
187
188 btfsc divemode_gaschange ; Gas switch flag set?
189 call gas_switched_common ; YES 225 call gas_switched_common ; YES
190 226
191 btfsc toggle_gf ; Toggle GF/aGF? 227 btfsc toggle_gf ; toggle GF/aGF?
192 rcall divemodemode_togglegf ; YES 228 rcall divemodemode_togglegf ; YES
193 229
194 btfsc FLAG_set_marker ; shall a marker be set? 230 IFDEF _cave_mode
231 btfsc toggle_turn_dive ; toggle dive turned?
232 rcall divemodemode_toggleturn ; YES
233 ENDIF
234
235 btfsc FLAG_set_marker ; shall set a marker?
195 call set_logbook_marker ; YES 236 call set_logbook_marker ; YES
196 237
197 btfsc store_sample ; store new sample? 238 btfsc store_sample ; shall store new sample?
198 call store_dive_data ; Store profile data 239 call store_dive_data ; YES - store profile data
199 240
200 btfss divemode ; Dive finished? 241 btfss divemode ; dive finished?
201 goto ghostwriter_end_dive ; Dive finished! 242 goto ghostwriter_end_dive ; YES - dive finished!
202 243
203 btfsc pressure_refresh ; new pressure available? 244 btfsc pressure_refresh ; new pressure available?
204 rcall set_max_depth ; update max. depth if required 245 rcall set_max_depth ; YES - update max. depth if required
205 btfsc pressure_refresh ; new pressure available? 246 btfsc pressure_refresh ; new pressure available?
206 bsf FLAG_TFT_depth ; Yes, update depth 247 bsf FLAG_TFT_depth ; YES - update depth
207 bcf pressure_refresh ; clear flag 248 bcf pressure_refresh ; clear flag
208 249
209 btfsc temp_changed 250 btfsc temp_changed ; temperature changed?
210 bsf FLAG_TFT_temp_divemode ; Displays temperature 251 bsf FLAG_TFT_temp_divemode ; YES - display temperature
211 252
212 ; display depth based on as-fast-as-possible (no nice blinking) 253 IFDEF _screendump
213 ;btfss alternative_divelayout 254 btfsc enable_screen_dumps ; screen dump function enabled?
214 ;rcall TFT_output4_normal 255 call TFT_dump_screen_check ; YES - check if requested and do it
215 ;btfsc alternative_divelayout 256 ENDIF
216 ;rcall TFT_output4_alternative 257
217 258 bra diveloop_loop ; loop the dive mode
218 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
219 bra diveloop_loop5
220 bra diveloop_loop6
221
222 diveloop_loop5:
223 btfss vusb_in ; USB (still) plugged in?
224 bcf enable_screen_dumps ; No, clear flag
225 call rs232_get_byte
226 btfsc rs232_receive_overflow
227 bra diveloop_loop6
228 movlw "l"
229 cpfseq RCREG1
230 bra diveloop_loop6
231 call TFT_dump_screen ; Dump the screen contents
232
233 diveloop_loop6:
234 bra diveloop_loop ; Loop the divemode
235 259
236 ;-------------------------------------------------------------------------------------------------------- 260 ;--------------------------------------------------------------------------------------------------------
237 261
238 TFT_output1_normal: ; beginning of any new second - only for deco modes 262 TFT_output1_normal: ; beginning of any new second - only for deco modes
239 btfsc FLAG_TFT_divemode_mask 263 btfsc FLAG_TFT_divemode_mask
240 call TFT_divemode_mask 264 call TFT_divemode_mask
241 btfsc FLAG_TFT_divemins 265 btfsc FLAG_TFT_divemins
242 call TFT_divemins ; Display (new) divetime! 266 call TFT_divemins ; display (new) dive time!
243 call customview_second ; Do every-second tasks for the custom view area (In sync with the divetime) mH 267 call customview_second ; do every-second tasks for the custom view area (in sync with the dive time) mH
244 btfsc FLAG_TFT_show_safety_stop 268 btfsc FLAG_TFT_show_safety_stop
245 call TFT_show_safety_stop ; Show safety stop 269 call TFT_show_safety_stop ; show safety stop
246 btfsc FLAG_TFT_clear_safety_stop 270 btfsc FLAG_TFT_clear_safety_stop
247 call TFT_clear_safety_stop ; Clear safety stop 271 call TFT_clear_safety_stop ; clear safety stop
248 return 272 return
249 273
250 TFT_output1_alternative: ; beginning of any new second - only for deco modes 274 TFT_output1_alternative: ; beginning of any new second - only for deco modes
275 btfsc FLAG_TFT_divemode_mask_alt
276 call TFT_divemode_mask_alternative ; alternative mask
251 btfsc FLAG_TFT_divemins 277 btfsc FLAG_TFT_divemins
252 call TFT_divemins_alternative ; Display (new) divetime! 278 call TFT_divemins_alternative ; display (new) divetime!
253 btfsc FLAG_TFT_divemode_mask_alt 279 call customview_alternative_second ; do every-second tasks for the custom view area (in sync with the dive time) mH
254 call TFT_divemode_mask_alternative ; Alt. mask
255 call customview_alternative_second ; Do every-second tasks for the custom view area (In sync with the divetime) mH
256 btfsc FLAG_TFT_big_deco_alt 280 btfsc FLAG_TFT_big_deco_alt
257 call TFT_big_deco_alt ; Big deco and safety stop 281 call TFT_big_deco_alt ; big deco, also manages alternative safety stop thus moved to first wave of outputs [rl]
258 return 282 return
259 283
260 TFT_output2_normal: ; any new second - only for deco modes 284 TFT_output2_normal: ; any new second - only for deco modes
261 btfsc FLAG_TFT_display_ndl_mask 285 btfsc FLAG_TFT_display_ndl_mask
262 call TFT_display_ndl_mask 286 call TFT_display_ndl_mask
263 btfsc FLAG_TFT_display_ndl 287 btfsc FLAG_TFT_display_ndl
264 call TFT_display_ndl 288 call TFT_display_ndl
265 btfsc FLAG_TFT_display_deko_mask 289 btfsc FLAG_TFT_display_deko_mask
268 call TFT_display_deko 292 call TFT_display_deko
269 btfsc FLAG_TFT_display_tts 293 btfsc FLAG_TFT_display_tts
270 call TFT_display_tts 294 call TFT_display_tts
271 return 295 return
272 296
273 TFT_output2_alternative: ; any new second - only for deco modes 297 TFT_output2_alternative: ; any new second - only for deco modes
274 return 298 return
275 299
276 TFT_output3_normal: ; tasks any new second, any mode 300 TFT_output3_normal: ; tasks any new second, any mode, after deco calculations
277 btfsc FLAG_TFT_max_depth 301 btfsc FLAG_TFT_max_depth
278 call TFT_max_depth ; use normal max. depth 302 call TFT_max_depth ; use normal max. depth
279 btfsc FLAG_TFT_divemode_warning 303 btfsc FLAG_TFT_divemode_warning
280 call TFT_divemode_warning 304 call TFT_divemode_warning
281 btfsc FLAG_TFT_divemode_warning_clear 305 btfsc FLAG_TFT_divemode_warning_clear
282 call TFT_divemode_warning_clear 306 call TFT_divemode_warning_clear
307 btfsc FLAG_TFT_dive_warning_text_clear
308 call TFT_clear_warning_text ; clear complete warnings area
309 btfsc FLAG_TFT_dive_warning_text_clr2
310 call TFT_clear_warning_text_2nd_row ; clear 2nd row of warnings
311 return
312
313 TFT_output3_alternative: ; tasks any new second
314 btfsc FLAG_TFT_max_depth
315 call TFT_max_depth_alternative ; big max. depth
316 btfsc FLAG_TFT_dive_warning_text_clear
317 call TFT_clear_warning_text ; clear complete warnings area (in alt mode only 2nd row...)
318 return
319
320 TFT_output4_normal: ; tasks any round, any mode, before deco calculations (stable timebase)
321 btfsc FLAG_TFT_depth
322 call TFT_depth ; display depth
283 btfsc FLAG_TFT_active_gas_divemode 323 btfsc FLAG_TFT_active_gas_divemode
284 call TFT_active_gas_divemode ; Display gas/Setpoint 324 call TFT_active_gas_divemode ; display gas/setpoint
285 btfsc FLAG_TFT_dive_warning_text_clear 325 btfsc FLAG_TFT_temp_divemode
286 call TFT_clear_warning_text ; clear complete warnings area 326 call TFT_temp_divemode ; update temperature
287 btfsc FLAG_TFT_dive_warning_text_clr2 327 return
288 call TFT_clear_warning_text_2nd_row; clear 2nd row of warnings 328
289 return 329 TFT_output4_alternative: ; tasks any round, any mode
290
291 TFT_output3_alternative: ; tasks any new second, any mode
292 btfsc FLAG_TFT_max_depth_alt
293 call TFT_max_depth_alternative ; big max. depth
294 btfsc FLAG_TFT_dive_warning_text_clear
295 call TFT_clear_warning_text ; clear complete warnings area (In alt mode only 2nd. row...)
296 return
297
298 TFT_output4_normal: ; tasks any round, any mode
299 btfsc FLAG_TFT_depth 330 btfsc FLAG_TFT_depth
300 call TFT_depth ; Displays new depth 331 call TFT_depth ; display new depth
301 btfsc FLAG_TFT_temp_divemode
302 call TFT_temp_divemode ; Update temperature
303 return
304
305 TFT_output4_alternative: ; tasks any round, any mode
306 btfsc FLAG_TFT_depth
307 call TFT_depth ; Displays new depth
308 return 332 return
309 333
310 334
311 ;-------------------------------------------------------------------------------------------------------- 335 ;--------------------------------------------------------------------------------------------------------
312 336
313 divemode_apnoe_tasks: ; 1 sec. Apnoe tasks 337 divemode_apnoe_tasks: ; 1 sec. apnoe tasks
314 call TFT_display_apnoe_descent ; Yes, Show descent timer 338 call TFT_display_apnoe_descent ; show descent timer
315 call TFT_max_depth ; use normal max. depth 339 call TFT_max_depth ; use normal max. depth
316 340
317 btfsc divemode2 ; Time running? 341 btfsc divemode2 ; time running?
318 bra divemode_apnoe_tasks2 ; New descent, reset data if flag is set 342 bra divemode_apnoe_tasks2 ; YES - new descent, reset data if flag is set
319 343
320 rcall apnoe_calc_maxdepth 344 rcall apnoe_calc_maxdepth
321 call TFT_display_apnoe_surface 345 call TFT_display_apnoe_surface
322 call TFT_display_apnoe_last_max ; Show last max. depth 346 call TFT_display_apnoe_last_max ; show last max. depth
323 incf apnoe_surface_secs,F 347 incf apnoe_surface_secs,F
324 movlw d'60' 348 movlw d'60'
325 cpfseq apnoe_surface_secs 349 cpfseq apnoe_surface_secs
326 bra divemode_apnoe_tasks1 350 bra divemode_apnoe_tasks1
327 clrf apnoe_surface_secs 351 clrf apnoe_surface_secs
328 incf apnoe_surface_mins,F 352 incf apnoe_surface_mins,F
329 353
330 divemode_apnoe_tasks1: 354 divemode_apnoe_tasks1:
331 bcf FLAG_active_descent ; Clear flag 355 bcf FLAG_active_descent ; clear flag
332 btfsc divemode2 ; Time running? 356 btfsc divemode2 ; time running?
333 return ; Yes, return 357 return ; YES - return
334 bsf FLAG_active_descent ; Set Flag 358 bsf FLAG_active_descent ; set flag
335 return 359 return
336 360
337 divemode_apnoe_tasks2: 361 divemode_apnoe_tasks2:
338 btfss FLAG_active_descent ; Are we descending? 362 btfss FLAG_active_descent ; are we descending?
339 return ; No, We are at the surface 363 return ; NO - we are at the surface
340 rcall apnoe_calc_maxdepth ; Yes! 364 rcall apnoe_calc_maxdepth ; YES
341 call TFT_apnoe_clear_surface ; Clear Surface timer 365 call TFT_apnoe_clear_surface ; clear surface timer
342 clrf apnoe_timeout_counter ; Delete timeout 366 clrf apnoe_timeout_counter ; delete timeout
343 clrf apnoe_surface_secs 367 clrf apnoe_surface_secs
344 clrf apnoe_surface_mins 368 clrf apnoe_surface_mins
345 clrf apnoe_secs 369 clrf apnoe_secs
346 clrf apnoe_mins ; Reset Descent time 370 clrf apnoe_mins ; reset descent time
347 movlw .0 371 movlw .0
348 movff WREG,max_pressure+0 372 movff WREG,max_pressure+0
349 movff WREG,max_pressure+1 ; Reset Max. Depth 373 movff WREG,max_pressure+1 ; reset max. depth
350 bcf FLAG_active_descent ; Clear flag 374 bcf FLAG_active_descent ; clear flag
351 return 375 return
352 376
353 global apnoe_calc_maxdepth 377 global apnoe_calc_maxdepth
354 apnoe_calc_maxdepth: 378 apnoe_calc_maxdepth:
355 movff apnoe_max_pressure+0,sub_a+0 379 movff apnoe_max_pressure+0,sub_a+0
356 movff apnoe_max_pressure+1,sub_a+1 380 movff apnoe_max_pressure+1,sub_a+1
357 movff max_pressure+0,sub_b+0 381 movff max_pressure+0,sub_b+0
358 movff max_pressure+1,sub_b+1 382 movff max_pressure+1,sub_b+1
359 call subU16 ; sub_c = sub_a - sub_b 383 call subU16 ; sub_c = sub_a - sub_b
360 ; apnoe_max_pressure<max_pressure -> neg_flag=1 384 ; apnoe_max_pressure < max_pressure -> neg_flag=1
361 ; max_pressure<=apnoe_max_pressure -> neg_flag=0 385 ; max_pressure <= apnoe_max_pressure -> neg_flag=0
362 btfss neg_flag 386 btfss neg_flag
363 return 387 return
364 ;apnoe_max_pressure<max_pressure 388 ;apnoe_max_pressure<max_pressure
365 movff max_pressure+0,apnoe_max_pressure+0 389 movff max_pressure+0,apnoe_max_pressure+0
366 movff max_pressure+1,apnoe_max_pressure+1 390 movff max_pressure+1,apnoe_max_pressure+1
367 return 391 return
368 392
369 ; -------------------------------------------------------------------------------------- 393 ; --------------------------------------------------------------------------------------
370 394
371 calc_deko_divemode: 395 calc_deko_divemode:
372 rcall calc_deko_divemode2 ; all deco relevant code is now invoked every second 396 btfss FLAG_gauge_mode ; in gauge mode?
373 btfsc twosecupdate 397 rcall calc_deko_engine ; NO - do deco calculations
374 bra calc_deko_divemode1 398
375 bsf twosecupdate 399 ; Increment the time accumulators used for calculating the average depths.
376 return 400 ; This done here and not in the ISR to guarantee synchronism between time
377 401 ; and depth accumulator incrementing.
378 calc_deko_divemode1: ; the following code is invoked every 2 seconds 402 infsnz average_divesecs+0,F
379 bcf twosecupdate 403 incf average_divesecs+1,F
380 404 infsnz average_divesecs_total+0,F
405 incf average_divesecs_total+1,F
406
407 btg onesectoggle ; toggle the one-second toggle bit
408 btfss onesectoggle ; toggle bit set?
409 bra calc_deko_divemode2 ; NO
410 ;bra calc_deko_divemode1 ; YES
411
412 calc_deko_divemode1: ; every-2-seconds tasks, 1st phase
413 ; call TFT_debug_output ; optional debug output
414 btfsc FLAG_gauge_mode ; in gauge mode?
415 return ; YES - done
416 goto check_gas_best ; NO - checks if a better gas should be selected (by user) and return
417
418 calc_deko_divemode2: ; every-2-seconds tasks, 2nd phase
381 call calc_average_depth ; calculate average depth 419 call calc_average_depth ; calculate average depth
382 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds) 420 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds)
383 call set_reset_safety_stop ; Set flags for safety stop and/or reset safety stop 421 goto set_reset_safety_stop ; set/reset flags for safety stop and return
384 call TFT_debug_output 422
385 423
386 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode 424 calc_deko_engine:
387 return 425 btfsc FLAG_ccr_mode ; in CCR mode?
388 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode 426 call check_dive_autosp ; YES - check for Auto-SP
389 return 427
390 428 btfsc FLAG_ccr_mode ; in CCR mode?
391 ; Check for a gas change 429 rcall calc_deko_divemode_sensor ; YES - do sensor data acquisition if applicable by OSTC model
392 goto check_gas_change ; Checks if a better gas should be selected (by user) and return... 430
393 431 btfsc FLAG_pscr_mode ; in pSCR mode?
394 432 rcall calc_deko_divemode_sensor ; YES - do sensor data acquisition if applicable by OSTC model
395 calc_deko_divemode2:
396 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode
397 return
398
399 btfsc FLAG_ccr_mode ; In CCR mode?
400 rcall calc_deko_divemode_sensor ; do sensor data acquisition if applicable by OSTC model
401
402 btfsc FLAG_pscr_mode ; In PSCR mode?
403 rcall calc_deko_divemode_sensor ; do sensor data acquisition if applicable by OSTC model
404
405 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; transfer ambient pressure to deco engine
406 433
407 434
408 ; check deco engine state and switch between normal and alternative plan calculations 435 ; check deco engine state and switch between normal and alternative plan calculations
409 ; 436 ;
410 ; Remark: Any reconfigurations done here do only affect the ascent & deco calculation settings, 437 ; Remark: Any reconfigurations done here do only affect the ascent & deco calculation settings,
411 ; not the settings for the calculations done on the real tissues. The later ones are only 438 ; not the settings for the calculations done on the real tissues. The later ones are only
412 ; altered in case of a gas change, or in case of a real bailout or switchback to setpoint 439 ; altered in case of a gas change, or in case of a real bailout or switchback to setpoint
413 ; or sensor, respectively. 440 ; or sensor, respectively.
414 ; In case of a gas change or real bailout/switchback, the settings for the deco calculations 441 ; In case of a gas change or real bailout/switchback, the settings for the deco calculations
415 ; are also changed to match the settings for the real tissues. This is done on signal through 442 ; are also changed to match the settings for the real tissues. This is done on signal through
416 ; 'divemode_gaschange' and will also leave the deco engine status in state as if having done 443 ; 'divemode_gaschange' and will also leave the deco engine status in state as if having done
417 ; the alternative plan last. 444 ; the alternative plan last.
418 445
419 ; check state of ascent/deco calculations 446 ; get working copies of char_O_main_status and char_O_deco_status
420 movff char_O_deco_status,lo ; get a working copy of char_O_deco_status into bank common 447 movff char_O_main_status,hi ; get char_O_main_status into hi
421 movlw DECO_STATUS_MASK ; load bit mask covering the deco status bits 448 movff char_O_deco_status,lo ; get char_O_deco_status into lo
422 andwf lo,W ; mask out bits showing deco engine computations state 449
423 tstfsz WREG ; check if the last compute cycle has finished (bits 1 and 0 cleared) 450 ; check state of deco calculations
424 bra calc_deko_divemode2e ; NO - computations still in progress, needs more computation cycles 451 btfsc hi,DECO_COMPLETED_NORM ; finished calculations for normal plan?
425 btfss lo,DECO_PLAN_FLAG ; YES - computation cycle finished, so check what has been computed 452 bra calc_deko_engine_alt ; YES - do an alternative plan next (or a normal one with more features enabled)
426 bra calc_deko_divemode2b ; PLAN bit is cleared i.e. normal plan was done, may do alternative next 453 btfsc hi,DECO_COMPLETED_ALT ; finished calculations for alternative plan?
427 454 bra calc_deko_engine_norm ; YES - do a normal plan next
428 ; The PLAN bit is set, i.e. an alternative plan was computed in the last cycle, or the deco engine has 455 bra calc_deko_engine_cont ; NO to both - continue calculations / do first invocation in INIT mode
429 ; been restarted because of a gas change etc. --> Reconfigure to normal plan for next computation cycle. 456
430 457 calc_deko_engine_norm:
431 ; reset flags for special calculations 458 ; Last cycle did an alternative plan, or the deco engine has been restarted because of a gas change etc.
459 ; --> Reconfigure to normal plan for next computation cycle.
460 bcf lo,DECO_PLAN_FLAG ; clear flag for alternative plan to do a normal plan next
461 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation
462 bcf lo,DECO_VOLUME_FLAG ; clear flag for gas needs calculation
463 bcf lo,DECO_BAILOUT_FLAG ; clear flag for bailout mode
464 IFDEF _cave_mode
465 bcf hi,DECO_CAVE_MODE ; clear flag for cave mode
466 ENDIF
467
468 btfsc FLAG_ccr_mode ; in CCR mode?
469 bra calc_deko_engine_norm_loop ; YES - reload diluents and reconfigure CCR mode if not in bailout
470 btfsc FLAG_pscr_mode ; in pSCR mode?
471 bra calc_deko_engine_norm_loop ; YES - reload diluents and reconfigure pSCR mode if not in bailout
472 ;bra calc_deko_engine_norm_OC ; neither in CCR nor pSCR mode, so reload OC gases and reconfigure OC mode
473 ; (first cycle omits gas needs calculation for faster first deco results)
474 calc_deko_engine_norm_OC:
475 movff active_gas,WREG ; get current OC gas
476 call deco_setup_oc_gases_pre ; set up deco calculations in OC mode with OC gases
477 bra calc_deko_engine_start ; start deco engine
478
479 calc_deko_engine_norm_loop: ; switch to loop calculation if not in a real bailout situation
480 btfsc FLAG_bailout_mode ; check if a real bailout situation is present
481 bra calc_deko_engine_norm_OC ; YES - revert to OC mode
482 ; NO - switch to loop calculation:
483 movff active_dil,WREG ; - get current diluent
484 call deco_setup_cc_diluents_pre ; - set up deco calculations in CCR/pSCR mode with diluents
485 bra calc_deko_engine_start ; - start deco engine
486
487 calc_deko_engine_alt:
488 ; A normal plan was computed in the last cycle. For the next calculation cycle the mode may be switched
489 ; to alternative plan, or stay in normal plan but with certain features enabled...
490 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation
491 bcf lo,DECO_VOLUME_FLAG ; clear flag for gas needs calculation
492 bcf lo,DECO_BAILOUT_FLAG ; clear flag for bailout mode
493 IFDEF _cave_mode
494 bcf hi,DECO_CAVE_MODE ; clear flag for cave mode
495 ENDIF
496
497 btfsc FLAG_bailout_mode ; check if a real bailout situation is present
498 bra calc_deko_engine_alt_1 ; YES - stay in normal plan mode and preclude delayed ascent calculation
499 TSTOSS char_I_extra_time ; NO - check if a delayed ascent is enabled
500 bra calc_deko_engine_alt_1 ; NO - stay in normal plan mode and preclude delayed ascent calculation
501 bsf lo,DECO_PLAN_FLAG ; YES - set flag for alternative plan
502 bsf lo,DECO_ASCENT_FLAG ; - set flag for delayed ascent
503
504 calc_deko_engine_alt_1:
505 TSTOSS opt_calc_asc_gasvolume ; check if gas volume calculation is enabled
506 bra calc_deko_engine_start ; NO - no volume calculation, no simulated bailout plan in this case
507 bsf lo,DECO_VOLUME_FLAG ; YES - set gas needs calculation flag
508
509 btfsc FLAG_bailout_mode ; check if a real bailout situation is present
510 bra calc_deko_engine_start ; YES - normal plan already does bailout (OC) calculation "for real"
511
512 IFDEF _cave_mode
513 bsf hi,DECO_CAVE_MODE ; activate cave mode by default
514 btfss FLAG_cave_mode ; cave mode switched on?
515 bcf hi,DECO_CAVE_MODE ; NO - deactivate p2deco cave mode again
516 btfsc FLAG_dive_turned ; dive turned?
517 bcf hi,DECO_CAVE_MODE ; YES - deactivate p2deco cave mode again
518 btfsc FLAG_cave_mode_shutdown ; cave mode function shut down?
519 bcf hi,DECO_CAVE_MODE ; YES - deactivate p2deco cave mode again
520 ENDIF
521
522 btfss lo,DECO_MODE_LOOP_FLAG ; NO - has a loop mode calculation been done during the normal plan?
523 bra calc_deko_engine_start ; NO - when not in loop mode, no simulated bailout to be done
524 decf best_gas_number,W ; YES - get best gas number -1 into WREG. If not available, WREG will be 255 now. If not computed yet, WREG will be 254 now.
525 btfsc WREG,7 ; - WREG < 128 (a bailout gas is available)?
526 bra calc_deko_engine_alt_2 ; NO - no simulated bailout possible because no bailout gas available to switch to
527 bsf lo,DECO_PLAN_FLAG ; YES - set flag for alternative plan
528 bsf lo,DECO_BAILOUT_FLAG ; - set bailout mode flag (enables gas changes before 1st stop)
529 movf best_gas_number,W ; - put number of best gas into WREG
530 call deco_setup_oc_gases_pre ; - set up deco calculations in OC mode with OC gases
531 bra calc_deko_engine_start ; - start in alternative plan mode
532
533 calc_deko_engine_alt_2:
432 bcf lo,DECO_PLAN_FLAG ; clear flag for alternative plan 534 bcf lo,DECO_PLAN_FLAG ; clear flag for alternative plan
433 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation 535 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation
434 bcf lo,DECO_VOLUME_FLAG ; clear flag for gas needs calculation 536 bcf lo,DECO_VOLUME_FLAG ; clear flag for gas needs calculation
537 IFDEF _cave_mode
538 bcf hi,DECO_CAVE_MODE ; clear flag for cave mode
539 ENDIF
540 call inval_alternative_plan_data ; invalidate all alternative (bailout) plan data because they are not applicable any more
541
542 calc_deko_engine_start:
543 IFDEF _cave_mode
544 movff hi,char_O_main_status ; write-back char_O_main_status to deco engine interface
545 ENDIF
435 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface 546 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface
436 547
437 ; check if a switchback from CCR or pSCR bailout calculation is to be done 548 calc_deko_engine_cont:
438 btfsc FLAG_ccr_mode ; may a switchback from a CCR bailout calculation be needed? 549 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; transfer ambient pressure to deco engine
439 bra calc_deko_divemode2a ; in CCR mode, so may need to switch back from bailout calculation 550 clrf TMR5L ; restart timer used to preempt stops calculation
440 btfsc FLAG_pscr_mode ; may a switchback from a pSCR bailout calculation be needed? 551 clrf TMR5H ;
441 bra calc_deko_divemode2a ; in pSCR mode, so may need to switch back from bailout calculation 552 call deco_calc_hauptroutine ; invoke the deco engine (p2_deco.c)
442 bra calc_deko_divemode2e ; not in CCR nor pSCR, so no switchback needed, start normal plan now
443 ; (first cycle omits gas needs calculation in OC without delayed ascent)
444
445 ; switch back to loop calculation if last cycle was doing a bailout calculation
446 calc_deko_divemode2a:
447 movff opt_calc_asc_gasvolume,hi ; get the gas volume needs calculation setting
448 movf hi,W ; are gas volume calculations turned on?
449 bz calc_deko_divemode2e ; NO - can't have done a bailout calculation then, start normal plan
450 btfsc is_bailout ; YES - check if a real bailout situation is present
451 bra calc_deko_divemode2e ; YES - OC gases have been set by bailout action then, start normal plan
452 movff active_gas,WREG ; NO - switch back to loop calculation: get current (diluent) gas, ...
453 call deco_setup_cc_diluents ; ... set up deco calculations in CCR/pSCR mode with diluents,
454 bra calc_deko_divemode2e ; ... and start in normal plan mode
455
456 ; The PLAN bit was cleared, i.e. a normal plan was computed in the last cycle. For the next
457 ; computation cycle the mode may be switched to alternative plan, or stay in normal mode...
458
459 calc_deko_divemode2b:
460 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation (for safety only)
461 btfsc is_bailout ; check if a real bailout situation is present
462 bra calc_deko_divemode2c ; YES - stay in normal plan mode and preclude delayed ascent calculation
463 movff char_I_extra_time,hi ; NO - get the delayed ascent setting
464 tstfsz hi ; check if delayed ascent calculation is enabled
465 bsf lo,DECO_ASCENT_FLAG ; YES - set flag for delayed ascent calculation
466 tstfsz hi ; check if delayed ascent calculation is enabled (again)
467 bsf lo,DECO_PLAN_FLAG ; YES - set flag for alternative plan
468
469 ; check if a gas needs calculation shall be done
470 calc_deko_divemode2c:
471 bsf lo,DECO_VOLUME_FLAG ; set gas needs calculation flag (may be cleared again next)
472 TSTOSS opt_calc_asc_gasvolume ; check if gas needs calculation is enabled
473 bcf lo,DECO_VOLUME_FLAG ; NO - reset flag again
474 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface
475 TSTOSS opt_calc_asc_gasvolume ; check if gas volume calculation is enabled (again)
476 bra calc_deko_divemode2e ; NO - no volume calculation, no simulated bailout plan in no case
477
478 ; check if conditions are met to calculate a bailout plan
479 btfsc is_bailout ; check if a real bailout situation is present
480 bra calc_deko_divemode2e ; YES - normal plan already does bailout (OC) calculation "for real"
481 btfss lo,DECO_MODE_LOOP_FLAG ; NO - have loop mode calculation been done during the normal plan?
482 bra calc_deko_divemode2e ; NO - when not in loop mode, no simulated bailout to be done
483 bsf lo,DECO_PLAN_FLAG ; YES - set flag for alternative plan
484 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface
485 call get_first_gas_to_WREG ; get first OC gas, ...
486 call deco_setup_oc_gases ; ... set up deco calculations in OC mode with OC gases,
487 ;bra calc_deko_divemode2e ; ... and start in alternative plan mode
488
489
490 calc_deko_divemode2e:
491 clrf TMR5L
492 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H
493 call deco_calc_hauptroutine ; calc_tissue
494 banksel common 553 banksel common
495 554
496 ; Check if deco stops are necessary 555 ; check if display shall be updated due to deco engine restart
497 movff char_O_first_deco_depth,WREG; get ceiling 556 btfsc FLAG_TFT_display_ndl_or_deko; shall update immediately?
498 tstfsz WREG ; ceiling < 0m (aka in deco) ? 557 bra calc_deko_engine_update ; YES
499 bra calc_deko_divemode3 ; YES 558
500 ; NO - within NDL 559 ; check if new calculation results for normal plan mode are available
501 btfsc decostop_active ; already in no deco mode ? 560 movff char_O_main_status,WREG ; get deco status of deco engine
502 bsf FLAG_TFT_display_ndl_mask ; NO - clear deco data, display NDL time 561 btfss WREG,DECO_COMPLETED_NORM ; new calculation results for normal plan available?
562 return ; NO - done
563 calc_deko_engine_update:
564 bcf FLAG_TFT_display_ndl_or_deko; YES - reset flag for immediate update
565 movff char_O_deco_info,WREG ; - get deco info vector
566 btfsc WREG,deco_ceiling ; - ceiling depth > 0 ?
567 bra calc_deko_engine_update_deco; YES - in deco
568 ;bra calc_deko_engine_update_NDL ; NO - within NDL
569
570 calc_deko_engine_update_NDL: ; within NDL
571 btfsc decostop_active ; been in deco mode before?
572 bsf FLAG_TFT_display_ndl_mask ; YES - clear deco data, display NDL time
503 bsf FLAG_TFT_display_ndl ; display NDL time 573 bsf FLAG_TFT_display_ndl ; display NDL time
504 bcf decostop_active ; clear flag (again) 574 bcf decostop_active ; clear flag for been in deco mode before
505 return 575 return
506 576
507 calc_deko_divemode3: 577 calc_deko_engine_update_deco: ; in deco
508 ; YES - in deco 578 btfss decostop_active ; already been in deco mode before?
509 btfss decostop_active ; already in deco mode ?
510 bsf FLAG_TFT_display_deko_mask ; NO - clear NDL time, display deco data 579 bsf FLAG_TFT_display_deko_mask ; NO - clear NDL time, display deco data
511 bsf FLAG_TFT_display_deko ; display deco data 580 bsf FLAG_TFT_display_deko ; display deco data
512 bsf FLAG_TFT_display_tts ; display TTS 581 bsf FLAG_TFT_display_tts ; display TTS
513 bsf decostop_active ; set flag (again) 582 bsf decostop_active ; set flag for being in deco mode
514 return 583 return
515 584
516 ; -------------------------------------------------------------------------------------- 585 ; --------------------------------------------------------------------------------------
517 586
518 global calc_deko_divemode_sensor 587 global calc_deko_divemode_sensor
519 calc_deko_divemode_sensor: 588 calc_deko_divemode_sensor:
520 ; sensor acquisition code 589 ; sensor acquisition code
521 btfss s8_digital ; check if we have a digital interface to the sensors 590 btfss s8_digital ; check if we have a digital interface to the sensors
522 bra calc_deko_divemode_sensor_analog ; NO - check if we have an analog interface 591 bra calc_deko_divemode_sensor_analog ; NO - check if we have an analog interface
523 btfss new_s8_data_available ; YES - check if a new data frame was received 592 btfss new_s8_data_available ; YES - check if a new data frame was received
524 bra calc_deko_divemode_sensor_common ; NO - use old values -- TODO: add timeout for no new data 593 bra calc_deko_divemode_sensor_common ; NO - use old values
525 call compute_mvolts_for_all_sensors ; YES - compute mV values from digital data 594 call compute_mvolts_for_all_sensors ; YES - compute mV values from digital data
526 bra calc_deko_divemode_sensor_common 595 bra calc_deko_divemode_sensor_common
527 596 calc_deko_divemode_sensor_analog:
597 btfss analog_o2_input ; do we have an analog input?
598 bra calc_deko_divemode_sensor_opt ; NO - check if we have an optical interface
599 call get_analog_inputs ; YES - get the analog voltages and continue with the common part
600 bra calc_deko_divemode_sensor_common
528 calc_deko_divemode_sensor_opt: 601 calc_deko_divemode_sensor_opt:
529 btfss optical_input ; do we have an optical input? 602 btfss optical_input ; do we have an optical input?
530 return ; No, return (We have no sensors at all. Not analog, not S8 and not optical) 603 return ; NO - return (we have no sensors at all: not analog, not S8 and not optical)
531 ;o2_ppo2_sensor1, o2_ppo2_sensor2 and o2_ppo2_sensor3 are already filled in ISR 604 btfss sensor1_active ; YES - o2_ppo2_sensor1, o2_ppo2_sensor2 and o2_ppo2_sensor3 are already filled in ISR
532 ;clear use_O2_sensorX for timeout case 605 bcf use_O2_sensor1 ; check HUD status data and eventually clear use_O2_sensorX
533 btfss sensor1_active 606 btfss sensor2_active
534 bcf use_O2_sensor1 607 bcf use_O2_sensor2
535 btfss sensor2_active
536 bcf use_O2_sensor2
537 btfss sensor3_active 608 btfss sensor3_active
538 bcf use_O2_sensor3 609 bcf use_O2_sensor3
539 bra calc_deko_divemode_sensor1 610 bra calc_deko_divemode_sensor_A ; continue with calculating sensor average
540
541 calc_deko_divemode_sensor_analog:
542 btfss analog_o2_input ; do we have an analog input?
543 bra calc_deko_divemode_sensor_opt ; NO - check if we have an optical interface
544 call get_analog_inputs ; YES - get the analog voltages and continue with the common part
545 611
546 calc_deko_divemode_sensor_common: 612 calc_deko_divemode_sensor_common:
547 ; Check for each sensor if it is calibrated and if its mv value is within min_mv and max_mv limits. 613 ; Check each sensor if it is calibrated and if its mV value is within min_mv and max_mv limits.
548 ; If ok: compute o2_ppo2_sensorX := o2_mv_sensorX * opt_x_sX / 1000 614 ; If ok: compute o2_ppo2_sensorX = o2_mv_sensorX * opt_x_sX / 1000
549 ; If not ok: reset o2_ppo2_sensorX, reset use_O2_sensorX and show the customview 1 in case the sensor was ok before 615 ; If not ok: reset o2_ppo2_sensorX, reset use_O2_sensorX and show the customview 1 in case the sensor was ok before
550 616
551 ; Check min_mv of sensor 1 617 ; check sensor 1
552 btfss sensor1_calibrated_ok ; check if sensor is usable at all 618 btfss sensor1_calibrated_ok ; check if sensor is usable at all
553 bra check_sensor_1_fail ; NO - handle it as failed 619 bra check_sensor_1_fail ; NO - handle it as failed
554 movff o2_mv_sensor1+0, sub_a+0 ; load sensor mV value 620 ; check min threshold
555 movff o2_mv_sensor1+1, sub_a+1 621 movff o2_mv_sensor1+0,sub_a+0 ; load sensor mV value
556 movlw LOW min_mv ; load minimum mV value 622 movff o2_mv_sensor1+1,sub_a+1
557 movwf sub_b+0 623 rcall check_min_threshold
558 movlw HIGH min_mv
559 movwf sub_b+1
560 call sub16 ; sub_c = sensor_mv - min_mv
561 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv 624 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv
562 bra check_sensor_1_fail ; YES - declare sensor as failed 625 bra check_sensor_1_fail ; YES - declare sensor as failed
563 ; Check max_mv of sensor 1 ; NO - continue with next check 626 ; check max_threshold
564 movff o2_mv_sensor1+0, sub_a+0 627 rcall check_max_threshold
565 movff o2_mv_sensor1+1, sub_a+1
566 movlw LOW max_mv
567 movwf sub_b+0
568 movlw HIGH max_mv
569 movwf sub_b+1
570 call sub16 ; sub_c = sensor_mv - max_mv
571 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv 628 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv
572 bra check_sensor_1_fail ; NO - declare sensor as failed 629 bra check_sensor_1_fail ; NO - declare sensor as failed
573 ; Check HUD data, if available ; YES - continue with next check 630 ; check HUD data, if available
574 btfss hud_connection_ok ; check if there is a HUD connected 631 btfss hud_connection_ok ; check if there is a HUD connected
575 bra check_sensor_1_ok ; NO - all checks done then and positive 632 bra check_sensor_1_ok ; NO - all checks done then and positive
576 btfss sensor1_active ; YES - check HUD report on sensor 633 btfss sensor1_active ; YES - HUD status ok?
577 bra check_sensor_1_fail ; HUD reports a fail 634 bra check_sensor_1_fail ; NO - HUD reports a fail
578
579 check_sensor_1_ok: 635 check_sensor_1_ok:
580 ; o2_ppo2_sensor1 := o2_mv_sensor1:2 * opt_x_s1:2 / 1000 636 ; o2_ppo2_sensor1 = o2_mv_sensor1:2 * opt_x_s1:2 / 1000
581 movff o2_mv_sensor1+0,xA+0 637 movff o2_mv_sensor1+0,xA+0
582 movff o2_mv_sensor1+1,xA+1 638 movff o2_mv_sensor1+1,xA+1
583 movff opt_x_s1+0,xB+0 639 movff opt_x_s1+0,xB+0
584 movff opt_x_s1+1,xB+1 640 movff opt_x_s1+1,xB+1
585 rcall compute_ppo2_helper 641 rcall compute_ppo2_helper
586 movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar 642 movff xC+0,o2_ppo2_sensor1 ; result in 0.01 bar
587 bra check_sensor_2 ; continue with next sensor 643 bra check_sensor_2 ; continue with next sensor
588
589 check_sensor_1_fail: 644 check_sensor_1_fail:
590 clrf WREG 645 clrf WREG
591 movff WREG,o2_ppo2_sensor1 ; set ppO2 reading to zero 646 movff WREG,o2_ppo2_sensor1 ; set ppO2 reading to zero
592 btfss use_O2_sensor1 ; check if sensor was in use before 647 btfss use_O2_sensor1 ; check if sensor was in use before
593 bra check_sensor_1_fail_1 ; NO - no new news then 648 bra check_sensor_1_fail_1 ; NO - no new news then
594 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met 649 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met
595 check_sensor_1_fail_1: 650 check_sensor_1_fail_1:
596 bcf use_O2_sensor1 ; revoke sensor from usage 651 bcf use_O2_sensor1 ; revoke sensor from usage
597 ;bra check_sensor_2 ; continue with next sensor 652
598 653 check_sensor_2: ; check min_mv of sensor 2
599 check_sensor_2: ; Check min_mv of sensor 2
600 btfss sensor2_calibrated_ok ; check if sensor is usable at all 654 btfss sensor2_calibrated_ok ; check if sensor is usable at all
601 bra check_sensor_2_fail ; NO - handle it as failed 655 bra check_sensor_2_fail ; NO - handle it as failed
602 movff o2_mv_sensor2+0, sub_a+0 ; load sensor mV value 656 ; check min threshold
603 movff o2_mv_sensor2+1, sub_a+1 657 movff o2_mv_sensor2+0,sub_a+0 ; load sensor mV value
604 movlw LOW min_mv ; load minimum mV value 658 movff o2_mv_sensor2+1,sub_a+1
605 movwf sub_b+0 659 rcall check_min_threshold
606 movlw HIGH min_mv
607 movwf sub_b+1
608 call sub16 ; sub_c = sensor_mv - min_mv
609 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv 660 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv
610 bra check_sensor_2_fail ; YES - declare sensor as failed 661 bra check_sensor_2_fail ; YES - declare sensor as failed
611 ; Check max_mv of sensor 2 ; NO - continue with next check 662 ; check max_threshold
612 movff o2_mv_sensor2+0, sub_a+0 663 rcall check_max_threshold
613 movff o2_mv_sensor2+1, sub_a+1
614 movlw LOW max_mv
615 movwf sub_b+0
616 movlw HIGH max_mv
617 movwf sub_b+1
618 call sub16 ; sub_c = sensor_mv - max_mv
619 btfss neg_flag ; check if result is nagative, i.e. sensor_mv < max_mv 664 btfss neg_flag ; check if result is nagative, i.e. sensor_mv < max_mv
620 bra check_sensor_2_fail ; NO - declare sensor as failed 665 bra check_sensor_2_fail ; NO - declare sensor as failed
621 ; Check HUD data, if available ; YES - continue with next check 666 ; check HUD data, if available
622 btfss hud_connection_ok ; check if there is a HUD connected 667 btfss hud_connection_ok ; check if there is a HUD connected
623 bra check_sensor_2_ok ; NO - all checks done then and positive 668 bra check_sensor_2_ok ; NO - all checks done then and positive
624 btfss sensor2_active ; YES - check HUD report on sensor 669 btfss sensor2_active ; YES - HUD status ok?
625 bra check_sensor_2_fail ; HUD reports a fail 670 bra check_sensor_2_fail ; NO - HUD reports a fail
626
627 check_sensor_2_ok: 671 check_sensor_2_ok:
628 ; o2_ppo2_sensor2 := o2_mv_sensor2:2 * opt_x_s2:2 / 1000 672 ; o2_ppo2_sensor2 = o2_mv_sensor2:2 * opt_x_s2:2 / 1000
629 movff o2_mv_sensor2+0,xA+0 673 movff o2_mv_sensor2+0,xA+0
630 movff o2_mv_sensor2+1,xA+1 674 movff o2_mv_sensor2+1,xA+1
631 movff opt_x_s2+0,xB+0 675 movff opt_x_s2+0,xB+0
632 movff opt_x_s2+1,xB+1 676 movff opt_x_s2+1,xB+1
633 rcall compute_ppo2_helper 677 rcall compute_ppo2_helper
634 movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar 678 movff xC+0,o2_ppo2_sensor2 ; result in 0.01 bar
635 bra check_sensor_3 ; continue with next sensor 679 bra check_sensor_3 ; continue with next sensor
636
637 check_sensor_2_fail: 680 check_sensor_2_fail:
638 clrf WREG 681 clrf WREG
639 movff WREG,o2_ppo2_sensor2 ; set ppO2 reading to zero 682 movff WREG,o2_ppo2_sensor2 ; set ppO2 reading to zero
640 btfss use_O2_sensor2 ; check if sensor was in use before 683 btfss use_O2_sensor2 ; check if sensor was in use before
641 bra check_sensor_2_fail_1 ; NO - no new news then 684 bra check_sensor_2_fail_1 ; NO - no new news then
642 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met 685 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met
643 check_sensor_2_fail_1: 686 check_sensor_2_fail_1:
644 bcf use_O2_sensor2 ; revoke sensor from usage 687 bcf use_O2_sensor2 ; revoke sensor from usage
645 ;bra check_sensor_3 ; continue with next sensor 688
646 689 check_sensor_3: ; check min_mv of sensor 2
647 check_sensor_3: ; Check min_mv of sensor 2
648 btfss sensor3_calibrated_ok ; check if sensor is usable at all 690 btfss sensor3_calibrated_ok ; check if sensor is usable at all
649 bra check_sensor_3_fail ; NO - handle it as failed 691 bra check_sensor_3_fail ; NO - handle it as failed
650 movff o2_mv_sensor3+0, sub_a+0 ; load sensor mV value 692 ; check min threshold
651 movff o2_mv_sensor3+1, sub_a+1 693 movff o2_mv_sensor3+0,sub_a+0 ; load sensor mV value
652 movlw LOW min_mv ; load minimum mV value 694 movff o2_mv_sensor3+1,sub_a+1
653 movwf sub_b+0 695 rcall check_min_threshold
654 movlw HIGH min_mv
655 movwf sub_b+1
656 call sub16 ; sub_c = sensor_mv - min_mv
657 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv 696 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv
658 bra check_sensor_3_fail ; YES - declare sensor as failed 697 bra check_sensor_3_fail ; YES - declare sensor as failed
659 ; Check max_mv of sensor 2 ; NO - continue with next check 698 ; check max threshold
660 movff o2_mv_sensor3+0, sub_a+0 699 rcall check_max_threshold
661 movff o2_mv_sensor3+1, sub_a+1
662 movlw LOW max_mv
663 movwf sub_b+0
664 movlw HIGH max_mv
665 movwf sub_b+1
666 call sub16 ; sub_c = sensor_mv - max_mv
667 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv 700 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv
668 bra check_sensor_3_fail ; NO - declare sensor as failed 701 bra check_sensor_3_fail ; NO - declare sensor as failed
669 ; Check HUD data, if available ; YES - continue with next check 702 ; check HUD data, if available
670 btfss hud_connection_ok ; check if there is a HUD connected 703 btfss hud_connection_ok ; check if there is a HUD connected
671 bra check_sensor_3_ok ; NO - all checks done then and positive 704 bra check_sensor_3_ok ; NO - all checks done then and positive
672 btfss sensor3_active ; YES - check HUD report on sensor 705 btfss sensor3_active ; YES - HUD status ok?
673 bra check_sensor_3_fail ; HUD reports a fail 706 bra check_sensor_3_fail ; NO - HUD reports a fail
674
675 check_sensor_3_ok: 707 check_sensor_3_ok:
676 ; o2_ppo2_sensor3 := o2_mv_sensor3:2 * opt_x_s1:2 / 1000 708 ; o2_ppo2_sensor3 = o2_mv_sensor3:2 * opt_x_s1:2 / 1000
677 movff o2_mv_sensor3+0,xA+0 709 movff o2_mv_sensor3+0,xA+0
678 movff o2_mv_sensor3+1,xA+1 710 movff o2_mv_sensor3+1,xA+1
679 movff opt_x_s3+0,xB+0 711 movff opt_x_s3+0,xB+0
680 movff opt_x_s3+1,xB+1 712 movff opt_x_s3+1,xB+1
681 rcall compute_ppo2_helper 713 rcall compute_ppo2_helper
682 movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar 714 movff xC+0,o2_ppo2_sensor3 ; result in 0.01 bar
683 bra calc_deko_divemode_sensor1 ; continue with calculating sensor average 715 bra calc_deko_divemode_sensor_A ; continue with calculating sensor average
684
685 check_sensor_3_fail: 716 check_sensor_3_fail:
686 clrf WREG 717 clrf WREG
687 movff WREG,o2_ppo2_sensor3 ; set ppO2 reading to zero 718 movff WREG,o2_ppo2_sensor3 ; set ppO2 reading to zero
688 btfss use_O2_sensor3 ; check if sensor was in use before 719 btfss use_O2_sensor3 ; check if sensor was in use before
689 bra check_sensor_3_fail_1 ; NO - no new news then 720 bra check_sensor_3_fail_1 ; NO - no new news then
690 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met 721 call check_sensor_custview_helper; YES - show custom view 1 (sensor values) on further conditions met
691 check_sensor_3_fail_1: 722 check_sensor_3_fail_1:
692 bcf use_O2_sensor3 ; revoke sensor from usage 723 bcf use_O2_sensor3 ; revoke sensor from usage
693 ;bra calc_deko_divemode_sensor1 ; continue with calculating sensor average 724
694 725 calc_deko_divemode_sensor_A: ; calculate sensor average
695 calc_deko_divemode_sensor1: ; calculate sensor average 726 ; exit here if not in dive mode
696 ; exit here if not in divemode
697 btfss divemode 727 btfss divemode
698 return 728 return
699 729
700 ; compute sensor_setpoint := average of all o2_ppo2_sensorX of those sensors that have use_O2_sensorX == true 730 ; compute sensor_setpoint = average of all o2_ppo2_sensorX of those sensors that have use_O2_sensorX == true
701 ; sum up sensor values (in xA:2) and active sensors in (xB:2) 731 ; sum up sensor values (in xA:2) and active sensors in (xB:2)
702 clrf xB+0 732 clrf xB+0
703 clrf xB+1 733 clrf xB+1
704 clrf xA+0 734 clrf xA+0
705 clrf xA+1 735 clrf xA+1
706 btfss use_O2_sensor1 ; Sensor1 active? 736 divemode_setup_sensor_1_value:
707 bra divemode_setup_sensor_values2 ; No 737 btfss use_O2_sensor1 ; sensor1 active?
738 bra divemode_setup_sensor_2_value ; NO
708 movf o2_ppo2_sensor1,W 739 movf o2_ppo2_sensor1,W
709 addwf xA+0 740 addwf xA+0,F
710 movlw .0 741 movlw .0
711 addwfc xA+1 ; Add into xA:2 742 addwfc xA+1,F ; add into xA:2
712 incf xB+0,F ; Add a sensor 743 incf xB+0,F ; add a sensor
713 divemode_setup_sensor_values2: 744 divemode_setup_sensor_2_value:
714 btfss use_O2_sensor2 ; Sensor2 active? 745 btfss use_O2_sensor2 ; sensor2 active?
715 bra divemode_setup_sensor_values3 ; No 746 bra divemode_setup_sensor_3_value ; NO
716 movf o2_ppo2_sensor2,W 747 movf o2_ppo2_sensor2,W
717 addwf xA+0 748 addwf xA+0,F
718 movlw .0 749 movlw .0
719 addwfc xA+1 ; Add into xA:2 750 addwfc xA+1,F ; add into xA:2
720 incf xB+0,F ; Add a sensor 751 incf xB+0,F ; add a sensor
721 divemode_setup_sensor_values3: 752 divemode_setup_sensor_3_value:
722 btfss use_O2_sensor3 ; Sensor3 active? 753 btfss use_O2_sensor3 ; sensor3 active?
723 bra divemode_setup_sensor_values4 ; No 754 bra divemode_setup_sensor_mean ; NO
724 movf o2_ppo2_sensor3,W 755 movf o2_ppo2_sensor3,W
725 addwf xA+0 756 addwf xA+0,F
726 movlw .0 757 movlw .0
727 addwfc xA+1 ; Add into xA:2 758 addwfc xA+1,F ; add into xA:2
728 incf xB+0,F ; Add a sensor 759 incf xB+0,F ; add a sensor
729 760
730 ; Divide sum of sensor values by number of active sensors found. 761 ; divide sum of sensor values by number of active sensors found
731 divemode_setup_sensor_values4: 762 divemode_setup_sensor_mean:
732 call div16x16 ; xA/xB=xC with xA+0 as remainder 763 clrf xC+0 ; set zero as default result
733 movff xC+0,sensor_setpoint ; copy result 764 tstfsz xB+0 ; pending div/0 ?
734 765 call div16x16 ; NO - execute xC = xA / xB = summed ppO2 / number of sensors
735 ; set default value for pSCR mode: 0 = let p2_deco.c compute the ppO2 based on current dil gas and depth 766 movff xC+0,sensor_setpoint ; copy result (or its default)
767
768 ; set default value for pSCR mode: 0 => let p2_deco.c compute the ppO2 based on current dil gas and depth
736 ; will be overwritten later in case we are in sensor mode and have at least one usable sensor 769 ; will be overwritten later in case we are in sensor mode and have at least one usable sensor
737 clrf WREG ; preload a zero 770 clrf WREG ; preload a zero
738 btfsc FLAG_pscr_mode ; check if we are in pSCR mode 771 btfsc FLAG_pscr_mode ; check if we are in pSCR mode
739 movff WREG,char_I_const_ppO2 ; YES - write 0 to char_I_const_ppo2, 772 movff WREG,char_I_const_ppO2 ; YES - write 0 to char_I_const_ppo2,
740 ; it will be overwritten if we have a usable sensor reading 773 ; it will be overwritten if we have a usable sensor reading
741 774 btfsc FLAG_bailout_mode ; check if we are in bailout
742 btfsc is_bailout ; check if we are in bailout 775 bra calc_deko_divemode_sensor_V ; YES - no sensor data transfer to char_I_const_ppO2 in this case
743 bra calc_deko_divemode_sensor2 ; YES - no sensor data transfer to char_I_const_ppO2 in this case 776 movff opt_ccr_mode,WREG ; NO - get mode (0: Fixed SP, 1: Sensor, 2: Auto SP)
744 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 777 sublw .1 ; - in sensor mode?
745 sublw .1 ; opt_ccr_mode = 1 (Sensor)? 778 bnz calc_deko_divemode_sensor_V ; NO - not in sensor mode - no transfer of sensor data to char_I_const_ppO2
746 bnz calc_deko_divemode_sensor2 ; not in sensor mode - no transfer of sensor data to char_I_const_ppO2 779 tstfsz xB+0 ; YES - check if we have found at least one usable sensor
747 tstfsz xB+0 ; check if we have found at least one usable sensor 780 bra divemode_setup_sensor_mean1 ; YES - we have at least one usable sensor
748 bra calc_deko_divemode_sensor1a ; YES - we have at least one usable sensor 781 bsf setpoint_fallback ; NO - we have NO usable sensors -> initiate fallback
749 bsf setpoint_fallback ; NO - we have NO usable sensors -> initiate fallback 782 btfss FLAG_ccr_mode ; - check if we are in CCR mode
750 btfss FLAG_ccr_mode ; check if we are in CCR mode 783 bra calc_deko_divemode_sensor_V ; NO - continue with voting logic flags
751 bra calc_deko_divemode_sensor2 ; NO - continue with voting logic flags 784 movff char_I_setpoint_cbar+0,char_I_const_ppO2; YES - select fixed setpoint no. 1 for fallback
752 movff char_I_setpoint_cbar+0,char_I_const_ppO2 ; YES - select fixed setpoint no. 1 for fallback 785 bra calc_deko_divemode_sensor_V ; - continue with voting logic flags
753 bra calc_deko_divemode_sensor2 ; done - continue with voting logic flags 786 ; we have at least one usable sensor with a ppO2 value > 0
754 calc_deko_divemode_sensor1a: ; we have at least one usable sensor with a value > 0 787 divemode_setup_sensor_mean1:
755 bcf setpoint_fallback ; clear fallback condition 788 bcf setpoint_fallback ; clear fallback condition
756 movff sensor_setpoint,char_I_const_ppO2 ; transfer average sensor value to p2_deco.c code 789 movff sensor_setpoint,char_I_const_ppO2 ; transfer average sensor value to p2_deco.c code
757 ;bra calc_deko_divemode_sensor2 790 ; vote sensors
758 791 calc_deko_divemode_sensor_V:
759 calc_deko_divemode_sensor2:
760 bsf voting_logic_sensor1 792 bsf voting_logic_sensor1
761 movff o2_ppo2_sensor1,lo 793 movff o2_ppo2_sensor1,lo
762 rcall check_sensor_voting_helper 794 rcall check_sensor_voting_helper
763 incfsz WREG ; Was WREG = 255? 795 tstfsz WREG ; sensor within range (WREG = 0)?
764 bcf voting_logic_sensor1 ; No, ignore this sensor 796 bcf voting_logic_sensor1 ; NO - vote out this sensor
765 797
766 bsf voting_logic_sensor2 798 bsf voting_logic_sensor2
767 movff o2_ppo2_sensor2,lo 799 movff o2_ppo2_sensor2,lo
768 rcall check_sensor_voting_helper 800 rcall check_sensor_voting_helper
769 incfsz WREG ; Was WREG=255? 801 tstfsz WREG ; sensor within range (WREG = 0)?
770 bcf voting_logic_sensor2 ; No, ignore this sensor 802 bcf voting_logic_sensor2 ; NO - vote out this sensor
771 803
772 bsf voting_logic_sensor3 804 bsf voting_logic_sensor3
773 movff o2_ppo2_sensor3,lo 805 movff o2_ppo2_sensor3,lo
774 rcall check_sensor_voting_helper 806 rcall check_sensor_voting_helper
775 incfsz WREG ; Was WREG=255? 807 tstfsz WREG ; sensor within range (WREG = 0)?
776 bcf voting_logic_sensor3 ; No, ignore this sensor 808 bcf voting_logic_sensor3 ; NO - vote out this sensor
777 809
778 ; check if a warning shall be issued on sensor disagreement 810 ; check if a warning shall be issued on sensor disagreement
779
780 btfsc FLAG_ccr_mode ; check if we are in CCR mode 811 btfsc FLAG_ccr_mode ; check if we are in CCR mode
781 bra check_warn_sensor_1 ; YES - continue with further checks 812 bra check_warn_sensor_0 ; YES - continue with further checks
782 btfsc FLAG_pscr_mode ; check if we are in pSCR mode 813 btfsc FLAG_pscr_mode ; check if we are in pSCR mode
783 bra check_warn_sensor_1 ; YES - continue with further checks 814 bra check_warn_sensor_0 ; YES - continue with further checks
784 bra check_warn_sensor_agree ; not in CCR and not in pSCR, so no warning 815 bra check_warn_sensor_done ; not in CCR and not in pSCR, so no warning
785 check_warn_sensor_1: ; we are in CCR or pSCR mode 816 check_warn_sensor_0: ; we are in CCR or pSCR mode
786 btfsc is_bailout ; check if we are in bailout 817 btfsc FLAG_bailout_mode ; check if we are in bailout
787 bra check_warn_sensor_agree ; YES - no warning in this case 818 bra check_warn_sensor_done ; YES - no warning in this case
788 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 819 movff opt_ccr_mode,WREG ; get mode (0: Fixed SP, 1: Sensor, 2: Auto SP)
789 sublw .1 ; opt_ccr_mode = 1 (Sensor)? 820 sublw .1 ; in sensor mode?
790 bnz check_warn_sensor_agree ; not in sensor mode - no warning in this case 821 bnz check_warn_sensor_done ; NO - not in sensor mode - no warning in this case
791 ; check sensor 1 822 ; check sensor 1
823 check_warn_sensor_1:
792 btfss sensor1_calibrated_ok ; check if sensor has a valid calibration 824 btfss sensor1_calibrated_ok ; check if sensor has a valid calibration
793 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then 825 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then
794 btfss use_O2_sensor1 ; YES - check if sensor is in use 826 btfss use_O2_sensor1 ; YES - check if sensor is in use
795 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then 827 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then
796 btfsc voting_logic_sensor1 ; YES - check if sensor value is within agreement range 828 btfsc voting_logic_sensor1 ; YES - check if sensor value is within agreement range
797 bra check_warn_sensor_2 ; YES - continue with next sensor 829 bra check_warn_sensor_2 ; YES - continue with next sensor
798 bcf sensors_agree ; NO - issue a warning 830 bcf sensors_agree ; NO - issue a warning
799 return 831 return
800 832 ; check sensor 2
801 check_warn_sensor_2: ; check sensor 2 833 check_warn_sensor_2:
802 btfss sensor2_calibrated_ok ; check if sensor has a valid calibration 834 btfss sensor2_calibrated_ok ; check if sensor has a valid calibration
803 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then 835 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then
804 btfss use_O2_sensor2 ; YES - check if sensor is in use 836 btfss use_O2_sensor2 ; YES - check if sensor is in use
805 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then 837 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then
806 btfsc voting_logic_sensor2 ; YES - check if sensor value is within agreement range 838 btfsc voting_logic_sensor2 ; YES - check if sensor value is within agreement range
807 bra check_warn_sensor_3 ; YES - continue with next sensor 839 bra check_warn_sensor_3 ; YES - continue with next sensor
808 bcf sensors_agree ; NO - issue a warning 840 bcf sensors_agree ; NO - issue a warning
809 return 841 return
810 842 ; check sensor 3
811 check_warn_sensor_3: ; check sensor 2 843 check_warn_sensor_3:
812 btfss sensor3_calibrated_ok ; check if sensor has a valid calibration 844 btfss sensor3_calibrated_ok ; check if sensor has a valid calibration
813 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then 845 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then
814 btfss use_O2_sensor3 ; YES - check if sensor is in use 846 btfss use_O2_sensor3 ; YES - check if sensor is in use
815 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then 847 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then
816 btfsc voting_logic_sensor3 ; YES - check if sensor value is within agreement range 848 btfsc voting_logic_sensor3 ; YES - check if sensor value is within agreement range
817 bra check_warn_sensor_agree ; YES - continue with next sensor 849 bra check_warn_sensor_agree ; YES - continue with next sensor
818 bcf sensors_agree ; NO - issue a warning 850 bcf sensors_agree ; NO - issue a warning
819 return 851 return
820 852 ; no need for a warning
853 check_warn_sensor_done:
821 check_warn_sensor_agree: 854 check_warn_sensor_agree:
822 bsf sensors_agree 855 bsf sensors_agree
823 return 856 return
857
858
859 check_min_threshold:
860 movlw LOW min_mv ; load minimum mV value
861 movwf sub_b+0
862 movlw HIGH min_mv
863 movwf sub_b+1
864 goto sub16 ; sub_c = sensor_mv - min_mv (and return)
865
866 check_max_threshold:
867 movlw LOW max_mv
868 movwf sub_b+0
869 movlw HIGH max_mv
870 movwf sub_b+1
871 goto sub16 ; sub_c = sensor_mv - max_mv (and return)
824 872
825 compute_ppo2_helper: 873 compute_ppo2_helper:
826 call mult16x16 ; xA:2*xB:2=xC:4 874 call mult16x16 ; xA:2*xB:2=xC:4
827 movlw LOW .1000 875 movlw LOW .1000
828 movwf xB+0 876 movwf xB+0
832 movlw d'1' 880 movlw d'1'
833 addwf xC+0,W ; we are just interested in the carry flag 881 addwf xC+0,W ; we are just interested in the carry flag
834 movlw d'0' 882 movlw d'0'
835 addwfc xC+1,W ; we are still just interested in the carry flag 883 addwfc xC+1,W ; we are still just interested in the carry flag
836 tstfsz WREG ; ppO2 is higher than 2.55bar? 884 tstfsz WREG ; ppO2 is higher than 2.55bar?
837 setf xC+0 ; Yes. 885 setf xC+0 ; YES
838 return 886 return
839 887
840 check_sensor_custview_helper: 888 check_sensor_custview_helper:
841 btfss divemode ; check if we are in divemode 889 btfss divemode ; check if we are in dive mode
842 return ; NO - not in dive mode, return 890 return ; NO - not in dive mode, return
843 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 891 movff opt_ccr_mode,WREG ; YES - =0: Fixed SP, =1: Sensor, =2: Auto SP
844 sublw .1 ; opt_ccr_mode = 1 (Sensors)? 892 decfsz WREG,W ; - opt_ccr_mode = 1 (sensors)?
845 bnz check_sensor_helper_1 ; NO - not using the sensors in the moment 893 return ; NO - not using the sensors in the moment
846 clrf menupos3 ; YES - arm customview 1 (sensor values) 894 btfsc alternative_divelayout ; YES - in alternative layout?
847 bsf toggle_customview ; and request a customview toggle 895 call switch_layout_to_normal ; YES - switch to normal layout
848 check_sensor_helper_1: 896 movlw index_ppo2_sensors-1 ; custom view number one below ppO2 sensors
849 return 897 movwf menupos3 ; set custom view number
850 898 bsf toggle_customview ; initiate toggle to desired custom view -> ppO2 sensors
899 return
851 900
852 check_sensor_voting_helper: 901 check_sensor_voting_helper:
853 movf lo,W 902 movf lo,W
854 cpfsgt sensor_setpoint 903 cpfsgt sensor_setpoint
855 bra check_sensor_voting_common2 ; lo < sensor_setpoint 904 bra check_sensor_voting_helper2 ; lo < sensor_setpoint
856 ; lo > sensor_setpoint 905 ; lo > sensor_setpoint
857 movf lo,W 906 movf lo,W
858 subwf sensor_setpoint,W 907 subwf sensor_setpoint,W
859 movwf lo 908 movwf lo
860 check_sensor_voting_common1: 909 check_sensor_voting_helper1:
861 movlw sensor_voting_logic_threshold ; Threshold in 0.01 bar 910 movlw sensor_voting_logic_threshold ; threshold in 0.01 bar
862 cpfsgt lo 911 cpfsgt lo
863 retlw .255 ; Within range 912 retlw .0 ; within range
864 retlw .0 ; Out of range 913 retlw .1 ; out of range
865 check_sensor_voting_common2: 914 check_sensor_voting_helper2:
866 ; lo<sensor_setpoint 915 ; lo < sensor_setpoint
867 movf sensor_setpoint,W 916 movf sensor_setpoint,W
868 subwf lo,F 917 subwf lo,F
869 bra check_sensor_voting_common1 918 bra check_sensor_voting_helper1
870 919
871 ;----------------------------------------------------------------------------- 920 ;-----------------------------------------------------------------------------
872 921
873 divemodemode_togglegf: ; Toggle aGF/GF 922 divemodemode_togglegf: ; toggle aGF/GF
874 bcf toggle_gf ; clear flag 923 bcf toggle_gf ; clear command flag
875 btg use_agf ; toggle GF 924 btg use_agf ; toggle status flag for GF
876 925
877 btfsc use_agf ; switch to aGF? 926 btfsc use_agf ; aGF activated?
878 bra divemodemode_togglegf_1 ; YES - branch to using aGF 927 bra divemodemode_togglegf_1 ; YES - branch to using aGF
879 movff opt_GF_low,char_I_GF_Low_percentage ; NO - use normal GF factors 928 movff opt_GF_low,char_I_GF_Low_percentage ; NO - use normal GF factors
880 movff opt_GF_high,char_I_GF_High_percentage ; 929 movff opt_GF_high,char_I_GF_High_percentage ; -
881 bra divemodemode_togglegf_2 ; continue with common part 930 bra divemodemode_togglegf_2 ; - continue with common part
882 931 divemodemode_togglegf_1:
883 divemodemode_togglegf_1: ; use alternative GF factors 932 movff opt_aGF_low,char_I_GF_Low_percentage ; YES - use alternative GF factors
884 movff opt_aGF_low,char_I_GF_Low_percentage 933 movff opt_aGF_high,char_I_GF_High_percentage ; -
885 movff opt_aGF_high,char_I_GF_High_percentage
886
887 divemodemode_togglegf_2: 934 divemodemode_togglegf_2:
888 call TFT_gf_mask ; update customview mask to show which one is in use 935 call TFT_gf_factors_mask ; update custom view mask to show which one is in use
889 ; the customview itself has been called from divemenu_tree before 936 ; the custom view itself has been called from divemenu_tree before
890 goto restart_deco_engine ; ...and return 937 goto restart_deco_engine ; ...and return
891 938
892 939
893 calc_velocity: ; called every two seconds 940 IFDEF _cave_mode
941 divemodemode_toggleturn:
942 bcf toggle_turn_dive ; clear command flag
943 btg FLAG_dive_turned ; toggle dive turned state
944 btfsc FLAG_cave_mode_shutdown ; cave mode function shut down?
945 bsf FLAG_dive_turned ; YES - allow only activating turned state
946 goto set_logbook_marker ; set a logbook marker (and return)
947 ENDIF
948
949 calc_velocity: ; called every two seconds
894 btfsc display_velocity 950 btfsc display_velocity
895 bra calc_velocity1 ; Always update if already displayed 951 bra calc_velocity1 ; always update if already displayed
896 btfss divemode2 952 btfss divemode2
897 return ; display velocity only if deeper then 1m (Not at the surface after the dive) 953 return ; display velocity only if deeper then 1m (Not at the surface after the dive)
898 calc_velocity1: 954 calc_velocity1:
899 SAFE_2BYTE_COPY amb_pressure, sub_a 955 SAFE_2BYTE_COPY amb_pressure, sub_a
900 movff last_pressure_velocity+0,sub_b+0 956 movff last_pressure_velocity+0,sub_b+0
901 movff last_pressure_velocity+1,sub_b+1 957 movff last_pressure_velocity+1,sub_b+1
902 movff sub_a+0,last_pressure_velocity+0 ; store old value for velocity 958 movff sub_a+0,last_pressure_velocity+0 ; store old value for velocity
903 movff sub_a+1,last_pressure_velocity+1 959 movff sub_a+1,last_pressure_velocity+1
904 960
905 call subU16 ; sub_c = amb_pressure - last_pressure 961 call subU16 ; sub_c = amb_pressure - last_pressure
906 962
907 bcf neg_flag_velocity 963 bcf neg_flag_velocity
908 btfsc neg_flag 964 btfsc neg_flag
909 bsf neg_flag_velocity 965 bsf neg_flag_velocity
910 966
915 clrf xB+1 971 clrf xB+1
916 call mult16x16 ; differential pressure in mbar*77... 972 call mult16x16 ; differential pressure in mbar*77...
917 movff xC+0,divA+0 973 movff xC+0,divA+0
918 movff xC+1,divA+1 974 movff xC+1,divA+1
919 movlw d'7' 975 movlw d'7'
920 movwf divB+0 976 call div16 ; divA = divA / 2^WREG, divide by 2^7 equals velocity in m/min
921 call div16 ; divided by 2^7 equals velocity in m/min
922 977
923 movlw d'99' 978 movlw d'99'
924 cpfsgt divA+0 ; limit to 99m/min 979 cpfsgt divA+0 ; velocity > 99 m/min ?
925 bra calc_velocity3 980 bra calc_velocity3 ; NO
926 movwf divA+0 ; divA=99 981 movwf divA+0 ; YES - set divA = 99
927 982
928 calc_velocity3: 983 calc_velocity3:
929 ; Copy old speeds 984 ; Copy old speeds
930 movff old_velocity+2,old_velocity+3 985 movff old_velocity+2,old_velocity+3
931 movff old_velocity+1,old_velocity+2 986 movff old_velocity+1,old_velocity+2
946 ; rrcf divA+0,F ; /2 1001 ; rrcf divA+0,F ; /2
947 ; movff old_velocity+0,WREG 1002 ; movff old_velocity+0,WREG
948 ; addwf divA+0,F ; add old speed 1003 ; addwf divA+0,F ; add old speed
949 ; bcf STATUS,C 1004 ; bcf STATUS,C
950 ; rrcf divA+0,F ; /2 1005 ; rrcf divA+0,F ; /2
951 goto TFT_display_velocity ; With divA+0 = m/min..., and return... 1006 goto TFT_display_velocity ; with divA+0 = m/min..., and return...
952 1007
953 1008
954 ;============================================================================= 1009 ;=============================================================================
955 1010
956 set_reset_safety_stop: ; Set flags for safety stop and/or reset safety stop 1011 set_reset_safety_stop: ; set flags for safety stop and/or reset safety stop
957 TSTOSS opt_enable_safetystop ; =1: A safety stop is shown 1012 TSTOSS opt_enable_safetystop ; safety stop enabled? (=1: show safety stop)
958 bra delete_safety_stop ; No, don't show safety stop 1013 bra delete_safety_stop ; NO - don't show safety stop
959 1014
960 btfsc decostop_active ; Is a deco stop displayed? 1015 btfsc decostop_active ; is a deco stop displayed?
961 bra delete_safety_stop ; Yes, don't show safety stop 1016 bra delete_safety_stop ; YES - don't show safety stop
962 1017
963 ; Below "opt_safety_stop_reset"? Set flag and reset count-down timer 1018 ; Below "opt_safety_stop_reset"? if yes, set flag and reset count-down timer
964 SAFE_2BYTE_COPY rel_pressure, lo 1019 SAFE_2BYTE_COPY rel_pressure, lo
965 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar] 1020 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar]
966 movff lo,sub_a+0 1021 movff lo,sub_a+0
967 movff hi,sub_a+1 1022 movff hi,sub_a+1
968 movff opt_safety_stop_reset,WREG ; [cbar] 1023 movff opt_safety_stop_reset,WREG ; [cbar]
969 mullw .10 ; mbar in PRODL:H 1024 mullw .10 ; mbar in PRODL:H
970 movff PRODL,sub_b+0 1025 movff PRODL,sub_b+0
971 movff PRODH,sub_b+1 1026 movff PRODH,sub_b+1
972 call subU16 ; sub_c = sub_a - sub_b 1027 call subU16 ; sub_c = sub_a - sub_b
973 btfss neg_flag 1028 btfss neg_flag
974 bra reset_safety_stop ; Below 10m, reset safety stop 1029 bra reset_safety_stop ; below 10m, reset safety stop
975 1030
976 ; Above "opt_safety_stop_end"? Clear flag. 1031 ; Above "opt_safety_stop_end"? if yes ,clear flag
977 SAFE_2BYTE_COPY rel_pressure, lo
978 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar]
979 movff lo,sub_a+0
980 movff hi,sub_a+1
981 movff opt_safety_stop_end,WREG ; [cbar] 1032 movff opt_safety_stop_end,WREG ; [cbar]
982 mullw .10 ; mbar in PRODL:H 1033 mullw .10 ; mbar in PRODL:H
983 movff PRODL,sub_b+0 1034 movff PRODL,sub_b+0 ; sub_a is still loaded with adjusted rel_pressure
984 movff PRODH,sub_b+1 1035 movff PRODH,sub_b+1
985 call subU16 ; sub_c = sub_a - sub_b 1036 call subU16 ; sub_c = sub_a - sub_b
986 btfsc neg_flag 1037 btfsc neg_flag
987 bra delete_safety_stop ; Above 3m, remove safety stop 1038 bra delete_safety_stop ; above 3m, remove safety stop
988 1039
989 ; Above "opt_safety_stop_start"? Activate safety stop 1040 ; Above "opt_safety_stop_start"? if yes, activate safety stop
990 SAFE_2BYTE_COPY rel_pressure, lo
991 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar]
992 movff lo,sub_a+0
993 movff hi,sub_a+1
994 movff opt_safety_stop_start,WREG ; [cbar] 1041 movff opt_safety_stop_start,WREG ; [cbar]
995 mullw .10 ; mbar in PRODL:H 1042 mullw .10 ; mbar in PRODL:H
996 movff PRODL,sub_b+0 1043 movff PRODL,sub_b+0 ; sub_a is still loaded with adjusted rel_pressure
997 movff PRODH,sub_b+1 1044 movff PRODH,sub_b+1
998 call subU16 ; sub_c = sub_a - sub_b 1045 call subU16 ; sub_c = sub_a - sub_b
999 btfsc neg_flag 1046 btfsc neg_flag
1000 bra acivate_safety_stop ; Above 5m, activate safety stop 1047 bra acivate_safety_stop ; above 5m, activate safety stop
1001 bra reset_safety_stop2 ; Pause safety stop 1048 bra reset_safety_stop2 ; pause safety stop
1002 1049
1003 acivate_safety_stop: 1050 acivate_safety_stop:
1004 tstfsz safety_stop_countdown ; Countdown at zero? 1051 tstfsz safety_stop_countdown ; countdown at zero?
1005 bsf show_safety_stop ; No, Set flag! 1052 bsf show_safety_stop ; NO - set flag
1006 return 1053 return
1007 1054
1008 delete_safety_stop: 1055 delete_safety_stop:
1009 clrf safety_stop_countdown ; reset timer 1056 clrf safety_stop_countdown ; reset timer
1010 bra reset_safety_stop2 ; Remove safety stop from display 1057 bra reset_safety_stop2 ; remove safety stop from display
1011 1058
1012 reset_safety_stop: 1059 reset_safety_stop:
1013 movff opt_safety_stop_length,safety_stop_countdown ; reset timer 1060 movff opt_safety_stop_length,safety_stop_countdown ; reset timer
1014 reset_safety_stop2: 1061 reset_safety_stop2:
1015 bcf show_safety_stop ; Clear flag 1062 bcf show_safety_stop ; clear flag
1016 btfss safety_stop_active ; Safety stop shown 1063 btfss safety_stop_active ; safety stop shown?
1017 return ; No, don't delete it 1064 return ; NO - don't delete it
1018 bcf safety_stop_active ; Clear flag 1065 bcf safety_stop_active ; clear flag
1019 bsf FLAG_TFT_clear_safety_stop ; Clear safety stop 1066 bsf FLAG_TFT_clear_safety_stop ; Clear safety stop
1020 return 1067 return
1021 1068
1022 1069
1023 ;============================================================================= 1070 ;=============================================================================
1024 1071
1025 timeout_menuview: 1072 timeout_menuview:
1026 decfsz timeout_counter2,F ; timeout for menuview 1073 decfsz timeout_counter2,F ; timeout for menu view?
1027 return ; No timeout, return 1074 return ; NO - done
1028 ; Timeout, clear e.g. "Menu?" 1075 ; Timeout, clear e.g. "Menu?"
1029 goto menuview_toggle_reset ; "returns" 1076 goto menuview_toggle_reset ; ...and return
1030 1077
1031 timeout_divemode_menu: 1078 timeout_divemode_menu:
1032 decfsz timeout_counter2,F ; timeout for divemode menu 1079 decfsz timeout_counter2,F ; timeout for divemode menu
1033 return 1080 return
1034 1081
1035 global timeout_divemode_menu2 1082 global timeout_divemode_menu2
1036 timeout_divemode_menu2: ; Called from divemenu_tree.asm 1083 timeout_divemode_menu2: ; called from divemenu_tree.asm
1037 bcf divemode_menu ; Timeout! Clear flag 1084 bcf divemode_menu ; timeout, clear flag
1038 call TFT_clear_divemode_menu ; Clear menu 1085 call TFT_clear_divemode_menu ; clear menu
1039 bsf FLAG_TFT_active_gas_divemode; Redraw gas/setpoint/diluent 1086 bsf FLAG_TFT_active_gas_divemode; redraw gas/setpoint/diluent
1040 bcf blinking_better_gas ; Clear flag to have temperature updated once 1087 bcf blinking_better_gas ; clear flag to have temperature updated once
1041 bsf FLAG_TFT_temp_divemode ; Displays temperature 1088 bcf blinking_better_dil ; clear flag to have temperature updated once
1042 call TFT_draw_gassep_line ; Gas separator grid in spec mode only 1089 bsf FLAG_TFT_temp_divemode ; display temperature
1043 1090 call TFT_draw_gassep_line ; gas separator grid in spec mode only
1044 btfss decostop_active ; In deco mode ? 1091
1045 bra timeout_divemode_menu_ndl ; No, show NDL again 1092 btfss decostop_active ; in deco mode ?
1046 ; Show deco 1093 bra timeout_divemode_menu_ndl ; NO - show NDL again
1094 ; Show deco data
1047 bsf FLAG_TFT_display_deko_mask 1095 bsf FLAG_TFT_display_deko_mask
1048 bsf FLAG_TFT_display_deko 1096 bsf FLAG_TFT_display_deko
1049 bsf FLAG_TFT_display_tts 1097 bsf FLAG_TFT_display_tts
1050 return 1098 return
1051 1099
1054 bsf FLAG_TFT_display_ndl_mask 1102 bsf FLAG_TFT_display_ndl_mask
1055 bsf FLAG_TFT_display_ndl 1103 bsf FLAG_TFT_display_ndl
1056 return 1104 return
1057 1105
1058 timeout_divemode: 1106 timeout_divemode:
1059 btfsc divemode_menu ; Divemode menu active? 1107 btfsc divemode_menu ; divemode menu active?
1060 rcall timeout_divemode_menu ; Yes, check the timeout for it... 1108 rcall timeout_divemode_menu ; YES - check the timeout for it...
1061 1109
1062 btfsc menuview ; is a menuview shown? 1110 btfsc menuview ; is a menu view shown?
1063 rcall timeout_menuview ; Yes, check the timeout for it... 1111 rcall timeout_menuview ; YES - check the timeout for it...
1064 1112
1065 btfss realdive ; Dive longer then one minute 1113 btfss realdive ; dive longer than one minute?
1066 return 1114 return ; NO - done
1067 1115
1068 btfsc FLAG_apnoe_mode ; In Apnoe mode? 1116 btfsc FLAG_apnoe_mode ; in apnoe mode?
1069 bra timeout_divemode2 ; Yes, use apnoe_timeout [min] for timeout 1117 bra timeout_divemode2 ; YES - use apnoe_timeout [min] for timeout
1070 1118
1071 ifndef __DEBUG 1119 IFNDEF __DEBUG
1072 btfsc simulatormode_active ; In Simulator mode? 1120 btfsc simulatormode_active ; in simulator mode?
1073 bra timeout_divemode3 ; Yes, use simulator timeout 1121 bra timeout_divemode3 ; YES - use simulator timeout
1074 endif 1122 ENDIF
1075 1123
1076 bcf divemode 1124 bcf divemode ; terminate divemode my default
1077 infsnz timeout_counter1+0,F 1125 infsnz timeout_counter1+0,F ; increment timeout counter
1078 incf timeout_counter1+1,F ; timeout is 16 bit counter 1126 incf timeout_counter1+1,F ; timeout is 16 bit counter
1079 1127
1080 movff opt_diveTimeout,WREG ; in [min] 1128 movff opt_diveTimeout,WREG ; get timeout in minutes
1081 mullw .60 1129 mullw .60 ; convert into seconds
1082 movff PRODL,sub_a+0 1130 movff PRODL,sub_a+0
1083 movff PRODH,sub_a+1 ; in [s] 1131 movff PRODH,sub_a+1
1084 1132
1085 movff timeout_counter1+0,sub_b+0 1133 movff timeout_counter1+0,sub_b+0
1086 movff timeout_counter1+1,sub_b+1 1134 movff timeout_counter1+1,sub_b+1
1087 call subU16 ; sub_c = sub_a - sub_b 1135 call subU16 ; sub_c = sub_a - sub_b
1088 btfss neg_flag ; Result negative? 1136 btfss neg_flag ; result negative, i.e. timeout?
1089 bsf divemode ; No, set flag 1137 bsf divemode ; NO - set divemode flag again
1090 return 1138 return
1091 1139
1092 timeout_divemode2: 1140 timeout_divemode2:
1093 incf timeout_counter1+0,F ; seconds... 1141 incf timeout_counter1+0,F ; seconds...
1094 movlw d'60' 1142 movlw d'60'
1111 bsf divemode 1159 bsf divemode
1112 return 1160 return
1113 1161
1114 update_divemode60: ; update any minute 1162 update_divemode60: ; update any minute
1115 call get_battery_voltage ; gets battery voltage 1163 call get_battery_voltage ; gets battery voltage
1116 rcall set_powersafe ; Battery low? 1164 rcall set_powersafe ; check if battery low
1117 call customview_minute ; Do every-minute tasks for the custom view area 1165 ;call customview_minute ; do every-minute tasks for the custom view area
1118 bcf oneminupdate 1166 bcf oneminupdate
1119 1167 IFDEF _cave_mode
1168 movlw .1 ; prepare to add backtrack data for 1 minute
1169 btfsc FLAG_cave_mode ; cave mode enabled?
1170 rcall update_backtrack ; YES - make it so
1171 ENDIF
1120 btfss simulatormode_active ; in simulator mode? 1172 btfss simulatormode_active ; in simulator mode?
1121 return ; No 1173 return ; NO - done
1122 ; Yes, quite dive mode simulation after 21*256s=89min:36s 1174 movlw .20 ; YES - quite dive mode simulation after 21 * 256 sec = 89 min : 36 sec
1123 movlw .20 1175 cpfsgt total_divetime_seconds+1 ; timeout?
1124 cpfsgt total_divetime_seconds+1 ; Timeout? 1176 return ; NO - done
1125 return ; No 1177 IFDEF __DEBUG
1126 1178 return ; YES - but no timeout in debug mode
1127 ifdef __DEBUG 1179 ENDIF
1128 return ; No simulator timeout in debug mode 1180 bra divemode_option1 ; YES - set depth to 0 m and "return"
1129 endif 1181
1130 1182 IFDEF _cave_mode
1131 bra divemode_option1 ; Yes, set to 0m and "return" 1183 update_backtrack:
1184 btfsc FLAG_dive_turned ; dive turned?
1185 return ; YES - done
1186 movwf lo ; store minutes to add in lo
1187 lfsr FSR1,char_I_backtrack_depth ; load FSR1 with base address of backtrack storage
1188 movff char_I_backtrack_time,FSR1L ; adjust FSR1 to last index
1189 update_backtrack_loop:
1190 btfsc FLAG_cave_mode_shutdown ; backtrack storage full?
1191 return ; YES - done
1192 movff curr_depth,PREINC1 ; NO - increment index and write current depth to backtrack storage
1193 incfsz FSR1L,W ; - did a wrap-around of the index occur (backtrack storage full)?
1194 bra update_backtrack_loop_1 ; NO - continue loop
1195 bsf FLAG_cave_mode_shutdown ; YES - flag backtrack storage as being full
1196 return
1197 update_backtrack_loop_1:
1198 decfsz lo,F ; decrement loop counter, did it became zero?
1199 bra update_backtrack_loop ; NO - loop
1200 movff FSR1L,char_I_backtrack_time ; YES - read-back index
1201 return ; - done
1202 ENDIF
1132 1203
1133 set_max_depth: 1204 set_max_depth:
1134 movff max_pressure+0,sub_a+0 1205 movff max_pressure+0,sub_a+0
1135 movff max_pressure+1,sub_a+1 1206 movff max_pressure+1,sub_a+1
1136 SAFE_2BYTE_COPY rel_pressure, sub_b 1207 SAFE_2BYTE_COPY rel_pressure, sub_b
1137 call subU16 ; sub_c = sub_a - sub_b 1208 call subU16 ; sub_c = sub_a - sub_b
1138 ; max_pressure<rel_pressure -> neg_flag=1 1209 ; max_pressure < rel_pressure -> neg_flag=1
1139 ; rel_pressure<=max_pressure -> neg_flag=0 1210 ; rel_pressure <= max_pressure -> neg_flag=0
1140 btfss neg_flag 1211 btfss neg_flag
1141 return 1212 return
1142 ; max_pressure<rel_pressure 1213 ; max_pressure < rel_pressure
1143 movff sub_b+0,max_pressure+0 1214 movff sub_b+0,max_pressure+0
1144 movff sub_b+1,max_pressure+1 1215 movff sub_b+1,max_pressure+1
1145 bsf FLAG_TFT_max_depth ; Set flag 1216 bsf FLAG_TFT_max_depth ; set flag
1146 return 1217 return
1147 1218
1148 set_min_temp: 1219 set_min_temp:
1149 movff minimum_temperature+0,sub_a+0 1220 movff minimum_temperature+0,sub_a+0
1150 movff minimum_temperature+1,sub_a+1 1221 movff minimum_temperature+1,sub_a+1
1151 SAFE_2BYTE_COPY temperature,sub_b 1222 SAFE_2BYTE_COPY temperature,sub_b
1152 call sub16 ; sub_c = sub_a - sub_b 1223 call sub16 ; sub_c = sub_a - sub_b
1153 ; minimum_temperature<T -> neg_flag=1 1224 ; minimum_temperature < T -> neg_flag=1
1154 ; T<=minimum_temperature -> neg_flag=0 1225 ; T <= minimum_temperature -> neg_flag=0
1155 btfsc neg_flag 1226 btfsc neg_flag
1156 return 1227 return
1157 ; minimum_temperature >= T 1228 ; minimum_temperature >= T
1158 movff sub_b+0,minimum_temperature+0 1229 movff sub_b+0,minimum_temperature+0
1159 movff sub_b+1,minimum_temperature+1 1230 movff sub_b+1,minimum_temperature+1
1160 return 1231 return
1161 1232
1162 global set_dive_modes 1233 global set_dive_modes
1163 set_dive_modes: 1234 set_dive_modes:
1164 btfsc high_altitude_mode ; In high altitude (Fly) mode? 1235 btfsc high_altitude_mode ; in high altitude (fly) mode?
1165 bra set_dive_modes3 ; Yes! 1236 bra set_dive_modes3 ; YES
1166 1237
1167 set_dive_modes0: 1238 set_dive_modes0:
1168 movlw LOW start_dive_threshold 1239 movlw LOW start_dive_threshold
1169 movwf sub_a+0 ; dive_treshold is in cm 1240 movwf sub_a+0 ; dive_treshold is in cm
1170 movlw HIGH start_dive_threshold 1241 movlw HIGH start_dive_threshold
1175 call subU16 ; sub_c = sub_a - sub_b 1246 call subU16 ; sub_c = sub_a - sub_b
1176 1247
1177 btfss neg_flag 1248 btfss neg_flag
1178 bra set_dive_modes2 ; too shallow (rel_pressure < dive_threshold) 1249 bra set_dive_modes2 ; too shallow (rel_pressure < dive_threshold)
1179 1250
1180 btfsc realdive ; Dive longer than one minute? 1251 btfsc realdive ; dive longer than one minute?
1181 clrf timeout_counter1+0 ; Yes, reset timeout counter +++ 1252 clrf timeout_counter1+0 ; YES - reset timeout counter
1182 1253
1183 bsf divemode ; (Re-)Set divemode flag 1254 bsf divemode ; (re-)set divemode flag
1184 bsf divemode2 ; displayed divetime is running 1255 bsf divemode2 ; displayed divetime is running
1185 return 1256 return
1186 1257
1187 set_dive_modes2: 1258 set_dive_modes2:
1188 bcf divemode2 ; Stop time 1259 bcf divemode2 ; stop time
1189 btfss realdive ; dive longer then one minute? 1260 btfss realdive ; dive longer then one minute?
1190 bcf divemode ; no -> this was no real dive 1261 bcf divemode ; NO - this was no real dive
1191 return ; No, return 1262 return ; YES - return
1192 1263
1193 1264 set_dive_modes3: ; high-altitude mode
1194 set_dive_modes3: ; High-altitude mode
1195 btfsc realdive ; dive longer then one minute? 1265 btfsc realdive ; dive longer then one minute?
1196 bra set_dive_modes0 ; Yes -> this is a real dive -> Use start_dive_threshold or ascend 1266 bra set_dive_modes0 ; YES - this is a real dive -> Use start_dive_threshold or ascend
1197 1267
1198 movlw LOW high_altitude_dive_threshold 1268 movlw LOW high_altitude_dive_threshold
1199 movwf sub_a+0 1269 movwf sub_a+0
1200 movlw HIGH high_altitude_dive_threshold 1270 movlw HIGH high_altitude_dive_threshold
1201 movwf sub_a+1 1271 movwf sub_a+1
1204 set_powersafe: 1274 set_powersafe:
1205 movlw color_code_battery_low+1; [%] 1275 movlw color_code_battery_low+1; [%]
1206 cpfslt batt_percent 1276 cpfslt batt_percent
1207 return 1277 return
1208 1278
1209 movlw d'7' ; Type of Alarm (Battery Low) 1279 movlw d'7' ; type of alarm (battery Low)
1210 movwf AlarmType ; Copy to Alarm Register 1280 movwf AlarmType ; copy to alarm register
1211 bsf event_occured ; set event flag 1281 bsf event_occured ; set event flag
1212 movlw .0 1282 movlw .0
1213 movff WREG,opt_brightness ; Set Brightness to ECO 1283 movff WREG,opt_brightness ; set brightness to ECO
1214 return ; return 1284 return ; return
1215 1285
1286
1287 reset_average:
1288 bcf reset_average_depth ; clear reset-average flag
1289 clrf average_depth_hold+0 ; clear the depth accumulator
1290 clrf average_depth_hold+1 ; ...
1291 clrf average_depth_hold+2 ; ...
1292 clrf average_depth_hold+3 ; ...
1293 clrf average_divesecs+0 ; clear the time accumulator
1294 clrf average_divesecs+1 ; ...
1295 SAFE_2BYTE_COPY rel_pressure,avg_rel_pressure ; prime result with current rel.pressure/depth
1296 return
1297
1298
1216 calc_average_depth: 1299 calc_average_depth:
1217 btfsc reset_average_depth ; Reset the Average depth? 1300 ; 1. compute rel_pressure x 2, because this routine is called every 2nd second only
1218 rcall reset_average1 ; Reset the resettable average depth 1301 SAFE_2BYTE_COPY rel_pressure,xB ; copy current rel pressure to xB
1219
1220 ; 1. Add new 2xdepth to the Sum of depths registers
1221 SAFE_2BYTE_COPY rel_pressure,xB ; Buffer...
1222 bcf STATUS,C 1302 bcf STATUS,C
1223 rlcf xB+0,F 1303 rlcf xB+0,F ; multiply rel pressure x 2 (via shift left)
1224 rlcf xB+1,F ; x2 1304 rlcf xB+1,F ; ...
1225 1305
1226 movf xB+0,w 1306 ; 2a add (rel_pressure x 2) to the resettable depth accumulator
1307 movf xB+0,W
1227 addwf average_depth_hold+0,F 1308 addwf average_depth_hold+0,F
1228 movf xB+1,w 1309 movf xB+1,W
1229 addwfc average_depth_hold+1,F 1310 addwfc average_depth_hold+1,F
1230 movlw d'0' 1311 movlw .0
1231 addwfc average_depth_hold+2,F 1312 addwfc average_depth_hold+2,F
1232 addwfc average_depth_hold+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar 1313 addwfc average_depth_hold+3,F ; will work up to 9999 mbar * 60 * 60 * 24 = 863913600 mbar (24h @ 90 m depth)
1233 1314
1234 ; Do the same for the _total registers (Non-Resettable) 1315 ; 2b add (rel_pressure x 2) to the total depth accumulator
1235 movf xB+0,w 1316 movf xB+0,W
1236 addwf average_depth_hold_total+0,F 1317 addwf average_depth_hold_total+0,F
1237 movf xB+1,w 1318 movf xB+1,W
1238 addwfc average_depth_hold_total+1,F 1319 addwfc average_depth_hold_total+1,F
1239 movlw d'0' 1320 movlw .0
1240 addwfc average_depth_hold_total+2,F 1321 addwfc average_depth_hold_total+2,F
1241 addwfc average_depth_hold_total+3,F; Will work up to 9999mbar*60*60*24=863913600mbar 1322 addwfc average_depth_hold_total+3,F ; will work up to 9999 mbar * 60 * 60 * 24 = 863913600 mbar (24h @ 90 m depth)
1242 1323
1243 ; 2. Compute Average Depth on base of average_divesecs:2 1324 ; 3a compute avg_rel_pressure on base of average_divesecs:2
1244 movff average_divesecs+0,xB+0
1245 movff average_divesecs+1,xB+1 ; Copy
1246 movff average_depth_hold+0,xC+0 1325 movff average_depth_hold+0,xC+0
1247 movff average_depth_hold+1,xC+1 1326 movff average_depth_hold+1,xC+1
1248 movff average_depth_hold+2,xC+2 1327 movff average_depth_hold+2,xC+2
1249 movff average_depth_hold+3,xC+3 1328 movff average_depth_hold+3,xC+3 ; copy accumulated depth
1250 1329 movff average_divesecs+0,xB+0
1251 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder 1330 movff average_divesecs+1,xB+1 ; copy accumulated time
1331 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
1252 movff xC+0,avg_rel_pressure+0 1332 movff xC+0,avg_rel_pressure+0
1253 movff xC+1,avg_rel_pressure+1 1333 movff xC+1,avg_rel_pressure+1 ; store result
1254 1334
1255 btfss divemode2 ; displayed divetime is running? 1335 btfss divemode2 ; displayed divetime is running?
1256 return ; No (e.g. too shallow) 1336 return ; NO (e.g. too shallow)
1257 1337
1258 ; 3. Compute Total Average Depth on base of total_divetime_seconds:2 1338 ; 3b compute avg_rel_pressure_total on base of average_divesecs_total:2
1259 movff total_divetime_seconds+0,xB+0
1260 movff total_divetime_seconds+1,xB+1 ; Copy
1261 movff average_depth_hold_total+0,xC+0 1339 movff average_depth_hold_total+0,xC+0
1262 movff average_depth_hold_total+1,xC+1 1340 movff average_depth_hold_total+1,xC+1
1263 movff average_depth_hold_total+2,xC+2 1341 movff average_depth_hold_total+2,xC+2
1264 movff average_depth_hold_total+3,xC+3 1342 movff average_depth_hold_total+3,xC+3 ; copy accumulated depth
1265 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder 1343 movff average_divesecs_total+0,xB+0
1344 movff average_divesecs_total+1,xB+1 ; copy accumulated time
1345 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
1266 movff xC+0,avg_rel_pressure_total+0 1346 movff xC+0,avg_rel_pressure_total+0
1267 movff xC+1,avg_rel_pressure_total+1 1347 movff xC+1,avg_rel_pressure_total+1 ; store result
1268 return 1348
1269 1349 btfsc reset_average_depth ; reset the resettable average depth?
1270 reset_average1: 1350 rcall reset_average ; YES - reset the resettable average depth
1271 clrf average_depth_hold+0 1351
1272 clrf average_depth_hold+1 1352 TSTOSS opt_2ndDepthDisp ; drawing avg depth instead of max depth?
1273 clrf average_depth_hold+2 1353 return ; NO - done
1274 clrf average_depth_hold+3 ; Clear average depth register 1354 bsf FLAG_TFT_max_depth ; YES - flag to update display
1275 movlw d'2' 1355 return
1276 movwf average_divesecs+0 1356
1277 clrf average_divesecs+1 1357
1278 bcf reset_average_depth ; Clear flag 1358 test_switches_divemode: ; checks switches in divemode
1279 return 1359 btfsc divemode_menu ; divemode menu shown?
1280 1360 bra test_switches_divemode_menu ; YES - use menu processor
1281 test_switches_divemode: ; checks switches in divemode 1361 btfsc switch_left ; NO - left button pressed?
1282 btfsc divemode_menu ; Divemode menu shown? 1362 goto menuview_toggle ; YES - menu or simulator tasks; and return...
1283 bra test_switches_divemode_menu ; Yes, use menu processor 1363 btfss switch_right ; NO - right button pressed?
1284 btfsc switch_left 1364 return ; NO - done
1285 ;bra test_switches_divemode2 ; Enter button pressed, check if we need to do something 1365 tstfsz menupos2 ; YES - any option shown?
1286 goto menuview_toggle ; Menu or Simulator tasks; and return... 1366 bra test_switches_divemode1 ; YES - do option tasks
1287 btfss switch_right 1367 bsf toggle_customview ; NO - toggle custom view
1288 return ; No button press 1368 return ; - done
1289 tstfsz menupos2 ; any option shown?
1290 bra test_switches_divemode1 ; Yes, do option tasks
1291 bsf toggle_customview ; No, toggle custom view
1292 return
1293 1369
1294 test_switches_divemode_menu: 1370 test_switches_divemode_menu:
1295 btfsc switch_left 1371 btfsc switch_left
1296 bra test_switches_divemode_menu2; Move cursor 1372 bra test_switches_divemode_menu2 ; move cursor
1297 btfsc switch_right 1373 btfsc switch_right ; left button pressed?
1298 bra test_switches_divemode_menu3; Enter submenu or do something 1374 bra test_switches_divemode_menu3 ; YES - enter submenu or do something
1299 return ; No button press 1375 return ; NO - done
1300 1376
1301 test_switches_divemode_menu1: 1377 test_switches_divemode_menu1:
1302 clrf menupos1 1378 clrf menupos1
1303 test_switches_divemode_menu2: 1379 test_switches_divemode_menu2:
1304 incf menupos1,F 1380 incf menupos1,F
1305 incf menupos4,W ; menupos4+1 -> WREG 1381 incf menupos4,W ; menupos4 + 1 -> WREG
1306 cpfslt menupos1 ; > menupos4 (Set in menu_processor.asm)? 1382 cpfslt menupos1 ; > menupos4 (set in menu_processor.asm)?
1307 bra test_switches_divemode_menu1; > Yes, set to 1 1383 bra test_switches_divemode_menu1 ; YES - set to 1
1308 call TFT_divemode_menu_cursor ; Update the cursor 1384 call TFT_divemode_menu_cursor ; update the cursor
1309 bcf switch_left 1385 bcf switch_left
1310 movlw divemode_menu_timeout ; Reload timeout 1386 movlw divemode_menu_timeout ; reload timeout
1311 movwf timeout_counter2 ; timeout for divemode menu 1387 movwf timeout_counter2 ; timeout for divemode menu
1312 return 1388 return
1313 1389
1314 test_switches_divemode_menu3: ; Enter submenu or do something 1390 test_switches_divemode_menu3: ; enter submenu or do something
1315 bcf switch_right 1391 bcf switch_right
1316 ; decf menupos1,F ; menu_processor needs 0-5... 1392 ; decf menupos1,F ; menu_processor needs 0-5...
1317 goto do_line_menu ; Warning! Trashes STKPTR and returns to diveloop_loop4: 1393 goto do_line_menu ; Warning! trashes STKPTR and returns to diveloop_loop4:
1318 1394
1319 test_switches_divemode1: 1395 test_switches_divemode1:
1320 bcf switch_right 1396 bcf switch_right
1321 movlw divemode_menuview_timeout 1397 movlw divemode_menuview_timeout
1322 movwf timeout_counter2 ; Reload timeout 1398 movwf timeout_counter2 ; reload timeout
1323 movff menupos2,WREG ; menupos2 holds number of customview/divemode menu function 1399 movff menupos2,WREG ; menupos2 holds number of customview/divemode menu function
1324 dcfsnz WREG,F 1400 dcfsnz WREG,F
1325 bra divemode_option_gaschange ; Switch to the indicated "better gas" 1401 bra divemode_option_gaschange ; switch to the the "better gas" / "better diluent"
1326 dcfsnz WREG,F 1402 dcfsnz WREG,F
1327 bra divemode_option0 ; Start/Setup Divemode menu 1403 bra divemode_option0 ; start/setup Divemode menu
1328 dcfsnz WREG,F 1404 dcfsnz WREG,F
1329 bra divemode_option1 ; Quit Simulation? 1405 bra divemode_option1 ; quit simulation?
1330 dcfsnz WREG,F 1406 dcfsnz WREG,F
1331 bra divemode_option2 ; Descent 1m 1407 bra divemode_option2 ; descent 1m
1332 dcfsnz WREG,F 1408 dcfsnz WREG,F
1333 bra divemode_option3 ; Ascend 1m 1409 bra divemode_option3 ; ascend 1m
1334 dcfsnz WREG,F 1410 dcfsnz WREG,F
1335 bra divemode_option4 ; Quit Apnoe mode 1411 bra divemode_option4 ; quit Apnoe mode
1336 dcfsnz WREG,F 1412 dcfsnz WREG,F
1337 bra divemode_option5 ; Reset Stopwatch (In Gauge mode) 1413 bra divemode_option5 ; reset stopwatch (gauge mode only)
1338 dcfsnz WREG,F 1414 dcfsnz WREG,F
1339 bra divemode_option6 ; +5mins simulation 1415 bra divemode_option6 ; +5mins simulation
1340 dcfsnz WREG,F 1416 dcfsnz WREG,F
1341 bra divemode_option7 ; Store heading 1417 bra divemode_option7 ; store heading
1342 dcfsnz WREG,F 1418 dcfsnz WREG,F
1343 bra divemode_option8 ; Switch to alt. layout 1419 bra divemode_option8 ; switch to alternative layout
1344 return 1420 return
1345 1421
1346 gas_switched_common: 1422 gas_switched_common:
1347 bcf divemode_gaschange ; Clear flag 1423 bcf divemode_gaschange ; clear flag
1348 btfss FLAG_back_to_loop ; check if it is a switchback from OC bailout to loop 1424 btfss FLAG_back_to_loop ; check if it is a switchback from OC bailout to loop
1349 bra gas_switched_common0 ; NO - continue with checking if selected gas is valid 1425 bra gas_switched_common0 ; NO - continue with checking if selected gas is valid
1350 bcf FLAG_back_to_loop ; YES - clear flag 1426 bcf FLAG_back_to_loop ; YES - clear flag
1351 movff active_diluent,menupos1 ; reload last diluent 1427 movff active_dil,menupos1 ; reload last diluent
1352 bra gas_switched_common1 ; continue with common part 1428 bra gas_switched_common1 ; continue with common part
1353 gas_switched_common0: 1429 gas_switched_common0:
1354 tstfsz menupos1 ; menupos1=0? 1430 tstfsz menupos1 ; menupos1 = 0 ?
1355 bra gas_switched_common1 ; NO - valid gas 1431 bra gas_switched_common1 ; NO - valid gas
1356 return ; YES - something went wrong, invalid gas, abort 1432 return ; YES - something went wrong, invalid gas, abort
1357 gas_switched_common1: 1433 gas_switched_common1:
1358 movf menupos1,W ; get selected gas into WREG (1-6) 1434 movf menupos1,W ; get selected gas into WREG (1-6)
1359 1435 btfsc FLAG_oc_mode ; in OC mode?
1360 btfsc FLAG_ccr_mode ; in CCR mode? 1436 bra gas_switched_common_OC ; YES
1361 bra gas_switched_common2 ; YES - configure diluent or bailout 1437 btfsc FLAG_bailout_mode ; in bailout?
1362 btfsc FLAG_pscr_mode ; in pSCR mode? 1438 bra gas_switched_common_OC ; YES
1363 bra gas_switched_common2 ; YES - configure diluent or bailout 1439 gas_switched_common_loop: ; NO to both - must be loop mode then
1364 1440 rcall setup_dil_registers ; with WREG = diluent 1-6
1365 ; OC 1441 rcall deco_setup_cc_diluents ; with WREG = diluent 1-6
1366 rcall setup_gas_registers ; With WREG = Gas 1-6
1367 rcall deco_setup_oc_gases ; With WREG = Gas 1-6
1368 bra gas_switched_common3 1442 bra gas_switched_common3
1369 1443 gas_switched_common_OC:
1370 ; loop or bailout 1444 rcall setup_gas_registers ; with WREG = Gas 1-6
1371 gas_switched_common2: 1445 rcall deco_setup_oc_gases ; with WREG = Gas 1-6
1372 rcall setup_dil_registers ; With WREG = diluent 1-6, in case of is_bailout reverts to OC gases
1373 rcall deco_setup_cc_diluents ; With WREG = diluent 1-6, in case of is_bailout reverts to OC gases
1374
1375 gas_switched_common3: 1446 gas_switched_common3:
1376 bsf FLAG_TFT_active_gas_divemode ; Redraw gas/setpoint/diluent 1447 bsf FLAG_TFT_active_gas_divemode ; redraw gas/setpoint/diluent
1377 call restart_deco_engine_wo_ceiling ; abort any running deco calculations and restart the deco engine 1448 call restart_deco_engine_wo_ceiling ; abort any running deco calculations and restart the deco engine
1378 1449 ; set flags for profile recording
1379 ; Set flags for profile recording
1380 bsf event_occured ; set event flag 1450 bsf event_occured ; set event flag
1381 btfsc is_bailout ; Choose OC Bailouts (OC Gases) 1451 btfsc FLAG_bailout_mode ; choose OC Bailouts (OC Gases)
1382 bsf bailoutgas_event ; Bailout gas change 1452 bsf bailoutgas_event ; bailout gas change
1383 btfss is_bailout ; Choose OC Bailouts (OC Gases) 1453 btfss FLAG_bailout_mode ; choose OC Bailouts (OC Gases)
1384 bsf stored_gas_changed ; OC gas change 1454 bsf stored_gas_changed ; OC gas change
1385 return 1455 return
1386 1456
1387 1457
1388 ; Code to pass all parameters to the C code 1458 ; Code to pass all parameters to the C code
1389 1459
1390 global get_first_gas_to_WREG 1460 global get_first_gas_to_WREG
1391 get_first_gas_to_WREG: ; Gets first gas (1-5) into WREG 1461 get_first_gas_to_WREG: ; gets first gas (1-5) into WREG
1392 lfsr FSR1,opt_gas_type ; Point to gas types 1462 lfsr FSR1,opt_gas_type ; point to gas types
1393 clrf lo ; start with Gas0 1463 clrf lo ; start with gas 0
1394 get_first_gas_to_WREG2: 1464 get_first_gas_to_WREG2:
1395 movf lo,W 1465 movf lo,W
1396 movf PLUSW1,W ; Get Type of Gas #lo 1466 movf PLUSW1,W ; get type of gas #lo
1397 sublw .1 ; it is = 1 (First Gas) 1467 sublw .1 ; it is = 1 (First Gas)
1398 bz get_first_gas_to_WREG3 ; Found the first gas! 1468 bz get_first_gas_to_WREG3 ; found the first gas!
1399 incf lo,F ; ++ 1469 incf lo,F ; ++
1400 movlw NUM_GAS+1 1470 movlw NUM_GAS+1
1401 cpfseq lo ; All done? 1471 cpfseq lo ; all done?
1402 bra get_first_gas_to_WREG2 ; Not yet 1472 bra get_first_gas_to_WREG2 ; NO - not yet
1403 ; No first gas found, use #1 1473 ; no first gas found, use #1
1404 movlw .0 1474 movlw .0
1405 movff WREG,opt_gas_type+0 ; Set Gas1 to First 1475 movff WREG,opt_gas_type+0 ; set gas 1 to First
1406 incf WREG,W ; 0 -> 1 1476 incf WREG,W ; 0 -> 1
1407 return 1477 return
1408 get_first_gas_to_WREG3: 1478 get_first_gas_to_WREG3:
1409 movf lo,W ; Put into Wreg 1479 movf lo,W ; put into WREG
1410 incf WREG,W ; 0-4 -> 1-5 1480 incf WREG,W ; 0-4 -> 1-5
1411 return ; Done 1481 return ; done
1412 1482
1413 global get_first_dil_to_WREG 1483 global get_first_dil_to_WREG
1414 get_first_dil_to_WREG: ; Gets first dil (1-5) into WREG 1484 get_first_dil_to_WREG: ; gets first dil (1-5) into WREG
1415 lfsr FSR1,opt_dil_type ; Point to dil types 1485 lfsr FSR1,opt_dil_type ; point to dil types
1416 clrf lo ; start with Gas0 1486 clrf lo ; start with dil 0
1417 get_first_dil_to_WREG2: 1487 get_first_dil_to_WREG2:
1418 movf lo,W 1488 movf lo,W
1419 movf PLUSW1,W ; Get Type of Dil #lo 1489 movf PLUSW1,W ; get type of Dil #lo
1420 sublw .1 ; it is = 1 (First Dil) 1490 sublw .1 ; it is = 1 (First Dil)
1421 bz get_first_dil_to_WREG3 ; Found the first dil! 1491 bz get_first_dil_to_WREG3 ; found the first dil!
1422 incf lo,F ; ++ 1492 incf lo,F ; ++
1423 movlw NUM_GAS+1 1493 movlw NUM_GAS+1
1424 cpfseq lo ; All done? 1494 cpfseq lo ; all done?
1425 bra get_first_dil_to_WREG2 ; Not yet 1495 bra get_first_dil_to_WREG2 ; NO - not yet
1426 ; No first dil found, use #1 1496 ; no first dil found, use #1
1427 movlw .0 1497 movlw .0
1428 movff WREG,opt_dil_type+0 ; Set Dil1 to First 1498 movff WREG,opt_dil_type+0 ; set dil 1 to First
1429 incf WREG,W ; 0 -> 1 1499 incf WREG,W ; 0 -> 1
1430 return 1500 return
1431 get_first_dil_to_WREG3: 1501 get_first_dil_to_WREG3:
1432 movf lo,W ; Put into Wreg 1502 movf lo,W ; Put into WREG
1433 incf WREG,W ; 0-4 -> 1-5 1503 incf WREG,W ; 0-4 -> 1-5
1434 return ; Done 1504 return ; done
1435 1505
1436 global deco_setup_oc_gases 1506
1437 deco_setup_oc_gases: ; with currently breathed gas in WREG (1-5 or 6) 1507 deco_setup_oc_gases: ; with currently breathed gas in WREG (1-5 or 6)
1438 movff WREG,char_I_current_gas ; gas to start with when doing the deco calculations
1439
1440 banksel opt_gas_type ; opt_gas_type[] and opt_OC_bail_gas_change[] are together in bank common2
1441
1442 movff opt_gas_He_ratio+0,char_I_deco_He_ratio+0
1443 movff opt_gas_O2_ratio+0,char_I_deco_O2_ratio+0
1444
1445 movlw .3 ; 3=Deco
1446 cpfseq opt_gas_type+0 ; Gas is deco type?
1447 clrf opt_OC_bail_gas_change+0 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1448
1449 movff opt_gas_He_ratio+1,char_I_deco_He_ratio+1
1450 movff opt_gas_O2_ratio+1,char_I_deco_O2_ratio+1
1451 movlw .3 ; 3=Deco
1452 cpfseq opt_gas_type+1 ; Gas is deco type?
1453 clrf opt_OC_bail_gas_change+1 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1454
1455 movff opt_gas_He_ratio+2,char_I_deco_He_ratio+2
1456 movff opt_gas_O2_ratio+2,char_I_deco_O2_ratio+2
1457 movlw .3 ; 3=Deco
1458 cpfseq opt_gas_type+2 ; Gas is deco type?
1459 clrf opt_OC_bail_gas_change+2 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1460
1461 movff opt_gas_He_ratio+3,char_I_deco_He_ratio+3
1462 movff opt_gas_O2_ratio+3,char_I_deco_O2_ratio+3
1463 movlw .3 ; 3=Deco
1464 cpfseq opt_gas_type+3 ; Gas is deco type?
1465 clrf opt_OC_bail_gas_change+3 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1466
1467 movff opt_gas_He_ratio+4,char_I_deco_He_ratio+4
1468 movff opt_gas_O2_ratio+4,char_I_deco_O2_ratio+4
1469 movlw .3 ; 3=Deco
1470 cpfseq opt_gas_type+4 ; Gas is deco type?
1471 clrf opt_OC_bail_gas_change+4 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1472
1473 banksel common
1474
1475 ; Setup char_I_deco_gas_change array
1476 movff opt_OC_bail_gas_change+0, char_I_deco_gas_change+0
1477 movff opt_OC_bail_gas_change+1, char_I_deco_gas_change+1
1478 movff opt_OC_bail_gas_change+2, char_I_deco_gas_change+2
1479 movff opt_OC_bail_gas_change+3, char_I_deco_gas_change+3
1480 movff opt_OC_bail_gas_change+4, char_I_deco_gas_change+4
1481
1482 ; switch to oc mode
1483 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common 1508 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common
1509 deco_setup_oc_gases_pre: ; entry point with lo preloaded
1510 movff WREG,char_I_current_gas ; set gas to start with when doing the deco calculations
1511 ;
1512 ; Memory Map:
1513 ; ---------------------------------------------------------------------------------
1514 ; opt_gas_O2_ratio res NUM_GAS | char_I_deco_O2_ratio res NUM_GAS
1515 ; opt_dil_O2_ratio res NUM_GAS |
1516 ; opt_gas_He_ratio res NUM_GAS | char_I_deco_He_ratio res NUM_GAS
1517 ; opt_dil_He_ratio res NUM_GAS |
1518 ; opt_gas_type res NUM_GAS | char_I_deco_gas_type res NUM_GAS
1519 ; opt_dil_type res NUM_GAS |
1520 ; opt_gas_change res NUM_GAS | char_I_deco_gas_change res NUM_GAS
1521 ; opt_dil_change res NUM_GAS |
1522 ;
1523 lfsr FSR2,char_I_deco_O2_ratio ; Load FSR2 with base address of char_I_deco_O2_ratio.
1524 ; FSR2 will step through all char_I_deco_... vars.
1525 lfsr FSR1,opt_gas_O2_ratio ; load FSR1 with base address of opt_gas_O2_ratio
1526 rcall deco_setup_copy ; copy all OC O2 ratios
1527 lfsr FSR1,opt_gas_He_ratio ; load FSR1 with base address of opt_gas_He_ratio
1528 rcall deco_setup_copy ; copy all OC He ratios
1529 lfsr FSR1,opt_gas_type ; load FSR1 with base address of opt_gas_type
1530 rcall deco_setup_copy ; copy all gas types
1531 lfsr FSR1,opt_gas_change ; load FSR1 with base address of opt_gas_change
1532 rcall deco_setup_copy ; copy all gas change depths
1533 ; switch to oc mode
1484 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind) 1534 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind)
1485 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag 1535 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag
1486 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status 1536 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status
1487 1537 return
1488 return 1538
1489 1539
1490 1540 deco_setup_cc_diluents: ; with currently breathed diluent in WREG (1-5 or 6)
1491 global deco_setup_cc_diluents
1492 deco_setup_cc_diluents: ; with currently breathed gas in WREG (1-5 or 6)
1493 btfsc is_bailout ; check if in bailout condition
1494 bra deco_setup_oc_gases ; revert to setting up OC gases in bailout condition
1495
1496 movff WREG,char_I_current_gas ; gas to start with when doing the deco calculations
1497
1498 movff opt_dil_He_ratio+0,char_I_deco_He_ratio+0
1499 movff opt_dil_O2_ratio+0,char_I_deco_O2_ratio+0
1500 movff opt_dil_type+0,WREG ; 0=Disabled, 1=First, 2=Normal
1501 tstfsz WREG ; Disabled?
1502 bra $+4 ; No
1503 movff WREG,char_I_dil_change+0 ; Yes, clear char_I_deco_gas_change (Bank safe)
1504
1505 movff opt_dil_He_ratio+1,char_I_deco_He_ratio+1
1506 movff opt_dil_O2_ratio+1,char_I_deco_O2_ratio+1
1507 movff opt_dil_type+1,WREG ; 0=Disabled, 1=First, 2=Normal
1508 tstfsz WREG ; Disabled?
1509 bra $+4 ; No
1510 movff WREG,char_I_dil_change+1 ; Yes, clear char_I_dil_change
1511
1512 movff opt_dil_He_ratio+2,char_I_deco_He_ratio+2
1513 movff opt_dil_O2_ratio+2,char_I_deco_O2_ratio+2
1514 movff opt_dil_type+2,WREG ; 0=Disabled, 1=First, 2=Normal
1515 tstfsz WREG ; Disabled?
1516 bra $+4 ; No
1517 movff WREG,char_I_dil_change+2 ; Yes, clear char_I_dil_change
1518
1519 movff opt_dil_He_ratio+3,char_I_deco_He_ratio+3
1520 movff opt_dil_O2_ratio+3,char_I_deco_O2_ratio+3
1521 movff opt_dil_type+3,WREG ; 0=Disabled, 1=First, 2=Normal
1522 tstfsz WREG ; Disabled?
1523 bra $+4 ; No
1524 movff WREG,char_I_dil_change+3 ; Yes, clear char_I_dil_change
1525
1526 movff opt_dil_He_ratio+4,char_I_deco_He_ratio+4
1527 movff opt_dil_O2_ratio+4,char_I_deco_O2_ratio+4
1528 movff opt_dil_type+4,WREG ; 0=Disabled, 1=First, 2=Normal
1529 tstfsz WREG ; Disabled?
1530 bra $+4 ; No
1531 movff WREG,char_I_dil_change+4 ; Yes, clear char_I_dil_change
1532
1533 ; Setup char_I_deco_gas_change array
1534 movff char_I_dil_change+0, char_I_deco_gas_change+0
1535 movff char_I_dil_change+1, char_I_deco_gas_change+1
1536 movff char_I_dil_change+2, char_I_deco_gas_change+2
1537 movff char_I_dil_change+3, char_I_deco_gas_change+3
1538 movff char_I_dil_change+4, char_I_deco_gas_change+4
1539
1540 ; switch to CCR / pSCR mode
1541 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common 1541 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common
1542 deco_setup_cc_diluents_pre: ; entry point with lo preloaded
1543 btfsc FLAG_bailout_mode ; check if in bailout condition | --------------- FOR SAFETY ONLY --------------
1544 bra deco_setup_oc_gases_pre ; YES - revert to setting up OC gases | This branch should never happen to be taken...
1545 movff WREG,char_I_current_gas ; NO - set diluent to start with when doing the deco calculations
1546 ;
1547 ; Memory Map:
1548 ; ---------------------------------------------------------------------------------
1549 ; opt_gas_O2_ratio res NUM_GAS |
1550 ; opt_dil_O2_ratio res NUM_GAS | char_I_deco_O2_ratio res NUM_GAS
1551 ; opt_gas_He_ratio res NUM_GAS |
1552 ; opt_dil_He_ratio res NUM_GAS | char_I_deco_He_ratio res NUM_GAS
1553 ; opt_gas_type res NUM_GAS |
1554 ; opt_dil_type res NUM_GAS | char_I_deco_gas_type res NUM_GAS
1555 ; opt_gas_change res NUM_GAS |
1556 ; opt_dil_change res NUM_GAS | char_I_deco_gas_change res NUM_GAS
1557 ;
1558 lfsr FSR2,char_I_deco_O2_ratio ; Load FSR2 with base address of char_I_deco_O2_ratio.
1559 ; FSR2 will step through all char_I_deco_... vars.
1560 lfsr FSR1,opt_dil_O2_ratio ; load FSR1 with base address of opt_dil_O2_ratio
1561 rcall deco_setup_copy ; copy all dil O2 ratios
1562 lfsr FSR1,opt_dil_He_ratio ; load FSR1 with base address of opt_dil_He_ratio
1563 rcall deco_setup_copy ; copy all dil He ratios
1564 lfsr FSR1,opt_dil_type ; load FSR1 with base address of opt_dil_type
1565 rcall deco_setup_copy ; copy all dil types
1566 lfsr FSR1,opt_dil_change ; load FSR1 with base address of opt_dil_change
1567 rcall deco_setup_copy ; copy all dil change depths
1568 ; switch to CCR / pSCR mode
1542 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode 1569 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode
1543 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default 1570 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default
1544 btfsc FLAG_pscr_mode ; check if we are in pSCR mode 1571 btfsc FLAG_pscr_mode ; check if we are in pSCR mode
1545 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode 1572 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode
1546 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status 1573 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status
1547 1574 return
1548 return 1575
1576 deco_setup_copy:
1577 movlw NUM_GAS ; load loop counter with number of gases (5)
1578 deco_setup_copy_loop:
1579 movff POSTINC1,POSTINC2 ; copy from (FSR1) to (FSR2)
1580 decfsz WREG ; decrement loop counter and check if it became 0
1581 bra deco_setup_copy_loop ; NO - not yet, loop
1582 return ; YES - done
1583
1549 1584
1550 global setup_gas_registers 1585 global setup_gas_registers
1551 setup_gas_registers: ; with currently breathed gas in WREG (1-5 or 6) 1586 setup_gas_registers: ; with currently breathed gas in WREG (1-5 or 6)
1552 movwf active_gas ; set as current gas 1587 movwf active_gas ; set as current gas
1553 movlw .6 1588 movlw .6
1554 cpfseq active_gas ; gas = gas6 ? 1589 cpfseq active_gas ; gas = gas6 ?
1555 bra setup_gas_registers_15 ; NO - load gas 1-5 1590 bra setup_gas_registers_15 ; NO - load gas 1-5
1556 movff gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine 1591 movff gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine
1557 movff gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine 1592 movff gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine
1593 movlw .3 ; declare gas6 as a deco gas
1594 movff WREG,char_I_current_gas_type; copy gas type to deco engine
1595 movff curr_depth,char_I_gas6_depth; set current depth as change depth
1558 bra setup_gas_registers_com ; continue with common part 1596 bra setup_gas_registers_com ; continue with common part
1559 setup_gas_registers_15: 1597 setup_gas_registers_15:
1560 decf active_gas,W ; 1-5 -> 0-4 1598 decf active_gas,W ; 1-5 -> 0-4
1561 lfsr FSR1,opt_gas_O2_ratio+0 1599 lfsr FSR1,opt_gas_O2_ratio
1562 movff PLUSW1,char_I_O2_ratio ; copy gas 1-5 O2 ratio to deco engine 1600 movff PLUSW1,char_I_O2_ratio ; copy gas 1-5 O2 ratio to deco engine
1563 lfsr FSR1,opt_gas_He_ratio+0 1601 lfsr FSR1,opt_gas_He_ratio
1564 movff PLUSW1,char_I_He_ratio ; copy gas 1-5 He ratio to deco engine 1602 movff PLUSW1,char_I_He_ratio ; copy gas 1-5 He ratio to deco engine
1565 setup_gas_registers_com: 1603 lfsr FSR1,opt_gas_type ;
1566 ;lfsr FSR1,opt_gas_type ; commented out - currently not used anywhere 1604 movff PLUSW1,char_I_current_gas_type ; copy gas 1-5 type (0=Disabled, 1=First, 2=Travel, 3=Deco)
1567 ;movff PLUSW1,active_gas_type ; 0=Disabled, 1=First, 2=Travel, 3=Deco 1605 setup_gas_registers_com:
1568 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common 1606 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common
1569 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind) 1607 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind)
1570 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag 1608 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag
1571 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status 1609 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status
1572 movf active_gas,W ; reload WREG with diluent 1-5 or 6 (important!) 1610 movf active_gas,W ; reload WREG with gas 1-5 or 6 (important!)
1573 return 1611 return
1574 1612
1575 global setup_dil_registers 1613 global setup_dil_registers
1576 setup_dil_registers: ; with currently breathed gas in WREG (1-5 or 6) 1614 setup_dil_registers: ; with currently breathed gas in WREG (1-5 or 6)
1577 btfsc is_bailout ; check if in bailout condition 1615 btfsc FLAG_bailout_mode ; check if in bailout condition | --------------- FOR SAFETY ONLY --------------
1578 bra setup_gas_registers ; revert to setting up OC gases in bailout condition 1616 bra setup_gas_registers ; revert to setting up OC gases in bailout condition | This branch should never happen to be taken...
1579 movwf active_gas ; set as current gas 1617 movwf active_dil ; set as current diluent
1580 movff WREG,active_diluent ; remember for when switching back from bailout to loop
1581 movlw .6 1618 movlw .6
1582 cpfseq active_gas ; diluent = gas6 ? 1619 cpfseq active_dil ; diluent = gas6 ?
1583 bra setup_dil_registers_15 ; NO - load diluent 1-5 1620 bra setup_dil_registers_15 ; NO - load diluent 1-5
1584 movff gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine 1621 movff gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine
1585 movff gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine 1622 movff gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine
1623 movlw .2 ; declare gas6 as a normal diluent
1624 movff WREG,char_I_current_gas_type; copy gas type to deco engine
1625 movff curr_depth,char_I_gas6_depth; set current depth as change depth
1586 bra setup_dil_registers_com ; continue with common part 1626 bra setup_dil_registers_com ; continue with common part
1587 setup_dil_registers_15: 1627 setup_dil_registers_15:
1588 decf active_gas,W ; 1-5 -> 0-4 1628 decf active_dil,W ; 1-5 -> 0-4
1589 lfsr FSR1,opt_dil_O2_ratio+0 1629 lfsr FSR1,opt_dil_O2_ratio
1590 movff PLUSW1,char_I_O2_ratio ; copy diluent 1-5 O2 ratio to deco engine 1630 movff PLUSW1,char_I_O2_ratio ; copy diluent 1-5 O2 ratio to deco engine
1591 lfsr FSR1,opt_dil_He_ratio+0 1631 lfsr FSR1,opt_dil_He_ratio
1592 movff PLUSW1,char_I_He_ratio ; copy diluent 1-5 He ratio to deco engine 1632 movff PLUSW1,char_I_He_ratio ; copy diluent 1-5 He ratio to deco engine
1633 lfsr FSR1,opt_dil_type ;
1634 movff PLUSW1,char_I_current_gas_type ; copy dil type (0=Disabled, 1=First, 2=Normal)
1593 setup_dil_registers_com: 1635 setup_dil_registers_com:
1594 ;lfsr FSR1,opt_dil_type ; commented out - currently not used anywhere
1595 ;movff PLUSW1,active_gas_type ; 0=Disabled, 1=First, 2=Normal (there is no type 3 for diluents)
1596 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common 1636 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common
1597 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode 1637 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode
1598 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default 1638 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default
1599 btfsc FLAG_pscr_mode ; check if we are in pSCR mode 1639 btfsc FLAG_pscr_mode ; check if we are in pSCR mode
1600 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode 1640 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode
1601 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status 1641 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status
1602 movf active_gas,W ; reload WREG with diluent 1-5 or 6 (important!) 1642 movf active_dil,W ; reload WREG with diluent 1-5 or 6 (important!)
1603 return 1643 return
1604 1644
1605 divemode_option_gaschange: ; Switch to the better gas 1645
1606 movff better_gas_number,menupos1 ; 1-5 1646 divemode_option_gaschange: ; switch to the "better gas" / "better diluent"
1607 bsf divemode_gaschange ; Change the gas in the dive mode loop... 1647 btfsc FLAG_oc_mode ; in OC mode?
1608 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) 1648 bra divemode_option_gaschange_oc; YES
1609 bcf better_gas_available ; Clear flag immediately 1649 btfsc FLAG_bailout_mode ; in bailout?
1610 return 1650 bra divemode_option_gaschange_oc; YES
1611 1651 divemode_option_gaschange_loop: ; in CCR/pSCR mode and not in bailout
1612 divemode_option0: ; Start/Setup Divemode menu 1652 movff best_dil_number,menupos1 ; NO - select best diluent
1613 call TFT_clear_divemode_menu ; Clear menu area 1653 bcf better_dil_available ; - clear flag immediately
1654 bra divemode_option_gaschange3 ; - continue with common part
1655 divemode_option_gaschange_oc: ; in OC or bailout
1656 movff best_gas_number,menupos1 ; select best gas
1657 bcf better_gas_available ; clear flag immediately
1658 divemode_option_gaschange3 ; common part
1659 bsf divemode_gaschange ; command a gas/diluent change
1660 call menuview_toggle_reset ; terminate the options menu
1661 return
1662
1663 divemode_option0: ; start/setup dive mode menu
1664 call TFT_clear_divemode_menu ; clear menu area
1614 bcf menuview 1665 bcf menuview
1615 call do_main_divemenu 1666 call do_main_divemenu
1616 1667
1617 global divemode_option0_return 1668 global divemode_option0_return
1618 divemode_option0_return: 1669 divemode_option0_return:
1619 ; movlw .1 1670 ; movlw .1
1620 ; movwf menupos1 ; Set to first option in divemode menu 1671 ; movwf menupos1 ; set to first option in dive mode menu
1621 call TFT_divemode_menu_cursor ; Show the cursor 1672 call TFT_divemode_menu_cursor ; show the cursor
1622 movlw divemode_menu_timeout 1673 movlw divemode_menu_timeout
1623 movwf timeout_counter2 ; timeout for divemode menu 1674 movwf timeout_counter2 ; timeout for dive mode menu
1624 bsf divemode_menu ; Set flag 1675 bsf divemode_menu ; set flag
1625 clrf menupos2 ; Clear option counter 1676 clrf menupos2 ; clear option counter
1626 goto diveloop_loop4 ; Goto back to diveloop (menu processor trashes STKPTR!) 1677 goto diveloop_loop4 ; go back to dive loop (menu processor trashes STKPTR!)
1627 1678
1628 divemode_option4: 1679 divemode_option4:
1629 movlw d'58' ; two seconds left 1680 movlw d'58' ; two seconds left
1630 movwf timeout_counter1+0 1681 movwf timeout_counter1+0
1631 movlw apnoe_timeout-1 ; apnoe timeout [min] 1682 movlw apnoe_timeout-1 ; apnoe timeout [min]
1632 movwf apnoe_timeout_counter 1683 movwf apnoe_timeout_counter
1633 btfss simulatormode_active ; in simulator mode? 1684 btfss simulatormode_active ; in simulator mode?
1634 return ; No 1685 return ; NO
1635 divemode_option1: ; Quit simulation mode 1686 ;bra divemode_option1 ; YES
1687
1688 divemode_option1: ; quit simulation mode
1636 banksel isr_backup 1689 banksel isr_backup
1637 movlw LOW .1000 1690 movlw LOW .1000
1638 movwf sim_pressure+0 1691 movwf sim_pressure+0
1639 movlw HIGH .1000 1692 movlw HIGH .1000
1640 movwf sim_pressure+1 ; Set to 0m -> End of Dive 1693 movwf sim_pressure+1 ; set to 0m -> end of dive
1641 banksel common 1694 banksel common
1642 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) 1695 call menuview_toggle_reset ; reset to zero (zero = no menu view)
1643 1696
1644 btfss FLAG_apnoe_mode ; In Apnoe mode? 1697 btfss FLAG_apnoe_mode ; in apnoe mode?
1645 return ; No 1698 return ; NO - done
1646 movlw d'58' ; two seconds left 1699 movlw d'58' ; two seconds left
1647 movwf timeout_counter1+0 1700 movwf timeout_counter1+0
1648 movlw apnoe_timeout-1 ; apnoe timeout [min] 1701 movlw apnoe_timeout-1 ; apnoe timeout [min]
1649 movwf apnoe_timeout_counter 1702 movwf apnoe_timeout_counter
1650 return 1703 return
1660 return 1713 return
1661 1714
1662 divemode_option2: ; plus 1m 1715 divemode_option2: ; plus 1m
1663 banksel isr_backup 1716 banksel isr_backup
1664 movlw d'100' 1717 movlw d'100'
1665 addwf sim_pressure+0 1718 addwf sim_pressure+0,F
1666 movlw .0 1719 movlw .0
1667 addwfc sim_pressure+1 1720 addwfc sim_pressure+1,F
1668 rcall divemode_simulator_check_limits 1721 rcall divemode_simulator_check_limits
1669 banksel common 1722 banksel common
1670 return 1723 return
1671 1724
1672 divemode_option5: 1725 divemode_option5:
1673 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) 1726 call menuview_toggle_reset ; reset to zero (zero = no menu view)
1674 bsf reset_average_depth ; Set Flag 1727 bsf reset_average_depth ; set flag
1675 return 1728 return
1676 1729
1677 divemode_option6: 1730 divemode_option6:
1678 bcf divemode2 ; Stop divetime 1731 ; advance tissues and deco by 5 minutes
1732 movlw .5 ; + 5 minutes
1733 movff WREG,char_I_sim_advance_time; copy to mailbox
1734 call restart_deco_engine
1735
1736 ; stop divetime incrementing in ISR
1737 bcf divemode2
1738
1739 ; add 5 minutes to divemins
1679 movlw .5 1740 movlw .5
1680 addwf divemins+0,F 1741 addwf divemins+0,F
1681 movlw .0 1742 movlw .0
1682 addwfc divemins+1,F ; Add 5 mins 1743 addwfc divemins+1,F
1744
1745 ; add 5 minutes (5 * 60 seconds) to total_divetime_seconds
1746 movlw LOW (.5*.60)
1747 addwf total_divetime_seconds+0,F
1748 movlw HIGH (.5*.60)
1749 addwfc total_divetime_seconds+1,F
1750
1751 ; continue dive time incrementing in ISR
1752 bsf divemode2
1753
1754 ; add 5 minutes (5 * 60 seconds) to resettable time accumulator
1683 movlw LOW (.5*.60) 1755 movlw LOW (.5*.60)
1684 addwf average_divesecs+0,F 1756 addwf average_divesecs+0,F
1685 movlw HIGH (.5*.60) 1757 movlw HIGH (.5*.60)
1686 addwfc average_divesecs+1,F ; Add 5*60 seconds 1758 addwfc average_divesecs+1,F
1759
1760 ; add 5 minutes (5 * 60 seconds) to total time accumulator
1687 movlw LOW (.5*.60) 1761 movlw LOW (.5*.60)
1688 addwf total_divetime_seconds+0,F 1762 addwf average_divesecs_total+0,F
1689 movlw HIGH (.5*.60) 1763 movlw HIGH (.5*.60)
1690 addwfc total_divetime_seconds+1,F ; Add 5*60 seconds 1764 addwfc average_divesecs_total+1,F
1691 1765
1692 ; 1. Add 300xdepth to the sum of depths registers 1766
1693 SAFE_2BYTE_COPY rel_pressure, xB ; Buffer... 1767 ; calculate 300 x depth in mbar (300 = 5 min * 60 sec/min)
1768 SAFE_2BYTE_COPY rel_pressure, xB
1694 movlw LOW (.5*.60) 1769 movlw LOW (.5*.60)
1695 movwf xA+0 1770 movwf xA+0
1696 movlw HIGH (.5*.60) 1771 movlw HIGH (.5*.60)
1697 movwf xA+1 1772 movwf xA+1
1698 call mult16x16 ; xA*xB=xC 1773 call mult16x16 ; xA*xB=xC
1699 1774
1700 movf xC+0,w 1775 ; add to the resettable depth accumulator
1776 movf xC+0,W
1701 addwf average_depth_hold+0,F 1777 addwf average_depth_hold+0,F
1702 movf xC+1,w 1778 movf xC+1,W
1703 addwfc average_depth_hold+1,F 1779 addwfc average_depth_hold+1,F
1704 movf xC+2,w 1780 movf xC+2,W
1705 addwfc average_depth_hold+2,F 1781 addwfc average_depth_hold+2,F
1706 movf xC+3,w 1782 movf xC+3,W
1707 addwfc average_depth_hold+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar 1783 addwfc average_depth_hold+3,F
1708 1784
1709 ; Do the same for the _total registers (Non-Resettable) 1785 ; add to the total depth accumulator
1710 movf xC+0,w 1786 movf xC+0,w
1711 addwf average_depth_hold_total+0,F 1787 addwf average_depth_hold_total+0,F
1712 movf xC+1,w 1788 movf xC+1,w
1713 addwfc average_depth_hold_total+1,F 1789 addwfc average_depth_hold_total+1,F
1714 movf xC+2,w 1790 movf xC+2,w
1715 addwfc average_depth_hold_total+2,F 1791 addwfc average_depth_hold_total+2,F
1716 movf xC+3,w 1792 movf xC+3,w
1717 addwfc average_depth_hold_total+3,F; Will work up to 9999mbar*60*60*24=863913600mbar 1793 addwfc average_depth_hold_total+3,F
1718 1794
1719 movlw .5 ; + 5 minutes 1795 IFDEF _cave_mode
1720 movff WREG,char_I_sim_advance_time; copy to mailbox 1796 ; update backtracking data
1721 bsf divemode2 ; continue divetime 1797 movlw .5 ; add backtrack data for 5 minutes
1722 call restart_deco_engine 1798 call update_backtrack ; make it so
1799 ENDIF
1800
1723 goto menuview_toggle_reset ; and return... 1801 goto menuview_toggle_reset ; and return...
1724 1802
1725 divemode_option7: 1803 divemode_option7:
1726 ; Store heading for compass view 1804 ; Store heading for compass view
1727 movff compass_heading_shown+0,compass_bearing+0 1805 movff compass_heading_shown+0,compass_bearing+0
1728 movff compass_heading_shown+1,compass_bearing+1 1806 movff compass_heading_shown+1,compass_bearing+1
1729 bsf compass_bearing_set ; set flag 1807 bsf compass_bearing_set ; set flag
1730 goto menuview_toggle_reset ; Done and return... 1808 goto menuview_toggle_reset ; and return...
1731 1809
1732 divemode_option8: 1810 divemode_option8:
1733 bsf alternative_divelayout ; Set flag for mode 1811 bsf alternative_divelayout ; set flag for alternative layout mode
1734 bsf FLAG_TFT_divemode_mask_alt ; Set flag for mask 1812 call menuview_toggle_reset ; terminate the pre-menu
1735 movlw .1 1813 call TFT_ClearScreen ; clear the whole screen
1736 movwf menupos3 ; For the customviews... 1814 bsf FLAG_TFT_divemode_mask_alt ; set flag to draw the alternative mask
1737 call TFT_ClearScreen ; Clear screen 1815 movff menupos3,customview_divemode; back-up the custom view shown in normal layout
1738 goto menuview_toggle_reset ; Done and return... 1816 clrf menupos3 ; select the default alternative layout
1817 call customview_mask_alternative ; draw the default alternative layout
1818 return ; done
1819
1739 1820
1740 divemode_simulator_check_limits: 1821 divemode_simulator_check_limits:
1741 ; Check limits (150m and 0m) 1822 ; check limits (150m and 0m)
1742 movlw LOW d'16000' ; Compare to 16bar=16000mbar (150m). 1823 movlw LOW d'16000' ; compare to 16 bar = 16000 mbar (150m)
1743 subwf sim_pressure+0,W 1824 subwf sim_pressure+0,W
1744 movlw HIGH d'16000' 1825 movlw HIGH d'16000'
1745 subwfb sim_pressure+1,W 1826 subwfb sim_pressure+1,W
1746 bnc divemode_simulator_check_limits2 ; No-carry = borrow = not deeper 1827 bnc divemode_simulator_check_limits2 ; no carry = borrow = not deeper
1747 1828
1748 ; Too deep, limit to 150m 1829 ; too deep, limit to 150m
1749 movlw LOW d'16000' 1830 movlw LOW d'16000'
1750 movwf sim_pressure+0 1831 movwf sim_pressure+0
1751 movlw HIGH d'16000' 1832 movlw HIGH d'16000'
1752 movwf sim_pressure+1 1833 movwf sim_pressure+1
1753 return 1834 return
1835
1754 divemode_simulator_check_limits2: 1836 divemode_simulator_check_limits2:
1755 movlw LOW d'1000' ; Compare to 1bar == 0m == 1000 mbar. 1837 movlw LOW d'1000' ; compare to 1 bar == 0m == 1000 mbar
1756 subwf sim_pressure+0,W 1838 subwf sim_pressure+0,W
1757 movlw HIGH d'1000' 1839 movlw HIGH d'1000'
1758 subwfb sim_pressure+1,W 1840 subwfb sim_pressure+1,W
1759 btfsc STATUS,C ; No-carry = borrow = not deeper. 1841 btfsc STATUS,C ; no carry = borrow = not deeper
1760 return ; Deeper than 0m == Ok. 1842 return ; deeper than 0 m == ok
1761 ; Too shallow, limit to 0m 1843 ; too shallow, limit to 0m
1762 movlw LOW d'1000' 1844 movlw LOW d'1000'
1763 movwf sim_pressure+0 1845 movwf sim_pressure+0
1764 movlw HIGH d'1000' 1846 movlw HIGH d'1000'
1765 movwf sim_pressure+1 1847 movwf sim_pressure+1
1766 return 1848 return
1767 1849
1768 ;============================================================================= 1850 ;=============================================================================
1769 ; Compare all enabled gas in list, to see if a better one is available. 1851 ; Find the best gas and diluent for the current depth
1852 ; and check if a gas/diluent change is to be advised.
1770 ; 1853 ;
1771 ; Output: better_gas_available, better_gas_number 1854 ; Output: best_gas_number : number of best gas, 0= none avail, 255= not computed
1855 ; best_dil_number : number of best dil, 0= none avail, 255= not computed
1856 ; better_gas_available : flag indicating if a change is advised
1857 ; better_dil_available : flag indicating if a change is advised
1772 ; 1858 ;
1773 check_gas_change: ; Checks if a better gas should be selected (by user) 1859 ;
1774 bcf better_gas_available ; =1: A better gas is available and a gas change is advised in divemode 1860 ; in CCR and pSCR mode: - checks both, gases and diluents for respective best gas / best diluent
1775 clrf WREG 1861 ; - if not in bailout, sets better_dil_available on diluents
1776 movff WREG,better_gas_number ; clear better gas register 1862 ; - if in bailout, sets better_gas_available on OC gases
1777 1863 ;
1778 SAFE_2BYTE_COPY rel_pressure,xA 1864 ; in OC mode : - checks only gases for best gas
1779 movlw d'100' 1865 ; - sets better_gas_available on OC gases
1780 movwf xB+0 1866 ;
1867 check_gas_best:
1868 movff amb_press_10+0,xA+0 ; copy ambient pressure / 10 into xA:2, will be used by ppO2 min/max checks later
1869 movff amb_press_10+1,xA+1 ; ...
1870 ; set maximum ppO2 allowed
1871 movff char_I_ppO2_max,ppO2_max ; max ppO2 for working phase (default)
1872 movff char_O_deco_info,lo ; bank-safe copy of deco info vector
1873 btfsc lo,deco_flag ; is the ppo2 deco limit enabled?
1874 movff char_I_ppO2_max_deco,ppO2_max ; YES - replace by max ppO2 for deco phase
1875 ; check dive mode
1876 btfsc FLAG_oc_mode ; in OC mode?
1877 bra check_gas_best_gas ; YES - skip diluents, check for best gas only
1878
1879 check_gas_best_dil:
1880 ; set minimum ppO2 required
1881 movff char_I_ppO2_min,WREG ; min ppO2 for pure diluent in CCR mode (default)
1882 btfsc FLAG_pscr_mode ; in pSCR mode?
1883 movff char_I_ppO2_min_loop,ppO2_min ; YES - replace by min ppO2 for pure diluent in pSCR mode
1884 ; preset results to nothing found
1885 clrf best_gas_num ; initialize best diluent as 0 = nothing found yet
1886 bcf better_dil_available ; =1: a better diluent is available and a gas change is advised in divemode
1887 ; ; current diluent = 'gas6' ?
1888 ; movlw .6 ;
1889 ; cpfseq active_dil ; using 'gas6' as current diluent?
1890 ; bra check_gas_best_dil0 ; NO - continue
1891 ; bra check_gas_best_dil3 ; YES - suppress better diluent search in this case
1892 ;check_gas_best_dil0:
1893 ; check all diluents
1894 lfsr FSR1,opt_dil_O2_ratio ; set base address for diluent arrays
1895 movff active_dil,lo ; number of currently used diluent
1896 setf best_gas_depth ; initialize change depth of best dil found so far to 255 meter
1897 ; original code
1898 clrf check_gas_num
1899 incf check_gas_num,F
1900 rcall check_gas_best_common ; check diluent 1
1901 incf check_gas_num,F
1902 rcall check_gas_best_common ; check diluent 2
1903 incf check_gas_num,F
1904 rcall check_gas_best_common ; check diluent 3
1905 incf check_gas_num,F
1906 rcall check_gas_best_common ; check diluent 4
1907 incf check_gas_num,F
1908 rcall check_gas_best_common ; check diluent 5
1909 ; alternative code
1910 ; movlw .5
1911 ; movwf check_gas_num
1912 ;check_gas_best_dil_loop:
1913 ; rcall check_gas_best_common
1914 ; decfsz check_gas_num
1915 ; bra check_gas_best_dil_loop
1916 ;
1917 ; store result
1918 movff best_gas_num,best_dil_number ; store new best diluent found (1-5 or 0 of no usable diluent available)
1919 ; check if change advices shall be given in general
1920 btfsc FLAG_bailout_mode ; in bailout?
1921 bra check_gas_best_gas ; YES - no better diluent advice when in bailout
1922 check_gas_best_dil1:
1923 ; check if a change advice shall be given right now
1924 movf best_dil_number,W ; load number of best diluent into WREG (1-5)
1925 bz check_gas_best_dil3 ; has a best diluent been found at all? NO - nothing to signal for
1926 cpfseq active_dil ; is this the currently used diluent?
1927 bra check_gas_best_dil2 ; NO
1928 bra check_gas_best_dil3 ; YES - no need to signal a better diluent if this diluent is already in use
1929 check_gas_best_dil2:
1930 btfsc setpoint_fallback ; is a fallback warning active?
1931 bra check_gas_best_dil3 ; YES - suppress better diluent prompt in this case
1932 ; not using the best gas - show better diluent hint whenever a better diluent is available
1933 bsf better_dil_available ; signal that a better diluent is available
1934 bsf FLAG_TFT_active_gas_divemode ; redraw gas/setpoint/diluent
1935 check_gas_best_dil3:
1936 btfss better_dil_available ; shall a better diluent be signaled for?
1937 bcf blinking_better_dil ; NO - clear blinking flag
1938 ; continue with checking for best bailout gas
1939
1940 check_gas_best_gas:
1941 ; set minimum ppO2 required
1942 movff char_I_ppO2_min,ppO2_min ; min ppO2 for OC/Bailout
1943 ; preset results to nothing found
1944 clrf best_gas_num ; initialize best gas as 0 = nothing found yet
1945 bcf better_gas_available ; =1: a better gas is available and a gas change is advised in divemode
1946 ; ; current gas = 'gas6' ?
1947 ; movlw .6 ;
1948 ; cpfseq active_gas ; using 'gas6' as current gas?
1949 ; bra check_gas_best_gas0 ; NO - continue
1950 ; bra check_gas_best_gas3 ; YES - suppress better gas search in this case
1951 ;check_gas_best_gas0:
1952 ; check all gases
1953 lfsr FSR1,opt_gas_O2_ratio ; set base address for gas arrays
1954 movff active_gas,lo ; number of currently used gas
1955 setf best_gas_depth ; initialize change depth of best gas found so far to 255 meter
1956 ; original code
1957 clrf check_gas_num
1958 incf check_gas_num,F
1959 rcall check_gas_best_common ; check gas 1
1960 incf check_gas_num,F
1961 rcall check_gas_best_common ; check gas 2
1962 incf check_gas_num,F
1963 rcall check_gas_best_common ; check gas 3
1964 incf check_gas_num,F
1965 rcall check_gas_best_common ; check gas 4
1966 incf check_gas_num,F
1967 rcall check_gas_best_common ; check gas 5
1968 ; alternative code
1969 ; movlw .5
1970 ; movwf check_gas_num
1971 ;check_gas_best_gas_loop:
1972 ; rcall check_gas_best_common
1973 ; decfsz check_gas_num
1974 ; bra check_gas_best_gas_loop
1975 ;
1976 ; store result
1977 movff best_gas_num,best_gas_number ; store new best gas found (1-5 or 0 of no usable gas available)
1978 ; check if change advices shall be given in general
1979 btfsc FLAG_oc_mode ; in OC mode?
1980 bra check_gas_best_gas1 ; YES
1981 btfsc FLAG_bailout_mode ; in bailout?
1982 bra check_gas_best_gas1 ; YES
1983 return ; NO - no better (OC) gas advice when not in OC or bailout mode
1984 check_gas_best_gas1: ; check if we are already on the best gas
1985 ; check if a change advice shall be given right now
1986 movf best_gas_number,W ; load number of best gas into WREG (1-5)
1987 bz check_gas_best_gas3 ; has a best gas been found at all? NO - nothing to signal for
1988 cpfseq active_gas ; is this the currently used gas?
1989 bra check_gas_best_gas2 ; NO
1990 bra check_gas_best_gas3 ; YES - no need to signal a better gas if this gas is already in use
1991 check_gas_best_gas2:
1992 ; not using the best gas - show better gas hint whenever a better gas is available
1993 bsf better_gas_available ; YES - signal that a better gas is available
1994 bsf FLAG_TFT_active_gas_divemode ; YES - redraw gas/setpoint/diluent
1995 check_gas_best_gas3:
1996 btfss better_gas_available ; shall a better gas be signaled for?
1997 bcf blinking_better_gas ; NO - clear blinking flag
1998 return
1999
2000 check_gas_best_common: ; with gas to be checked in check_gas_num (1-5)
2001 ; ; and current gas in lo (1-5)
2002 ;
2003 ; Memory Map:
2004 ; ---------------------------------------------------------------------------------------
2005 ; opt_gas_O2_ratio res 5 ; base address for gases
2006 ; opt_dil_O2_ratio res 5 ; base address for diluents
2007 ; opt_gas_He_ratio res 5 ; (not needed here)
2008 ; opt_dil_He_ratio res 5 ; (not needed here)
2009 ; opt_gas_type res 5 ; has offset of 20 bytes from base address for gases
2010 ; opt_dil_type res 5 ; has offset of 20 bytes from base address for diluents
2011 ; opt_gas_change res 5 ; has offset of 10 bytes from opt_gas_type
2012 ; opt_dil_change res 5 ; has offset of 10 bytes from opt_dil_type
2013
2014 ; get gas data
2015 decf check_gas_num,W ; (1-5) -> (0-4) into WREG to be used as index
2016 movff PLUSW1,check_gas_O2_ratio ; load O2 ratio (%) of current gas/dil into check_gas_O2_ratio
2017 addlw .20 ; add offset of 20 bytes to index type in opt_gas_type/opt_dil_type
2018 movff PLUSW1,check_gas_type ; load type of current gas/dil into check_gas_type (0=disabled, 1=first, 2=travel/normal, 3=deco/-)
2019 addlw .10 ; add offset of 10 bytes to index change depth in opt_gas_change/opt_dil_change
2020 movff PLUSW1,check_gas_depth ; load change depth of current gas/dil into check_gas_depth
2021 ; check if gas is usable (i.e. not disabled)
2022 tstfsz check_gas_type ; type = disabled (0)?
2023 bra check_gas_best_common0 ; NO - continue checks
2024 movf check_gas_num,W ; YES - get the number of the gas to be checked (1-5)
2025 cpfseq lo ; - is this the currently used gas?
2026 return ; NO - skip disabled gases which are not the current gas
2027 bra check_gas_best_common1 ; YES - a gas in use overrides it's disabled status, therefore treat it as available
2028 check_gas_best_common0:
2029 ; skip deco gases (type=3) if not in deco mode, but search among all enabled gases when in loop or bailout mode
2030 movlw .3
2031 cpfseq check_gas_type ; type = deco (3)?
2032 bra check_gas_best_common1 ; NO - proceed
2033 btfsc FLAG_bailout_mode ; YES - in bailout?
2034 bra check_gas_best_common1 ; YES - proceed, include deco gases
2035 movff char_O_main_status,WREG ; NO - get main deco mode
2036 btfsc WREG,DECO_MODE_LOOP_FLAG ; - in loop mode?
2037 bra check_gas_best_common1 ; YES - proceed, include deco gases
2038 movff char_O_deco_info,WREG ; NO - get deco info vector
2039 btfss WREG,deco_flag ; - in deco mode (deco_flag set), i.e. use of deco gases allowed?
2040 return ; NO - skip deco gas while not in deco mode
2041 check_gas_best_common1: ; YES - proceed
2042 ; ; check if gas change depth is below minimum change depth
2043 ; movlw minimum_change_depth ; for value see definition in hwos.inc
2044 ; cpfsgt check_gas_depth ; change depth of checked gas > minimum_change_depth?
2045 ; return ; NO - change depth not deep enough, skip and check next gas
2046 ; check if gas is usable, i.e. its change depth is below or equal to the current depth
2047 movf curr_depth,W ; load current depth (in m) into WREG
2048 cpfslt check_gas_depth ; change depth of checked gas < (shallower than) current depth?
2049 bra check_gas_best_common2 ; NO - gas is usable
2050 return ; YES - gas is not usable
2051 check_gas_best_common2:
2052 ; check if this gas is the first best gas candidate
2053 movf best_gas_num,W ; get best gas found so far (1-5) or 0 if none found yet
2054 tstfsz WREG ; has a best gas candidate been found yet?
2055 bra check_gas_best_common3 ; YES - check if the new one is better than the one we have so far
2056 bra check_gas_best_common4 ; NO - no need to do the above mentioned check
2057 check_gas_best_common3:
2058 ; check if the change depth of the checked gas is < (shallower) than the change depth of the best gas found so far
2059 movf best_gas_depth,W ; load change depth of best gas so far into WREG
2060 cpfslt check_gas_depth ; change depth of checked gas < (shallower than) change depth of best gas so far?
2061 return ; NO - this gas is not better than the best already found
2062 check_gas_best_common4:
2063 ; check if the gas fits into the ppO2 limits
2064 movff check_gas_O2_ratio,xB+0 ; xB = O2 ratio, xA is still loaded with (p_amb / 10)
1781 clrf xB+1 2065 clrf xB+1
1782 call div16x16 ; compute depth in full m -> result in xC+0 2066 call mult16x16 ; xC = O2 ratio * (p_amb / 10)
1783 2067 ; check for very high ppO2
1784 btfsc FLAG_pscr_mode ; in PSCR mode? 2068 tstfsz xC+2 ; O2_ratio * p_amb / 10 > 65536, i.e. ppO2 > 6.55 bar ?
1785 bra check_gas_change2 ; YES - check for diluents 2069 return ; YES - gas is not usable
1786 btfss FLAG_ccr_mode ; in CCR mode? 2070 btfsc xC+1,7 ; check if ppO2 > 3.30 bar
1787 bra check_gas_change_OC_bail ; NO - check for OC 2071 return ; YES - gas is not usable
1788 check_gas_change2: 2072 ; check for low ppO2
1789 btfsc is_bailout ; in bailout?
1790 bra check_gas_change_OC_bail ; YES - check for OC
1791
1792 ; Check Diluents
1793 movlw .0
1794 rcall check_dil_common ; With Gas 0-4 in WREG
1795 movlw .1
1796 rcall check_dil_common ; With Gas 0-4 in WREG
1797 movlw .2
1798 rcall check_dil_common ; With Gas 0-4 in WREG
1799 movlw .3
1800 rcall check_dil_common ; With Gas 0-4 in WREG
1801 movlw .4
1802 rcall check_dil_common ; With Gas 0-4 in WREG
1803 bra check_gas_change_exit
1804
1805 check_gas_change_OC_bail:
1806 movlw .0
1807 rcall check_gas_common ; With Gas 0-4 in WREG
1808 movlw .1
1809 rcall check_gas_common ; With Gas 0-4 in WREG
1810 movlw .2
1811 rcall check_gas_common ; With Gas 0-4 in WREG
1812 movlw .3
1813 rcall check_gas_common ; With Gas 0-4 in WREG
1814 movlw .4
1815 rcall check_gas_common ; With Gas 0-4 in WREG
1816 ;bra check_gas_change_exit
1817
1818 check_gas_change_exit:
1819 bsf FLAG_TFT_active_gas_divemode; redraw gas/setpoint/diluent
1820 btfss better_gas_available ; is a better gas available?
1821 bcf blinking_better_gas ; NO - clear blinking flag
1822 btfsc better_gas_available ; is a better gas available?
1823 return ; YES
1824 clrf WREG ; NO - clear better_gas_number (for gaslist display)
1825 movff WREG,better_gas_number
1826 return
1827
1828 check_gas_common: ; With Gas 0-4 in WREG
1829 btfsc better_gas_available ; Better Gas already found?
1830 return ; Yes, return
1831 lfsr FSR1,opt_gas_type ; 0=Disabled, 1=First, 2=Travel, 3=Deco
1832 btfss PLUSW1,0 ; Test for Bit0 and 1 -> type=3 -> Deco
1833 return ; No
1834 btfss PLUSW1,1 ; Test for Bit0 and 1 -> type=3 -> Deco
1835 return ; No
1836 incf WREG,W ; 1-5
1837 cpfseq active_gas ; is this gas current gas?
1838 bra check_gas_common2 ; No
1839 return ; Yes, skip test for active gas
1840 check_gas_common2:
1841 decf WREG,W ; 0-4
1842 movwf hi ; Save tested gas 0-4
1843 lfsr FSR1,opt_OC_bail_gas_change
1844 movff PLUSW1,lo ; Change depth into lo
1845 movlw minimum_change_depth
1846 cpfsgt lo ; Change depth>minimum_change_depth?
1847 return ; No, Change depth not deep enough, skip!
1848 movf xC+0,W ; load depth in m into WREG
1849 cpfsgt lo ; gas_change_depth < current depth?
1850 bra check_gas_common3 ; No, check if we are within the better_gas_window_pos window
1851 incf hi,W ; 1-5
1852 movff WREG,better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available
1853 movlw better_gas_window_neg
1854 subwf lo,W ; Change depth-better_gas_window_neg
1855 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg?
1856 bra check_gas_common4 ; Ok, now check the better gas ppO2<char_I_ppO2_max
1857 return
1858 check_gas_common3:
1859 incf hi,W ; 1-5
1860 movff WREG,better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available
1861 movlw better_gas_window_pos
1862 addwf lo,W ; Change depth+better_gas_window_pos
1863 cpfsgt xC+0 ; current depth>Change depth+better_gas_window_pos?
1864 bra check_gas_common4 ; Ok, now check the better gas ppO2<char_I_ppO2_max
1865 return
1866 check_gas_common4:
1867 movf hi,W ; gas 0-4 into WREG
1868 lfsr FSR1,char_I_deco_O2_ratio ; load base address char_I_deco_O2_ratio array
1869 movff PLUSW1,lo ; read O2 ratio from array into lo
1870
1871 SAFE_2BYTE_COPY amb_pressure, xA
1872 movlw d'10'
1873 movwf xB+0
1874 clrf xB+1
1875 call div16x16 ; xC=p_amb/10
1876 movff xC+0,xA+0
1877 movff xC+1,xA+1
1878 movff lo,xB+0 ; =O2 ratio
1879 clrf xB+1
1880 call mult16x16 ; lo * p_amb/10
1881
1882 ; Check very high ppO2 manually
1883 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar?
1884 return ; Done.
1885 ; Check if ppO2>3,30bar
1886 btfsc xC+1,7
1887 return ; Done.
1888
1889 ; Check for low ppo2
1890 movff xC+0,sub_b+0
1891 movff xC+1,sub_b+1
1892 movff char_I_ppO2_min,WREG
1893 mullw d'100' ; char_I_ppO2_min*100
1894 movff PRODL,sub_a+0
1895 movff PRODH,sub_a+1
1896 call subU16 ; sub_c = sub_a - sub_b
1897 btfss neg_flag
1898 return ; Done (Too low).
1899
1900 ;check if we are within our warning thresholds!
1901 movff xC+0,sub_a+0 2073 movff xC+0,sub_a+0
1902 movff xC+1,sub_a+1 2074 movff xC+1,sub_a+1
1903 movff char_I_ppO2_max_deco,WREG ; ppO2 max for MOD calculation and color coding in divemode 2075 movf ppO2_min,W
1904 addlw .1 ; e.g. >1.60 2076 mullw .100 ; char_I_ppO2_min * 100
1905 mullw d'100' ; char_I_ppO2_max*100
1906 movff PRODL,sub_b+0 2077 movff PRODL,sub_b+0
1907 movff PRODH,sub_b+1 2078 movff PRODH,sub_b+1
1908 call subU16 ; sub_c = sub_a - sub_b 2079 call subU16 ; sub_c = sub_a - sub_b
1909 btfsc neg_flag 2080 btfsc neg_flag ; within limit?
1910 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode 2081 return ; NO - too low, gas is not usable
1911 return ; Done. 2082 ; check for high ppO2
1912 2083 movf ppO2_max,W
1913 2084 mullw .100 ; ppO2_max * 100
1914 check_dil_common: ; With Dil 0-4 in WREG 2085 movff PRODL,sub_b+0
1915 btfsc better_gas_available ; Better Diluent already found? 2086 movff PRODH,sub_b+1
1916 return ; Yes, return 2087 infsnz sub_b+0,F ; add 1 mbar to allowance to avoid exclusion on equal
1917 lfsr FSR1,opt_dil_type ; 0=Disabled, 1=First, 2=Normal 2088 incf sub_b+1,F
1918 tstfsz PLUSW1 ; =0? 2089 call subU16 ; sub_c = sub_a - sub_b
1919 bra check_dil_common1 ; No 2090 btfss neg_flag ; within limit?
1920 return ; Yes, skip inactive diluents for test 2091 return ; NO - too high, gas is not usable
1921 check_dil_common1: 2092 ; we have a (new) best gas
1922 incf WREG,W ; 1-5 2093 movff check_gas_num, best_gas_num ; set checked gas (1-5) as best gas
1923 cpfseq active_gas ; is this the current diluent? 2094 movff check_gas_depth,best_gas_depth ; memorize its change depth
1924 bra check_dil_common2 ; No
1925 return ; Yes, skip test for active diluent
1926 check_dil_common2:
1927 decf WREG,W ; 0-4
1928 movwf hi ; Save tested diluent 0-4
1929 lfsr FSR1,char_I_dil_change
1930 movff PLUSW1,lo ; Change depth into lo
1931 movlw minimum_change_depth
1932 cpfsgt lo ; Change depth>minimum_change_depth?
1933 return ; No, Change depth not deep enough, skip!
1934 movf xC+0,W ; load depth in m into WREG
1935 cpfsgt lo ; gas_change_depth < current depth?
1936 return ; No, check next gas
1937 incf hi,W ; 1-5
1938 movff WREG,better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available
1939 movlw better_gas_window_neg
1940 subwf lo,W ; Change depth-better_gas_window_neg
1941 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg?
1942 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode
1943 return 2095 return
1944 2096
1945 2097
1946 ;============================================================================= 2098 ;=============================================================================
1947 ; Check for Auto-SP 2099 ; Check for Auto-SP
1948 ; 2100 ;
1949 check_dive_autosp: ; Check for Auto-SP 2101 check_dive_autosp: ; check for Auto-SP
1950 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 2102 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP
1951 sublw .2 ; opt_ccr_mode = 2 (Auto SP)? 2103 sublw .2 ; opt_ccr_mode = 2 (Auto SP)?
1952 bz check_dive_autosp2 ; Yes, check 2104 bz check_dive_autosp2 ; YES - check
1953 return ; No, return for Sensor or Fixed mode 2105 return ; NO - return for sensor or fixed mode
1954 check_dive_autosp2: 2106 check_dive_autosp2:
1955 SAFE_2BYTE_COPY rel_pressure,xA
1956 movlw d'100'
1957 movwf xB+0
1958 clrf xB+1
1959 call div16x16 ; compute depth in full m -> result in xC+0
1960 ; Check SP2 2107 ; Check SP2
1961 btfsc sp2_switched ; =1: This setpoint has been autoselected already 2108 btfsc sp2_switched ; SP 2 used so far?
1962 bra check_dive_autosp3 ; Skip check 2109 bra check_dive_autosp3 ; YES - continue with SP 3
1963 movff char_I_setpoint_change+1,lo ; Get depth in m 2110 movff char_I_setpoint_change+1,lo ; NO - get depth in m
1964 tstfsz lo ; =0? 2111 tstfsz lo ; - SP change depth = 0 ?
1965 bra check_dive_autosp2a ; No, continue 2112 bra check_dive_autosp2a ; NO - continue
1966 bra check_dive_autosp3 ; Skip check 2113 bra check_dive_autosp3 ; YES - continue with SP 3
1967 check_dive_autosp2a: 2114 check_dive_autosp2a:
1968 decf lo,W ; -1 -> WREG 2115 decf lo,W ; SP change depth -1 -> WREG
1969 cpfsgt xC+0 ; Compare with depth 2116 cpfsgt curr_depth ; current depth > change depth - 1 ?
1970 bra check_dive_autosp3 ; lower depth, do not switch 2117 bra check_dive_autosp3 ; NO - continue with SP 3
1971 ; auto switch to SP2 2118 ; auto switch to SP2
1972 movff char_I_setpoint_cbar+1,char_I_const_ppO2 ; Use SetPoint 2119 movff char_I_setpoint_cbar+1,char_I_const_ppO2 ; YES - use SP
1973 rcall xmit_sp_set_flag 2120 rcall xmit_sp_set_flag ; - send SP to external devices
1974 bsf sp2_switched ; Set flag 2121 bsf sp2_switched ; - set SP 2 used flag
1975 check_dive_autosp3: 2122 check_dive_autosp3:
1976 ; Check SP3 2123 ; Check SP3
1977 btfsc sp3_switched ;=1: This setpoint has been autoselected already 2124 btfsc sp3_switched ; SP 3 used so far?
1978 bra check_dive_autosp4 ; Skip check 2125 bra check_dive_autosp4 ; YES - continue with SP 4
1979 movff char_I_setpoint_change+2,lo ; Get depth in m 2126 movff char_I_setpoint_change+2,lo ; NO - get depth in m
1980 tstfsz lo ; =0? 2127 tstfsz lo ; - SP change depth = 0 ?
1981 bra check_dive_autosp3a ; No, continue 2128 bra check_dive_autosp3a ; NO - continue
1982 bra check_dive_autosp4 ; Skip check 2129 bra check_dive_autosp4 ; YES - continue with SP 4
1983 check_dive_autosp3a: 2130 check_dive_autosp3a:
1984 decf lo,W ; -1 -> WREG 2131 decf lo,W ; SP change depth -1 -> WREG
1985 cpfsgt xC+0 ; Compare with depth 2132 cpfsgt curr_depth ; current depth > change depth - 1 ?
1986 bra check_dive_autosp4 ; lower depth, do not switch 2133 bra check_dive_autosp4 ; NO - continue with SP 4
1987 ; auto switch to SP3 2134 ; auto switch to SP3
1988 movff char_I_setpoint_cbar+2,char_I_const_ppO2 ; Use SetPoint 2135 movff char_I_setpoint_cbar+2,char_I_const_ppO2 ; YES - use SP
1989 rcall xmit_sp_set_flag 2136 rcall xmit_sp_set_flag ; - send SP to external devices
1990 bsf sp3_switched ; Set flag 2137 bsf sp3_switched ; - set SP 3 used flag
1991 check_dive_autosp4: 2138 check_dive_autosp4:
1992 ; Check SP4 2139 ; Check SP4
1993 btfsc sp4_switched ;=1: This setpoint has been autoselected already 2140 btfsc sp4_switched ; SP 4 used so far?
1994 bra check_dive_autosp5 ; Skip check 2141 bra check_dive_autosp5 ; YES - continue with SP 5
1995 movff char_I_setpoint_change+3,lo ; Get depth in m 2142 movff char_I_setpoint_change+3,lo ; NO - get depth in m
1996 tstfsz lo ; =0? 2143 tstfsz lo ; - SP change depth = 0 ?
1997 bra check_dive_autosp4a ; No, continue 2144 bra check_dive_autosp4a ; NO - continue
1998 bra check_dive_autosp5 ; Skip check 2145 bra check_dive_autosp5 ; YES - continue with SP 5
1999 check_dive_autosp4a: 2146 check_dive_autosp4a:
2000 decf lo,W ; -1 -> WREG 2147 decf lo,W ; SP change depth -1 -> WREG
2001 cpfsgt xC+0 ; Compare with depth 2148 cpfsgt curr_depth ; current depth > change depth - 1 ?
2002 bra check_dive_autosp5 ; lower depth, do not switch 2149 bra check_dive_autosp5 ; NO - continue with SP 5
2003 ; auto switch to SP4 2150 ; auto switch to SP4
2004 movff char_I_setpoint_cbar+3,char_I_const_ppO2 ; Use SetPoint 2151 movff char_I_setpoint_cbar+3,char_I_const_ppO2 ; YES - use SP
2005 rcall xmit_sp_set_flag 2152 rcall xmit_sp_set_flag ; - send SP to external devices
2006 bsf sp4_switched ; Set flag 2153 bsf sp4_switched ; - set SP 4 used flag
2007 check_dive_autosp5: 2154 check_dive_autosp5:
2008 ; Check SP5 2155 ; Check SP5
2009 btfsc sp5_switched ;=1: This setpoint has been autoselected already 2156 btfsc sp5_switched ; SP 5 used so far?
2010 bra check_dive_autosp6 ; Skip check 2157 bra check_dive_autosp6 ; YES - done
2011 movff char_I_setpoint_change+4,lo ; Get depth in m 2158 movff char_I_setpoint_change+4,lo ; NO - get depth in m
2012 tstfsz lo ; =0? 2159 tstfsz lo ; - SP change depth = 0 ?
2013 bra check_dive_autosp5a ; No, continue 2160 bra check_dive_autosp5a ; NO - continue
2014 bra check_dive_autosp6 ; Skip check 2161 bra check_dive_autosp6 ; YES - done
2015 check_dive_autosp5a: 2162 check_dive_autosp5a:
2016 decf lo,W ; -1 -> WREG 2163 decf lo,W ; SP change depth -1 -> WREG
2017 cpfsgt xC+0 ; Compare with depth 2164 cpfsgt curr_depth ; current depth > change depth - 1 ?
2018 bra check_dive_autosp6 ; lower depth, do not switch 2165 bra check_dive_autosp6 ; NO - done
2019 ; auto switch to SP5 2166 ; auto switch to SP5
2020 movff char_I_setpoint_cbar+4,char_I_const_ppO2 ; Use SetPoint 2167 movff char_I_setpoint_cbar+4,char_I_const_ppO2 ; YES - use SP
2021 rcall xmit_sp_set_flag 2168 rcall xmit_sp_set_flag ; - send SP to external devices
2022 bsf sp5_switched ; Set flag 2169 bsf sp5_switched ; - set SP 5 used flag
2023 check_dive_autosp6: 2170 check_dive_autosp6:
2024 return 2171 return
2025 2172
2026 xmit_sp_set_flag: 2173 xmit_sp_set_flag:
2027 movff char_I_const_ppO2,WREG 2174 movff char_I_const_ppO2,WREG
2028 call transmit_setpoint ; Transmit current setpoint from WREG (in cbar) to external electronics 2175 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics
2029 bsf setpoint_changed ; Set flag (for profile) 2176 bsf setpoint_changed ; set flag (for profile)
2030 bsf event_occured ; Set event flag 2177 bsf event_occured ; set event flag
2031 return 2178 return
2032 2179
2033 set_logbook_marker: 2180 set_logbook_marker:
2034 bcf FLAG_set_marker ; clear flag 2181 bcf FLAG_set_marker ; clear flag
2035 movlw d'6' ; set type of Alarm (manual marker) 2182 movlw d'6' ; set type of alarm (manual marker)
2036 movwf AlarmType ; copy to Alarm Register 2183 movwf AlarmType ; copy to alarm register
2037 bsf event_occured ; Set event flag 2184 bsf event_occured ; set event flag
2038 return 2185 return
2039 2186
2040 ;============================================================================= 2187 ;=============================================================================
2041 ; Setup everything to enter divemode. 2188 ; Setup everything to enter dive mode
2042 ; 2189 ;
2190 global dive_boot_oc_bail
2191 dive_boot_oc_bail:
2192 ; copy opt_gas_types into backup (for "lost gas" feature)
2193 movff opt_gas_type+0,opt_gas_type_backup+0 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2194 movff opt_gas_type+1,opt_gas_type_backup+1 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2195 movff opt_gas_type+2,opt_gas_type_backup+2 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2196 movff opt_gas_type+3,opt_gas_type_backup+3 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2197 movff opt_gas_type+4,opt_gas_type_backup+4 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2198 ; done
2199 return
2200
2201 global dive_boot_oc
2043 dive_boot_oc: 2202 dive_boot_oc:
2044 rcall get_first_gas_to_WREG ; Gets first gas (1-5) into WREG 2203 ; set-up registers
2204 rcall get_first_gas_to_WREG ; get first gas (1-5) into WREG
2045 rcall setup_gas_registers ; set-up of gas parameters of currently breathed gas (with WREG = gas 1-5) 2205 rcall setup_gas_registers ; set-up of gas parameters of currently breathed gas (with WREG = gas 1-5)
2046 rcall deco_setup_oc_gases ; set-up of gas list for deco calculations (with WREG = gas 1-5) 2206 rcall deco_setup_oc_gases ; set-up of gas list for deco calculations (with WREG = gas 1-5)
2047 return 2207 return
2048 2208
2209 global dive_boot_cc
2049 dive_boot_cc: 2210 dive_boot_cc:
2050 bcf is_bailout ; =1: Bailout 2211 ; copy opt_dil_types into backup (for "lost diluent" feature)
2051 bcf setpoint_fallback ; =1: Fallback to SP1 due to external O2 sensor failure 2212 movff opt_dil_type+0,opt_dil_type_backup+0 ; 0=Disabled, 1=First, 2=Normal
2052 bcf blinking_setpoint ; Reset blinking SP flag 2213 movff opt_dil_type+1,opt_dil_type_backup+1 ; 0=Disabled, 1=First, 2=Normal
2053 2214 movff opt_dil_type+2,opt_dil_type_backup+2 ; 0=Disabled, 1=First, 2=Normal
2215 movff opt_dil_type+3,opt_dil_type_backup+3 ; 0=Disabled, 1=First, 2=Normal
2216 movff opt_dil_type+4,opt_dil_type_backup+4 ; 0=Disabled, 1=First, 2=Normal
2217 ; clear flags
2218 bcf FLAG_bailout_mode ; =1: bailout
2219 bcf setpoint_fallback ; =1: fallback to SP1 due to external O2 sensor failure
2220 ; set-up registers
2221 rcall get_first_dil_to_WREG ; get first diluent (1-5) into WREG
2222 rcall setup_dil_registers ; set-up of diluent parameters for currently breathed diluent (with WREG = current diluent 1-5)
2223 rcall deco_setup_cc_diluents ; set-up of diluent list for deco calculations (with WREG = current diluent 1-5)
2224 ; done
2225 return
2226
2227 dive_boot_cc_part2:
2054 ; revoke sensors from usage if they do not have a valid calibration 2228 ; revoke sensors from usage if they do not have a valid calibration
2055 bsf use_O2_sensor1 2229 bsf use_O2_sensor1
2056 bsf use_O2_sensor2 2230 bsf use_O2_sensor2
2057 bsf use_O2_sensor3 2231 bsf use_O2_sensor3
2058 btfss sensor1_calibrated_ok 2232 btfss sensor1_calibrated_ok
2059 bcf use_O2_sensor1 2233 bcf use_O2_sensor1
2060 btfss sensor2_calibrated_ok 2234 btfss sensor2_calibrated_ok
2061 bcf use_O2_sensor2 2235 bcf use_O2_sensor2
2062 btfss sensor3_calibrated_ok 2236 btfss sensor3_calibrated_ok
2063 bcf use_O2_sensor3 2237 bcf use_O2_sensor3
2064 2238 ; check for external HUD/ppO2 Monitor
2065 btfss optical_input ; do we have an optical input? 2239 btfss optical_input ; do we have an optical input?
2066 bra dive_boot_cc_0 ; No 2240 bra dive_boot_cc_part2_1 ; NO
2067 ; Copy (initial) valid flags from HUD/ppO2 Monitor 2241 ; copy (initial) valid flags from HUD/ppO2 Monitor
2068 btfsc sensor1_active 2242 btfsc sensor1_active
2069 bsf use_O2_sensor1 2243 bsf use_O2_sensor1
2070 btfsc sensor2_active 2244 btfsc sensor2_active
2071 bsf use_O2_sensor2 2245 bsf use_O2_sensor2
2072 btfsc sensor3_active 2246 btfsc sensor3_active
2073 bsf use_O2_sensor3 2247 bsf use_O2_sensor3
2074 2248 dive_boot_cc_part2_1:
2075 dive_boot_cc_0:
2076 ; In pSCR mode, only settings 0 (calculated ppO2) and 1 (ppO2 from sensors) are defined. 2249 ; In pSCR mode, only settings 0 (calculated ppO2) and 1 (ppO2 from sensors) are defined.
2077 ; In case we still have 3 (auto SP) selected out of previous ccr mode, we reset to 0. 2250 ; In case we still have 3 (auto SP) selected out of previous CCR mode, we reset to 0.
2078 btfss FLAG_pscr_mode 2251 btfss FLAG_pscr_mode
2079 bra dive_boot_cc_1 2252 bra dive_boot_cc_part2_2
2080 movff opt_ccr_mode,WREG ; =0: Fixed SP (CCR) / calculated SP (pSCR), =1: Sensor, =2: Auto SP 2253 movff opt_ccr_mode,WREG ; =0: Fixed SP (CCR) / calculated SP (pSCR), =1: Sensor, =2: Auto SP
2081 sublw .2 ; opt_ccr_mode = 1 (Auto SP)? 2254 sublw .2 ; opt_ccr_mode = 1 (Auto SP)?
2082 bnz dive_boot_cc_1 2255 bnz dive_boot_cc_part2_2
2083 movlw .0 2256 movlw .0
2084 movff WREG,opt_ccr_mode 2257 movff WREG,opt_ccr_mode
2085 2258 dive_boot_cc_part2_2:
2086 dive_boot_cc_1:
2087 bsf setpoint_changed ; set flag (for profile) 2259 bsf setpoint_changed ; set flag (for profile)
2088 bcf sp2_switched ; =1: This setpoint has been auto-selected already 2260 bcf sp2_switched ; =1: this setpoint has been auto-selected already
2089 bcf sp3_switched ; =1: This setpoint has been auto-selected already 2261 bcf sp3_switched ; =1: this setpoint has been auto-selected already
2090 bcf sp4_switched ; =1: This setpoint has been auto-selected already 2262 bcf sp4_switched ; =1: this setpoint has been auto-selected already
2091 bcf sp5_switched ; =1: This setpoint has been auto-selected already 2263 bcf sp5_switched ; =1: this setpoint has been auto-selected already
2092
2093 rcall get_first_dil_to_WREG ; get first gas (1-5) into WREG
2094 rcall setup_dil_registers ; set-up of gas parameters for currently breathed gas (with WREG = current gas 1-5)
2095 rcall deco_setup_cc_diluents ; set-up of gas list for deco calculations (with WREG = current gas 1-5)
2096
2097 ; Start with SP1 (CCR) or 0 (pSCR) as default. 2264 ; Start with SP1 (CCR) or 0 (pSCR) as default.
2098 ; If in sensor mode, this value will be overwritten by calc_deko_divemode_sensor 2265 ; If in sensor mode, this value will be overwritten by calc_deko_divemode_sensor
2099 clrf WREG ; preload WREG with setpoint value 0 for pSCR calculated 2266 clrf WREG ; preload WREG with setpoint value 0 for pSCR calculated
2100 btfss FLAG_ccr_mode ; are we in CCR mode? 2267 btfsc FLAG_ccr_mode ; are we in CCR mode?
2101 bra dive_boot_cc_2 ; NO - keep preloaded value
2102 movff char_I_setpoint_cbar+0,WREG ; YES - get value of setpoint 1 2268 movff char_I_setpoint_cbar+0,WREG ; YES - get value of setpoint 1
2103 dive_boot_cc_2:
2104 movff WREG,char_I_const_ppO2 ; write setpoint to deco engine 2269 movff WREG,char_I_const_ppO2 ; write setpoint to deco engine
2105 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics 2270 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics
2106 goto calc_deko_divemode_sensor ; read & process sensor data (and return) 2271 goto calc_deko_divemode_sensor ; read & process sensor data (and return)
2107 2272
2273
2108 diveloop_boot: 2274 diveloop_boot:
2275
2276 ; do the basic initialization
2109 call restart_set_modes_and_flags 2277 call restart_set_modes_and_flags
2110 2278
2111 call I2C_sleep_accelerometer ; stop accelerometer 2279 ; stop accelerometer and compass
2112 call I2C_sleep_compass ; stop compass 2280 call I2C_sleep_accelerometer
2113 2281 call I2C_sleep_compass
2282
2283 ; reset max pressure aka max depth
2114 clrf WREG 2284 clrf WREG
2115 movff WREG,max_pressure+0 ; clear some variables 2285 movff WREG,max_pressure+0
2116 movff WREG,max_pressure+1 2286 movff WREG,max_pressure+1
2117 2287
2118 ; init in invalid data state 2288 ; initialize press needs to zero and invalid (not yet computed) state
2119 clrf WREG ; set WREG to 0 2289 clrf WREG ; set WREG to 0
2120 bsf WREG,int_invalid_flag ; set invalid flag 2290 IFDEF _cave_mode
2291 movff WREG,char_I_backtrack_time ; clear backtracking time (index to char_I_backtrack_depth)
2292 movff WREG,char_I_backtrack_depth ; prime first entry with depth 0
2293 ENDIF
2121 bsf WREG,int_is_zero ; set zero flag 2294 bsf WREG,int_is_zero ; set zero flag
2122 movff WREG,int_O_tank_pres_need+1 ; Set flags for tank pressure needs = 0 before p2_deco.c 2295 bsf WREG,int_invalid_flag ; set invalid flag (additionally)
2123 movff WREG,int_O_tank_pres_need+3 ; can do it. If this is not done here and the gas needs 2296 banksel int_O_ascent_pres_need ; select bank with shared output vars
2124 movff WREG,int_O_tank_pres_need+5 ; custom view is shown before p2_deco.c completes the first 2297 movwf int_O_ascent_pres_need+1 ; Set flags for tank pressure needs = 0 before p2_deco.c
2125 movff WREG,int_O_tank_pres_need+7 ; deco calculation, some rubbish numbers from last dive of 2298 movwf int_O_ascent_pres_need+3 ; can do it. If this is not done here and the gas needs
2126 movff WREG,int_O_tank_pres_need+9 ; simulation may be shown 2299 movwf int_O_ascent_pres_need+5 ; custom view is shown before p2_deco.c completes the first
2127 2300 movwf int_O_ascent_pres_need+7 ; deco calculation, some rubbish numbers from last dive or
2128 ; configure the deco engine: 2301 movwf int_O_ascent_pres_need+9 ; simulation may be shown
2129 movff char_O_deco_status,WREG ; bank-safe copy 2302 banksel common ; back to bank common
2130 bsf WREG,DECO_STATUS_0_FLAG ; configure init ... 2303
2131 bsf WREG,DECO_STATUS_1_FLAG ; ... state, 2304 ; configure the deco engine
2132 bcf WREG,DECO_PLAN_FLAG ; normal plan mode, 2305 clrf hi
2133 bsf WREG,DECO_CNS_FLAG ; enable CNS calculation (CNS at end of dive), 2306 bsf hi,DECO_Z_FACTOR_FLAG ; enable Z factor mode by default
2134 bcf WREG,DECO_VOLUME_FLAG ; disable gas volume calculation, and 2307 TSTOSS opt_ZfactorUse ; shall use Z factor mode?
2135 bcf WREG,DECO_ASCENT_FLAG ; disable delayed ascent calculation 2308 bcf hi,DECO_Z_FACTOR_FLAG ; NO - disable again
2136 movff WREG,char_O_deco_status ; bank-safe copy back 2309 IFDEF _rx_functions
2310 bsf hi,DECO_TR_FUNCTIONS ; enable TR mode by default
2311 btfss FLAG_tr_enabled ; shall use TR mode?
2312 bcf hi,DECO_TR_FUNCTIONS ; NO - disable again
2313 ENDIF
2314 movff hi,char_O_main_status ; bank-safe copy to deco engine
2315
2316 movff char_O_deco_status,lo ; bank-safe read
2317 bsf lo,DECO_STATUS_0_FLAG ; set init- | ATTENTION: The deco engine must be started in init state! If omitted, it may
2318 bsf lo,DECO_STATUS_1_FLAG ; state, | enter an infinite loop at some point in time and brick the OSTC!
2319 bcf lo,DECO_PLAN_FLAG ; normal plan mode,
2320 bcf lo,DECO_VOLUME_FLAG ; disable gas volume calculation, and
2321 bcf lo,DECO_ASCENT_FLAG ; disable delayed ascent calculation
2322 movff lo,char_O_deco_status ; bank-safe copy back to deco engine
2137 2323
2138 clrf WREG 2324 clrf WREG
2139 movff WREG,char_O_main_status ; reset char_O_main_status 2325 movff WREG,char_O_deco_warnings ; clear any deco warnings remaining from last dive
2140 2326 movff WREG,char_O_deco_info ; clear any deco infos remaining from last dive
2141 movlw deco_distance 2327
2142 movff WREG,char_I_deco_distance 2328 movlw deco_distance ; load distance between actual depth and depth used for deco calculation
2143 movff opt_last_stop,char_I_depth_last_deco 2329 movff WREG,char_I_deco_distance ; write distance to the deco engine
2144 movff opt_GF_low,char_I_GF_Low_percentage 2330
2145 movff opt_GF_high,char_I_GF_High_percentage 2331 movff opt_last_stop,char_I_depth_last_deco ; write last stop depth to deco engine
2146 2332 movff opt_GF_low,char_I_GF_Low_percentage ; write GF low to deco engine
2147 bcf use_agf ; Start with normal GF set 2333 movff opt_GF_high,char_I_GF_High_percentage ; write GF high to deco engine
2148 bcf divemode_menu ; clear divemode menu flag 2334
2149 2335 bcf onesectoggle ; clear toggle bit for calculation phasing
2150 bcf alternative_divelayout ; Start with default layout 2336 bcf use_agf ; start with normal GF set
2151 2337 bcf divemode_menu ; clear dive mode menu flag
2338 bcf alternative_divelayout ; start with default layout
2152 bcf blinking_depth_prev ; clear flag for blinking depth 2339 bcf blinking_depth_prev ; clear flag for blinking depth
2153 bcf blinking_depth_warning ; clear flag for blinking depth
2154 bcf blinking_depth_toggle ; clear flag for blinking depth 2340 bcf blinking_depth_toggle ; clear flag for blinking depth
2341 bcf blinking_depth_warning ; clear flag for blinking depth as warning
2342 bcf blinking_depth_attention ; clear flag for blinking depth as attention
2343 bcf max_depth_greater_100m ; clear flag for last max/avg depth was > 100 m
2155 2344
2156 movlw d'1' 2345 movlw d'1'
2157 movwf apnoe_max_pressure+0 2346 movwf apnoe_max_pressure+0
2158 clrf apnoe_max_pressure+1 2347 clrf apnoe_max_pressure+1
2159 ; clrf apnoe_surface_mins 2348 ; clrf apnoe_surface_mins
2160 ; clrf apnoe_surface_secs 2349 ; clrf apnoe_surface_secs
2161 clrf apnoe_mins 2350
2162 clrf divemins+0 2351 ; copy date and time for logbook
2163 clrf divemins+1
2164
2165 ; Copy date and time for logbook
2166 movff year,start_year 2352 movff year,start_year
2167 movff month,start_month 2353 movff month,start_month
2168 movff day,start_day 2354 movff day,start_day
2169 movff hours,start_hours 2355 movff hours,start_hours
2170 movff mins,start_mins 2356 movff mins,start_mins
2171 2357
2172 movff int_O_CNS_fraction+0,CNS_start+0 ; save CNS value at beginning of dive 2358 movff int_O_CNS_fraction+0,CNS_start+0 ; save CNS value at beginning of dive
2173 movff int_O_CNS_fraction+1,WREG ; get high byte to WREG 2359 movff int_O_CNS_fraction+1,WREG ; get high byte to WREG
2174 bcf WREG,int_warning_flag ; clear warning flag 2360 bcf WREG,int_warning_flag ; clear warning flag
2175 bcf WREG,int_attention_flag ; clear attention flag 2361 bcf WREG,int_attention_flag ; clear attention flag
2176 movff WREG,CNS_start+1 ; move high byte on 2362 movff WREG,CNS_start+1 ; move high byte on
2177 movff int_O_gradient_factor+0,GF_start ; save GF value at beginning of dive (only lower byte used for value) 2363 movff int_O_gradient_factor+0,GF_start ; save GF value at beginning of dive (only lower byte used for value)
2178 2364
2179 bcf no_more_divesecs ; =1: do no longer show seconds in divemode 2365 bcf no_more_divesecs ; =1: do no longer show seconds in dive mode
2180 bcf divemode_menu_active 2366 bcf divemode_menu_active
2181 clrf menupos1 2367 clrf menupos1
2182 clrf menupos2 ; Reset to zero (Zero=no premenu or simulator task) 2368 clrf menupos2 ; reset to zero (Zero=no pre-menu or simulator task)
2183 bsf sensors_agree ; init of sensors disagree warning system 2369 bsf sensors_agree ; init of sensors disagree warning system
2184 2370
2185 btfsc FLAG_ccr_mode 2371 bcf show_safety_stop ; =1: show the safety stop
2186 bra diveloop_boot_cc 2372 clrf safety_stop_countdown ; clear count-down
2187 btfsc FLAG_pscr_mode 2373
2188 bra diveloop_boot_cc 2374 clrf samplesecs ; timer for data logging
2189 rcall dive_boot_oc
2190 bra diveloop_boot_cont
2191
2192 diveloop_boot_cc:
2193 rcall dive_boot_cc
2194
2195 diveloop_boot_cont:
2196 ; Copy opt_dil_types into backup (For "lost gas" feature)
2197 movff opt_dil_type+0,opt_dil_type_backup+0 ; 0=Disabled, 1=First, 2=Normal
2198 movff opt_dil_type+1,opt_dil_type_backup+1 ; 0=Disabled, 1=First, 2=Normal
2199 movff opt_dil_type+2,opt_dil_type_backup+2 ; 0=Disabled, 1=First, 2=Normal
2200 movff opt_dil_type+3,opt_dil_type_backup+3 ; 0=Disabled, 1=First, 2=Normal
2201 movff opt_dil_type+4,opt_dil_type_backup+4 ; 0=Disabled, 1=First, 2=Normal
2202 ; Copy opt_gas_types into backup (For "lost gas" feature)
2203 movff opt_gas_type+0,opt_gas_type_backup+0 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2204 movff opt_gas_type+1,opt_gas_type_backup+1 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2205 movff opt_gas_type+2,opt_gas_type_backup+2 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2206 movff opt_gas_type+3,opt_gas_type_backup+3 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2207 movff opt_gas_type+4,opt_gas_type_backup+4 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2208 ; Also copy change depths into backup (For "lost gas" feature)
2209 movff char_I_dil_change+0,opt_dil_change_backup+0 ; Gas change depths Diluents
2210 movff char_I_dil_change+1,opt_dil_change_backup+1 ; Gas change depths Diluents
2211 movff char_I_dil_change+2,opt_dil_change_backup+2 ; Gas change depths Diluents
2212 movff char_I_dil_change+3,opt_dil_change_backup+3 ; Gas change depths Diluents
2213 movff char_I_dil_change+4,opt_dil_change_backup+4 ; Gas change depths Diluents
2214 ; Also copy change depths into backup (For "lost gas" feature)
2215 movff opt_OC_bail_gas_change+0,opt_OC_bail_gas_change_backup+0; Gas change depths OC/Bailout
2216 movff opt_OC_bail_gas_change+1,opt_OC_bail_gas_change_backup+1; Gas change depths OC/Bailout
2217 movff opt_OC_bail_gas_change+2,opt_OC_bail_gas_change_backup+2; Gas change depths OC/Bailout
2218 movff opt_OC_bail_gas_change+3,opt_OC_bail_gas_change_backup+3; Gas change depths OC/Bailout
2219 movff opt_OC_bail_gas_change+4,opt_OC_bail_gas_change_backup+4; Gas change depths OC/Bailout
2220
2221 clrf WREG
2222 movff WREG,better_gas_number ; clear better gas register
2223
2224 bcf show_safety_stop ; =1: Show the safety stop
2225 clrf safety_stop_countdown ; Clear count-down
2226
2227 clrf samplesecs
2228 clrf apnoe_timeout_counter ; timeout in minutes 2375 clrf apnoe_timeout_counter ; timeout in minutes
2229 clrf timeout_counter1+0 ; takes care of the timeout (low byte) 2376 clrf timeout_counter1+0 ; takes care of the timeout (low byte)
2230 clrf timeout_counter1+1 ; takes care of the timeout (high byte) 2377 clrf timeout_counter1+1 ; takes care of the timeout (high byte)
2231 clrf AlarmType ; Clear all alarms 2378 clrf AlarmType ; Clear all alarms
2232 bcf event_occured ; clear flag 2379 bcf event_occured ; clear flag
2233 clrf average_depth_hold_total+0 2380 clrf average_divesecs_total+0 ; clear non-resettable time accumulator
2381 clrf average_divesecs_total+1
2382 clrf average_depth_hold_total+0 ; clear non-resettable average depth
2234 clrf average_depth_hold_total+1 2383 clrf average_depth_hold_total+1
2235 clrf average_depth_hold_total+2 2384 clrf average_depth_hold_total+2
2236 clrf average_depth_hold_total+3 ; Clear Non-Resettable Average 2385 clrf average_depth_hold_total+3
2237 rcall reset_average1 ; Reset the resettable average depth 2386 call reset_average ; reset the resettable average depth
2238 bcf decostop_active 2387
2239 bcf better_gas_available ; =1: A better gas is available and a gas change is advised in divemode 2388 IFDEF _rx_functions
2240 call ghostwriter_short_header ; Write short header with divenumber into profile memory 2389 btfss FLAG_tr_enabled ; TR functions enabled?
2390 bra diveloop_boot_0 ; NO - skip TR function initialization
2391 ; YES - initialize TR function variables
2392 banksel int_O_sac_rate
2393 clrf int_O_sac_rate+0 ; clear low byte of SAC rate
2394 clrf int_O_pressure_need+0 ; clear low byte of 1st pressure need value
2395 clrf int_O_pressure_need+2 ; clear low byte of 2nd pressure need value
2396 banksel int_IO_pressure_value
2397 clrf int_IO_pressure_value+0 ; clear low byte of 1st pressure reading value
2398 clrf int_IO_pressure_value+2 ; clear low byte of 2nd pressure reading value
2399 clrf int_I_pressure_drop+0 ; clear low byte of 1st pressure drop value
2400 clrf int_I_pressure_drop+2 ; clear low byte of 2nd pressure drop value
2401 clrf char_I_pressure_gas+0 ; clear gas selection of 1st pressure reading
2402 clrf char_I_pressure_gas+1 ; clear gas selection of 2nd pressure reading
2403 clrf char_I_pressure_age+0 ; clear age of 1st pressure reading
2404 clrf char_I_pressure_age+1 ; clear age of 2nd pressure reading
2405 clrf char_I_pressure_stat+0 ; clear status of 1st pressure reading
2406 clrf char_I_pressure_stat+1 ; clear status of 2nd pressure reading
2407 clrf WREG ; clear WREG
2408 bsf WREG,int_not_avail_flag ; set WREG to coding for integer numbers -> data not available
2409 banksel int_O_sac_rate
2410 movwf int_O_sac_rate+1 ; copy to high byte of SAC rate
2411 movwf int_O_pressure_need+1 ; copy to high byte of 1st pressure need value
2412 movwf int_O_pressure_need+3 ; copy to high byte of 1st pressure need value
2413 banksel int_IO_pressure_value
2414 movwf int_IO_pressure_value+1 ; copy to high byte of 1st pressure reading value
2415 movwf int_IO_pressure_value+3 ; copy to high byte of 2nd pressure reading value
2416 movwf int_I_pressure_drop+1 ; copy to high byte of 1st pressure drop value
2417 movwf int_I_pressure_drop+3 ; copy to high byte of 1st pressure drop value
2418 banksel gas__last_1st ; select bank with vars for pressure drop calculation
2419 setf gas__last_1st ; invalidate last gas of 1st reading
2420 setf gas__last_2nd ; invalidate last gas of 2nd reading
2421 banksel common ; back to bank common
2422 ENDIF
2423
2424 diveloop_boot_0:
2425 bcf decostop_active ; clear flag for being in deco
2426 setf best_gas_number ; initialize best gas as not computed yet (255)
2427 setf best_dil_number ; initialize best diluent as not computed yet (255)
2428 bcf better_gas_available ; =1: a better gas is available and a gas change is advised
2429 bcf better_dil_available ; =1: a better diluent is available and a gas change is advised
2430
2431 rcall dive_boot_oc_bail ; basic settings required for all modes
2432
2433 btfsc FLAG_oc_mode ; in OC mode?
2434 rcall dive_boot_oc ; YES - add OC mode settings
2435
2436 btfsc FLAG_ccr_mode ; in CCR mode?
2437 rcall dive_boot_cc ; YES - add CC mode settings
2438 btfsc FLAG_ccr_mode ; in CCR mode?
2439 rcall dive_boot_cc_part2 ; YES - add CC sensor and SP settings
2440
2441 btfsc FLAG_pscr_mode ; in pSCR mode?
2442 rcall dive_boot_cc ; YES - add CC mode settings
2443 btfsc FLAG_pscr_mode ; in pSCR mode?
2444 rcall dive_boot_cc_part2 ; YES - add CC sensor and SP settings
2445
2446 call ghostwriter_short_header ; write short header with dive number into profile memory
2241 2447
2242 btfsc simulatormode_active 2448 btfsc simulatormode_active
2243 bra diveloop_boot_1 2449 bra diveloop_boot_1
2244 ; Normal mode = Surface pressure is the pressure 30mn before dive. 2450
2245 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ;copy surfacepressure to deco routine 2451 ; normal mode = surface pressure is the pressure 30 minutes before dive
2246 SAFE_2BYTE_COPY last_surfpressure_30min, last_surfpressure ;copy surfacepressure to last_surfpressure for correct depth 2452 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ;copy surface pressure to deco routine
2453 SAFE_2BYTE_COPY last_surfpressure_30min, last_surfpressure ;copy surface pressure to last_surfpressure for correct depth
2247 bra diveloop_boot_2 2454 bra diveloop_boot_2
2248 2455
2249 diveloop_boot_1: 2456 diveloop_boot_1:
2250 ; Simulator mode: Surface pressure is 1bar. 2457 ; simulator mode: set surface pressure to 1 bar because simulated depths are also based on 1 bar surface pressure
2251 movlw LOW .1000 2458 movlw LOW .1000
2252 movff WREG,int_I_pres_surface+0 ; LOW copy surface pressure to deco routine 2459 movff WREG,int_I_pres_surface+0 ; LOW copy surface pressure to deco routine
2253 movlw HIGH .1000 2460 movlw HIGH .1000
2254 movff WREG,int_I_pres_surface+1 ; HIGH copy surface pressure to deco routine 2461 movff WREG,int_I_pres_surface+1 ; HIGH copy surface pressure to deco routine
2255 2462
2256 diveloop_boot_2: 2463 diveloop_boot_2:
2257 SAFE_2BYTE_COPY temperature,minimum_temperature ; Reset Min-Temp registers 2464 SAFE_2BYTE_COPY temperature,minimum_temperature ; reset minimum temperature registers
2258 2465
2259 call init_recording_params ; set up all the divisors 2466 call init_recording_params ; set up all the divisors
2260 2467
2261 bsf ccr_diluent_setup ; For CCR mode (Required to have better gas working) 2468 bsf FLAG_diluent_setup ; for CCR mode (required to have better gas working)
2262 btfsc FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active 2469 btfsc FLAG_ccr_mode ; =1: CCR mode (fixed ppO2 or Sensor) active
2263 bra divemode_boot2 2470 bra diveloop_boot_3
2264 btfsc FLAG_pscr_mode 2471 btfsc FLAG_pscr_mode
2265 bra divemode_boot2 2472 bra diveloop_boot_3
2266 bcf ccr_diluent_setup ; For OC mode (Required to have better gas working) 2473 bcf FLAG_diluent_setup ; for OC mode (required to have better gas working)
2267 2474
2268 divemode_boot2: 2475 diveloop_boot_3:
2269 bcf LEDg ; switch off green LED / release reset to RX circuitry 2476 bcf LEDg ; switch off green LED / release reset to RX circuitry
2270 bcf LEDr ; switch off red LED 2477 bcf LEDr ; switch off red LED
2271 bcf realdive 2478 bcf realdive
2272 btfss simulatormode_active ; do not disable in simulator mode! 2479 btfss simulatormode_active ; in simulator mode?
2273 call disable_rs232 ; Disable RS232 2480 call disable_rs232 ; NO - disable RS232
2274 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) 2481
2275 call enable_rs232 ; Also sets to speed_normal ... 2482 IFDEF _screendump
2276 ; Reset divetime seconds 2483 btfsc enable_screen_dumps ; =1: ignore vin_usb, wait for "l" command (screen dump)
2277 movlw .2 ; Start at 2seconds 2484 call enable_rs232 ; also sets to speed_normal
2278 movwf total_divetime_seconds+0 2485 ENDIF
2486
2487 ; reset dive time seconds
2488 ; movlw .2 ; start at 2 seconds
2489 ; movwf total_divetime_seconds+0
2490 ; clrf total_divetime_seconds+1
2491 ; movwf divesecs
2492 ; movwf apnoe_secs
2493 ; bsf divemode2 ; displayed dive time is running (dive time starts HERE)
2494
2495 ; clear the timers (start dive times at zero)
2496 clrf total_divetime_seconds+0
2279 clrf total_divetime_seconds+1 2497 clrf total_divetime_seconds+1
2280 movwf divesecs 2498 clrf divesecs
2281 movwf apnoe_secs 2499 clrf divemins+0
2282 bsf divemode2 ; displayed divetime is running (Divetime starts HERE) 2500 clrf divemins+1
2283 return ; Done with divemode boot 2501 clrf apnoe_secs
2284 2502 clrf apnoe_mins
2503
2504 ; divemode2 flag will be set by pressure & timeout evaluation in function set_dive_modes
2505
2506 return ; done with dive mode boot
2507
2508
2509 ;=============================================================================
2285 2510
2286 divemode_check_for_warnings: 2511 divemode_check_for_warnings:
2287 movlw .1 ; One warning at a time in alt. layout mode 2512 movlw .1 ; one message at a time in alternative layout
2288 btfss alternative_divelayout 2513 btfss alternative_divelayout
2289 movlw .2 ; Two warnings at a time in default layout mode 2514 movlw .2 ; two messages at a time in default layout
2290 cpfsgt warning_counter ; only one (or two) warnings active? 2515 cpfsgt message_counter ; only one (or two) messages active?
2291 bra divemode_check_for_warnings1 ; Yes, update every second 2516 bra divemode_check_for_warnings1; YES - update every second
2292 2517
2293 btfss secs,0 ; Every two seconds... 2518 btfss secs,0 ; every two seconds...
2294 return 2519 return
2295 btfss secs,1 ; Every four seconds... 2520 btfss secs,1 ; every four seconds...
2296 return 2521 return
2297 2522
2298 divemode_check_for_warnings1: 2523 divemode_check_for_warnings1:
2299 bcf warning_active ; Clear flag 2524 bcf message_advice ; clear flag for messages of level advice
2300 clrf warning_counter ; Clear counter 2525 bcf message_attention ; clear flag for messages of level attention
2301 2526 bcf message_warning ; clear flag for messages of level warning
2302 ; warnings sorted by severity, highest severity first 2527 clrf message_counter ; clear message counter
2303 2528
2304 ; Warnings for all modes 2529 ; messages sorted by severity: highest severity warnings first, then attentions, advices and last info
2305 call check_warn_battery ; Check if the battery level should be displayed/warned 2530
2306 call check_divetimeout ; Not actually a warning. Check and show the divemode timeout 2531 ; warnings for all modes
2307 2532 call check_warn_battery ; check if the battery level should be displayed/warned
2308 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode 2533 call check_divetimeout ; check and show the dive mode timeout (not actually a warning)
2309 bra divemode_check_for_warnings2 2534
2310 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode 2535 btfsc FLAG_apnoe_mode ; in Apnoe mode?
2311 bra divemode_check_for_warnings2 2536 bra divemode_check_for_warnings2; YES
2312 2537 btfsc FLAG_gauge_mode ; in gauge mode?
2313 ; Warnings only in deco modes 2538 bra divemode_check_for_warnings2; YES
2539
2540 ; warnings applicable only in deco modes
2314 rcall check_ppO2 ; check ppO2 and displays warning, if required 2541 rcall check_ppO2 ; check ppO2 and displays warning, if required
2315 2542
2316 btfss sensors_agree ; are the sensor values within the threshold range? 2543 btfss sensors_agree ; are the sensor values within the threshold range?
2317 rcall check_warn_sensors_disagree ; NO - further evaluate 2544 rcall check_warn_sensors_disagree ; NO - further evaluate
2318 btfsc sensors_agree ; are the sensor values within the threshold range? 2545 btfsc sensors_agree ; are the sensor values within the threshold range?
2319 bcf sensor_warning ; YES - revoke memorized sensor warning 2546 bcf sensor_warning ; YES - revoke memorized sensor warning
2320 2547
2321 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings 2548 rcall check_outside ; check of ZHL16 model violation
2322 btfsc WREG,outside_warning_lock ; are we outside of the ZH-L16 model?
2323 rcall warn_outside ; YES
2324 2549
2325 rcall check_IBCD ; check for IBCD attention or warning 2550 rcall check_IBCD ; check for IBCD attention or warning
2326 2551
2327 btfsc decostop_active ; In deco mode? 2552 rcall check_OC_gas_avail ; check if a breathable OC gas is available
2328 rcall check_and_store_gf_violation; Yes, sets warnings, if required 2553
2329 2554 btfsc decostop_active ; in deco mode?
2330 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings 2555 rcall check_and_store_gf_violation; YES - sets warnings, if required
2331 btfsc WREG,mbubble_warning_lock ; do we have a microbubbles warning? 2556
2332 rcall warn_mbubbles ; YES 2557 rcall check_mbubbles ; check for micro bubbles
2333 2558
2334 rcall check_cns_violation ; Check CNS value and display it, if required 2559 rcall check_cns_violation ; Check CNS value and display it, if required
2335 2560
2336 ;btfsc decostop_active ; In deco mode? 2561 rcall check_gas_needs_ascent ; show gas needs warning if any gas need for ascent is > threshold
2337 rcall check_gas_needs ; show gas needs warning if any gas need is > threshold 2562
2338 2563 rcall check_eod_cns_violation ; check CNS values for end-of-dive and display warning, if required
2339 rcall check_eod_cns_violation ; Check CNS values for end-of-dive and display warning, if required 2564
2340 2565 rcall check_display_ftts ; show @+x time
2341 call TFT_display_ftts ; Show @+x time 2566
2342 2567 IFDEF _cave_mode
2343 btfsc use_agf ; In aGF mode? 2568 btfsc FLAG_cave_mode ; cave mode enabled?
2344 rcall warn_agf ; Yes, show a warning for it 2569 rcall check_cavemode ; YES - check cave mode status
2345 2570 ENDIF
2346 btfsc setpoint_fallback ; =1: Fallback to SP1 due to external O2 sensor failure 2571
2347 rcall warn_fallback ; Show the warning 2572 btfsc use_agf ; in aGF mode?
2573 rcall warn_agf ; YES - show memo
2574
2575 btfsc setpoint_fallback ; fallback to SP1 due to external O2 sensor failure?
2576 rcall warn_fallback ; YES - show a warning
2577
2578 btfsc better_dil_available ; is a better diluent available?
2579 rcall advice_gas_change ; YES - display an advice
2580 btfsc better_gas_available ; is a better gas available?
2581 rcall advice_gas_change ; YES - display an advice
2348 2582
2349 divemode_check_for_warnings2: 2583 divemode_check_for_warnings2:
2350 ; Display the warning icon? 2584 IFDEF _rx_functions
2351 btfsc warning_active ; Any warning active? 2585 btfss FLAG_tr_enabled ; TR functions enabled?
2352 bsf FLAG_TFT_divemode_warning ; Yes 2586 bra divemode_check_for_warnings3 ; NO - skip
2353 btfss warning_active ; Any warning active? 2587 call check_tr_functions ; YES - check transmitter functions
2354 bsf FLAG_TFT_divemode_warning_clear ; No, clear warning icon 2588 call check_tr_messages ; - check SAC attention and switch advice
2355 2589 ENDIF
2356 ; Setup warning_page number 2590
2357 incf warning_page,F 2591 divemode_check_for_warnings3:
2358 movf warning_page,W 2592 ; Display the attention or warning icon?
2593 btfsc message_advice ; any message of level advice?
2594 bsf FLAG_TFT_divemode_warning ; YES
2595 btfsc message_attention ; any message of level attention?
2596 bsf FLAG_TFT_divemode_warning ; YES
2597 btfsc message_warning ; any message of level warning?
2598 bsf FLAG_TFT_divemode_warning ; YES
2599 btfss FLAG_TFT_divemode_warning ; any message of above levels?
2600 bsf FLAG_TFT_divemode_warning_clear ; NO - clear warning icon
2601
2602 ; Setup message page number
2603 incf message_page,F
2604 movf message_page,W
2359 bcf STATUS,C 2605 bcf STATUS,C
2360 btfss alternative_divelayout 2606 btfss alternative_divelayout ; in alternative layout?
2361 rlcf warning_page,W ; *2 (But only in standard layout mode) 2607 rlcf message_page,W ; NO - *2
2362 cpfsgt warning_counter ; > warning_counter 2608 cpfsgt message_counter ; > message_counter?
2363 clrf warning_page ; No, clear 2609 clrf message_page ; NO - clear
2364 2610
2365 ; Clear both rows of warnings if there is nothing to show at all 2611 ; Clear both rows of messages if there is nothing to show at all
2366 tstfsz warning_counter ; any warnings? 2612 tstfsz message_counter ; any messages?
2367 bra divemode_check_for_warnings3 ; YES - look if second row needs to be cleared 2613 bra divemode_check_for_warnings4 ; YES - look if second row needs to be cleared
2368 bsf FLAG_TFT_dive_warning_text_clear ; Set flag 2614 bsf FLAG_TFT_dive_warning_text_clear; set flag
2369 return 2615 return
2370 divemode_check_for_warnings3: 2616
2371 2617 divemode_check_for_warnings4:
2372 2618 ; Clear 2nd row of messages if there is nothing to show (on this page)
2373 ; Clear 2nd row of warnings if there is nothing to show (on this page) 2619 btfss second_row_warning ; =1: the second row contains a warning
2374 btfss second_row_warning ; =1: The second row contains a warning 2620 bsf FLAG_TFT_dive_warning_text_clr2 ; set flag for 2nd row
2375 bsf FLAG_TFT_dive_warning_text_clr2 ; Set flag for 2nd row 2621 return ; done
2376 return ; Done.
2377 2622
2378 global check_warn_battery 2623 global check_warn_battery
2379 check_warn_battery: 2624 check_warn_battery:
2380 movff batt_percent,lo 2625 movff batt_percent,lo
2381 movlw battery_show_level+1 2626 movlw battery_show_level+1
2382 cpfslt lo 2627 cpfslt lo ; battery percentage ok?
2383 return ; No Display, no warning 2628 return ; YES - no display, no warning
2384 ; Display Battery, but warn? 2629 ; Display Battery, but warn?
2385 movff batt_percent,lo 2630 movff batt_percent,lo
2386 movlw color_code_battery_low+1 2631 movlw color_code_battery_low+1
2387 cpfsgt lo 2632 cpfsgt lo ; battery percent below warning threshold?
2388 bsf warning_active ; Set Warning flag 2633 bsf message_warning ; YES - set warning flag
2389 2634 btfsc alternative_divelayout ; in alternative layout?
2390 movlw .4 2635 bra check_warn_battery2 ; YES - show warning
2391 cpfseq menupos3 ; battery shown in Custom View 4? 2636 movlw index_clock_batt_surfpress ; NO - index of custom view clock, battery and surface pressure
2392 bra check_warn_battery2 ; No 2637 cpfseq menupos3 ; - battery shown in custom view?
2393 return ; Yes, do not show twice (in custom view and in warning area) 2638 bra check_warn_battery2 ; NO - show warning
2639 return ; YES - do not show twice (in custom view and in message area)
2394 check_warn_battery2: 2640 check_warn_battery2:
2395 incf warning_counter,F ; increase counter 2641 incf message_counter,F ; increase counter
2396 goto TFT_update_batt_percent_divemode ; Show percent (And return) 2642 goto TFT_update_batt_percent_divemode ; show percent (and return)
2397 2643
2398 check_divetimeout: 2644 check_divetimeout:
2399 btfsc divemode2 2645 btfsc divemode2 ; dive time running?
2400 return ; displayed divetime is not running 2646 return ; YES - do nothing
2401 incf warning_counter,F ; increase counter 2647 incf message_counter,F ; increase counter
2402 goto TFT_divetimeout ; Show timeout counter (and return) 2648 goto TFT_divetimeout ; show timeout counter (and return)
2403
2404 2649
2405 check_ppO2: 2650 check_ppO2:
2406 btfsc FLAG_ccr_mode ; are we in CCR mode? 2651 btfsc FLAG_oc_mode ; are we in OC mode?
2407 bra check_ppO2_loop ; YES 2652 bra check_ppO2_1 ; YES - continue with breathed gas
2408 btfsc FLAG_pscr_mode ; are we in pSCR mode? 2653 btfsc FLAG_bailout_mode ; NO - in bailout?
2409 bra check_ppO2_loop ; YES 2654 bra check_ppO2_1 ; YES - continue with breathed gas
2410 bra check_ppO2_oc_1 ; NO - neither CCR nor pSCR 2655 ; CCR / pSCR mode - checks on pure diluent
2411 check_ppO2_loop: 2656 movff int_O_pure_ppO2+0,lo ; get value and attention/warning flags for the pure diluent
2412 btfsc is_bailout ; in bailout? 2657 movff int_O_pure_ppO2+1,hi ;
2413 bra check_ppO2_oc_1 ; YES - continue with OC 2658 btfsc hi,int_warning_flag ; ppO2 of the pure diluent to low or high?
2414 movff int_O_pure_ppO2+1,hi ; NO - get upper part of int_O_pure_ppO2 2659 rcall check_ppO2_dw ; YES - show warning and return on next line
2415 btfsc hi,int_warning_flag ; ppO2 of the pure diluent to low or high? 2660 btfsc hi,int_attention_flag ; ppO2 of the pure diluent in attention state?
2416 rcall check_ppo2_display ; YES - show warning and return on next line 2661 rcall check_ppO2_da ; YES - show attention and return on next line
2417 btfsc hi,int_attention_flag ; ppO2 of the pure diluent close to setpoint? 2662 ; all modes - checks on breathed gas (OC or from loop)
2418 rcall check_ppo2_display ; YES - show warning and return on next line 2663 check_ppO2_1:
2419 bra check_ppO2_oc_2 ; skip attention threshold test on breathed ppO2 2664 movff int_O_breathed_ppO2+0,lo ; get value and attention/warning flags for the breathed gas
2420 check_ppO2_oc_1: 2665 movff int_O_breathed_ppO2+1,hi ; get warnings for breathed gas
2421 movff int_O_breathed_ppO2+1,WREG ; get upper part of int_O_breathed_ppO2 2666 btfsc hi,int_attention_flag ; breathed ppO2 in attention state (when in loop mode, no attention will be generated)?
2422 btfsc WREG,int_attention_flag ; breathed ppO2 just above attention threshold? 2667 bra check_ppo2_display_a ; YES - set attention flag and show ppO2
2423 bra check_ppo2_display ; YES - show ppO2 2668 btfsc hi,int_low_flag ; breathed ppO2 to low?
2424 check_ppO2_oc_2:
2425 movff int_O_breathed_ppO2+1,WREG ; get upper part of int_O_breathed_ppO2 (perhaps again)
2426 btfsc WREG,int_low_flag ; breathed ppO2 to low?
2427 bra check_ppO2_low ; YES - record the warning and show ppO2 2669 bra check_ppO2_low ; YES - record the warning and show ppO2
2428 btfsc WREG,int_high_flag ; breathed ppO2 to high? 2670 btfsc hi,int_high_flag ; breathed ppO2 to high?
2429 bra check_ppO2_high ; YES - record the warning and show ppO2 2671 bra check_ppO2_high ; YES - record the warning and show ppO2
2430 TSTOSS opt_showppo2 ; show ppO2 anyhow? (0 = no, 1 = show always) 2672 TSTOSS opt_showppo2 ; show ppO2 anyhow? (0 = no, 1 = show always)
2431 return ; NO - no warnings, no show 2673 return ; NO - no warnings, no show - done
2432 bra check_ppo2_display ; YES - just show ppO2 2674 bra check_ppO2_common_2 ; YES - but only when in OC or bailout...
2433 check_ppO2_low: 2675 check_ppO2_low:
2434 movlw d'4' ; set type of alarm (ppO2 low) 2676 movlw d'4' ; set type of alarm (ppO2 low)
2435 bra check_ppO2_common ; continue with common part 2677 bra check_ppO2_common ; continue with common part
2436 check_ppO2_high: 2678 check_ppO2_high:
2437 movlw d'5' ; set type of alarm (ppO2 high) 2679 movlw d'5' ; set type of alarm (ppO2 high)
2438 check_ppO2_common: 2680 check_ppO2_common:
2439 movwf AlarmType ; copy alarm type to alarm register 2681 movwf AlarmType ; copy alarm type to alarm register
2440 bsf event_occured ; set event flag 2682 bsf event_occured ; set event flag
2441 bsf warning_active ; set warning flag 2683 bsf message_warning ; show warning sign
2442 btfsc is_bailout ; are we in bailout? 2684 check_ppO2_common_2:
2443 bra check_ppo2_display ; YES - skip CCR/pSCR checks 2685 btfsc FLAG_oc_mode ; are we in OC mode?
2444 btfsc FLAG_ccr_mode ; are we in CCR mode? 2686 bra check_ppo2_display ; YES
2445 return ; YES - no extra warning required 2687 btfsc FLAG_bailout_mode ; are we in bailout mode?
2446 btfsc FLAG_pscr_mode ; are we in pSCR mode? 2688 bra check_ppo2_display ; YES
2447 return ; YES - no extra warning required 2689 return ; NO - in loop mode, ppO2 is already shown via setpoint display
2448 check_ppo2_display: ; display warning if ppO2 is not already shown in custom view 2690 check_ppo2_display_a:
2449 movlw .9 2691 bsf message_attention ; show attention sign
2450 cpfseq menupos3 ; ppO2 shown in Custom View 9? 2692 check_ppo2_display:
2451 bra check_ppO2_a ; No 2693 btfsc alternative_divelayout ; in alternative layout?
2452 return ; Yes, do not show twice (in custom view and in warning area) 2694 bra check_ppO2_d ; YES - show warning
2453 check_ppO2_a: 2695 movlw index_ppo2_ead_end_cns ; NO - index of custom view ppO2, EAD/END and CNS)
2454 movlw .11 2696 cpfseq menupos3 ; ppO2 shown?
2455 cpfseq menupos3 ; ppO2 shown in Custom View 11? 2697 bra check_ppO2_b ; NO
2456 bra check_ppO2_b ; No 2698 return ; YES - do not show twice (in custom view and in warning area)
2457 return ; Yes, do not show twice (in custom view and in warning area)
2458 check_ppO2_b: 2699 check_ppO2_b:
2459 movlw .12 2700 movlw index_pscr_info ; index of custom view with pSCR data
2460 cpfseq menupos3 ; ppO2 shown in Custom View 12? 2701 cpfseq menupos3 ; ppO2 shown?
2461 bra check_ppO2_c ; No 2702 bra check_ppO2_d ; NO - show warning
2462 return ; Yes, do not show twice (in custom view and in warning area) 2703 return ; YES - do not show twice (in custom view and in warning area)
2463 check_ppO2_c: 2704 check_ppO2_dw:
2464 movlw .10 2705 bsf message_warning ; show warning sign
2465 cpfseq menupos3 ; ppO2 shown in Custom View 10? 2706 check_ppO2_da:
2466 bra check_ppO2_d ; No 2707 bsf message_attention ; show attention sign (no problem if a warning sign is set as well, as it will take priority)
2467 return ; Yes, do not show twice (in custom view and in warning area)
2468 check_ppO2_d: 2708 check_ppO2_d:
2469 incf warning_counter,F ; increase counter 2709 incf message_counter,F ; increase counter
2470 goto TFT_display_ppo2 ; show breathed gas or diluent ppO2 warning (and return) 2710 goto TFT_display_ppo2_warning ; show breathed gas or diluent ppO2 warning (and return)
2711
2712
2713 check_display_ftts:
2714 movff char_I_extra_time,lo ; get extra time
2715 tstfsz lo ; extra time > 0 ?
2716 bra check_display_ftts_1 ; YES - continue checking bailout condition
2717 return ; NO - done
2718 check_display_ftts_1:
2719 btfsc FLAG_bailout_mode ; in bailout mode?
2720 return ; YES - in bailout no fTTS will be computed, so nothing to display
2721 incf message_counter,F ; NO - increase counter
2722 goto TFT_display_ftts ; - show @+x time
2471 2723
2472 2724
2473 global check_cns_violation 2725 global check_cns_violation
2474 check_cns_violation: 2726 check_cns_violation:
2475 ; Check if CNS should be displayed 2727 ; Check if CNS should be displayed
2476 movff int_O_CNS_fraction+1,WREG ; get high byte 2728 movff int_O_CNS_fraction+1,WREG ; get high byte
2477 btfsc WREG,int_warning_flag ; warning flag set? 2729 btfsc WREG,int_warning_flag ; warning flag set?
2478 bra check_cns_violation2 ; Yes - issue warning 2730 bra check_cns_violation_1 ; YES - issue warning
2479 btfsc WREG,int_attention_flag ; attention flag set? 2731 btfsc WREG,int_attention_flag ; NO - attention flag set?
2480 bra display_cns_violation ; YES - just display CNS 2732 bra check_cns_violation_2 ; YES - issue attention
2481 return ; No - no display, no warning 2733 return ; NO - done
2482 check_cns_violation2: 2734 check_cns_violation_1:
2483 bsf warning_active ; Set Warning flag 2735 bsf message_warning ; show warning sign
2484 display_cns_violation: ; Show CNS if not shown in the custom view 2736 check_cns_violation_2:
2485 movlw .11 2737 bsf message_attention ; show attention sign
2486 cpfseq menupos3 ; CNS shown in Custom View? 2738 btfsc alternative_divelayout ; in alternative layout?
2487 bra display_cns_violation2 ; No 2739 bra check_cns_violation_4 ; YES - show attention
2488 return ; Yes, do not show twice (in custom view and in warning area) 2740 movlw index_ppo2_ead_end_cns ; NO - index of custom view ppO2, EAD/END and CNS
2489 display_cns_violation2: 2741 cpfseq menupos3 ; - CNS shown?
2490 movlw .8 2742 bra check_cns_violation_3 ; NO
2491 cpfseq menupos3 ; CNS shown through Custom View 8 right now? 2743 return ; YES - do not show twice (in custom view and in warning area)
2492 bra display_cns_violation3 ; No 2744 check_cns_violation_3:
2493 return ; Yes, do not show twice (in custom view and in warning area) 2745 movlw index_CNS ; index of custom view with CNS values
2494 display_cns_violation3: 2746 cpfseq menupos3 ; CNS shown?
2495 incf warning_counter,F ; increase counter 2747 bra check_cns_violation_4 ; NO
2496 goto TFT_display_cns ; Show CNS (and return) 2748 return ; YES - do not show twice (in custom view and in warning area)
2749 check_cns_violation_4:
2750 incf message_counter,F ; increase counter
2751 goto TFT_display_cns ; show CNS (and return)
2497 2752
2498 2753
2499 global check_eod_cns_violation ; check end-of-dive CNS values 2754 global check_eod_cns_violation ; check end-of-dive CNS values
2500 check_eod_cns_violation: 2755 check_eod_cns_violation:
2501 movff int_O_CNS_fraction+1,WREG ; get high-byte of current CNS value 2756 movff int_O_CNS_fraction+1,WREG ; get high-byte of current CNS value
2502 btfsc WREG,int_warning_flag ; current CNS value in warning state? 2757 btfsc WREG,int_warning_flag ; current CNS value in warning state?
2503 return ; YES - inhibit eod warning if current CNS is already in warning 2758 return ; YES - inhibit end-of-dive warning if current CNS is already in warning
2504 movff int_O_normal_CNS_fraction+1,WREG 2759 movff int_O_normal_CNS_fraction+1,WREG
2505 btfsc WREG,int_invalid_flag ; flag for invalid value set? 2760 btfsc WREG,int_invalid_flag ; flag for invalid value set?
2506 bra check_eod_cns_violation1 ; YES - continue with checking the other CNS value 2761 bra check_eod_cns_violation1 ; YES - continue with checking the other CNS value
2507 btfsc WREG,int_warning_flag ; NO - flag for warning set? 2762 btfsc WREG,int_warning_flag ; NO - flag for warning set?
2508 bra check_eod_cns_violation2 ; YES - issue warning 2763 bra check_eod_cns_violation2 ; YES - issue warning
2509 check_eod_cns_violation1: ; NO - continue with checking the other CNS value 2764 check_eod_cns_violation1: ; NO - continue with checking the other CNS value
2510 movff int_O_alternate_CNS_fraction+1,WREG 2765 movff int_O_alternate_CNS_fraction+1,WREG
2511 btfsc WREG,int_invalid_flag ; flag for invalid value set? 2766 btfsc WREG,int_invalid_flag ; flag for invalid value set?
2512 return ; YES - done with CNS checking 2767 return ; YES - done with CNS checking
2513 btfsc WREG,int_warning_flag ; NO - flag for warning set? 2768 btfsc WREG,int_warning_flag ; NO - flag for warning set?
2514 bra check_eod_cns_violation2 ; Yes - issue warning 2769 bra check_eod_cns_violation2 ; YES - issue warning
2515 return ; NO - done with CNS checking 2770 return ; NO - done with CNS checking
2516 check_eod_cns_violation2: ; YES - issue warning 2771 check_eod_cns_violation2: ; issue warning (actually only on attention level)
2517 bsf warning_active ; set Warning flag 2772 bsf message_attention ; show attention sign
2518 movlw .8 ; issue textual warning if CNS values are not shown in the custom view right now 2773 btfsc alternative_divelayout ; in alternative layout?
2519 cpfseq menupos3 ; CNS values shown through Custom View 8 right now? 2774 bra display_eod_cns_violation ; YES - show warning
2520 bra display_eod_cns_violation ; NO - issue textual warning 2775 movlw index_CNS ; NO - index of custom view with CNS values
2521 return ; YES - do not show twice (in custom view and in warning area) 2776 cpfseq menupos3 ; - CNS values shown?
2777 bra display_eod_cns_violation ; NO - issue textual warning
2778 return ; YES - do not show twice (in custom view and in warning area)
2522 display_eod_cns_violation: 2779 display_eod_cns_violation:
2523 incf warning_counter,F ; increase counter 2780 incf message_counter,F ; increase counter
2524 goto TFT_display_eod_cns ; issue CNS at end-of-dive warning (and return) 2781 goto TFT_display_eod_cns ; issue CNS at end-of-dive warning (and return)
2525 2782
2526 2783
2527 global check_and_store_gf_violation 2784 global check_and_store_gf_violation
2528 check_and_store_gf_violation: 2785 check_and_store_gf_violation:
2530 btfss WREG,int_warning_flag ; check if the warning flag is set 2787 btfss WREG,int_warning_flag ; check if the warning flag is set
2531 bra check_and_store_gf_violation2 ; NO - continue with checking for attention flag 2788 bra check_and_store_gf_violation2 ; NO - continue with checking for attention flag
2532 movlw d'2' ; YES - set type of alarm 2789 movlw d'2' ; YES - set type of alarm
2533 movwf AlarmType ; copy to alarm register 2790 movwf AlarmType ; copy to alarm register
2534 bsf event_occured ; set event flag 2791 bsf event_occured ; set event flag
2535 bsf warning_active ; set warning flag 2792 bsf message_warning ; set warning flag
2536 bra check_and_store_gf_violation3 ; show gf warning 2793 bra check_and_store_gf_violation3 ; show gf warning
2537 check_and_store_gf_violation2: 2794 check_and_store_gf_violation2:
2538 btfsc WREG,int_attention_flag ; check if the attention flag is set 2795 btfsc WREG,int_attention_flag ; check if the attention flag is set
2539 bra check_and_store_gf_violation3 ; YES - show gf 2796 bra check_and_store_gf_violation3 ; YES - show gf
2540 TSTOSS opt_enable_IBCD ; NO - IBCD warning activated? 2797 TSTOSS opt_enable_IBCD ; NO - IBCD warning activated?
2541 bra check_and_store_gf_violation4 ; NO - continue checking of deco info 2798 bra check_and_store_gf_violation4 ; NO - continue checking of deco info
2542 movff char_O_deco_warnings,WREG ; YES - get the deco warnings vector 2799 movff char_O_deco_warnings,WREG ; YES - get the deco warnings vector
2543 btfss WREG,IBCD_warning ; is the IBCD warning flag set? 2800 btfss WREG,IBCD_warning ; is the IBCD warning flag set?
2544 bra check_and_store_gf_violation4 ; NO - continue checking for deco info 2801 bra check_and_store_gf_violation4 ; NO - continue checking for deco info
2545 check_and_store_gf_violation3: ; YES - show gf 2802 check_and_store_gf_violation3: ; YES - show gf
2546 bsf warning_active ; set Warning flag 2803 bsf message_attention ; show attention sign
2547 incf warning_counter,F ; increase counter 2804 incf message_counter,F ; increase counter
2548 goto TFT_warning_gf ; show GF (and return) 2805 goto TFT_warning_gf ; show GF (and return)
2549 check_and_store_gf_violation4: ; check for deco info 2806 check_and_store_gf_violation4: ; check for deco info
2550 btfss divemode ; in divemode? 2807 btfss divemode ; in dive mode?
2551 return ; NO - done, return 2808 return ; NO - done, return
2552 movff char_O_deco_warnings,WREG ; YES - get the deco warnings vector 2809 btfsc FLAG_bailout_mode ; YES - in bailout mode?
2553 btfss WREG,deco_flag ; check if the deco flag is set 2810 return ; YES - done, return (deco_decreasing flag is not updated when in bailout mode)
2554 return ; NO - all done, return 2811 movff char_O_deco_info,WREG ; NO - get the deco info vector
2555 incf warning_counter,F ; YES - increase counter 2812 btfss WREG,deco_decreasing ; check if the deco_decreasing flag is set
2556 goto TFT_info_deco ; show deco info 2813 return ; NO - done, return
2557 2814 incf message_counter,F ; YES - increase counter
2558 2815 goto TFT_info_deco ; - show deco info
2559 warn_outside: 2816
2560 incf warning_counter,F ; increase counter 2817
2561 bsf warning_active ; Set Warning flag 2818 check_outside:
2562 goto TFT_warning_outside ; show outside warning (and return) 2819 movff char_O_deco_warnings,WREG ; bank-safe copy of deco warnings
2563 2820 btfss WREG,outside_warning_lock ; are we outside of the ZH-L16 model?
2564 2821 return ; NO - done
2565 global warn_mbubbles 2822 incf message_counter,F ; YES - increase counter
2566 warn_mbubbles: 2823 bsf message_attention ; - show attention sign
2567 incf warning_counter,F ; increase counter 2824 btfsc WREG,outside_warning ; - are we outside the ZH-L16 model right now (-> warning)?
2568 bsf warning_active ; Set Warning flag 2825 bsf message_warning ; - set warning flag
2569 goto TFT_warning_mbubbles ; show microbubbles warning (and return) 2826 goto TFT_warning_outside ; - show outside-ZHL-model warning/attention (and return)
2570 2827
2828
2829 global check_mbubbles
2830 check_mbubbles:
2831 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings
2832 btfsc WREG,mbubble_warning ; are we in micro bubbling zone right now?
2833 bra check_mbubbles_warn ; YES
2834 btfss WREG,mbubble_warning_lock ; were we in micro bubbling zone?
2835 return ; NO - done
2836 check_mbubble_att ; YES - attention level
2837 incf message_counter,F ; increase counter
2838 bsf message_attention ; show attention sign
2839 goto TFT_warning_mbubbles ; show micro bubble attention (and return) - TFT_warning_mbubbles switches by itself between attention and warning
2840 check_mbubbles_warn: ; locked micro bubbles - warning level if at issue, attention level if locked
2841 incf message_counter,F ; increase counter
2842 bsf message_warning ; set warning flag
2843 goto TFT_warning_mbubbles ; show micro bubbles warning (and return)
2844
2845 IFDEF _cave_mode
2846 check_cavemode:
2847 incf message_counter,F ; increase counter
2848 btfsc FLAG_dive_turned ; dive turned?
2849 goto TFT_info_dive_turned ; YES - show info that dive is turned
2850 btfsc FLAG_cave_mode_shutdown ; NO - has cave mode shut down?
2851 goto TFT_warn_cave_shutdown ; YES - show that cave mode has shut down
2852 goto TFT_info_cave_mode ; NO - show that cave mode is active
2853 ENDIF
2854
2571 warn_agf: 2855 warn_agf:
2572 incf warning_counter,F ; increase counter 2856 incf message_counter,F ; increase counter
2573 goto TFT_warning_agf ; Show aGF warning (and return) 2857 goto TFT_warning_agf ; show aGF warning (and return)
2574 2858
2575 warn_fallback: 2859 warn_fallback:
2576 incf warning_counter,F ; increase counter 2860 incf message_counter,F ; increase counter
2577 bsf warning_active ; Set Warning flag 2861 bsf message_warning ; set warning flag
2578 goto TFT_warning_fallback ; Show fallback warning (and return) 2862 goto TFT_warning_fallback ; show fallback warning (and return)
2579 2863
2580 2864
2581 check_gas_needs: 2865 IFDEF _rx_functions
2582 banksel int_O_tank_pres_need 2866
2583 movf int_O_tank_pres_need+1,w ; get HIGH(pres need of 1st tank) 2867 check_tr_messages:
2584 iorwf int_O_tank_pres_need+3,w ; inclusive or with HIGH(pres need of 2nd tank) 2868 movff int_O_sac_rate+1,WREG ; bank-safe copy of current SAC rate
2585 iorwf int_O_tank_pres_need+5,w ; inclusive or with HIGH(pres need of 3rd tank) 2869 btfss WREG,int_attention_flag ; attention flag set?
2586 iorwf int_O_tank_pres_need+7,w ; inclusive or with HIGH(pres need of 4th tank) 2870 bra check_tr_messages2 ; NO - skip
2587 iorwf int_O_tank_pres_need+9,w ; inclusive or with HIGH(pres need of 5th tank) 2871 btfsc WREG,int_not_avail_flag ; SAC rate available?
2872 bra check_tr_messages2 ; NO - continue with swap advice
2873 bsf message_attention ; YES - show attention sign
2874 btfsc alternative_divelayout ; - in alternative layout?
2875 bra check_tr_messages1 ; YES - show attention message
2876 movlw index_pressures_SAC ; NO - index of custom view with SAC rate
2877 cpfseq menupos3 ; - SAC rate shown right now?
2878 bra check_tr_messages1 ; NO - show attention message
2879 bra check_tr_messages2 ; YES - do not show twice, continue with swap advice
2880 check_tr_messages1:
2881 incf message_counter,F ; increase counter
2882 call TFT_attention_sac ; show SAC attention
2883 check_tr_messages2:
2884 movff char_O_deco_info,WREG ; bank-safe copy of deco info vector
2885 btfss WREG,ind_double_switch ; swap tank flag set?
2886 return ; NO
2887 incf message_counter,F ; YES - increase counter
2888 bsf message_advice ; - show advice sign
2889 goto TFT_advice_switch ; - show swap advice
2890
2891
2892 #DEFINE show_custview ul,0 ; show pressure readings custom view
2893 #DEFINE show_transmitter ul,1 ; show transmitter attention
2894 #DEFINE show_pres_warning ul,2 ; show transmitter pressure warning
2895 #DEFINE show_pres_attention ul,3 ; show transmitter pressure attention
2896
2897 check_tr_functions:
2898 clrf ul ; set all messages as not shown yet
2899 btfsc alternative_divelayout ; in alternative layout?
2900 bra check_tr_functions_tr1 ; YES - continue with checking transmitter 1
2901 movlw index_pressures_SAC ; NO - index of custom view pressure readings
2902 cpfseq menupos3 ; - pressure readings shown?
2903 bra check_tr_functions_tr1 ; NO - continue with checking transmitter 1
2904 bsf show_custview ; YES - suppress redraw by faking it has already been redrawn
2905 check_tr_functions_tr1:
2906 movff char_I_pressure_stat+0,WREG ; get status of 1st pressure reading
2907 rcall check_tr_functions_helper1 ; check for transmitter 1 lost
2908 rcall check_tr_functions_helper2 ; check for transmitter 1 low battery
2909 movff int_IO_pressure_value+1,WREG ; get high byte of 1st pressure reading
2910 rcall check_tr_functions_helper3 ; check for transmitter 1 pressure warning
2911 rcall check_tr_functions_helper4 ; check for transmitter 1 pressure attention
2912 check_tr_functions_tr2:
2913 movff char_I_pressure_stat+1,WREG ; get status of 2nd pressure reading
2914 rcall check_tr_functions_helper5 ; check for transmitter 2 lost
2915 rcall check_tr_functions_helper6 ; check for transmitter 2 low battery
2916 movff int_IO_pressure_value+3,WREG ; get high byte of 2nd pressure reading
2917 rcall check_tr_functions_helper7 ; check for transmitter 2 pressure warning
2918 rcall check_tr_functions_helper8 ; check for transmitter 2 pressure attention
2919 check_tr_functions_show_xmtr:
2920 btfss show_transmitter ; shall show transmitter message?
2921 bra check_tr_functions_show_warn ; NO - continue with pressure warning
2922 bsf message_attention ; YES - set flag for attention
2923 incf message_counter,F ; - increase counter
2924 call TFT_attention_transmitter ; - show transmitter attention message
2925 check_tr_functions_show_warn:
2926 btfss show_pres_warning ; shall show pressure warning?
2927 bra check_tr_functions_show_att ; NO - continue with pressure attention
2928 bsf message_warning ; YES - set flag for warning
2929 incf message_counter,F ; - increase counter
2930 goto TFT_warning_pres_reading ; - pressure reading warning message and done then
2931 check_tr_functions_show_att:
2932 btfss show_pres_attention ; shall show pressure attention?
2933 return ; NO - done
2934 bsf message_attention ; YES - set flag for attention
2935 incf message_counter,F ; - increase counter
2936 goto TFT_attention_pres_reading ; - pressure reading warning message and done then
2937
2938 check_tr_functions_helper1:
2939 btfsc WREG,char_transmitter_lost ; transmitter 1 lost?
2940 bra check_tr_functions_helper1a ; YES - show transmitter attention message
2941 bcf transmitter1_lost ; NO - clear flag for old lost attention
2942 return ; - done
2943 check_tr_functions_helper1a:
2944 bsf show_transmitter ; show transmitter attention
2945 btfsc transmitter1_lost ; is it a new message?
2946 return ; NO - do not show the pressure readings custom view again
2947 bsf transmitter1_lost ; YES - memorize it's an old message now
2948 bra check_tr_functions_show_cv ; - show custom view
2949
2950 check_tr_functions_helper2:
2951 btfsc WREG,char_transmitter_low_bat ; transmitter 1 low battery?
2952 bra check_tr_functions_helper2a ; YES - show transmitter attention message
2953 bcf transmitter1_battery ; NO - clear flag for old battery attention
2954 return ; - done
2955 check_tr_functions_helper2a:
2956 bsf show_transmitter ; show transmitter attention
2957 btfsc transmitter1_battery ; is it a new message?
2958 return ; NO - do not show the pressure readings custom view again
2959 bsf transmitter1_battery ; YES - memorize it's an old message now
2960 bra check_tr_functions_show_cv ; - show custom view
2961
2962 check_tr_functions_helper3:
2963 btfsc WREG,int_warning_flag ; transmitter 1 pressure warning?
2964 bra check_tr_functions_helper3a ; YES - show pressure reading message as warning
2965 bcf transmitter1_pres_warn ; NO - clear flag for old warning
2966 return ; - done
2967 check_tr_functions_helper3a:
2968 bsf show_pres_warning ; show pressure warning
2969 btfsc transmitter1_pres_warn ; is it a new message?
2970 return ; NO - do not show the pressure readings custom view again
2971 bsf transmitter1_pres_warn ; YES - memorize it's an old message now
2972 bra check_tr_functions_show_cv ; - show custom view
2973
2974 check_tr_functions_helper4:
2975 btfsc WREG,int_attention_flag ; transmitter 1 pressure attention?
2976 bra check_tr_functions_helper4a ; YES - show pressure reading message as attention
2977 bcf transmitter1_pres_att ; NO - clear flag for old attention
2978 return ; - done
2979 check_tr_functions_helper4a
2980 bsf show_pres_attention ; show pressure attention
2981 btfsc transmitter1_pres_att ; is it a new message?
2982 return ; NO - do not show the pressure readings custom view again
2983 bsf transmitter1_pres_att ; YES - memorize it's an old message now
2984 bra check_tr_functions_show_cv ; - show custom view
2985
2986 check_tr_functions_helper5:
2987 btfsc WREG,char_transmitter_lost ; transmitter 2 lost?
2988 bra check_tr_functions_helper5a ; YES - show transmitter attention message
2989 bcf transmitter2_lost ; NO - clear flag for old lost attention
2990 return ; - done
2991 check_tr_functions_helper5a:
2992 bsf show_transmitter ; show transmitter attention
2993 btfsc transmitter2_lost ; is it a new message?
2994 return ; NO - do not show the pressure readings custom view again
2995 bsf transmitter2_lost ; YES - memorize it's an old message now
2996 bra check_tr_functions_show_cv ; - show custom view
2997
2998 check_tr_functions_helper6:
2999 btfsc WREG,char_transmitter_low_bat ; transmitter 2 low battery?
3000 bra check_tr_functions_helper6a ; YES - show transmitter attention message
3001 bcf transmitter2_battery ; NO - clear flag for old battery attention
3002 return ; - done
3003 check_tr_functions_helper6a:
3004 bsf show_transmitter ; show transmitter attention
3005 btfsc transmitter2_battery ; is it a new message?
3006 return ; NO - do not show the pressure readings custom view again
3007 bsf transmitter2_battery ; YES - memorize it's an old message now
3008 bra check_tr_functions_show_cv ; - show custom view
3009
3010 check_tr_functions_helper7:
3011 btfsc WREG,int_warning_flag ; transmitter 2 pressure warning?
3012 bra check_tr_functions_helper7a ; YES - show pressure reading message as warning
3013 bcf transmitter2_pres_warn ; NO - clear flag for old warning
3014 return ; - done
3015 check_tr_functions_helper7a:
3016 bsf show_pres_warning ; show pressure warning
3017 btfsc transmitter2_pres_warn ; is it a new message?
3018 return ; NO - do not show the pressure readings custom view again
3019 bsf transmitter2_pres_warn ; YES - memorize it's an old message now
3020 bra check_tr_functions_show_cv ; - show custom view
3021
3022 check_tr_functions_helper8:
3023 btfsc WREG,int_attention_flag ; transmitter 2 pressure attention?
3024 bra check_tr_functions_helper8a ; YES - show pressure reading message as attention
3025 bcf transmitter2_pres_att ; NO - clear flag for old attention
3026 return ; - done
3027 check_tr_functions_helper8a
3028 bsf show_pres_attention ; show pressure attention
3029 btfsc transmitter2_pres_att ; is it a new message?
3030 return ; NO - do not show the pressure readings custom view again
3031 bsf transmitter2_pres_att ; YES - memorize it's an old message now
3032 ;bra check_tr_functions_show_cv ; - show custom view
3033
3034 check_tr_functions_show_cv:
3035 btfsc show_custview ; is the pressure readings custom view not shown yet shown?
3036 return ; NO - already shown, done
3037 bsf show_custview ; YES - mark as shown
3038 btfsc alternative_divelayout ; - in alternative layout?
3039 call switch_layout_to_normal ; YES - switch to normal layout
3040 movlw index_pressures_SAC-1 ; custom view number one below pressure readings
3041 movwf menupos3 ; set custom view number
3042 bsf toggle_customview ; initiate toggle to desired custom view -> pressure readings view will be shown
3043 return ; done
3044
3045 ENDIF
3046
3047
3048 check_gas_needs_ascent:
3049 banksel int_O_ascent_pres_need
3050 movf int_O_ascent_pres_need+1,w ; get high byte from pres need of 1st tank
3051 iorwf int_O_ascent_pres_need+3,w ; inclusive or with high byte from pres need of 2nd tank
3052 iorwf int_O_ascent_pres_need+5,w ; inclusive or with high byte from pres need of 3rd tank
3053 iorwf int_O_ascent_pres_need+7,w ; inclusive or with high byte from pres need of 4th tank
3054 iorwf int_O_ascent_pres_need+9,w ; inclusive or with high byte from pres need of 5th tank
2588 banksel common 3055 banksel common
2589 btfsc WREG,int_invalid_flag ; check if invalid flag is set 3056 btfsc WREG,int_invalid_flag ; check if invalid flag is set
2590 return ; YES - no further checking required 3057 return ; YES - no further checking required
2591 btfsc WREG,int_warning_flag ; NO - check if any gas has a pres_need >= pres_fill 3058 btfsc WREG,int_warning_flag ; check if any gas has a pres_need >= pres_fill
2592 bsf warning_active ; YES - set warning flag 3059 bsf message_warning ; YES - set warning flag
2593 btfsc WREG,int_warning_flag ; NO - check if any gas has a pres_need >= pres_fill 3060 btfsc WREG,int_warning_flag ; check if any gas has a pres_need >= pres_fill
2594 goto TFT_warning_gas_needs_warn ; Yes - show a warning 3061 goto TFT_warning_gas_needs_warn ; Yes - show a warning
2595 btfsc WREG,int_attention_flag ; NO - check if any gas has a pres_need >= pres_fill * threshold 3062 btfsc WREG,int_attention_flag ; check if any gas has a pres_need >= pres_fill * threshold
3063 bsf message_attention ; YES - set attention flag
3064 btfsc WREG,int_attention_flag ; check if any gas has a pres_need >= pres_fill * threshold
2596 goto TFT_warning_gas_needs_att ; YES - show an attention 3065 goto TFT_warning_gas_needs_att ; YES - show an attention
2597 bcf gas_needs_attention ; NO - clear flag for a new attention 3066 bcf gas_needs_attention ; NO - clear flag for a new attention
2598 bcf gas_needs_warning ; clear flag for a new warning 3067 bcf gas_needs_warning ; clear flag for a new warning
2599 return 3068 return
2600 3069
2601 3070
2602 check_warn_sensors_disagree: 3071 check_warn_sensors_disagree:
2603 incf warning_counter,F ; increase counter 3072 incf message_counter,F ; increase counter
2604 bsf warning_active ; YES - set Warning flag 3073 bsf message_warning ; YES - set warning flag
2605 goto TFT_warning_sensor_disagree ; show sensor disagree warning (and return) 3074 goto TFT_warning_sensor_disagree ; show sensor disagree warning (and return)
2606 3075
2607 3076
2608 check_IBCD: 3077 check_IBCD:
2609 TSTOSS opt_enable_IBCD ; IBCD warning activated? 3078 TSTOSS opt_enable_IBCD ; IBCD warning activated?
2610 return ; NO - done 3079 return ; NO - done
2611 movff char_O_deco_warnings,WREG ; YES - get deco warnings vector 3080 movff char_O_deco_warnings,WREG ; YES - get deco warnings vector
2612 btfss WREG,IBCD_warning ; IBCD warning flag set? 3081 btfss WREG,IBCD_warning ; IBCD warning flag set?
2613 return ; NO - return 3082 return ; NO - return
2614 incf warning_counter,F ; YES - increase counter 3083 incf message_counter,F ; YES - increase counter
2615 goto TFT_warning_IBCD ; write warning to display 3084 goto TFT_warning_IBCD ; write warning to display
3085
3086
3087 check_OC_gas_avail:
3088 tstfsz best_gas_number ; is a breathable gas available?
3089 return ; > 0 : a breathable gas is available
3090 btfsc FLAG_ccr_mode ; = 0 : problem - in CCR mode?
3091 bra check_OC_gas_avail_1 ; YES - real problem
3092 btfsc FLAG_pscr_mode ; NO - in PSCR mode?
3093 bra check_OC_gas_avail_1 ; YES - real problem
3094 return ; NO - neither CCR nor pSCR mode, suppress warning
3095 check_OC_gas_avail_1:
3096 btfsc FLAG_bailout_mode ; in bailout?
3097 return ; YES - suppress warning
3098 incf message_counter,F ; NO - increase counter
3099 bsf message_attention ; set attention flag
3100 goto TFT_warning_no_BO_gas ; show message (and return)
3101
3102
3103 advice_gas_change:
3104 bsf message_advice ; show advice sign
3105 incf message_counter,F ; increase counter
3106 goto TFT_advice_gas_change
2616 3107
2617 3108
2618 global restart_deco_engine 3109 global restart_deco_engine
2619 global restart_deco_engine_wo_ceiling 3110 global restart_deco_engine_wo_ceiling
2620 restart_deco_engine: 3111 restart_deco_engine:
2621 ; make bank save copies and set flags for invalid data 3112 ; invalidate ceiling
2622 movff int_O_ceiling+1,WREG 3113 movff int_O_ceiling+1,WREG
2623 bsf WREG,char_invalid_flag ; int_O_ceiling has its invalid flag on a char's position! 3114 bsf WREG,char_invalid_flag ; int_O_ceiling has its invalid flag on a char's position!
2624 movff WREG,int_O_ceiling+1 3115 movff WREG,int_O_ceiling+1
2625 3116
2626 restart_deco_engine_wo_ceiling: 3117 restart_deco_engine_wo_ceiling:
2627 ; make more bank save copies and set more flags for invalid data 3118 ; invalidate deco data (stop table data)
2628 movff char_O_deco_gas+0,WREG 3119 movff char_O_deco_gas+0,WREG
2629 bsf WREG,char_invalid_flag 3120 bsf WREG,char_invalid_flag
2630 movff WREG,char_O_deco_gas+0 3121 movff WREG,char_O_deco_gas+0
2631 3122
3123 ; invalidate ascent time (normal plan)
2632 movff int_O_ascenttime+1,WREG 3124 movff int_O_ascenttime+1,WREG
2633 bsf WREG,int_invalid_flag 3125 bsf WREG,int_invalid_flag
2634 movff WREG,int_O_ascenttime+1 3126 movff WREG,int_O_ascenttime+1
2635 3127
3128 ; invalidate CNS at end of dive in normal plan
3129 movff int_O_normal_CNS_fraction+1,WREG
3130 bsf WREG,int_invalid_flag
3131 movff WREG,int_O_normal_CNS_fraction+1
3132
3133 ; restart deco engine
3134 movff char_O_main_status,WREG ; get current main engine configuration
3135 bcf WREG,DECO_COMPLETED_NORM ; eventually clear flag stating completion of normal plan
3136 bsf WREG,DECO_COMPLETED_ALT ; fake we came from alternative plan to force normal plan to be done next
3137 movff WREG,char_O_main_status ; write back new configuration
3138 movff char_O_deco_status,WREG ; get current deco engine status
3139 bcf WREG,DECO_STATUS_0_FLAG ; set status flags to...
3140 bcf WREG,DECO_STATUS_1_FLAG ; ... DECO_STATUS_START
3141 movff WREG,char_O_deco_status ; write back new configuration to restart deco computations
3142
3143 inval_alternative_plan_data:
3144 ; invalidate ascent time (alternative plan)
2636 movff int_O_alternate_ascenttime+1,WREG 3145 movff int_O_alternate_ascenttime+1,WREG
2637 bsf WREG,int_invalid_flag 3146 bsf WREG,int_invalid_flag
2638 movff WREG,int_O_alternate_ascenttime+1 3147 movff WREG,int_O_alternate_ascenttime+1
2639 3148
2640 movff int_O_normal_CNS_fraction+1,WREG 3149 ; invalidate CNS at end of dive in alternative plan
2641 bsf WREG,int_invalid_flag
2642 movff WREG,int_O_normal_CNS_fraction+1
2643
2644 movff int_O_alternate_CNS_fraction+1,WREG 3150 movff int_O_alternate_CNS_fraction+1,WREG
2645 bsf WREG,int_invalid_flag 3151 bsf WREG,int_invalid_flag
2646 movff WREG,int_O_alternate_CNS_fraction+1 3152 movff WREG,int_O_alternate_CNS_fraction+1
2647 3153
2648 movff int_O_tank_pres_need+1,WREG 3154 ; invalidate ascent gas needs
3155 movff int_O_ascent_pres_need+1,WREG
2649 bsf WREG,int_invalid_flag 3156 bsf WREG,int_invalid_flag
2650 movff WREG,int_O_tank_pres_need+1 3157 movff WREG,int_O_ascent_pres_need+1
2651 3158
2652 ; restart deco engine 3159 IFDEF _rx_functions
2653 movff char_O_deco_status,WREG ; get current deco engine configuration 3160 ; invalidate pressure needs (TR functions)
2654 bcf WREG,DECO_STATUS_0_FLAG ; set status flags to... 3161 movff int_O_pressure_need+1,WREG
2655 bcf WREG,DECO_STATUS_1_FLAG ; ... DECO_STATUS_START 3162 bsf WREG,int_not_avail_flag
2656 bsf WREG,DECO_PLAN_FLAG ; fake we came from alternative plan to force normal plan to be done next 3163 movff WREG,int_O_pressure_need+1
2657 movff WREG,char_O_deco_status ; write back new configuration to restart deco computations 3164 movff int_O_pressure_need+3,WREG
3165 bsf WREG,int_not_avail_flag
3166 movff WREG,int_O_pressure_need+3
3167 ENDIF
3168
3169 ; update display depended on NDL or deco mode
3170 bsf FLAG_TFT_display_ndl_or_deko
2658 3171
2659 return 3172 return
2660 3173
2661 ;============================================================================= 3174 ;=============================================================================
2662 ; simulator mode 3175 ; Simulator Mode
2663 ; 3176 ;
2664 3177
2665 global do_demo_divemode 3178 global do_demo_divemode
2666 do_demo_divemode: 3179 do_demo_divemode:
2667 call option_save_all ; Save all settings into EEPROM before starting simulation 3180 call TFT_ClearScreen ; blank screen
3181 call option_save_all ; save all settings into EEPROM before starting simulation
2668 call deco_push_tissues_to_vault ; C-code: back-up status of the real tissues 3182 call deco_push_tissues_to_vault ; C-code: back-up status of the real tissues
2669 banksel common ; Bank1 3183 banksel common ; bank 1
2670 3184
2671 ; +++ COMMENTED OUT FOR TESTING PURPOSE ONLY !!! +++ 3185 ; +++ COMMENT OUT FOR TESTING PURPOSE ONLY !!! +++
2672 ; +++ DO NOT COMMENT OUT IN OPERATIONAL USE !!! +++ 3186 bsf restore_deco_data ; restore tissue and CNS after simulator use
2673 ; 3187 ; +++ DO NOT COMMENT OUT IN OPERATIONAL USE !!! +++
2674 bsf restore_deco_data ; Restore tissue and CNS after simulator use
2675 3188
2676 bcf pressure_refresh 3189 bcf pressure_refresh
2677 btfss pressure_refresh ; Wait for sensor 3190 btfss pressure_refresh ; wait for sensor
2678 bra $-2 3191 bra $-2
2679 3192
2680 bsf simulatormode_active ; Set Flag 3193 bsf simulatormode_active ; set flag
2681 ; Compute dive ambient conditions 3194
2682 banksel char_I_bottom_depth 3195 banksel char_I_bottom_depth ; compute dive ambient conditions
2683 movf char_I_bottom_depth,W 3196 movf char_I_bottom_depth,W
2684 mullw .100 3197 mullw .100
2685 movff PRODL,rel_pressure+0 3198 movff PRODL,rel_pressure+0
2686 movff PRODH,rel_pressure+1 3199 movff PRODH,rel_pressure+1
2687 movlw LOW (.1000) 3200 movlw LOW (.1000)
2688 addwf PRODL,W 3201 addwf PRODL,W
2689 movff WREG,sim_pressure+0 3202 movff WREG,sim_pressure+0
2690 movlw HIGH (.1000) 3203 movlw HIGH (.1000)
2691 addwfc PRODH,W 3204 addwfc PRODH,W
2692 movff WREG,sim_pressure+1 3205 movff WREG,sim_pressure+1
2693 banksel common ; Bank1 3206 banksel common ; bank 1
2694 3207
2695 bsf divemode 3208 bsf divemode
2696 goto diveloop ; Switch into Divemode! 3209 goto diveloop ; switch into dive mode
2697 3210
2698 END 3211 END