comparison src/divemode.asm @ 640:8c1f1f334275

3.13 release
author heinrichsweikamp
date Thu, 29 Oct 2020 09:29:15 +0100
parents 9a64914a8fca
children 7d8a4c60ec1a 5b7fe7777425
comparison
equal deleted inserted replaced
639:0ff82370991d 640:8c1f1f334275
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File divemode.asm * combined next generation V3.09.5 3 ; File divemode.asm * combined next generation V3.12.3
4 ; 4 ;
5 ; Dive Mode 5 ; Dive Mode
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
309 MOVII mpr, xA ; copy depth in [cm] into xA 309 MOVII mpr, xA ; copy depth in [cm] into xA
310 MOVLI .100,xB ; load factor 100 cm/m into xB 310 MOVLI .100,xB ; load factor 100 cm/m into xB
311 call div16x16 ; xC = xA / xB = depth in full meters 311 call div16x16 ; xC = xA / xB = depth in full meters
312 movff xC+0,depth_meter ; store result as depth in [m], only low byte needed 312 movff xC+0,depth_meter ; store result as depth in [m], only low byte needed
313 313
314 IFDEF _ccr_pscr
315 ; adjust auto-setpoint
316 btfsc FLAG_ccr_mode ; in CCR mode?
317 call check_dive_autosp ; YES - check for Auto-SP
318 ENDIF
319
320 ; check for new max pressure 314 ; check for new max pressure
321 btfss trigger_pres_max_changed ; has the max pressure changed? 315 btfss trigger_pres_max_changed ; has the max pressure changed?
322 bra diveloop_loop_4 ; NO - continue with tasks every 1/1 second 316 bra diveloop_loop_4 ; NO - continue with tasks every 1/1 second
323 bcf trigger_pres_max_changed ; YES - clear flag for new max pressure 317 bcf trigger_pres_max_changed ; YES - clear flag for new max pressure
324 bsf FLAG_TFT_depth_maximum ; - set flag for displaying new max depth 318 bsf FLAG_TFT_depth_maximum ; - set flag for displaying new max depth
325 SMOVII pressure_rel_max,pressure_rel_max_cached ; - cache new max depth 319 SMOVII pressure_rel_max,pressure_rel_max_cached ; - cache new max depth
326 320
327 diveloop_loop_4: 321 diveloop_loop_4:
328 ; continue tasks every 1/1 second 322 ; continue tasks every 1/1 second
323
324 IFDEF _ccr_pscr
325 ; adjust auto-setpoint
326 btfsc FLAG_ccr_mode ; in CCR mode?
327 call check_dive_autosp ; YES - check for Auto-SP
328 ENDIF
329 329
330 IFDEF _external_sensor 330 IFDEF _external_sensor
331 btfsc FLAG_ccr_mode ; in CCR mode? 331 btfsc FLAG_ccr_mode ; in CCR mode?
332 rcall calc_deko_divemode_sensor ; YES - process sensor readings 332 rcall calc_deko_divemode_sensor ; YES - process sensor readings
333 btfsc FLAG_pscr_mode ; in pSCR mode? 333 btfsc FLAG_pscr_mode ; in pSCR mode?
1159 btfsc FLAG_pscr_mode ; check if we are in pSCR mode 1159 btfsc FLAG_pscr_mode ; check if we are in pSCR mode
1160 movff WREG,char_I_const_ppO2 ; YES - write 0 to char_I_const_ppo2, 1160 movff WREG,char_I_const_ppO2 ; YES - write 0 to char_I_const_ppo2,
1161 ; it will be overwritten if we have a usable sensor reading 1161 ; it will be overwritten if we have a usable sensor reading
1162 btfsc bailout_mode ; check if we are in bailout 1162 btfsc bailout_mode ; check if we are in bailout
1163 bra check_sensor_vote ; YES - no sensor data transfer to char_I_const_ppO2 in this case 1163 bra check_sensor_vote ; YES - no sensor data transfer to char_I_const_ppO2 in this case
1164 movff opt_ccr_mode,WREG ; NO - get mode (0: Fixed SP, 1: Sensor, 2: Auto SP) 1164 movf dive_ccr_mode,W ; NO - get mode (0: Fixed SP, 1: Sensor, 2: Auto SP)
1165 sublw .1 ; - in sensor mode? 1165 sublw .1 ; - in sensor mode?
1166 bnz check_sensor_vote ; NO - not in sensor mode - no transfer of sensor data to char_I_const_ppO2 1166 bnz check_sensor_vote ; NO - not in sensor mode - no transfer of sensor data to char_I_const_ppO2
1167 tstfsz xB+0 ; YES - check if we have found at least one usable sensor 1167 tstfsz xB+0 ; YES - check if we have found at least one usable sensor
1168 bra check_sensor_avg_use ; YES - we have at least one usable sensor 1168 bra check_sensor_avg_use ; YES - we have at least one usable sensor
1169 bsf warn_det_sensors_lost ; NO - we have NO usable sensors 1169 bsf warn_det_sensors_lost ; NO - we have NO usable sensors
1205 bra check_warn_sensor_done ; not in CCR and not in pSCR, so no warning 1205 bra check_warn_sensor_done ; not in CCR and not in pSCR, so no warning
1206 1206
1207 check_warn_sensor_0: ; we are in CCR or pSCR mode 1207 check_warn_sensor_0: ; we are in CCR or pSCR mode
1208 btfsc bailout_mode ; check if we are in bailout 1208 btfsc bailout_mode ; check if we are in bailout
1209 bra check_warn_sensor_done ; YES - no warning in this case 1209 bra check_warn_sensor_done ; YES - no warning in this case
1210 movff opt_ccr_mode,WREG ; get mode (0: Fixed SP, 1: Sensor, 2: Auto SP) 1210 movf dive_ccr_mode,W ; get mode (0: Fixed SP, 1: Sensor, 2: Auto SP)
1211 sublw .1 ; in sensor mode? 1211 sublw .1 ; in sensor mode?
1212 bnz check_warn_sensor_done ; NO - not in sensor mode - no warning in this case 1212 bnz check_warn_sensor_done ; NO - not in sensor mode - no warning in this case
1213 1213
1214 check_warn_sensor_1: 1214 check_warn_sensor_1:
1215 btfss sensor1_calibrated_ok ; check if sensor has a valid calibration 1215 btfss sensor1_calibrated_ok ; check if sensor has a valid calibration
1803 bra timeout_divemode_2 ; NO - skip 1803 bra timeout_divemode_2 ; NO - skip
1804 btfsc trigger_timeout ; YES - timeout occurred? 1804 btfsc trigger_timeout ; YES - timeout occurred?
1805 call menuview_toggle_reset ; YES - terminate the pre-menu 1805 call menuview_toggle_reset ; YES - terminate the pre-menu
1806 1806
1807 timeout_divemode_2: 1807 timeout_divemode_2:
1808 INCI dive_timeout_timer ; increment timeout timer
1809
1808 btfss divetime_longer_1min ; does the dive already last for longer than one minute? 1810 btfss divetime_longer_1min ; does the dive already last for longer than one minute?
1809 return ; NO - suspend timeout 1811 bra timeout_divemode_sub_1min ; NO - use a short timeout to achieve some extra hysteris when starting the dive
1810
1811 INCI dive_timeout_timer ; increment timeout timer
1812 1812
1813 btfsc FLAG_apnoe_mode ; in apnoe mode? 1813 btfsc FLAG_apnoe_mode ; in apnoe mode?
1814 bra timeout_divemode_apnoe ; YES - use apnoe timeout 1814 bra timeout_divemode_apnoe ; YES - use apnoe timeout
1815 1815
1816 IFNDEF _DEBUG 1816 IFNDEF _DEBUG
1827 1827
1828 timeout_divemode_sim: 1828 timeout_divemode_sim:
1829 MOVLI simulator_timeout,sub_a ; get simulator timeout in seconds directly into sub_a 1829 MOVLI simulator_timeout,sub_a ; get simulator timeout in seconds directly into sub_a
1830 bra timeout_divemode_com_sec ; continue with common part for seconds 1830 bra timeout_divemode_com_sec ; continue with common part for seconds
1831 1831
1832 timeout_divemode_sub_1min:
1833 MOVLI divetime_less_1min_timeout,sub_a ; use a short timeout as an extra hysteresis during the descent
1834 bra timeout_divemode_com_sec ; continue with common part for seconds
1835
1832 timeout_divemode_com_min: 1836 timeout_divemode_com_min:
1833 mullw .60 ; multiply with 60 to convert minutes in WREG to seconds 1837 mullw .60 ; multiply with 60 to convert minutes in WREG to seconds
1834 MOVII PRODL,sub_a ; copy resulting seconds to sub_a 1838 MOVII PRODL,sub_a ; copy resulting seconds to sub_a
1835 1839
1836 timeout_divemode_com_sec: 1840 timeout_divemode_com_sec:
1951 bsf count_divetime ; - count dive time 1955 bsf count_divetime ; - count dive time
1952 return ; - done 1956 return ; - done
1953 1957
1954 check_dive_modes_shallow: 1958 check_dive_modes_shallow:
1955 bcf count_divetime ; stop counting dive time 1959 bcf count_divetime ; stop counting dive time
1956 btfss divetime_longer_1min ; diving > one minute? 1960 ; btfss divetime_longer_1min ; diving > one minute?
1957 bcf divemode ; NO - quit dive mode as this was no real dive 1961 ; bcf divemode ; NO - quit dive mode as this was no real dive
1958 return ; done 1962 return ; done mH
1959 1963
1960 1964
1961 ;----------------------------------------------------------------------------- 1965 ;-----------------------------------------------------------------------------
1962 ; Initialize the resettable Depth and Timer 1966 ; Initialize the resettable Depth and Timer
1963 ; 1967 ;
2717 2721
2718 ;----------------------------------------------------------------------------- 2722 ;-----------------------------------------------------------------------------
2719 ; Check for Auto-SP 2723 ; Check for Auto-SP
2720 ; 2724 ;
2721 check_dive_autosp: 2725 check_dive_autosp:
2722 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 2726 movf dive_ccr_mode,W ; =0: Fixed SP, =1: Sensor, =2: Auto SP
2723 sublw .2 ; opt_ccr_mode = 2 (Auto SP)? 2727 sublw .2 ; dive_ccr_mode = 2 (Auto SP)?
2724 bz check_dive_autosp2 ; YES - check 2728 bz check_dive_autosp2 ; YES - check
2725 return ; NO - return for sensor or fixed mode 2729 return ; NO - return for sensor or fixed mode
2726 2730
2727 check_dive_autosp2: 2731 check_dive_autosp2:
2732 ; check for restart request
2733 btfss restart_auto_sp ; shall restart from 1st SP?
2734 bra check_dive_autosp2a ; NO - skip next
2735 bcf restart_auto_sp ; YES - clear request flag
2736 bcf FLAG_SP2_used ; - flag SP 2, ...
2737 bcf FLAG_SP3_used ; - flag SP 3, ...
2738 bcf FLAG_SP4_used ; - flag SP 4, ...
2739 bcf FLAG_SP5_used ; - flag SP 5 as unused so far
2740
2741 check_dive_autosp2a:
2728 ; check SP2 2742 ; check SP2
2729 btfsc FLAG_SP2_used ; SP 2 used so far? 2743 btfsc FLAG_SP2_used ; SP 2 used so far?
2730 bra check_dive_autosp3 ; YES - continue with SP 3 2744 bra check_dive_autosp3 ; YES - continue with SP 3
2731 movff opt_setpoint_change+1,lo ; NO - get depth in m 2745 movff opt_setpoint_change+1,lo ; NO - get depth in m
2732 tstfsz lo ; - SP change depth = 0 ? 2746 tstfsz lo ; - SP change depth = 0 ?
2733 bra check_dive_autosp2a ; NO - continue 2747 bra check_dive_autosp2b ; NO - continue
2734 bra check_dive_autosp3 ; YES - continue with SP 3 2748 bra check_dive_autosp3 ; YES - continue with SP 3
2735 check_dive_autosp2a: 2749 check_dive_autosp2b:
2736 decf lo,W ; SP change depth -1 -> WREG 2750 decf lo,W ; SP change depth -1 -> WREG
2737 cpfsgt depth_meter ; current depth > change depth - 1 ? 2751 cpfsgt depth_meter ; current depth > change depth - 1 ?
2738 bra check_dive_autosp3 ; NO - continue with SP 3 2752 bra check_dive_autosp3 ; NO - continue with SP 3
2739 ; auto switch to SP2 2753 ; auto switch to SP2
2740 movff opt_setpoint_cbar+1,char_I_const_ppO2 ; YES - use SP 2754 movff opt_setpoint_cbar+1,char_I_const_ppO2 ; YES - use SP
3094 dive_boot_cc_part2_1: 3108 dive_boot_cc_part2_1:
3095 ; In pSCR mode, only settings 0 (calculated ppO2) and 1 (ppO2 from sensors) are defined. 3109 ; In pSCR mode, only settings 0 (calculated ppO2) and 1 (ppO2 from sensors) are defined.
3096 ; In case we still have 3 (auto SP) selected out of previous CCR mode, we reset to 0. 3110 ; In case we still have 3 (auto SP) selected out of previous CCR mode, we reset to 0.
3097 btfss FLAG_pscr_mode ; in pSCR mode? 3111 btfss FLAG_pscr_mode ; in pSCR mode?
3098 bra dive_boot_cc_part2_2 ; NO 3112 bra dive_boot_cc_part2_2 ; NO
3099 movff opt_ccr_mode,WREG ; YES - get mode (=0: Fixed SP (CCR) / calculated SP (pSCR), =1: Sensor, =2: Auto SP) 3113 movf dive_ccr_mode,W ; YES - get mode (=0: Fixed SP (CCR) / calculated SP (pSCR), =1: Sensor, =2: Auto SP)
3100 sublw .2 ; opt_ccr_mode = 1 (Auto SP)? 3114 sublw .2 ; dive_ccr_mode = 1 (Auto SP)?
3101 bnz dive_boot_cc_part2_2 ; NO - ok 3115 bnz dive_boot_cc_part2_2 ; NO - ok
3102 movlw .0 ; YES - revert to calculated SP 3116 clrf dive_ccr_mode ; YES - revert to calculated SP
3103 movff WREG,opt_ccr_mode ; ...
3104 3117
3105 dive_boot_cc_part2_2: 3118 dive_boot_cc_part2_2:
3106 bsf event_SP_change ; set setpoint event flag 3119 bsf event_SP_change ; set setpoint event flag
3107 3120
3108 ; Start with SP1 (CCR) or 0 (pSCR) as default. 3121 ; Start with SP1 (CCR) or 0 (pSCR) as default.
3152 TSTOSC char_I_model ; GF factors enabled? 3165 TSTOSC char_I_model ; GF factors enabled?
3153 bsf tissue_graphic_gf ; YES - show GF lines 3166 bsf tissue_graphic_gf ; YES - show GF lines
3154 3167
3155 ; reset max relative pressure (max depth) 3168 ; reset max relative pressure (max depth)
3156 bsf reset_max_pressure ; request ISR to reset the max pressure 3169 bsf reset_max_pressure ; request ISR to reset the max pressure
3170
3171 ; make working copy of opt_ccr_mode
3172 movff opt_ccr_mode,dive_ccr_mode ; copy option setting
3173
3157 3174
3158 IFDEF _min_depth_option 3175 IFDEF _min_depth_option
3159 ; reset the resettable min/max relative pressure (trip-wise min/max depth) 3176 ; reset the resettable min/max relative pressure (trip-wise min/max depth)
3160 bsf reset_trip_pressure ; request ISR to reset the resettable min/max pressure 3177 bsf reset_trip_pressure ; request ISR to reset the resettable min/max pressure
3161 ENDIF 3178 ENDIF