comparison src/divemode.asm @ 545:7e6df19264b6

BUGFIX: Simulator in CC mode BUGFIX: Changing the dive mode and starting the simulator (without leaving the menu first) caused false calculations in the simulator BUGFIX: PSCR Mode "OC Gases" showed Diluents, not OC gases BUGFIX: CCR Mode ("First Diluent") was chosen based on OC "First Gas" number
author heinrichsweikamp
date Wed, 06 Sep 2017 21:26:18 +0200
parents a92cecf8cee4
children 49be7b31b4db
comparison
equal deleted inserted replaced
544:64a45f203144 545:7e6df19264b6
88 88
89 diveloop_loop1x: 89 diveloop_loop1x:
90 ; Common 1sec. tasks for all modes 90 ; Common 1sec. tasks for all modes
91 rcall timeout_divemode ; dive finished? This routine sets the required flags 91 rcall timeout_divemode ; dive finished? This routine sets the required flags
92 rcall set_dive_modes ; tests if depth>threshold 92 rcall set_dive_modes ; tests if depth>threshold
93 rcall set_min_temp ; store min. temp if required 93 rcall set_min_temp ; store min. temp if required (Future hardware will need this to be checked 1/second...)
94 94
95 btfsc store_sample ; store new sample? 95 btfsc store_sample ; store new sample?
96 call store_dive_data ; Store profile data 96 call store_dive_data ; Store profile data
97 97
98 btfss divemode ; Dive finished? 98 btfss divemode ; Dive finished?
104 btfsc toggle_gf ; =1: Toggle GF/aGF 104 btfsc toggle_gf ; =1: Toggle GF/aGF
105 rcall divemodemode_togglegf ; Toggle aGF/GF 105 rcall divemodemode_togglegf ; Toggle aGF/GF
106 106
107 btfsc FLAG_ccr_mode ; In CCR mode... 107 btfsc FLAG_ccr_mode ; In CCR mode...
108 call check_dive_autosp ; ...check for Auto-SP 108 call check_dive_autosp ; ...check for Auto-SP
109
110 call compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays
111 109
112 diveloop_loop3: 110 diveloop_loop3:
113 rcall test_switches_divemode ; Check switches in divemode 111 rcall test_switches_divemode ; Check switches in divemode
114 112
115 global diveloop_loop4 113 global diveloop_loop4
130 movlw .6 128 movlw .6
131 cpfseq menupos3 ; in compass view? 129 cpfseq menupos3 ; in compass view?
132 bra diveloop_loop4a ; No 130 bra diveloop_loop4a ; No
133 extern TFT_dive_compass_heading 131 extern TFT_dive_compass_heading
134 call TFT_dive_compass_heading ; Yes, update compass heading value 132 call TFT_dive_compass_heading ; Yes, update compass heading value
135 call TFT_temp_divemode ; Redraw temperature 133 call TFT_temp_divemode ; Redraw temperature (Is slighty affected from compass heading arrow)
136 diveloop_loop4a: 134 diveloop_loop4a:
137 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) 135 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
138 bra diveloop_loop5 136 bra diveloop_loop5
139 bra diveloop_loop6 137 bra diveloop_loop6
140 diveloop_loop5: 138 diveloop_loop5:
295 bsf voting_logic_sensor3 293 bsf voting_logic_sensor3
296 rcall divemode_setup_sensor_values ; Setup sensor values 294 rcall divemode_setup_sensor_values ; Setup sensor values
297 goto check_sensors ; Check O2 sensor thresholds for fallback customview_minute 295 goto check_sensors ; Check O2 sensor thresholds for fallback customview_minute
298 296
299 calc_deko_divemode2: 297 calc_deko_divemode2:
300 bcf twosecupdate 298 bcf twosecupdate
301 299
302 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode
303 return
304 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode 300 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode
305 return 301 return
306 302
307 extern deco_setup_dive 303 extern deco_setup_dive
308 call deco_setup_dive ; Pass all parameters to the C code 304 call deco_setup_dive ; Pass all parameters to the C code
416 calc_deko_divemode_sensor: ; External sensor stuff 412 calc_deko_divemode_sensor: ; External sensor stuff
417 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 413 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP
418 sublw .1 ; opt_ccr_mode = 1 (Sensor)? 414 sublw .1 ; opt_ccr_mode = 1 (Sensor)?
419 bnz calc_deko_divemode_sensor_done ; No, return 415 bnz calc_deko_divemode_sensor_done ; No, return
420 416
421 rcall divemode_setup_sensor_values ; Setup sensor values 417 call compute_ppo2 ; computes o2_ppo2_sensorX from mV-Readings
422 call check_sensors ; Check O2 sensor thresholds for fallback 418 call check_sensors ; analyses mv-Readings to set up use- and voting-Flags
423 movff sensor_setpoint,char_I_const_ppO2; Copy sensor result 419 call divemode_setup_sensor_values ; computes sensor_setpoint from o2_pp02_sensorX and Flags
420 movff sensor_setpoint,char_I_const_ppO2; Copy sensor result to C-code
424 421
425 TSTOSS opt_sensor_fallback ; =1: Fallback to SP1 when sensor is lost 422 TSTOSS opt_sensor_fallback ; =1: Fallback to SP1 when sensor is lost
426 return ; Never fallback 423 return ; Never fallback
427 424
428 btfsc is_bailout ; In bailout? 425 btfsc is_bailout ; In bailout?
720 717
721 update_divemode60: ; update any minute 718 update_divemode60: ; update any minute
722 call get_battery_voltage ; gets battery voltage 719 call get_battery_voltage ; gets battery voltage
723 rcall set_powersafe ; Battery low? 720 rcall set_powersafe ; Battery low?
724 call customview_minute ; Do every-minute tasks for the custom view area 721 call customview_minute ; Do every-minute tasks for the custom view area
725 bcf oneminupdate 722 bcf oneminupdate
726 723
727 btfss simulatormode_active ; in simulator mode? 724 btfss simulatormode_active ; in simulator mode?
728 return ; No 725 return ; No
729 ; Yes, quite dive mode simulation after 21*256s=89min:36s 726 ; Yes, quite dive mode simulation after 21*256s=89min:36s
730 movlw .20 727 movlw .20
968 rcall setup_gas_registers ; With WREG=Gas 0-4 965 rcall setup_gas_registers ; With WREG=Gas 0-4
969 gas_switched_common2: 966 gas_switched_common2:
970 decf menupos,W ; 1-5 -> 0-4 967 decf menupos,W ; 1-5 -> 0-4
971 btfsc is_bailout ; Choose OC Bailouts (OC Gases) 968 btfsc is_bailout ; Choose OC Bailouts (OC Gases)
972 rcall setup_gas_registers ; With WREG=Gas 0-4 969 rcall setup_gas_registers ; With WREG=Gas 0-4
970
971 movlw .0
972 btfsc is_bailout
973 movff WREG,char_I_const_ppO2 ; deactivate CCR-mode deco calc
973 974
974 call TFT_active_gas_divemode ; Display gas/Setpoint 975 call TFT_active_gas_divemode ; Display gas/Setpoint
975 clrf WREG 976 clrf WREG
976 movff WREG,char_O_deco_status ; Restart decoplan computation 977 movff WREG,char_O_deco_status ; Restart decoplan computation
977 978
1455 ; Setup everything to enter divemode. 1456 ; Setup everything to enter divemode.
1456 ; 1457 ;
1457 dive_boot_oc: 1458 dive_boot_oc:
1458 extern get_first_gas_to_WREG 1459 extern get_first_gas_to_WREG
1459 call get_first_gas_to_WREG ; Gets first gas (0-4) into WREG 1460 call get_first_gas_to_WREG ; Gets first gas (0-4) into WREG
1460 movff WREG,char_I_first_gas ; Copy for compatibility 1461 addlw .1
1461 rcall setup_gas_registers ; With WREG=Gas 0-4 1462 movff WREG,char_I_first_gas ; Copy for compatibility (1-5)
1462 banksel char_I_first_gas 1463 sublw .1 ; decrement WREG to old value again
1463 incf char_I_first_gas,F ; 0-4 -> 1-5 1464 rcall setup_gas_registers ; With WREG=Gas 0-4
1464 banksel common 1465 movlw .0
1466 movff WREG,char_I_const_ppO2 ; deactivate CCR-mode deco calc
1465 return 1467 return
1466 1468
1467 dive_boot_cc: 1469 dive_boot_cc:
1468 bcf is_bailout ; =1: Bailout 1470 bcf is_bailout ; =1: Bailout
1469 bcf setpoint_fallback ; =1: Fallback to SP1 due to external O2 sensor failure 1471 bcf setpoint_fallback ; =1: Fallback to SP1 due to external O2 sensor failure
1470 bcf blinking_setpoint ; Reset blinking SP flag 1472 bcf blinking_setpoint ; Reset blinking SP flag
1471 call compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays 1473 ; Noch testen mH
1472 bsf voting_logic_sensor1 1474 ; call compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays
1473 bsf voting_logic_sensor2 1475 ; bsf voting_logic_sensor1
1474 bsf voting_logic_sensor3 1476 ; bsf voting_logic_sensor2
1475 call divemode_setup_sensor_values ; setup sensor values 1477 ; bsf voting_logic_sensor3
1478 ; call divemode_setup_sensor_values ; setup sensor values
1476 1479
1477 ; Setup first SP for Fixed or Auto mode (Skipped here, because value is overwritten in sensor mode immediately anyway) 1480 ; Setup first SP for Fixed or Auto mode (Skipped here, because value is overwritten in sensor mode immediately anyway)
1478 ; movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP 1481 ; movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP
1479 ; sublw .1 ; opt_ccr_mode = 1 (Sensor)? 1482 ; sublw .1 ; opt_ccr_mode = 1 (Sensor)?
1480 ; bnz dive_boot_cc2 ; No, Skip 1483 ; bnz dive_boot_cc2 ; No, Skip
1488 bcf sp4_switched ; =1: This setpoint has been autoselected already 1491 bcf sp4_switched ; =1: This setpoint has been autoselected already
1489 bcf sp5_switched ; =1: This setpoint has been autoselected already 1492 bcf sp5_switched ; =1: This setpoint has been autoselected already
1490 1493
1491 extern get_first_dil_to_WREG 1494 extern get_first_dil_to_WREG
1492 call get_first_dil_to_WREG ; Gets first gas (0-4) into WREG 1495 call get_first_dil_to_WREG ; Gets first gas (0-4) into WREG
1496 addlw .1
1493 movff WREG,char_I_first_gas ; Copy for compatibility 1497 movff WREG,char_I_first_gas ; Copy for compatibility
1498 sublw .1
1494 rcall setup_dil_registers ; With WREG=Gas 0-4 1499 rcall setup_dil_registers ; With WREG=Gas 0-4
1495 banksel char_I_first_gas 1500 goto calc_deko_divemode_sensor ; External sensor stuff (and return!)
1496 incf char_I_first_gas,F ; 0-4 -> 1-5
1497 banksel common
1498 goto calc_deko_divemode_sensor ; External sensor stuff and return...
1499 1501
1500 diveloop_boot: 1502 diveloop_boot:
1501 call restart_set_modes_and_flags 1503 call restart_set_modes_and_flags
1502 1504
1503 call I2C_sleep_accelerometer ; Stop accelerometer 1505 call I2C_sleep_accelerometer ; Stop accelerometer
1522 movff year,start_year 1524 movff year,start_year
1523 movff month,start_month 1525 movff month,start_month
1524 movff day,start_day 1526 movff day,start_day
1525 movff hours,start_hours 1527 movff hours,start_hours
1526 movff mins,start_mins 1528 movff mins,start_mins
1529
1530 movff int_O_CNS_fraction+0,CNS_start+0
1531 movff int_O_CNS_fraction+1,CNS_start+1 ; Save CNS value at beginning of dive
1532 movff char_O_gradient_factor,GF_start ; Save GF value at beginning of dive
1533
1527 1534
1528 bcf no_more_divesecs ; =1: Do no longer show seconds in divemode 1535 bcf no_more_divesecs ; =1: Do no longer show seconds in divemode
1529 bcf divemode_menu_active 1536 bcf divemode_menu_active
1530 clrf menupos 1537 clrf menupos
1531 clrf menupos2 ; Reset to zero (Zero=no premenu or simulator task) 1538 clrf menupos2 ; Reset to zero (Zero=no premenu or simulator task)
1532 1539
1533 btfss FLAG_ccr_mode 1540 btfsc FLAG_ccr_mode
1541 bra diveloop_boot_cc
1542 btfsc FLAG_pscr_mode
1543 bra diveloop_boot_cc
1534 rcall dive_boot_oc 1544 rcall dive_boot_oc
1535 btfsc FLAG_ccr_mode 1545 bra diveloop_boot_cont
1536 rcall dive_boot_cc 1546 diveloop_boot_cc:
1537 btfsc FLAG_pscr_mode 1547 rcall dive_boot_cc
1538 rcall dive_boot_cc 1548 diveloop_boot_cont:
1539 1549
1540 ; Copy opt_dil_types into backup (For "lost gas" feature) 1550 ; Copy opt_dil_types into backup (For "lost gas" feature)
1541 movff opt_dil_type+0,opt_dil_type_backup+0 ; 0=Disabled, 1=First, 2=Normal 1551 movff opt_dil_type+0,opt_dil_type_backup+0 ; 0=Disabled, 1=First, 2=Normal
1542 movff opt_dil_type+1,opt_dil_type_backup+1 ; 0=Disabled, 1=First, 2=Normal 1552 movff opt_dil_type+1,opt_dil_type_backup+1 ; 0=Disabled, 1=First, 2=Normal
1543 movff opt_dil_type+2,opt_dil_type_backup+2 ; 0=Disabled, 1=First, 2=Normal 1553 movff opt_dil_type+2,opt_dil_type_backup+2 ; 0=Disabled, 1=First, 2=Normal
1571 clrf apnoe_timeout_counter ; timeout in minutes 1581 clrf apnoe_timeout_counter ; timeout in minutes
1572 clrf timeout_counter ; takes care of the timeout (Low byte) 1582 clrf timeout_counter ; takes care of the timeout (Low byte)
1573 clrf timeout_counter2 ; takes care of the timeout (High byte) 1583 clrf timeout_counter2 ; takes care of the timeout (High byte)
1574 clrf AlarmType ; Clear all alarms 1584 clrf AlarmType ; Clear all alarms
1575 bcf event_occured ; clear flag 1585 bcf event_occured ; clear flag
1576 clrf total_divetime_seconds+1
1577 clrf average_depth_hold_total+0 1586 clrf average_depth_hold_total+0
1578 clrf average_depth_hold_total+1 1587 clrf average_depth_hold_total+1
1579 clrf average_depth_hold_total+2 1588 clrf average_depth_hold_total+2
1580 clrf average_depth_hold_total+3 ; Clear Non-Resettable Average 1589 clrf average_depth_hold_total+3 ; Clear Non-Resettable Average
1581 rcall reset_average1 ; Reset the resettable average depth 1590 rcall reset_average1 ; Reset the resettable average depth
1582 bcf decostop_active 1591 bcf decostop_active
1583 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode 1592 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode
1584 call ghostwriter_short_header ; Write short header with divenumber into profile memory 1593 call ghostwriter_short_header ; Write short header with divenumber into profile memory
1585 1594
1586 btfsc simulatormode_active 1595 btfsc simulatormode_active
1587 bra diveloop_boot_1 1596 bra diveloop_boot_1
1588 ; Normal mode = Surface pressure is the pressure 30mn before dive. 1597 ; Normal mode = Surface pressure is the pressure 30mn before dive.
1643 call disable_rs232 ; Disable RS232 1652 call disable_rs232 ; Disable RS232
1644 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) 1653 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
1645 call enable_rs232 ; Also sets to speed_normal ... 1654 call enable_rs232 ; Also sets to speed_normal ...
1646 ; Reset divetime seconds 1655 ; Reset divetime seconds
1647 movlw .2 ; Start at 2seconds 1656 movlw .2 ; Start at 2seconds
1648 movwf total_divetime_seconds+0 1657 movwf total_divetime_seconds+0
1649 movwf divesecs 1658 clrf total_divetime_seconds+1
1650 movwf apnoe_secs 1659 movwf divesecs
1651 bsf divemode2 ; displayed divetime is running (Divetime starts HERE) 1660 movwf apnoe_secs
1652 1661 bsf divemode2 ; displayed divetime is running (Divetime starts HERE)
1653 movff int_O_CNS_fraction+0,CNS_start+0 1662
1654 movff int_O_CNS_fraction+1,CNS_start+1 ; Save CNS value at beginning of dive 1663 return ; Done with divemode boot
1655 movff char_O_gradient_factor,GF_start ; Save GF value at beginning of dive
1656 return ; Done with divemode boot
1657 1664
1658 divemode_check_for_warnings: 1665 divemode_check_for_warnings:
1659 movlw .2 1666 movlw .2
1660 cpfsgt warning_counter ; only two warnings active? 1667 cpfsgt warning_counter ; only two warnings active?
1661 bra divemode_check_for_warnings1 ; Yes, update every second 1668 bra divemode_check_for_warnings1 ; Yes, update every second