comparison src/surfmode.asm @ 560:b7eb98dbd800

bump to 2.96beta (REFACTORED VERSION)
author heinrichsweikamp
date Wed, 31 Jan 2018 19:39:37 +0100
parents cf68fe0c3002
children 54346c651b6a
comparison
equal deleted inserted replaced
559:9cb967d844f0 560:b7eb98dbd800
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File surfmode.asm 3 ; File surfmode.asm REFACTORED VERSION V2.94
4 ; 4 ;
5 ; Surfacemode 5 ; Surfacemode
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
9 ; HISTORY 9 ; HISTORY
10 ; 2011-08-07 : [mH] moving from OSTC code 10 ; 2011-08-07 : [mH] moving from OSTC code
11 11
12 #include "hwos.inc" ; Mandatory header 12 #include "hwos.inc" ; Mandatory header
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c 13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c
14 #include "start.inc" 14 #include "start.inc"
15 #include "tft.inc" 15 #include "tft.inc"
16 #include "tft_outputs.inc" 16 #include "tft_outputs.inc"
17 #include "isr.inc" 17 #include "isr.inc"
41 41
42 ;============================================================================= 42 ;=============================================================================
43 ; Boot tasks for all modes 43 ; Boot tasks for all modes
44 global surfloop 44 global surfloop
45 surfloop: 45 surfloop:
46 call speed_normal 46 call speed_normal
47 bcf no_sensor_int ; Normal pressure mode 47 bcf no_sensor_int ; Normal pressure mode
48 48
49 bcf LEDg
50 bcf LEDr 49 bcf LEDr
51 50
52 clrf CCP1CON ; stop PWM 51 clrf CCP1CON ; stop PWM
53 bcf PORTC,2 ; Pull PWM output to GND 52 bcf PORTC,2 ; Pull PWM output to GND
54 call TFT_boot ; Initialize TFT (includes clear screen) 53 call TFT_boot ; Initialize TFT (includes clear screen)
55 bcf restore_deco_data 54 bcf restore_deco_data
56 55
57 WIN_TOP .50 56 WIN_TOP .50
58 WIN_LEFT .10 57 WIN_LEFT .10
59 movlw LOW 0x1E000 58 movlw LOW 0x1E000
60 movwf TBLPTRL 59 movwf TBLPTRL
98 clrf last_pressure+1 97 clrf last_pressure+1
99 bcf is_bailout ; =1: Bailout 98 bcf is_bailout ; =1: Bailout
100 bcf ccr_diluent_setup ; Use OC gases for gaslist routine 99 bcf ccr_diluent_setup ; Use OC gases for gaslist routine
101 100
102 bcf simulatormode_active ; Quit simulator mode (if active) 101 bcf simulatormode_active ; Quit simulator mode (if active)
103 bcf switch_left 102
104 bcf switch_right 103 ; MOVE from here to below ## V2.94
104 ; bcf switch_left
105 ; bcf switch_right
105 106
106 ;---- Fade to standard surface view -------------------------------------- 107 ;---- Fade to standard surface view --------------------------------------
107 ; Wait 1 second 108 ; Wait 1 second
108 bcf onesecupdate 109 bcf onesecupdate
109 btfss onesecupdate 110 btfss onesecupdate
143 call get_battery_voltage ; get battery voltage 144 call get_battery_voltage ; get battery voltage
144 call TFT_update_batt_voltage ; display battery voltage 145 call TFT_update_batt_voltage ; display battery voltage
145 call TFT_update_surf_press ; display surface pressure 146 call TFT_update_surf_press ; display surface pressure
146 call TFT_temp_surfmode ; Displays temperature 147 call TFT_temp_surfmode ; Displays temperature
147 call TFT_display_decotype_surface 148 call TFT_display_decotype_surface
148 call compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays 149
149 call check_sensors ; Set enable/disable flags 150 ; REPLACE ## voting logic
151 ; call compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays
152 ; call check_sensors ; Set enable/disable flags
153 ; BY
154 call calc_deko_divemode_sensor
150 155
151 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR 156 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR
152 tstfsz lo 157 tstfsz lo
153 bra surfloop_no_oc ; Not OC 158 bra surfloop_no_oc ; Not OC
154 call TFT_show_OC_startgas_surface; Show first gas and "OSTC2-like" active gases 159 call TFT_show_OC_startgas_surface; Show first gas and "OSTC2-like" active gases
156 movff customview_surfmode,menupos3 ; Reload last customview 161 movff customview_surfmode,menupos3 ; Reload last customview
157 call surf_customview_mask ; Update #menupos3 view 162 call surf_customview_mask ; Update #menupos3 view
158 163
159 call TFT_Display_FadeIn ; Display resulting surface screen. 164 call TFT_Display_FadeIn ; Display resulting surface screen.
160 165
166 ; MOVED from above to here ## V2.94
167 bcf switch_left
168 bcf switch_right
169
161 ;---- Late initialisations ----------------------------------------------- 170 ;---- Late initialisations -----------------------------------------------
162 movff last_surfpressure_30min+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine 171 movff last_surfpressure_30min+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine ## not used any more (!?)
163 movff last_surfpressure_30min+1,int_I_pres_respiration+1 ; 30min old values 172 movff last_surfpressure_30min+1,int_I_pres_respiration+1 ; 30min old values ## not used any more (!?)
164 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine 173 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine
165 movff last_surfpressure_30min+1,int_I_pres_surface+1 ; 30min old values 174 movff last_surfpressure_30min+1,int_I_pres_surface+1 ; 30min old values
166 movff last_surfpressure_30min+0,last_surfpressure+0 ; Use 30min old airpressure 175 movff last_surfpressure_30min+0,last_surfpressure+0 ; Use 30min old airpressure
167 movff last_surfpressure_30min+1,last_surfpressure+1 ; Use 30min old airpressure 176 movff last_surfpressure_30min+1,last_surfpressure+1 ; Use 30min old airpressure
168 177
178 ; NEW ## no fly
179 movff opt_GF_low,char_I_GF_Low_percentage
180 movff opt_GF_high,char_I_GF_High_percentage
181
169 ; Startup tasks for all modes 182 ; Startup tasks for all modes
170 ; Desaturation time needs: 183 ; Desaturation time needs:
171 ; int_I_pres_surface 184 ; int_I_pres_surface
172 ; char_I_desaturation_multiplier 185 ; char_I_desaturation_multiplier
173 call deco_calc_desaturation_time ; calculate desaturation time 186 call deco_calc_desaturation_time ; calculate desaturation time
174 movlb b'00000001' ; select ram bank 1 187
188 ; REPLACE ## (code unification)
189 ; movlb b'00000001' ; select ram bank 1
190 ; BY
191 banksel common
175 192
176 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) 193 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
177 call enable_rs232 ; Also sets to speed_normal ... 194 call enable_rs232 ; Also sets to speed_normal ...
178 195
179 surfloop_loop: 196 surfloop_loop:
190 call set_dive_modes ; tests if depth>threshold 207 call set_dive_modes ; tests if depth>threshold
191 btfss secs,0 ; Every two seconds... 208 btfss secs,0 ; Every two seconds...
192 call TFT_temp_surfmode ; Displays temperature 209 call TFT_temp_surfmode ; Displays temperature
193 btfss secs,0 ; Every two seconds... 210 btfss secs,0 ; Every two seconds...
194 call surfmode_check_for_warnings ; ... check for warnings (and display/update) them 211 call surfmode_check_for_warnings ; ... check for warnings (and display/update) them
195
196 bcf onesecupdate ; every second tasks done 212 bcf onesecupdate ; every second tasks done
197 213
198 surfloop_loop2: 214 surfloop_loop2:
199 ; Tasks approx. every 50ms for all modes 215 ; Tasks approx. every 50ms for all modes
200 call test_switches_surfmode ; check switches 216 call test_switches_surfmode ; check switches
220 bra surfloop_loop2b 236 bra surfloop_loop2b
221 237
222 bcf quarter_second_update 238 bcf quarter_second_update
223 239
224 ; Update Sensors 240 ; Update Sensors
225 call compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays 241 ; REPLACE ## voting logic
226 call check_sensors ; Set enable/disable flags 242 ; call compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays
243 ; call check_sensors ; Set enable/disable flags
244 ; BY
245 call calc_deko_divemode_sensor
246
227 btfsc FLAG_ccr_mode ; In CCR mode? 247 btfsc FLAG_ccr_mode ; In CCR mode?
228 bra surfloop_loop2a1 ; Yes. 248 bra surfloop_loop2a1 ; Yes.
229 btfss FLAG_pscr_mode ; In PSCR mode? 249 btfss FLAG_pscr_mode ; In PSCR mode?
230 bra surfloop_loop2a ; No, skip 250 bra surfloop_loop2a ; No, skip
231 251
232 surfloop_loop2a1: 252 surfloop_loop2a1:
233 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 253 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP
234 sublw .1 ; opt_ccr_mode = 1 (Sensor)? 254 sublw .1 ; opt_ccr_mode = 1 (Sensor)?
235 bnz surfloop_loop2a ; No, skip 255 bnz surfloop_loop2a ; No, skip
236 256
237 call TFT_surface_sensor ; ...update sensor data in surface mode 257 call TFT_surface_sensor ; ...update sensor data in surface mode
238 call TFT_sensor_surface_warning ; Show a warning arrow-down behind sensor readings when sensor is end-of-life 258 call TFT_sensor_surface_warning ; Show a warning arrow-down behind sensor readings when sensor is end-of-life
239 movlw .9 259 movlw .9
240 cpfseq menupos3 ; in Sensor mV surface custom view? 260 cpfseq menupos3 ; in Sensor mV surface custom view?
241 bra surfloop_loop2a ; No 261 bra surfloop_loop2a ; No
242 extern TFT_sensor_mV 262 extern TFT_sensor_mV
243 call TFT_sensor_mV ; Yes, update mV readings (Each 1/4 second and not each second as in customview.asm) 263 call TFT_sensor_mV ; Yes, update mV readings (Each 1/4 second and not each second as in customview.asm)
244 264
245 surfloop_loop2a: 265 surfloop_loop2a:
246 movlw .6 266 movlw .6
253 btfsc toggle_customview ; Next view? 273 btfsc toggle_customview ; Next view?
254 call surf_customview_toggle ; Yes, show next customview (and delete this flag) 274 call surf_customview_toggle ; Yes, show next customview (and delete this flag)
255 275
256 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) 276 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
257 bra surfloop_loop3 277 bra surfloop_loop3
258 btfsc vusb_in ; USB plugged in? 278
259 call comm_mode ; Start COMM mode 279 ; DELETE - In surface mode, only charing is available now - but now you can see the charging status :-) ## USB
280 ; To do USB communication, you now need to be in menu or logbook mode
281 ;btfsc vusb_in ; USB plugged in?
282 ;call comm_mode ; Start COMM mode
283
260 bra surfloop_loop4 284 bra surfloop_loop4
261 surfloop_loop3: 285 surfloop_loop3:
262 btfss vusb_in ; USB (still) plugged in? 286 btfss vusb_in ; USB (still) plugged in?
263 bcf enable_screen_dumps ; No, clear flag 287 bcf enable_screen_dumps ; No, clear flag
264 call rs232_get_byte 288 call rs232_get_byte
265 btfsc rs232_recieve_overflow 289 btfsc rs232_recieve_overflow
266 bra surfloop_loop4 290 bra surfloop_loop4
267 movlw "l" 291 movlw "l"
268 cpfseq RCREG1 292 cpfseq RCREG1
269 bra surfloop_loop4 293 bra surfloop_loop4
270 call TFT_dump_screen ; Dump the screen contents 294 call TFT_dump_screen ; Dump the screen contents
271 surfloop_loop4: 295 surfloop_loop4:
272 btfsc sleepmode ; Sleepmode active? 296 btfsc sleepmode ; Sleepmode active?
273 goto sleeploop ; Yes, switch into sleepmode! 297 goto sleeploop ; Yes, switch into sleepmode!
274 298
275 bra surfloop_loop ; loop surfacemode 299 bra surfloop_loop ; loop surfacemode
276 300
277 update_surfloop60: 301 update_surfloop60:
278 ; One minute tasks for all modes 302 ; One minute tasks for all modes
279 call TFT_date ; Update date 303 call TFT_date ; Update date
280 call calc_deko_surfmode ; calculate desaturation every minute 304
305 ; REPLACE ## no fly 2
306 ; call calc_deko_surfmode ; calculate desaturation time every minute
307 ; BY
308 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode. int_I_pres_surface gets updated by
309 call deco_calc_desaturation_time ; TFT_update_surf_press when amb_pressure has changed by >= 10 mbar
310 banksel common
311
312 ; NEW ## deco engine
313 ; update tissue diagram if it is on display
314 movlw .5 ; number of tissue custom view
315 cpfseq menupos3 ; is this the current customview?
316 bra update_surfloop60_1 ; NO
317 call TFT_standard_color ; YES - set standard color
318 call TFT_surface_tissues ; show tissue diagram
319 update_surfloop60_1:
320
321 ; NEW ## no fly
322 ; update last dive info if it is on display
323 movlw .8 ; number of the last dive info customview
324 cpfseq menupos3 ; is this the current customview?
325 bra update_surfloop60_2 ; NO
326 call TFT_standard_color ; YES - set standard color
327 call TFT_surface_lastdive ; show last dive infos
328 update_surfloop60_2:
329
281 bcf oneminupdate 330 bcf oneminupdate
282 return 331 return
283 332
284 extern check_cns_violation,check_warn_battery,check_and_store_gf_violation 333 extern check_cns_violation,check_warn_battery,check_and_store_gf_violation
285 surfmode_check_for_warnings: 334 surfmode_check_for_warnings:
286 movf warning_counter_backup,W 335
287 cpfseq warning_counter ; warning_counter_backup = warning_counter? 336 ; DELETE ## (screen flicker)
288 call TFT_clear_warning_text ; No, clear all warnings 337 ; movf warning_counter_backup,W
289 movff warning_counter,warning_counter_backup ; copy warning_counter 338 ; cpfseq warning_counter ; warning_counter_backup = warning_counter?
339 ; call TFT_clear_warning_text ; No, clear all warnings
340 ; movff warning_counter,warning_counter_backup ; copy warning_counter
290 341
291 bcf warning_active ; Clear flag 342 bcf warning_active ; Clear flag
292 clrf warning_counter ; Clear counter 343 clrf warning_counter ; Clear counter
293 344
294 ; Warnings for all modes 345 ; Warnings for all modes
295 call check_warn_battery ; Check if the battery level should be displayed/warned 346 call check_warn_battery ; Check if the battery level should be displayed/warned
296 rcall surfmode_check_for_nofly ; Check if nofly time should be shown 347
297 rcall surfmode_check_for_desat ; Check if desat time should be shown 348 ; DELETE HERE... ## (general fix)
298 rcall surfmode_check_for_interval ; Check if surface interval should be shown 349 ; rcall surfmode_check_for_nofly ; Check if nofly time should be shown
299 350 ; rcall surfmode_check_for_desat ; Check if desat time should be shown
300 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode 351
352 ; DELETE - surface interval is now shown in last dive custom view, not as "warning" any more ## no fly
353 ; rcall surfmode_check_for_interval ; Check if surface interval should be shown
354
355 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode
301 bra surfmode_check_for_warnings2 356 bra surfmode_check_for_warnings2
302 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode 357 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode
303 bra surfmode_check_for_warnings2 358 bra surfmode_check_for_warnings2
304 359
305 ; Warnings only in deco modes 360 ; Warnings only in deco modes
361
362 ; ...INSERT HERE ## (general fix) - desat and no-fly time belong to deco modes
363 rcall surfmode_check_for_desat ; Check if desat time should be shown
364 rcall surfmode_check_for_nofly ; Check if nofly time should be shown
365
306 call check_cns_violation ; Check CNS value and display it, if required 366 call check_cns_violation ; Check CNS value and display it, if required
307 call check_and_store_gf_violation ; Check GF value and display it, if required 367 call check_and_store_gf_violation ; Check GF value and display it, if required
368
369 ; NEW ## microbubbles
370 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings
371 btfsc WREG,mbubble_warning_lock ; do we have a microbubbles warning?
372 extern warn_mbubbles
373 call warn_mbubbles ; YES
308 374
309 surfmode_check_for_warnings2: 375 surfmode_check_for_warnings2:
310 ; Setup warning_page number 376 ; Setup warning_page number
311 incf warning_page,F 377 incf warning_page,F
312 bcf STATUS,C 378 bcf STATUS,C
313 rlcf warning_page,W ; *2 379 rlcf warning_page,W ; *2
314 cpfsgt warning_counter ; > warning_counter 380 cpfsgt warning_counter ; > warning_counter
315 clrf warning_page ; No, clear 381 clrf warning_page ; No, clear
382
383 ; NEW ## (screen flicker)
384 ; Clear both rows of warnings if there is nothing to show at all
385 tstfsz warning_counter ; any warnings?
386 bra surfmode_check_for_warnings3 ; YES - look if second row needs to be cleared
387 call TFT_clear_warning_text ; NO - clear complete warnings area
388 return
389 surfmode_check_for_warnings3:
316 390
317 ; Clear 2nd row of warnings if there is nothing to show (on this page) 391 ; Clear 2nd row of warnings if there is nothing to show (on this page)
318 btfss second_row_warning ; =1: The second row contains a warning 392 btfss second_row_warning ; =1: The second row contains a warning
319 call TFT_clear_warning_text_2nd_row ; No, clear this row 393 call TFT_clear_warning_text_2nd_row ; No, clear this row
320 return ; Done. 394 return ; Done.
321 395
322 surfmode_check_for_interval: 396 ; DELETE - surface interval is now shown in last dive custom view, not as "warning" any more ## no fly
323 movf surface_interval+0,W ; Is interval null ? 397 ;
324 iorwf surface_interval+1,W 398 ;surfmode_check_for_interval:
325 bnz surfmode_check_for_interval2 ; No 399 ; movf surface_interval+0,W ; Is interval null ?
326 return 400 ; iorwf surface_interval+1,W
327 surfmode_check_for_interval2: 401 ; bnz surfmode_check_for_interval2 ; No
328 incf warning_counter,F ; increase counter 402 ; return
329 call TFT_interval 403 ;surfmode_check_for_interval2:
330 return 404 ; incf warning_counter,F ; increase counter
405 ; call TFT_interval
406 ; return
331 407
332 408
333 surfmode_check_for_desat: 409 surfmode_check_for_desat:
334 movf desaturation_time+0,W ; Is nofly null ? 410 ; REPLACE ## no fly
335 iorwf desaturation_time+1,W 411 ; movf desaturation_time+0,W ; Is nofly null ?
336 bnz surfmode_check_for_desat2 ; No 412 ; iorwf desaturation_time+1,W
337 return 413 ; BY
414 banksel int_O_desaturation_time
415 movf int_O_desaturation_time+0,W ; Is nofly null ?
416 iorwf int_O_desaturation_time+1,W
417
418 bnz surfmode_check_for_desat2 ; No
419
420 ; NEW ## no fly
421 banksel common
422
423 return
424
338 surfmode_check_for_desat2: 425 surfmode_check_for_desat2:
339 incf warning_counter,F ; increase counter 426 ; NEW ## no fly
427 banksel common
428
429 incf warning_counter,F ; increase counter
340 call TFT_desaturation_time 430 call TFT_desaturation_time
341 return 431 return
342 432
343 surfmode_check_for_nofly: 433 surfmode_check_for_nofly:
344 movf nofly_time+0,W ; Is nofly null ? 434 ; REPLACE ## no fly
345 iorwf nofly_time+1,W 435 ; movf nofly_time+0,W ; Is nofly null ?
346 bnz surfmode_check_for_nofly2 ; No... 436 ; iorwf nofly_time+1,W
347 return 437 ; BY
438 banksel int_O_nofly_time
439 movf int_O_nofly_time+0,W ; Is nofly null ?
440 iorwf int_O_nofly_time+1,W
441
442 bnz surfmode_check_for_nofly2 ; No...
443
444 ; NEW ## no fly
445 banksel common
446
447 return
448
348 surfmode_check_for_nofly2: 449 surfmode_check_for_nofly2:
349 incf warning_counter,F ; increase counter 450 ; NEW ## no fly
451 banksel common
452
453 incf warning_counter,F ; increase counter
350 call TFT_nofly_time 454 call TFT_nofly_time
351 return 455 return
352 456
353 457
354 ;============================================================================= 458 ;=============================================================================
355 global calc_deko_surfmode 459
356 calc_deko_surfmode: 460 ; DELETE - not used any more ## no fly
357 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy surface air pressure to deco routine 461 ; global calc_deko_surfmode
358 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode 462 ;calc_deko_surfmode:
359 banksel common 463 ;
360 return 464 ; ; DELETE - deco_calc_wo_deco_step_1_min uses int_I_pres_surface, not int_I_pres_respiration ## no fly
465 ; ; SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy surface air pressure to deco routine
466 ;
467 ; call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode
468 ;
469 ; ; NEW ## no fly
470 ; ; call deco_calc_desaturation_time
471 ;
472 ; banksel common
473 ; return
361 474
362 test_switches_surfmode: ; checks switches in surfacemode 475 test_switches_surfmode: ; checks switches in surfacemode
363 btfsc switch_right 476 btfsc switch_right
364 bra test_switches_surfmode2 477 bra test_switches_surfmode2
365 btfsc switch_left 478 btfsc switch_left
381 bcf switch_left 494 bcf switch_left
382 return 495 return
383 496
384 test_switches_surfmode3a: 497 test_switches_surfmode3a:
385 bcf switch_left 498 bcf switch_left
386 bsf menubit ; Enter Menu! 499 bsf menubit ; Enter Menu!
387 return 500 return
388 501
389 test_switches_surfmode3b: 502 test_switches_surfmode3b:
390 ; Clear "Heading?" 503 ; Clear "Heading?"
391 WIN_BOX_BLACK .158,.190, .15, .99 ; top, bottom, left, right 504 WIN_BOX_BLACK .158,.190, .15, .99 ; top, bottom, left, right