Mercurial > public > hwos_code
view src/surfmode.asm @ 595:1719de53e497
2.97 SP2 (999bar fix)
author | heinrichsweikamp |
---|---|
date | Mon, 25 Jun 2018 18:29:54 +0200 |
parents | e81cf407261a |
children | ca4556fb60b9 |
line wrap: on
line source
;============================================================================= ; ; File surfmode.asm REFACTORED VERSION V2.97 SP1 ; ; Surfacemode ; ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. ;============================================================================= ; HISTORY ; 2011-08-07 : [mH] moving from OSTC code #include "hwos.inc" ; Mandatory header #include "shared_definitions.h" ; Mailbox from/to p2_deco.c #include "start.inc" #include "tft.inc" #include "tft_outputs.inc" #include "isr.inc" #include "adc_lightsensor.inc" #include "menu_processor.inc" #include "strings.inc" #include "sleepmode.inc" #include "wait.inc" ; speed_* #include "external_flash.inc" #include "customview.inc" #include "divemode.inc" #include "mcp.inc" ; RX #include "i2c.inc" #include "comm.inc" #include "eeprom_rs232.inc" #include "calibrate.inc" extern do_main_menu extern color_image ;---- Private local variables ------------------------------------------------- CBLOCK local1 ; max size is 16 Byte !!! ; currently not used ENDC ; used: 0 byte, remaining: 16 byte #DEFINE menu_pos_row .215 #DEFINE menu_pos_column .1 #DEFINE view_row .215 #DEFINE view_column .124 gui CODE ;============================================================================= ; Boot tasks for all modes global surfloop surfloop: call speed_normal bcf no_sensor_int ; Normal pressure mode bcf LEDr clrf CCP1CON ; stop PWM bcf PORTC,2 ; Pull PWM output to GND call TFT_boot ; Initialize TFT (includes clear screen) bcf restore_deco_data WIN_TOP .50 WIN_LEFT .10 movlw LOW 0x1E000 movwf TBLPTRL movlw HIGH 0x1E000 movwf TBLPTRH movlw UPPER 0x1E000 movwf TBLPTRU call color_image ; Show logo WIN_TOP .100 WIN_LEFT .34 extern ostc_logo_block movlw LOW ostc_logo_block movwf TBLPTRL movlw HIGH ostc_logo_block ; &0xFFFF movwf TBLPTRH movlw UPPER ostc_logo_block movwf TBLPTRU call color_image call TFT_Display_FadeIn ; Show splash call TFT_serial ; Show serial and firmware version ;---- Do any useful initializes that takes time ------------------------- call restart_set_modes_and_flags ; Sets deco mode flags bcf pressure_refresh call I2C_init_compass call I2C_init_accelerometer clrf ext_flash_address+0 clrf ext_flash_address+1 clrf ext_flash_address+2 movlw surface_sp ; in cbar call transmit_setpoint ; Transmit current setpoint from WREG (in cbar) to external electronics clrf timeout_counter2 ; clrf timeout_counter3 ; not used / required [rl] bcf menubit ; clear menu flag bcf premenu clrf last_pressure+0 clrf last_pressure+1 bcf is_bailout ; =1: Bailout bcf ccr_diluent_setup ; Use OC gases for gaslist routine bcf simulatormode_active ; Quit simulator mode (if active) ;---- Fade to standard surface view -------------------------------------- ; Wait 1 second bcf onesecupdate btfss onesecupdate bra $-2 ; Wait 1 second bcf onesecupdate btfss onesecupdate bra $-2 call TFT_Display_FadeOut ; Go to black screen call TFT_ClearScreen ; Then change everything WIN_TOP .0 WIN_LEFT .0 WIN_FONT FT_SMALL bcf win_invert ; Reset invert flag WIN_COLOR color_lightblue WIN_SMALL menu_pos_column,menu_pos_row STRCPY_TEXT_PRINT tMenu ;"<Menu" WIN_SMALL view_column,view_row STRCPY_TEXT_PRINT tView ;"View>" call TFT_standard_color ; Logo WIN_TOP .0 WIN_LEFT .70 movlw LOW ostc_logo_block movwf TBLPTRL movlw HIGH ostc_logo_block ; &0xFFFF movwf TBLPTRH movlw UPPER ostc_logo_block movwf TBLPTRU call color_image call TFT_clock ; display time call update_surfloop60 call get_battery_voltage ; get battery voltage call TFT_update_batt_voltage ; display battery voltage call TFT_update_surf_press ; display surface pressure call TFT_temp_surfmode ; Displays temperature call TFT_display_decotype_surface call calc_deko_divemode_sensor movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR tstfsz lo bra surfloop_no_oc ; Not OC call TFT_show_OC_startgas_surface; Show first gas and "OSTC2-like" active gases surfloop_no_oc: movff customview_surfmode,menupos3; Reload last customview call surf_customview_mask ; Update #menupos3 view call TFT_Display_FadeIn ; Display resulting surface screen. bcf switch_left bcf switch_right ;---- Late initializations ----------------------------------------------- movff last_surfpressure_30min+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine movff last_surfpressure_30min+1,int_I_pres_respiration+1 ; 30min old values movff last_surfpressure_30min+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine movff last_surfpressure_30min+1,int_I_pres_surface+1 ; 30min old values movff last_surfpressure_30min+0,last_surfpressure+0 ; Use 30min old airpressure movff last_surfpressure_30min+1,last_surfpressure+1 ; Use 30min old airpressure movff opt_GF_low,char_I_GF_Low_percentage movff opt_GF_high,char_I_GF_High_percentage ; Startup tasks for all modes ; Desaturation time needs: ; int_I_pres_surface ; char_I_desaturation_multiplier call deco_calc_desaturation_time ; calculate desaturation time banksel common btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) call enable_rs232 ; Also sets to speed_normal ... surfloop_loop: btfss onesecupdate ; do every second tasks? bra surfloop_loop2 ; no, loop ; One Second tasks for all modes call speed_normal ;call TFT_debug_output call TFT_clock ; update clock call timeout_surfmode ; check timeout call get_battery_voltage ; get battery voltage call TFT_update_batt_voltage ; display battery voltage call set_dive_modes ; tests if depth>threshold btfss secs,0 ; Every two seconds... call TFT_temp_surfmode ; Displays temperature btfss secs,0 ; Every two seconds... call surfmode_check_for_warnings ; ... check for warnings (and display/update) them bcf onesecupdate ; every second tasks done surfloop_loop2: ; Tasks approx. every 50ms for all modes call test_switches_surfmode ; check switches call TFT_debug_output ; One minute tasks for all modes btfsc oneminupdate ; do every minute tasks call update_surfloop60 ; yes, e.g. update time and date ; Mode tasks btfsc divemode ; Divemode active? goto diveloop ; Yes, switch into Divemode! btfsc menubit ; Menu? goto do_main_menu ; Menu! btfsc pressure_refresh ; new pressure available? call TFT_update_surf_press ; display surface pressure bcf pressure_refresh ; until new pressure is available ; Updates every 1/4 second btfss quarter_second_update bra surfloop_loop2b bcf quarter_second_update ; Update Sensors call calc_deko_divemode_sensor btfsc FLAG_ccr_mode ; In CCR mode? bra surfloop_loop2a1 ; Yes. btfss FLAG_pscr_mode ; In PSCR mode? bra surfloop_loop2a ; No, skip surfloop_loop2a1: movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP sublw .1 ; opt_ccr_mode = 1 (Sensor)? bnz surfloop_loop2a ; No, skip call TFT_surface_sensor ; ...update sensor data in surface mode call TFT_sensor_surface_warning ; Show a warning arrow-down behind sensor readings when sensor is end-of-life movlw .9 cpfseq menupos3 ; in Sensor mV surface custom view? bra surfloop_loop2a ; No extern TFT_sensor_mV call TFT_sensor_mV ; Yes, update mV readings (Each 1/4 second and not each second as in customview.asm) surfloop_loop2a: movlw .6 cpfseq menupos3 ; in compass view? bra surfloop_loop2b ; No extern TFT_surface_compass_heading call TFT_surface_compass_heading ; Yes, update compass heading value surfloop_loop2b: btfsc toggle_customview ; Next view? call surf_customview_toggle ; Yes, show next customview (and delete this flag) btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) bra surfloop_loop3 ;btfsc vusb_in ; USB plugged in? ;call comm_mode ; Start COMM mode bra surfloop_loop4 surfloop_loop3: btfss vusb_in ; USB (still) plugged in? bcf enable_screen_dumps ; No, clear flag call rs232_get_byte btfsc rs232_receive_overflow bra surfloop_loop4 movlw "l" cpfseq RCREG1 bra surfloop_loop4 call TFT_dump_screen ; Dump the screen contents surfloop_loop4: btfss sleepmode ; shall we go into sleepmode? bra surfloop_loop ; NO - loop in surfacemode movff menupos3,customview_surfmode; YES - save last customview goto sleeploop ; switch into sleepmode update_surfloop60: ; One minute tasks for all modes call TFT_date ; Update date call deco_calc_dive_interval_1min; calculate deco in surface mode. int_I_pres_surface gets updated by call deco_calc_desaturation_time ; TFT_update_surf_press when amb_pressure has changed by >= 10 mbar banksel common ; update tissue diagram if it is on display movlw .5 ; number of tissue custom view cpfseq menupos3 ; is this the current customview? bra update_surfloop60_1 ; NO call TFT_standard_color ; YES - set standard color call TFT_surface_tissues ; show tissue diagram update_surfloop60_1: ; update last dive info if it is on display movlw .8 ; number of the last dive info customview cpfseq menupos3 ; is this the current customview? bra update_surfloop60_2 ; NO call TFT_standard_color ; YES - set standard color call TFT_surface_lastdive ; show last dive infos update_surfloop60_2: bcf oneminupdate return extern check_cns_violation,check_warn_battery,check_and_store_gf_violation surfmode_check_for_warnings: bcf warning_active ; Clear flag clrf warning_counter ; Clear counter ; Warnings for all modes call check_warn_battery ; Check if the battery level should be displayed/warned btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode bra surfmode_check_for_warnings2 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode bra surfmode_check_for_warnings2 ; Warnings only in deco modes rcall surfmode_check_for_desat ; Check if desat time should be shown rcall surfmode_check_for_nofly ; Check if nofly time should be shown call check_cns_violation ; Check CNS value and display it, if required call check_and_store_gf_violation; Check GF value and display it, if required movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings btfsc WREG,mbubble_warning_lock ; do we have a microbubbles warning? extern warn_mbubbles call warn_mbubbles ; YES surfmode_check_for_warnings2: ; Setup warning_page number incf warning_page,F bcf STATUS,C rlcf warning_page,W ; *2 cpfsgt warning_counter ; > warning_counter clrf warning_page ; No, clear ; Clear both rows of warnings if there is nothing to show at all tstfsz warning_counter ; any warnings? bra surfmode_check_for_warnings3; YES - look if second row needs to be cleared call TFT_clear_warning_text ; NO - clear complete warnings area return surfmode_check_for_warnings3: ; Clear 2nd row of warnings if there is nothing to show (on this page) btfss second_row_warning ; =1: The second row contains a warning call TFT_clear_warning_text_2nd_row ; No, clear this row return ; Done. surfmode_check_for_desat: banksel int_O_desaturation_time movf int_O_desaturation_time+0,W ; is nofly-time null ? iorwf int_O_desaturation_time+1,W banksel common bnz surfmode_check_for_desat_1 ; NO return surfmode_check_for_desat_1: ; YES incf warning_counter,F ; increase counter call TFT_desaturation_time ; show desaturation time return surfmode_check_for_nofly: banksel int_O_nofly_time movf int_O_nofly_time+0,W ; is nofly-time null ? iorwf int_O_nofly_time+1,W banksel common bnz surfmode_check_for_nofly_1 ; No... return surfmode_check_for_nofly_1: ; YES incf warning_counter,F ; increase counter call TFT_nofly_time ; show nofly-time return ;============================================================================= test_switches_surfmode: ; checks switches in surfacemode btfsc switch_right bra test_switches_surfmode2 btfsc switch_left bra test_switches_surfmode3 ; No button pressed return test_switches_surfmode3: movlw .6 cpfseq menupos3 ; in compass view? bra test_switches_surfmode3a ; No btfsc premenu ; already shown "Bearing" bra test_switches_surfmode3b ; Yes, remove it extern TFT_surf_set_bearing call TFT_surf_set_bearing ; Yes. bcf switch_left return test_switches_surfmode3a: bcf switch_left bcf compass_bearing_set ; clear bearing on entering menu bsf menubit ; Enter Menu! return test_switches_surfmode3b: ; Clear "Heading?" WIN_BOX_BLACK .158,.190, .15, .99 ; top, bottom, left, right bcf premenu bcf switch_left return test_switches_surfmode2: movlw .6 cpfseq menupos3 ; in compass view? bra test_switches_surfmode2a ; No btfss premenu ; "Heading?" shown? bra test_switches_surfmode2a ; No ; Set new heading bcf premenu bsf compass_bearing_set movff compass_heading_shown+0,compass_bearing+0 movff compass_heading_shown+1,compass_bearing+1 bcf switch_right return test_switches_surfmode2a: bcf switch_right bsf toggle_customview bcf premenu clrf timeout_counter2 ; and reset timeout return global timeout_surfmode timeout_surfmode: movlw timeout_surfacemode ; [s] Default timeout btfsc menu_show_sensors2 ; In the "Calibrate" menu? movlw timeout_calibrate_menu ; [s] CCR Calibrate Menu timeout btfsc menubit ; in Menu? bra timeout_testmode ; No, done. ; Must be in surface mode btfss FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active bra timeout_testmode ; No, not CCR movlw timeout_ccr_surface ; [s] CCR Surface mode timeout global timeout_testmode timeout_testmode: incf timeout_counter2,F ; increase timeout counter cpfsgt timeout_counter2 ; Compare with timeout limit return ; return, no timeout bsf sleepmode ; Set Flag return ; Return END