comparison src/divemode.asm @ 582:b455b31ce022

work on 2.97 stable
author heinrichsweikamp
date Mon, 26 Feb 2018 16:40:28 +0100
parents 54346c651b6a
children 6636cbe64c6d
comparison
equal deleted inserted replaced
581:f5de1ff88814 582:b455b31ce022
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File divemode.asm REFACTORED VERSION V2.96a 3 ; File divemode.asm REFACTORED VERSION V2.98
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"
19 #include "math.inc" 19 #include "math.inc"
20 #include "wait.inc" 20 #include "wait.inc"
21 #include "customview.inc" 21 #include "customview.inc"
22 #include "start.inc" 22 #include "start.inc"
23 #include "adc_lightsensor.inc" 23 #include "adc_lightsensor.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 gui CODE 29
30 extern TFT_dive_compass_heading
31 extern do_line_menu
32 extern do_main_divemenu
33 extern option_save_all
34 extern init_recording_params
35
36
37 ;---- Private local variables -------------------------------------------------
38
39 CBLOCK local1 ; max size is 16 Byte !!!
40 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
43 active_diluent ; backup of diluent gas for when switching back from bailout to CCR/pSCR loop
44 average_depth_hold_total:4 ; used to calculate the average depth
45 ENDC ; used: 11 byte, remaining: 5 byte
46
47 gui CODE
48
49 ;=============================================================================
30 50
31 global diveloop 51 global diveloop
32 diveloop: 52 diveloop:
33 banksel common 53 banksel common
34 call speed_normal 54 call speed_normal
35 call diveloop_boot ; Boot tasks for all modes 55 call diveloop_boot ; Boot tasks for all modes
36 56
37 ; Startup Tasks for all modes 57 ; Startup Tasks for all modes
38 call TFT_boot ; Initialize TFT (includes clear screen) 58 call TFT_boot ; Initialize TFT (includes clear screen)
39 bsf FLAG_TFT_divemode_mask ; Display mask 59 bsf FLAG_TFT_divemode_mask ; Display mask
40 movff customview_divemode,menupos3; Reload last customview 60 movff customview_divemode,menupos3; Reload last customview
41 call customview_mask ; Redraw last custom view 61 call customview_mask ; Redraw last custom view
42 62
43 btfsc FLAG_apnoe_mode 63 btfsc FLAG_apnoe_mode
44 bsf realdive ; Set Realdive flag in Apnoe mode 64 bsf realdive ; Set Realdive flag in Apnoe mode
45 65
46 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode 66 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode
47 bra diveloop_loop_start 67 bra diveloop_loop_start
48 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode 68 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode
49 bra diveloop_loop_start 69 bra diveloop_loop_start
50 70
51 bsf FLAG_TFT_display_ndl_mask ; display "NDL" 71 bsf FLAG_TFT_display_ndl_mask ; display "NDL"
52 72
53 ; +@5 init 73 ; +@5 init
54 clrf WREG ; WAIT marker: display "---" 74 clrf WREG ; WAIT marker: display "---"
55 movff WREG,char_I_sim_advance_time; bank safe clrf 75 movff WREG,char_I_sim_advance_time
56 movff WREG,int_O_alternate_ascenttime+0 76 movff WREG,int_O_alternate_ascenttime+0
57 bsf WREG,int_not_yet_computed 77 bsf WREG,int_not_yet_computed
58 bsf WREG,int_invalid_flag 78 bsf WREG,int_invalid_flag
59 movff WREG,int_O_alternate_ascenttime+1 79 movff WREG,int_O_alternate_ascenttime+1
60 80
61 diveloop_loop_start: 81 diveloop_loop_start:
62 btfsc FLAG_TFT_display_ndl_mask 82 btfsc FLAG_TFT_display_ndl_mask
63 call TFT_display_ndl_mask 83 call TFT_display_ndl_mask
64 84
65 85
66 diveloop_loop: ; The diveloop starts here 86 diveloop_loop: ; The diveloop starts here
67 btfss quarter_second_update 87 btfss quarter_second_update
68 bra diveloop_loop4a 88 bra diveloop_loop1
69 89
70 ; tasks any 1/4 second, any mode 90 ; tasks any 1/4 second, any mode
71 bcf quarter_second_update ; clear flag 91 bcf quarter_second_update ; clear flag
72 92
73 movlw .6 93 movlw .6
74 cpfseq menupos3 ; in compass view? 94 cpfseq menupos3 ; in compass view?
75 bra diveloop_loop4a ; No, done. 95 bra diveloop_loop1 ; No, done.
76 96
77 btfsc alternative_divelayout ; In alternative layout mode? 97 btfsc alternative_divelayout ; In alternative layout mode?
78 bra diveloop_loop4a ; Yes, done. No Compass. 98 bra diveloop_loop1 ; Yes, done. No Compass.
79 99
80 ; TFT Output routines 100 ; TFT Output routines
81 extern TFT_dive_compass_heading 101 call TFT_dive_compass_heading ; Yes, update compass heading value
82 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)
83 bsf FLAG_TFT_temp_divemode ; Redraw temperature (Is slighty affected from compass heading arrow) 103 ; TFT Output routines
84 ; TFT Output routines 104
85 105 diveloop_loop1:
86 diveloop_loop4a: 106 btfss onesecupdate
87 btfss onesecupdate
88 bra diveloop_loop3 107 bra diveloop_loop3
89 108
90 ; tasks any new second... 109 ; tasks any new second...
91 bcf onesecupdate ; one seconds update, clear flag here in case it's set again in ISR before all tasks are done. 110 bcf onesecupdate ; one seconds update, clear flag here in case it's set again in ISR before all tasks are done.
92 111
93 ;bsf LEDg ; ### DEBUG - used to measure the time used by all deco code to see if there is enough margin each second ### 112 ;bsf LEDg ; ### USE FOR DEBUG ONLY - RESETS RX CIRCUITRY ###
94 113
95 ; display depth based on full seconds interval (nicer blinking) 114 ; display depth based on full seconds interval (nicer blinking)
96 btfss alternative_divelayout 115 btfss alternative_divelayout
97 rcall TFT_output4_normal 116 rcall TFT_output4_normal
98 btfsc alternative_divelayout 117 btfsc alternative_divelayout
99 rcall TFT_output4_alternative 118 rcall TFT_output4_alternative
100 119
101 btfsc FLAG_apnoe_mode ; Only in apnoe mode 120 btfsc FLAG_apnoe_mode ; Only in apnoe mode
102 bra diveloop_loop1b ; One Second Tasks in Apnoe mode 121 bra diveloop_loop1_nonedeco ; One Second Tasks in Apnoe mode
103 122
104 ; tasks any new second - only for deco modes 123 ; tasks any new second - only for deco modes
124 diveloop_loop1_decomodes:
105 bsf FLAG_TFT_divemins ; Display (new) divetime! 125 bsf FLAG_TFT_divemins ; Display (new) divetime!
106 btfsc show_safety_stop ; Show the safety stop? 126 btfsc show_safety_stop ; Show the safety stop?
107 bsf FLAG_TFT_show_safety_stop ; Yes, show/delete if done. 127 bsf FLAG_TFT_show_safety_stop ; Yes, show/delete if done.
108 128
109 btfss alternative_divelayout 129 btfss alternative_divelayout
110 rcall TFT_output1_normal 130 rcall TFT_output1_normal
111 btfsc alternative_divelayout 131 btfsc alternative_divelayout
112 rcall TFT_output1_alternative 132 rcall TFT_output1_alternative
113 133
114 btfsc FLAG_ccr_mode ; In CCR mode... 134 btfsc FLAG_ccr_mode ; in CCR mode...
115 call check_dive_autosp ; ...check for Auto-SP 135 call check_dive_autosp ; ...check for Auto-SP
116 136
117 call calc_deko_divemode ; calculate decompression and set resulting display flags 137 call calc_deko_divemode ; calculate decompression and set resulting display flags
118 138
119 btfss alternative_divelayout 139 btfss alternative_divelayout
120 rcall TFT_output2_normal 140 rcall TFT_output2_normal
121 btfsc alternative_divelayout 141 btfsc alternative_divelayout
122 rcall TFT_output2_alternative 142 rcall TFT_output2_alternative
123 143
124 call divemode_check_for_warnings ; Check for any warnings 144 call divemode_check_for_warnings ; Check for any warnings
125 145
126 bra diveloop_loop1x ; Common Tasks 146 bra diveloop_loop2 ; Common Tasks
127 147
128 148
129 ; tasks any new second - only for apnoe mode 149 ; tasks any new second - only for apnoe mode
130 diveloop_loop1b: 150 diveloop_loop1_nonedeco:
131 rcall divemode_apnoe_tasks ; 1 sec. Apnoe tasks 151 rcall divemode_apnoe_tasks ; 1 sec. Apnoe tasks
132 call customview_second ; Do every-second tasks for the custom view area 152 call customview_second ; Do every-second tasks for the custom view area
133 153 ;bra diveloop_loop2 ; Common Tasks
134 ;bra diveloop_loop1x ; Common Tasks
135 154
136 ; continue tasks any new second, any mode 155 ; continue tasks any new second, any mode
137 diveloop_loop1x: 156 diveloop_loop2:
138 rcall timeout_divemode ; ** menu timeout? ** This routine sets the required flags 157 rcall timeout_divemode ; ** menu timeout? ** This routine sets the required flags
139 rcall set_dive_modes ; tests if depth>threshold 158 rcall set_dive_modes ; tests if depth > threshold
140 rcall set_min_temp ; store min. temp if required (Future hardware will need this to be checked 1/second...) 159 rcall set_min_temp ; store min. temp if required (Future hardware will need this to be checked 1/second...)
141 160
142 btfsc oneminupdate ; one minute tasks 161 btfsc oneminupdate ; one minute tasks
143 rcall update_divemode60 ; Update clock, etc. 162 rcall update_divemode60 ; Update clock, etc.
144 163
145 btfss alternative_divelayout 164 btfss alternative_divelayout
146 rcall TFT_output3_normal 165 rcall TFT_output3_normal
147 btfsc alternative_divelayout 166 btfsc alternative_divelayout
148 rcall TFT_output3_alternative 167 rcall TFT_output3_alternative
149 168
150 ;bcf LEDg ; ### DEBUG - used to measure the time used by all deco code to see if there is enough margin each second ### 169 ;bcf LEDg ; ### USE FOR DEBUG ONLY - RESETS RX CIRCUITRY ###
151 170
152 ; tasks any round, any mode 171 ; tasks any round, any mode
153 diveloop_loop3: 172 diveloop_loop3:
154 call test_switches_divemode ; Check switches in divemode 173 call test_switches_divemode ; Check switches in divemode
155 174
156 global diveloop_loop4 175 global diveloop_loop4
157 diveloop_loop4: ; Menu-Exit returns here... 176 diveloop_loop4: ; Menu-Exit returns here...
158 btfsc divemode_menu ; in the big divemode menu? 177 btfsc divemode_menu ; in the big divemode menu?
159 bra diveloop_loop4b ; YES - no space for CCR/pSCR info 178 bra diveloop_loop4b ; YES - no space for CCR/pSCR info
160 btfsc menuview ; NO - in the small yellow menu? 179 btfsc menuview ; NO - in the small yellow menu?
161 bra diveloop_loop4b ; YES - no space for CCR/pSCR info 180 bra diveloop_loop4b ; YES - no space for CCR/pSCR info
162 btfsc alternative_divelayout ; NO - in the alternative layout? 181 btfsc alternative_divelayout ; NO - in the alternative layout?
163 bra diveloop_loop4b ; YES - no space for CCR/pSCR info 182 bra diveloop_loop4b ; YES - no space for CCR/pSCR info
164 call TFT_show_mode_divemode ; NO - (re)write CCR/pSCR mode info to display 183 call TFT_show_mode_divemode ; NO - (re)write CCR/pSCR mode info to display
165 diveloop_loop4b: 184 diveloop_loop4b:
166 btfsc toggle_customview ; Next view? 185 btfsc toggle_customview ; Next view?
167 call customview_toggle ; Yes, show next customview (and delete this flag) 186 call customview_toggle ; Yes, show next customview (and delete this flag)
168 187
169 btfsc store_sample ; store new sample? 188 btfsc divemode_gaschange ; Gas switch flag set?
170 call store_dive_data ; Store profile data 189 call gas_switched_common ; YES
171 190
172 btfss divemode ; Dive finished? 191 btfsc toggle_gf ; Toggle GF/aGF?
173 goto ghostwriter_end_dive ; Dive finished! 192 rcall divemodemode_togglegf ; YES
174 193
175 btfsc divemode_gaschange ; Gas switch flag set? 194 btfsc FLAG_set_marker ; shall a marker be set?
176 call gas_switched_common ; Yes 195 call set_logbook_marker ; YES
177 196
178 btfsc toggle_gf ; =1: Toggle GF/aGF 197 btfsc store_sample ; store new sample?
179 rcall divemodemode_togglegf ; Toggle aGF/GF 198 call store_dive_data ; Store profile data
180 199
181 btfsc pressure_refresh ; new pressure available? 200 btfss divemode ; Dive finished?
182 rcall set_max_depth ; update max. depth if required 201 goto ghostwriter_end_dive ; Dive finished!
183 btfsc pressure_refresh ; new pressure available? 202
184 bsf FLAG_TFT_depth ; Yes, update depth asap 203 btfsc pressure_refresh ; new pressure available?
185 bcf pressure_refresh ; clear flag 204 rcall set_max_depth ; update max. depth if required
186 205 btfsc pressure_refresh ; new pressure available?
187 btfsc temp_changed 206 bsf FLAG_TFT_depth ; Yes, update depth
188 bsf FLAG_TFT_temp_divemode ; Displays temperature 207 bcf pressure_refresh ; clear flag
208
209 btfsc temp_changed
210 bsf FLAG_TFT_temp_divemode ; Displays temperature
189 211
190 ; display depth based on as-fast-as-possible (no nice blinking) 212 ; display depth based on as-fast-as-possible (no nice blinking)
191 ;btfss alternative_divelayout 213 ;btfss alternative_divelayout
192 ;rcall TFT_output4_normal 214 ;rcall TFT_output4_normal
193 ;btfsc alternative_divelayout 215 ;btfsc alternative_divelayout
194 ;rcall TFT_output4_alternative 216 ;rcall TFT_output4_alternative
195 217
196 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) 218 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
197 bra diveloop_loop5 219 bra diveloop_loop5
198 bra diveloop_loop6 220 bra diveloop_loop6
199 221
200 diveloop_loop5: 222 diveloop_loop5:
201 btfss vusb_in ; USB (still) plugged in? 223 btfss vusb_in ; USB (still) plugged in?
202 bcf enable_screen_dumps ; No, clear flag 224 bcf enable_screen_dumps ; No, clear flag
203 call rs232_get_byte 225 call rs232_get_byte
204 btfsc rs232_recieve_overflow 226 btfsc rs232_receive_overflow
205 bra diveloop_loop6 227 bra diveloop_loop6
206 movlw "l" 228 movlw "l"
207 cpfseq RCREG1 229 cpfseq RCREG1
208 bra diveloop_loop6 230 bra diveloop_loop6
209 call TFT_dump_screen ; Dump the screen contents 231 call TFT_dump_screen ; Dump the screen contents
210 232
211 diveloop_loop6: 233 diveloop_loop6:
212 bra diveloop_loop ; Loop the divemode 234 bra diveloop_loop ; Loop the divemode
213 235
214 ;-------------------------------------------------------------------------------------------------------- 236 ;--------------------------------------------------------------------------------------------------------
215 237
216 TFT_output1_normal: ; beginning of any new second - only for deco modes 238 TFT_output1_normal: ; beginning of any new second - only for deco modes
217 btfsc FLAG_TFT_divemode_mask 239 btfsc FLAG_TFT_divemode_mask
218 call TFT_divemode_mask 240 call TFT_divemode_mask
219 btfsc FLAG_TFT_divemins 241 btfsc FLAG_TFT_divemins
220 call TFT_divemins ; Display (new) divetime! 242 call TFT_divemins ; Display (new) divetime!
221 call customview_second ; Do every-second tasks for the custom view area (In sync with the divetime) mH 243 call customview_second ; Do every-second tasks for the custom view area (In sync with the divetime) mH
222 btfsc FLAG_TFT_show_safety_stop 244 btfsc FLAG_TFT_show_safety_stop
223 call TFT_show_safety_stop ; Show safety stop 245 call TFT_show_safety_stop ; Show safety stop
224 btfsc FLAG_TFT_clear_safety_stop 246 btfsc FLAG_TFT_clear_safety_stop
225 call TFT_clear_safety_stop ; Clear safety stop 247 call TFT_clear_safety_stop ; Clear safety stop
226 return 248 return
227 249
228 TFT_output1_alternative: ; beginning of any new second - only for deco modes 250 TFT_output1_alternative: ; beginning of any new second - only for deco modes
229 btfsc FLAG_TFT_divemins 251 btfsc FLAG_TFT_divemins
230 call TFT_divemins_alternative ; Display (new) divetime! 252 call TFT_divemins_alternative ; Display (new) divetime!
231 btfsc FLAG_TFT_divemode_mask_alt 253 btfsc FLAG_TFT_divemode_mask_alt
232 call TFT_divemode_mask_alternative ; Alt. mask 254 call TFT_divemode_mask_alternative ; Alt. mask
233 call customview_alternative_second ; Do every-second tasks for the custom view area (In sync with the divetime) mH 255 call customview_alternative_second ; Do every-second tasks for the custom view area (In sync with the divetime) mH
234 return 256 return
235 257
236 TFT_output2_normal: ; any new second - only for deco modes 258 TFT_output2_normal: ; any new second - only for deco modes
237 btfsc FLAG_TFT_display_ndl_mask 259 btfsc FLAG_TFT_display_ndl_mask
238 call TFT_display_ndl_mask 260 call TFT_display_ndl_mask
239 btfsc FLAG_TFT_display_ndl 261 btfsc FLAG_TFT_display_ndl
240 call TFT_display_ndl 262 call TFT_display_ndl
241 btfsc FLAG_TFT_display_deko_mask 263 btfsc FLAG_TFT_display_deko_mask
242 call TFT_display_deko_mask 264 call TFT_display_deko_mask
243 btfsc FLAG_TFT_display_deko 265 btfsc FLAG_TFT_display_deko
244 call TFT_display_deko 266 call TFT_display_deko
245 btfsc FLAG_TFT_display_tts 267 btfsc FLAG_TFT_display_tts
246 call TFT_display_tts 268 call TFT_display_tts
247 return 269 return
248 270
249 TFT_output2_alternative: ; any new second - only for deco modes 271 TFT_output2_alternative: ; any new second - only for deco modes
250 return 272 return
251 273
252 TFT_output3_normal: ; tasks any new second, any mode 274 TFT_output3_normal: ; tasks any new second, any mode
253 btfsc FLAG_TFT_max_depth 275 btfsc FLAG_TFT_max_depth
254 call TFT_max_depth ; use normal max. depth 276 call TFT_max_depth ; use normal max. depth
255 btfsc FLAG_TFT_divemode_warning 277 btfsc FLAG_TFT_divemode_warning
256 call TFT_divemode_warning 278 call TFT_divemode_warning
257 btfsc FLAG_TFT_divemode_warning_clear 279 btfsc FLAG_TFT_divemode_warning_clear
258 call TFT_divemode_warning_clear 280 call TFT_divemode_warning_clear
259 btfsc FLAG_TFT_active_gas_divemode 281 btfsc FLAG_TFT_active_gas_divemode
260 call TFT_active_gas_divemode ; Display gas/Setpoint 282 call TFT_active_gas_divemode ; Display gas/Setpoint
261 btfsc FLAG_TFT_dive_warning_text_clear 283 btfsc FLAG_TFT_dive_warning_text_clear
262 call TFT_clear_warning_text ; clear complete warnings area 284 call TFT_clear_warning_text ; clear complete warnings area
263 btfsc FLAG_TFT_dive_warning_text_clr2 285 btfsc FLAG_TFT_dive_warning_text_clr2
264 call TFT_clear_warning_text_2nd_row ; clear 2nd row of warnings 286 call TFT_clear_warning_text_2nd_row; clear 2nd row of warnings
265 return 287 return
266 288
267 TFT_output3_alternative: ; tasks any new second, any mode 289 TFT_output3_alternative: ; tasks any new second, any mode
268 btfsc FLAG_TFT_max_depth_alt 290 btfsc FLAG_TFT_max_depth_alt
269 call TFT_max_depth_alternative ; big max. depth 291 call TFT_max_depth_alternative ; big max. depth
270 btfsc FLAG_TFT_dive_warning_text_clear 292 btfsc FLAG_TFT_dive_warning_text_clear
271 call TFT_clear_warning_text ; clear complete warnings area (In alt mode only 2nd. row...) 293 call TFT_clear_warning_text ; clear complete warnings area (In alt mode only 2nd. row...)
272 btfsc FLAG_TFT_big_deco_alt 294 btfsc FLAG_TFT_big_deco_alt
274 return 296 return
275 297
276 TFT_output4_normal: ; tasks any round, any mode 298 TFT_output4_normal: ; tasks any round, any mode
277 btfsc FLAG_TFT_depth 299 btfsc FLAG_TFT_depth
278 call TFT_depth ; Displays new depth 300 call TFT_depth ; Displays new depth
279 btfsc FLAG_TFT_temp_divemode 301 btfsc FLAG_TFT_temp_divemode
280 call TFT_temp_divemode ; Update temperature 302 call TFT_temp_divemode ; Update temperature
281 return 303 return
282 304
283 TFT_output4_alternative: ; tasks any round, any mode 305 TFT_output4_alternative: ; tasks any round, any mode
284 btfsc FLAG_TFT_depth 306 btfsc FLAG_TFT_depth
285 call TFT_depth ; Displays new depth 307 call TFT_depth ; Displays new depth
286 return 308 return
287 309
288 310
289 ;-------------------------------------------------------------------------------------------------------- 311 ;--------------------------------------------------------------------------------------------------------
290 312
291 divemode_apnoe_tasks: ; 1 sec. Apnoe tasks 313 divemode_apnoe_tasks: ; 1 sec. Apnoe tasks
292 call TFT_display_apnoe_descent ; Yes, Show descent timer 314 call TFT_display_apnoe_descent ; Yes, Show descent timer
293 call TFT_max_depth ; use normal max. depth 315 call TFT_max_depth ; use normal max. depth
303 cpfseq apnoe_surface_secs 325 cpfseq apnoe_surface_secs
304 bra divemode_apnoe_tasks1 326 bra divemode_apnoe_tasks1
305 clrf apnoe_surface_secs 327 clrf apnoe_surface_secs
306 incf apnoe_surface_mins,F 328 incf apnoe_surface_mins,F
307 329
308 divemode_apnoe_tasks1: 330 divemode_apnoe_tasks1:
309 bcf FLAG_active_descent ; Clear flag 331 bcf FLAG_active_descent ; Clear flag
310 btfsc divemode2 ; Time running? 332 btfsc divemode2 ; Time running?
311 return ; Yes, return 333 return ; Yes, return
312 bsf FLAG_active_descent ; Set Flag 334 bsf FLAG_active_descent ; Set Flag
313 return 335 return
314 336
315 divemode_apnoe_tasks2: 337 divemode_apnoe_tasks2:
316 btfss FLAG_active_descent ; Are we descending? 338 btfss FLAG_active_descent ; Are we descending?
317 return ; No, We are at the surface 339 return ; No, We are at the surface
335 movff max_pressure+0,sub_b+0 357 movff max_pressure+0,sub_b+0
336 movff max_pressure+1,sub_b+1 358 movff max_pressure+1,sub_b+1
337 call subU16 ; sub_c = sub_a - sub_b 359 call subU16 ; sub_c = sub_a - sub_b
338 ; apnoe_max_pressure<max_pressure -> neg_flag=1 360 ; apnoe_max_pressure<max_pressure -> neg_flag=1
339 ; max_pressure<=apnoe_max_pressure -> neg_flag=0 361 ; max_pressure<=apnoe_max_pressure -> neg_flag=0
340 btfss neg_flag 362 btfss neg_flag
341 return 363 return
342 ;apnoe_max_pressure<max_pressure 364 ;apnoe_max_pressure<max_pressure
343 movff max_pressure+0,apnoe_max_pressure+0 365 movff max_pressure+0,apnoe_max_pressure+0
344 movff max_pressure+1,apnoe_max_pressure+1 366 movff max_pressure+1,apnoe_max_pressure+1
345 return 367 return
350 rcall calc_deko_divemode2 ; all deco relevant code is now invoked every second 372 rcall calc_deko_divemode2 ; all deco relevant code is now invoked every second
351 btfsc twosecupdate 373 btfsc twosecupdate
352 bra calc_deko_divemode1 374 bra calc_deko_divemode1
353 bsf twosecupdate 375 bsf twosecupdate
354 return 376 return
355 377
356 calc_deko_divemode1: ; the following code is invoked every 2 seconds 378 calc_deko_divemode1: ; the following code is invoked every 2 seconds
357 bcf twosecupdate 379 bcf twosecupdate
358 380
359 call calc_average_depth ; calculate average depth 381 call calc_average_depth ; calculate average depth
360 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds) 382 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds)
361 call set_reset_safety_stop ; Set flags for safety stop and/or reset safety stop 383 call set_reset_safety_stop ; Set flags for safety stop and/or reset safety stop
362 call TFT_debug_output 384 call TFT_debug_output
363 385
367 return 389 return
368 390
369 ; Check for a gas change 391 ; Check for a gas change
370 goto check_gas_change ; Checks if a better gas should be selected (by user) and return... 392 goto check_gas_change ; Checks if a better gas should be selected (by user) and return...
371 393
372 394
373 calc_deko_divemode2: 395 calc_deko_divemode2:
374 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode 396 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode
375 return 397 return
376 398
377 btfsc FLAG_ccr_mode ; In CCR mode? 399 btfsc FLAG_ccr_mode ; In CCR mode?
378 rcall calc_deko_divemode_sensor ; do sensor data acquisition if applicable by OSTC model 400 rcall calc_deko_divemode_sensor ; do sensor data acquisition if applicable by OSTC model
379 401
380 btfsc FLAG_pscr_mode ; In PSCR mode? 402 btfsc FLAG_pscr_mode ; In PSCR mode?
381 rcall calc_deko_divemode_sensor ; do sensor data acquisition if applicable by OSTC model 403 rcall calc_deko_divemode_sensor ; do sensor data acquisition if applicable by OSTC model
382 404
383 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; transfer ambient pressure to deco engine 405 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; transfer ambient pressure to deco engine
384 406
385 407
386 ; check deco engine state and switch between normal and alternative plan calculations 408 ; check deco engine state and switch between normal and alternative plan calculations
387 ; 409 ;
388 ; Remark: Any reconfigurations done here do only affect the ascent & deco calculation settings, 410 ; Remark: Any reconfigurations done here do only affect the ascent & deco calculation settings,
389 ; not the settings for the calculations done on the real tissues. The later ones are only 411 ; not the settings for the calculations done on the real tissues. The later ones are only
390 ; altered in case of a gas change, or in case of a real bailout or switchback to setpoint 412 ; altered in case of a gas change, or in case of a real bailout or switchback to setpoint
391 ; or sensor, respectively. 413 ; or sensor, respectively.
392 ; In case of a gas change or real bailout/switchback, the settings for the deco calculations 414 ; In case of a gas change or real bailout/switchback, the settings for the deco calculations
393 ; are also changed to match the settings for the real tissues. This is done on signal through 415 ; are also changed to match the settings for the real tissues. This is done on signal through
394 ; 'divemode_gaschange' and will also leave the deco engine status in state as if having done 416 ; 'divemode_gaschange' and will also leave the deco engine status in state as if having done
395 ; the alternative plan last. 417 ; the alternative plan last.
396 418
397 ; check state of ascent/deco calculations 419 ; check state of ascent/deco calculations
398 movff char_O_deco_status,lo ; get a working copy of char_O_deco_status into bank common 420 movff char_O_deco_status,lo ; get a working copy of char_O_deco_status into bank common
399 movlw DECO_STATUS_MASK ; load bit mask covering the deco status bits 421 movlw DECO_STATUS_MASK ; load bit mask covering the deco status bits
400 andwf lo,W ; mask out bits showing deco engine computations state 422 andwf lo,W ; mask out bits showing deco engine computations state
401 tstfsz WREG ; check if the last compute cycle has finished (bits 1 and 0 cleared) 423 tstfsz WREG ; check if the last compute cycle has finished (bits 1 and 0 cleared)
403 btfss lo,DECO_PLAN_FLAG ; YES - computation cycle finished, so check what has been computed 425 btfss lo,DECO_PLAN_FLAG ; YES - computation cycle finished, so check what has been computed
404 bra calc_deko_divemode2b ; PLAN bit is cleared i.e. normal plan was done, may do alternative next 426 bra calc_deko_divemode2b ; PLAN bit is cleared i.e. normal plan was done, may do alternative next
405 427
406 ; The PLAN bit is set, i.e. an alternative plan was computed in the last cycle, or the deco engine has 428 ; The PLAN bit is set, i.e. an alternative plan was computed in the last cycle, or the deco engine has
407 ; been restarted because of a gas change etc. --> Reconfigure to normal plan for next computation cycle. 429 ; been restarted because of a gas change etc. --> Reconfigure to normal plan for next computation cycle.
408 430
409 ; reset flags for special calculations 431 ; reset flags for special calculations
410 bcf lo,DECO_PLAN_FLAG ; clear flag for alternative plan 432 bcf lo,DECO_PLAN_FLAG ; clear flag for alternative plan
411 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation 433 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation
412 bcf lo,DECO_VOLUME_FLAG ; clear flag for gas needs calculation 434 bcf lo,DECO_VOLUME_FLAG ; clear flag for gas needs calculation
413 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface 435 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface
426 movf hi,W ; are gas volume calculations turned on? 448 movf hi,W ; are gas volume calculations turned on?
427 bz calc_deko_divemode2e ; NO - can't have done a bailout calculation then, start normal plan 449 bz calc_deko_divemode2e ; NO - can't have done a bailout calculation then, start normal plan
428 btfsc is_bailout ; YES - check if a real bailout situation is present 450 btfsc is_bailout ; YES - check if a real bailout situation is present
429 bra calc_deko_divemode2e ; YES - OC gases have been set by bailout action then, start normal plan 451 bra calc_deko_divemode2e ; YES - OC gases have been set by bailout action then, start normal plan
430 movff active_gas,WREG ; NO - switch back to loop calculation: get current (diluent) gas, ... 452 movff active_gas,WREG ; NO - switch back to loop calculation: get current (diluent) gas, ...
431 call deco_setup_cc_diluents ; ... set up deco calculations in CCR/pSCR mode with diluents, 453 call deco_setup_cc_diluents ; ... set up deco calculations in CCR/pSCR mode with diluents,
432 bra calc_deko_divemode2e ; ... and start in normal plan mode 454 bra calc_deko_divemode2e ; ... and start in normal plan mode
433 455
434 ; The PLAN bit was cleared, i.e. a normal plan was computed in the last cycle. For the next 456 ; The PLAN bit was cleared, i.e. a normal plan was computed in the last cycle. For the next
435 ; computation cycle the mode may be switched to alternative plan, or stay in normal mode... 457 ; computation cycle the mode may be switched to alternative plan, or stay in normal mode...
436 458
437 calc_deko_divemode2b: 459 calc_deko_divemode2b:
438 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation (for safety only) 460 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation (for safety only)
439 btfsc is_bailout ; check if a real bailout situation is present 461 btfsc is_bailout ; check if a real bailout situation is present
440 bra calc_deko_divemode2c ; YES - stay in normal plan mode and preclude delayed ascent calculation 462 bra calc_deko_divemode2c ; YES - stay in normal plan mode and preclude delayed ascent calculation
441 movff char_I_extra_time,hi ; NO - get the delayed ascent setting 463 movff char_I_extra_time,hi ; NO - get the delayed ascent setting
442 tstfsz hi ; check if delayed ascent calculation is enabled 464 tstfsz hi ; check if delayed ascent calculation is enabled
443 bsf lo,DECO_ASCENT_FLAG ; YES - set flag for delayed ascent calculation 465 bsf lo,DECO_ASCENT_FLAG ; YES - set flag for delayed ascent calculation
444 tstfsz hi ; check if delayed ascent calculation is enabled (again) 466 tstfsz hi ; check if delayed ascent calculation is enabled (again)
445 bsf lo,DECO_PLAN_FLAG ; YES - set flag for alternative plan 467 bsf lo,DECO_PLAN_FLAG ; YES - set flag for alternative plan
446 468
447 ; check if a gas needs calculation shall be done 469 ; check if a gas needs calculation shall be done
448 calc_deko_divemode2c: 470 calc_deko_divemode2c:
449 bsf lo,DECO_VOLUME_FLAG ; set gas needs calculation flag (may be cleared again next) 471 bsf lo,DECO_VOLUME_FLAG ; set gas needs calculation flag (may be cleared again next)
450 TSTOSS opt_calc_asc_gasvolume ; check if gas needs calculation is enabled 472 TSTOSS opt_calc_asc_gasvolume ; check if gas needs calculation is enabled
451 bcf lo,DECO_VOLUME_FLAG ; NO - reset flag again 473 bcf lo,DECO_VOLUME_FLAG ; NO - reset flag again
452 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface 474 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface
453 TSTOSS opt_calc_asc_gasvolume ; check if gas volume calculation is enabled (again) 475 TSTOSS opt_calc_asc_gasvolume ; check if gas volume calculation is enabled (again)
454 bra calc_deko_divemode2e ; NO - no volume calculation, no simulated bailout plan in no case 476 bra calc_deko_divemode2e ; NO - no volume calculation, no simulated bailout plan in no case
455 477
456 ; check if conditions are met to calculate a bailout plan 478 ; check if conditions are met to calculate a bailout plan
457 btfsc is_bailout ; check if a real bailout situation is present 479 btfsc is_bailout ; check if a real bailout situation is present
458 bra calc_deko_divemode2e ; YES - normal plan already does bailout (OC) calculation "for real" 480 bra calc_deko_divemode2e ; YES - normal plan already does bailout (OC) calculation "for real"
459 btfss lo,DECO_MODE_LOOP_FLAG ; NO - have loop mode calculation been done during the normal plan? 481 btfss lo,DECO_MODE_LOOP_FLAG ; NO - have loop mode calculation been done during the normal plan?
460 bra calc_deko_divemode2e ; NO - when not in loop mode, no simulated bailout to be done 482 bra calc_deko_divemode2e ; NO - when not in loop mode, no simulated bailout to be done
461 bsf lo,DECO_PLAN_FLAG ; YES - set flag for alternative plan 483 bsf lo,DECO_PLAN_FLAG ; YES - set flag for alternative plan
462 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface 484 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface
463 call get_first_gas_to_WREG ; get first OC gas, ... 485 call get_first_gas_to_WREG ; get first OC gas, ...
464 call deco_setup_oc_gases ; ... set up deco calculations in OC mode with OC gases, 486 call deco_setup_oc_gases ; ... set up deco calculations in OC mode with OC gases,
465 ;bra calc_deko_divemode2e ; ... and start in alternative plan mode 487 ;bra calc_deko_divemode2e ; ... and start in alternative plan mode
466 488
467 489
468 calc_deko_divemode2e: 490 calc_deko_divemode2e:
469 clrf TMR5L 491 clrf TMR5L
470 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H 492 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H
471 call deco_calc_hauptroutine ; calc_tissue 493 call deco_calc_hauptroutine ; calc_tissue
472 banksel common 494 banksel common
473 495
474 ; Check if deco stops are necessary ? 496 ; Check if deco stops are necessary
475 movff char_O_first_deco_depth,wait_temp ; copy ceiling to temp register 497 movff char_O_first_deco_depth,WREG; get ceiling
476 tstfsz wait_temp ; Ceiling<0m? 498 tstfsz WREG ; ceiling < 0m (aka in deco) ?
477 bra calc_deko_divemode3 ; Yes! 499 bra calc_deko_divemode3 ; YES
478 500 ; NO - within NDL
479 btfsc decostop_active ; Already in nodeco mode ? 501 btfsc decostop_active ; already in no deco mode ?
480 bsf FLAG_TFT_display_ndl_mask ; No, Clear deco data, display nostop time 502 bsf FLAG_TFT_display_ndl_mask ; NO - clear deco data, display NDL time
481 bcf decostop_active ; clear flag (again) 503 bsf FLAG_TFT_display_ndl ; display NDL time
482 504 bcf decostop_active ; clear flag (again)
483 ; Copy for profile recording
484 clrf decodata+0
485 movff char_O_nullzeit,decodata+1 ; NDL
486
487 bsf FLAG_TFT_display_ndl ; display no deco limit
488 return 505 return
489 506
490 calc_deko_divemode3: 507 calc_deko_divemode3:
491 btfss decostop_active ; Already in deco mode ? 508 ; YES - in deco
492 bsf FLAG_TFT_display_deko_mask ; No, clear nostop time, display decodata 509 btfss decostop_active ; already in deco mode ?
493 bsf decostop_active ; Set flag (again) 510 bsf FLAG_TFT_display_deko_mask ; NO - clear NDL time, display deco data
494 511 bsf FLAG_TFT_display_deko ; display deco data
495 ; Copy for profile recording 512 bsf FLAG_TFT_display_tts ; display TTS
496 movff char_O_first_deco_depth,decodata+0 ; ceiling 513 bsf decostop_active ; set flag (again)
497 movff char_O_first_deco_time,decodata+1 ; length of first stop in minutes
498 bsf FLAG_TFT_display_deko ; display decodata
499 bsf FLAG_TFT_display_tts ; display TTS
500 return 514 return
501 515
502 ; -------------------------------------------------------------------------------------- 516 ; --------------------------------------------------------------------------------------
503 517
504 global calc_deko_divemode_sensor 518 global calc_deko_divemode_sensor
505 calc_deko_divemode_sensor: 519 calc_deko_divemode_sensor:
506 ; sensor acquisition code 520 ; sensor acquisition code
507 btfss s8_digital ; check if we have digital interface to the sensors 521 btfss s8_digital ; check if we have a digital interface to the sensors
508 bra calc_deko_divemode_sensor_analog ; NO - use analog interface 522 bra calc_deko_divemode_sensor_analog ; NO - check if we have an analog interface
509 btfss new_s8_data_available ; YES - check if a new data frame was received 523 btfss new_s8_data_available ; YES - check if a new data frame was received
510 bra calc_deko_divemode_sensor_common ; NO - use old values 524 bra calc_deko_divemode_sensor_common ; NO - use old values -- TODO: add timeout for no new data
511 call compute_mvolts_for_all_sensors ; YES - compute mV values from digital data 525 call compute_mvolts_for_all_sensors ; YES - compute mV values from digital data
512 bra calc_deko_divemode_sensor_common 526 bra calc_deko_divemode_sensor_common
513 527
514 calc_deko_divemode_sensor_analog: 528 calc_deko_divemode_sensor_analog:
515 call get_analog_inputs ; TODO: abort when OSTC model does not have analog inputs 529 btfss analog_o2_input ; do we have an analog input?
530 return ; NO - return
531 call get_analog_inputs ; YES - get the analog voltages and continue with the common part
516 532
517 calc_deko_divemode_sensor_common: 533 calc_deko_divemode_sensor_common:
518 ; Check for each sensor if it is calibrated and if its mv value is within min_mv and max_mv limits. 534 ; Check for each sensor if it is calibrated and if its mv value is within min_mv and max_mv limits.
519 ; If ok: compute o2_ppo2_sensorX := o2_mv_sensorX * opt_x_sX / 1000. 535 ; If ok: compute o2_ppo2_sensorX := o2_mv_sensorX * opt_x_sX / 1000
520 ; If not ok: reset o2_ppo2_sensorX, reset use_O2_sensorX and show the customview 1 in case the sensor was ok before. 536 ; If not ok: reset o2_ppo2_sensorX, reset use_O2_sensorX and show the customview 1 in case the sensor was ok before
521 537
522 ; Check min_mv of sensor 1 538 ; Check min_mv of sensor 1
523 btfss sensor1_calibrated_ok ; check if sensor is usable at all 539 btfss sensor1_calibrated_ok ; check if sensor is usable at all
524 bra check_sensor_1_fail ; NO - handle it as failed 540 bra check_sensor_1_fail ; NO - handle it as failed
525 movff o2_mv_sensor1+0, sub_a+0 ; load sensor mV value 541 movff o2_mv_sensor1+0, sub_a+0 ; load sensor mV value
526 movff o2_mv_sensor1+1, sub_a+1 542 movff o2_mv_sensor1+1, sub_a+1
527 movlw LOW min_mv ; load minimum mV value 543 movlw LOW min_mv ; load minimum mV value
528 movwf sub_b+0 544 movwf sub_b+0
529 movlw HIGH min_mv 545 movlw HIGH min_mv
530 movwf sub_b+1 546 movwf sub_b+1
531 call sub16 ; sub_c = sensor_mv - min_mv 547 call sub16 ; sub_c = sensor_mv - min_mv
532 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv 548 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv
533 bra check_sensor_1_fail ; YES - declare sensor as failed 549 bra check_sensor_1_fail ; YES - declare sensor as failed
534 ; Check max_mv of sensor 1 NO - continue with next check 550 ; Check max_mv of sensor 1 ; NO - continue with next check
535 movff o2_mv_sensor1+0, sub_a+0 551 movff o2_mv_sensor1+0, sub_a+0
536 movff o2_mv_sensor1+1, sub_a+1 552 movff o2_mv_sensor1+1, sub_a+1
537 movlw LOW max_mv 553 movlw LOW max_mv
538 movwf sub_b+0 554 movwf sub_b+0
539 movlw HIGH max_mv 555 movlw HIGH max_mv
540 movwf sub_b+1 556 movwf sub_b+1
541 call sub16 ; sub_c = sensor_mv - max_mv 557 call sub16 ; sub_c = sensor_mv - max_mv
542 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv 558 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv
543 bra check_sensor_1_fail ; NO - declare sensor as failed 559 bra check_sensor_1_fail ; NO - declare sensor as failed
544 ; Check HUD data, if available YES - continue with next check 560 ; Check HUD data, if available ; YES - continue with next check
545 btfss hud_connection_ok ; check if there is a HUD connected 561 btfss hud_connection_ok ; check if there is a HUD connected
546 bra check_sensor_1_ok ; NO - all checks done then and positive 562 bra check_sensor_1_ok ; NO - all checks done then and positive
547 btfss sensor1_active ; YES - check HUD report on sensor 563 btfss sensor1_active ; YES - check HUD report on sensor
548 bra check_sensor_1_fail ; HUD reports a fail 564 bra check_sensor_1_fail ; HUD reports a fail
549 565
550 check_sensor_1_ok: 566 check_sensor_1_ok:
551 ; o2_ppo2_sensor1 := o2_mv_sensor1:2 * opt_x_s1:2 / 1000 567 ; o2_ppo2_sensor1 := o2_mv_sensor1:2 * opt_x_s1:2 / 1000
552 movff o2_mv_sensor1+0,xA+0 568 movff o2_mv_sensor1+0,xA+0
553 movff o2_mv_sensor1+1,xA+1 569 movff o2_mv_sensor1+1,xA+1
554 movff opt_x_s1+0,xB+0 570 movff opt_x_s1+0,xB+0
555 movff opt_x_s1+1,xB+1 571 movff opt_x_s1+1,xB+1
556 rcall compute_ppo2_helper 572 rcall compute_ppo2_helper
557 movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar 573 movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar
558 bra check_sensor_2 ; continue with next sensor 574 bra check_sensor_2 ; continue with next sensor
559 575
560 check_sensor_1_fail: 576 check_sensor_1_fail:
561 clrf WREG 577 clrf WREG
562 movff WREG,o2_ppo2_sensor1 ; set ppO2 reading to zero 578 movff WREG,o2_ppo2_sensor1 ; set ppO2 reading to zero
563 btfss use_O2_sensor1 ; check if sensor was in use before 579 btfss use_O2_sensor1 ; check if sensor was in use before
564 bra check_sensor_1_fail_1 ; NO - no new news then 580 bra check_sensor_1_fail_1 ; NO - no new news then
565 call check_sensor_custview_helper ; YES - show customview 1 (sensor values) on further conditions met 581 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met
566 check_sensor_1_fail_1: 582 check_sensor_1_fail_1:
567 bcf use_O2_sensor1 ; revoke sensor from usage 583 bcf use_O2_sensor1 ; revoke sensor from usage
568 ;bra check_sensor_2 ; continue with next sensor 584 ;bra check_sensor_2 ; continue with next sensor
569 585
570 check_sensor_2: ; Check min_mv of sensor 2 586 check_sensor_2: ; Check min_mv of sensor 2
571 btfss sensor2_calibrated_ok ; check if sensor is usable at all 587 btfss sensor2_calibrated_ok ; check if sensor is usable at all
572 bra check_sensor_2_fail ; NO - handle it as failed 588 bra check_sensor_2_fail ; NO - handle it as failed
573 movff o2_mv_sensor2+0, sub_a+0 ; load sensor mV value 589 movff o2_mv_sensor2+0, sub_a+0 ; load sensor mV value
574 movff o2_mv_sensor2+1, sub_a+1 590 movff o2_mv_sensor2+1, sub_a+1
575 movlw LOW min_mv ; load minimum mV value 591 movlw LOW min_mv ; load minimum mV value
576 movwf sub_b+0 592 movwf sub_b+0
577 movlw HIGH min_mv 593 movlw HIGH min_mv
578 movwf sub_b+1 594 movwf sub_b+1
579 call sub16 ; sub_c = sensor_mv - min_mv 595 call sub16 ; sub_c = sensor_mv - min_mv
580 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv 596 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv
581 bra check_sensor_2_fail ; YES - declare sensor as failed 597 bra check_sensor_2_fail ; YES - declare sensor as failed
582 ; Check max_mv of sensor 2 NO - continue with next check 598 ; Check max_mv of sensor 2 ; NO - continue with next check
583 movff o2_mv_sensor2+0, sub_a+0 599 movff o2_mv_sensor2+0, sub_a+0
584 movff o2_mv_sensor2+1, sub_a+1 600 movff o2_mv_sensor2+1, sub_a+1
585 movlw LOW max_mv 601 movlw LOW max_mv
586 movwf sub_b+0 602 movwf sub_b+0
587 movlw HIGH max_mv 603 movlw HIGH max_mv
588 movwf sub_b+1 604 movwf sub_b+1
589 call sub16 ; sub_c = sensor_mv - max_mv 605 call sub16 ; sub_c = sensor_mv - max_mv
590 btfss neg_flag ; check if result is nagative, i.e. sensor_mv < max_mv 606 btfss neg_flag ; check if result is nagative, i.e. sensor_mv < max_mv
591 bra check_sensor_2_fail ; NO - declare sensor as failed 607 bra check_sensor_2_fail ; NO - declare sensor as failed
592 ; Check HUD data, if available YES - continue with next check 608 ; Check HUD data, if available ; YES - continue with next check
593 btfss hud_connection_ok ; check if there is a HUD connected 609 btfss hud_connection_ok ; check if there is a HUD connected
594 bra check_sensor_2_ok ; NO - all checks done then and positive 610 bra check_sensor_2_ok ; NO - all checks done then and positive
595 btfss sensor2_active ; YES - check HUD report on sensor 611 btfss sensor2_active ; YES - check HUD report on sensor
596 bra check_sensor_2_fail ; HUD reports a fail 612 bra check_sensor_2_fail ; HUD reports a fail
597 613
598 check_sensor_2_ok: 614 check_sensor_2_ok:
599 ; o2_ppo2_sensor2 := o2_mv_sensor2:2 * opt_x_s2:2 / 1000 615 ; o2_ppo2_sensor2 := o2_mv_sensor2:2 * opt_x_s2:2 / 1000
600 movff o2_mv_sensor2+0,xA+0 616 movff o2_mv_sensor2+0,xA+0
601 movff o2_mv_sensor2+1,xA+1 617 movff o2_mv_sensor2+1,xA+1
602 movff opt_x_s2+0,xB+0 618 movff opt_x_s2+0,xB+0
603 movff opt_x_s2+1,xB+1 619 movff opt_x_s2+1,xB+1
604 rcall compute_ppo2_helper 620 rcall compute_ppo2_helper
605 movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar 621 movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar
606 bra check_sensor_3 ; continue with next sensor 622 bra check_sensor_3 ; continue with next sensor
607 623
608 check_sensor_2_fail: 624 check_sensor_2_fail:
609 clrf WREG 625 clrf WREG
610 movff WREG,o2_ppo2_sensor2 ; set ppO2 reading to zero 626 movff WREG,o2_ppo2_sensor2 ; set ppO2 reading to zero
611 btfss use_O2_sensor2 ; check if sensor was in use before 627 btfss use_O2_sensor2 ; check if sensor was in use before
612 bra check_sensor_2_fail_1 ; NO - no new news then 628 bra check_sensor_2_fail_1 ; NO - no new news then
613 call check_sensor_custview_helper ; YES - show customview 1 (sensor values) on further conditions met 629 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met
614 check_sensor_2_fail_1: 630 check_sensor_2_fail_1:
615 bcf use_O2_sensor2 ; revoke sensor from usage 631 bcf use_O2_sensor2 ; revoke sensor from usage
616 ;bra check_sensor_3 ; continue with next sensor 632 ;bra check_sensor_3 ; continue with next sensor
617 633
618 check_sensor_3: ; Check min_mv of sensor 2 634 check_sensor_3: ; Check min_mv of sensor 2
619 btfss sensor3_calibrated_ok ; check if sensor is usable at all 635 btfss sensor3_calibrated_ok ; check if sensor is usable at all
620 bra check_sensor_3_fail ; NO - handle it as failed 636 bra check_sensor_3_fail ; NO - handle it as failed
621 movff o2_mv_sensor3+0, sub_a+0 ; load sensor mV value 637 movff o2_mv_sensor3+0, sub_a+0 ; load sensor mV value
622 movff o2_mv_sensor3+1, sub_a+1 638 movff o2_mv_sensor3+1, sub_a+1
623 movlw LOW min_mv ; load minimum mV value 639 movlw LOW min_mv ; load minimum mV value
624 movwf sub_b+0 640 movwf sub_b+0
625 movlw HIGH min_mv 641 movlw HIGH min_mv
626 movwf sub_b+1 642 movwf sub_b+1
627 call sub16 ; sub_c = sensor_mv - min_mv 643 call sub16 ; sub_c = sensor_mv - min_mv
628 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv 644 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv
629 bra check_sensor_3_fail ; YES - declare sensor as failed 645 bra check_sensor_3_fail ; YES - declare sensor as failed
630 ; Check max_mv of sensor 2 NO - continue with next check 646 ; Check max_mv of sensor 2 ; NO - continue with next check
631 movff o2_mv_sensor3+0, sub_a+0 647 movff o2_mv_sensor3+0, sub_a+0
632 movff o2_mv_sensor3+1, sub_a+1 648 movff o2_mv_sensor3+1, sub_a+1
633 movlw LOW max_mv 649 movlw LOW max_mv
634 movwf sub_b+0 650 movwf sub_b+0
635 movlw HIGH max_mv 651 movlw HIGH max_mv
636 movwf sub_b+1 652 movwf sub_b+1
637 call sub16 ; sub_c = sensor_mv - max_mv 653 call sub16 ; sub_c = sensor_mv - max_mv
638 btfss neg_flag ; check if result is nagative, i.e. sensor_mv < max_mv 654 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv
639 bra check_sensor_3_fail ; NO - declare sensor as failed 655 bra check_sensor_3_fail ; NO - declare sensor as failed
640 ; Check HUD data, if available YES - continue with next check 656 ; Check HUD data, if available ; YES - continue with next check
641 btfss hud_connection_ok ; check if there is a HUD connected 657 btfss hud_connection_ok ; check if there is a HUD connected
642 bra check_sensor_3_ok ; NO - all checks done then and positive 658 bra check_sensor_3_ok ; NO - all checks done then and positive
643 btfss sensor3_active ; YES - check HUD report on sensor 659 btfss sensor3_active ; YES - check HUD report on sensor
644 bra check_sensor_3_fail ; HUD reports a fail 660 bra check_sensor_3_fail ; HUD reports a fail
645 661
646 check_sensor_3_ok: 662 check_sensor_3_ok:
647 ; o2_ppo2_sensor3 := o2_mv_sensor3:2 * opt_x_s1:2 / 1000 663 ; o2_ppo2_sensor3 := o2_mv_sensor3:2 * opt_x_s1:2 / 1000
648 movff o2_mv_sensor3+0,xA+0 664 movff o2_mv_sensor3+0,xA+0
649 movff o2_mv_sensor3+1,xA+1 665 movff o2_mv_sensor3+1,xA+1
650 movff opt_x_s3+0,xB+0 666 movff opt_x_s3+0,xB+0
651 movff opt_x_s3+1,xB+1 667 movff opt_x_s3+1,xB+1
652 rcall compute_ppo2_helper 668 rcall compute_ppo2_helper
653 movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar 669 movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar
654 bra calc_deko_divemode_sensor1 ; continue with calculating sensor average 670 bra calc_deko_divemode_sensor1 ; continue with calculating sensor average
655 671
656 check_sensor_3_fail: 672 check_sensor_3_fail:
657 clrf WREG 673 clrf WREG
658 movff WREG,o2_ppo2_sensor3 ; set ppO2 reading to zero 674 movff WREG,o2_ppo2_sensor3 ; set ppO2 reading to zero
659 btfss use_O2_sensor3 ; check if sensor was in use before 675 btfss use_O2_sensor3 ; check if sensor was in use before
660 bra check_sensor_3_fail_1 ; NO - no new news then 676 bra check_sensor_3_fail_1 ; NO - no new news then
661 call check_sensor_custview_helper ; YES - show customview 1 (sensor values) on further conditions met 677 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met
662 check_sensor_3_fail_1: 678 check_sensor_3_fail_1:
663 bcf use_O2_sensor3 ; revoke sensor from usage 679 bcf use_O2_sensor3 ; revoke sensor from usage
664 ;bra calc_deko_divemode_sensor1 ; continue with calculating sensor average 680 ;bra calc_deko_divemode_sensor1 ; continue with calculating sensor average
665 681
666 calc_deko_divemode_sensor1: ; calculate sensor average 682 calc_deko_divemode_sensor1: ; calculate sensor average
667 ; exit here if not in divemode 683 ; exit here if not in divemode
668 btfss divemode 684 btfss divemode
669 return 685 return
670 686
671 ; compute sensor_setpoint := average of all o2_ppo2_sensorX of those sensors that have use_O2_sensorX == true 687 ; compute sensor_setpoint := average of all o2_ppo2_sensorX of those sensors that have use_O2_sensorX == true
672 ; sum up sensor values (in xA:2) and active sensors in (xB:2) 688 ; sum up sensor values (in xA:2) and active sensors in (xB:2)
673 clrf xB+0 689 clrf xB+0
674 clrf xB+1 690 clrf xB+1
675 clrf xA+0 691 clrf xA+0
676 clrf xA+1 692 clrf xA+1
677 btfss use_O2_sensor1 ; Sensor1 active? 693 btfss use_O2_sensor1 ; Sensor1 active?
678 bra divemode_setup_sensor_values2 ; No 694 bra divemode_setup_sensor_values2 ; No
679 movf o2_ppo2_sensor1,W 695 movf o2_ppo2_sensor1,W
680 addwf xA+0 696 addwf xA+0
681 movlw .0 697 movlw .0
682 addwfc xA+1 ; Add into xA:2 698 addwfc xA+1 ; Add into xA:2
683 incf xB+0,F ; Add a sensor 699 incf xB+0,F ; Add a sensor
684 divemode_setup_sensor_values2: 700 divemode_setup_sensor_values2:
685 btfss use_O2_sensor2 ; Sensor2 active? 701 btfss use_O2_sensor2 ; Sensor2 active?
686 bra divemode_setup_sensor_values3 ; No 702 bra divemode_setup_sensor_values3 ; No
687 movf o2_ppo2_sensor2,W 703 movf o2_ppo2_sensor2,W
688 addwf xA+0 704 addwf xA+0
689 movlw .0 705 movlw .0
690 addwfc xA+1 ; Add into xA:2 706 addwfc xA+1 ; Add into xA:2
691 incf xB+0,F ; Add a sensor 707 incf xB+0,F ; Add a sensor
692 divemode_setup_sensor_values3: 708 divemode_setup_sensor_values3:
693 btfss use_O2_sensor3 ; Sensor3 active? 709 btfss use_O2_sensor3 ; Sensor3 active?
694 bra divemode_setup_sensor_values4 ; No 710 bra divemode_setup_sensor_values4 ; No
695 movf o2_ppo2_sensor3,W 711 movf o2_ppo2_sensor3,W
696 addwf xA+0 712 addwf xA+0
697 movlw .0 713 movlw .0
698 addwfc xA+1 ; Add into xA:2 714 addwfc xA+1 ; Add into xA:2
699 incf xB+0,F ; Add a sensor 715 incf xB+0,F ; Add a sensor
700 716
701 ; Divide sum of sensor values by number of active sensors found. 717 ; Divide sum of sensor values by number of active sensors found.
702 divemode_setup_sensor_values4: 718 divemode_setup_sensor_values4:
703 call div16x16 ; xA/xB=xC with xA+0 as remainder 719 call div16x16 ; xA/xB=xC with xA+0 as remainder
704 movff xC+0,sensor_setpoint ; copy result 720 movff xC+0,sensor_setpoint ; copy result
705 721
706 ; set default value for pSCR mode: 0 = let p2_deco.c compute the ppO2 based on current dil gas and depth 722 ; set default value for pSCR mode: 0 = let p2_deco.c compute the ppO2 based on current dil gas and depth
707 ; will be overwritten later in case we are in sensor mode and have at least one usable sensor 723 ; will be overwritten later in case we are in sensor mode and have at least one usable sensor
708 clrf WREG ; preload a zero 724 clrf WREG ; preload a zero
709 btfsc FLAG_pscr_mode ; check if we are in pSCR mode 725 btfsc FLAG_pscr_mode ; check if we are in pSCR mode
710 movff WREG,char_I_const_ppO2 ; YES - write 0 to char_I_const_ppo2, 726 movff WREG,char_I_const_ppO2 ; YES - write 0 to char_I_const_ppo2,
711 ; it will be overwritten if we have a usable sensor reading 727 ; it will be overwritten if we have a usable sensor reading
712 728
713 btfsc is_bailout ; check if we are in bailout 729 btfsc is_bailout ; check if we are in bailout
714 bra calc_deko_divemode_sensor2 ; YES - no sensor data transfer to char_I_const_ppO2 in this case 730 bra calc_deko_divemode_sensor2 ; YES - no sensor data transfer to char_I_const_ppO2 in this case
715 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 731 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP
716 sublw .1 ; opt_ccr_mode = 1 (Sensor)? 732 sublw .1 ; opt_ccr_mode = 1 (Sensor)?
717 bnz calc_deko_divemode_sensor2 ; not in sensor mode - no transfer of sensor data to char_I_const_ppO2 733 bnz calc_deko_divemode_sensor2 ; not in sensor mode - no transfer of sensor data to char_I_const_ppO2
718 tstfsz xB+0 ; check if we have found at least one usable sensor 734 tstfsz xB+0 ; check if we have found at least one usable sensor
719 bra calc_deko_divemode_sensor1a ; YES - we have at least one usable sensor 735 bra calc_deko_divemode_sensor1a ; YES - we have at least one usable sensor
720 bsf setpoint_fallback ; NO - we have NO usable sensors -> initiate fallback 736 bsf setpoint_fallback ; NO - we have NO usable sensors -> initiate fallback
721 btfss FLAG_ccr_mode ; check if we are in CCR mode 737 btfss FLAG_ccr_mode ; check if we are in CCR mode
722 bra calc_deko_divemode_sensor2 ; NO - continue with voting logic flags 738 bra calc_deko_divemode_sensor2 ; NO - continue with voting logic flags
723 movff char_I_setpoint_cbar+0,char_I_const_ppO2 ; YES - select fixed setpoint no. 1 for fallback 739 movff char_I_setpoint_cbar+0,char_I_const_ppO2 ; YES - select fixed setpoint no. 1 for fallback
724 bra calc_deko_divemode_sensor2 ; done - continue with voting logic flags 740 bra calc_deko_divemode_sensor2 ; done - continue with voting logic flags
725 calc_deko_divemode_sensor1a: ; we have at least one usable sensor with a value > 0 741 calc_deko_divemode_sensor1a: ; we have at least one usable sensor with a value > 0
726 bcf setpoint_fallback ; clear fallback condition 742 bcf setpoint_fallback ; clear fallback condition
727 movff sensor_setpoint,char_I_const_ppO2 ; transfer average sensor value to p2_deco.c code 743 movff sensor_setpoint,char_I_const_ppO2 ; transfer average sensor value to p2_deco.c code
728 ; bra calc_deko_divemode_sensor2 744 ;bra calc_deko_divemode_sensor2
729 745
730 calc_deko_divemode_sensor2: 746 calc_deko_divemode_sensor2:
731 bsf voting_logic_sensor1 747 bsf voting_logic_sensor1
732 movff o2_ppo2_sensor1,temp1 748 movff o2_ppo2_sensor1,lo
733 rcall check_sensor_voting_helper 749 rcall check_sensor_voting_helper
734 incfsz WREG ; Was Wreg=255? 750 incfsz WREG ; Was WREG = 255?
735 bcf voting_logic_sensor1 ; No, ignore this sensor 751 bcf voting_logic_sensor1 ; No, ignore this sensor
736 752
737 bsf voting_logic_sensor2 753 bsf voting_logic_sensor2
738 movff o2_ppo2_sensor2,temp1 754 movff o2_ppo2_sensor2,lo
739 rcall check_sensor_voting_helper 755 rcall check_sensor_voting_helper
740 incfsz WREG ; Was Wreg=255? 756 incfsz WREG ; Was WREG=255?
741 bcf voting_logic_sensor2 ; No, ignore this sensor 757 bcf voting_logic_sensor2 ; No, ignore this sensor
742 758
743 bsf voting_logic_sensor3 759 bsf voting_logic_sensor3
744 movff o2_ppo2_sensor3,temp1 760 movff o2_ppo2_sensor3,lo
745 rcall check_sensor_voting_helper 761 rcall check_sensor_voting_helper
746 incfsz WREG ; Was Wreg=255? 762 incfsz WREG ; Was WREG=255?
747 bcf voting_logic_sensor3 ; No, ignore this sensor 763 bcf voting_logic_sensor3 ; No, ignore this sensor
748 764
749 ; check if a warning shall be issued on sensor disagreement 765 ; check if a warning shall be issued on sensor disagreement
750 766
751 btfsc FLAG_ccr_mode ; check if we are in CCR mode 767 btfsc FLAG_ccr_mode ; check if we are in CCR mode
752 bra check_warn_sensor_1 ; YES - continue with further checks 768 bra check_warn_sensor_1 ; YES - continue with further checks
753 btfsc FLAG_pscr_mode ; check if we are in pSCR mode 769 btfsc FLAG_pscr_mode ; check if we are in pSCR mode
754 bra check_warn_sensor_1 ; YES - continue with further checks 770 bra check_warn_sensor_1 ; YES - continue with further checks
755 bra check_warn_sensor_agree ; not in CCR and not in pSCR, so no warning 771 bra check_warn_sensor_agree ; not in CCR and not in pSCR, so no warning
756 check_warn_sensor_1: ; we are in CCR or pSCR mode 772 check_warn_sensor_1: ; we are in CCR or pSCR mode
757 btfsc is_bailout ; check if we are in bailout 773 btfsc is_bailout ; check if we are in bailout
758 bra check_warn_sensor_agree ; YES - no warning in this case 774 bra check_warn_sensor_agree ; YES - no warning in this case
759 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 775 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP
760 sublw .1 ; opt_ccr_mode = 1 (Sensor)? 776 sublw .1 ; opt_ccr_mode = 1 (Sensor)?
761 bnz check_warn_sensor_agree ; not in sensor mode - no warning in this case 777 bnz check_warn_sensor_agree ; not in sensor mode - no warning in this case
762 ; check sensor 1 778 ; check sensor 1
763 btfss sensor1_calibrated_ok ; check if sensor has a valid calibration 779 btfss sensor1_calibrated_ok ; check if sensor has a valid calibration
764 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then 780 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then
765 btfss use_O2_sensor1 ; YES - check if sensor is in use 781 btfss use_O2_sensor1 ; YES - check if sensor is in use
766 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then 782 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then
767 btfsc voting_logic_sensor1 ; YES - check if sensor value is within agreement range 783 btfsc voting_logic_sensor1 ; YES - check if sensor value is within agreement range
768 bra check_warn_sensor_2 ; YES - continue with next sensor 784 bra check_warn_sensor_2 ; YES - continue with next sensor
769 bcf sensors_agree ; NO - issue a warning 785 bcf sensors_agree ; NO - issue a warning
770 return 786 return
771 787
772 check_warn_sensor_2: ; check sensor 2 788 check_warn_sensor_2: ; check sensor 2
773 btfss sensor2_calibrated_ok ; check if sensor has a valid calibration 789 btfss sensor2_calibrated_ok ; check if sensor has a valid calibration
774 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then 790 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then
775 btfss use_O2_sensor2 ; YES - check if sensor is in use 791 btfss use_O2_sensor2 ; YES - check if sensor is in use
776 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then 792 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then
777 btfsc voting_logic_sensor2 ; YES - check if sensor value is within agreement range 793 btfsc voting_logic_sensor2 ; YES - check if sensor value is within agreement range
778 bra check_warn_sensor_3 ; YES - continue with next sensor 794 bra check_warn_sensor_3 ; YES - continue with next sensor
779 bcf sensors_agree ; NO - issue a warning 795 bcf sensors_agree ; NO - issue a warning
780 return 796 return
781 797
782 check_warn_sensor_3: ; check sensor 2 798 check_warn_sensor_3: ; check sensor 2
783 btfss sensor3_calibrated_ok ; check if sensor has a valid calibration 799 btfss sensor3_calibrated_ok ; check if sensor has a valid calibration
784 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then 800 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then
785 btfss use_O2_sensor3 ; YES - check if sensor is in use 801 btfss use_O2_sensor3 ; YES - check if sensor is in use
786 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then 802 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then
787 btfsc voting_logic_sensor3 ; YES - check if sensor value is within agreement range 803 btfsc voting_logic_sensor3 ; YES - check if sensor value is within agreement range
788 bra check_warn_sensor_agree ; YES - continue with next sensor 804 bra check_warn_sensor_agree ; YES - continue with next sensor
789 bcf sensors_agree ; NO - issue a warning 805 bcf sensors_agree ; NO - issue a warning
790 return 806 return
791 807
792 check_warn_sensor_agree: 808 check_warn_sensor_agree:
793 bsf sensors_agree 809 bsf sensors_agree
794 return 810 return
795 811
796 compute_ppo2_helper: 812 compute_ppo2_helper:
797 call mult16x16 ;xA:2*xB:2=xC:4 813 call mult16x16 ; xA:2*xB:2=xC:4
798 movlw LOW .1000 814 movlw LOW .1000
799 movwf xB+0 815 movwf xB+0
800 movlw HIGH .1000 816 movlw HIGH .1000
801 movwf xB+1 817 movwf xB+1
802 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder 818 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
803 movlw d'1' 819 movlw d'1'
804 addwf xC+0,W ; we are just interessed in the carry flag 820 addwf xC+0,W ; we are just interested in the carry flag
805 movlw d'0' 821 movlw d'0'
806 addwfc xC+1,W ; we are still just interessed in the carry flag 822 addwfc xC+1,W ; we are still just interested in the carry flag
807 tstfsz WREG ; ppO2 is higher than 2.55bar? 823 tstfsz WREG ; ppO2 is higher than 2.55bar?
808 setf xC+0 ; Yes. 824 setf xC+0 ; Yes.
809 return 825 return
810 826
811 check_sensor_custview_helper: 827 check_sensor_custview_helper:
812 btfss divemode ; check if we are in divemode 828 btfss divemode ; check if we are in divemode
813 return ; NO - not in dive mode, return 829 return ; NO - not in dive mode, return
814 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 830 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP
815 sublw .1 ; opt_ccr_mode = 1 (Sensors)? 831 sublw .1 ; opt_ccr_mode = 1 (Sensors)?
816 bnz check_sensor_helper_1 ; NO - not using the sensors in the moment 832 bnz check_sensor_helper_1 ; NO - not using the sensors in the moment
817 clrf menupos3 ; YES - arm customview 1 (sensor values) 833 clrf menupos3 ; YES - arm customview 1 (sensor values)
818 bsf toggle_customview ; and request a customview toggle 834 bsf toggle_customview ; and request a customview toggle
819 check_sensor_helper_1: 835 check_sensor_helper_1:
820 return 836 return
821 837
822 838
823 check_sensor_voting_helper: 839 check_sensor_voting_helper:
824 movf temp1,W 840 movf lo,W
825 cpfsgt sensor_setpoint 841 cpfsgt sensor_setpoint
826 bra check_sensor_voting_common2 ; temp1<sensor_setpoint 842 bra check_sensor_voting_common2 ; lo < sensor_setpoint
827 ; temp1>sensor_setpoint 843 ; lo > sensor_setpoint
828 movf temp1,W 844 movf lo,W
829 subwf sensor_setpoint,W 845 subwf sensor_setpoint,W
830 movwf temp1 846 movwf lo
831 check_sensor_voting_common1: 847 check_sensor_voting_common1:
832 movlw sensor_voting_logic_threshold ; Threshold in 0.01 bar 848 movlw sensor_voting_logic_threshold ; Threshold in 0.01 bar
833 cpfsgt temp1 849 cpfsgt lo
834 retlw .255 ; Within range 850 retlw .255 ; Within range
835 retlw .0 ; Out of range 851 retlw .0 ; Out of range
836 check_sensor_voting_common2: 852 check_sensor_voting_common2:
837 ; temp1<sensor_setpoint 853 ; lo<sensor_setpoint
838 movf sensor_setpoint,W 854 movf sensor_setpoint,W
839 subwf temp1,F 855 subwf lo,F
840 bra check_sensor_voting_common1 856 bra check_sensor_voting_common1
841 857
842 ;----------------------------------------------------------------------------- 858 ;-----------------------------------------------------------------------------
843 859
844 divemodemode_togglegf: ; Toggle aGF/GF 860 divemodemode_togglegf: ; Toggle aGF/GF
845 bcf toggle_gf ; clear flag 861 bcf toggle_gf ; clear flag
846 btg use_agf ; toggle GF 862 btg use_agf ; toggle GF
847 863
848 movff opt_GF_low,char_I_GF_Low_percentage 864 btfsc use_agf ; switch to aGF?
849 movff opt_GF_high,char_I_GF_High_percentage 865 bra divemodemode_togglegf_1 ; YES - branch to using aGF
850 866 movff opt_GF_low,char_I_GF_Low_percentage ; NO - use normal GF factors
851 ; Overwrite GF if aGF is wanted 867 movff opt_GF_high,char_I_GF_High_percentage ;
852 btfsc use_agf ; =1: Use aGF 868 bra divemodemode_togglegf_2 ; continue with common part
869
870 divemodemode_togglegf_1: ; use alternative GF factors
853 movff opt_aGF_low,char_I_GF_Low_percentage 871 movff opt_aGF_low,char_I_GF_Low_percentage
854 btfsc use_agf ; =1: Use aGF
855 movff opt_aGF_high,char_I_GF_High_percentage 872 movff opt_aGF_high,char_I_GF_High_percentage
856 873
857 call TFT_gf_mask ; Setup Mask 874 divemodemode_togglegf_2:
858 goto restart_deco_engine ; ...and return 875 call TFT_gf_mask ; update customview mask to show which one is in use
859 876 ; the customview itself has been called from divemenu_tree before
860 877 goto restart_deco_engine ; ...and return
861 calc_velocity: ; called every two seconds 878
862 btfsc display_velocity 879
863 bra calc_velocity1 ; Always update if already displayed 880 calc_velocity: ; called every two seconds
864 btfss divemode2 881 btfsc display_velocity
865 return ; display velocity only if deepter then 1m (Not at the surface after the dive) 882 bra calc_velocity1 ; Always update if already displayed
883 btfss divemode2
884 return ; display velocity only if deeper then 1m (Not at the surface after the dive)
866 calc_velocity1: 885 calc_velocity1:
867 SAFE_2BYTE_COPY amb_pressure, sub_a 886 SAFE_2BYTE_COPY amb_pressure, sub_a
868 movff last_pressure_velocity+0,sub_b+0 887 movff last_pressure_velocity+0,sub_b+0
869 movff last_pressure_velocity+1,sub_b+1 888 movff last_pressure_velocity+1,sub_b+1
870 movff sub_a+0,last_pressure_velocity+0 ; store old value for velocity 889 movff sub_a+0,last_pressure_velocity+0 ; store old value for velocity
871 movff sub_a+1,last_pressure_velocity+1 890 movff sub_a+1,last_pressure_velocity+1
872 891
873 call subU16 ; sub_c = amb_pressure - last_pressure 892 call subU16 ; sub_c = amb_pressure - last_pressure
874 893
875 bcf neg_flag_velocity 894 bcf neg_flag_velocity
876 btfsc neg_flag 895 btfsc neg_flag
877 bsf neg_flag_velocity 896 bsf neg_flag_velocity
878 897
879 movff sub_c+0,xA+0 898 movff sub_c+0,xA+0
880 movff sub_c+1,xA+1 899 movff sub_c+1,xA+1
881 movlw d'39' ; 77 when called every second.... 900 movlw d'39' ; 77 when called every second....
882 movwf xB+0 901 movwf xB+0
883 clrf xB+1 902 clrf xB+1
884 call mult16x16 ; differential pressure in mbar*77... 903 call mult16x16 ; differential pressure in mbar*77...
885 movff xC+0,divA+0 904 movff xC+0,divA+0
886 movff xC+1,divA+1 905 movff xC+1,divA+1
887 movlw d'7' 906 movlw d'7'
888 movwf divB+0 907 movwf divB+0
889 call div16 ; devided by 2^7 equals velocity in m/min 908 call div16 ; divided by 2^7 equals velocity in m/min
890 909
891 movlw d'99' 910 movlw d'99'
892 cpfsgt divA+0 ; limit to 99m/min 911 cpfsgt divA+0 ; limit to 99m/min
893 bra calc_velocity3 912 bra calc_velocity3
894 movwf divA+0 ; divA=99 913 movwf divA+0 ; divA=99
895 914
896 calc_velocity3: 915 calc_velocity3:
897 ; Copy old speeds 916 ; Copy old speeds
898 movff old_velocity+2,old_velocity+3 917 movff old_velocity+2,old_velocity+3
899 movff old_velocity+1,old_velocity+2 918 movff old_velocity+1,old_velocity+2
900 movff old_velocity+0,old_velocity+1 919 movff old_velocity+0,old_velocity+1
901 movff divA+0,old_velocity+0 920 movff divA+0,old_velocity+0
902 921
903 ; movff old_velocity+3,WREG 922 ; movff old_velocity+3,WREG
904 ; addwf divA+0,F ; add old speed 923 ; addwf divA+0,F ; add old speed
905 ; bcf STATUS,C 924 ; bcf STATUS,C
906 ; rrcf divA+0,F ; /2 925 ; rrcf divA+0,F ; /2
907 ; movff old_velocity+2,WREG 926 ; movff old_velocity+2,WREG
908 ; addwf divA+0,F ; add old speed 927 ; addwf divA+0,F ; add old speed
909 ; bcf STATUS,C 928 ; bcf STATUS,C
910 ; rrcf divA+0,F ; /2 929 ; rrcf divA+0,F ; /2
911 ; movff old_velocity+1,WREG 930 ; movff old_velocity+1,WREG
912 ; addwf divA+0,F ; add old speed 931 ; addwf divA+0,F ; add old speed
913 ; bcf STATUS,C 932 ; bcf STATUS,C
914 ; rrcf divA+0,F ; /2 933 ; rrcf divA+0,F ; /2
915 ; movff old_velocity+0,WREG 934 ; movff old_velocity+0,WREG
916 ; addwf divA+0,F ; add old speed 935 ; addwf divA+0,F ; add old speed
917 ; bcf STATUS,C 936 ; bcf STATUS,C
918 ; rrcf divA+0,F ; /2 937 ; rrcf divA+0,F ; /2
919 goto TFT_display_velocity ; With divA+0 = m/min..., and return... 938 goto TFT_display_velocity ; With divA+0 = m/min..., and return...
920 939
921 940
922 ;============================================================================= 941 ;=============================================================================
923 942
924 set_reset_safety_stop: ; Set flags for safety stop and/or reset safety stop 943 set_reset_safety_stop: ; Set flags for safety stop and/or reset safety stop
925 TSTOSS opt_enable_safetystop ; =1: A safety stop is shown 944 TSTOSS opt_enable_safetystop ; =1: A safety stop is shown
926 bra delete_safety_stop ; No, don't show safety stop 945 bra delete_safety_stop ; No, don't show safety stop
927 946
928 btfsc decostop_active ; Is a deco stop displayed? 947 btfsc decostop_active ; Is a deco stop displayed?
929 bra delete_safety_stop ; Yes, don't show safety stop 948 bra delete_safety_stop ; Yes, don't show safety stop
930 949
931 ; Below "opt_safety_stop_reset"? Set flag and reset count-down timer 950 ; Below "opt_safety_stop_reset"? Set flag and reset count-down timer
932 SAFE_2BYTE_COPY rel_pressure, lo 951 SAFE_2BYTE_COPY rel_pressure, lo
933 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar] 952 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar]
934 movff lo,sub_a+0 953 movff lo,sub_a+0
935 movff hi,sub_a+1 954 movff hi,sub_a+1
936 movff opt_safety_stop_reset,WREG ; [cbar] 955 movff opt_safety_stop_reset,WREG ; [cbar]
937 mullw .10 ; mbar in PRODL:H 956 mullw .10 ; mbar in PRODL:H
938 movff PRODL,sub_b+0 957 movff PRODL,sub_b+0
939 movff PRODH,sub_b+1 958 movff PRODH,sub_b+1
940 call subU16 ; sub_c = sub_a - sub_b 959 call subU16 ; sub_c = sub_a - sub_b
941 btfss neg_flag 960 btfss neg_flag
942 bra reset_safety_stop ; Below 10m, reset safety stop 961 bra reset_safety_stop ; Below 10m, reset safety stop
943 962
944 ; Above "opt_safety_stop_end"? Clear flag. 963 ; Above "opt_safety_stop_end"? Clear flag.
945 SAFE_2BYTE_COPY rel_pressure, lo 964 SAFE_2BYTE_COPY rel_pressure, lo
946 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar] 965 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar]
947 movff lo,sub_a+0 966 movff lo,sub_a+0
948 movff hi,sub_a+1 967 movff hi,sub_a+1
949 movff opt_safety_stop_end,WREG ; [cbar] 968 movff opt_safety_stop_end,WREG ; [cbar]
950 mullw .10 ; mbar in PRODL:H 969 mullw .10 ; mbar in PRODL:H
951 movff PRODL,sub_b+0 970 movff PRODL,sub_b+0
952 movff PRODH,sub_b+1 971 movff PRODH,sub_b+1
953 call subU16 ; sub_c = sub_a - sub_b 972 call subU16 ; sub_c = sub_a - sub_b
954 btfsc neg_flag 973 btfsc neg_flag
955 bra delete_safety_stop ; Above 3m, remove safety stop 974 bra delete_safety_stop ; Above 3m, remove safety stop
956 975
957 ; Above "opt_safety_stop_start"? Activate safety stop 976 ; Above "opt_safety_stop_start"? Activate safety stop
958 SAFE_2BYTE_COPY rel_pressure, lo 977 SAFE_2BYTE_COPY rel_pressure, lo
959 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar] 978 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar]
960 movff lo,sub_a+0 979 movff lo,sub_a+0
961 movff hi,sub_a+1 980 movff hi,sub_a+1
962 movff opt_safety_stop_start,WREG ; [cbar] 981 movff opt_safety_stop_start,WREG ; [cbar]
963 mullw .10 ; mbar in PRODL:H 982 mullw .10 ; mbar in PRODL:H
964 movff PRODL,sub_b+0 983 movff PRODL,sub_b+0
965 movff PRODH,sub_b+1 984 movff PRODH,sub_b+1
966 call subU16 ; sub_c = sub_a - sub_b 985 call subU16 ; sub_c = sub_a - sub_b
967 btfsc neg_flag 986 btfsc neg_flag
968 bra acivate_safety_stop ; Above 5m, activate safety stop 987 bra acivate_safety_stop ; Above 5m, activate safety stop
969 bra reset_safety_stop2 ; Pause safety stop 988 bra reset_safety_stop2 ; Pause safety stop
970 989
971 acivate_safety_stop: 990 acivate_safety_stop:
972 tstfsz safety_stop_countdown ; Countdown at zero? 991 tstfsz safety_stop_countdown ; Countdown at zero?
973 bsf show_safety_stop ; No, Set flag! 992 bsf show_safety_stop ; No, Set flag!
974 return 993 return
975 994
976 delete_safety_stop: 995 delete_safety_stop:
977 clrf safety_stop_countdown ; reset timer 996 clrf safety_stop_countdown ; reset timer
978 bra reset_safety_stop2 ; Remove safety stop from display 997 bra reset_safety_stop2 ; Remove safety stop from display
979 998
980 reset_safety_stop: 999 reset_safety_stop:
981 movff opt_safety_stop_length,safety_stop_countdown ; reset timer 1000 movff opt_safety_stop_length,safety_stop_countdown ; reset timer
982 reset_safety_stop2: 1001 reset_safety_stop2:
983 bcf show_safety_stop ; Clear flag 1002 bcf show_safety_stop ; Clear flag
984 btfss safety_stop_active ; Safety stop shown 1003 btfss safety_stop_active ; Safety stop shown
985 return ; No, don't delete it 1004 return ; No, don't delete it
986 bcf safety_stop_active ; Clear flag 1005 bcf safety_stop_active ; Clear flag
987 bsf FLAG_TFT_clear_safety_stop ; Clear safety stop 1006 bsf FLAG_TFT_clear_safety_stop ; Clear safety stop
988 return 1007 return
989 1008
990 1009
991 ;============================================================================= 1010 ;=============================================================================
992 1011
993 timeout_menuview: 1012 timeout_menuview:
994 decfsz timeout_counter3,F ; timeout for menuview 1013 decfsz timeout_counter2,F ; timeout for menuview
995 return ; No timeout, return 1014 return ; No timeout, return
996 ; Timeout, clear e.g. "Menu?" 1015 ; Timeout, clear e.g. "Menu?"
997 goto menuview_toggle_reset ; "returns" 1016 goto menuview_toggle_reset ; "returns"
998 1017
999 timeout_divemode_menu: 1018 timeout_divemode_menu:
1000 decfsz timeout_counter3,F ; timeout for divemode menu 1019 decfsz timeout_counter2,F ; timeout for divemode menu
1001 return 1020 return
1002 1021
1003 global timeout_divemode_menu2 1022 global timeout_divemode_menu2
1004 timeout_divemode_menu2: ; Called from divemenu_tree.asm 1023 timeout_divemode_menu2: ; Called from divemenu_tree.asm
1005 bcf divemode_menu ; Timeout! Clear flag 1024 bcf divemode_menu ; Timeout! Clear flag
1006 call TFT_clear_divemode_menu ; Clear menu 1025 call TFT_clear_divemode_menu ; Clear menu
1007 bsf FLAG_TFT_active_gas_divemode; Redraw gas/setpoint/diluent 1026 bsf FLAG_TFT_active_gas_divemode; Redraw gas/setpoint/diluent
1008 bcf blinking_better_gas ; Clear flag to have temperature updated once 1027 bcf blinking_better_gas ; Clear flag to have temperature updated once
1009 bsf FLAG_TFT_temp_divemode ; Displays temperature 1028 bsf FLAG_TFT_temp_divemode ; Displays temperature
1010 call TFT_draw_gassep_line ; Gas separator grid in spec mode only 1029 call TFT_draw_gassep_line ; Gas separator grid in spec mode only
1011 1030
1012 btfss decostop_active ; In deco mode ? 1031 btfss decostop_active ; In deco mode ?
1013 bra timeout_divemode_menu_ndl ; No, show NDL again 1032 bra timeout_divemode_menu_ndl ; No, show NDL again
1014 ; Show deco 1033 ; Show deco
1015 bsf FLAG_TFT_display_deko_mask 1034 bsf FLAG_TFT_display_deko_mask
1016 bsf FLAG_TFT_display_deko 1035 bsf FLAG_TFT_display_deko
1017 bsf FLAG_TFT_display_tts 1036 bsf FLAG_TFT_display_tts
1018 return 1037 return
1019 1038
1020 timeout_divemode_menu_ndl: 1039 timeout_divemode_menu_ndl:
1021 ; Show NDL 1040 ; Show NDL
1022 bsf FLAG_TFT_display_ndl_mask 1041 bsf FLAG_TFT_display_ndl_mask
1023 bsf FLAG_TFT_display_ndl 1042 bsf FLAG_TFT_display_ndl
1024 return 1043 return
1025 1044
1026 timeout_divemode: 1045 timeout_divemode:
1027 btfsc divemode_menu ; Divemode menu active? 1046 btfsc divemode_menu ; Divemode menu active?
1028 rcall timeout_divemode_menu ; Yes, check the timeout for it... 1047 rcall timeout_divemode_menu ; Yes, check the timeout for it...
1029 1048
1030 btfsc menuview ; is a menuview shown? 1049 btfsc menuview ; is a menuview shown?
1031 rcall timeout_menuview ; Yes, check the timeout for it... 1050 rcall timeout_menuview ; Yes, check the timeout for it...
1032 1051
1033 btfss realdive ; Dive longer then one minute 1052 btfss realdive ; Dive longer then one minute
1034 return 1053 return
1035 1054
1036 btfsc FLAG_apnoe_mode ; In Apnoe mode? 1055 btfsc FLAG_apnoe_mode ; In Apnoe mode?
1037 bra timeout_divemode2 ; Yes, use apnoe_timeout [min] for timeout 1056 bra timeout_divemode2 ; Yes, use apnoe_timeout [min] for timeout
1038 1057
1039 ifndef __DEBUG 1058 ifndef __DEBUG
1040 btfsc simulatormode_active ; In Simulator mode? 1059 btfsc simulatormode_active ; In Simulator mode?
1041 bra timeout_divemode3 ; Yes, use simulator timeout 1060 bra timeout_divemode3 ; Yes, use simulator timeout
1042 endif 1061 endif
1043 1062
1044 bcf divemode 1063 bcf divemode
1045 infsnz timeout_counter,F 1064 infsnz timeout_counter1+0,F
1046 incf timeout_counter2,F ; timeout is 15bits 1065 incf timeout_counter1+1,F ; timeout is 16 bit counter
1047 1066
1048 movff opt_diveTimeout,WREG ; in [min] 1067 movff opt_diveTimeout,WREG ; in [min]
1049 mullw .60 1068 mullw .60
1050 movff PRODL,sub_a+0 1069 movff PRODL,sub_a+0
1051 movff PRODH,sub_a+1 ; in [s] 1070 movff PRODH,sub_a+1 ; in [s]
1052 1071
1053 movff timeout_counter, sub_b+0 1072 movff timeout_counter1+0,sub_b+0
1054 movff timeout_counter2, sub_b+1 1073 movff timeout_counter1+1,sub_b+1
1055 call subU16 ; sub_c = sub_a - sub_b 1074 call subU16 ; sub_c = sub_a - sub_b
1056 btfss neg_flag ; Result negative? 1075 btfss neg_flag ; Result negative?
1057 bsf divemode ; No, set flag 1076 bsf divemode ; No, set flag
1058 return 1077 return
1059 1078
1060 timeout_divemode2: 1079 timeout_divemode2:
1061 incf timeout_counter,F ; seconds... 1080 incf timeout_counter1+0,F ; seconds...
1062 movlw d'60' 1081 movlw d'60'
1063 cpfseq timeout_counter ; timeout_counter=60? 1082 cpfseq timeout_counter1+0 ; timeout_counter1+0 = 60 ?
1064 return ; No. 1083 return ; No
1065 ; One minute timeout done. 1084 ; one minute timeout done
1066 clrf timeout_counter 1085 clrf timeout_counter1+0
1067 bcf divemode 1086 bcf divemode
1068 incf apnoe_timeout_counter,F 1087 incf apnoe_timeout_counter,F
1069 movlw apnoe_timeout ; apnoe timeout [min] 1088 movlw apnoe_timeout ; apnoe timeout [min]
1070 cpfseq apnoe_timeout_counter 1089 cpfseq apnoe_timeout_counter
1071 bsf divemode 1090 bsf divemode
1072 return 1091 return
1073 1092
1074 timeout_divemode3: 1093 timeout_divemode3:
1075 bcf divemode 1094 bcf divemode
1076 incf timeout_counter,F 1095 incf timeout_counter1+0,F
1077 movlw simulator_timeout ; simulator timeout 1096 movlw simulator_timeout ; simulator timeout
1078 cpfsgt timeout_counter 1097 cpfsgt timeout_counter1+0
1079 bsf divemode 1098 bsf divemode
1080 return 1099 return
1081 1100
1082 update_divemode60: ; update any minute 1101 update_divemode60: ; update any minute
1083 call get_battery_voltage ; gets battery voltage 1102 call get_battery_voltage ; gets battery voltage
1084 rcall set_powersafe ; Battery low? 1103 rcall set_powersafe ; Battery low?
1085 call customview_minute ; Do every-minute tasks for the custom view area 1104 call customview_minute ; Do every-minute tasks for the custom view area
1086 bcf oneminupdate 1105 bcf oneminupdate
1087 1106
1088 btfss simulatormode_active ; in simulator mode? 1107 btfss simulatormode_active ; in simulator mode?
1089 return ; No 1108 return ; No
1090 ; Yes, quite dive mode simulation after 21*256s=89min:36s 1109 ; Yes, quite dive mode simulation after 21*256s=89min:36s
1091 movlw .20 1110 movlw .20
1092 cpfsgt total_divetime_seconds+1 ; Timeout? 1111 cpfsgt total_divetime_seconds+1 ; Timeout?
1093 return ; No 1112 return ; No
1094 ifdef __DEBUG 1113
1095 return ; No simulator timeout in debug mode 1114 ifdef __DEBUG
1096 endif 1115 return ; No simulator timeout in debug mode
1097 bra divemode_option1 ; Yes, set to 0m and "return" 1116 endif
1117
1118 bra divemode_option1 ; Yes, set to 0m and "return"
1098 1119
1099 set_max_depth: 1120 set_max_depth:
1100 movff max_pressure+0,sub_a+0 1121 movff max_pressure+0,sub_a+0
1101 movff max_pressure+1,sub_a+1 1122 movff max_pressure+1,sub_a+1
1102 SAFE_2BYTE_COPY rel_pressure, sub_b 1123 SAFE_2BYTE_COPY rel_pressure, sub_b
1103 call subU16 ; sub_c = sub_a - sub_b 1124 call subU16 ; sub_c = sub_a - sub_b
1104 ; max_pressure<rel_pressure -> neg_flag=1 1125 ; max_pressure<rel_pressure -> neg_flag=1
1105 ; rel_pressure<=max_pressure -> neg_flag=0 1126 ; rel_pressure<=max_pressure -> neg_flag=0
1106 btfss neg_flag 1127 btfss neg_flag
1107 return 1128 return
1108 ; max_pressure<rel_pressure 1129 ; max_pressure<rel_pressure
1109 movff sub_b+0,max_pressure+0 1130 movff sub_b+0,max_pressure+0
1110 movff sub_b+1,max_pressure+1 1131 movff sub_b+1,max_pressure+1
1111 bsf FLAG_TFT_max_depth ; Set flag 1132 bsf FLAG_TFT_max_depth ; Set flag
1112 return 1133 return
1113 1134
1114 set_min_temp: 1135 set_min_temp:
1115 movff minimum_temperature+0,sub_a+0 1136 movff minimum_temperature+0,sub_a+0
1116 movff minimum_temperature+1,sub_a+1 1137 movff minimum_temperature+1,sub_a+1
1117 SAFE_2BYTE_COPY temperature,sub_b 1138 SAFE_2BYTE_COPY temperature,sub_b
1118 call sub16 ; sub_c = sub_a - sub_b 1139 call sub16 ; sub_c = sub_a - sub_b
1119 ; minimum_temperature<T -> neg_flag=1 1140 ; minimum_temperature<T -> neg_flag=1
1120 ; T<=minimum_temperature -> neg_flag=0 1141 ; T<=minimum_temperature -> neg_flag=0
1121 btfsc neg_flag 1142 btfsc neg_flag
1122 return 1143 return
1123 ; minimum_temperature>=T 1144 ; minimum_temperature >= T
1124 movff sub_b+0,minimum_temperature+0 1145 movff sub_b+0,minimum_temperature+0
1125 movff sub_b+1,minimum_temperature+1 1146 movff sub_b+1,minimum_temperature+1
1126 return 1147 return
1127 1148
1128 global set_dive_modes 1149 global set_dive_modes
1129 set_dive_modes: 1150 set_dive_modes:
1130 btfsc high_altitude_mode ; In high altitude (Fly) mode? 1151 btfsc high_altitude_mode ; In high altitude (Fly) mode?
1131 bra set_dive_modes3 ; Yes! 1152 bra set_dive_modes3 ; Yes!
1132 1153
1133 set_dive_modes0: 1154 set_dive_modes0:
1134 movlw LOW start_dive_threshold 1155 movlw LOW start_dive_threshold
1135 movwf sub_a+0 ; dive_treshold is in cm 1156 movwf sub_a+0 ; dive_treshold is in cm
1136 movlw HIGH start_dive_threshold 1157 movlw HIGH start_dive_threshold
1137 movwf sub_a+1 ; dive_treshold is in cm 1158 movwf sub_a+1 ; dive_treshold is in cm
1138 1159
1139 set_dive_modes1: 1160 set_dive_modes1:
1140 SAFE_2BYTE_COPY rel_pressure, sub_b 1161 SAFE_2BYTE_COPY rel_pressure, sub_b
1141 call subU16 ; sub_c = sub_a - sub_b 1162 call subU16 ; sub_c = sub_a - sub_b
1142 1163
1143 btfss neg_flag 1164 btfss neg_flag
1144 bra set_dive_modes2 ; too shallow (rel_pressure<dive_threshold) 1165 bra set_dive_modes2 ; too shallow (rel_pressure < dive_threshold)
1145 1166
1146 btfsc realdive ; Dive longer than one minute? 1167 btfsc realdive ; Dive longer than one minute?
1147 clrf timeout_counter ; Yes, reset timout counter 1168 clrf timeout_counter1+0 ; Yes, reset timeout counter +++
1148 1169
1149 bsf divemode ; (Re-)Set divemode flag 1170 bsf divemode ; (Re-)Set divemode flag
1150 bsf divemode2 ; displayed divetime is running 1171 bsf divemode2 ; displayed divetime is running
1151 return 1172 return
1152 1173
1159 1180
1160 set_dive_modes3: ; High-altitude mode 1181 set_dive_modes3: ; High-altitude mode
1161 btfsc realdive ; dive longer then one minute? 1182 btfsc realdive ; dive longer then one minute?
1162 bra set_dive_modes0 ; Yes -> this is a real dive -> Use start_dive_threshold or ascend 1183 bra set_dive_modes0 ; Yes -> this is a real dive -> Use start_dive_threshold or ascend
1163 1184
1164 movlw HIGH high_altitude_dive_threshold 1185 movlw LOW high_altitude_dive_threshold
1186 movwf sub_a+0
1187 movlw HIGH high_altitude_dive_threshold
1165 movwf sub_a+1 1188 movwf sub_a+1
1166 movlw LOW high_altitude_dive_threshold
1167 movwf sub_a+0
1168 bra set_dive_modes1 1189 bra set_dive_modes1
1169 1190
1170 set_powersafe: 1191 set_powersafe:
1171 movlw color_code_battery_low+1; [%] 1192 movlw color_code_battery_low+1; [%]
1172 cpfslt batt_percent 1193 cpfslt batt_percent
1173 return 1194 return
1174 1195
1175 movlw d'7' ; Type of Alarm (Battery Low) 1196 movlw d'7' ; Type of Alarm (Battery Low)
1176 movwf AlarmType ; Copy to Alarm Register 1197 movwf AlarmType ; Copy to Alarm Register
1177 bsf event_occured ; Set Event Flag 1198 bsf event_occured ; set event flag
1178 movlw .0 1199 movlw .0
1179 movff WREG,opt_brightness ; Set Brightness to ECO 1200 movff WREG,opt_brightness ; Set Brightness to ECO
1180 return ; return 1201 return ; return
1181 1202
1182 calc_average_depth: 1203 calc_average_depth:
1183 btfsc reset_average_depth ; Reset the Average depth? 1204 btfsc reset_average_depth ; Reset the Average depth?
1184 rcall reset_average1 ; Reset the resettable average depth 1205 rcall reset_average1 ; Reset the resettable average depth
1185 1206
1186 ; 1. Add new 2xdepth to the Sum of depths registers 1207 ; 1. Add new 2xdepth to the Sum of depths registers
1187 SAFE_2BYTE_COPY rel_pressure, xB ; Buffer... 1208 SAFE_2BYTE_COPY rel_pressure,xB ; Buffer...
1188 bcf STATUS,C 1209 bcf STATUS,C
1189 rlcf xB+0,F 1210 rlcf xB+0,F
1190 rlcf xB+1,F ; x2 1211 rlcf xB+1,F ; x2
1191 1212
1192 movf xB+0,w 1213 movf xB+0,w
1193 addwf average_depth_hold+0,F 1214 addwf average_depth_hold+0,F
1194 movf xB+1,w 1215 movf xB+1,w
1195 addwfc average_depth_hold+1,F 1216 addwfc average_depth_hold+1,F
1196 movlw d'0' 1217 movlw d'0'
1197 addwfc average_depth_hold+2,F 1218 addwfc average_depth_hold+2,F
1198 addwfc average_depth_hold+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar 1219 addwfc average_depth_hold+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar
1199 1220
1200 ; Do the same for the _total registers (Non-Resettable) 1221 ; Do the same for the _total registers (Non-Resettable)
1201 movf xB+0,w 1222 movf xB+0,w
1202 addwf average_depth_hold_total+0,F 1223 addwf average_depth_hold_total+0,F
1203 movf xB+1,w 1224 movf xB+1,w
1204 addwfc average_depth_hold_total+1,F 1225 addwfc average_depth_hold_total+1,F
1205 movlw d'0' 1226 movlw d'0'
1206 addwfc average_depth_hold_total+2,F 1227 addwfc average_depth_hold_total+2,F
1207 addwfc average_depth_hold_total+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar 1228 addwfc average_depth_hold_total+3,F; Will work up to 9999mbar*60*60*24=863913600mbar
1208 1229
1209 ; 2. Compute Average Depth on base of average_divesecs:2 1230 ; 2. Compute Average Depth on base of average_divesecs:2
1210 movff average_divesecs+0,xB+0 1231 movff average_divesecs+0,xB+0
1211 movff average_divesecs+1,xB+1 ; Copy 1232 movff average_divesecs+1,xB+1 ; Copy
1212 movff average_depth_hold+0,xC+0 1233 movff average_depth_hold+0,xC+0
1213 movff average_depth_hold+1,xC+1 1234 movff average_depth_hold+1,xC+1
1214 movff average_depth_hold+2,xC+2 1235 movff average_depth_hold+2,xC+2
1215 movff average_depth_hold+3,xC+3 1236 movff average_depth_hold+3,xC+3
1216 1237
1217 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder 1238 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
1218 movff xC+0,avg_rel_pressure+0 1239 movff xC+0,avg_rel_pressure+0
1219 movff xC+1,avg_rel_pressure+1 1240 movff xC+1,avg_rel_pressure+1
1220 1241
1221 btfss divemode2 ; displayed divetime is running? 1242 btfss divemode2 ; displayed divetime is running?
1222 return ; No (e.g. too shallow) 1243 return ; No (e.g. too shallow)
1223 1244
1224 ; 3. Compute Total Average Depth on base of total_divetime_seconds:2 1245 ; 3. Compute Total Average Depth on base of total_divetime_seconds:2
1225 movff total_divetime_seconds+0,xB+0 1246 movff total_divetime_seconds+0,xB+0
1226 movff total_divetime_seconds+1,xB+1 ; Copy 1247 movff total_divetime_seconds+1,xB+1 ; Copy
1227 movff average_depth_hold_total+0,xC+0 1248 movff average_depth_hold_total+0,xC+0
1228 movff average_depth_hold_total+1,xC+1 1249 movff average_depth_hold_total+1,xC+1
1229 movff average_depth_hold_total+2,xC+2 1250 movff average_depth_hold_total+2,xC+2
1230 movff average_depth_hold_total+3,xC+3 1251 movff average_depth_hold_total+3,xC+3
1231 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder 1252 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
1232 movff xC+0,avg_rel_pressure_total+0 1253 movff xC+0,avg_rel_pressure_total+0
1233 movff xC+1,avg_rel_pressure_total+1 1254 movff xC+1,avg_rel_pressure_total+1
1234 return 1255 return
1235 1256
1236 reset_average1: 1257 reset_average1:
1243 clrf average_divesecs+1 1264 clrf average_divesecs+1
1244 bcf reset_average_depth ; Clear flag 1265 bcf reset_average_depth ; Clear flag
1245 return 1266 return
1246 1267
1247 test_switches_divemode: ; checks switches in divemode 1268 test_switches_divemode: ; checks switches in divemode
1248 btfsc divemode_menu ; Divemode menu shown? 1269 btfsc divemode_menu ; Divemode menu shown?
1249 bra test_switches_divemode_menu ; Yes, use menu processor 1270 bra test_switches_divemode_menu ; Yes, use menu processor
1250 btfsc switch_left 1271 btfsc switch_left
1251 ; bra test_switches_divemode2 ; Enter button pressed, check if we need to do something 1272 ;bra test_switches_divemode2 ; Enter button pressed, check if we need to do something
1252 goto menuview_toggle ; Menu or Simulator tasks; and return... 1273 goto menuview_toggle ; Menu or Simulator tasks; and return...
1253 btfss switch_right 1274 btfss switch_right
1254 return ; No button press 1275 return ; No button press
1255 tstfsz menupos2 ; any option shown? 1276 tstfsz menupos2 ; any option shown?
1256 bra test_switches_divemode1 ; Yes, do option tasks 1277 bra test_switches_divemode1 ; Yes, do option tasks
1257 bsf toggle_customview ; No, toggle custom view 1278 bsf toggle_customview ; No, toggle custom view
1258 return 1279 return
1259 1280
1260 test_switches_divemode_menu: 1281 test_switches_divemode_menu:
1261 btfsc switch_left 1282 btfsc switch_left
1262 bra test_switches_divemode_menu2 ; Move cursor 1283 bra test_switches_divemode_menu2; Move cursor
1263 btfsc switch_right 1284 btfsc switch_right
1264 bra test_switches_divemode_menu3 ; Enter submenu or do something 1285 bra test_switches_divemode_menu3; Enter submenu or do something
1265 return ; No button press 1286 return ; No button press
1266 1287
1267 test_switches_divemode_menu1: 1288 test_switches_divemode_menu1:
1268 clrf menupos 1289 clrf menupos1
1269 test_switches_divemode_menu2: 1290 test_switches_divemode_menu2:
1270 incf menupos,F 1291 incf menupos1,F
1271 incf menupos4,W ; menupos4+1 -> WREG 1292 incf menupos4,W ; menupos4+1 -> WREG
1272 cpfslt menupos ; >menupos4 (Set in menu_processor.asm)? 1293 cpfslt menupos1 ; > menupos4 (Set in menu_processor.asm)?
1273 bra test_switches_divemode_menu1; > Yes, set to 1 1294 bra test_switches_divemode_menu1; > Yes, set to 1
1274 call TFT_divemode_menu_cursor ; Update the cursor 1295 call TFT_divemode_menu_cursor ; Update the cursor
1275 bcf switch_left 1296 bcf switch_left
1276 movlw divemode_menu_timeout ; Reload timeout 1297 movlw divemode_menu_timeout ; Reload timeout
1277 movwf timeout_counter3 ; timeout for divemode menu 1298 movwf timeout_counter2 ; timeout for divemode menu
1278 return 1299 return
1279 1300
1280 test_switches_divemode_menu3: ; Enter submenu or do something 1301 test_switches_divemode_menu3: ; Enter submenu or do something
1281 bcf switch_right 1302 bcf switch_right
1282 ; decf menupos,F ; menu_processor needs 0-5... 1303 ; decf menupos1,F ; menu_processor needs 0-5...
1283 extern do_line_menu 1304 goto do_line_menu ; Warning! Trashes STKPTR and returns to diveloop_loop4:
1284 goto do_line_menu ; Warning! Trashes STKPTR and returns to diveloop_loop4:
1285 1305
1286 test_switches_divemode1: 1306 test_switches_divemode1:
1287 bcf switch_right 1307 bcf switch_right
1288 movlw divemode_menuview_timeout 1308 movlw divemode_menuview_timeout
1289 movwf timeout_counter3 ; Reload timeout 1309 movwf timeout_counter2 ; Reload timeout
1290 movff menupos2,WREG ; menupos2 holds number of customview/divemode menu function 1310 movff menupos2,WREG ; menupos2 holds number of customview/divemode menu function
1291 dcfsnz WREG,F 1311 dcfsnz WREG,F
1292 bra divemode_option_gaschange ; Switch to the indicated "better gas" 1312 bra divemode_option_gaschange ; Switch to the indicated "better gas"
1293 dcfsnz WREG,F 1313 dcfsnz WREG,F
1294 bra divemode_option0 ; Start/Setup Divemode menu 1314 bra divemode_option0 ; Start/Setup Divemode menu
1295 dcfsnz WREG,F 1315 dcfsnz WREG,F
1296 bra divemode_option1 ; Quit Simulation? 1316 bra divemode_option1 ; Quit Simulation?
1297 dcfsnz WREG,F 1317 dcfsnz WREG,F
1298 bra divemode_option2 ; Descent 1m 1318 bra divemode_option2 ; Descent 1m
1299 dcfsnz WREG,F 1319 dcfsnz WREG,F
1306 bra divemode_option6 ; +5mins simulation 1326 bra divemode_option6 ; +5mins simulation
1307 dcfsnz WREG,F 1327 dcfsnz WREG,F
1308 bra divemode_option7 ; Store heading 1328 bra divemode_option7 ; Store heading
1309 dcfsnz WREG,F 1329 dcfsnz WREG,F
1310 bra divemode_option8 ; Switch to alt. layout 1330 bra divemode_option8 ; Switch to alt. layout
1311 return 1331 return
1312 1332
1313 gas_switched_common: 1333 gas_switched_common:
1314 bcf divemode_gaschange ; Clear flag 1334 bcf divemode_gaschange ; Clear flag
1315 tstfsz menupos ; menupos=0? 1335 btfss FLAG_back_to_loop ; check if it is a switchback from OC bailout to loop
1316 bra gas_switched_common1 ; No 1336 bra gas_switched_common0 ; NO - continue with checking if selected gas is valid
1317 return ; Yes, do not switch gas (there is no Gas #0 !) 1337 bcf FLAG_back_to_loop ; YES - clear flag
1338 movff active_diluent,menupos1 ; reload last diluent
1339 bra gas_switched_common1 ; continue with common part
1340 gas_switched_common0:
1341 tstfsz menupos1 ; menupos1=0?
1342 bra gas_switched_common1 ; NO - valid gas
1343 return ; YES - something went wrong, invalid gas, abort
1318 gas_switched_common1: 1344 gas_switched_common1:
1319 movf menupos,W ; get selected gas into WREG (1-6) 1345 movf menupos1,W ; get selected gas into WREG (1-6)
1320 1346
1321 btfsc FLAG_ccr_mode ; in CCR mode? 1347 btfsc FLAG_ccr_mode ; in CCR mode?
1322 bra gas_switched_common2 ; YES - configure diluent or bailout 1348 bra gas_switched_common2 ; YES - configure diluent or bailout
1323 btfsc FLAG_pscr_mode ; in pSCR mode? 1349 btfsc FLAG_pscr_mode ; in pSCR mode?
1324 bra gas_switched_common2 ; YES - configure diluent or bailout 1350 bra gas_switched_common2 ; YES - configure diluent or bailout
1325 1351
1326 ; OC 1352 ; OC
1327 rcall setup_gas_registers ; With WREG = Gas 1-6 1353 rcall setup_gas_registers ; With WREG = Gas 1-6
1328 rcall deco_setup_oc_gases ; With WREG = Gas 1-6 1354 rcall deco_setup_oc_gases ; With WREG = Gas 1-6
1329 bra gas_switched_common3 1355 bra gas_switched_common3
1330 1356
1331 ; Loop or Bailout 1357 ; loop or bailout
1332 gas_switched_common2: 1358 gas_switched_common2:
1333 rcall setup_dil_registers ; With WREG = diluent 1-6, in case of is_bailout reverts to OC gases 1359 rcall setup_dil_registers ; With WREG = diluent 1-6, in case of is_bailout reverts to OC gases
1334 rcall deco_setup_cc_diluents ; With WREG = diluent 1-6, in case of is_bailout reverts to OC gases 1360 rcall deco_setup_cc_diluents ; With WREG = diluent 1-6, in case of is_bailout reverts to OC gases
1335 1361
1336 gas_switched_common3: 1362 gas_switched_common3:
1337 bsf FLAG_TFT_active_gas_divemode ; Redraw gas/setpoint/diluent 1363 bsf FLAG_TFT_active_gas_divemode ; Redraw gas/setpoint/diluent
1338 call restart_deco_engine_wo_ceiling ; abort any running deco calculations and restart the deco engine 1364 call restart_deco_engine_wo_ceiling ; abort any running deco calculations and restart the deco engine
1339 1365
1340 ; Set flags for profile recording 1366 ; Set flags for profile recording
1341 bsf event_occured ; Set global event byte 1367 bsf event_occured ; set event flag
1342 btfsc is_bailout ; Choose OC Bailouts (OC Gases) 1368 btfsc is_bailout ; Choose OC Bailouts (OC Gases)
1343 bsf bailoutgas_event ; Bailout gas change 1369 bsf bailoutgas_event ; Bailout gas change
1344 btfss is_bailout ; Choose OC Bailouts (OC Gases) 1370 btfss is_bailout ; Choose OC Bailouts (OC Gases)
1345 bsf stored_gas_changed ; OC gas change 1371 bsf stored_gas_changed ; OC gas change
1346 return 1372 return
1347 1373
1348 1374
1349 ; Code to pass all parameters to the C code 1375 ; Code to pass all parameters to the C code
1350 1376
1351 global get_first_gas_to_WREG 1377 global get_first_gas_to_WREG
1352 get_first_gas_to_WREG: ; Gets first gas (1-5) into WREG 1378 get_first_gas_to_WREG: ; Gets first gas (1-5) into WREG
1353 lfsr FSR1,opt_gas_type ; Point to gas types 1379 lfsr FSR1,opt_gas_type ; Point to gas types
1354 clrf lo ; start with Gas0 1380 clrf lo ; start with Gas0
1355 get_first_gas_to_WREG2: 1381 get_first_gas_to_WREG2:
1356 movf lo,W 1382 movf lo,W
1357 movf PLUSW1,W ; Get Type of Gas #lo 1383 movf PLUSW1,W ; Get Type of Gas #lo
1358 sublw .1 ; it is = 1 (First Gas) 1384 sublw .1 ; it is = 1 (First Gas)
1359 bz get_first_gas_to_WREG3 ; Found the first gas! 1385 bz get_first_gas_to_WREG3 ; Found the first gas!
1360 incf lo,F ; ++ 1386 incf lo,F ; ++
1361 movlw NUM_GAS+1 1387 movlw NUM_GAS+1
1362 cpfseq lo ; All done? 1388 cpfseq lo ; All done?
1363 bra get_first_gas_to_WREG2 ; Not yet 1389 bra get_first_gas_to_WREG2 ; Not yet
1364 ; No first gas found, use #1 1390 ; No first gas found, use #1
1365 movlw .0 1391 movlw .0
1366 movff WREG,opt_gas_type+0 ; Set Gas1 to First 1392 movff WREG,opt_gas_type+0 ; Set Gas1 to First
1367 incf WREG,W ; 0 -> 1 1393 incf WREG,W ; 0 -> 1
1368 return 1394 return
1369 get_first_gas_to_WREG3: 1395 get_first_gas_to_WREG3:
1370 movf lo,W ; Put into Wreg 1396 movf lo,W ; Put into Wreg
1371 incf WREG,W ; 0-4 -> 1-5 1397 incf WREG,W ; 0-4 -> 1-5
1372 return ; Done 1398 return ; Done
1373 1399
1374 global get_first_dil_to_WREG 1400 global get_first_dil_to_WREG
1375 get_first_dil_to_WREG: ; Gets first dil (1-5) into WREG 1401 get_first_dil_to_WREG: ; Gets first dil (1-5) into WREG
1376 lfsr FSR1,opt_dil_type ; Point to dil types 1402 lfsr FSR1,opt_dil_type ; Point to dil types
1377 clrf lo ; start with Gas0 1403 clrf lo ; start with Gas0
1378 get_first_dil_to_WREG2: 1404 get_first_dil_to_WREG2:
1379 movf lo,W 1405 movf lo,W
1380 movf PLUSW1,W ; Get Type of Dil #lo 1406 movf PLUSW1,W ; Get Type of Dil #lo
1381 sublw .1 ; it is = 1 (First Dil) 1407 sublw .1 ; it is = 1 (First Dil)
1382 bz get_first_dil_to_WREG3 ; Found the first dil! 1408 bz get_first_dil_to_WREG3 ; Found the first dil!
1383 incf lo,F ; ++ 1409 incf lo,F ; ++
1384 movlw NUM_GAS+1 1410 movlw NUM_GAS+1
1385 cpfseq lo ; All done? 1411 cpfseq lo ; All done?
1386 bra get_first_dil_to_WREG2 ; Not yet 1412 bra get_first_dil_to_WREG2 ; Not yet
1387 ; No first dil found, use #1 1413 ; No first dil found, use #1
1388 movlw .0 1414 movlw .0
1389 movff WREG,opt_dil_type+0 ; Set Dil1 to First 1415 movff WREG,opt_dil_type+0 ; Set Dil1 to First
1390 incf WREG,W ; 0 -> 1 1416 incf WREG,W ; 0 -> 1
1391 return 1417 return
1392 get_first_dil_to_WREG3: 1418 get_first_dil_to_WREG3:
1393 movf lo,W ; Put into Wreg 1419 movf lo,W ; Put into Wreg
1394 incf WREG,W ; 0-4 -> 1-5 1420 incf WREG,W ; 0-4 -> 1-5
1395 return ; Done 1421 return ; Done
1396 1422
1397 global deco_setup_oc_gases 1423 global deco_setup_oc_gases
1398 deco_setup_oc_gases: ; with currently breathed gas in WREG (1-5 or 6) 1424 deco_setup_oc_gases: ; with currently breathed gas in WREG (1-5 or 6)
1399 movff WREG,char_I_current_gas ; gas to start with when doing the deco calculations 1425 movff WREG,char_I_current_gas ; gas to start with when doing the deco calculations
1400 1426
1401 movff opt_gas_He_ratio+0,char_I_deco_He_ratio+0 1427 banksel opt_gas_type ; opt_gas_type[] and opt_OC_bail_gas_change[] are together in bank common2
1402 movff opt_gas_O2_ratio+0,char_I_deco_O2_ratio+0 1428
1403 banksel opt_gas_type+0 1429 movff opt_gas_He_ratio+0,char_I_deco_He_ratio+0
1404 movlw .3 ; 3=Deco 1430 movff opt_gas_O2_ratio+0,char_I_deco_O2_ratio+0
1405 cpfseq opt_gas_type+0 ; Gas is deco type? 1431
1406 clrf opt_OC_bail_gas_change+0 ; No, clear depth for 0=Disabled, 1=First and 2=Travel 1432 movlw .3 ; 3=Deco
1433 cpfseq opt_gas_type+0 ; Gas is deco type?
1434 clrf opt_OC_bail_gas_change+0 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1435
1436 movff opt_gas_He_ratio+1,char_I_deco_He_ratio+1
1437 movff opt_gas_O2_ratio+1,char_I_deco_O2_ratio+1
1438 movlw .3 ; 3=Deco
1439 cpfseq opt_gas_type+1 ; Gas is deco type?
1440 clrf opt_OC_bail_gas_change+1 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1441
1442 movff opt_gas_He_ratio+2,char_I_deco_He_ratio+2
1443 movff opt_gas_O2_ratio+2,char_I_deco_O2_ratio+2
1444 movlw .3 ; 3=Deco
1445 cpfseq opt_gas_type+2 ; Gas is deco type?
1446 clrf opt_OC_bail_gas_change+2 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1447
1448 movff opt_gas_He_ratio+3,char_I_deco_He_ratio+3
1449 movff opt_gas_O2_ratio+3,char_I_deco_O2_ratio+3
1450 movlw .3 ; 3=Deco
1451 cpfseq opt_gas_type+3 ; Gas is deco type?
1452 clrf opt_OC_bail_gas_change+3 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1453
1454 movff opt_gas_He_ratio+4,char_I_deco_He_ratio+4
1455 movff opt_gas_O2_ratio+4,char_I_deco_O2_ratio+4
1456 movlw .3 ; 3=Deco
1457 cpfseq opt_gas_type+4 ; Gas is deco type?
1458 clrf opt_OC_bail_gas_change+4 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1459
1407 banksel common 1460 banksel common
1408 1461
1409 movff opt_gas_He_ratio+1,char_I_deco_He_ratio+1
1410 movff opt_gas_O2_ratio+1,char_I_deco_O2_ratio+1
1411 banksel opt_gas_type+1
1412 movlw .3 ; 3=Deco
1413 cpfseq opt_gas_type+1 ; Gas is deco type?
1414 clrf opt_OC_bail_gas_change+1 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1415 banksel common
1416
1417 movff opt_gas_He_ratio+2,char_I_deco_He_ratio+2
1418 movff opt_gas_O2_ratio+2,char_I_deco_O2_ratio+2
1419 banksel opt_gas_type+2
1420 movlw .3 ; 3=Deco
1421 cpfseq opt_gas_type+2 ; Gas is deco type?
1422 clrf opt_OC_bail_gas_change+2 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1423 banksel common
1424
1425 movff opt_gas_He_ratio+3,char_I_deco_He_ratio+3
1426 movff opt_gas_O2_ratio+3,char_I_deco_O2_ratio+3
1427 banksel opt_gas_type+3
1428 movlw .3 ; 3=Deco
1429 cpfseq opt_gas_type+3 ; Gas is deco type?
1430 clrf opt_OC_bail_gas_change+3 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1431 banksel common
1432
1433 movff opt_gas_He_ratio+4,char_I_deco_He_ratio+4
1434 movff opt_gas_O2_ratio+4,char_I_deco_O2_ratio+4
1435 banksel opt_gas_type+4
1436 movlw .3 ; 3=Deco
1437 cpfseq opt_gas_type+4 ; Gas is deco type?
1438 clrf opt_OC_bail_gas_change+4 ; No, clear depth for 0=Disabled, 1=First and 2=Travel
1439 banksel common
1440
1441 ; Setup char_I_deco_gas_change array 1462 ; Setup char_I_deco_gas_change array
1442 movff opt_OC_bail_gas_change+0, char_I_deco_gas_change+0 1463 movff opt_OC_bail_gas_change+0, char_I_deco_gas_change+0
1443 movff opt_OC_bail_gas_change+1, char_I_deco_gas_change+1 1464 movff opt_OC_bail_gas_change+1, char_I_deco_gas_change+1
1444 movff opt_OC_bail_gas_change+2, char_I_deco_gas_change+2 1465 movff opt_OC_bail_gas_change+2, char_I_deco_gas_change+2
1445 movff opt_OC_bail_gas_change+3, char_I_deco_gas_change+3 1466 movff opt_OC_bail_gas_change+3, char_I_deco_gas_change+3
1446 movff opt_OC_bail_gas_change+4, char_I_deco_gas_change+4 1467 movff opt_OC_bail_gas_change+4, char_I_deco_gas_change+4
1447 1468
1448 ; switch to oc mode 1469 ; switch to oc mode
1449 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common 1470 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common
1450 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind) 1471 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind)
1451 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag 1472 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag
1452 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status 1473 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status
1453 1474
1454 return 1475 return
1455 1476
1456 1477
1457 global deco_setup_cc_diluents 1478 global deco_setup_cc_diluents
1458 deco_setup_cc_diluents: ; with currently breathed gas in WREG (1-5 or 6) 1479 deco_setup_cc_diluents: ; with currently breathed gas in WREG (1-5 or 6)
1459 btfsc is_bailout ; check if in bailout condition 1480 btfsc is_bailout ; check if in bailout condition
1460 bra deco_setup_oc_gases ; revert to setting up OC gases in bailout condition 1481 bra deco_setup_oc_gases ; revert to setting up OC gases in bailout condition
1461 1482
1462 movff WREG,char_I_current_gas ; gas to start with when doing the deco calculations 1483 movff WREG,char_I_current_gas ; gas to start with when doing the deco calculations
1463 1484
1464 movff opt_dil_He_ratio+0,char_I_deco_He_ratio+0 1485 movff opt_dil_He_ratio+0,char_I_deco_He_ratio+0
1465 movff opt_dil_O2_ratio+0,char_I_deco_O2_ratio+0 1486 movff opt_dil_O2_ratio+0,char_I_deco_O2_ratio+0
1466 movff opt_dil_type+0,WREG ; 0=Disabled, 1=First, 2=Normal 1487 movff opt_dil_type+0,WREG ; 0=Disabled, 1=First, 2=Normal
1467 tstfsz WREG ; Disabled? 1488 tstfsz WREG ; Disabled?
1468 bra $+4 ; No 1489 bra $+4 ; No
1469 movff WREG,char_I_dil_change+0 ; Yes, clear char_I_deco_gas_change (Bank safe) 1490 movff WREG,char_I_dil_change+0 ; Yes, clear char_I_deco_gas_change (Bank safe)
1470 1491
1471 movff opt_dil_He_ratio+1,char_I_deco_He_ratio+1 1492 movff opt_dil_He_ratio+1,char_I_deco_He_ratio+1
1472 movff opt_dil_O2_ratio+1,char_I_deco_O2_ratio+1 1493 movff opt_dil_O2_ratio+1,char_I_deco_O2_ratio+1
1473 movff opt_dil_type+1,WREG ; 0=Disabled, 1=First, 2=Normal 1494 movff opt_dil_type+1,WREG ; 0=Disabled, 1=First, 2=Normal
1474 tstfsz WREG ; Disabled? 1495 tstfsz WREG ; Disabled?
1475 bra $+4 ; No 1496 bra $+4 ; No
1476 movff WREG,char_I_dil_change+1 ; Yes, clear char_I_dil_change 1497 movff WREG,char_I_dil_change+1 ; Yes, clear char_I_dil_change
1477 1498
1478 movff opt_dil_He_ratio+2,char_I_deco_He_ratio+2 1499 movff opt_dil_He_ratio+2,char_I_deco_He_ratio+2
1479 movff opt_dil_O2_ratio+2,char_I_deco_O2_ratio+2 1500 movff opt_dil_O2_ratio+2,char_I_deco_O2_ratio+2
1480 movff opt_dil_type+2,WREG ; 0=Disabled, 1=First, 2=Normal 1501 movff opt_dil_type+2,WREG ; 0=Disabled, 1=First, 2=Normal
1481 tstfsz WREG ; Disabled? 1502 tstfsz WREG ; Disabled?
1482 bra $+4 ; No 1503 bra $+4 ; No
1483 movff WREG,char_I_dil_change+2 ; Yes, clear char_I_dil_change 1504 movff WREG,char_I_dil_change+2 ; Yes, clear char_I_dil_change
1484 1505
1485 movff opt_dil_He_ratio+3,char_I_deco_He_ratio+3 1506 movff opt_dil_He_ratio+3,char_I_deco_He_ratio+3
1486 movff opt_dil_O2_ratio+3,char_I_deco_O2_ratio+3 1507 movff opt_dil_O2_ratio+3,char_I_deco_O2_ratio+3
1487 movff opt_dil_type+3,WREG ; 0=Disabled, 1=First, 2=Normal 1508 movff opt_dil_type+3,WREG ; 0=Disabled, 1=First, 2=Normal
1488 tstfsz WREG ; Disabled? 1509 tstfsz WREG ; Disabled?
1489 bra $+4 ; No 1510 bra $+4 ; No
1490 movff WREG,char_I_dil_change+3 ; Yes, clear char_I_dil_change 1511 movff WREG,char_I_dil_change+3 ; Yes, clear char_I_dil_change
1491 1512
1492 movff opt_dil_He_ratio+4,char_I_deco_He_ratio+4 1513 movff opt_dil_He_ratio+4,char_I_deco_He_ratio+4
1493 movff opt_dil_O2_ratio+4,char_I_deco_O2_ratio+4 1514 movff opt_dil_O2_ratio+4,char_I_deco_O2_ratio+4
1494 movff opt_dil_type+4,WREG ; 0=Disabled, 1=First, 2=Normal 1515 movff opt_dil_type+4,WREG ; 0=Disabled, 1=First, 2=Normal
1495 tstfsz WREG ; Disabled? 1516 tstfsz WREG ; Disabled?
1496 bra $+4 ; No 1517 bra $+4 ; No
1497 movff WREG,char_I_dil_change+4 ; Yes, clear char_I_dil_change 1518 movff WREG,char_I_dil_change+4 ; Yes, clear char_I_dil_change
1498 1519
1499 ; Setup char_I_deco_gas_change array 1520 ; Setup char_I_deco_gas_change array
1500 movff char_I_dil_change+0, char_I_deco_gas_change+0 1521 movff char_I_dil_change+0, char_I_deco_gas_change+0
1501 movff char_I_dil_change+1, char_I_deco_gas_change+1 1522 movff char_I_dil_change+1, char_I_deco_gas_change+1
1502 movff char_I_dil_change+2, char_I_deco_gas_change+2 1523 movff char_I_dil_change+2, char_I_deco_gas_change+2
1503 movff char_I_dil_change+3, char_I_deco_gas_change+3 1524 movff char_I_dil_change+3, char_I_deco_gas_change+3
1504 movff char_I_dil_change+4, char_I_deco_gas_change+4 1525 movff char_I_dil_change+4, char_I_deco_gas_change+4
1505 1526
1506 ; switch to CCR / pSCR mode 1527 ; switch to CCR / pSCR mode
1507 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common 1528 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common
1508 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode 1529 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode
1509 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default 1530 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default
1510 btfsc FLAG_pscr_mode ; check if we are in pSCR mode 1531 btfsc FLAG_pscr_mode ; check if we are in pSCR mode
1511 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode 1532 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode
1512 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status 1533 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status
1513 1534
1514 return 1535 return
1515 1536
1516 global setup_gas_registers 1537 global setup_gas_registers
1517 setup_gas_registers: ; with currently breathed gas in WREG (1-5 or 6) 1538 setup_gas_registers: ; with currently breathed gas in WREG (1-5 or 6)
1518 movwf active_gas ; set as current gas 1539 movwf active_gas ; set as current gas
1519 movlw .6 1540 movlw .6
1520 cpfseq active_gas ; gas = gas6 ? 1541 cpfseq active_gas ; gas = gas6 ?
1521 bra setup_gas_registers_15 ; NO - load gas 1-5 1542 bra setup_gas_registers_15 ; NO - load gas 1-5
1522 movff gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine 1543 movff gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine
1523 movff gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine 1544 movff gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine
1524 bra setup_gas_registers_com ; continue with common part 1545 bra setup_gas_registers_com ; continue with common part
1525 setup_gas_registers_15: 1546 setup_gas_registers_15:
1526 decf active_gas,W ; 1-5 -> 0-4 1547 decf active_gas,W ; 1-5 -> 0-4
1527 lfsr FSR1,opt_gas_O2_ratio+0 1548 lfsr FSR1,opt_gas_O2_ratio+0
1528 movff PLUSW1,char_I_O2_ratio ; copy gas 1-5 O2 ratio to deco engine 1549 movff PLUSW1,char_I_O2_ratio ; copy gas 1-5 O2 ratio to deco engine
1529 lfsr FSR1,opt_gas_He_ratio+0 1550 lfsr FSR1,opt_gas_He_ratio+0
1530 movff PLUSW1,char_I_He_ratio ; copy gas 1-5 He ratio to deco engine 1551 movff PLUSW1,char_I_He_ratio ; copy gas 1-5 He ratio to deco engine
1531 setup_gas_registers_com: 1552 setup_gas_registers_com:
1532 ;lfsr FSR1,opt_gas_type ; commented out - currently not used anywhere 1553 ;lfsr FSR1,opt_gas_type ; commented out - currently not used anywhere
1533 ;movff PLUSW1,active_gas_type ; 0=Disabled, 1=First, 2=Travel, 3=Deco 1554 ;movff PLUSW1,active_gas_type ; 0=Disabled, 1=First, 2=Travel, 3=Deco
1534 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common 1555 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common
1535 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind) 1556 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind)
1536 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag 1557 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag
1537 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status 1558 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status
1538 movf active_gas,W ; reload WREG with diluent 1-5 or 6 (important!) 1559 movf active_gas,W ; reload WREG with diluent 1-5 or 6 (important!)
1539 return 1560 return
1540 1561
1541 global setup_dil_registers 1562 global setup_dil_registers
1542 setup_dil_registers: ; with currently breathed gas in WREG (1-5 or 6) 1563 setup_dil_registers: ; with currently breathed gas in WREG (1-5 or 6)
1543 btfsc is_bailout ; check if in bailout condition 1564 btfsc is_bailout ; check if in bailout condition
1544 bra setup_gas_registers ; revert to setting up OC gases in bailout condition 1565 bra setup_gas_registers ; revert to setting up OC gases in bailout condition
1545 movwf active_gas ; set as current gas 1566 movwf active_gas ; set as current gas
1546 movff WREG,active_diluent ; remember for when switching back from bailout to loop 1567 movff WREG,active_diluent ; remember for when switching back from bailout to loop
1547 movlw .6 1568 movlw .6
1548 cpfseq active_gas ; diluent = gas6 ? 1569 cpfseq active_gas ; diluent = gas6 ?
1549 bra setup_dil_registers_15 ; NO - load diluent 1-5 1570 bra setup_dil_registers_15 ; NO - load diluent 1-5
1550 movff gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine 1571 movff gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine
1551 movff gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine 1572 movff gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine
1552 bra setup_dil_registers_com ; continue with common part 1573 bra setup_dil_registers_com ; continue with common part
1553 setup_dil_registers_15: 1574 setup_dil_registers_15:
1554 decf active_gas,W ; 1-5 -> 0-4 1575 decf active_gas,W ; 1-5 -> 0-4
1555 lfsr FSR1,opt_dil_O2_ratio+0 1576 lfsr FSR1,opt_dil_O2_ratio+0
1556 movff PLUSW1,char_I_O2_ratio ; copy diluent 1-5 O2 ratio to deco engine 1577 movff PLUSW1,char_I_O2_ratio ; copy diluent 1-5 O2 ratio to deco engine
1557 lfsr FSR1,opt_dil_He_ratio+0 1578 lfsr FSR1,opt_dil_He_ratio+0
1558 movff PLUSW1,char_I_He_ratio ; copy diluent 1-5 He ratio to deco engine 1579 movff PLUSW1,char_I_He_ratio ; copy diluent 1-5 He ratio to deco engine
1559 setup_dil_registers_com: 1580 setup_dil_registers_com:
1560 ;lfsr FSR1,opt_dil_type ; commented out - currently not used anywhere 1581 ;lfsr FSR1,opt_dil_type ; commented out - currently not used anywhere
1561 ;movff PLUSW1,active_gas_type ; 0=Disabled, 1=First, 2=Normal (there is no type 3 for diluents) 1582 ;movff PLUSW1,active_gas_type ; 0=Disabled, 1=First, 2=Normal (there is no type 3 for diluents)
1562 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common 1583 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common
1563 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode 1584 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode
1564 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default 1585 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default
1565 btfsc FLAG_pscr_mode ; check if we are in pSCR mode 1586 btfsc FLAG_pscr_mode ; check if we are in pSCR mode
1566 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode 1587 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode
1567 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status 1588 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status
1568 movf active_gas,W ; reload WREG with diluent 1-5 or 6 (important!) 1589 movf active_gas,W ; reload WREG with diluent 1-5 or 6 (important!)
1569 return 1590 return
1570 1591
1571 divemode_option_gaschange: ; Switch to the better gas 1592 divemode_option_gaschange: ; Switch to the better gas
1572 movff better_gas_number,menupos ; 1-5 1593 movff better_gas_number,menupos1 ; 1-5
1573 bsf divemode_gaschange ; Change the gas in the dive mode loop... 1594 bsf divemode_gaschange ; Change the gas in the dive mode loop...
1574 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) 1595 call menuview_toggle_reset ; Reset to zero (Zero=no menuview)
1575 bcf better_gas_available ; Clear flag immediately 1596 bcf better_gas_available ; Clear flag immediately
1576 return 1597 return
1577 1598
1578 divemode_option0: ; Start/Setup Divemode menu 1599 divemode_option0: ; Start/Setup Divemode menu
1579 call TFT_clear_divemode_menu ; Clear menu area 1600 call TFT_clear_divemode_menu ; Clear menu area
1580 bcf menuview 1601 bcf menuview
1581 extern do_main_divemenu
1582 call do_main_divemenu 1602 call do_main_divemenu
1583 1603
1584 global divemode_option0_return 1604 global divemode_option0_return
1585 divemode_option0_return: 1605 divemode_option0_return:
1586 ; movlw .1 1606 ; movlw .1
1587 ; movwf menupos ; Set to first option in divemode menu 1607 ; movwf menupos1 ; Set to first option in divemode menu
1588 call TFT_divemode_menu_cursor; Show the cursor 1608 call TFT_divemode_menu_cursor ; Show the cursor
1589 movlw divemode_menu_timeout 1609 movlw divemode_menu_timeout
1590 movwf timeout_counter3 ; timeout for divemode menu 1610 movwf timeout_counter2 ; timeout for divemode menu
1591 bsf divemode_menu ; Set flag 1611 bsf divemode_menu ; Set flag
1592 clrf menupos2 ; Clear option counter 1612 clrf menupos2 ; Clear option counter
1593 goto diveloop_loop4 ; Goto back to diveloop (Menuprocessor trashes STKPTR!) 1613 goto diveloop_loop4 ; Goto back to diveloop (menu processor trashes STKPTR!)
1594 1614
1595 divemode_option4: 1615 divemode_option4:
1596 movlw d'58' ; two seconds left 1616 movlw d'58' ; two seconds left
1597 movwf timeout_counter 1617 movwf timeout_counter1+0
1598 movlw apnoe_timeout-1 ; apnoe timeout [min] 1618 movlw apnoe_timeout-1 ; apnoe timeout [min]
1599 movwf apnoe_timeout_counter 1619 movwf apnoe_timeout_counter
1600 btfss simulatormode_active ; in simulator mode? 1620 btfss simulatormode_active ; in simulator mode?
1601 return ; No 1621 return ; No
1602 divemode_option1: ; Quit simulation mode 1622 divemode_option1: ; Quit simulation mode
1603 banksel isr_backup 1623 banksel isr_backup
1604 movlw low .1000 1624 movlw LOW .1000
1605 movwf sim_pressure+0 1625 movwf sim_pressure+0
1606 movlw high .1000 1626 movlw HIGH .1000
1607 movwf sim_pressure+1 ; Set to 0m -> End of Dive 1627 movwf sim_pressure+1 ; Set to 0m -> End of Dive
1608 banksel common 1628 banksel common
1609 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) 1629 call menuview_toggle_reset ; Reset to zero (Zero=no menuview)
1610 1630
1611 btfss FLAG_apnoe_mode ; In Apnoe mode? 1631 btfss FLAG_apnoe_mode ; In Apnoe mode?
1612 return ; No 1632 return ; No
1613 movlw d'58' ; two seconds left 1633 movlw d'58' ; two seconds left
1614 movwf timeout_counter 1634 movwf timeout_counter1+0
1615 movlw apnoe_timeout-1 ; apnoe timeout [min] 1635 movlw apnoe_timeout-1 ; apnoe timeout [min]
1616 movwf apnoe_timeout_counter 1636 movwf apnoe_timeout_counter
1617 return 1637 return
1618 1638
1619 divemode_option3: ; minus 1m 1639 divemode_option3: ; minus 1m
1620 banksel isr_backup 1640 banksel isr_backup
1621 movlw d'100' 1641 movlw d'100'
1622 subwf sim_pressure+0 1642 subwf sim_pressure+0
1623 movlw .0 1643 movlw .0
1624 subwfb sim_pressure+1 1644 subwfb sim_pressure+1
1625 rcall divemode_simulator_check_limits 1645 rcall divemode_simulator_check_limits
1626 banksel common 1646 banksel common
1627 return 1647 return
1628 1648
1629 divemode_option2: ; plus 1m 1649 divemode_option2: ; plus 1m
1630 banksel isr_backup 1650 banksel isr_backup
1631 movlw d'100' 1651 movlw d'100'
1632 addwf sim_pressure+0 1652 addwf sim_pressure+0
1633 movlw .0 1653 movlw .0
1634 addwfc sim_pressure+1 1654 addwfc sim_pressure+1
1635 rcall divemode_simulator_check_limits 1655 rcall divemode_simulator_check_limits
1636 banksel common 1656 banksel common
1637 return 1657 return
1638 1658
1639 divemode_option5: 1659 divemode_option5:
1640 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) 1660 call menuview_toggle_reset ; Reset to zero (Zero=no menuview)
1641 bsf reset_average_depth ; Set Flag 1661 bsf reset_average_depth ; Set Flag
1642 return 1662 return
1643 1663
1644 divemode_option6: 1664 divemode_option6:
1645 bcf divemode2 ; Stop divetime 1665 bcf divemode2 ; Stop divetime
1646 movlw .5 1666 movlw .5
1647 addwf divemins+0,F 1667 addwf divemins+0,F
1648 movlw .0 1668 movlw .0
1649 addwfc divemins+1,F ; Add 5 mins 1669 addwfc divemins+1,F ; Add 5 mins
1650 movlw LOW (.5*.60) 1670 movlw LOW (.5*.60)
1651 addwf average_divesecs+0,F 1671 addwf average_divesecs+0,F
1652 movlw HIGH (.5*.60) 1672 movlw HIGH (.5*.60)
1653 addwfc average_divesecs+1,F ; Add 5*60 seconds 1673 addwfc average_divesecs+1,F ; Add 5*60 seconds
1654 movlw LOW (.5*.60) 1674 movlw LOW (.5*.60)
1655 addwf total_divetime_seconds+0,F 1675 addwf total_divetime_seconds+0,F
1656 movlw HIGH (.5*.60) 1676 movlw HIGH (.5*.60)
1657 addwfc total_divetime_seconds+1,F ; Add 5*60 seconds 1677 addwfc total_divetime_seconds+1,F ; Add 5*60 seconds
1658 1678
1659 ; 1. Add 300xdepth to the Sum of depths registers 1679 ; 1. Add 300xdepth to the sum of depths registers
1660 SAFE_2BYTE_COPY rel_pressure, xB ; Buffer... 1680 SAFE_2BYTE_COPY rel_pressure, xB ; Buffer...
1661 movlw LOW (.5*.60) 1681 movlw LOW (.5*.60)
1662 movwf xA+0 1682 movwf xA+0
1663 movlw HIGH (.5*.60) 1683 movlw HIGH (.5*.60)
1664 movwf xA+1 1684 movwf xA+1
1665 call mult16x16 ; xA*xB=xC 1685 call mult16x16 ; xA*xB=xC
1666 1686
1667 movf xC+0,w 1687 movf xC+0,w
1668 addwf average_depth_hold+0,F 1688 addwf average_depth_hold+0,F
1669 movf xC+1,w 1689 movf xC+1,w
1670 addwfc average_depth_hold+1,F 1690 addwfc average_depth_hold+1,F
1671 movf xC+2,w 1691 movf xC+2,w
1672 addwfc average_depth_hold+2,F 1692 addwfc average_depth_hold+2,F
1673 movf xC+3,w 1693 movf xC+3,w
1674 addwfc average_depth_hold+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar 1694 addwfc average_depth_hold+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar
1675 1695
1676 ; Do the same for the _total registers (Non-Resettable) 1696 ; Do the same for the _total registers (Non-Resettable)
1677 movf xC+0,w 1697 movf xC+0,w
1678 addwf average_depth_hold_total+0,F 1698 addwf average_depth_hold_total+0,F
1683 movf xC+3,w 1703 movf xC+3,w
1684 addwfc average_depth_hold_total+3,F; Will work up to 9999mbar*60*60*24=863913600mbar 1704 addwfc average_depth_hold_total+3,F; Will work up to 9999mbar*60*60*24=863913600mbar
1685 1705
1686 movlw .5 ; + 5 minutes 1706 movlw .5 ; + 5 minutes
1687 movff WREG,char_I_sim_advance_time; copy to mailbox 1707 movff WREG,char_I_sim_advance_time; copy to mailbox
1688 bsf divemode2 ; continue divetime 1708 bsf divemode2 ; continue divetime
1689 call restart_deco_engine 1709 call restart_deco_engine
1690 goto menuview_toggle_reset ; and return... 1710 goto menuview_toggle_reset ; and return...
1691 1711
1692 divemode_option7: 1712 divemode_option7:
1693 ; Store heading for compass view 1713 ; Store heading for compass view
1694 movff compass_heading_shown+0,compass_bearing+0 1714 movff compass_heading_shown+0,compass_bearing+0
1695 movff compass_heading_shown+1,compass_bearing+1 1715 movff compass_heading_shown+1,compass_bearing+1
1696 bsf compass_bearing_set ; set flag 1716 bsf compass_bearing_set ; set flag
1697 goto menuview_toggle_reset ; Done and return... 1717 goto menuview_toggle_reset ; Done and return...
1698 1718
1699 divemode_option8: 1719 divemode_option8:
1700 bsf alternative_divelayout ; Set flag for mode 1720 bsf alternative_divelayout ; Set flag for mode
1701 bsf FLAG_TFT_divemode_mask_alt ; Set flag for mask 1721 bsf FLAG_TFT_divemode_mask_alt ; Set flag for mask
1702 movlw .1 1722 movlw .1
1703 movwf menupos3 ; For the customviews... 1723 movwf menupos3 ; For the customviews...
1704 call TFT_ClearScreen ; Clear screen 1724 call TFT_ClearScreen ; Clear screen
1705 goto menuview_toggle_reset ; Done and return... 1725 goto menuview_toggle_reset ; Done and return...
1706 1726
1707 divemode_simulator_check_limits: 1727 divemode_simulator_check_limits:
1708 ; Check limits (150m and 0m) 1728 ; Check limits (150m and 0m)
1709 movlw LOW d'16000' ; Compare to 16bar=16000mbar (150m). 1729 movlw LOW d'16000' ; Compare to 16bar=16000mbar (150m).
1710 subwf sim_pressure+0,W 1730 subwf sim_pressure+0,W
1711 movlw HIGH d'16000' 1731 movlw HIGH d'16000'
1712 subwfb sim_pressure+1,W 1732 subwfb sim_pressure+1,W
1713 bnc divemode_simulator_check_limits2 ; No-carry = borrow = not deeper 1733 bnc divemode_simulator_check_limits2 ; No-carry = borrow = not deeper
1714 1734
1715 ; Too deep, limit to 150m 1735 ; Too deep, limit to 150m
1716 movlw LOW d'16000' 1736 movlw LOW d'16000'
1717 movwf sim_pressure+0 1737 movwf sim_pressure+0
1718 movlw HIGH d'16000' 1738 movlw HIGH d'16000'
1719 movwf sim_pressure+1 1739 movwf sim_pressure+1
1720 return 1740 return
1721 divemode_simulator_check_limits2: 1741 divemode_simulator_check_limits2:
1722 movlw LOW d'1000' ; Compare to 1bar == 0m == 1000 mbar. 1742 movlw LOW d'1000' ; Compare to 1bar == 0m == 1000 mbar.
1723 subwf sim_pressure+0,W 1743 subwf sim_pressure+0,W
1724 movlw HIGH d'1000' 1744 movlw HIGH d'1000'
1725 subwfb sim_pressure+1,W 1745 subwfb sim_pressure+1,W
1726 btfsc STATUS,C ; No-carry = borrow = not deeper. 1746 btfsc STATUS,C ; No-carry = borrow = not deeper.
1727 return ; Deeper than 0m == Ok. 1747 return ; Deeper than 0m == Ok.
1728 ; Too shallow, limit to 0m 1748 ; Too shallow, limit to 0m
1729 movlw LOW d'1000' 1749 movlw LOW d'1000'
1730 movwf sim_pressure+0 1750 movwf sim_pressure+0
1731 movlw HIGH d'1000' 1751 movlw HIGH d'1000'
1732 movwf sim_pressure+1 1752 movwf sim_pressure+1
1733 return 1753 return
1734 1754
1735 ;============================================================================= 1755 ;=============================================================================
1736 ; Compare all enabled gas in list, to see if a better one is available. 1756 ; Compare all enabled gas in list, to see if a better one is available.
1737 ; 1757 ;
1738 ; Output: better_gas_available, better_gas_number 1758 ; Output: better_gas_available, better_gas_number
1739 ; 1759 ;
1740 check_gas_change: ; Checks if a better gas should be selected (by user) 1760 check_gas_change: ; Checks if a better gas should be selected (by user)
1741 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode 1761 bcf better_gas_available ; =1: A better gas is available and a gas change is advised in divemode
1742 clrf better_gas_number ; Clear better gas register 1762 clrf WREG
1743 1763 movff WREG,better_gas_number ; clear better gas register
1744 SAFE_2BYTE_COPY rel_pressure,xA 1764
1765 SAFE_2BYTE_COPY rel_pressure,xA
1745 movlw d'100' 1766 movlw d'100'
1746 movwf xB+0 1767 movwf xB+0
1747 clrf xB+1 1768 clrf xB+1
1748 call div16x16 ; compute depth in full m -> result in xC+0 1769 call div16x16 ; compute depth in full m -> result in xC+0
1749 1770
1750 btfsc FLAG_pscr_mode ; In PSCR mode... 1771 btfsc FLAG_pscr_mode ; in PSCR mode?
1751 bra check_gas_change2 ; Yes, check for diluents 1772 bra check_gas_change2 ; YES - check for diluents
1752 btfss FLAG_ccr_mode ; In CCR mode... 1773 btfss FLAG_ccr_mode ; in CCR mode?
1753 bra check_gas_change_OC_bail; No, check for OC or bailout 1774 bra check_gas_change_OC_bail ; NO - check for OC
1754 check_gas_change2: 1775 check_gas_change2:
1755 btfsc is_bailout ; Bailout? 1776 btfsc is_bailout ; in bailout?
1756 bra check_gas_change_OC_bail; Yes, check for OC or bailout 1777 bra check_gas_change_OC_bail ; YES - check for OC
1757 1778
1758 ; Check Diluents 1779 ; Check Diluents
1759 movlw .0 1780 movlw .0
1760 rcall check_dil_common ; With Gas 0-4 in WREG 1781 rcall check_dil_common ; With Gas 0-4 in WREG
1761 movlw .1 1782 movlw .1
1762 rcall check_dil_common ; With Gas 0-4 in WREG 1783 rcall check_dil_common ; With Gas 0-4 in WREG
1763 movlw .2 1784 movlw .2
1764 rcall check_dil_common ; With Gas 0-4 in WREG 1785 rcall check_dil_common ; With Gas 0-4 in WREG
1765 movlw .3 1786 movlw .3
1766 rcall check_dil_common ; With Gas 0-4 in WREG 1787 rcall check_dil_common ; With Gas 0-4 in WREG
1767 movlw .4 1788 movlw .4
1768 rcall check_dil_common ; With Gas 0-4 in WREG 1789 rcall check_dil_common ; With Gas 0-4 in WREG
1769 bra check_gas_change_exit 1790 bra check_gas_change_exit
1770 1791
1771 check_gas_change_OC_bail: 1792 check_gas_change_OC_bail:
1772 movlw .0 1793 movlw .0
1773 rcall check_gas_common ; With Gas 0-4 in WREG 1794 rcall check_gas_common ; With Gas 0-4 in WREG
1774 movlw .1 1795 movlw .1
1775 rcall check_gas_common ; With Gas 0-4 in WREG 1796 rcall check_gas_common ; With Gas 0-4 in WREG
1776 movlw .2 1797 movlw .2
1777 rcall check_gas_common ; With Gas 0-4 in WREG 1798 rcall check_gas_common ; With Gas 0-4 in WREG
1778 movlw .3 1799 movlw .3
1779 rcall check_gas_common ; With Gas 0-4 in WREG 1800 rcall check_gas_common ; With Gas 0-4 in WREG
1780 movlw .4 1801 movlw .4
1781 rcall check_gas_common ; With Gas 0-4 in WREG 1802 rcall check_gas_common ; With Gas 0-4 in WREG
1782 ; bra check_gas_change_exit 1803 ;bra check_gas_change_exit
1783 1804
1784 check_gas_change_exit: 1805 check_gas_change_exit:
1785 btfss better_gas_available ; Is a better gas available 1806 bsf FLAG_TFT_active_gas_divemode; redraw gas/setpoint/diluent
1786 bcf blinking_better_gas ; No, Clear blinking flag 1807 btfss better_gas_available ; is a better gas available?
1787 btfss better_gas_available ; Is a better gas available 1808 bcf blinking_better_gas ; NO - clear blinking flag
1788 clrf better_gas_number ; No, Clear better_gas_number (For gaslist display) 1809 btfsc better_gas_available ; is a better gas available?
1789 bsf FLAG_TFT_active_gas_divemode; Redraw gas/setpoint/diluent 1810 return ; YES
1790 return 1811 clrf WREG ; NO - clear better_gas_number (for gaslist display)
1791 1812 movff WREG,better_gas_number
1792 check_gas_common: ; With Gas 0-4 in WREG 1813 return
1793 btfsc better_gas_available ; Better Gas already found? 1814
1794 return ; Yes, return 1815 check_gas_common: ; With Gas 0-4 in WREG
1795 lfsr FSR1,opt_gas_type ; 0=Disabled, 1=First, 2=Travel, 3=Deco 1816 btfsc better_gas_available ; Better Gas already found?
1796 btfss PLUSW1,0 ; Test for Bit0 and 1 -> type=3 -> Deco 1817 return ; Yes, return
1797 return ; No 1818 lfsr FSR1,opt_gas_type ; 0=Disabled, 1=First, 2=Travel, 3=Deco
1798 btfss PLUSW1,1 ; Test for Bit0 and 1 -> type=3 -> Deco 1819 btfss PLUSW1,0 ; Test for Bit0 and 1 -> type=3 -> Deco
1799 return ; No 1820 return ; No
1800 incf WREG,W ; 1-5 1821 btfss PLUSW1,1 ; Test for Bit0 and 1 -> type=3 -> Deco
1801 cpfseq active_gas ; is this gas current gas? 1822 return ; No
1802 bra check_gas_common2 ; No 1823 incf WREG,W ; 1-5
1803 return ; Yes, skip test for active gas 1824 cpfseq active_gas ; is this gas current gas?
1825 bra check_gas_common2 ; No
1826 return ; Yes, skip test for active gas
1804 check_gas_common2: 1827 check_gas_common2:
1805 decf WREG,W ; 0-4 1828 decf WREG,W ; 0-4
1806 movwf hi ; Save tested gas 0-4 1829 movwf hi ; Save tested gas 0-4
1807 lfsr FSR1,opt_OC_bail_gas_change 1830 lfsr FSR1,opt_OC_bail_gas_change
1808 movff PLUSW1,lo ; Change depth into lo 1831 movff PLUSW1,lo ; Change depth into lo
1809 movlw minimum_change_depth 1832 movlw minimum_change_depth
1810 cpfsgt lo ; Change depth>minimum_change_depth? 1833 cpfsgt lo ; Change depth>minimum_change_depth?
1811 return ; No, Change depth not deep enough, skip! 1834 return ; No, Change depth not deep enough, skip!
1812 movf xC+0,W ; load depth in m into WREG 1835 movf xC+0,W ; load depth in m into WREG
1813 cpfsgt lo ; gas_change_depth < current depth? 1836 cpfsgt lo ; gas_change_depth < current depth?
1814 bra check_gas_common3 ; No, check if we are within the better_gas_window_pos window 1837 bra check_gas_common3 ; No, check if we are within the better_gas_window_pos window
1815 incf hi,W ; 1-5 1838 incf hi,W ; 1-5
1816 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available 1839 movff WREG,better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available
1817 movlw better_gas_window_neg 1840 movlw better_gas_window_neg
1818 subwf lo,W ; Change depth-better_gas_window_neg 1841 subwf lo,W ; Change depth-better_gas_window_neg
1819 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg? 1842 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg?
1820 bra check_gas_common4 ; Ok, now check the better gas ppO2<char_I_ppO2_max 1843 bra check_gas_common4 ; Ok, now check the better gas ppO2<char_I_ppO2_max
1821 return 1844 return
1822
1823 check_gas_common3: 1845 check_gas_common3:
1824 incf hi,W ; 1-5 1846 incf hi,W ; 1-5
1825 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available 1847 movff WREG,better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available
1826 movlw better_gas_window_pos 1848 movlw better_gas_window_pos
1827 addwf lo,W ; Change depth+better_gas_window_pos 1849 addwf lo,W ; Change depth+better_gas_window_pos
1828 cpfsgt xC+0 ; current depth>Change depth+better_gas_window_pos? 1850 cpfsgt xC+0 ; current depth>Change depth+better_gas_window_pos?
1829 bra check_gas_common4 ; Ok, now check the better gas ppO2<char_I_ppO2_max 1851 bra check_gas_common4 ; Ok, now check the better gas ppO2<char_I_ppO2_max
1830 return 1852 return
1831
1832 check_gas_common4: 1853 check_gas_common4:
1833 movf hi,W ; gas 0-4 into WREG 1854 movf hi,W ; gas 0-4 into WREG
1834 lfsr FSR1,char_I_deco_O2_ratio ; load base address char_I_deco_O2_ratio array 1855 lfsr FSR1,char_I_deco_O2_ratio ; load base address char_I_deco_O2_ratio array
1835 movff PLUSW1,lo ; read O2 ratio from array into lo 1856 movff PLUSW1,lo ; read O2 ratio from array into lo
1836 1857
1837 SAFE_2BYTE_COPY amb_pressure, xA 1858 SAFE_2BYTE_COPY amb_pressure, xA
1838 movlw d'10' 1859 movlw d'10'
1839 movwf xB+0 1860 movwf xB+0
1840 clrf xB+1 1861 clrf xB+1
1841 call div16x16 ; xC=p_amb/10 1862 call div16x16 ; xC=p_amb/10
1842 movff xC+0,xA+0 1863 movff xC+0,xA+0
1843 movff xC+1,xA+1 1864 movff xC+1,xA+1
1844 movff lo,xB+0 ; =O2 ratio 1865 movff lo,xB+0 ; =O2 ratio
1845 clrf xB+1 1866 clrf xB+1
1846 call mult16x16 ; lo * p_amb/10 1867 call mult16x16 ; lo * p_amb/10
1847 1868
1848 ; Check very high ppO2 manually 1869 ; Check very high ppO2 manually
1849 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar? 1870 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar?
1850 return ; Done. 1871 return ; Done.
1851 ; Check if ppO2>3,30bar 1872 ; Check if ppO2>3,30bar
1852 btfsc xC+1,7 1873 btfsc xC+1,7
1853 return ; Done. 1874 return ; Done.
1854 1875
1855 ; Check for low ppo2 1876 ; Check for low ppo2
1856 movff xC+0,sub_b+0 1877 movff xC+0,sub_b+0
1857 movff xC+1,sub_b+1 1878 movff xC+1,sub_b+1
1858 movff char_I_ppO2_min,WREG 1879 movff char_I_ppO2_min,WREG
1859 mullw d'100' ; char_I_ppO2_min*100 1880 mullw d'100' ; char_I_ppO2_min*100
1860 movff PRODL,sub_a+0 1881 movff PRODL,sub_a+0
1861 movff PRODH,sub_a+1 1882 movff PRODH,sub_a+1
1862 call subU16 ; sub_c = sub_a - sub_b 1883 call subU16 ; sub_c = sub_a - sub_b
1863 btfss neg_flag 1884 btfss neg_flag
1864 return ; Done (Too low). 1885 return ; Done (Too low).
1865 1886
1866 ;check if we are within our warning thresholds! 1887 ;check if we are within our warning thresholds!
1867 movff xC+0,sub_a+0 1888 movff xC+0,sub_a+0
1868 movff xC+1,sub_a+1 1889 movff xC+1,sub_a+1
1869 movff char_I_ppO2_max_deco,WREG ; ppO2 max for MOD calculation and color coding in divemode 1890 movff char_I_ppO2_max_deco,WREG ; ppO2 max for MOD calculation and color coding in divemode
1870 addlw .1 ; e.g. >1.60 1891 addlw .1 ; e.g. >1.60
1871 mullw d'100' ; char_I_ppO2_max*100 1892 mullw d'100' ; char_I_ppO2_max*100
1872 movff PRODL,sub_b+0 1893 movff PRODL,sub_b+0
1873 movff PRODH,sub_b+1 1894 movff PRODH,sub_b+1
1874 call subU16 ; sub_c = sub_a - sub_b 1895 call subU16 ; sub_c = sub_a - sub_b
1875 btfsc neg_flag 1896 btfsc neg_flag
1876 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode 1897 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode
1877 return ; Done. 1898 return ; Done.
1878 1899
1879 check_dil_common: ; With Dil 0-4 in WREG 1900
1880 btfsc better_gas_available ; Better Diluent already found? 1901 check_dil_common: ; With Dil 0-4 in WREG
1881 return ; Yes, return 1902 btfsc better_gas_available ; Better Diluent already found?
1882 lfsr FSR1,opt_dil_type ; 0=Disabled, 1=First, 2=Normal 1903 return ; Yes, return
1883 tstfsz PLUSW1 ; =0? 1904 lfsr FSR1,opt_dil_type ; 0=Disabled, 1=First, 2=Normal
1884 bra check_dil_common1 ; No 1905 tstfsz PLUSW1 ; =0?
1885 return ; Yes, skip inactive diluents for test 1906 bra check_dil_common1 ; No
1907 return ; Yes, skip inactive diluents for test
1886 check_dil_common1: 1908 check_dil_common1:
1887 incf WREG,W ; 1-5 1909 incf WREG,W ; 1-5
1888 cpfseq active_gas ; is this the current diluent? 1910 cpfseq active_gas ; is this the current diluent?
1889 bra check_dil_common2 ; No 1911 bra check_dil_common2 ; No
1890 return ; Yes, skip test for active diluent 1912 return ; Yes, skip test for active diluent
1891 check_dil_common2: 1913 check_dil_common2:
1892 decf WREG,W ; 0-4 1914 decf WREG,W ; 0-4
1893 movwf hi ; Save tested diluent 0-4 1915 movwf hi ; Save tested diluent 0-4
1894 lfsr FSR1,char_I_dil_change 1916 lfsr FSR1,char_I_dil_change
1895 movff PLUSW1,lo ; Change depth into lo 1917 movff PLUSW1,lo ; Change depth into lo
1896 movlw minimum_change_depth 1918 movlw minimum_change_depth
1897 cpfsgt lo ; Change depth>minimum_change_depth? 1919 cpfsgt lo ; Change depth>minimum_change_depth?
1898 return ; No, Change depth not deep enough, skip! 1920 return ; No, Change depth not deep enough, skip!
1899 movf xC+0,W ; load depth in m into WREG 1921 movf xC+0,W ; load depth in m into WREG
1900 cpfsgt lo ; gas_change_depth < current depth? 1922 cpfsgt lo ; gas_change_depth < current depth?
1901 return ; No, check next gas 1923 return ; No, check next gas
1902 incf hi,W ; 1-5 1924 incf hi,W ; 1-5
1903 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available 1925 movff WREG,better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available
1904 movlw better_gas_window_neg 1926 movlw better_gas_window_neg
1905 subwf lo,W ; Change depth-better_gas_window_neg 1927 subwf lo,W ; Change depth-better_gas_window_neg
1906 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg? 1928 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg?
1907 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode 1929 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode
1908 return 1930 return
1909 1931
1910 1932
1911 ;============================================================================= 1933 ;=============================================================================
1912 ; Check for Auto-SP 1934 ; Check for Auto-SP
1913 ; 1935 ;
1914 check_dive_autosp: ; Check for Auto-SP 1936 check_dive_autosp: ; Check for Auto-SP
1915 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 1937 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP
1916 sublw .2 ; opt_ccr_mode = 2 (Auto SP)? 1938 sublw .2 ; opt_ccr_mode = 2 (Auto SP)?
1917 bz check_dive_autosp2 ; Yes, check 1939 bz check_dive_autosp2 ; Yes, check
1918 return ; No, return for Sensor or Fixed mode 1940 return ; No, return for Sensor or Fixed mode
1919 check_dive_autosp2: 1941 check_dive_autosp2:
1920 SAFE_2BYTE_COPY rel_pressure,xA 1942 SAFE_2BYTE_COPY rel_pressure,xA
1921 movlw d'100' 1943 movlw d'100'
1922 movwf xB+0 1944 movwf xB+0
1923 clrf xB+1 1945 clrf xB+1
1924 call div16x16 ; compute depth in full m -> result in xC+0 1946 call div16x16 ; compute depth in full m -> result in xC+0
1925 ; Check SP2 1947 ; Check SP2
1926 btfsc sp2_switched ; =1: This setpoint has been autoselected already 1948 btfsc sp2_switched ; =1: This setpoint has been autoselected already
1927 bra check_dive_autosp3 ; Skip check 1949 bra check_dive_autosp3 ; Skip check
1928 movff char_I_setpoint_change+1,lo ; Get depth in m 1950 movff char_I_setpoint_change+1,lo ; Get depth in m
1929 tstfsz lo ; =0? 1951 tstfsz lo ; =0?
1930 bra check_dive_autosp2a ; No, continue 1952 bra check_dive_autosp2a ; No, continue
1931 bra check_dive_autosp3 ; Skip check 1953 bra check_dive_autosp3 ; Skip check
1932 check_dive_autosp2a: 1954 check_dive_autosp2a:
1933 decf lo,W ; -1 -> WREG 1955 decf lo,W ; -1 -> WREG
1934 cpfsgt xC+0 ; Compare with depth 1956 cpfsgt xC+0 ; Compare with depth
1935 bra check_dive_autosp3 ; lower depth, do not switch 1957 bra check_dive_autosp3 ; lower depth, do not switch
1936 ; auto switch to SP2 1958 ; auto switch to SP2
1937 movff char_I_setpoint_cbar+1,char_I_const_ppO2 ; Use SetPoint 1959 movff char_I_setpoint_cbar+1,char_I_const_ppO2 ; Use SetPoint
1938 rcall xmit_sp_set_flag 1960 rcall xmit_sp_set_flag
1939 bsf sp2_switched ; Set flag 1961 bsf sp2_switched ; Set flag
1940 check_dive_autosp3: 1962 check_dive_autosp3:
1941 ; Check SP3 1963 ; Check SP3
1942 btfsc sp3_switched ;=1: This setpoint has been autoselected already 1964 btfsc sp3_switched ;=1: This setpoint has been autoselected already
1943 bra check_dive_autosp4 ; Skip check 1965 bra check_dive_autosp4 ; Skip check
1944 movff char_I_setpoint_change+2,lo ; Get depth in m 1966 movff char_I_setpoint_change+2,lo ; Get depth in m
1945 tstfsz lo ; =0? 1967 tstfsz lo ; =0?
1946 bra check_dive_autosp3a ; No, continue 1968 bra check_dive_autosp3a ; No, continue
1947 bra check_dive_autosp4 ; Skip check 1969 bra check_dive_autosp4 ; Skip check
1948 check_dive_autosp3a: 1970 check_dive_autosp3a:
1949 decf lo,W ; -1 -> WREG 1971 decf lo,W ; -1 -> WREG
1950 cpfsgt xC+0 ; Compare with depth 1972 cpfsgt xC+0 ; Compare with depth
1951 bra check_dive_autosp4 ; lower depth, do not switch 1973 bra check_dive_autosp4 ; lower depth, do not switch
1952 ; auto switch to SP3 1974 ; auto switch to SP3
1953 movff char_I_setpoint_cbar+2,char_I_const_ppO2 ; Use SetPoint 1975 movff char_I_setpoint_cbar+2,char_I_const_ppO2 ; Use SetPoint
1954 rcall xmit_sp_set_flag 1976 rcall xmit_sp_set_flag
1955 bsf sp3_switched ; Set flag 1977 bsf sp3_switched ; Set flag
1956 check_dive_autosp4: 1978 check_dive_autosp4:
1957 ; Check SP4 1979 ; Check SP4
1958 btfsc sp4_switched ;=1: This setpoint has been autoselected already 1980 btfsc sp4_switched ;=1: This setpoint has been autoselected already
1959 bra check_dive_autosp5 ; Skip check 1981 bra check_dive_autosp5 ; Skip check
1960 movff char_I_setpoint_change+3,lo ; Get depth in m 1982 movff char_I_setpoint_change+3,lo ; Get depth in m
1961 tstfsz lo ; =0? 1983 tstfsz lo ; =0?
1962 bra check_dive_autosp4a ; No, continue 1984 bra check_dive_autosp4a ; No, continue
1963 bra check_dive_autosp5 ; Skip check 1985 bra check_dive_autosp5 ; Skip check
1964 check_dive_autosp4a: 1986 check_dive_autosp4a:
1965 decf lo,W ; -1 -> WREG 1987 decf lo,W ; -1 -> WREG
1966 cpfsgt xC+0 ; Compare with depth 1988 cpfsgt xC+0 ; Compare with depth
1967 bra check_dive_autosp5 ; lower depth, do not switch 1989 bra check_dive_autosp5 ; lower depth, do not switch
1968 ; auto switch to SP4 1990 ; auto switch to SP4
1969 movff char_I_setpoint_cbar+3,char_I_const_ppO2 ; Use SetPoint 1991 movff char_I_setpoint_cbar+3,char_I_const_ppO2 ; Use SetPoint
1970 rcall xmit_sp_set_flag 1992 rcall xmit_sp_set_flag
1971 bsf sp4_switched ; Set flag 1993 bsf sp4_switched ; Set flag
1972 check_dive_autosp5: 1994 check_dive_autosp5:
1973 ; Check SP5 1995 ; Check SP5
1974 btfsc sp5_switched ;=1: This setpoint has been autoselected already 1996 btfsc sp5_switched ;=1: This setpoint has been autoselected already
1975 bra check_dive_autosp6 ; Skip check 1997 bra check_dive_autosp6 ; Skip check
1976 movff char_I_setpoint_change+4,lo ; Get depth in m 1998 movff char_I_setpoint_change+4,lo ; Get depth in m
1977 tstfsz lo ; =0? 1999 tstfsz lo ; =0?
1978 bra check_dive_autosp5a ; No, continue 2000 bra check_dive_autosp5a ; No, continue
1979 bra check_dive_autosp6 ; Skip check 2001 bra check_dive_autosp6 ; Skip check
1980 check_dive_autosp5a: 2002 check_dive_autosp5a:
1981 decf lo,W ; -1 -> WREG 2003 decf lo,W ; -1 -> WREG
1982 cpfsgt xC+0 ; Compare with depth 2004 cpfsgt xC+0 ; Compare with depth
1983 bra check_dive_autosp6 ; lower depth, do not switch 2005 bra check_dive_autosp6 ; lower depth, do not switch
1984 ; auto switch to SP5 2006 ; auto switch to SP5
1985 movff char_I_setpoint_cbar+4,char_I_const_ppO2 ; Use SetPoint 2007 movff char_I_setpoint_cbar+4,char_I_const_ppO2 ; Use SetPoint
1986 rcall xmit_sp_set_flag 2008 rcall xmit_sp_set_flag
1987 bsf sp5_switched ; Set flag 2009 bsf sp5_switched ; Set flag
1988 check_dive_autosp6: 2010 check_dive_autosp6:
1989 return 2011 return
1990 2012
1991 xmit_sp_set_flag: 2013 xmit_sp_set_flag:
1992 movff char_I_const_ppO2,WREG 2014 movff char_I_const_ppO2,WREG
1993 call transmit_setpoint ; Transmit current setpoint from WREG (in cbar) to external electronics 2015 call transmit_setpoint ; Transmit current setpoint from WREG (in cbar) to external electronics
1994 bsf setpoint_changed ; Set flag (For profile) 2016 bsf setpoint_changed ; Set flag (for profile)
1995 bsf event_occured ; Set global event byte 2017 bsf event_occured ; Set event flag
1996 return 2018 return
2019
2020 set_logbook_marker:
2021 bcf FLAG_set_marker ; clear flag
2022 movlw d'6' ; set type of Alarm (manual marker)
2023 movwf AlarmType ; copy to Alarm Register
2024 bsf event_occured ; Set event flag
2025 return
1997 2026
1998 ;============================================================================= 2027 ;=============================================================================
1999 ; Setup everything to enter divemode. 2028 ; Setup everything to enter divemode.
2000 ; 2029 ;
2001 dive_boot_oc: 2030 dive_boot_oc:
2002 rcall get_first_gas_to_WREG ; Gets first gas (1-5) into WREG 2031 rcall get_first_gas_to_WREG ; Gets first gas (1-5) into WREG
2003 rcall setup_gas_registers ; set-up of gas parameters of currently breathed gas (with WREG = gas 1-5) 2032 rcall setup_gas_registers ; set-up of gas parameters of currently breathed gas (with WREG = gas 1-5)
2004 rcall deco_setup_oc_gases ; set-up of gas list for deco calculations (with WREG = gas 1-5) 2033 rcall deco_setup_oc_gases ; set-up of gas list for deco calculations (with WREG = gas 1-5)
2005 return 2034 return
2006 2035
2007 dive_boot_cc: 2036 dive_boot_cc:
2008 bcf is_bailout ; =1: Bailout 2037 bcf is_bailout ; =1: Bailout
2009 bcf setpoint_fallback ; =1: Fallback to SP1 due to external O2 sensor failure 2038 bcf setpoint_fallback ; =1: Fallback to SP1 due to external O2 sensor failure
2010 bcf blinking_setpoint ; Reset blinking SP flag 2039 bcf blinking_setpoint ; Reset blinking SP flag
2011 2040
2012 ; revoke sensors from usage if they do not have a valid calibration 2041 ; revoke sensors from usage if they do not have a valid calibration
2013 bsf use_O2_sensor1 2042 bsf use_O2_sensor1
2014 bsf use_O2_sensor2 2043 bsf use_O2_sensor2
2015 bsf use_O2_sensor3 2044 bsf use_O2_sensor3
2017 bcf use_O2_sensor1 2046 bcf use_O2_sensor1
2018 btfss sensor2_calibrated_ok 2047 btfss sensor2_calibrated_ok
2019 bcf use_O2_sensor2 2048 bcf use_O2_sensor2
2020 btfss sensor3_calibrated_ok 2049 btfss sensor3_calibrated_ok
2021 bcf use_O2_sensor3 2050 bcf use_O2_sensor3
2022 2051
2023 ; In pSCR mode, only settings 0 (calculated ppO2) and 1 (ppO2 from sensors) are defined. 2052 ; In pSCR mode, only settings 0 (calculated ppO2) and 1 (ppO2 from sensors) are defined.
2024 ; In case we still have 3 (auto SP) selected out of previous ccr mode, we reset to 0. 2053 ; In case we still have 3 (auto SP) selected out of previous ccr mode, we reset to 0.
2025 btfss FLAG_pscr_mode 2054 btfss FLAG_pscr_mode
2026 bra dive_boot_cc_1 2055 bra dive_boot_cc_1
2027 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 2056 movff opt_ccr_mode,WREG ; =0: Fixed SP (CCR) / calculated SP (pSCR), =1: Sensor, =2: Auto SP
2028 sublw .2 ; opt_ccr_mode = 1 (Auto SP)? 2057 sublw .2 ; opt_ccr_mode = 1 (Auto SP)?
2029 bnz dive_boot_cc_1 2058 bnz dive_boot_cc_1
2030 movlw .0 2059 movlw .0
2031 movff WREG,opt_ccr_mode 2060 movff WREG,opt_ccr_mode
2032 2061
2033 dive_boot_cc_1: 2062 dive_boot_cc_1:
2034 bsf setpoint_changed ; Set flag (For profile) 2063 bsf setpoint_changed ; set flag (for profile)
2035 bcf sp2_switched ; =1: This setpoint has been autoselected already 2064 bcf sp2_switched ; =1: This setpoint has been auto-selected already
2036 bcf sp3_switched ; =1: This setpoint has been autoselected already 2065 bcf sp3_switched ; =1: This setpoint has been auto-selected already
2037 bcf sp4_switched ; =1: This setpoint has been autoselected already 2066 bcf sp4_switched ; =1: This setpoint has been auto-selected already
2038 bcf sp5_switched ; =1: This setpoint has been autoselected already 2067 bcf sp5_switched ; =1: This setpoint has been auto-selected already
2039 2068
2040 rcall get_first_dil_to_WREG ; get first gas (1-5) into WREG 2069 rcall get_first_dil_to_WREG ; get first gas (1-5) into WREG
2041 rcall setup_dil_registers ; set-up of gas parameters for currently breathed gas (with WREG = current gas 1-5) 2070 rcall setup_dil_registers ; set-up of gas parameters for currently breathed gas (with WREG = current gas 1-5)
2042 rcall deco_setup_cc_diluents ; set-up of gas list for deco calculations (with WREG = current gas 1-5) 2071 rcall deco_setup_cc_diluents ; set-up of gas list for deco calculations (with WREG = current gas 1-5)
2043 2072
2044 ; Start with SP1 (CCR) or 0 (pSCR) as default. 2073 ; Start with SP1 (CCR) or 0 (pSCR) as default.
2045 ; If in sensor mode, this value will be overwritten by calc_deko_divemode_sensor 2074 ; If in sensor mode, this value will be overwritten by calc_deko_divemode_sensor
2046 clrf WREG ; preload WREG with setpoint value 0 for pSCR calculated 2075 clrf WREG ; preload WREG with setpoint value 0 for pSCR calculated
2047 btfss FLAG_ccr_mode ; are we in CCR mode? 2076 btfss FLAG_ccr_mode ; are we in CCR mode?
2048 bra dive_boot_cc_2 ; NO - keep preloaded value 2077 bra dive_boot_cc_2 ; NO - keep preloaded value
2049 movff char_I_setpoint_cbar+0,WREG ; YES - get value of setpoint 1 2078 movff char_I_setpoint_cbar+0,WREG ; YES - get value of setpoint 1
2050 dive_boot_cc_2: 2079 dive_boot_cc_2:
2051 movff WREG,char_I_const_ppO2 ; write setpoint to deco engine 2080 movff WREG,char_I_const_ppO2 ; write setpoint to deco engine
2052 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics 2081 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics
2053 goto calc_deko_divemode_sensor ; read & process sensor data (and return) 2082 goto calc_deko_divemode_sensor ; read & process sensor data (and return)
2054 2083
2055 diveloop_boot: 2084 diveloop_boot:
2056 call restart_set_modes_and_flags 2085 call restart_set_modes_and_flags
2057 2086
2058 call I2C_sleep_accelerometer ; Stop accelerometer 2087 call I2C_sleep_accelerometer ; stop accelerometer
2059 call I2C_sleep_compass ; Stop compass 2088 call I2C_sleep_compass ; stop compass
2060 2089
2061 clrf WREG 2090 clrf WREG
2062 movff WREG,max_pressure+0 ; clear some variables 2091 movff WREG,max_pressure+0 ; clear some variables
2063 movff WREG,max_pressure+1 2092 movff WREG,max_pressure+1
2064 2093
2065 ; init in invalid data state 2094 ; init in invalid data state
2066 clrf WREG ; set WREG to 0 2095 clrf WREG ; set WREG to 0
2067 bsf WREG,int_invalid_flag ; set invalid flag 2096 bsf WREG,int_invalid_flag ; set invalid flag
2068 bsf WREG,int_is_zero ; set zero flag 2097 bsf WREG,int_is_zero ; set zero flag
2069 movff WREG,int_O_tank_pres_need+1 ; Set flags for tank pressure needs = 0 before p2_deco.c 2098 movff WREG,int_O_tank_pres_need+1 ; Set flags for tank pressure needs = 0 before p2_deco.c
2070 movff WREG,int_O_tank_pres_need+3 ; can do it. If this is not done here and the gas needs 2099 movff WREG,int_O_tank_pres_need+3 ; can do it. If this is not done here and the gas needs
2071 movff WREG,int_O_tank_pres_need+5 ; custom view is shown before p2_deco.c completes the first 2100 movff WREG,int_O_tank_pres_need+5 ; custom view is shown before p2_deco.c completes the first
2072 movff WREG,int_O_tank_pres_need+7 ; deco calculation, some rubbish numbers from last dive of 2101 movff WREG,int_O_tank_pres_need+7 ; deco calculation, some rubbish numbers from last dive of
2073 movff WREG,int_O_tank_pres_need+9 ; simulation may be shown 2102 movff WREG,int_O_tank_pres_need+9 ; simulation may be shown
2074 2103
2075 ; configure the deco engine: 2104 ; configure the deco engine:
2076 movff char_O_deco_status,WREG ; bank-safe copy 2105 movff char_O_deco_status,WREG ; bank-safe copy
2077 bsf WREG,DECO_STATUS_0_FLAG ; configure init ... 2106 bsf WREG,DECO_STATUS_0_FLAG ; configure init ...
2078 bsf WREG,DECO_STATUS_1_FLAG ; ... state, 2107 bsf WREG,DECO_STATUS_1_FLAG ; ... state,
2079 bcf WREG,DECO_PLAN_FLAG ; normal plan mode, 2108 bcf WREG,DECO_PLAN_FLAG ; normal plan mode,
2080 bsf WREG,DECO_CNS_FLAG ; enable CNS calculation (CNS at end of dive), 2109 bsf WREG,DECO_CNS_FLAG ; enable CNS calculation (CNS at end of dive),
2081 bcf WREG,DECO_VOLUME_FLAG ; disable gas volume calculation, and 2110 bcf WREG,DECO_VOLUME_FLAG ; disable gas volume calculation, and
2082 bcf WREG,DECO_ASCENT_FLAG ; disable delayed ascent calculation 2111 bcf WREG,DECO_ASCENT_FLAG ; disable delayed ascent calculation
2083 movff WREG,char_O_deco_status ; bank-safe copy back 2112 movff WREG,char_O_deco_status ; bank-safe copy back
2084 2113
2085 clrf WREG 2114 clrf WREG
2086 movff WREG,char_O_main_status ; reset char_O_main_status 2115 movff WREG,char_O_main_status ; reset char_O_main_status
2087 2116
2088 movlw deco_distance 2117 movlw deco_distance
2089 movff WREG,char_I_deco_distance 2118 movff WREG,char_I_deco_distance
2090 movff opt_last_stop,char_I_depth_last_deco 2119 movff opt_last_stop,char_I_depth_last_deco
2091 movff opt_GF_low,char_I_GF_Low_percentage 2120 movff opt_GF_low,char_I_GF_Low_percentage
2092 movff opt_GF_high,char_I_GF_High_percentage 2121 movff opt_GF_high,char_I_GF_High_percentage
2093 2122
2094 bcf use_agf ; Start with normal GF set 2123 bcf use_agf ; Start with normal GF set
2095 bcf divemode_menu ; clear divemode menu flag 2124 bcf divemode_menu ; clear divemode menu flag
2096 2125
2097 bcf alternative_divelayout ; Start with default layout 2126 bcf alternative_divelayout ; Start with default layout
2098 2127
2099 bcf blinking_depth_prev ; clear flag for blinking depth ## NEW BUGFIX 2128 bcf blinking_depth_prev ; clear flag for blinking depth
2100 bcf blinking_depth_warning ; clear flag for blinking depth ## NEW BUGFIX 2129 bcf blinking_depth_warning ; clear flag for blinking depth
2101 bcf blinking_depth_toggle ; clear flag for blinking depth ## NEW BUGFIX 2130 bcf blinking_depth_toggle ; clear flag for blinking depth
2102 2131
2103 movlw d'1' 2132 movlw d'1'
2104 movwf apnoe_max_pressure+0 2133 movwf apnoe_max_pressure+0
2105 clrf apnoe_max_pressure+1 2134 clrf apnoe_max_pressure+1
2106 ; clrf apnoe_surface_mins 2135 ; clrf apnoe_surface_mins
2107 ; clrf apnoe_surface_secs 2136 ; clrf apnoe_surface_secs
2108 clrf apnoe_mins 2137 clrf apnoe_mins
2109 clrf divemins+0 2138 clrf divemins+0
2110 clrf divemins+1 2139 clrf divemins+1
2111 2140
2112 ; Copy date and time for logbook 2141 ; Copy date and time for logbook
2113 movff year,start_year 2142 movff year,start_year
2114 movff month,start_month 2143 movff month,start_month
2115 movff day,start_day 2144 movff day,start_day
2116 movff hours,start_hours 2145 movff hours,start_hours
2117 movff mins,start_mins 2146 movff mins,start_mins
2118 2147
2119 movff int_O_CNS_fraction+0,CNS_start+0 ; save CNS value at beginning of dive 2148 movff int_O_CNS_fraction+0,CNS_start+0 ; save CNS value at beginning of dive
2120 movff int_O_CNS_fraction+1,WREG ; get high byte to WREG 2149 movff int_O_CNS_fraction+1,WREG ; get high byte to WREG
2121 bcf WREG,int_warning_flag ; clear warning flag bit 2150 bcf WREG,int_warning_flag ; clear warning flag bit
2122 movff WREG,CNS_start+1 ; move high byte on 2151 movff WREG,CNS_start+1 ; move high byte on
2123 movff int_O_gradient_factor+0,GF_start ; save GF value at beginning of dive (only lower byte used for value) 2152 movff int_O_gradient_factor+0,GF_start ; save GF value at beginning of dive (only lower byte used for value)
2124 2153
2125 bcf no_more_divesecs ; =1: do no longer show seconds in divemode 2154 bcf no_more_divesecs ; =1: do no longer show seconds in divemode
2126 bcf divemode_menu_active 2155 bcf divemode_menu_active
2127 clrf menupos 2156 clrf menupos1
2128 clrf menupos2 ; Reset to zero (Zero=no premenu or simulator task) 2157 clrf menupos2 ; Reset to zero (Zero=no premenu or simulator task)
2129 bsf sensors_agree ; init of sensors disagree warning system 2158 bsf sensors_agree ; init of sensors disagree warning system
2130 2159
2131 btfsc FLAG_ccr_mode 2160 btfsc FLAG_ccr_mode
2132 bra diveloop_boot_cc 2161 bra diveloop_boot_cc
2133 btfsc FLAG_pscr_mode 2162 btfsc FLAG_pscr_mode
2134 bra diveloop_boot_cc 2163 bra diveloop_boot_cc
2135 rcall dive_boot_oc 2164 rcall dive_boot_oc
2136 bra diveloop_boot_cont 2165 bra diveloop_boot_cont
2137 2166
2138 diveloop_boot_cc: 2167 diveloop_boot_cc:
2139 rcall dive_boot_cc 2168 rcall dive_boot_cc
2140 2169
2141 diveloop_boot_cont: 2170 diveloop_boot_cont:
2142 ; Copy opt_dil_types into backup (For "lost gas" feature) 2171 ; Copy opt_dil_types into backup (For "lost gas" feature)
2143 movff opt_dil_type+0,opt_dil_type_backup+0 ; 0=Disabled, 1=First, 2=Normal 2172 movff opt_dil_type+0,opt_dil_type_backup+0 ; 0=Disabled, 1=First, 2=Normal
2144 movff opt_dil_type+1,opt_dil_type_backup+1 ; 0=Disabled, 1=First, 2=Normal 2173 movff opt_dil_type+1,opt_dil_type_backup+1 ; 0=Disabled, 1=First, 2=Normal
2145 movff opt_dil_type+2,opt_dil_type_backup+2 ; 0=Disabled, 1=First, 2=Normal 2174 movff opt_dil_type+2,opt_dil_type_backup+2 ; 0=Disabled, 1=First, 2=Normal
2146 movff opt_dil_type+3,opt_dil_type_backup+3 ; 0=Disabled, 1=First, 2=Normal 2175 movff opt_dil_type+3,opt_dil_type_backup+3 ; 0=Disabled, 1=First, 2=Normal
2147 movff opt_dil_type+4,opt_dil_type_backup+4 ; 0=Disabled, 1=First, 2=Normal 2176 movff opt_dil_type+4,opt_dil_type_backup+4 ; 0=Disabled, 1=First, 2=Normal
2148 ; Copy opt_gas_types into backup (For "lost gas" feature) 2177 ; Copy opt_gas_types into backup (For "lost gas" feature)
2149 movff opt_gas_type+0,opt_gas_type_backup+0 ; 0=Disabled, 1=First, 2=Travel, 3=Deco 2178 movff opt_gas_type+0,opt_gas_type_backup+0 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2150 movff opt_gas_type+1,opt_gas_type_backup+1 ; 0=Disabled, 1=First, 2=Travel, 3=Deco 2179 movff opt_gas_type+1,opt_gas_type_backup+1 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2151 movff opt_gas_type+2,opt_gas_type_backup+2 ; 0=Disabled, 1=First, 2=Travel, 3=Deco 2180 movff opt_gas_type+2,opt_gas_type_backup+2 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2152 movff opt_gas_type+3,opt_gas_type_backup+3 ; 0=Disabled, 1=First, 2=Travel, 3=Deco 2181 movff opt_gas_type+3,opt_gas_type_backup+3 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2153 movff opt_gas_type+4,opt_gas_type_backup+4 ; 0=Disabled, 1=First, 2=Travel, 3=Deco 2182 movff opt_gas_type+4,opt_gas_type_backup+4 ; 0=Disabled, 1=First, 2=Travel, 3=Deco
2154 ; Also copy change depths into backup (For "lost gas" feature) 2183 ; Also copy change depths into backup (For "lost gas" feature)
2155 movff char_I_dil_change+0,opt_dil_change_backup+0 ; Gas change depths Diluents 2184 movff char_I_dil_change+0,opt_dil_change_backup+0 ; Gas change depths Diluents
2156 movff char_I_dil_change+1,opt_dil_change_backup+1 ; Gas change depths Diluents 2185 movff char_I_dil_change+1,opt_dil_change_backup+1 ; Gas change depths Diluents
2157 movff char_I_dil_change+2,opt_dil_change_backup+2 ; Gas change depths Diluents 2186 movff char_I_dil_change+2,opt_dil_change_backup+2 ; Gas change depths Diluents
2158 movff char_I_dil_change+3,opt_dil_change_backup+3 ; Gas change depths Diluents 2187 movff char_I_dil_change+3,opt_dil_change_backup+3 ; Gas change depths Diluents
2159 movff char_I_dil_change+4,opt_dil_change_backup+4 ; Gas change depths Diluents 2188 movff char_I_dil_change+4,opt_dil_change_backup+4 ; Gas change depths Diluents
2160 ; Also copy change depths into backup (For "lost gas" feature) 2189 ; Also copy change depths into backup (For "lost gas" feature)
2161 movff opt_OC_bail_gas_change+0,opt_OC_bail_gas_change_backup+0; Gas change depths OC/Bailout 2190 movff opt_OC_bail_gas_change+0,opt_OC_bail_gas_change_backup+0; Gas change depths OC/Bailout
2162 movff opt_OC_bail_gas_change+1,opt_OC_bail_gas_change_backup+1; Gas change depths OC/Bailout 2191 movff opt_OC_bail_gas_change+1,opt_OC_bail_gas_change_backup+1; Gas change depths OC/Bailout
2163 movff opt_OC_bail_gas_change+2,opt_OC_bail_gas_change_backup+2; Gas change depths OC/Bailout 2192 movff opt_OC_bail_gas_change+2,opt_OC_bail_gas_change_backup+2; Gas change depths OC/Bailout
2164 movff opt_OC_bail_gas_change+3,opt_OC_bail_gas_change_backup+3; Gas change depths OC/Bailout 2193 movff opt_OC_bail_gas_change+3,opt_OC_bail_gas_change_backup+3; Gas change depths OC/Bailout
2165 movff opt_OC_bail_gas_change+4,opt_OC_bail_gas_change_backup+4; Gas change depths OC/Bailout 2194 movff opt_OC_bail_gas_change+4,opt_OC_bail_gas_change_backup+4; Gas change depths OC/Bailout
2166 2195
2167 clrf better_gas_number ; Clear better gas register 2196 clrf WREG
2197 movff WREG,better_gas_number ; clear better gas register
2168 2198
2169 bcf show_safety_stop ; =1: Show the safety stop 2199 bcf show_safety_stop ; =1: Show the safety stop
2170 clrf safety_stop_countdown ; Clear count-down 2200 clrf safety_stop_countdown ; Clear count-down
2171 2201
2172 clrf samplesecs 2202 clrf samplesecs
2173 clrf apnoe_timeout_counter ; timeout in minutes 2203 clrf apnoe_timeout_counter ; timeout in minutes
2174 clrf timeout_counter ; takes care of the timeout (Low byte) 2204 clrf timeout_counter1+0 ; takes care of the timeout (low byte)
2175 clrf timeout_counter2 ; takes care of the timeout (High byte) 2205 clrf timeout_counter1+1 ; takes care of the timeout (high byte)
2176 clrf AlarmType ; Clear all alarms 2206 clrf AlarmType ; Clear all alarms
2177 bcf event_occured ; clear flag 2207 bcf event_occured ; clear flag
2178 clrf average_depth_hold_total+0 2208 clrf average_depth_hold_total+0
2179 clrf average_depth_hold_total+1 2209 clrf average_depth_hold_total+1
2180 clrf average_depth_hold_total+2 2210 clrf average_depth_hold_total+2
2181 clrf average_depth_hold_total+3 ; Clear Non-Resettable Average 2211 clrf average_depth_hold_total+3 ; Clear Non-Resettable Average
2182 rcall reset_average1 ; Reset the resettable average depth 2212 rcall reset_average1 ; Reset the resettable average depth
2183 bcf decostop_active 2213 bcf decostop_active
2184 bcf better_gas_available ; =1: A better gas is available and a gas change is advised in divemode 2214 bcf better_gas_available ; =1: A better gas is available and a gas change is advised in divemode
2185 call ghostwriter_short_header ; Write short header with divenumber into profile memory 2215 call ghostwriter_short_header ; Write short header with divenumber into profile memory
2186 2216
2187 btfsc simulatormode_active 2217 btfsc simulatormode_active
2188 bra diveloop_boot_1 2218 bra diveloop_boot_1
2189 ; Normal mode = Surface pressure is the pressure 30mn before dive. 2219 ; Normal mode = Surface pressure is the pressure 30mn before dive.
2190 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ;copy surfacepressure to deco routine 2220 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ;copy surfacepressure to deco routine
2191 SAFE_2BYTE_COPY last_surfpressure_30min, last_surfpressure ;copy surfacepressure to last_surfpressure for correct depth 2221 SAFE_2BYTE_COPY last_surfpressure_30min, last_surfpressure ;copy surfacepressure to last_surfpressure for correct depth
2192 bra diveloop_boot_2 2222 bra diveloop_boot_2
2193 2223
2194 diveloop_boot_1: 2224 diveloop_boot_1:
2195 ; Simulator mode: Surface pressure is 1bar. 2225 ; Simulator mode: Surface pressure is 1bar.
2196 movlw LOW .1000 2226 movlw LOW .1000
2197 movff WREG,int_I_pres_surface+0 ; LOW copy surfacepressure to deco routine 2227 movff WREG,int_I_pres_surface+0 ; LOW copy surface pressure to deco routine
2198 movlw HIGH .1000 2228 movlw HIGH .1000
2199 movff WREG,int_I_pres_surface+1 ; HIGH copy surfacepressure to deco routine 2229 movff WREG,int_I_pres_surface+1 ; HIGH copy surface pressure to deco routine
2200 2230
2201 diveloop_boot_2: 2231 diveloop_boot_2:
2202 SAFE_2BYTE_COPY temperature,minimum_temperature ; Reset Min-Temp registers 2232 SAFE_2BYTE_COPY temperature,minimum_temperature ; Reset Min-Temp registers
2203 2233
2204 ; Init profile recording parameters 2234 call init_recording_params ; set up all the divisors
2205 movff samplingrate,samplesecs_value ; to avoid EEPROM access in the ISR 2235
2206 movlw div_temperature 2236 bsf ccr_diluent_setup ; For CCR mode (Required to have better gas working)
2207 movwf divisor_temperature ; load divisors for profile storage 2237 btfsc FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active
2208 movlw div_deco 2238 bra divemode_boot2
2209 movwf divisor_deco 2239 btfsc FLAG_pscr_mode
2210 movlw div_gf 2240 bra divemode_boot2
2211 movwf divisor_gf 2241 bcf ccr_diluent_setup ; For OC mode (Required to have better gas working)
2212 movlw div_ppo2_sensors
2213 movwf divisor_ppo2_sensors
2214 movlw div_decoplan
2215 movwf divisor_decoplan
2216 movlw div_cns
2217 movwf divisor_cns
2218 movlw div_tank
2219 movwf divisor_tank
2220
2221 btfss FLAG_apnoe_mode ; In Apnoe mode?
2222 bra divemode_boot1
2223
2224 ; Overwrite some parameters in Apnoe mode....
2225 movlw samplingrate_apnoe
2226 movwf samplesecs_value ; to avoid EEPROM access in the ISR
2227
2228 divemode_boot1:
2229 bsf ccr_diluent_setup ; For CCR mode (Required to have better gas working)
2230 btfsc FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active
2231 bra divemode_boot2
2232 btfsc FLAG_pscr_mode
2233 bra divemode_boot2
2234
2235 ; in OC Mode, disable ppO2 logging
2236 movlw .0
2237 movwf divisor_ppo2_sensors
2238
2239 bcf ccr_diluent_setup ; For OC mode (Required to have better gas working)
2240 2242
2241 divemode_boot2: 2243 divemode_boot2:
2242 bcf LEDg 2244 bcf LEDg ; switch off green LED / release reset to RX circuitry
2243 bcf LEDr 2245 bcf LEDr ; switch off red LED
2244 bcf realdive 2246 bcf realdive
2245 btfss simulatormode_active ; do not disable in simulator mode! 2247 btfss simulatormode_active ; do not disable in simulator mode!
2246 call disable_rs232 ; Disable RS232 2248 call disable_rs232 ; Disable RS232
2247 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) 2249 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
2248 call enable_rs232 ; Also sets to speed_normal ... 2250 call enable_rs232 ; Also sets to speed_normal ...
2249 ; Reset divetime seconds 2251 ; Reset divetime seconds
2250 movlw .2 ; Start at 2seconds 2252 movlw .2 ; Start at 2seconds
2251 movwf total_divetime_seconds+0 2253 movwf total_divetime_seconds+0
2252 clrf total_divetime_seconds+1 2254 clrf total_divetime_seconds+1
2253 movwf divesecs 2255 movwf divesecs
2254 movwf apnoe_secs 2256 movwf apnoe_secs
2255 bsf divemode2 ; displayed divetime is running (Divetime starts HERE) 2257 bsf divemode2 ; displayed divetime is running (Divetime starts HERE)
2256 return ; Done with divemode boot 2258 return ; Done with divemode boot
2259
2257 2260
2258 divemode_check_for_warnings: 2261 divemode_check_for_warnings:
2259 movlw .1 ; One warning at a time in alt. layout mode 2262 movlw .1 ; One warning at a time in alt. layout mode
2260 btfss alternative_divelayout 2263 btfss alternative_divelayout
2261 movlw .2 ; Two warnings at a time in default layout mode 2264 movlw .2 ; Two warnings at a time in default layout mode
2262 cpfsgt warning_counter ; only one (or two) warnings active? 2265 cpfsgt warning_counter ; only one (or two) warnings active?
2263 bra divemode_check_for_warnings1 ; Yes, update every second 2266 bra divemode_check_for_warnings1 ; Yes, update every second
2264 2267
2265 btfss secs,0 ; Every two seconds... 2268 btfss secs,0 ; Every two seconds...
2266 return 2269 return
2267 btfss secs,1 ; Every four seconds... 2270 btfss secs,1 ; Every four seconds...
2268 return 2271 return
2269 2272
2270 divemode_check_for_warnings1: 2273 divemode_check_for_warnings1:
2271 bcf warning_active ; Clear flag 2274 bcf warning_active ; Clear flag
2272 clrf warning_counter ; Clear counter 2275 clrf warning_counter ; Clear counter
2273 2276
2274 ; warnings sorted by severity, highest severity first 2277 ; warnings sorted by severity, highest severity first
2275 2278
2276 ; Warnings for all modes 2279 ; Warnings for all modes
2277 call check_warn_battery ; Check if the battery level should be displayed/warned 2280 call check_warn_battery ; Check if the battery level should be displayed/warned
2278 call check_divetimeout ; Not actually a warning. Check and show the divemode timeout 2281 call check_divetimeout ; Not actually a warning. Check and show the divemode timeout
2279 2282
2280 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode 2283 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode
2281 bra divemode_check_for_warnings2 2284 bra divemode_check_for_warnings2
2282 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode 2285 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode
2283 bra divemode_check_for_warnings2 2286 bra divemode_check_for_warnings2
2284 2287
2285 ; Warnings only in deco modes 2288 ; Warnings only in deco modes
2286 rcall check_ppO2 ; check ppO2 and displays warning, if required 2289 rcall check_ppO2 ; check ppO2 and displays warning, if required
2287 2290
2288 btfss sensors_agree ; are the sensor values within the threshold range? 2291 btfss sensors_agree ; are the sensor values within the threshold range?
2289 rcall check_warn_sensors_disagree ; NO - further evaluate 2292 rcall check_warn_sensors_disagree ; NO - further evaluate
2290 btfsc sensors_agree ; are the sensor values within the threshold range? 2293 btfsc sensors_agree ; are the sensor values within the threshold range?
2291 bcf sensor_warning ; YES - revoke memorized sensor warning 2294 bcf sensor_warning ; YES - revoke memorized sensor warning
2292 2295
2293 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings 2296 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings
2294 btfsc WREG,outside_warning_lock ; are we outside of the ZH-L16 model? 2297 btfsc WREG,outside_warning_lock ; are we outside of the ZH-L16 model?
2295 rcall warn_outside ; YES 2298 rcall warn_outside ; YES
2296 2299
2297 rcall check_IBCD ; check for IBCD attention or warning 2300 rcall check_IBCD ; check for IBCD attention or warning
2298 2301
2299 btfsc decostop_active ; In deco mode? 2302 btfsc decostop_active ; In deco mode?
2300 rcall check_and_store_gf_violation ; Yes, sets warnings, if required 2303 rcall check_and_store_gf_violation; Yes, sets warnings, if required
2301 2304
2302 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings 2305 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings
2303 btfsc WREG,mbubble_warning_lock ; do we have a microbubbles warning? 2306 btfsc WREG,mbubble_warning_lock ; do we have a microbubbles warning?
2304 rcall warn_mbubbles ; YES 2307 rcall warn_mbubbles ; YES
2305 2308
2306 rcall check_cns_violation ; Check CNS value and display it, if required 2309 rcall check_cns_violation ; Check CNS value and display it, if required
2307 2310
2308 ;btfsc decostop_active ; In deco mode? 2311 ;btfsc decostop_active ; In deco mode?
2309 rcall check_gas_needs ; show gas needs warning if any gas need is > threshold 2312 rcall check_gas_needs ; show gas needs warning if any gas need is > threshold
2310 2313
2311 rcall check_eod_cns_violation ; Check CNS values for end-of-dive and display warning, if required 2314 rcall check_eod_cns_violation ; Check CNS values for end-of-dive and display warning, if required
2312 2315
2313 call TFT_display_ftts ; Show @+x time 2316 call TFT_display_ftts ; Show @+x time
2314 2317
2315 btfsc use_agf ; In aGF mode? 2318 btfsc use_agf ; In aGF mode?
2316 rcall warn_agf ; Yes, show a warning for it 2319 rcall warn_agf ; Yes, show a warning for it
2317 2320
2318 btfsc setpoint_fallback ; =1: Fallback to SP1 due to external O2 sensor failure 2321 btfsc setpoint_fallback ; =1: Fallback to SP1 due to external O2 sensor failure
2319 rcall warn_fallback ; Show the warning 2322 rcall warn_fallback ; Show the warning
2320 2323
2321 divemode_check_for_warnings2: 2324 divemode_check_for_warnings2:
2322 ; Display the warning icon? 2325 ; Display the warning icon?
2323 btfsc warning_active ; Any warning active? 2326 btfsc warning_active ; Any warning active?
2324 bsf FLAG_TFT_divemode_warning ; Yes 2327 bsf FLAG_TFT_divemode_warning ; Yes
2325 btfss warning_active ; Any warning active? 2328 btfss warning_active ; Any warning active?
2326 bsf FLAG_TFT_divemode_warning_clear ; No, clear warning icon 2329 bsf FLAG_TFT_divemode_warning_clear ; No, clear warning icon
2327 2330
2328 ; Setup warning_page number 2331 ; Setup warning_page number
2329 incf warning_page,F 2332 incf warning_page,F
2330 movf warning_page,W 2333 movf warning_page,W
2331 bcf STATUS,C 2334 bcf STATUS,C
2332 btfss alternative_divelayout 2335 btfss alternative_divelayout
2333 rlcf warning_page,W ; *2 (But only in standard layout mode) 2336 rlcf warning_page,W ; *2 (But only in standard layout mode)
2334 cpfsgt warning_counter ; > warning_counter 2337 cpfsgt warning_counter ; > warning_counter
2335 clrf warning_page ; No, clear 2338 clrf warning_page ; No, clear
2336 2339
2337 ; Clear both rows of warnings if there is nothing to show at all 2340 ; Clear both rows of warnings if there is nothing to show at all
2338 tstfsz warning_counter ; any warnings? 2341 tstfsz warning_counter ; any warnings?
2339 bra divemode_check_for_warnings3 ; YES - look if second row needs to be cleared 2342 bra divemode_check_for_warnings3 ; YES - look if second row needs to be cleared
2340 bsf FLAG_TFT_dive_warning_text_clear ; Set flag 2343 bsf FLAG_TFT_dive_warning_text_clear ; Set flag
2341 return 2344 return
2342 divemode_check_for_warnings3: 2345 divemode_check_for_warnings3:
2343 2346
2344 2347
2345 ; Clear 2nd row of warnings if there is nothing to show (on this page) 2348 ; Clear 2nd row of warnings if there is nothing to show (on this page)
2346 btfss second_row_warning ; =1: The second row contains a warning 2349 btfss second_row_warning ; =1: The second row contains a warning
2347 bsf FLAG_TFT_dive_warning_text_clr2 ; Set flag for 2nd row 2350 bsf FLAG_TFT_dive_warning_text_clr2 ; Set flag for 2nd row
2348 return ; Done. 2351 return ; Done.
2349 2352
2350 global check_warn_battery 2353 global check_warn_battery
2351 check_warn_battery: 2354 check_warn_battery:
2352 movff batt_percent,lo 2355 movff batt_percent,lo
2353 movlw battery_show_level+1 2356 movlw battery_show_level+1
2354 cpfslt lo 2357 cpfslt lo
2355 return ; No Display, no warning 2358 return ; No Display, no warning
2356 ; Display Battery, but warn? 2359 ; Display Battery, but warn?
2357 movff batt_percent,lo 2360 movff batt_percent,lo
2358 movlw color_code_battery_low+1 2361 movlw color_code_battery_low+1
2359 cpfsgt lo ; 2362 cpfsgt lo
2360 bsf warning_active ; Set Warning flag 2363 bsf warning_active ; Set Warning flag
2361 2364
2362 movlw .4 2365 movlw .4
2363 cpfseq menupos3 ; battery shown in Custom View 4? 2366 cpfseq menupos3 ; battery shown in Custom View 4?
2364 bra check_warn_battery2 ; No 2367 bra check_warn_battery2 ; No
2365 return ; Yes, do not show twice (in custom view and in warning area) 2368 return ; Yes, do not show twice (in custom view and in warning area)
2366 check_warn_battery2: 2369 check_warn_battery2:
2367 incf warning_counter,F ; increase counter 2370 incf warning_counter,F ; increase counter
2368 goto TFT_update_batt_percent_divemode ; Show percent (And return) 2371 goto TFT_update_batt_percent_divemode ; Show percent (And return)
2369 2372
2370 check_divetimeout: 2373 check_divetimeout:
2371 btfsc divemode2 2374 btfsc divemode2
2372 return ; displayed divetime is not running 2375 return ; displayed divetime is not running
2373 incf warning_counter,F ; increase counter 2376 incf warning_counter,F ; increase counter
2374 goto TFT_divetimeout ; Show timeout counter (and return) 2377 goto TFT_divetimeout ; Show timeout counter (and return)
2375 2378
2376 2379
2377 check_ppO2: 2380 check_ppO2:
2378 btfsc FLAG_ccr_mode ; are we in CCR mode? 2381 btfsc FLAG_ccr_mode ; are we in CCR mode?
2379 bra check_ppO2_loop ; YES 2382 bra check_ppO2_loop ; YES
2380 btfsc FLAG_pscr_mode ; are we in pSCR mode? 2383 btfsc FLAG_pscr_mode ; are we in pSCR mode?
2381 bra check_ppO2_loop ; YES 2384 bra check_ppO2_loop ; YES
2382 bra check_ppO2_oc_1 ; NO - neither CCR nor pSCR 2385 bra check_ppO2_oc_1 ; NO - neither CCR nor pSCR
2383 check_ppO2_loop: 2386 check_ppO2_loop:
2384 btfsc is_bailout ; in bailout? 2387 btfsc is_bailout ; in bailout?
2385 bra check_ppO2_oc_1 ; YES - continue with OC 2388 bra check_ppO2_oc_1 ; YES - continue with OC
2386 movff int_O_pure_ppO2+1,hi ; NO - get upper part of int_O_pure_ppO2 2389 movff int_O_pure_ppO2+1,hi ; NO - get upper part of int_O_pure_ppO2
2387 btfsc hi,int_warning_flag ; ppO2 of the pure diluent to low or high? 2390 btfsc hi,int_warning_flag ; ppO2 of the pure diluent to low or high?
2388 rcall check_ppO2_d ; YES - show warning and return on next line 2391 rcall check_ppo2_display ; YES - show warning and return on next line
2389 bra check_ppO2_oc_2 ; skip pre-warning threshold test on breathed ppO2 2392 btfsc hi,int_attention_flag ; ppO2 of the pure diluent close to setpoint?
2393 rcall check_ppo2_display ; YES - show warning and return on next line
2394 bra check_ppO2_oc_2 ; skip attention threshold test on breathed ppO2
2390 check_ppO2_oc_1: 2395 check_ppO2_oc_1:
2391 movff int_O_breathed_ppO2+1,WREG ; get upper part of int_O_breathed_ppO2 2396 movff int_O_breathed_ppO2+1,WREG ; get upper part of int_O_breathed_ppO2
2392 btfsc WREG,int_prewarning_flag ; breathed ppO2 just above pre-warning threshold? 2397 btfsc WREG,int_attention_flag ; breathed ppO2 just above attention threshold?
2393 bra check_ppo2_display ; YES - show ppO2 2398 bra check_ppo2_display ; YES - show ppO2
2394 check_ppO2_oc_2: 2399 check_ppO2_oc_2:
2395 movff int_O_breathed_ppO2+1,WREG ; get upper part of int_O_breathed_ppO2 (perhaps again) 2400 movff int_O_breathed_ppO2+1,WREG ; get upper part of int_O_breathed_ppO2 (perhaps again)
2396 btfsc WREG,int_low_flag ; breathed ppO2 to low? 2401 btfsc WREG,int_low_flag ; breathed ppO2 to low?
2397 bra check_ppO2_low ; YES - record the warning and show ppO2 2402 bra check_ppO2_low ; YES - record the warning and show ppO2
2398 btfsc WREG,int_high_flag ; breathed ppO2 to high? 2403 btfsc WREG,int_high_flag ; breathed ppO2 to high?
2399 bra check_ppO2_high ; YES - record the warning and show ppO2 2404 bra check_ppO2_high ; YES - record the warning and show ppO2
2400 TSTOSS opt_showppo2 ; show ppO2 anyhow? (0 = no, 1 = show always) 2405 TSTOSS opt_showppo2 ; show ppO2 anyhow? (0 = no, 1 = show always)
2401 return ; NO - no warnings, no show 2406 return ; NO - no warnings, no show
2402 bra check_ppo2_display ; YES - just show ppO2 2407 bra check_ppo2_display ; YES - just show ppO2
2403 check_ppO2_low: 2408 check_ppO2_low:
2404 movlw d'4' ; set type of alarm (ppO2 low) 2409 movlw d'4' ; set type of alarm (ppO2 low)
2405 bra check_ppO2_common ; continue with common part 2410 bra check_ppO2_common ; continue with common part
2406 check_ppO2_high: 2411 check_ppO2_high:
2407 movlw d'5' ; set type of alarm (ppO2 high) 2412 movlw d'5' ; set type of alarm (ppO2 high)
2408 check_ppO2_common: 2413 check_ppO2_common:
2409 movwf AlarmType ; copy alarm type to alarm register 2414 movwf AlarmType ; copy alarm type to alarm register
2410 bsf event_occured ; set event flag 2415 bsf event_occured ; set event flag
2411 bsf warning_active ; set warning flag 2416 bsf warning_active ; set warning flag
2412 btfsc is_bailout ; are we in bailout? 2417 btfsc is_bailout ; are we in bailout?
2413 bra check_ppo2_display ; YES - skip CCR/pSCR checks 2418 bra check_ppo2_display ; YES - skip CCR/pSCR checks
2414 btfsc FLAG_ccr_mode ; are we in CCR mode? 2419 btfsc FLAG_ccr_mode ; are we in CCR mode?
2415 return ; YES - no extra warning required 2420 return ; YES - no extra warning required
2416 btfsc FLAG_pscr_mode ; are we in pSCR mode? 2421 btfsc FLAG_pscr_mode ; are we in pSCR mode?
2417 return ; YES - no extra warning required 2422 return ; YES - no extra warning required
2418 check_ppo2_display: ; display warning if ppO2 is not already shown in custom view 2423 check_ppo2_display: ; display warning if ppO2 is not already shown in custom view
2419 movlw .9 2424 movlw .9
2420 cpfseq menupos3 ; ppO2 shown in Custom View 9? 2425 cpfseq menupos3 ; ppO2 shown in Custom View 9?
2421 bra check_ppO2_a ; No 2426 bra check_ppO2_a ; No
2422 return ; Yes, do not show twice (in custom view and in warning area) 2427 return ; Yes, do not show twice (in custom view and in warning area)
2423 check_ppO2_a: 2428 check_ppO2_a:
2424 movlw .11 2429 movlw .11
2425 cpfseq menupos3 ; ppO2 shown in Custom View 11? 2430 cpfseq menupos3 ; ppO2 shown in Custom View 11?
2426 bra check_ppO2_b ; No 2431 bra check_ppO2_b ; No
2427 return ; Yes, do not show twice (in custom view and in warning area) 2432 return ; Yes, do not show twice (in custom view and in warning area)
2428 check_ppO2_b: 2433 check_ppO2_b:
2429 movlw .12 2434 movlw .12
2430 cpfseq menupos3 ; ppO2 shown in Custom View 12? 2435 cpfseq menupos3 ; ppO2 shown in Custom View 12?
2431 bra check_ppO2_c ; No 2436 bra check_ppO2_c ; No
2432 return ; Yes, do not show twice (in custom view and in warning area) 2437 return ; Yes, do not show twice (in custom view and in warning area)
2433 check_ppO2_c: 2438 check_ppO2_c:
2434 movlw .10 2439 movlw .10
2435 cpfseq menupos3 ; ppO2 shown in Custom View 10? 2440 cpfseq menupos3 ; ppO2 shown in Custom View 10?
2436 bra check_ppO2_d ; No 2441 bra check_ppO2_d ; No
2437 return ; Yes, do not show twice (in custom view and in warning area) 2442 return ; Yes, do not show twice (in custom view and in warning area)
2438 check_ppO2_d: 2443 check_ppO2_d:
2439 incf warning_counter,F ; increase counter 2444 incf warning_counter,F ; increase counter
2440 goto TFT_display_ppo2 ; show breathed gas or diluent ppO2 warning (and return) 2445 goto TFT_display_ppo2 ; show breathed gas or diluent ppO2 warning (and return)
2441 2446
2442 2447
2443 global check_cns_violation 2448 global check_cns_violation
2444 check_cns_violation: 2449 check_cns_violation:
2445 ; Check if CNS should be displayed 2450 ; Check if CNS should be displayed
2446 movff int_O_CNS_fraction+1,WREG ; get high byte 2451 movff int_O_CNS_fraction+1,WREG ; get high byte
2447 btfsc WREG,int_warning_flag ; warning flag set? 2452 btfsc WREG,int_warning_flag ; warning flag set?
2448 bra check_cns_violation2 ; Yes - issue warning 2453 bra check_cns_violation2 ; Yes - issue warning
2449 btfsc WREG,int_prewarning_flag ; pre-warning flag set? 2454 btfsc WREG,int_attention_flag ; attention flag set?
2450 bra display_cns_violation ; YES - just display CNS 2455 bra display_cns_violation ; YES - just display CNS
2451 return ; No - no display, no warning 2456 return ; No - no display, no warning
2452 check_cns_violation2: 2457 check_cns_violation2:
2453 bsf warning_active ; Set Warning flag 2458 bsf warning_active ; Set Warning flag
2454 display_cns_violation: ; Show CNS if not shown in the custom view 2459 display_cns_violation: ; Show CNS if not shown in the custom view
2455 movlw .11 2460 movlw .11
2456 cpfseq menupos3 ; CNS shown in Custom View? 2461 cpfseq menupos3 ; CNS shown in Custom View?
2457 bra display_cns_violation2 ; No 2462 bra display_cns_violation2 ; No
2458 return ; Yes, do not show twice (in custom view and in warning area) 2463 return ; Yes, do not show twice (in custom view and in warning area)
2459 display_cns_violation2: 2464 display_cns_violation2:
2460 movlw .8 2465 movlw .8
2461 cpfseq menupos3 ; CNS shown through Custom View 8 right now? 2466 cpfseq menupos3 ; CNS shown through Custom View 8 right now?
2462 bra display_cns_violation3 ; No 2467 bra display_cns_violation3 ; No
2463 return ; Yes, do not show twice (in custom view and in warning area) 2468 return ; Yes, do not show twice (in custom view and in warning area)
2464 display_cns_violation3: 2469 display_cns_violation3:
2465 incf warning_counter,F ; increase counter 2470 incf warning_counter,F ; increase counter
2466 goto TFT_display_cns ; Show CNS (and return) 2471 goto TFT_display_cns ; Show CNS (and return)
2467 2472
2468 2473
2469 global check_eod_cns_violation ; check end-of-dive CNS values 2474 global check_eod_cns_violation ; check end-of-dive CNS values
2470 check_eod_cns_violation: 2475 check_eod_cns_violation:
2471 movff int_O_CNS_fraction+1,WREG ; get high-byte of current CNS value 2476 movff int_O_CNS_fraction+1,WREG ; get high-byte of current CNS value
2472 btfsc WREG,int_warning_flag ; current CNS value in warning state? 2477 btfsc WREG,int_warning_flag ; current CNS value in warning state?
2473 return ; YES - inhibit eod warning if current CNS is already in warning 2478 return ; YES - inhibit eod warning if current CNS is already in warning
2474 movff int_O_normal_CNS_fraction+1,WREG 2479 movff int_O_normal_CNS_fraction+1,WREG
2475 btfsc WREG,int_invalid_flag ; flag for invalid value set? 2480 btfsc WREG,int_invalid_flag ; flag for invalid value set?
2476 bra check_eod_cns_violation1 ; YES - continue with checking the other CNS value 2481 bra check_eod_cns_violation1 ; YES - continue with checking the other CNS value
2477 btfsc WREG,int_warning_flag ; NO - flag for warning set? 2482 btfsc WREG,int_warning_flag ; NO - flag for warning set?
2478 bra check_eod_cns_violation2 ; YES - issue warning 2483 bra check_eod_cns_violation2 ; YES - issue warning
2479 check_eod_cns_violation1: ; NO - continue with checking the other CNS value 2484 check_eod_cns_violation1: ; NO - continue with checking the other CNS value
2480 movff int_O_alternate_CNS_fraction+1,WREG 2485 movff int_O_alternate_CNS_fraction+1,WREG
2481 btfsc WREG,int_invalid_flag ; flag for invalid value set? 2486 btfsc WREG,int_invalid_flag ; flag for invalid value set?
2482 return ; YES - done with CNS checking 2487 return ; YES - done with CNS checking
2483 btfsc WREG,int_warning_flag ; NO - flag for warning set? 2488 btfsc WREG,int_warning_flag ; NO - flag for warning set?
2484 bra check_eod_cns_violation2 ; Yes - issue warning 2489 bra check_eod_cns_violation2 ; Yes - issue warning
2485 return ; NO - done with CNS checking 2490 return ; NO - done with CNS checking
2486 check_eod_cns_violation2: ; YES - issue warning 2491 check_eod_cns_violation2: ; YES - issue warning
2487 bsf warning_active ; set Warning flag 2492 bsf warning_active ; set Warning flag
2488 movlw .8 ; issue textual warning if CNS values are not shown in the custom view right now 2493 movlw .8 ; issue textual warning if CNS values are not shown in the custom view right now
2489 cpfseq menupos3 ; CNS values shown through Custom View 8 right now? 2494 cpfseq menupos3 ; CNS values shown through Custom View 8 right now?
2490 bra display_eod_cns_violation ; NO - issue textual warning 2495 bra display_eod_cns_violation ; NO - issue textual warning
2491 return ; YES - do not show twice (in custom view and in warning area) 2496 return ; YES - do not show twice (in custom view and in warning area)
2492 display_eod_cns_violation: 2497 display_eod_cns_violation:
2493 incf warning_counter,F ; increase counter 2498 incf warning_counter,F ; increase counter
2494 goto TFT_display_eod_cns ; issue CNS at end-of-dive warning (and return) 2499 goto TFT_display_eod_cns ; issue CNS at end-of-dive warning (and return)
2495 2500
2496 2501
2497 global check_and_store_gf_violation 2502 global check_and_store_gf_violation
2498 check_and_store_gf_violation: 2503 check_and_store_gf_violation:
2499 movff int_O_gradient_factor+1,WREG ; get upper byte of gradient factor 2504 movff int_O_gradient_factor+1,WREG ; get upper byte of gradient factor
2500 btfss WREG,int_warning_flag ; check if the warning flag is set 2505 btfss WREG,int_warning_flag ; check if the warning flag is set
2501 bra check_and_store_gf_violation2 ; NO - continue with checking for pre-warning 2506 bra check_and_store_gf_violation2 ; NO - continue with checking for attention flag
2502 movlw d'2' ; YES - set type of alarm 2507 movlw d'2' ; YES - set type of alarm
2503 movwf AlarmType ; copy to alarm register 2508 movwf AlarmType ; copy to alarm register
2504 bsf event_occured ; set event flag 2509 bsf event_occured ; set event flag
2505 bsf warning_active ; set warning flag 2510 bsf warning_active ; set warning flag
2506 bra check_and_store_gf_violation3 ; show gf warning 2511 bra check_and_store_gf_violation3 ; show gf warning
2507 check_and_store_gf_violation2: 2512 check_and_store_gf_violation2:
2508 btfsc WREG,int_prewarning_flag ; check if the pre-warning flag is set 2513 btfsc WREG,int_attention_flag ; check if the attention flag is set
2509 bra check_and_store_gf_violation3 ; YES - show gf 2514 bra check_and_store_gf_violation3 ; YES - show gf
2510 TSTOSS opt_enable_IBCD ; NO - IBCD warning activated? 2515 TSTOSS opt_enable_IBCD ; NO - IBCD warning activated?
2511 bra check_and_store_gf_violation4 ; NO - continue checking of deco info 2516 bra check_and_store_gf_violation4 ; NO - continue checking of deco info
2512 movff char_O_deco_warnings,WREG ; YES - get the deco warnings vector 2517 movff char_O_deco_warnings,WREG ; YES - get the deco warnings vector
2513 btfss WREG,IBCD_warning ; is the IBCD warning flag set? 2518 btfss WREG,IBCD_warning ; is the IBCD warning flag set?
2514 bra check_and_store_gf_violation4 ; NO - continue checking for deco info 2519 bra check_and_store_gf_violation4 ; NO - continue checking for deco info
2515 check_and_store_gf_violation3: ; YES - show gf 2520 check_and_store_gf_violation3: ; YES - show gf
2516 bsf warning_active ; set Warning flag 2521 bsf warning_active ; set Warning flag
2517 incf warning_counter,F ; increase counter 2522 incf warning_counter,F ; increase counter
2518 goto TFT_warning_gf ; show GF (and return) 2523 goto TFT_warning_gf ; show GF (and return)
2519 check_and_store_gf_violation4: ; check for deco info 2524 check_and_store_gf_violation4: ; check for deco info
2520 btfss divemode ; in divemode? 2525 btfss divemode ; in divemode?
2521 return ; NO - done, return 2526 return ; NO - done, return
2522 movff char_O_deco_warnings,WREG ; YES - get the deco warnings vector 2527 movff char_O_deco_warnings,WREG ; YES - get the deco warnings vector
2523 btfss WREG,deco_flag ; check if the deco flag is set 2528 btfss WREG,deco_flag ; check if the deco flag is set
2524 return ; NO - all done, return 2529 return ; NO - all done, return
2525 incf warning_counter,F ; YES - increase counter 2530 incf warning_counter,F ; YES - increase counter
2526 goto TFT_info_deco ; show deco info 2531 goto TFT_info_deco ; show deco info
2527 2532
2528 2533
2529 warn_outside: 2534 warn_outside:
2530 incf warning_counter,F ; increase counter 2535 incf warning_counter,F ; increase counter
2531 bsf warning_active ; Set Warning flag 2536 bsf warning_active ; Set Warning flag
2532 goto TFT_warning_outside ; show microbubbles warning (and return) 2537 goto TFT_warning_outside ; show outside warning (and return)
2533 2538
2534 2539
2535 global warn_mbubbles 2540 global warn_mbubbles
2536 warn_mbubbles: 2541 warn_mbubbles:
2537 incf warning_counter,F ; increase counter 2542 incf warning_counter,F ; increase counter
2538 bsf warning_active ; Set Warning flag 2543 bsf warning_active ; Set Warning flag
2539 goto TFT_warning_mbubbles ; show microbubbles warning (and return) 2544 goto TFT_warning_mbubbles ; show microbubbles warning (and return)
2540 2545
2541 warn_agf: 2546 warn_agf:
2542 incf warning_counter,F ; increase counter 2547 incf warning_counter,F ; increase counter
2543 goto TFT_warning_agf ; Show aGF warning (and return) 2548 goto TFT_warning_agf ; Show aGF warning (and return)
2544 2549
2545 warn_fallback: 2550 warn_fallback:
2546 incf warning_counter,F ; increase counter 2551 incf warning_counter,F ; increase counter
2547 bsf warning_active ; Set Warning flag 2552 bsf warning_active ; Set Warning flag
2548 goto TFT_warning_fallback ; Show fallback warning (and return) 2553 goto TFT_warning_fallback ; Show fallback warning (and return)
2549 2554
2550 2555
2551 check_gas_needs: 2556 check_gas_needs:
2552 banksel int_O_tank_pres_need 2557 banksel int_O_tank_pres_need
2553 movf int_O_tank_pres_need+1,w ; get HIGH(pres need of 1st tank) 2558 movf int_O_tank_pres_need+1,w ; get HIGH(pres need of 1st tank)
2554 iorwf int_O_tank_pres_need+3,w ; inclusive or with HIGH(pres need of 2nd tank) 2559 iorwf int_O_tank_pres_need+3,w ; inclusive or with HIGH(pres need of 2nd tank)
2555 iorwf int_O_tank_pres_need+5,w ; inclusive or with HIGH(pres need of 3rd tank) 2560 iorwf int_O_tank_pres_need+5,w ; inclusive or with HIGH(pres need of 3rd tank)
2556 iorwf int_O_tank_pres_need+7,w ; inclusive or with HIGH(pres need of 4th tank) 2561 iorwf int_O_tank_pres_need+7,w ; inclusive or with HIGH(pres need of 4th tank)
2557 iorwf int_O_tank_pres_need+9,w ; inclusive or with HIGH(pres need of 5th tank) 2562 iorwf int_O_tank_pres_need+9,w ; inclusive or with HIGH(pres need of 5th tank)
2558 banksel common 2563 banksel common
2559 btfsc WREG,int_invalid_flag ; check if invalid flag is set 2564 btfsc WREG,int_invalid_flag ; check if invalid flag is set
2560 return ; YES - no further checking required 2565 return ; YES - no further checking required
2561 btfsc WREG,int_warning_flag ; NO - check if any gas has a pres_need >= pres_fill 2566 btfsc WREG,int_warning_flag ; NO - check if any gas has a pres_need >= pres_fill
2562 bsf warning_active ; YES - set warning flag 2567 bsf warning_active ; YES - set warning flag
2563 btfsc WREG,int_warning_flag ; NO - check if any gas has a pres_need >= pres_fill 2568 btfsc WREG,int_warning_flag ; NO - check if any gas has a pres_need >= pres_fill
2564 goto TFT_warning_gas_needs_warn ; Yes - show a warning 2569 goto TFT_warning_gas_needs_warn ; Yes - show a warning
2565 btfsc WREG,int_prewarning_flag ; NO - check if any gas has a pres_need >= pres_fill * threshold 2570 btfsc WREG,int_attention_flag ; NO - check if any gas has a pres_need >= pres_fill * threshold
2566 goto TFT_warning_gas_needs_att ; YES - show an attention 2571 goto TFT_warning_gas_needs_att ; YES - show an attention
2567 bcf gas_needs_attention ; NO - clear flag for a new attention 2572 bcf gas_needs_attention ; NO - clear flag for a new attention
2568 bcf gas_needs_warning ; clear flag for a new warning 2573 bcf gas_needs_warning ; clear flag for a new warning
2569 return 2574 return
2570 2575
2571 2576
2572 check_warn_sensors_disagree: 2577 check_warn_sensors_disagree:
2573 incf warning_counter,F ; increase counter 2578 incf warning_counter,F ; increase counter
2574 bsf warning_active ; YES - set Warning flag 2579 bsf warning_active ; YES - set Warning flag
2575 goto TFT_warning_sensor_disagree ; show sensor disagree warning (and return) 2580 goto TFT_warning_sensor_disagree ; show sensor disagree warning (and return)
2576 2581
2577 2582
2578 check_IBCD: 2583 check_IBCD:
2579 TSTOSS opt_enable_IBCD ; IBCD warning activated? 2584 TSTOSS opt_enable_IBCD ; IBCD warning activated?
2580 return ; NO - done 2585 return ; NO - done
2581 movff char_O_deco_warnings,WREG ; YES - get deco warnings vector 2586 movff char_O_deco_warnings,WREG ; YES - get deco warnings vector
2582 btfss WREG,IBCD_warning ; IBCD warning flag set? 2587 btfss WREG,IBCD_warning ; IBCD warning flag set?
2583 return ; NO - return 2588 return ; NO - return
2584 incf warning_counter,F ; YES - increase counter 2589 incf warning_counter,F ; YES - increase counter
2585 goto TFT_warning_IBCD ; write warning to display 2590 goto TFT_warning_IBCD ; write warning to display
2586
2587 2591
2588 2592
2589 global restart_deco_engine 2593 global restart_deco_engine
2590 global restart_deco_engine_wo_ceiling 2594 global restart_deco_engine_wo_ceiling
2591 restart_deco_engine: 2595 restart_deco_engine:
2617 movff WREG,int_O_alternate_CNS_fraction+1 2621 movff WREG,int_O_alternate_CNS_fraction+1
2618 2622
2619 movff int_O_tank_pres_need+1,WREG 2623 movff int_O_tank_pres_need+1,WREG
2620 bsf WREG,int_invalid_flag 2624 bsf WREG,int_invalid_flag
2621 movff WREG,int_O_tank_pres_need+1 2625 movff WREG,int_O_tank_pres_need+1
2622 2626
2623 ; restart deco engine 2627 ; restart deco engine
2624 movff char_O_deco_status,WREG ; get current deco engine configuration 2628 movff char_O_deco_status,WREG ; get current deco engine configuration
2625 bcf WREG,DECO_STATUS_0_FLAG ; set status flags to... 2629 bcf WREG,DECO_STATUS_0_FLAG ; set status flags to...
2626 bcf WREG,DECO_STATUS_1_FLAG ; ... DECO_STATUS_START 2630 bcf WREG,DECO_STATUS_1_FLAG ; ... DECO_STATUS_START
2627 bsf WREG,DECO_PLAN_FLAG ; fake we came from alternative plan to force normal plan to be done next 2631 bsf WREG,DECO_PLAN_FLAG ; fake we came from alternative plan to force normal plan to be done next
2628 movff WREG,char_O_deco_status ; write back new configuration to restart deco computations 2632 movff WREG,char_O_deco_status ; write back new configuration to restart deco computations
2629 2633
2630 return 2634 return
2631 2635
2632 2636 ;=============================================================================
2633 END 2637 ; simulator mode
2638 ;
2639
2640 global do_demo_divemode
2641 do_demo_divemode:
2642 call option_save_all ; Save all settings into EEPROM before starting simulation
2643 call deco_push_tissues_to_vault ; C-code: back-up status of the real tissues
2644 banksel common ; Bank1
2645
2646 ; +++ COMMENTED OUT FOR TESTING PURPOSE ONLY !!! +++
2647 ; +++ DO NOT COMMENT OUT IN OPERATIONAL USE !!! +++
2648 ;
2649 bsf restore_deco_data ; Restore tissue and CNS after simulator use
2650
2651 bcf pressure_refresh
2652 btfss pressure_refresh ; Wait for sensor
2653 bra $-2
2654
2655 bsf simulatormode_active ; Set Flag
2656 ; Compute dive ambient conditions
2657 banksel char_I_bottom_depth
2658 movf char_I_bottom_depth,W
2659 mullw .100
2660 movff PRODL,rel_pressure+0
2661 movff PRODH,rel_pressure+1
2662 movlw LOW (.1000)
2663 addwf PRODL,W
2664 movff WREG,sim_pressure+0
2665 movlw HIGH (.1000)
2666 addwfc PRODH,W
2667 movff WREG,sim_pressure+1
2668 banksel common ; Bank1
2669
2670 bsf divemode
2671 goto diveloop ; Switch into Divemode!
2672
2673 END