annotate src/divemode.asm @ 14:440e537e19d6

Show "MOD:" instead of "EAD:" in gas setup
author heinrichsweikamp
date Tue, 11 Jun 2013 09:42:59 +0200
parents 11d4fc797f74
children e402813343b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
heinrichsweikamp
parents:
diff changeset
3 ; File divemode.asm
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; Divemode
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
heinrichsweikamp
parents:
diff changeset
10 ; 2011-08-15 : [mH] moving from OSTC code
heinrichsweikamp
parents:
diff changeset
11
heinrichsweikamp
parents:
diff changeset
12 #include "ostc3.inc" ; Mandatory header
heinrichsweikamp
parents:
diff changeset
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c
heinrichsweikamp
parents:
diff changeset
14 #include "tft_outputs.inc"
heinrichsweikamp
parents:
diff changeset
15 #include "strings.inc"
heinrichsweikamp
parents:
diff changeset
16 #include "tft.inc"
heinrichsweikamp
parents:
diff changeset
17 #include "eeprom_rs232.inc"
heinrichsweikamp
parents:
diff changeset
18 #include "isr.inc"
heinrichsweikamp
parents:
diff changeset
19 #include "math.inc"
heinrichsweikamp
parents:
diff changeset
20 #include "wait.inc"
heinrichsweikamp
parents:
diff changeset
21 #include "customview.inc"
heinrichsweikamp
parents:
diff changeset
22 #include "start.inc"
heinrichsweikamp
parents:
diff changeset
23 #include "adc_lightsensor.inc"
heinrichsweikamp
parents:
diff changeset
24 #include "ghostwriter.inc"
heinrichsweikamp
parents:
diff changeset
25 #include "i2c.inc"
heinrichsweikamp
parents:
diff changeset
26
heinrichsweikamp
parents:
diff changeset
27 gui CODE
heinrichsweikamp
parents:
diff changeset
28
heinrichsweikamp
parents:
diff changeset
29 global diveloop
heinrichsweikamp
parents:
diff changeset
30 diveloop:
heinrichsweikamp
parents:
diff changeset
31 banksel common
heinrichsweikamp
parents:
diff changeset
32 call speed_normal
heinrichsweikamp
parents:
diff changeset
33 call diveloop_boot ; Boot tasks for all modes
heinrichsweikamp
parents:
diff changeset
34
heinrichsweikamp
parents:
diff changeset
35 ; Startup Tasks for all modes
heinrichsweikamp
parents:
diff changeset
36 call TFT_ClearScreen ; clean up TFT
heinrichsweikamp
parents:
diff changeset
37 call TFT_divemode_mask ; Display mask
heinrichsweikamp
parents:
diff changeset
38 call TFT_temp_divemode ; Displays temperature
heinrichsweikamp
parents:
diff changeset
39
heinrichsweikamp
parents:
diff changeset
40 btfsc FLAG_apnoe_mode
heinrichsweikamp
parents:
diff changeset
41 bsf realdive ; Set Realdive flag in Apnoe mode
heinrichsweikamp
parents:
diff changeset
42
heinrichsweikamp
parents:
diff changeset
43 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode
heinrichsweikamp
parents:
diff changeset
44 bra diveloop_loop
heinrichsweikamp
parents:
diff changeset
45 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode
heinrichsweikamp
parents:
diff changeset
46 bra diveloop_loop
heinrichsweikamp
parents:
diff changeset
47
heinrichsweikamp
parents:
diff changeset
48 call TFT_active_gas_divemode ; Display gas/Setpoint
heinrichsweikamp
parents:
diff changeset
49 call TFT_display_ndl_mask ; display "NDL"
heinrichsweikamp
parents:
diff changeset
50
heinrichsweikamp
parents:
diff changeset
51 ; +@5 init
heinrichsweikamp
parents:
diff changeset
52 setf WREG ; WAIT marker: display "---"
heinrichsweikamp
parents:
diff changeset
53 movff WREG,int_O_extra_ascenttime+0
heinrichsweikamp
parents:
diff changeset
54 movff WREG,int_O_extra_ascenttime+1
heinrichsweikamp
parents:
diff changeset
55 movlw 1
heinrichsweikamp
parents:
diff changeset
56 movwf apnoe_mins ; Start compute after next cycle.
heinrichsweikamp
parents:
diff changeset
57
heinrichsweikamp
parents:
diff changeset
58 ;--------------------------------------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
59 diveloop_loop: ; The diveloop starts here
heinrichsweikamp
parents:
diff changeset
60 btfss onesecupdate
heinrichsweikamp
parents:
diff changeset
61 bra diveloop_loop3
heinrichsweikamp
parents:
diff changeset
62
heinrichsweikamp
parents:
diff changeset
63 ; tasks any new second...
heinrichsweikamp
parents:
diff changeset
64 btfsc FLAG_apnoe_mode ; Only in apnoe mode
heinrichsweikamp
parents:
diff changeset
65 bra diveloop_loop1b ; One Second Tasks in Apnoe mode
heinrichsweikamp
parents:
diff changeset
66
heinrichsweikamp
parents:
diff changeset
67 call TFT_divemins ; Display (new) divetime!
heinrichsweikamp
parents:
diff changeset
68 call customview_second ; Do every-second tasks for the custom view area
heinrichsweikamp
parents:
diff changeset
69
heinrichsweikamp
parents:
diff changeset
70 ; Tasks only for deco modes
heinrichsweikamp
parents:
diff changeset
71 call calc_deko_divemode ; calculate decompression and display result (any two seconds)
heinrichsweikamp
parents:
diff changeset
72 bra diveloop_loop1x ; Common Tasks
heinrichsweikamp
parents:
diff changeset
73
heinrichsweikamp
parents:
diff changeset
74 diveloop_loop1b:
heinrichsweikamp
parents:
diff changeset
75 ; Tasks only for Apnoe mode
heinrichsweikamp
parents:
diff changeset
76 call divemode_apnoe_tasks ; 1 sec. Apnoe tasks
heinrichsweikamp
parents:
diff changeset
77 bra diveloop_loop1x ; Common Tasks
heinrichsweikamp
parents:
diff changeset
78
heinrichsweikamp
parents:
diff changeset
79 diveloop_loop1x:
heinrichsweikamp
parents:
diff changeset
80 ; Common 1sec. tasks for all modes
heinrichsweikamp
parents:
diff changeset
81 call timeout_divemode ; dive finished? This routine sets the required flags
heinrichsweikamp
parents:
diff changeset
82 call set_dive_modes ; tests if depth>threshold
heinrichsweikamp
parents:
diff changeset
83 call set_min_temp ; store min. temp if required
heinrichsweikamp
parents:
diff changeset
84
heinrichsweikamp
parents:
diff changeset
85 btfsc store_sample ; store new sample?
heinrichsweikamp
parents:
diff changeset
86 call store_dive_data ; Store profile data
heinrichsweikamp
parents:
diff changeset
87
heinrichsweikamp
parents:
diff changeset
88 btfss divemode ; Dive finished?
heinrichsweikamp
parents:
diff changeset
89 goto ghostwriter_end_dive ; Dive finished!
heinrichsweikamp
parents:
diff changeset
90
heinrichsweikamp
parents:
diff changeset
91 btfsc divemode_gaschange ; Gas switch flag set?
heinrichsweikamp
parents:
diff changeset
92 rcall gas_switched_common ; Yes
heinrichsweikamp
parents:
diff changeset
93
heinrichsweikamp
parents:
diff changeset
94 btfsc toggle_gf ; =1: Toggle GF/aGF
heinrichsweikamp
parents:
diff changeset
95 rcall divemodemode_togglegf ; Toggle aGF/GF
heinrichsweikamp
parents:
diff changeset
96
heinrichsweikamp
parents:
diff changeset
97 ; btfsc FLAG_ccr_mode ; In CCR mode
heinrichsweikamp
parents:
diff changeset
98 ; call TFT_active_gas_divemode ; Update Setpoint every second
heinrichsweikamp
parents:
diff changeset
99
heinrichsweikamp
parents:
diff changeset
100 bcf onesecupdate ; one seconds update done
heinrichsweikamp
parents:
diff changeset
101
heinrichsweikamp
parents:
diff changeset
102 diveloop_loop3:
heinrichsweikamp
parents:
diff changeset
103 rcall test_switches_divemode ; Check switches in divemode
heinrichsweikamp
parents:
diff changeset
104
heinrichsweikamp
parents:
diff changeset
105 global diveloop_loop4
heinrichsweikamp
parents:
diff changeset
106 diveloop_loop4: ; Menu-Exit returns here...
heinrichsweikamp
parents:
diff changeset
107 btfsc toggle_customview ; Next view?
heinrichsweikamp
parents:
diff changeset
108 call customview_toggle ; Yes, show next customview (and delete this flag)
heinrichsweikamp
parents:
diff changeset
109
heinrichsweikamp
parents:
diff changeset
110 btfsc pressure_refresh ; new pressure available?
heinrichsweikamp
parents:
diff changeset
111 rcall update_temp_and_or_depth ; Yes, display new depth and clear "pressure_refresh" flag
heinrichsweikamp
parents:
diff changeset
112
heinrichsweikamp
parents:
diff changeset
113 btfsc oneminupdate ; one minute tasks
heinrichsweikamp
parents:
diff changeset
114 rcall update_divemode60 ; Update clock, etc.
heinrichsweikamp
parents:
diff changeset
115
heinrichsweikamp
parents:
diff changeset
116 btfss quarter_second_update
heinrichsweikamp
parents:
diff changeset
117 bra diveloop_loop4a
heinrichsweikamp
parents:
diff changeset
118 bcf quarter_second_update
heinrichsweikamp
parents:
diff changeset
119 movlw .6
heinrichsweikamp
parents:
diff changeset
120 cpfseq menupos3 ; in compass view?
heinrichsweikamp
parents:
diff changeset
121 bra diveloop_loop4a ; No
heinrichsweikamp
parents:
diff changeset
122 call TFT_dive_compass_heading ; Yes, update compass heading value
heinrichsweikamp
parents:
diff changeset
123 diveloop_loop4a:
heinrichsweikamp
parents:
diff changeset
124 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
heinrichsweikamp
parents:
diff changeset
125 bra diveloop_loop5
heinrichsweikamp
parents:
diff changeset
126 bra diveloop_loop6
heinrichsweikamp
parents:
diff changeset
127 diveloop_loop5:
heinrichsweikamp
parents:
diff changeset
128 btfss vusb_in ; USB (still) plugged in?
heinrichsweikamp
parents:
diff changeset
129 bcf enable_screen_dumps ; No, clear flag
heinrichsweikamp
parents:
diff changeset
130 call rs232_get_byte
heinrichsweikamp
parents:
diff changeset
131 btfsc rs232_recieve_overflow
heinrichsweikamp
parents:
diff changeset
132 bra diveloop_loop6
heinrichsweikamp
parents:
diff changeset
133 movlw "l"
heinrichsweikamp
parents:
diff changeset
134 cpfseq RCREG1
heinrichsweikamp
parents:
diff changeset
135 bra diveloop_loop6
heinrichsweikamp
parents:
diff changeset
136 call TFT_dump_screen ; Dump the screen contents
heinrichsweikamp
parents:
diff changeset
137 diveloop_loop6:
heinrichsweikamp
parents:
diff changeset
138
heinrichsweikamp
parents:
diff changeset
139 bra diveloop_loop ; Loop the divemode
heinrichsweikamp
parents:
diff changeset
140 ;--------------------------------------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
141
heinrichsweikamp
parents:
diff changeset
142
heinrichsweikamp
parents:
diff changeset
143
heinrichsweikamp
parents:
diff changeset
144
heinrichsweikamp
parents:
diff changeset
145
heinrichsweikamp
parents:
diff changeset
146
heinrichsweikamp
parents:
diff changeset
147 divemode_apnoe_tasks: ; 1 sec. Apnoe tasks
heinrichsweikamp
parents:
diff changeset
148 call TFT_display_apnoe_descent ; Show descent timer
heinrichsweikamp
parents:
diff changeset
149 call TFT_max_pressure ; use normal max. depth
heinrichsweikamp
parents:
diff changeset
150
heinrichsweikamp
parents:
diff changeset
151 btfsc divemode2 ; Time running?
heinrichsweikamp
parents:
diff changeset
152 bra divemode_apnoe_tasks2 ; New descent, reset data if flag is set
heinrichsweikamp
parents:
diff changeset
153
heinrichsweikamp
parents:
diff changeset
154 rcall apnoe_calc_maxdepth
heinrichsweikamp
parents:
diff changeset
155 call TFT_display_apnoe_surface
heinrichsweikamp
parents:
diff changeset
156 call TFT_display_apnoe_last_max ; Show last max. depth
heinrichsweikamp
parents:
diff changeset
157 incf apnoe_surface_secs,F
heinrichsweikamp
parents:
diff changeset
158 movlw d'60'
heinrichsweikamp
parents:
diff changeset
159 cpfseq apnoe_surface_secs
heinrichsweikamp
parents:
diff changeset
160 bra divemode_apnoe_tasks1
heinrichsweikamp
parents:
diff changeset
161 clrf apnoe_surface_secs
heinrichsweikamp
parents:
diff changeset
162 incf apnoe_surface_mins,F
heinrichsweikamp
parents:
diff changeset
163
heinrichsweikamp
parents:
diff changeset
164 divemode_apnoe_tasks1:
heinrichsweikamp
parents:
diff changeset
165 bcf FLAG_active_descent ; Clear flag
heinrichsweikamp
parents:
diff changeset
166 btfsc divemode2 ; Time running?
heinrichsweikamp
parents:
diff changeset
167 return ; Yes, return
heinrichsweikamp
parents:
diff changeset
168 bsf FLAG_active_descent ; Set Flag
heinrichsweikamp
parents:
diff changeset
169 return
heinrichsweikamp
parents:
diff changeset
170
heinrichsweikamp
parents:
diff changeset
171 divemode_apnoe_tasks2:
heinrichsweikamp
parents:
diff changeset
172 btfss FLAG_active_descent ; Are we descending?
heinrichsweikamp
parents:
diff changeset
173 return ; No, We are at the surface
heinrichsweikamp
parents:
diff changeset
174 rcall apnoe_calc_maxdepth ; Yes!
heinrichsweikamp
parents:
diff changeset
175 call TFT_apnoe_clear_surface ; Clear Surface timer
heinrichsweikamp
parents:
diff changeset
176 clrf apnoe_timeout_counter ; Delete timeout
heinrichsweikamp
parents:
diff changeset
177 clrf apnoe_surface_secs
heinrichsweikamp
parents:
diff changeset
178 clrf apnoe_surface_mins
heinrichsweikamp
parents:
diff changeset
179 clrf apnoe_secs
heinrichsweikamp
parents:
diff changeset
180 clrf apnoe_mins ; Reset Descent time
heinrichsweikamp
parents:
diff changeset
181 movlw .0
heinrichsweikamp
parents:
diff changeset
182 movff WREG,max_pressure+0
heinrichsweikamp
parents:
diff changeset
183 movff WREG,max_pressure+1 ; Reset Max. Depth
heinrichsweikamp
parents:
diff changeset
184 bcf FLAG_active_descent ; Clear flag
heinrichsweikamp
parents:
diff changeset
185 return
heinrichsweikamp
parents:
diff changeset
186
heinrichsweikamp
parents:
diff changeset
187 global apnoe_calc_maxdepth
heinrichsweikamp
parents:
diff changeset
188 apnoe_calc_maxdepth:
heinrichsweikamp
parents:
diff changeset
189 movff apnoe_max_pressure+0,sub_a+0
heinrichsweikamp
parents:
diff changeset
190 movff apnoe_max_pressure+1,sub_a+1
heinrichsweikamp
parents:
diff changeset
191 movff max_pressure+0,sub_b+0
heinrichsweikamp
parents:
diff changeset
192 movff max_pressure+1,sub_b+1
heinrichsweikamp
parents:
diff changeset
193 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
194 ; apnoe_max_pressure<max_pressure -> neg_flag=1
heinrichsweikamp
parents:
diff changeset
195 ; max_pressure<=apnoe_max_pressure -> neg_flag=0
heinrichsweikamp
parents:
diff changeset
196 btfss neg_flag
heinrichsweikamp
parents:
diff changeset
197 return
heinrichsweikamp
parents:
diff changeset
198 ;apnoe_max_pressure<max_pressure
heinrichsweikamp
parents:
diff changeset
199 movff max_pressure+0,apnoe_max_pressure+0
heinrichsweikamp
parents:
diff changeset
200 movff max_pressure+1,apnoe_max_pressure+1
heinrichsweikamp
parents:
diff changeset
201 return
heinrichsweikamp
parents:
diff changeset
202
heinrichsweikamp
parents:
diff changeset
203
heinrichsweikamp
parents:
diff changeset
204 calc_deko_divemode:
heinrichsweikamp
parents:
diff changeset
205 btfsc twosecupdate ; two seconds after the last call
heinrichsweikamp
parents:
diff changeset
206 bra calc_deko_divemode2 ; Yes, calculate and display deco data ("first second")
heinrichsweikamp
parents:
diff changeset
207
heinrichsweikamp
parents:
diff changeset
208 bsf twosecupdate ; No, but next second!
heinrichsweikamp
parents:
diff changeset
209 ; Routines used in the "other second"
heinrichsweikamp
parents:
diff changeset
210 call calc_average_depth ; calculate average depth
heinrichsweikamp
parents:
diff changeset
211 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds)
heinrichsweikamp
parents:
diff changeset
212 call divemode_check_for_warnings ; Check for any warnings
heinrichsweikamp
parents:
diff changeset
213 call TFT_debug_output
heinrichsweikamp
parents:
diff changeset
214
heinrichsweikamp
parents:
diff changeset
215 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode
heinrichsweikamp
parents:
diff changeset
216 return
heinrichsweikamp
parents:
diff changeset
217 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode
heinrichsweikamp
parents:
diff changeset
218 return
heinrichsweikamp
parents:
diff changeset
219
heinrichsweikamp
parents:
diff changeset
220 ; Calculate CNS
heinrichsweikamp
parents:
diff changeset
221 rcall set_actual_ppo2 ; Set char_I_actual_ppO2
heinrichsweikamp
parents:
diff changeset
222 clrf WREG
heinrichsweikamp
parents:
diff changeset
223 movff WREG,char_I_step_is_1min ; Make sure to be in 2sec mode.
heinrichsweikamp
parents:
diff changeset
224 call deco_calc_CNS_fraction ; calculate CNS
heinrichsweikamp
parents:
diff changeset
225 movlb b'00000001' ; rambank 1 selected
heinrichsweikamp
parents:
diff changeset
226
heinrichsweikamp
parents:
diff changeset
227 ; Check for a gas change
heinrichsweikamp
parents:
diff changeset
228 rcall check_gas_change ; Checks if a better gas should be selected (by user)
heinrichsweikamp
parents:
diff changeset
229
heinrichsweikamp
parents:
diff changeset
230 return
heinrichsweikamp
parents:
diff changeset
231
heinrichsweikamp
parents:
diff changeset
232 global set_actual_ppo2
heinrichsweikamp
parents:
diff changeset
233 set_actual_ppo2: ; calculate ppO2 in 0.01bar (e.g. 150 = 1.50 bar ppO2)
heinrichsweikamp
parents:
diff changeset
234 SAFE_2BYTE_COPY amb_pressure, xA ; P_amb in millibar (1000 = 1.00 bar).
heinrichsweikamp
parents:
diff changeset
235 movlw d'10'
heinrichsweikamp
parents:
diff changeset
236 movwf xB+0
heinrichsweikamp
parents:
diff changeset
237 clrf xB+1
heinrichsweikamp
parents:
diff changeset
238 call div16x16 ; xC=p_amb/10 (100 = 1.00 bar).
heinrichsweikamp
parents:
diff changeset
239 movff xC+0,xA+0
heinrichsweikamp
parents:
diff changeset
240 movff xC+1,xA+1
heinrichsweikamp
parents:
diff changeset
241 movff char_I_O2_ratio,xB+0
heinrichsweikamp
parents:
diff changeset
242 clrf xB+1
heinrichsweikamp
parents:
diff changeset
243 call mult16x16 ; char_I_O2_ratio * (p_amb/10)
heinrichsweikamp
parents:
diff changeset
244 movff xC+0,xA+0
heinrichsweikamp
parents:
diff changeset
245 movff xC+1,xA+1
heinrichsweikamp
parents:
diff changeset
246 movlw d'100'
heinrichsweikamp
parents:
diff changeset
247 movwf xB+0
heinrichsweikamp
parents:
diff changeset
248 clrf xB+1
heinrichsweikamp
parents:
diff changeset
249 call div16x16 ; xC=(char_I_O2_ratio * p_amb/10)/100
heinrichsweikamp
parents:
diff changeset
250
heinrichsweikamp
parents:
diff changeset
251 ; Copy ppO2 for CNS calculation
heinrichsweikamp
parents:
diff changeset
252 tstfsz xC+1 ; Is ppO2 > 2.55bar ?
heinrichsweikamp
parents:
diff changeset
253 setf xC+0 ; yes: bound to 2.55... better than wrap around.
heinrichsweikamp
parents:
diff changeset
254
heinrichsweikamp
parents:
diff changeset
255 movff xC+0, char_I_actual_ppO2 ; copy last ppO2 to buffer register
heinrichsweikamp
parents:
diff changeset
256 btfsc is_bailout ; In Bailout?
heinrichsweikamp
parents:
diff changeset
257 return ; Yes, done.
heinrichsweikamp
parents:
diff changeset
258 ; No Bailout, check for ccr mode
heinrichsweikamp
parents:
diff changeset
259 btfsc FLAG_ccr_mode ; If FLAG_ccr_mode=1...
heinrichsweikamp
parents:
diff changeset
260 movff char_I_const_ppO2, char_I_actual_ppO2 ; ...copy last ppO2 to buffer register
heinrichsweikamp
parents:
diff changeset
261 return
heinrichsweikamp
parents:
diff changeset
262
heinrichsweikamp
parents:
diff changeset
263
heinrichsweikamp
parents:
diff changeset
264 calc_deko_divemode2:
heinrichsweikamp
parents:
diff changeset
265 bcf twosecupdate
heinrichsweikamp
parents:
diff changeset
266
heinrichsweikamp
parents:
diff changeset
267 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode
heinrichsweikamp
parents:
diff changeset
268 return
heinrichsweikamp
parents:
diff changeset
269 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode
heinrichsweikamp
parents:
diff changeset
270 return
heinrichsweikamp
parents:
diff changeset
271
heinrichsweikamp
parents:
diff changeset
272 extern deco_setup_dive
heinrichsweikamp
parents:
diff changeset
273 call deco_setup_dive ; Pass all parameters to the C code
heinrichsweikamp
parents:
diff changeset
274
heinrichsweikamp
parents:
diff changeset
275 TSTOSS opt_ccr_mode ; =0: Fixed SP, =1: Sensor
heinrichsweikamp
parents:
diff changeset
276 bra calc_deko_divemode2a
heinrichsweikamp
parents:
diff changeset
277 rcall divemode_setup_sensor_values ; Setup sensor values
heinrichsweikamp
parents:
diff changeset
278
heinrichsweikamp
parents:
diff changeset
279 calc_deko_divemode2a:
heinrichsweikamp
parents:
diff changeset
280 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; C-code needs the ambient pressure
heinrichsweikamp
parents:
diff changeset
281 clrf WREG
heinrichsweikamp
parents:
diff changeset
282 movff WREG,char_I_step_is_1min ; Force 2 second deco mode
heinrichsweikamp
parents:
diff changeset
283
heinrichsweikamp
parents:
diff changeset
284 clrf TMR5L
heinrichsweikamp
parents:
diff changeset
285 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H
heinrichsweikamp
parents:
diff changeset
286 call deco_calc_hauptroutine ; calc_tissue
heinrichsweikamp
parents:
diff changeset
287 movlb .1
heinrichsweikamp
parents:
diff changeset
288
heinrichsweikamp
parents:
diff changeset
289 movff char_O_deco_status,WREG ; Is a compute cycle finished ?
heinrichsweikamp
parents:
diff changeset
290 iorwf WREG,F
heinrichsweikamp
parents:
diff changeset
291 btfss STATUS,Z
heinrichsweikamp
parents:
diff changeset
292 return ; Return is status <> 0
heinrichsweikamp
parents:
diff changeset
293
heinrichsweikamp
parents:
diff changeset
294 ; Check if deco stops are necessary ?
heinrichsweikamp
parents:
diff changeset
295 movff char_O_first_deco_depth,wait_temp ; copy ceiling to temp register
heinrichsweikamp
parents:
diff changeset
296 tstfsz wait_temp ; Ceiling<0m?
heinrichsweikamp
parents:
diff changeset
297 bra calc_deko_divemode3 ; Yes!
heinrichsweikamp
parents:
diff changeset
298
heinrichsweikamp
parents:
diff changeset
299 btfsc decostop_active ; Already in nodeco mode ?
heinrichsweikamp
parents:
diff changeset
300 call TFT_display_ndl_mask ; No, Clear deco data, display nostop time
heinrichsweikamp
parents:
diff changeset
301 bcf decostop_active ; clear flag (again)
heinrichsweikamp
parents:
diff changeset
302
heinrichsweikamp
parents:
diff changeset
303 ; Copy for profile recording
heinrichsweikamp
parents:
diff changeset
304 clrf decodata+0
heinrichsweikamp
parents:
diff changeset
305 movff char_O_nullzeit,decodata+1 ; NDL
heinrichsweikamp
parents:
diff changeset
306
heinrichsweikamp
parents:
diff changeset
307 call TFT_display_ndl ; display no deco limit
heinrichsweikamp
parents:
diff changeset
308 return
heinrichsweikamp
parents:
diff changeset
309
heinrichsweikamp
parents:
diff changeset
310 calc_deko_divemode3:
heinrichsweikamp
parents:
diff changeset
311 btfss decostop_active ; Already in deco mode ?
heinrichsweikamp
parents:
diff changeset
312 call TFT_display_deko_mask ; No, clear nostop time, display decodata
heinrichsweikamp
parents:
diff changeset
313 bsf decostop_active ; Set flag (again)
heinrichsweikamp
parents:
diff changeset
314
heinrichsweikamp
parents:
diff changeset
315 ; Copy for profile recording
heinrichsweikamp
parents:
diff changeset
316 movff char_O_first_deco_depth,decodata+0 ; ceiling
heinrichsweikamp
parents:
diff changeset
317 movff char_O_first_deco_time,decodata+1 ; length of first stop in minues
heinrichsweikamp
parents:
diff changeset
318 call TFT_display_deko ; display decodata
heinrichsweikamp
parents:
diff changeset
319 call TFT_show_TTS_divemode ; display TTS
heinrichsweikamp
parents:
diff changeset
320
heinrichsweikamp
parents:
diff changeset
321 movff char_I_extra_time,WREG
heinrichsweikamp
parents:
diff changeset
322 tstfsz WREG ; extra time = 0?
heinrichsweikamp
parents:
diff changeset
323 bra calc_deko_divemode4 ; No, compute it
heinrichsweikamp
parents:
diff changeset
324 return
heinrichsweikamp
parents:
diff changeset
325
heinrichsweikamp
parents:
diff changeset
326 calc_deko_divemode4:
heinrichsweikamp
parents:
diff changeset
327 ; Check if extra cycles are needed to compute @5 variant:
heinrichsweikamp
parents:
diff changeset
328 decfsz apnoe_mins,F ; Reached count-down ?
heinrichsweikamp
parents:
diff changeset
329 return ; No: don't compute yet.
heinrichsweikamp
parents:
diff changeset
330
heinrichsweikamp
parents:
diff changeset
331 movlw .6
heinrichsweikamp
parents:
diff changeset
332 movff WREG,char_O_deco_status ; Stole next cycles for @5 variant.
heinrichsweikamp
parents:
diff changeset
333
heinrichsweikamp
parents:
diff changeset
334 movlw .2 ; Restart countdown.
heinrichsweikamp
parents:
diff changeset
335 movwf apnoe_mins
heinrichsweikamp
parents:
diff changeset
336 return ; done.
heinrichsweikamp
parents:
diff changeset
337
heinrichsweikamp
parents:
diff changeset
338 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
339
heinrichsweikamp
parents:
diff changeset
340 divemodemode_togglegf: ; Toggle aGF/GF
heinrichsweikamp
parents:
diff changeset
341 bcf toggle_gf ; clear flag
heinrichsweikamp
parents:
diff changeset
342 btg use_agf ; Toggle GF
heinrichsweikamp
parents:
diff changeset
343 call TFT_gf_mask ; Setup Mask
heinrichsweikamp
parents:
diff changeset
344 clrf WREG
heinrichsweikamp
parents:
diff changeset
345 movff WREG,char_O_deco_status ; Restart decoplan computation
heinrichsweikamp
parents:
diff changeset
346 return
heinrichsweikamp
parents:
diff changeset
347
heinrichsweikamp
parents:
diff changeset
348 divemode_setup_sensor_values:
heinrichsweikamp
parents:
diff changeset
349 ; sum up sensor values (in xA:2) and active sensors in (xB:2)
heinrichsweikamp
parents:
diff changeset
350 clrf xB+0
heinrichsweikamp
parents:
diff changeset
351 clrf xB+1
heinrichsweikamp
parents:
diff changeset
352 clrf xA+0
heinrichsweikamp
parents:
diff changeset
353 clrf xA+1
heinrichsweikamp
parents:
diff changeset
354 btfss hud_status_byte,3 ; Sensor1 active?
heinrichsweikamp
parents:
diff changeset
355 bra divemode_setup_sensor_values2 ; No
heinrichsweikamp
parents:
diff changeset
356 movf o2_ppo2_sensor1,W
heinrichsweikamp
parents:
diff changeset
357 addwf xA+0
heinrichsweikamp
parents:
diff changeset
358 movlw .0
heinrichsweikamp
parents:
diff changeset
359 addwfc xA+1 ; Add into xA:2
heinrichsweikamp
parents:
diff changeset
360 incf xB+0,F ; Add a sensor
heinrichsweikamp
parents:
diff changeset
361 divemode_setup_sensor_values2:
heinrichsweikamp
parents:
diff changeset
362 btfss hud_status_byte,4 ; Sensor2 active?
heinrichsweikamp
parents:
diff changeset
363 bra divemode_setup_sensor_values3 ; No
heinrichsweikamp
parents:
diff changeset
364 movf o2_ppo2_sensor2,W
heinrichsweikamp
parents:
diff changeset
365 addwf xA+0
heinrichsweikamp
parents:
diff changeset
366 movlw .0
heinrichsweikamp
parents:
diff changeset
367 addwfc xA+1 ; Add into xA:2
heinrichsweikamp
parents:
diff changeset
368 incf xB+0,F ; Add a sensor
heinrichsweikamp
parents:
diff changeset
369 divemode_setup_sensor_values3:
heinrichsweikamp
parents:
diff changeset
370 btfss hud_status_byte,5 ; Sensor3 active?
heinrichsweikamp
parents:
diff changeset
371 bra divemode_setup_sensor_values4 ; No
heinrichsweikamp
parents:
diff changeset
372 movf o2_ppo2_sensor3,W
heinrichsweikamp
parents:
diff changeset
373 addwf xA+0
heinrichsweikamp
parents:
diff changeset
374 movlw .0
heinrichsweikamp
parents:
diff changeset
375 addwfc xA+1 ; Add into xA:2
heinrichsweikamp
parents:
diff changeset
376 incf xB+0,F ; Add a sensor
heinrichsweikamp
parents:
diff changeset
377 divemode_setup_sensor_values4:
heinrichsweikamp
parents:
diff changeset
378 call div16x16 ; xA/xB=xC with xA+0 as remainder
heinrichsweikamp
parents:
diff changeset
379 movff xC+0,sensor_setpoint ; Copy result
heinrichsweikamp
parents:
diff changeset
380 movff sensor_setpoint,char_I_const_ppO2 ; use sensor ppO2
heinrichsweikamp
parents:
diff changeset
381 return
heinrichsweikamp
parents:
diff changeset
382
heinrichsweikamp
parents:
diff changeset
383 calc_velocity: ; called every two seconds
heinrichsweikamp
parents:
diff changeset
384 btfss divemode
heinrichsweikamp
parents:
diff changeset
385 bra do_not_display_velocity ; display velocity only in divemode (Not at the surface after dive)
heinrichsweikamp
parents:
diff changeset
386
heinrichsweikamp
parents:
diff changeset
387 calc_velocity2:
heinrichsweikamp
parents:
diff changeset
388 SAFE_2BYTE_COPY amb_pressure, sub_a
heinrichsweikamp
parents:
diff changeset
389 movff last_pressure_velocity+0,sub_b+0
heinrichsweikamp
parents:
diff changeset
390 movff last_pressure_velocity+1,sub_b+1
heinrichsweikamp
parents:
diff changeset
391 movff sub_a+0,last_pressure_velocity+0 ; store old value for velocity
heinrichsweikamp
parents:
diff changeset
392 movff sub_a+1,last_pressure_velocity+1
heinrichsweikamp
parents:
diff changeset
393
heinrichsweikamp
parents:
diff changeset
394 call subU16 ; sub_c = amb_pressure - last_pressure
heinrichsweikamp
parents:
diff changeset
395
heinrichsweikamp
parents:
diff changeset
396 movff sub_c+0,xA+0
heinrichsweikamp
parents:
diff changeset
397 movff sub_c+1,xA+1
heinrichsweikamp
parents:
diff changeset
398 movlw d'39' ; 77 when called every second....
heinrichsweikamp
parents:
diff changeset
399 movwf xB+0
heinrichsweikamp
parents:
diff changeset
400 clrf xB+1
heinrichsweikamp
parents:
diff changeset
401 call mult16x16 ; differential pressure in mbar*77...
heinrichsweikamp
parents:
diff changeset
402 movff xC+0,divA+0
heinrichsweikamp
parents:
diff changeset
403 movff xC+1,divA+1
heinrichsweikamp
parents:
diff changeset
404 movlw d'7'
heinrichsweikamp
parents:
diff changeset
405 movwf divB+0
heinrichsweikamp
parents:
diff changeset
406 call div16 ; devided by 2^7 equals velocity in m/min
heinrichsweikamp
parents:
diff changeset
407
heinrichsweikamp
parents:
diff changeset
408 movlw d'99'
heinrichsweikamp
parents:
diff changeset
409 cpfsgt divA+0 ; limit to 99m/min
heinrichsweikamp
parents:
diff changeset
410 bra calc_velocity3
heinrichsweikamp
parents:
diff changeset
411 movwf divA+0 ; divA=99
heinrichsweikamp
parents:
diff changeset
412
heinrichsweikamp
parents:
diff changeset
413 calc_velocity3:
heinrichsweikamp
parents:
diff changeset
414 movlw velocity_warning_level_1 ; lowest threshold for display vertical velocity
heinrichsweikamp
parents:
diff changeset
415 subwf divA+0,W ;
heinrichsweikamp
parents:
diff changeset
416 btfss STATUS,C
heinrichsweikamp
parents:
diff changeset
417 bra do_not_display_velocity
heinrichsweikamp
parents:
diff changeset
418
heinrichsweikamp
parents:
diff changeset
419 bsf display_velocity
heinrichsweikamp
parents:
diff changeset
420 call TFT_display_velocity ; With divA+0 = m/min...
heinrichsweikamp
parents:
diff changeset
421 return
heinrichsweikamp
parents:
diff changeset
422
heinrichsweikamp
parents:
diff changeset
423 do_not_display_velocity:
heinrichsweikamp
parents:
diff changeset
424 btfss display_velocity ; Velocity was not displayed, do not delete
heinrichsweikamp
parents:
diff changeset
425 return
heinrichsweikamp
parents:
diff changeset
426 bcf display_velocity ; Velocity was displayed, delete velocity now
heinrichsweikamp
parents:
diff changeset
427 call TFT_display_velocity_clear
heinrichsweikamp
parents:
diff changeset
428 return
heinrichsweikamp
parents:
diff changeset
429
heinrichsweikamp
parents:
diff changeset
430 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
431
heinrichsweikamp
parents:
diff changeset
432 timeout_menuview:
heinrichsweikamp
parents:
diff changeset
433 decfsz timeout_counter3,F ; timeout for menuview
heinrichsweikamp
parents:
diff changeset
434 return ; No timeout, return
heinrichsweikamp
parents:
diff changeset
435 ; Timeout, clear e.g. "Menu?"
heinrichsweikamp
parents:
diff changeset
436 goto menuview_toggle_reset ; "returns"
heinrichsweikamp
parents:
diff changeset
437
heinrichsweikamp
parents:
diff changeset
438 timeout_divemode_menu:
heinrichsweikamp
parents:
diff changeset
439 decfsz timeout_counter3,F ; timeout for divemode menu
heinrichsweikamp
parents:
diff changeset
440 return
heinrichsweikamp
parents:
diff changeset
441
heinrichsweikamp
parents:
diff changeset
442 global timeout_divemode_menu2
heinrichsweikamp
parents:
diff changeset
443 timeout_divemode_menu2: ; Called from divemenu_tree.asm
heinrichsweikamp
parents:
diff changeset
444 bcf divemode_menu ; Timeout! Clear flag
heinrichsweikamp
parents:
diff changeset
445 call TFT_clear_divemode_menu ; Clear menu
heinrichsweikamp
parents:
diff changeset
446 call TFT_active_gas_divemode ; Redraw gas/setpoint/diluent
heinrichsweikamp
parents:
diff changeset
447 bcf blinking_better_gas ; Clear flag to have temperature updated once
heinrichsweikamp
parents:
diff changeset
448 call TFT_temp_divemode ; Displays temperature
heinrichsweikamp
parents:
diff changeset
449
heinrichsweikamp
parents:
diff changeset
450 btfss decostop_active ; In deco mode ?
heinrichsweikamp
parents:
diff changeset
451 bra timeout_divemode_menu_ndl ; No, show NDL again
heinrichsweikamp
parents:
diff changeset
452 ; Show deco
heinrichsweikamp
parents:
diff changeset
453 call TFT_display_deko_mask ; clear nostop time, display decodata
heinrichsweikamp
parents:
diff changeset
454 call TFT_display_deko
heinrichsweikamp
parents:
diff changeset
455 call TFT_show_TTS_divemode
heinrichsweikamp
parents:
diff changeset
456 return
heinrichsweikamp
parents:
diff changeset
457 timeout_divemode_menu_ndl: ; Show NDL
heinrichsweikamp
parents:
diff changeset
458 call TFT_display_ndl_mask ; Clear deco data, display nostop time
heinrichsweikamp
parents:
diff changeset
459 call TFT_display_ndl
heinrichsweikamp
parents:
diff changeset
460 return
heinrichsweikamp
parents:
diff changeset
461
heinrichsweikamp
parents:
diff changeset
462 timeout_divemode:
heinrichsweikamp
parents:
diff changeset
463 btfsc divemode_menu ; Divemode menu active?
heinrichsweikamp
parents:
diff changeset
464 rcall timeout_divemode_menu ; Yes, check the timeout for it...
heinrichsweikamp
parents:
diff changeset
465
heinrichsweikamp
parents:
diff changeset
466 btfsc menuview ; is a menuview shown?
heinrichsweikamp
parents:
diff changeset
467 rcall timeout_menuview ; Yes, check the timeout for it...
heinrichsweikamp
parents:
diff changeset
468
heinrichsweikamp
parents:
diff changeset
469 btfss realdive ; Dive longer then one minute
heinrichsweikamp
parents:
diff changeset
470 return
heinrichsweikamp
parents:
diff changeset
471
heinrichsweikamp
parents:
diff changeset
472 btfsc FLAG_apnoe_mode ; In Apnoe mode?
heinrichsweikamp
parents:
diff changeset
473 bra timeout_divemode2 ; Yes, use CF30 [min] for timeout
heinrichsweikamp
parents:
diff changeset
474
heinrichsweikamp
parents:
diff changeset
475 ifndef __DEBUG
heinrichsweikamp
parents:
diff changeset
476 btfsc simulatormode_active ; In Simulator mode?
heinrichsweikamp
parents:
diff changeset
477 bra timeout_divemode3 ; Yes, use simulator timeout
heinrichsweikamp
parents:
diff changeset
478 endif
heinrichsweikamp
parents:
diff changeset
479
heinrichsweikamp
parents:
diff changeset
480 bcf divemode
heinrichsweikamp
parents:
diff changeset
481 incf timeout_counter,F
heinrichsweikamp
parents:
diff changeset
482 movlw d'0'
heinrichsweikamp
parents:
diff changeset
483 addwfc timeout_counter2,F ; timeout is 15bits
heinrichsweikamp
parents:
diff changeset
484
heinrichsweikamp
parents:
diff changeset
485 movlw LOW divemode_timeout
heinrichsweikamp
parents:
diff changeset
486 movwf sub_a+0
heinrichsweikamp
parents:
diff changeset
487 movlw HIGH divemode_timeout
heinrichsweikamp
parents:
diff changeset
488 movwf sub_a+1
heinrichsweikamp
parents:
diff changeset
489
heinrichsweikamp
parents:
diff changeset
490 movff timeout_counter, sub_b+0
heinrichsweikamp
parents:
diff changeset
491 movff timeout_counter2, sub_b+1
heinrichsweikamp
parents:
diff changeset
492 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
493 btfss neg_flag ; Result negative?
heinrichsweikamp
parents:
diff changeset
494 bsf divemode ; No, set flag
heinrichsweikamp
parents:
diff changeset
495 return
heinrichsweikamp
parents:
diff changeset
496
heinrichsweikamp
parents:
diff changeset
497 timeout_divemode2:
heinrichsweikamp
parents:
diff changeset
498 incf timeout_counter,F ; seconds...
heinrichsweikamp
parents:
diff changeset
499 movlw d'60'
heinrichsweikamp
parents:
diff changeset
500 cpfseq timeout_counter ; timeout_counter=60?
heinrichsweikamp
parents:
diff changeset
501 return ; No.
heinrichsweikamp
parents:
diff changeset
502 ; One minute timeout done.
heinrichsweikamp
parents:
diff changeset
503 clrf timeout_counter
heinrichsweikamp
parents:
diff changeset
504 bcf divemode
heinrichsweikamp
parents:
diff changeset
505 incf apnoe_timeout_counter,F
heinrichsweikamp
parents:
diff changeset
506 movlw apnoe_timeout ; apnoe timeout [min]
heinrichsweikamp
parents:
diff changeset
507 cpfseq apnoe_timeout_counter
heinrichsweikamp
parents:
diff changeset
508 bsf divemode
heinrichsweikamp
parents:
diff changeset
509 return
heinrichsweikamp
parents:
diff changeset
510
heinrichsweikamp
parents:
diff changeset
511 timeout_divemode3:
heinrichsweikamp
parents:
diff changeset
512 bcf divemode
heinrichsweikamp
parents:
diff changeset
513 incf timeout_counter,F
heinrichsweikamp
parents:
diff changeset
514 movlw simulator_timeout ; simulator timeout
heinrichsweikamp
parents:
diff changeset
515 cpfsgt timeout_counter
heinrichsweikamp
parents:
diff changeset
516 bsf divemode
heinrichsweikamp
parents:
diff changeset
517 return
heinrichsweikamp
parents:
diff changeset
518
heinrichsweikamp
parents:
diff changeset
519 update_temp_and_or_depth: ; New sensor data arrived...
heinrichsweikamp
parents:
diff changeset
520 btfsc temp_changed
heinrichsweikamp
parents:
diff changeset
521 call TFT_temp_divemode ; Displays temperature
heinrichsweikamp
parents:
diff changeset
522
heinrichsweikamp
parents:
diff changeset
523 btfsc pressure_refresh
heinrichsweikamp
parents:
diff changeset
524 call TFT_depth ; Displays new depth
heinrichsweikamp
parents:
diff changeset
525
heinrichsweikamp
parents:
diff changeset
526 rcall set_max_depth ; update max. depth if required
heinrichsweikamp
parents:
diff changeset
527 bcf pressure_refresh ; until new pressure is available
heinrichsweikamp
parents:
diff changeset
528 return
heinrichsweikamp
parents:
diff changeset
529
heinrichsweikamp
parents:
diff changeset
530 update_divemode60: ; update any minute
heinrichsweikamp
parents:
diff changeset
531 call get_battery_voltage ; gets battery voltage
heinrichsweikamp
parents:
diff changeset
532 call set_powersafe ; Battery low?
heinrichsweikamp
parents:
diff changeset
533 call TFT_max_pressure ; Update max. depth
heinrichsweikamp
parents:
diff changeset
534 call customview_minute ; Do every-minute tasks for the custom view area
heinrichsweikamp
parents:
diff changeset
535 bcf oneminupdate
heinrichsweikamp
parents:
diff changeset
536
heinrichsweikamp
parents:
diff changeset
537 btfss simulatormode_active ; in simulator mode?
heinrichsweikamp
parents:
diff changeset
538 return ; No
heinrichsweikamp
parents:
diff changeset
539 ; Yes, quite dive mode simulation after 21*256s=89min:36s
heinrichsweikamp
parents:
diff changeset
540 movlw .20
heinrichsweikamp
parents:
diff changeset
541 cpfsgt total_divetime_seconds+1 ; Timeout?
heinrichsweikamp
parents:
diff changeset
542 return ; No
heinrichsweikamp
parents:
diff changeset
543 ifdef __DEBUG
heinrichsweikamp
parents:
diff changeset
544 return ; No simulator timeout in debug mode
heinrichsweikamp
parents:
diff changeset
545 endif
heinrichsweikamp
parents:
diff changeset
546 bra divemode_option1 ; Yes, set to 0m and "return"
heinrichsweikamp
parents:
diff changeset
547
heinrichsweikamp
parents:
diff changeset
548 set_max_depth:
heinrichsweikamp
parents:
diff changeset
549 movff max_pressure+0,sub_a+0
heinrichsweikamp
parents:
diff changeset
550 movff max_pressure+1,sub_a+1
heinrichsweikamp
parents:
diff changeset
551 SAFE_2BYTE_COPY rel_pressure, sub_b
heinrichsweikamp
parents:
diff changeset
552 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
553 ; max_pressure<rel_pressure -> neg_flag=1
heinrichsweikamp
parents:
diff changeset
554 ; rel_pressure<=max_pressure -> neg_flag=0
heinrichsweikamp
parents:
diff changeset
555 btfss neg_flag
heinrichsweikamp
parents:
diff changeset
556 return
heinrichsweikamp
parents:
diff changeset
557 ; max_pressure<rel_pressure
heinrichsweikamp
parents:
diff changeset
558 movff sub_b+0,max_pressure+0
heinrichsweikamp
parents:
diff changeset
559 movff sub_b+1,max_pressure+1
heinrichsweikamp
parents:
diff changeset
560 call TFT_max_pressure ; No, use normal max. depth
heinrichsweikamp
parents:
diff changeset
561 return
heinrichsweikamp
parents:
diff changeset
562
heinrichsweikamp
parents:
diff changeset
563 set_min_temp:
heinrichsweikamp
parents:
diff changeset
564 movff minimum_temperature+0,sub_a+0
heinrichsweikamp
parents:
diff changeset
565 movff minimum_temperature+1,sub_a+1
heinrichsweikamp
parents:
diff changeset
566 SAFE_2BYTE_COPY temperature,sub_b
heinrichsweikamp
parents:
diff changeset
567 call sub16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
568 ; minimum_temperature<T -> neg_flag=1
heinrichsweikamp
parents:
diff changeset
569 ; T<=minimum_temperature -> neg_flag=0
heinrichsweikamp
parents:
diff changeset
570 btfsc neg_flag
heinrichsweikamp
parents:
diff changeset
571 return
heinrichsweikamp
parents:
diff changeset
572 ; minimum_temperature>=T
heinrichsweikamp
parents:
diff changeset
573 movff sub_b+0,minimum_temperature+0
heinrichsweikamp
parents:
diff changeset
574 movff sub_b+1,minimum_temperature+1
heinrichsweikamp
parents:
diff changeset
575 return
heinrichsweikamp
parents:
diff changeset
576
heinrichsweikamp
parents:
diff changeset
577 global set_dive_modes
heinrichsweikamp
parents:
diff changeset
578 set_dive_modes:
heinrichsweikamp
parents:
diff changeset
579 btfsc high_altitude_mode ; In high altitude (Fly) mode?
heinrichsweikamp
parents:
diff changeset
580 bra set_dive_modes3 ; Yes!
heinrichsweikamp
parents:
diff changeset
581
heinrichsweikamp
parents:
diff changeset
582 set_dive_modes0:
heinrichsweikamp
parents:
diff changeset
583 movlw LOW start_dive_threshold
heinrichsweikamp
parents:
diff changeset
584 movwf sub_a+0 ; dive_treshold is in cm
heinrichsweikamp
parents:
diff changeset
585 movlw HIGH start_dive_threshold
heinrichsweikamp
parents:
diff changeset
586 movwf sub_a+1 ; dive_treshold is in cm
heinrichsweikamp
parents:
diff changeset
587
heinrichsweikamp
parents:
diff changeset
588 set_dive_modes1:
heinrichsweikamp
parents:
diff changeset
589 SAFE_2BYTE_COPY rel_pressure, sub_b
heinrichsweikamp
parents:
diff changeset
590 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
591
heinrichsweikamp
parents:
diff changeset
592 btfss neg_flag
heinrichsweikamp
parents:
diff changeset
593 bra set_dive_modes2 ; too shallow (rel_pressure<dive_threshold)
heinrichsweikamp
parents:
diff changeset
594
heinrichsweikamp
parents:
diff changeset
595 btfsc realdive ; Dive longer than one minute?
heinrichsweikamp
parents:
diff changeset
596 clrf timeout_counter ; Yes, reset timout counter
heinrichsweikamp
parents:
diff changeset
597
heinrichsweikamp
parents:
diff changeset
598 set_dive_modes_common:
heinrichsweikamp
parents:
diff changeset
599 bsf divemode ; (Re-)Set divemode flag
heinrichsweikamp
parents:
diff changeset
600 bsf divemode2 ; displayed divetime is running
heinrichsweikamp
parents:
diff changeset
601 return
heinrichsweikamp
parents:
diff changeset
602
heinrichsweikamp
parents:
diff changeset
603 set_dive_modes2:
heinrichsweikamp
parents:
diff changeset
604 bcf divemode2 ; Stop time
heinrichsweikamp
parents:
diff changeset
605 btfss realdive ; dive longer then one minute?
heinrichsweikamp
parents:
diff changeset
606 bcf divemode ; no -> this was no real dive
heinrichsweikamp
parents:
diff changeset
607 return ; No, return
heinrichsweikamp
parents:
diff changeset
608
heinrichsweikamp
parents:
diff changeset
609
heinrichsweikamp
parents:
diff changeset
610 set_dive_modes3: ; High-altitude mode
heinrichsweikamp
parents:
diff changeset
611 btfsc realdive ; dive longer then one minute?
heinrichsweikamp
parents:
diff changeset
612 bra set_dive_modes0 ; Yes -> this is a real dive -> Use start_dive_threshold or ascend
heinrichsweikamp
parents:
diff changeset
613
heinrichsweikamp
parents:
diff changeset
614 movlw HIGH high_altitude_dive_threshold
heinrichsweikamp
parents:
diff changeset
615 movwf sub_a+1
heinrichsweikamp
parents:
diff changeset
616 movlw LOW high_altitude_dive_threshold
heinrichsweikamp
parents:
diff changeset
617 movwf sub_a+0
heinrichsweikamp
parents:
diff changeset
618 bra set_dive_modes1
heinrichsweikamp
parents:
diff changeset
619
heinrichsweikamp
parents:
diff changeset
620 set_powersafe:
heinrichsweikamp
parents:
diff changeset
621 movlw color_code_battery_low+1; [%]
heinrichsweikamp
parents:
diff changeset
622 cpfslt batt_percent
heinrichsweikamp
parents:
diff changeset
623 return
heinrichsweikamp
parents:
diff changeset
624
heinrichsweikamp
parents:
diff changeset
625 movlw d'7' ; Type of Alarm (Battery Low)
heinrichsweikamp
parents:
diff changeset
626 movwf AlarmType ; Copy to Alarm Register
heinrichsweikamp
parents:
diff changeset
627 bsf event_occured ; Set Event Flag
heinrichsweikamp
parents:
diff changeset
628 movlw .0
heinrichsweikamp
parents:
diff changeset
629 movff WREG,opt_brightness ; Set Brightness to ECO
heinrichsweikamp
parents:
diff changeset
630 return ; return
heinrichsweikamp
parents:
diff changeset
631
heinrichsweikamp
parents:
diff changeset
632 calc_average_depth:
heinrichsweikamp
parents:
diff changeset
633 btfsc reset_average_depth ; Reset the Avewrage depth?
heinrichsweikamp
parents:
diff changeset
634 rcall reset_average1 ; Reset the resettable average depth
heinrichsweikamp
parents:
diff changeset
635
heinrichsweikamp
parents:
diff changeset
636 ; 1. Add new 2xdepth to the Sum of depths registers
heinrichsweikamp
parents:
diff changeset
637 SAFE_2BYTE_COPY rel_pressure, xB ; Buffer...
heinrichsweikamp
parents:
diff changeset
638 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
639 rlcf xB+0,F
heinrichsweikamp
parents:
diff changeset
640 rlcf xB+1,F ; x2
heinrichsweikamp
parents:
diff changeset
641
heinrichsweikamp
parents:
diff changeset
642 movf xB+0,w
heinrichsweikamp
parents:
diff changeset
643 addwf average_depth_hold+0,F
heinrichsweikamp
parents:
diff changeset
644 movf xB+1,w
heinrichsweikamp
parents:
diff changeset
645 addwfc average_depth_hold+1,F
heinrichsweikamp
parents:
diff changeset
646 movlw d'0'
heinrichsweikamp
parents:
diff changeset
647 addwfc average_depth_hold+2,F
heinrichsweikamp
parents:
diff changeset
648 addwfc average_depth_hold+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar
heinrichsweikamp
parents:
diff changeset
649
heinrichsweikamp
parents:
diff changeset
650 ; Do the same for the _total registers (Non-Resettable)
heinrichsweikamp
parents:
diff changeset
651 movf xB+0,w
heinrichsweikamp
parents:
diff changeset
652 addwf average_depth_hold_total+0,F
heinrichsweikamp
parents:
diff changeset
653 movf xB+1,w
heinrichsweikamp
parents:
diff changeset
654 addwfc average_depth_hold_total+1,F
heinrichsweikamp
parents:
diff changeset
655 movlw d'0'
heinrichsweikamp
parents:
diff changeset
656 addwfc average_depth_hold_total+2,F
heinrichsweikamp
parents:
diff changeset
657 addwfc average_depth_hold_total+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar
heinrichsweikamp
parents:
diff changeset
658
heinrichsweikamp
parents:
diff changeset
659 ; 2. Compute Average Depth on base of average_divesecs:2
heinrichsweikamp
parents:
diff changeset
660 movff average_divesecs+0,xB+0
heinrichsweikamp
parents:
diff changeset
661 movff average_divesecs+1,xB+1 ; Copy
heinrichsweikamp
parents:
diff changeset
662 movff average_depth_hold+0,xC+0
heinrichsweikamp
parents:
diff changeset
663 movff average_depth_hold+1,xC+1
heinrichsweikamp
parents:
diff changeset
664 movff average_depth_hold+2,xC+2
heinrichsweikamp
parents:
diff changeset
665 movff average_depth_hold+3,xC+3
heinrichsweikamp
parents:
diff changeset
666
heinrichsweikamp
parents:
diff changeset
667 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
668 movff xC+0,avr_rel_pressure+0
heinrichsweikamp
parents:
diff changeset
669 movff xC+1,avr_rel_pressure+1
heinrichsweikamp
parents:
diff changeset
670
heinrichsweikamp
parents:
diff changeset
671 ; 3. Compute Total Average Depth on base of total_divetime_seconds:2
heinrichsweikamp
parents:
diff changeset
672 movff total_divetime_seconds+0,xB+0
heinrichsweikamp
parents:
diff changeset
673 movff total_divetime_seconds+1,xB+1 ; Copy
heinrichsweikamp
parents:
diff changeset
674 movff average_depth_hold_total+0,xC+0
heinrichsweikamp
parents:
diff changeset
675 movff average_depth_hold_total+1,xC+1
heinrichsweikamp
parents:
diff changeset
676 movff average_depth_hold_total+2,xC+2
heinrichsweikamp
parents:
diff changeset
677 movff average_depth_hold_total+3,xC+3
heinrichsweikamp
parents:
diff changeset
678 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
679 movff xC+0,avr_rel_pressure_total+0
heinrichsweikamp
parents:
diff changeset
680 movff xC+1,avr_rel_pressure_total+1
heinrichsweikamp
parents:
diff changeset
681
heinrichsweikamp
parents:
diff changeset
682 ; ; Compute Total Average Depth on base of divemins:2 and divesecs
heinrichsweikamp
parents:
diff changeset
683 ; movff divemins+0,xA+0
heinrichsweikamp
parents:
diff changeset
684 ; movff divemins+1,xA+1
heinrichsweikamp
parents:
diff changeset
685 ; movlw d'60'
heinrichsweikamp
parents:
diff changeset
686 ; movwf xB+0
heinrichsweikamp
parents:
diff changeset
687 ; clrf xB+1
heinrichsweikamp
parents:
diff changeset
688 ; call mult16x16 ; xC:4=xA:2*xB:2
heinrichsweikamp
parents:
diff changeset
689 ; movf divesecs,W
heinrichsweikamp
parents:
diff changeset
690 ; addwf xC+0,F
heinrichsweikamp
parents:
diff changeset
691 ; movlw d'0'
heinrichsweikamp
parents:
diff changeset
692 ; addwfc xC+1,F ; xC:2 holds total dive seconds
heinrichsweikamp
parents:
diff changeset
693 ; movlw d'3' ; 2+1
heinrichsweikamp
parents:
diff changeset
694 ; btfss divesecs,0 ; divesecs even?
heinrichsweikamp
parents:
diff changeset
695 ; movlw d'2' ; Yes, do not add +1
heinrichsweikamp
parents:
diff changeset
696 ; addwf xC+0,F
heinrichsweikamp
parents:
diff changeset
697 ; movlw d'0'
heinrichsweikamp
parents:
diff changeset
698 ; addwfc xC+1,F
heinrichsweikamp
parents:
diff changeset
699 ; ; Ignore xC+2 and xC+3. Total Average will only work up to divetime=1092:16
heinrichsweikamp
parents:
diff changeset
700 ; movff xC+0,xB+0
heinrichsweikamp
parents:
diff changeset
701 ; movff xC+1,xB+1 ; Copy
heinrichsweikamp
parents:
diff changeset
702 ; movff average_depth_hold_total+0,xC+0
heinrichsweikamp
parents:
diff changeset
703 ; movff average_depth_hold_total+1,xC+1
heinrichsweikamp
parents:
diff changeset
704 ; movff average_depth_hold_total+2,xC+2
heinrichsweikamp
parents:
diff changeset
705 ; movff average_depth_hold_total+3,xC+3
heinrichsweikamp
parents:
diff changeset
706 ;
heinrichsweikamp
parents:
diff changeset
707 ; call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
708 ; movff xC+0,avr_rel_pressure_total+0
heinrichsweikamp
parents:
diff changeset
709 ; movff xC+1,avr_rel_pressure_total+1
heinrichsweikamp
parents:
diff changeset
710
heinrichsweikamp
parents:
diff changeset
711 return
heinrichsweikamp
parents:
diff changeset
712
heinrichsweikamp
parents:
diff changeset
713 reset_average1:
heinrichsweikamp
parents:
diff changeset
714 clrf average_depth_hold+0
heinrichsweikamp
parents:
diff changeset
715 clrf average_depth_hold+1
heinrichsweikamp
parents:
diff changeset
716 clrf average_depth_hold+2
heinrichsweikamp
parents:
diff changeset
717 clrf average_depth_hold+3 ; Clear average depth register
heinrichsweikamp
parents:
diff changeset
718 movlw d'2'
heinrichsweikamp
parents:
diff changeset
719 movwf average_divesecs+0
heinrichsweikamp
parents:
diff changeset
720 clrf average_divesecs+1
heinrichsweikamp
parents:
diff changeset
721 bcf reset_average_depth ; Clear flag
heinrichsweikamp
parents:
diff changeset
722 return
heinrichsweikamp
parents:
diff changeset
723
heinrichsweikamp
parents:
diff changeset
724 test_switches_divemode: ; checks switches in divemode
heinrichsweikamp
parents:
diff changeset
725 btfsc divemode_menu ; Divemode menu shown?
heinrichsweikamp
parents:
diff changeset
726 bra test_switches_divemode_menu ; Yes, use menu processor
heinrichsweikamp
parents:
diff changeset
727 btfsc switch_left
heinrichsweikamp
parents:
diff changeset
728 bra test_switches_divemode2 ; Enter button pressed, check if we need to do something
heinrichsweikamp
parents:
diff changeset
729 btfss switch_right
heinrichsweikamp
parents:
diff changeset
730 return ; No button press
heinrichsweikamp
parents:
diff changeset
731 tstfsz menupos2 ; any option shown?
heinrichsweikamp
parents:
diff changeset
732 bra test_switches_divemode1 ; Yes, do option tasks
heinrichsweikamp
parents:
diff changeset
733 bsf toggle_customview ; No, toggle custom view
heinrichsweikamp
parents:
diff changeset
734 return
heinrichsweikamp
parents:
diff changeset
735
heinrichsweikamp
parents:
diff changeset
736 test_switches_divemode_menu:
heinrichsweikamp
parents:
diff changeset
737 btfsc switch_left
heinrichsweikamp
parents:
diff changeset
738 bra test_switches_divemode_menu2 ; Move cursor
heinrichsweikamp
parents:
diff changeset
739 btfsc switch_right
heinrichsweikamp
parents:
diff changeset
740 bra test_switches_divemode_menu3 ; Enter submenu or do something
heinrichsweikamp
parents:
diff changeset
741 return ; No button press
heinrichsweikamp
parents:
diff changeset
742
heinrichsweikamp
parents:
diff changeset
743 test_switches_divemode_menu1:
heinrichsweikamp
parents:
diff changeset
744 clrf menupos
heinrichsweikamp
parents:
diff changeset
745 test_switches_divemode_menu2:
heinrichsweikamp
parents:
diff changeset
746 incf menupos,F
heinrichsweikamp
parents:
diff changeset
747 incf menupos4,W ; menupos4+1 -> WREG
heinrichsweikamp
parents:
diff changeset
748 cpfslt menupos ; >menupos4 (Set in menu_processor.asm)?
heinrichsweikamp
parents:
diff changeset
749 bra test_switches_divemode_menu1; > Yes, set to 1
heinrichsweikamp
parents:
diff changeset
750 call TFT_divemode_menu_cursor ; Update the cursor
heinrichsweikamp
parents:
diff changeset
751 bcf switch_left
heinrichsweikamp
parents:
diff changeset
752 movlw divemode_menu_timeout ; Reload timeout
heinrichsweikamp
parents:
diff changeset
753 movwf timeout_counter3 ; timeout for divemode menu
heinrichsweikamp
parents:
diff changeset
754 return
heinrichsweikamp
parents:
diff changeset
755
heinrichsweikamp
parents:
diff changeset
756 test_switches_divemode_menu3: ; Enter submenu or do something
heinrichsweikamp
parents:
diff changeset
757 bcf switch_right
heinrichsweikamp
parents:
diff changeset
758 ; decf menupos,F ; menu_processor needs 0-5...
heinrichsweikamp
parents:
diff changeset
759 extern do_line_menu
heinrichsweikamp
parents:
diff changeset
760 goto do_line_menu ; Warning! Trashes STKPTR and returns to diveloop_loop4:
heinrichsweikamp
parents:
diff changeset
761
heinrichsweikamp
parents:
diff changeset
762 test_switches_divemode1:
heinrichsweikamp
parents:
diff changeset
763 bcf switch_right
heinrichsweikamp
parents:
diff changeset
764 movlw divemode_menuview_timeout
heinrichsweikamp
parents:
diff changeset
765 movwf timeout_counter3 ; Reload timeout
heinrichsweikamp
parents:
diff changeset
766 movff menupos2,WREG ; Menupos3 holds number of customview/divemode menu function
heinrichsweikamp
parents:
diff changeset
767 dcfsnz WREG,F
heinrichsweikamp
parents:
diff changeset
768 bra divemode_option0 ; Start/Setup Divemode menu
heinrichsweikamp
parents:
diff changeset
769 dcfsnz WREG,F
heinrichsweikamp
parents:
diff changeset
770 bra divemode_option1 ; Quit Simulation?
heinrichsweikamp
parents:
diff changeset
771 dcfsnz WREG,F
heinrichsweikamp
parents:
diff changeset
772 bra divemode_option2 ; Descent 1m
heinrichsweikamp
parents:
diff changeset
773 dcfsnz WREG,F
heinrichsweikamp
parents:
diff changeset
774 bra divemode_option3 ; Ascend 1m
heinrichsweikamp
parents:
diff changeset
775 dcfsnz WREG,F
heinrichsweikamp
parents:
diff changeset
776 bra divemode_option4 ; Quit Apnoe mode
heinrichsweikamp
parents:
diff changeset
777 dcfsnz WREG,F
heinrichsweikamp
parents:
diff changeset
778 bra divemode_option5 ; Reset Stopwatch (In Gauge mode)
heinrichsweikamp
parents:
diff changeset
779 return
heinrichsweikamp
parents:
diff changeset
780
heinrichsweikamp
parents:
diff changeset
781 test_switches_divemode2:
heinrichsweikamp
parents:
diff changeset
782 bcf switch_left
heinrichsweikamp
parents:
diff changeset
783 call menuview_toggle ; Menu or Simulator tasks
heinrichsweikamp
parents:
diff changeset
784 return
heinrichsweikamp
parents:
diff changeset
785
heinrichsweikamp
parents:
diff changeset
786 gas_switched_common:
heinrichsweikamp
parents:
diff changeset
787 decf menupos,W ; 1-5 -> 0-4
heinrichsweikamp
parents:
diff changeset
788 btfss FLAG_ccr_mode ; Choose OC Gases
heinrichsweikamp
parents:
diff changeset
789 rcall setup_gas_registers ; With WREG=Gas 0-4
heinrichsweikamp
parents:
diff changeset
790 btfsc FLAG_ccr_mode ; Choose CC Diluents
heinrichsweikamp
parents:
diff changeset
791 rcall setup_dil_registers ; With WREG=Gas 0-4
heinrichsweikamp
parents:
diff changeset
792
heinrichsweikamp
parents:
diff changeset
793 decf menupos,W ; 1-5 -> 0-4
heinrichsweikamp
parents:
diff changeset
794 btfsc is_bailout ; Choose OC Bailouts (OC Gases)
heinrichsweikamp
parents:
diff changeset
795 rcall setup_gas_registers ; With WREG=Gas 0-4
heinrichsweikamp
parents:
diff changeset
796
heinrichsweikamp
parents:
diff changeset
797 call TFT_active_gas_divemode ; Display gas/Setpoint
heinrichsweikamp
parents:
diff changeset
798 bsf event_occured ; Set global event byte
heinrichsweikamp
parents:
diff changeset
799 bsf stored_gas_changed ; Set Flag for profile
heinrichsweikamp
parents:
diff changeset
800 bcf divemode_gaschange ; Clear flag
heinrichsweikamp
parents:
diff changeset
801 clrf WREG
heinrichsweikamp
parents:
diff changeset
802 movff WREG,char_O_deco_status ; Restart decoplan computation
heinrichsweikamp
parents:
diff changeset
803 return
heinrichsweikamp
parents:
diff changeset
804
heinrichsweikamp
parents:
diff changeset
805 global setup_gas_registers
heinrichsweikamp
parents:
diff changeset
806 setup_gas_registers: ; With WREG=Gas 0-4
heinrichsweikamp
parents:
diff changeset
807 lfsr FSR1,opt_gas_O2_ratio+0
heinrichsweikamp
parents:
diff changeset
808 movff PLUSW1,char_I_O2_ratio ; O2 (For ppO2 calculations)
heinrichsweikamp
parents:
diff changeset
809 lfsr FSR1,opt_gas_He_ratio+0
heinrichsweikamp
parents:
diff changeset
810 movff PLUSW1,char_I_He_ratio ; He
heinrichsweikamp
parents:
diff changeset
811 incf WREG,W ; Gas# 1-5
heinrichsweikamp
parents:
diff changeset
812 movff WREG,char_I_current_gas ; Set gas
heinrichsweikamp
parents:
diff changeset
813 movff WREG,active_gas ; Set for logbook and display
heinrichsweikamp
parents:
diff changeset
814 banksel char_I_O2_ratio
heinrichsweikamp
parents:
diff changeset
815 movf char_I_O2_ratio,W ; Add O2...
heinrichsweikamp
parents:
diff changeset
816 addwf char_I_He_ratio,W ; ...and He...
heinrichsweikamp
parents:
diff changeset
817 sublw .100 ; ...subtract both from 100
heinrichsweikamp
parents:
diff changeset
818 movwf char_I_N2_ratio ; -> N2!
heinrichsweikamp
parents:
diff changeset
819 banksel common
heinrichsweikamp
parents:
diff changeset
820 return
heinrichsweikamp
parents:
diff changeset
821
heinrichsweikamp
parents:
diff changeset
822 global setup_dil_registers
heinrichsweikamp
parents:
diff changeset
823 setup_dil_registers: ; With WREG=dil 0-4
heinrichsweikamp
parents:
diff changeset
824 lfsr FSR1,opt_dil_O2_ratio+0
heinrichsweikamp
parents:
diff changeset
825 movff PLUSW1,char_I_O2_ratio ; O2 (For ppO2 calculations)
heinrichsweikamp
parents:
diff changeset
826 lfsr FSR1,opt_dil_He_ratio+0
heinrichsweikamp
parents:
diff changeset
827 movff PLUSW1,char_I_He_ratio ; He
heinrichsweikamp
parents:
diff changeset
828 incf WREG,W ; Gas# 1-5
heinrichsweikamp
parents:
diff changeset
829 movff WREG,char_I_current_gas ; Set gas
heinrichsweikamp
parents:
diff changeset
830 movff WREG,active_gas ; Set for logbook and display
heinrichsweikamp
parents:
diff changeset
831 banksel char_I_O2_ratio
heinrichsweikamp
parents:
diff changeset
832 movf char_I_O2_ratio,W ; Add O2...
heinrichsweikamp
parents:
diff changeset
833 addwf char_I_He_ratio,W ; ...and He...
heinrichsweikamp
parents:
diff changeset
834 sublw .100 ; ...subtract both from 100
heinrichsweikamp
parents:
diff changeset
835 movwf char_I_N2_ratio ; -> N2!
heinrichsweikamp
parents:
diff changeset
836 banksel common
heinrichsweikamp
parents:
diff changeset
837 return
heinrichsweikamp
parents:
diff changeset
838
heinrichsweikamp
parents:
diff changeset
839 divemode_option0: ; Start/Setup Divemode menu
heinrichsweikamp
parents:
diff changeset
840 call TFT_clear_divemode_menu ; Clear menu area
heinrichsweikamp
parents:
diff changeset
841 bcf menuview
heinrichsweikamp
parents:
diff changeset
842 extern do_main_divemenu
heinrichsweikamp
parents:
diff changeset
843 call do_main_divemenu
heinrichsweikamp
parents:
diff changeset
844 global divemode_option0_return
heinrichsweikamp
parents:
diff changeset
845 divemode_option0_return:
heinrichsweikamp
parents:
diff changeset
846 ; movlw .1
heinrichsweikamp
parents:
diff changeset
847 ; movwf menupos ; Set to first option in divemode menu
heinrichsweikamp
parents:
diff changeset
848 call TFT_divemode_menu_cursor; Show the cursor
heinrichsweikamp
parents:
diff changeset
849 movlw divemode_menu_timeout
heinrichsweikamp
parents:
diff changeset
850 movwf timeout_counter3 ; timeout for divemode menu
heinrichsweikamp
parents:
diff changeset
851 bsf divemode_menu ; Set flag
heinrichsweikamp
parents:
diff changeset
852 clrf menupos2 ; Clear option counter
heinrichsweikamp
parents:
diff changeset
853 bra diveloop_loop4 ; Goto back to diveloop (Menuprocessor trashes STKPTR!)
heinrichsweikamp
parents:
diff changeset
854
heinrichsweikamp
parents:
diff changeset
855 divemode_option4:
heinrichsweikamp
parents:
diff changeset
856 movlw d'58' ; two seconds left
heinrichsweikamp
parents:
diff changeset
857 movwf timeout_counter
heinrichsweikamp
parents:
diff changeset
858 movlw apnoe_timeout-1 ; apnoe timeout [min]
heinrichsweikamp
parents:
diff changeset
859 movwf apnoe_timeout_counter
heinrichsweikamp
parents:
diff changeset
860 btfss simulatormode_active ; in simulator mode?
heinrichsweikamp
parents:
diff changeset
861 return ; No
heinrichsweikamp
parents:
diff changeset
862 divemode_option1: ; Quit simulation mode
heinrichsweikamp
parents:
diff changeset
863 banksel isr_backup
heinrichsweikamp
parents:
diff changeset
864 movlw low .1000
heinrichsweikamp
parents:
diff changeset
865 movwf sim_pressure+0
heinrichsweikamp
parents:
diff changeset
866 movlw high .1000
heinrichsweikamp
parents:
diff changeset
867 movwf sim_pressure+1 ; Set to 0m -> End of Dive
heinrichsweikamp
parents:
diff changeset
868 banksel common
heinrichsweikamp
parents:
diff changeset
869 call menuview_toggle_reset ; Reset to zero (Zero=no menuview)
heinrichsweikamp
parents:
diff changeset
870
heinrichsweikamp
parents:
diff changeset
871 btfss FLAG_apnoe_mode ; In Apnoe mode?
heinrichsweikamp
parents:
diff changeset
872 return ; No
heinrichsweikamp
parents:
diff changeset
873 movlw d'58' ; two seconds left
heinrichsweikamp
parents:
diff changeset
874 movwf timeout_counter
heinrichsweikamp
parents:
diff changeset
875 movlw apnoe_timeout-1 ; apnoe timeout [min]
heinrichsweikamp
parents:
diff changeset
876 movwf apnoe_timeout_counter
heinrichsweikamp
parents:
diff changeset
877 return
heinrichsweikamp
parents:
diff changeset
878
heinrichsweikamp
parents:
diff changeset
879 divemode_option3: ; minus 1m
heinrichsweikamp
parents:
diff changeset
880 banksel isr_backup
heinrichsweikamp
parents:
diff changeset
881 movlw d'100'
heinrichsweikamp
parents:
diff changeset
882 subwf sim_pressure+0
heinrichsweikamp
parents:
diff changeset
883 movlw .0
heinrichsweikamp
parents:
diff changeset
884 subwfb sim_pressure+1
heinrichsweikamp
parents:
diff changeset
885 rcall divemode_simulator_check_limits
heinrichsweikamp
parents:
diff changeset
886 banksel common
heinrichsweikamp
parents:
diff changeset
887 return
heinrichsweikamp
parents:
diff changeset
888
heinrichsweikamp
parents:
diff changeset
889 divemode_option2: ; plus 1m
heinrichsweikamp
parents:
diff changeset
890 banksel isr_backup
heinrichsweikamp
parents:
diff changeset
891 movlw d'100'
heinrichsweikamp
parents:
diff changeset
892 addwf sim_pressure+0
heinrichsweikamp
parents:
diff changeset
893 movlw .0
heinrichsweikamp
parents:
diff changeset
894 addwfc sim_pressure+1
heinrichsweikamp
parents:
diff changeset
895 rcall divemode_simulator_check_limits
heinrichsweikamp
parents:
diff changeset
896 banksel common
heinrichsweikamp
parents:
diff changeset
897 return
heinrichsweikamp
parents:
diff changeset
898
heinrichsweikamp
parents:
diff changeset
899 divemode_option5:
heinrichsweikamp
parents:
diff changeset
900 call menuview_toggle_reset ; Reset to zero (Zero=no menuview)
heinrichsweikamp
parents:
diff changeset
901 bsf reset_average_depth ; Set Flag
heinrichsweikamp
parents:
diff changeset
902 return
heinrichsweikamp
parents:
diff changeset
903
heinrichsweikamp
parents:
diff changeset
904 divemode_simulator_check_limits:
heinrichsweikamp
parents:
diff changeset
905 ; Check limits (150m and 0m)
heinrichsweikamp
parents:
diff changeset
906 movlw LOW d'16000' ; Compare to 16bar=16000mbar (150m).
heinrichsweikamp
parents:
diff changeset
907 subwf sim_pressure+0,W
heinrichsweikamp
parents:
diff changeset
908 movlw HIGH d'16000'
heinrichsweikamp
parents:
diff changeset
909 subwfb sim_pressure+1,W
heinrichsweikamp
parents:
diff changeset
910 bnc divemode_simulator_check_limits2 ; No-carry = borrow = not deeper
heinrichsweikamp
parents:
diff changeset
911
heinrichsweikamp
parents:
diff changeset
912 ; Too deep, limit to 150m
heinrichsweikamp
parents:
diff changeset
913 movlw LOW d'16000'
heinrichsweikamp
parents:
diff changeset
914 movwf sim_pressure+0
heinrichsweikamp
parents:
diff changeset
915 movlw HIGH d'16000'
heinrichsweikamp
parents:
diff changeset
916 movwf sim_pressure+1
heinrichsweikamp
parents:
diff changeset
917 return
heinrichsweikamp
parents:
diff changeset
918 divemode_simulator_check_limits2:
heinrichsweikamp
parents:
diff changeset
919 movlw LOW d'1000' ; Compare to 1bar == 0m == 1000 mbar.
heinrichsweikamp
parents:
diff changeset
920 subwf sim_pressure+0,W
heinrichsweikamp
parents:
diff changeset
921 movlw HIGH d'1000'
heinrichsweikamp
parents:
diff changeset
922 subwfb sim_pressure+1,W
heinrichsweikamp
parents:
diff changeset
923 btfsc STATUS,C ; No-carry = borrow = not deeper.
heinrichsweikamp
parents:
diff changeset
924 return ; Deeper than 0m == Ok.
heinrichsweikamp
parents:
diff changeset
925 ; Too shallow, limit to 0m
heinrichsweikamp
parents:
diff changeset
926 movlw LOW d'1000'
heinrichsweikamp
parents:
diff changeset
927 movwf sim_pressure+0
heinrichsweikamp
parents:
diff changeset
928 movlw HIGH d'1000'
heinrichsweikamp
parents:
diff changeset
929 movwf sim_pressure+1
heinrichsweikamp
parents:
diff changeset
930 return
heinrichsweikamp
parents:
diff changeset
931
heinrichsweikamp
parents:
diff changeset
932 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
933 ; Compare all enabled gas in list, to see if a better one is available.
heinrichsweikamp
parents:
diff changeset
934 ;
heinrichsweikamp
parents:
diff changeset
935 ; Output: better_gas_available, better_gas_number
heinrichsweikamp
parents:
diff changeset
936 ;
heinrichsweikamp
parents:
diff changeset
937 check_gas_change: ; Checks if a better gas should be selected (by user)
heinrichsweikamp
parents:
diff changeset
938 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode
heinrichsweikamp
parents:
diff changeset
939 clrf better_gas_number ; Clear better gas register
heinrichsweikamp
parents:
diff changeset
940
heinrichsweikamp
parents:
diff changeset
941 SAFE_2BYTE_COPY rel_pressure,xA
heinrichsweikamp
parents:
diff changeset
942 movlw d'100'
heinrichsweikamp
parents:
diff changeset
943 movwf xB+0
heinrichsweikamp
parents:
diff changeset
944 clrf xB+1
heinrichsweikamp
parents:
diff changeset
945 call div16x16 ; compute depth in full m -> result in xC+0
heinrichsweikamp
parents:
diff changeset
946
heinrichsweikamp
parents:
diff changeset
947 btfss FLAG_ccr_mode ; In CCR mode...
heinrichsweikamp
parents:
diff changeset
948 bra check_gas_change_OC_bail; No, check for OC or bailout
heinrichsweikamp
parents:
diff changeset
949 btfsc is_bailout ; Bailout?
heinrichsweikamp
parents:
diff changeset
950 bra check_gas_change_OC_bail; Yes, check for OC or bailout
heinrichsweikamp
parents:
diff changeset
951
heinrichsweikamp
parents:
diff changeset
952 ; Check Diluents
heinrichsweikamp
parents:
diff changeset
953 movlw .0
heinrichsweikamp
parents:
diff changeset
954 rcall check_dil_common ; With Gas 0-4 in WREG
heinrichsweikamp
parents:
diff changeset
955 movlw .1
heinrichsweikamp
parents:
diff changeset
956 rcall check_dil_common ; With Gas 0-4 in WREG
heinrichsweikamp
parents:
diff changeset
957 movlw .2
heinrichsweikamp
parents:
diff changeset
958 rcall check_dil_common ; With Gas 0-4 in WREG
heinrichsweikamp
parents:
diff changeset
959 movlw .3
heinrichsweikamp
parents:
diff changeset
960 rcall check_dil_common ; With Gas 0-4 in WREG
heinrichsweikamp
parents:
diff changeset
961 movlw .4
heinrichsweikamp
parents:
diff changeset
962 rcall check_dil_common ; With Gas 0-4 in WREG
heinrichsweikamp
parents:
diff changeset
963 bra check_gas_change_exit
heinrichsweikamp
parents:
diff changeset
964
heinrichsweikamp
parents:
diff changeset
965 check_gas_change_OC_bail:
heinrichsweikamp
parents:
diff changeset
966 movlw .0
heinrichsweikamp
parents:
diff changeset
967 rcall check_gas_common ; With Gas 0-4 in WREG
heinrichsweikamp
parents:
diff changeset
968 movlw .1
heinrichsweikamp
parents:
diff changeset
969 rcall check_gas_common ; With Gas 0-4 in WREG
heinrichsweikamp
parents:
diff changeset
970 movlw .2
heinrichsweikamp
parents:
diff changeset
971 rcall check_gas_common ; With Gas 0-4 in WREG
heinrichsweikamp
parents:
diff changeset
972 movlw .3
heinrichsweikamp
parents:
diff changeset
973 rcall check_gas_common ; With Gas 0-4 in WREG
heinrichsweikamp
parents:
diff changeset
974 movlw .4
heinrichsweikamp
parents:
diff changeset
975 rcall check_gas_common ; With Gas 0-4 in WREG
heinrichsweikamp
parents:
diff changeset
976 ; bra check_gas_change_exit
heinrichsweikamp
parents:
diff changeset
977 check_gas_change_exit:
heinrichsweikamp
parents:
diff changeset
978 btfss better_gas_available ; Is a better gas available
heinrichsweikamp
parents:
diff changeset
979 bcf blinking_better_gas ; No, Clear blinking flag
heinrichsweikamp
parents:
diff changeset
980 btfss better_gas_available ; Is a better gas available
heinrichsweikamp
parents:
diff changeset
981 clrf better_gas_number ; No, Clear better_gas_number (For gaslist display)
heinrichsweikamp
parents:
diff changeset
982 call TFT_active_gas_divemode ; Display gas/Setpoint
heinrichsweikamp
parents:
diff changeset
983 return
heinrichsweikamp
parents:
diff changeset
984
heinrichsweikamp
parents:
diff changeset
985 check_gas_common: ; With Gas 0-4 in WREG
heinrichsweikamp
parents:
diff changeset
986 btfsc better_gas_available ; Better Gas already found?
heinrichsweikamp
parents:
diff changeset
987 return ; Yes, return
heinrichsweikamp
parents:
diff changeset
988 lfsr FSR1,opt_gas_type ; 0=Disabled, 1=First, 2=Travel, 3=Deco
heinrichsweikamp
parents:
diff changeset
989 btfss PLUSW1,0 ; Test for Bit0 and 1 -> type=3 -> Deco
heinrichsweikamp
parents:
diff changeset
990 return ; No
heinrichsweikamp
parents:
diff changeset
991 btfss PLUSW1,1 ; Test for Bit0 and 1 -> type=3 -> Deco
heinrichsweikamp
parents:
diff changeset
992 return ; No
heinrichsweikamp
parents:
diff changeset
993 incf WREG,W ; 1-5
heinrichsweikamp
parents:
diff changeset
994 cpfseq active_gas ; is this gas currently selected?
heinrichsweikamp
parents:
diff changeset
995 bra check_gas_common2 ; No
heinrichsweikamp
parents:
diff changeset
996 return ; Yes, skip test for active gas
heinrichsweikamp
parents:
diff changeset
997 check_gas_common2:
heinrichsweikamp
parents:
diff changeset
998 decf WREG,W ; 0-4
heinrichsweikamp
parents:
diff changeset
999 movwf hi ; Save tested gas 0-4
heinrichsweikamp
parents:
diff changeset
1000 lfsr FSR1,char_I_deco_gas_change
heinrichsweikamp
parents:
diff changeset
1001 movff PLUSW1,lo ; Change depth into lo
heinrichsweikamp
parents:
diff changeset
1002 movlw minimum_change_depth
heinrichsweikamp
parents:
diff changeset
1003 cpfsgt lo ; Change depth>minimum_change_depth?
heinrichsweikamp
parents:
diff changeset
1004 return ; No, Change depth not deep enough, skip!
heinrichsweikamp
parents:
diff changeset
1005 movf xC+0,W ; load depth in m into WREG
heinrichsweikamp
parents:
diff changeset
1006 cpfsgt lo ; gas_change_depth < current depth?
heinrichsweikamp
parents:
diff changeset
1007 return ; No, check next gas
heinrichsweikamp
parents:
diff changeset
1008 incf hi,W ; 1-5
heinrichsweikamp
parents:
diff changeset
1009 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available
heinrichsweikamp
parents:
diff changeset
1010 movlw better_gas_window
heinrichsweikamp
parents:
diff changeset
1011 subwf lo,W ; Change depth-better_gas_window
heinrichsweikamp
parents:
diff changeset
1012 cpfslt xC+0 ; current depth<Change depth-better_gas_window?
heinrichsweikamp
parents:
diff changeset
1013 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode
heinrichsweikamp
parents:
diff changeset
1014 return
heinrichsweikamp
parents:
diff changeset
1015
heinrichsweikamp
parents:
diff changeset
1016 check_dil_common: ; With Dil 0-4 in WREG
heinrichsweikamp
parents:
diff changeset
1017 btfsc better_gas_available ; Better Diluent already found?
heinrichsweikamp
parents:
diff changeset
1018 return ; Yes, return
heinrichsweikamp
parents:
diff changeset
1019 lfsr FSR1,opt_dil_type ; 0=Disabled, 1=First, 2=Normal
heinrichsweikamp
parents:
diff changeset
1020 tstfsz PLUSW1 ; =0?
heinrichsweikamp
parents:
diff changeset
1021 bra check_dil_common1 ; No
heinrichsweikamp
parents:
diff changeset
1022 return ; Yes, skip inactive diluents for test
heinrichsweikamp
parents:
diff changeset
1023 check_dil_common1:
heinrichsweikamp
parents:
diff changeset
1024 incf WREG,W ; 1-5
heinrichsweikamp
parents:
diff changeset
1025 cpfseq active_gas ; is this diluent currently selected?
heinrichsweikamp
parents:
diff changeset
1026 bra check_dil_common2 ; No
heinrichsweikamp
parents:
diff changeset
1027 return ; Yes, skip test for active diluent
heinrichsweikamp
parents:
diff changeset
1028 check_dil_common2:
heinrichsweikamp
parents:
diff changeset
1029 decf WREG,W ; 0-4
heinrichsweikamp
parents:
diff changeset
1030 movwf hi ; Save tested diluent 0-4
heinrichsweikamp
parents:
diff changeset
1031 lfsr FSR1,char_I_dil_change
heinrichsweikamp
parents:
diff changeset
1032 movff PLUSW1,lo ; Change depth into lo
heinrichsweikamp
parents:
diff changeset
1033 movlw minimum_change_depth
heinrichsweikamp
parents:
diff changeset
1034 cpfsgt lo ; Change depth>minimum_change_depth?
heinrichsweikamp
parents:
diff changeset
1035 return ; No, Change depth not deep enough, skip!
heinrichsweikamp
parents:
diff changeset
1036 movf xC+0,W ; load depth in m into WREG
heinrichsweikamp
parents:
diff changeset
1037 cpfsgt lo ; gas_change_depth < current depth?
heinrichsweikamp
parents:
diff changeset
1038 return ; No, check next gas
heinrichsweikamp
parents:
diff changeset
1039 incf hi,W ; 1-5
heinrichsweikamp
parents:
diff changeset
1040 addlw .5 ; 6-10
heinrichsweikamp
parents:
diff changeset
1041 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available
heinrichsweikamp
parents:
diff changeset
1042 movlw better_gas_window
heinrichsweikamp
parents:
diff changeset
1043 subwf lo,W ; Change depth-better_gas_window
heinrichsweikamp
parents:
diff changeset
1044 cpfslt xC+0 ; current depth<Change depth-better_gas_window?
heinrichsweikamp
parents:
diff changeset
1045 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode
heinrichsweikamp
parents:
diff changeset
1046 return
heinrichsweikamp
parents:
diff changeset
1047
heinrichsweikamp
parents:
diff changeset
1048 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
1049 ; Setup everything to enter divemode.
heinrichsweikamp
parents:
diff changeset
1050 ;
heinrichsweikamp
parents:
diff changeset
1051
heinrichsweikamp
parents:
diff changeset
1052 dive_boot_oc:
heinrichsweikamp
parents:
diff changeset
1053 extern get_first_gas_to_WREG
heinrichsweikamp
parents:
diff changeset
1054 call get_first_gas_to_WREG ; Gets first gas (0-4) into WREG
heinrichsweikamp
parents:
diff changeset
1055 movff WREG,char_I_first_gas ; Copy for compatibility
heinrichsweikamp
parents:
diff changeset
1056 movff WREG,active_gas ; Set for logbook and display
heinrichsweikamp
parents:
diff changeset
1057 rcall setup_gas_registers ; With WREG=Gas 0-4
heinrichsweikamp
parents:
diff changeset
1058 return
heinrichsweikamp
parents:
diff changeset
1059
heinrichsweikamp
parents:
diff changeset
1060 dive_boot_cc:
heinrichsweikamp
parents:
diff changeset
1061 rcall divemode_setup_sensor_values ; setup sensor values
heinrichsweikamp
parents:
diff changeset
1062 TSTOSS opt_ccr_mode ; =0: Fixed SP, =1: Sensor
heinrichsweikamp
parents:
diff changeset
1063 movff char_I_setpoint_cbar+0,char_I_const_ppO2 ; Setup fixed Setpoint (Always start with SP1)
heinrichsweikamp
parents:
diff changeset
1064 extern get_first_dil_to_WREG
heinrichsweikamp
parents:
diff changeset
1065 call get_first_dil_to_WREG ; Gets first gas (0-4) into WREG
heinrichsweikamp
parents:
diff changeset
1066 movff WREG,char_I_first_gas ; Copy for compatibility
heinrichsweikamp
parents:
diff changeset
1067 movff WREG,active_gas ; Set for logbook and display
heinrichsweikamp
parents:
diff changeset
1068 rcall setup_dil_registers ; With WREG=Gas 0-4
heinrichsweikamp
parents:
diff changeset
1069 return
heinrichsweikamp
parents:
diff changeset
1070
heinrichsweikamp
parents:
diff changeset
1071 diveloop_boot:
heinrichsweikamp
parents:
diff changeset
1072 call restart_set_modes_and_flags
heinrichsweikamp
parents:
diff changeset
1073
heinrichsweikamp
parents:
diff changeset
1074 call I2C_sleep_accelerometer ; Stop accelerometer
heinrichsweikamp
parents:
diff changeset
1075 call I2C_sleep_compass ; Stop compass
heinrichsweikamp
parents:
diff changeset
1076
heinrichsweikamp
parents:
diff changeset
1077 clrf WREG
heinrichsweikamp
parents:
diff changeset
1078 movff WREG,max_pressure+0 ; clear some variables
heinrichsweikamp
parents:
diff changeset
1079 movff WREG,max_pressure+1
heinrichsweikamp
parents:
diff changeset
1080
heinrichsweikamp
parents:
diff changeset
1081 bcf use_agf ; Start with normal GF set
heinrichsweikamp
parents:
diff changeset
1082 bcf divemode_menu ; clear divemode menu flag
heinrichsweikamp
parents:
diff changeset
1083 movlw d'1'
heinrichsweikamp
parents:
diff changeset
1084 movwf apnoe_max_pressure+0
heinrichsweikamp
parents:
diff changeset
1085 clrf apnoe_max_pressure+1
heinrichsweikamp
parents:
diff changeset
1086 clrf apnoe_surface_mins
heinrichsweikamp
parents:
diff changeset
1087 clrf apnoe_surface_secs
heinrichsweikamp
parents:
diff changeset
1088 clrf apnoe_mins
heinrichsweikamp
parents:
diff changeset
1089 clrf apnoe_secs
heinrichsweikamp
parents:
diff changeset
1090 clrf divemins+0
heinrichsweikamp
parents:
diff changeset
1091 clrf divemins+1
heinrichsweikamp
parents:
diff changeset
1092 bcf no_more_divesecs ; =1: Do no longer show seconds in divemode
heinrichsweikamp
parents:
diff changeset
1093 bcf divemode_menu_active
heinrichsweikamp
parents:
diff changeset
1094 clrf menupos
heinrichsweikamp
parents:
diff changeset
1095 clrf menupos3 ; Reset to zero (Zero=no custom view)
heinrichsweikamp
parents:
diff changeset
1096 clrf menupos2 ; Reset to zero (Zero=no premenu or simulator task)
heinrichsweikamp
parents:
diff changeset
1097
heinrichsweikamp
parents:
diff changeset
1098 bcf is_bailout ; =1: Bailout
heinrichsweikamp
parents:
diff changeset
1099 btfss FLAG_ccr_mode
heinrichsweikamp
parents:
diff changeset
1100 rcall dive_boot_oc
heinrichsweikamp
parents:
diff changeset
1101 btfsc FLAG_ccr_mode
heinrichsweikamp
parents:
diff changeset
1102 rcall dive_boot_cc
heinrichsweikamp
parents:
diff changeset
1103
heinrichsweikamp
parents:
diff changeset
1104 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode
heinrichsweikamp
parents:
diff changeset
1105 clrf better_gas_number ; Clear better gas register
heinrichsweikamp
parents:
diff changeset
1106
heinrichsweikamp
parents:
diff changeset
1107 clrf samplesecs
heinrichsweikamp
parents:
diff changeset
1108 clrf apnoe_timeout_counter ; timeout in minutes
heinrichsweikamp
parents:
diff changeset
1109 clrf timeout_counter ; takes care of the timeout (Low byte)
heinrichsweikamp
parents:
diff changeset
1110 clrf timeout_counter2 ; takes care of the timeout (High byte)
heinrichsweikamp
parents:
diff changeset
1111 clrf AlarmType ; Clear all alarms
heinrichsweikamp
parents:
diff changeset
1112 bcf event_occured ; clear flag
heinrichsweikamp
parents:
diff changeset
1113 clrf total_divetime_seconds+1
heinrichsweikamp
parents:
diff changeset
1114 clrf average_depth_hold_total+0
heinrichsweikamp
parents:
diff changeset
1115 clrf average_depth_hold_total+1
heinrichsweikamp
parents:
diff changeset
1116 clrf average_depth_hold_total+2
heinrichsweikamp
parents:
diff changeset
1117 clrf average_depth_hold_total+3 ; Clear Non-Resettable Average
heinrichsweikamp
parents:
diff changeset
1118 rcall reset_average1 ; Reset the resettable average depth
heinrichsweikamp
parents:
diff changeset
1119 bcf decostop_active
heinrichsweikamp
parents:
diff changeset
1120 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode
heinrichsweikamp
parents:
diff changeset
1121 call ghostwriter_short_header ; Write short header with divenumber into profile memory
heinrichsweikamp
parents:
diff changeset
1122
heinrichsweikamp
parents:
diff changeset
1123 btfsc simulatormode_active
heinrichsweikamp
parents:
diff changeset
1124 bra diveloop_boot_1
heinrichsweikamp
parents:
diff changeset
1125 ; Normal mode = Surface pressure is the pressure 30mn before dive.
heinrichsweikamp
parents:
diff changeset
1126 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ;copy surfacepressure to deco routine
heinrichsweikamp
parents:
diff changeset
1127 SAFE_2BYTE_COPY last_surfpressure_30min, last_surfpressure ;copy surfacepressure to last_surfpressure for correct depth
heinrichsweikamp
parents:
diff changeset
1128 bra diveloop_boot_2
heinrichsweikamp
parents:
diff changeset
1129
heinrichsweikamp
parents:
diff changeset
1130 diveloop_boot_1:
heinrichsweikamp
parents:
diff changeset
1131 ; Simulator mode: Surface pressure is 1bar.
heinrichsweikamp
parents:
diff changeset
1132 movlw LOW .1000
heinrichsweikamp
parents:
diff changeset
1133 movff WREG,int_I_pres_surface+0 ; LOW copy surfacepressure to deco routine
heinrichsweikamp
parents:
diff changeset
1134 movlw HIGH .1000
heinrichsweikamp
parents:
diff changeset
1135 movff WREG,int_I_pres_surface+1 ; HIGH copy surfacepressure to deco routine
heinrichsweikamp
parents:
diff changeset
1136
heinrichsweikamp
parents:
diff changeset
1137 diveloop_boot_2:
heinrichsweikamp
parents:
diff changeset
1138 SAFE_2BYTE_COPY temperature,minimum_temperature ; Reset Min-Temp registers
heinrichsweikamp
parents:
diff changeset
1139
heinrichsweikamp
parents:
diff changeset
1140 ; Init profile recording parameters
heinrichsweikamp
parents:
diff changeset
1141 movlw samplingrate
heinrichsweikamp
parents:
diff changeset
1142 movwf samplesecs_value ; to avoid EEPROM access in the ISR
heinrichsweikamp
parents:
diff changeset
1143 movlw div_temperature
heinrichsweikamp
parents:
diff changeset
1144 movwf divisor_temperature ; load divisors for profile storage
heinrichsweikamp
parents:
diff changeset
1145 movlw div_deco
heinrichsweikamp
parents:
diff changeset
1146 movwf divisor_deco
heinrichsweikamp
parents:
diff changeset
1147 movlw div_gf
heinrichsweikamp
parents:
diff changeset
1148 movwf divisor_gf
heinrichsweikamp
parents:
diff changeset
1149 movlw div_ppo2_sensors
heinrichsweikamp
parents:
diff changeset
1150 movwf divisor_ppo2_sensors
heinrichsweikamp
parents:
diff changeset
1151 movlw div_decoplan
heinrichsweikamp
parents:
diff changeset
1152 movwf divisor_decoplan
heinrichsweikamp
parents:
diff changeset
1153 movlw div_cns
heinrichsweikamp
parents:
diff changeset
1154 movwf divisor_cns
heinrichsweikamp
parents:
diff changeset
1155 movlw div_tank
heinrichsweikamp
parents:
diff changeset
1156 movwf divisor_tank
heinrichsweikamp
parents:
diff changeset
1157
heinrichsweikamp
parents:
diff changeset
1158 btfss FLAG_apnoe_mode ; In Apnoe mode?
heinrichsweikamp
parents:
diff changeset
1159 bra divemode1
heinrichsweikamp
parents:
diff changeset
1160 ; Overwrite some parameters in Apnoe mode....
heinrichsweikamp
parents:
diff changeset
1161 movlw samplingrate_apnoe
heinrichsweikamp
parents:
diff changeset
1162 movwf samplesecs_value ; to avoid EEPROM access in the ISR
heinrichsweikamp
parents:
diff changeset
1163
heinrichsweikamp
parents:
diff changeset
1164 divemode1:
heinrichsweikamp
parents:
diff changeset
1165 bcf LEDg
heinrichsweikamp
parents:
diff changeset
1166 bcf LEDr
heinrichsweikamp
parents:
diff changeset
1167 bcf realdive
heinrichsweikamp
parents:
diff changeset
1168 btfss simulatormode_active ; do not disable in simulator mode!
heinrichsweikamp
parents:
diff changeset
1169 call disable_rs232 ; Disable RS232
heinrichsweikamp
parents:
diff changeset
1170 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
heinrichsweikamp
parents:
diff changeset
1171 call enable_rs232 ; Also sets to speed_normal ...
heinrichsweikamp
parents:
diff changeset
1172 movlw .2
heinrichsweikamp
parents:
diff changeset
1173 movwf total_divetime_seconds+0
heinrichsweikamp
parents:
diff changeset
1174 movwf divesecs ; Start at 2seconds
heinrichsweikamp
parents:
diff changeset
1175 bsf divemode2 ; displayed divetime is running (Divetime starts HERE)
heinrichsweikamp
parents:
diff changeset
1176
heinrichsweikamp
parents:
diff changeset
1177 movff int_O_CNS_fraction+0,CNS_start+0
heinrichsweikamp
parents:
diff changeset
1178 movff int_O_CNS_fraction+1,CNS_start+1 ; Save CNS value at beginning of dive
heinrichsweikamp
parents:
diff changeset
1179 movff char_O_relative_gradient_GF,GF_start ; Save GF value at beginning of dive
heinrichsweikamp
parents:
diff changeset
1180 return ; Done with divemode boot
heinrichsweikamp
parents:
diff changeset
1181
heinrichsweikamp
parents:
diff changeset
1182 divemode_check_for_warnings:
heinrichsweikamp
parents:
diff changeset
1183 btfss secs,1 ; Every four seconds
heinrichsweikamp
parents:
diff changeset
1184 return
heinrichsweikamp
parents:
diff changeset
1185
heinrichsweikamp
parents:
diff changeset
1186 movf warning_counter_backup,W
heinrichsweikamp
parents:
diff changeset
1187 cpfseq warning_counter ; warning_counter_backup = warning_counter?
heinrichsweikamp
parents:
diff changeset
1188 call TFT_clear_warning_text ; No, clear all warnings
heinrichsweikamp
parents:
diff changeset
1189 movff warning_counter,warning_counter_backup ; copy warning_counter
heinrichsweikamp
parents:
diff changeset
1190
heinrichsweikamp
parents:
diff changeset
1191 bcf warning_active ; Clear flag
heinrichsweikamp
parents:
diff changeset
1192 clrf warning_counter ; Clear counter
heinrichsweikamp
parents:
diff changeset
1193
heinrichsweikamp
parents:
diff changeset
1194 ; Warnings for all modes
heinrichsweikamp
parents:
diff changeset
1195 call check_warn_battery ; Check if the battery level should be displayed/warned
heinrichsweikamp
parents:
diff changeset
1196
heinrichsweikamp
parents:
diff changeset
1197 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode
heinrichsweikamp
parents:
diff changeset
1198 bra divemode_check_for_warnings2
heinrichsweikamp
parents:
diff changeset
1199 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode
heinrichsweikamp
parents:
diff changeset
1200 bra divemode_check_for_warnings2
heinrichsweikamp
parents:
diff changeset
1201
heinrichsweikamp
parents:
diff changeset
1202 ; Warnings only in deco modes
heinrichsweikamp
parents:
diff changeset
1203 btfss FLAG_ccr_mode ; Don't check in CCR mode
heinrichsweikamp
parents:
diff changeset
1204 rcall check_ppO2 ; check ppO2 and displays warning, if required
heinrichsweikamp
parents:
diff changeset
1205 btfsc is_bailout ; But check in Bailout case...
heinrichsweikamp
parents:
diff changeset
1206 rcall check_ppO2 ; check ppO2 and displays warning, if required
heinrichsweikamp
parents:
diff changeset
1207 rcall check_cns_violation ; Check CNS value and display it, if required
heinrichsweikamp
parents:
diff changeset
1208 btfsc decostop_active ; In deco mode?
heinrichsweikamp
parents:
diff changeset
1209 rcall check_and_store_gf_violation ; Yes, Sets warnings, if required
heinrichsweikamp
parents:
diff changeset
1210 btfsc decostop_active ; In deco mode?
heinrichsweikamp
parents:
diff changeset
1211 call TFT_ftts ; Show @+x time
heinrichsweikamp
parents:
diff changeset
1212 btfsc use_agf ; In aGF mode?
heinrichsweikamp
parents:
diff changeset
1213 rcall warn_agf ; Yes, show a warning for it
heinrichsweikamp
parents:
diff changeset
1214
heinrichsweikamp
parents:
diff changeset
1215 divemode_check_for_warnings2:
heinrichsweikamp
parents:
diff changeset
1216 ; Display the warning icon?
heinrichsweikamp
parents:
diff changeset
1217 btfsc warning_active ; Any warning active?
heinrichsweikamp
parents:
diff changeset
1218 call TFT_divemode_warning ; Yes
heinrichsweikamp
parents:
diff changeset
1219 btfss warning_active ; Any warning active?
heinrichsweikamp
parents:
diff changeset
1220 call TFT_divemode_warning_clear ; No, clear warning icon
heinrichsweikamp
parents:
diff changeset
1221
heinrichsweikamp
parents:
diff changeset
1222 ; Setup warning_page number
heinrichsweikamp
parents:
diff changeset
1223 incf warning_page,F
heinrichsweikamp
parents:
diff changeset
1224 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
1225 rlcf warning_page,W ; *2
heinrichsweikamp
parents:
diff changeset
1226 cpfsgt warning_counter ; > warning_counter
heinrichsweikamp
parents:
diff changeset
1227 clrf warning_page ; No, clear
heinrichsweikamp
parents:
diff changeset
1228
heinrichsweikamp
parents:
diff changeset
1229 ; Clear 2nd row of warnings if there is nothing to show (on this page)
heinrichsweikamp
parents:
diff changeset
1230 btfss second_row_warning ; =1: The second row contains a warning
heinrichsweikamp
parents:
diff changeset
1231 call TFT_clear_warning_text_2nd_row ; No, clear this row
heinrichsweikamp
parents:
diff changeset
1232 return ; Done.
heinrichsweikamp
parents:
diff changeset
1233
heinrichsweikamp
parents:
diff changeset
1234 global check_warn_battery
heinrichsweikamp
parents:
diff changeset
1235 check_warn_battery:
heinrichsweikamp
parents:
diff changeset
1236 movff batt_percent,lo
heinrichsweikamp
parents:
diff changeset
1237 movlw battery_show_level+1
heinrichsweikamp
parents:
diff changeset
1238 cpfslt lo
heinrichsweikamp
parents:
diff changeset
1239 return ; No Display, no warning
heinrichsweikamp
parents:
diff changeset
1240 ; Display Battery, but warn?
heinrichsweikamp
parents:
diff changeset
1241 incf warning_counter,F ; increase counter
heinrichsweikamp
parents:
diff changeset
1242 call TFT_update_batt_percent_divemode ; Show percent
heinrichsweikamp
parents:
diff changeset
1243
heinrichsweikamp
parents:
diff changeset
1244 movlw color_code_battery_low+1
heinrichsweikamp
parents:
diff changeset
1245 cpfslt lo ;
heinrichsweikamp
parents:
diff changeset
1246 return ; No warning
heinrichsweikamp
parents:
diff changeset
1247 bsf warning_active ; Set Warning flag
heinrichsweikamp
parents:
diff changeset
1248 return
heinrichsweikamp
parents:
diff changeset
1249
heinrichsweikamp
parents:
diff changeset
1250 check_ppO2: ; check current ppO2 and display warning if required
heinrichsweikamp
parents:
diff changeset
1251 SAFE_2BYTE_COPY amb_pressure, xA
heinrichsweikamp
parents:
diff changeset
1252 movlw d'10'
heinrichsweikamp
parents:
diff changeset
1253 movwf xB+0
heinrichsweikamp
parents:
diff changeset
1254 clrf xB+1
heinrichsweikamp
parents:
diff changeset
1255 call div16x16 ; xC=p_amb/10
heinrichsweikamp
parents:
diff changeset
1256
heinrichsweikamp
parents:
diff changeset
1257 movff xC+0,xA+0
heinrichsweikamp
parents:
diff changeset
1258 movff xC+1,xA+1
heinrichsweikamp
parents:
diff changeset
1259 movff char_I_O2_ratio,xB+0 ; =O2 ratio
heinrichsweikamp
parents:
diff changeset
1260 clrf xB+1
heinrichsweikamp
parents:
diff changeset
1261 call mult16x16 ; char_I_O2_ratio * p_amb/10
heinrichsweikamp
parents:
diff changeset
1262
heinrichsweikamp
parents:
diff changeset
1263 ; Check very high ppO2 manually
heinrichsweikamp
parents:
diff changeset
1264 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar?
heinrichsweikamp
parents:
diff changeset
1265 bra check_ppO2_1 ; Yes, display Value!
heinrichsweikamp
parents:
diff changeset
1266 ; Check if ppO2>3,30bar
heinrichsweikamp
parents:
diff changeset
1267 btfsc xC+1,7
heinrichsweikamp
parents:
diff changeset
1268 bra check_ppO2_1 ; Yes!
heinrichsweikamp
parents:
diff changeset
1269
heinrichsweikamp
parents:
diff changeset
1270 ; Check for low ppo2
heinrichsweikamp
parents:
diff changeset
1271 movff xC+0,sub_b+0
heinrichsweikamp
parents:
diff changeset
1272 movff xC+1,sub_b+1
heinrichsweikamp
parents:
diff changeset
1273 movff opt_ppO2_min,WREG
heinrichsweikamp
parents:
diff changeset
1274 mullw d'100' ; opt_ppO2_min*100
heinrichsweikamp
parents:
diff changeset
1275 movff PRODL,sub_a+0
heinrichsweikamp
parents:
diff changeset
1276 movff PRODH,sub_a+1
heinrichsweikamp
parents:
diff changeset
1277 call subU16
heinrichsweikamp
parents:
diff changeset
1278 btfsc neg_flag
heinrichsweikamp
parents:
diff changeset
1279 bra check_ppO2_0 ; Not too low
heinrichsweikamp
parents:
diff changeset
1280 ; ppO2 low
heinrichsweikamp
parents:
diff changeset
1281 incf warning_counter,F ; increase counter
heinrichsweikamp
parents:
diff changeset
1282 call TFT_display_ppo2 ; Show ppO2
heinrichsweikamp
parents:
diff changeset
1283 movlw d'4' ; Type of Alarm (ppO2 low)
heinrichsweikamp
parents:
diff changeset
1284 movwf AlarmType ; Copy to Alarm Register
heinrichsweikamp
parents:
diff changeset
1285 bsf event_occured ; Set Event Flag
heinrichsweikamp
parents:
diff changeset
1286 bsf warning_active ; Set Warning flag
heinrichsweikamp
parents:
diff changeset
1287 return ; Done.
heinrichsweikamp
parents:
diff changeset
1288
heinrichsweikamp
parents:
diff changeset
1289 check_ppO2_0:
heinrichsweikamp
parents:
diff changeset
1290 ; Check if ppO2 should be displayed
heinrichsweikamp
parents:
diff changeset
1291 movlw ppo2_display_high
heinrichsweikamp
parents:
diff changeset
1292 mullw d'100' ; ppo2_display_high*100
heinrichsweikamp
parents:
diff changeset
1293 movff PRODL,sub_a+0
heinrichsweikamp
parents:
diff changeset
1294 movff PRODH,sub_a+1
heinrichsweikamp
parents:
diff changeset
1295 call subU16
heinrichsweikamp
parents:
diff changeset
1296 btfss neg_flag
heinrichsweikamp
parents:
diff changeset
1297 return ; No Display, no warning
heinrichsweikamp
parents:
diff changeset
1298 ; Display ppO2, but warn?
heinrichsweikamp
parents:
diff changeset
1299 incf warning_counter,F ; increase counter
heinrichsweikamp
parents:
diff changeset
1300 call TFT_display_ppo2 ; Show ppO2
heinrichsweikamp
parents:
diff changeset
1301
heinrichsweikamp
parents:
diff changeset
1302 ;check if we are within our warning thresholds!
heinrichsweikamp
parents:
diff changeset
1303 movff xC+0,sub_b+0
heinrichsweikamp
parents:
diff changeset
1304 movff xC+1,sub_b+1
heinrichsweikamp
parents:
diff changeset
1305 movff opt_ppO2_max,WREG ; PPO2 Max for MOD calculation and color coding in divemode
heinrichsweikamp
parents:
diff changeset
1306 mullw d'100' ; opt_ppO2_max*100
heinrichsweikamp
parents:
diff changeset
1307 movff PRODL,sub_a+0
heinrichsweikamp
parents:
diff changeset
1308 movff PRODH,sub_a+1
heinrichsweikamp
parents:
diff changeset
1309 call subU16
heinrichsweikamp
parents:
diff changeset
1310 btfss neg_flag
heinrichsweikamp
parents:
diff changeset
1311 return ; Done. Not too high
heinrichsweikamp
parents:
diff changeset
1312 movlw d'5' ; Type of Alarm (ppO2 high)
heinrichsweikamp
parents:
diff changeset
1313 movwf AlarmType ; Copy to Alarm Register
heinrichsweikamp
parents:
diff changeset
1314 bsf event_occured ; Set Event Flag
heinrichsweikamp
parents:
diff changeset
1315 bsf warning_active ; Set Warning flag
heinrichsweikamp
parents:
diff changeset
1316 return ; Done.
heinrichsweikamp
parents:
diff changeset
1317
heinrichsweikamp
parents:
diff changeset
1318 check_ppO2_1: ; ppO2 very high
heinrichsweikamp
parents:
diff changeset
1319 incf warning_counter,F ; increase counter
heinrichsweikamp
parents:
diff changeset
1320 call TFT_display_ppo2 ; Show ppO2
heinrichsweikamp
parents:
diff changeset
1321 movlw d'5' ; Type of Alarm
heinrichsweikamp
parents:
diff changeset
1322 movwf AlarmType ; Copy to Alarm Register
heinrichsweikamp
parents:
diff changeset
1323 bsf event_occured ; Set Event Flag
heinrichsweikamp
parents:
diff changeset
1324 bsf warning_active ; Set Warning flag
heinrichsweikamp
parents:
diff changeset
1325 return ; Done.
heinrichsweikamp
parents:
diff changeset
1326
heinrichsweikamp
parents:
diff changeset
1327 global check_cns_violation
heinrichsweikamp
parents:
diff changeset
1328 check_cns_violation:
heinrichsweikamp
parents:
diff changeset
1329 ; Check if CNS should be displayed
heinrichsweikamp
parents:
diff changeset
1330 movff int_O_CNS_fraction+1,lo ; copy into bank1
heinrichsweikamp
parents:
diff changeset
1331 tstfsz lo ; >255% ?
heinrichsweikamp
parents:
diff changeset
1332 bra check_cns_violation2 ; Yes
heinrichsweikamp
parents:
diff changeset
1333 movff int_O_CNS_fraction+0,lo ; copy into bank1
heinrichsweikamp
parents:
diff changeset
1334
heinrichsweikamp
parents:
diff changeset
1335 movlw cns_warning_high ; cns_warning_high
heinrichsweikamp
parents:
diff changeset
1336 subwf lo,W
heinrichsweikamp
parents:
diff changeset
1337 btfsc STATUS,C
heinrichsweikamp
parents:
diff changeset
1338 bsf warning_active ; Set Warning flag
heinrichsweikamp
parents:
diff changeset
1339
heinrichsweikamp
parents:
diff changeset
1340 movlw cns_display_high ; cns_display_high
heinrichsweikamp
parents:
diff changeset
1341 subwf lo,W
heinrichsweikamp
parents:
diff changeset
1342 btfss STATUS,C
heinrichsweikamp
parents:
diff changeset
1343 return ; No Display, no warning
heinrichsweikamp
parents:
diff changeset
1344 ; Display CNS
heinrichsweikamp
parents:
diff changeset
1345 incf warning_counter,F ; increase counter
heinrichsweikamp
parents:
diff changeset
1346 call TFT_display_cns ; Show CNS
heinrichsweikamp
parents:
diff changeset
1347 return
heinrichsweikamp
parents:
diff changeset
1348
heinrichsweikamp
parents:
diff changeset
1349 check_cns_violation2:
heinrichsweikamp
parents:
diff changeset
1350 incf warning_counter,F ; increase counter
heinrichsweikamp
parents:
diff changeset
1351 call TFT_display_cns ; Show CNS
heinrichsweikamp
parents:
diff changeset
1352 bsf warning_active ; Set Warning flag
heinrichsweikamp
parents:
diff changeset
1353 return
heinrichsweikamp
parents:
diff changeset
1354
heinrichsweikamp
parents:
diff changeset
1355 global check_and_store_gf_violation
heinrichsweikamp
parents:
diff changeset
1356 check_and_store_gf_violation:
heinrichsweikamp
parents:
diff changeset
1357 movff char_O_gradient_factor,lo ; gradient factor absolute (Non-GF model)
heinrichsweikamp
parents:
diff changeset
1358 movff char_I_deco_model,hi
heinrichsweikamp
parents:
diff changeset
1359 decfsz hi,F ; jump over next line if char_I_deco_model == 1
heinrichsweikamp
parents:
diff changeset
1360 movff char_O_relative_gradient_GF,lo ; gradient factor relative (GF model)
heinrichsweikamp
parents:
diff changeset
1361
heinrichsweikamp
parents:
diff changeset
1362 movlw gf_warning_high
heinrichsweikamp
parents:
diff changeset
1363 cpfsgt lo
heinrichsweikamp
parents:
diff changeset
1364 bra check_and_store_gf_violation2 ; No warning
heinrichsweikamp
parents:
diff changeset
1365 movlw d'2' ; Type of Alarm
heinrichsweikamp
parents:
diff changeset
1366 movwf AlarmType ; Copy to Alarm Register
heinrichsweikamp
parents:
diff changeset
1367 bsf event_occured ; Set Event Flag
heinrichsweikamp
parents:
diff changeset
1368 bsf warning_active ; Set Warning flag
heinrichsweikamp
parents:
diff changeset
1369 check_and_store_gf_violation2:
heinrichsweikamp
parents:
diff changeset
1370 movlw gf_display_high
heinrichsweikamp
parents:
diff changeset
1371 cpfsgt lo
heinrichsweikamp
parents:
diff changeset
1372 return ; No Display, no warning
heinrichsweikamp
parents:
diff changeset
1373 ; Display GF
heinrichsweikamp
parents:
diff changeset
1374 incf warning_counter,F ; increase counter
heinrichsweikamp
parents:
diff changeset
1375 call TFT_warning_gf ; Show GF Warning
heinrichsweikamp
parents:
diff changeset
1376 return
heinrichsweikamp
parents:
diff changeset
1377
heinrichsweikamp
parents:
diff changeset
1378 warn_agf:
heinrichsweikamp
parents:
diff changeset
1379 incf warning_counter,F ; increase counter
heinrichsweikamp
parents:
diff changeset
1380 call TFT_warning_agf ; Show aGF warning
heinrichsweikamp
parents:
diff changeset
1381 bsf warning_active ; Set Warning flag
heinrichsweikamp
parents:
diff changeset
1382 return
heinrichsweikamp
parents:
diff changeset
1383
heinrichsweikamp
parents:
diff changeset
1384
heinrichsweikamp
parents:
diff changeset
1385 END