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