Mercurial > public > hwos_code
comparison src/surfmode.asm @ 623:c40025d8e750
3.03 beta released
| author | heinrichsweikamp |
|---|---|
| date | Mon, 03 Jun 2019 14:01:48 +0200 |
| parents | 1ad0531e9078 |
| children | cd58f7fc86db |
comparison
equal
deleted
inserted
replaced
| 622:02d1386429a6 | 623:c40025d8e750 |
|---|---|
| 1 ;============================================================================= | 1 ;============================================================================= |
| 2 ; | 2 ; |
| 3 ; File surfmode.asm REFACTORED VERSION V2.99e | 3 ; File surfmode.asm next combined generation V3.03.2 |
| 4 ; | 4 ; |
| 5 ; Surfacemode | 5 ; Surface 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 ;============================================================================= |
| 9 ; HISTORY | 9 ; HISTORY |
| 10 ; 2011-08-07 : [mH] moving from OSTC code | 10 ; 2011-08-07 : [mH] moving from OSTC code |
| 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" | |
| 18 #include "adc_lightsensor.inc" | 17 #include "adc_lightsensor.inc" |
| 19 #include "menu_processor.inc" | 18 #include "menu_processor.inc" |
| 20 #include "strings.inc" | 19 #include "strings.inc" |
| 21 #include "sleepmode.inc" | 20 #include "sleepmode.inc" |
| 22 #include "wait.inc" ; speed_* | 21 #include "wait.inc" |
| 23 #include "external_flash.inc" | 22 #include "external_flash.inc" |
| 24 #include "customview.inc" | 23 #include "customview.inc" |
| 25 #include "divemode.inc" | 24 #include "divemode.inc" |
| 26 #include "mcp.inc" ; RX | 25 #include "mcp.inc" ; RX |
| 27 #include "i2c.inc" | 26 #include "i2c.inc" |
| 28 #include "comm.inc" | 27 #include "comm.inc" |
| 29 #include "eeprom_rs232.inc" | 28 #include "eeprom_rs232.inc" |
| 30 #include "calibrate.inc" | 29 #include "calibrate.inc" |
| 31 | |
| 32 IFDEF _rx_functions | |
| 33 #include "rx_ops.inc" | 30 #include "rx_ops.inc" |
| 34 ENDIF | 31 |
| 35 | 32 |
| 36 extern do_main_menu | 33 extern do_main_menu |
| 37 extern TFT_sensor_mV | |
| 38 extern TFT_surface_compass_heading | |
| 39 extern check_cns_violation | 34 extern check_cns_violation |
| 40 extern check_warn_battery | 35 extern check_warn_battery |
| 41 extern check_and_store_gf_violation | 36 extern check_and_store_sat_violation |
| 42 extern check_mbubbles | 37 extern check_mbubbles |
| 43 | 38 |
| 44 IFDEF _osct_logo | 39 IFDEF _osct_logo |
| 45 extern ostc_logo_block | 40 extern ostc_logo_block |
| 46 ENDIF | 41 ENDIF |
| 47 | 42 |
| 48 | 43 IFDEF _compass |
| 49 ;---- Private local variables ------------------------------------------------- | 44 extern TFT_surface_compass_heading |
| 50 | 45 ENDIF |
| 51 CBLOCK local1 ; max size is 16 Byte !!! | 46 |
| 47 | |
| 48 ;---- Private local variables ------------------------------------------------ | |
| 49 | |
| 50 CBLOCK local1 ; max size is 16 byte !!! | |
| 52 ; currently not used | 51 ; currently not used |
| 53 ENDC ; used: 0 byte, remaining: 16 byte | 52 ENDC ; used: 0 byte, remaining: 16 byte |
| 54 | 53 |
| 55 | 54 |
| 56 #DEFINE menu_pos_row .215 | 55 #DEFINE menu_pos_row .215 |
| 57 #DEFINE menu_pos_column .1 | 56 #DEFINE menu_pos_column .1 |
| 58 #DEFINE view_row .215 | 57 #DEFINE view_row .215 |
| 59 #DEFINE view_column .124 | 58 #DEFINE view_column .124 |
| 60 | 59 |
| 61 sfmode CODE | 60 |
| 61 sfmode CODE | |
| 62 | 62 |
| 63 ;============================================================================= | 63 ;============================================================================= |
| 64 ; Boot tasks for all modes | 64 ; Boot tasks for all modes |
| 65 | 65 ; |
| 66 ; called after restart via the battery selection, after compass calibration, | |
| 67 ; and via ghostwriter at the end of a dive | |
| 68 ; | |
| 66 global surfloop | 69 global surfloop |
| 67 surfloop: | 70 surfloop: |
| 68 call speed_normal | 71 clrf STKPTR ; clear return addresses stack |
| 69 bcf no_sensor_int ; normal pressure mode | 72 ; clrf CCP1CON ; stop PWM |
| 70 | 73 ; bcf PORTC,2 ; pull PWM output to GND |
| 71 bcf LEDr | 74 clrf CCPR1L ; backlight off |
| 72 | |
| 73 clrf CCP1CON ; stop PWM | |
| 74 bcf PORTC,2 ; pull PWM output to GND | |
| 75 call TFT_boot ; initialize TFT (includes clear screen) | 75 call TFT_boot ; initialize TFT (includes clear screen) |
| 76 bcf restore_deco_data | 76 |
| 77 | 77 btfsc restart_fast ; shall make a fast restart? |
| 78 bra surfloop_1 ; YES | |
| 79 | |
| 80 ; show heinrichsweikamp logo | |
| 78 WIN_TOP .40 | 81 WIN_TOP .40 |
| 79 WIN_LEFT .10 | 82 WIN_LEFT .10 |
| 80 TFT_WRITE_PROM_IMAGE_BY_ADDR hw_logo_block ; show heinrichsweikamp logo | 83 TFT_WRITE_PROM_IMAGE_BY_ADDR hw_logo_block |
| 81 | 84 |
| 82 IFDEF _ostc_logo | 85 IFDEF _ostc_logo |
| 86 ; show graphical OSTC logo | |
| 83 WIN_TOP .100 | 87 WIN_TOP .100 |
| 84 WIN_LEFT .34 | 88 WIN_LEFT .34 |
| 85 TFT_WRITE_PROM_IMAGE_BY_LABEL ostc_logo_block ; show OSTC logo | 89 TFT_WRITE_PROM_IMAGE_BY_LABEL ostc_logo_block |
| 86 ELSE | 90 ELSE |
| 91 ; show textual OSTC logo | |
| 87 WIN_COLOR color_white | 92 WIN_COLOR color_white |
| 88 WIN_STD .30,.90 ; column, row | 93 WIN_STD .30,.90 ; column, row |
| 89 STRCPY_PRINT "Open Source" ; show OSTC banner text, line 1 | 94 STRCPY_PRINT "Open Source" ; show OSTC banner text, line 1 |
| 90 WIN_STD .20,.130 ; column, row | 95 WIN_STD .20,.130 ; column, row |
| 91 STRCPY_PRINT "Tauch-Computer" ; show OSTC banner text, line 2 | 96 STRCPY_PRINT "Tauch-Computer" ; show OSTC banner text, line 2 |
| 93 | 98 |
| 94 WIN_COLOR color_white | 99 WIN_COLOR color_white |
| 95 WIN_SMALL .35,.180 | 100 WIN_SMALL .35,.180 |
| 96 PUTC "v" ; print v | 101 PUTC "v" ; print v |
| 97 call TFT_cat_firmware ; print x.y | 102 call TFT_cat_firmware ; print x.y |
| 98 PUTC " " ; print _ | 103 PUTC " " ; print _ |
| 99 call TFT_cat_beta_release ; print BetaZ or Release | 104 call TFT_cat_beta_release ; print BetaZ or Release |
| 100 STRCAT_PRINT "" ; finalize output | 105 STRCAT_PRINT "" ; finalize output |
| 101 bcf win_invert ; clean up eventual color-coding | 106 bcf win_invert ; clean up eventual color-coding |
| 102 call TFT_standard_color ; ditto | 107 call TFT_standard_color ; ditto |
| 103 | 108 call TFT_Display_FadeIn ; dim up the display |
| 104 call TFT_Display_FadeIn ; show splash | 109 |
| 105 | 110 surfloop_1: |
| 106 ;---- Do any useful initializes that takes time ------------------------- | 111 ;---- Do all useful initializations that take time ----------------------- |
| 107 | 112 |
| 108 call restart_set_modes_and_flags ; sets deco mode flags | 113 ; set deco mode flags |
| 109 bcf pressure_refresh | 114 call restart_set_modes_and_flags |
| 110 call I2C_sleep_compass | 115 |
| 111 call I2C_sleep_accelerometer | 116 bsf trigger_pres_cur_changed; set flag to have pressure written to display on first round of surface loop |
| 117 bsf trigger_temp_changed ; set flag to have temperature written to display on first round of surface loop | |
| 118 | |
| 119 call I2C_sleep_compass ; shut down compass | |
| 120 call I2C_sleep_accelerometer ; shut down accelerometer | |
| 121 | |
| 112 clrf ext_flash_address+0 | 122 clrf ext_flash_address+0 |
| 113 clrf ext_flash_address+1 | 123 clrf ext_flash_address+1 |
| 114 clrf ext_flash_address+2 | 124 clrf ext_flash_address+2 |
| 115 | 125 |
| 116 movlw surface_sp ; in cbar | 126 IFDEF _ccr_pscr |
| 117 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics | 127 movlw surface_sp ; load default surface setpoint (in cbar) |
| 118 | 128 movff WREG,char_I_const_ppO2 ; store it as current setpoint |
| 119 clrf timeout_counter2 | 129 ENDIF |
| 120 ; clrf timeout_counter3 ; not used / required [rl] | 130 |
| 121 bcf menubit ; clear menu flag | 131 IFDEF _external_sensor |
| 122 bcf premenu | 132 call transmit_setpoint ; transmit current setpoint (in cbar) via S8 digital interface (currently disabled) |
| 123 ; clrf last_pressure+0 | 133 ENDIF |
| 124 ; clrf last_pressure+1 | 134 |
| 125 bcf FLAG_bailout_mode ; =1: Bailout | 135 bcf surfmode_menu ; not in surface menu (any more) |
| 126 bcf FLAG_diluent_setup ; use OC gases for gaslist routine | 136 bcf compass_menu ; not in "set bearing" selection (any more) |
| 127 | 137 bcf bailout_mode ; not in bailout menu (any more) |
| 128 bcf simulatormode_active ; quit simulator mode (if active) | 138 |
| 139 bcf switch_left ; clear intermediate button event since start/restart | |
| 140 bcf switch_right ; clear intermediate button event since start/restart | |
| 141 | |
| 142 btfsc restart_fast ; shall make a fast restart? | |
| 143 bra surfloop_2 ; YES | |
| 129 | 144 |
| 130 call wait_1s ; wait <= 1 second | 145 call wait_1s ; wait <= 1 second |
| 131 call wait_1s ; wait 1 second | 146 call wait_1s ; wait 1 second |
| 132 call wait_1s ; wait 1 second | 147 call wait_1s ; wait 1 second |
| 133 | 148 |
| 134 ;---- Fade to standard surface view -------------------------------------- | 149 ;---- Fade to standard surface view -------------------------------------- |
| 135 | 150 |
| 136 call TFT_Display_FadeOut ; go to black screen | 151 call TFT_Display_FadeOut ; dim down display to black screen |
| 137 call TFT_ClearScreen ; then change everything | 152 call TFT_ClearScreen ; clear screen |
| 153 | |
| 154 surfloop_2: | |
| 138 WIN_TOP .0 | 155 WIN_TOP .0 |
| 139 WIN_LEFT .0 | 156 WIN_LEFT .0 |
| 140 WIN_FONT FT_SMALL | 157 WIN_FONT FT_SMALL |
| 141 bcf win_invert ; reset invert flag | 158 bcf win_invert ; clear flag for inverted text |
| 142 | 159 |
| 160 ; show button functionalities | |
| 143 WIN_COLOR color_lightblue | 161 WIN_COLOR color_lightblue |
| 144 WIN_SMALL menu_pos_column,menu_pos_row | 162 WIN_SMALL menu_pos_column,menu_pos_row |
| 145 STRCPY_TEXT_PRINT tMenu ;"<Menu" | 163 STRCPY_TEXT_PRINT tMenu ; show "<Menu" |
| 146 WIN_SMALL view_column,view_row | 164 WIN_SMALL view_column,view_row |
| 147 STRCPY_TEXT_PRINT tView ;"View>" | 165 STRCPY_TEXT_PRINT tView ; show "View>" |
| 148 call TFT_standard_color | 166 call TFT_standard_color |
| 149 | 167 |
| 150 ; Logo | 168 |
| 169 ;---- Logo in upper right corner ----------------------------------------- | |
| 151 IFDEF _ostc_logo | 170 IFDEF _ostc_logo |
| 171 ; show graphical OSTC logo | |
| 152 WIN_TOP .0 | 172 WIN_TOP .0 |
| 153 WIN_LEFT .70 | 173 WIN_LEFT .70 |
| 154 TFT_WRITE_PROM_IMAGE_BY_LABEL ostc_logo_block ; show OSTC logo | 174 TFT_WRITE_PROM_IMAGE_BY_LABEL ostc_logo_block |
| 155 ELSE | 175 ELSE |
| 156 WIN_COLOR color_white | 176 ; show textual OSTC logo |
| 157 WIN_STD .100,.0 | 177 WIN_COLOR color_white ; set text color to white |
| 178 WIN_STD .100,.2 ; set output position | |
| 158 STRCPY_PRINT "OSTC" ; show "OSTC" | 179 STRCPY_PRINT "OSTC" ; show "OSTC" |
| 159 WIN_COLOR color_cyan | 180 WIN_COLOR color_cyan ; set text color to cyan |
| 160 WIN_TINY .140,.0 | 181 WIN_TINY .138,.2 ; set output position |
| 161 STRCPY_PRINT "hwOS" ; show "hwOS" | 182 STRCPY_PRINT "hwOS" ; show "hwOS" |
| 162 WIN_TINY .139,.12 | 183 WIN_TINY .137,.14 ; set output position |
| 184 IFDEF _hwos_sport | |
| 185 STRCPY_PRINT "sport" ; show "sport" | |
| 186 ELSE | |
| 163 STRCPY_PRINT "tech" ; show "tech" | 187 STRCPY_PRINT "tech" ; show "tech" |
| 164 ENDIF | 188 ENDIF |
| 165 | 189 WIN_TINY .100,.32 ; set output position |
| 166 call TFT_clock ; display time | 190 call TFT_show_firmware ; show firmware version |
| 167 call update_surfloop60 | 191 ENDIF ; _ostc_logo |
| 168 call get_battery_voltage ; get battery voltage | 192 |
| 169 call TFT_update_batt_voltage ; display battery voltage | 193 |
| 170 call TFT_update_surf_press ; display surface pressure | 194 ;---- fill screen -------------------------------------------------------- |
| 171 call TFT_temp_surfmode ; display temperature | 195 call get_battery_voltage ; get battery voltage |
| 172 call TFT_display_decotype_surface | 196 call TFT_batt_surfmode ; display battery voltage |
| 173 call calc_deko_divemode_sensor | 197 call TFT_time_surfmode ; display time |
| 174 | 198 call TFT_date_surfmode ; display date |
| 175 TSTOSS opt_dive_mode ; in OC ? (0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR) | 199 call TFT_pres_surfmode ; display surface pressure |
| 176 call TFT_show_OC_startgas_surface; YES - show first gas and "OSTC2-like" active gases | 200 call TFT_temp_surfmode ; display temperature |
| 177 | 201 call TFT_decotype_surface ; display deco mode |
| 178 movff customview_surfmode,menupos3; reload last custom view | 202 |
| 179 call surf_customview_mask ; redraw last custom view | 203 TSTOSS opt_dive_mode ; in OC? (0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=pSCR) |
| 180 | 204 call TFT_show_OC_startgas_surface ; YES - show first gas and "OSTC2-like" active gases |
| 181 call TFT_Display_FadeIn ; display resulting surface screen | 205 |
| 182 | 206 movff customview_surfmode,active_customview ; reload last custom view |
| 183 bcf switch_left | 207 call surf_customview_mask ; redraw last custom view |
| 184 bcf switch_right | 208 |
| 185 | 209 call TFT_Display_FadeIn ; display resulting surface screen |
| 186 ;---- Late initializations ----------------------------------------------- | |
| 187 movff last_surfpressure_30min+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine | |
| 188 movff last_surfpressure_30min+1,int_I_pres_respiration+1 ; 30min old values | |
| 189 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine | |
| 190 movff last_surfpressure_30min+1,int_I_pres_surface+1 ; 30min old values | |
| 191 movff last_surfpressure_30min+0,last_surfpressure+0 ; use 30min old air pressure | |
| 192 movff last_surfpressure_30min+1,last_surfpressure+1 ; use 30min old air pressure | |
| 193 | |
| 194 movff opt_GF_low,char_I_GF_Low_percentage | |
| 195 movff opt_GF_high,char_I_GF_High_percentage | |
| 196 | |
| 197 ; Startup tasks for all modes | |
| 198 ; Desaturation time needs: | |
| 199 ; int_I_pres_surface | |
| 200 ; char_I_desaturation_multiplier | |
| 201 call deco_calc_desaturation_time ; calculate desaturation time | |
| 202 banksel common | |
| 203 | 210 |
| 204 IFDEF _screendump | 211 IFDEF _screendump |
| 205 btfsc enable_screen_dumps ; =1: ignore vin_usb, wait for "l" command (Screen dump) | 212 btfsc screen_dump_avail ; screen dump function enabled? |
| 206 call enable_rs232 ; also sets to speed_normal | 213 call enable_rs232 ; YES - activate RS232 (also sets CPU to normal speed) |
| 207 ENDIF | 214 ENDIF |
| 215 | |
| 216 bcf restart_fast ; clear flag for fast restart | |
| 217 bsf imprint_surfmode_data ; start imprinting surface mode data | |
| 218 | |
| 219 bcf switch_left ; clear pending left button event | |
| 220 bcf switch_right ; clear pending right button event | |
| 221 | |
| 222 rcall reset_timeout_surfmode ; reset timeout | |
| 208 | 223 |
| 209 surfloop_loop: | 224 surfloop_loop: |
| 210 btfss onesecupdate ; do every second tasks? | 225 ; call TFT_debug_output ; optional debug output |
| 211 bra surfloop_loop2 ; NO - loop | 226 |
| 212 | 227 call test_switches_surfmode ; check switches |
| 213 ; one second tasks for all modes | 228 |
| 214 call speed_normal | 229 btfsc request_next_custview ; shall show next custom view? |
| 215 ;call TFT_debug_output | 230 call surf_customview_toggle ; YES - show next custom view (and clear this flag) |
| 216 call TFT_clock ; update clock | 231 |
| 217 call timeout_surfmode ; check timeout | 232 btfss surfmode_menu ; shall enter surface menu? |
| 218 call get_battery_voltage ; get battery voltage | 233 bra surfloop_loop_1 ; NO |
| 219 call TFT_update_batt_voltage ; display battery voltage | 234 bcf imprint_surfmode_data ; YES - stop imprinting surface mode data |
| 220 call set_dive_modes ; tests if depth > threshold | 235 goto do_main_menu ; - goto surface menu |
| 221 btfss secs,0 ; every two seconds... | 236 |
| 222 call TFT_temp_surfmode ; ... displays temperature | 237 surfloop_loop_1: |
| 223 btfss secs,0 ; every two seconds... | 238 rcall housekeeping ; handle data imprinting, screen dump request, timeout and entering dive mode |
| 224 call surfmode_check_for_warnings ; ... check for warnings (and display/update) them | 239 bra surfloop_loop ; loop in surface mode |
| 225 bcf onesecupdate ; every second tasks done | 240 |
| 226 | |
| 227 IFDEF _rx_functions | |
| 228 btfss FLAG_tr_enabled ; YES - TR functions enabled? | |
| 229 bra surfloop_loop2 ; NO - skip tank pressure part | |
| 230 call get_pressure_readings ; YES - get pressure readings | |
| 231 call TFT_surface_tank_pres ; - update first gas/diluent pressure | |
| 232 movlw .10 ; - number of tank data custom view | |
| 233 cpfseq menupos3 ; - in tank data custom view? | |
| 234 bra surfloop_loop2 ; NO - skip | |
| 235 call TFT_surface_tankdata ; YES - update tank data custom view | |
| 236 ENDIF | |
| 237 | |
| 238 surfloop_loop2: | |
| 239 ; tasks approx. every 50 ms for all modes | |
| 240 call test_switches_surfmode ; check switches | |
| 241 ;call TFT_debug_output | |
| 242 | |
| 243 ; one minute tasks for all modes | |
| 244 btfsc oneminupdate ; do every minute tasks | |
| 245 call update_surfloop60 ; yes, e.g. update time and date | |
| 246 | |
| 247 ; mode tasks | |
| 248 btfsc divemode ; divemode active? | |
| 249 goto diveloop ; YES - switch into divemode! | |
| 250 | |
| 251 btfsc menubit ; shall enter menu? | |
| 252 goto do_main_menu ; YES - enter menu | |
| 253 | |
| 254 btfsc pressure_refresh ; new pressure available? | |
| 255 call TFT_update_surf_press ; display surface pressure | |
| 256 bcf pressure_refresh ; until new pressure is available | |
| 257 | |
| 258 ; updates every 1/4 second | |
| 259 btfss quarter_second_update | |
| 260 bra surfloop_loop2b | |
| 261 | |
| 262 bcf quarter_second_update | |
| 263 | |
| 264 ; update sensors | |
| 265 call calc_deko_divemode_sensor | |
| 266 | |
| 267 btfsc FLAG_ccr_mode ; in CCR mode? | |
| 268 bra surfloop_loop2a1 ; YES | |
| 269 btfsc FLAG_pscr_mode ; in pSCR mode? | |
| 270 bra surfloop_loop2a1 ; YES | |
| 271 bra surfloop_loop2a ; NO to both | |
| 272 | |
| 273 surfloop_loop2a1: | |
| 274 movff opt_ccr_mode,WREG ; =0: fixed SP, =1: sensor, =2: auto SP | |
| 275 decfsz WREG ; opt_ccr_mode = 1 (sensor)? | |
| 276 bra surfloop_loop2a ; NO - skip sensor readings | |
| 277 | |
| 278 call TFT_surface_sensor ; ...update sensor data in surface mode | |
| 279 call TFT_sensor_surface_warning ; show a warning arrow-down behind sensor readings when sensor is end-of-life | |
| 280 movlw .9 | |
| 281 cpfseq menupos3 ; in sensor mV surface custom view? | |
| 282 bra surfloop_loop2a ; NO | |
| 283 call TFT_sensor_mV ; YES - update mV readings (Each 1/4 second and not each second as in customview.asm) | |
| 284 | |
| 285 surfloop_loop2a: | |
| 286 movlw .6 | |
| 287 cpfseq menupos3 ; in compass view? | |
| 288 bra surfloop_loop2b ; NO | |
| 289 call TFT_surface_compass_heading ; YES - update compass heading value | |
| 290 | |
| 291 surfloop_loop2b: | |
| 292 btfsc toggle_customview ; next view? | |
| 293 call surf_customview_toggle ; YES - show next customview (and delete this flag) | |
| 294 | |
| 295 IFDEF _screendump | |
| 296 btfsc enable_screen_dumps ; screendump enabled? | |
| 297 call TFT_dump_screen_check ; YES - check if requested and do it | |
| 298 ENDIF | |
| 299 | |
| 300 ;btfsc vusb_in ; USB plugged in? | commented out - do not start COMM mode when charging in surface mode | |
| 301 ;call comm_mode ; YES - start COMM mode | | |
| 302 | |
| 303 btfss sleepmode ; shall we go into sleep mode? | |
| 304 bra surfloop_loop ; NO - loop in surface mode | |
| 305 movff menupos3,customview_surfmode; YES - save last custom view | |
| 306 goto sleeploop ; switch into sleep mode | |
| 307 | |
| 308 update_surfloop60: | |
| 309 ; one minute tasks for all modes | |
| 310 call TFT_date ; update date | |
| 311 | |
| 312 call deco_calc_dive_interval_1min; calculate deco in surface mode. int_I_pres_surface gets updated by | |
| 313 call deco_calc_desaturation_time ; TFT_update_surf_press when amb_pressure has changed by >= 10 mbar | |
| 314 banksel common | |
| 315 | |
| 316 ; update tissue diagram if it is on display | |
| 317 movlw .5 ; number of tissue custom view | |
| 318 cpfseq menupos3 ; is this the current custom view? | |
| 319 bra update_surfloop60_1 ; NO | |
| 320 call TFT_standard_color ; YES - set standard color | |
| 321 call TFT_surface_tissues ; show tissue diagram | |
| 322 | |
| 323 update_surfloop60_1: | |
| 324 ; update last dive info if it is on display | |
| 325 movlw .8 ; number of the last dive info custom view | |
| 326 cpfseq menupos3 ; is this the current custom view? | |
| 327 bra update_surfloop60_2 ; NO | |
| 328 call TFT_standard_color ; YES - set standard color | |
| 329 call TFT_surface_lastdive ; show last dive infos | |
| 330 | |
| 331 update_surfloop60_2: | |
| 332 bcf oneminupdate | |
| 333 return | |
| 334 | 241 |
| 335 surfmode_check_for_warnings: | 242 surfmode_check_for_warnings: |
| 336 bcf message_attention ; clear flag for messages of level attention | 243 clrf message_counter ; clear message counter |
| 337 bcf message_warning ; clear flag for messages of level warning | |
| 338 clrf message_counter ; clear message counter | |
| 339 | 244 |
| 340 ; warnings for all modes | 245 ; warnings for all modes |
| 341 call check_warn_battery ; check if the battery level should be displayed/warned | 246 call check_warn_battery ; check if the battery level should be displayed/warned |
| 342 | 247 |
| 343 btfsc FLAG_apnoe_mode ; done for Apnoe or Gauge mode | 248 btfsc FLAG_apnoe_mode ; done for Apnoe or Gauge mode |
| 344 bra surfmode_check_for_warnings2 | 249 bra surfmode_check_for_warnings2 |
| 345 btfsc FLAG_gauge_mode ; done for Apnoe or Gauge mode | 250 btfsc FLAG_gauge_mode ; done for Apnoe or Gauge mode |
| 346 bra surfmode_check_for_warnings2 | 251 bra surfmode_check_for_warnings2 |
| 347 | 252 |
| 348 ; warnings only in deco modes | 253 ; warnings only in deco modes |
| 349 rcall surfmode_check_for_desat ; check if desat time should be shown | 254 call check_and_store_sat_violation ; check/show tissue saturation |
| 350 rcall surfmode_check_for_nofly ; check if nofly time should be shown | 255 call check_cns_violation ; check/show CNS value |
| 351 call check_cns_violation ; check CNS value and display it, if required | 256 call check_mbubbles ; check/show micro bubbles warning |
| 352 call check_and_store_gf_violation; check GF value and display it, if required | 257 movff int_O_lead_supersat+1,WREG ; get upper byte of leading tissue's supersaturation |
| 353 call check_mbubbles ; check for micro bubbles | 258 btfsc WREG,int_warning_flag ; check if the warning flag is set |
| 259 bra surfmode_check_for_warnings2 ; YES - outside model | |
| 260 rcall surfmode_check_for_desat ; NO - check/display desaturation time | |
| 261 rcall surfmode_check_for_nofly ; NO - check/display no-fly time | |
| 354 | 262 |
| 355 surfmode_check_for_warnings2: | 263 surfmode_check_for_warnings2: |
| 356 ; setup message page number | 264 ; setup message page number |
| 357 incf message_page,F | 265 incf message_page,F ; increment page number |
| 358 bcf STATUS,C | 266 bcf STATUS,C ; clear carry bit |
| 359 rlcf message_page,W ; *2 | 267 rlcf message_page,W ; each page can take two messages |
| 360 cpfsgt message_counter ; > message_counter? | 268 cpfsgt message_counter ; number of actual messages > message capacity ? |
| 361 clrf message_page ; NO - clear | 269 clrf message_page ; NO - all messages could be shown, restart from first page next time |
| 362 | 270 |
| 363 ; clear both rows of warnings if there is nothing to show at all | 271 ; clear both rows if there is nothing to show at all |
| 364 tstfsz message_counter ; any warnings? | 272 tstfsz message_counter ; any message to show? |
| 365 bra surfmode_check_for_warnings3; YES - look if second row needs to be cleared | 273 bra surfmode_check_for_warnings3 ; YES - look if second row needs to be cleared |
| 366 call TFT_clear_warning_text ; NO - clear complete warnings area | 274 goto TFT_clear_message_window ; NO - clear complete message area and return |
| 367 return | |
| 368 | 275 |
| 369 surfmode_check_for_warnings3: | 276 surfmode_check_for_warnings3: |
| 370 ; clear 2nd row of warnings if there is nothing to show (on this page) | 277 ; clear 2nd row of messages if there is nothing to show (on this page) |
| 371 btfss second_row_warning ; =1: The second row contains a warning | 278 btfss message_2nd_row_used ; does the 2nd row contain a message? |
| 372 call TFT_clear_warning_text_2nd_row ; NO - clear this row | 279 goto TFT_clear_message_window_row2 ; NO - clear the 2nd row and return |
| 373 return ; Done. | 280 return ; YES - done |
| 281 | |
| 374 | 282 |
| 375 surfmode_check_for_desat: | 283 surfmode_check_for_desat: |
| 376 banksel int_O_desaturation_time | 284 banksel int_O_desaturation_time |
| 377 movf int_O_desaturation_time+0,W | 285 movf int_O_desaturation_time+0,W |
| 378 iorwf int_O_desaturation_time+1,W | 286 iorwf int_O_desaturation_time+1,W |
| 379 banksel common | 287 banksel common ; back to bank common |
| 380 bnz surfmode_check_for_desat_1 ; is the desat-time > 0 ? | 288 bnz surfmode_check_for_desat_1 ; is the desat-time > 0 ? |
| 381 return ; NO | 289 return ; NO - done |
| 382 surfmode_check_for_desat_1: ; YES | 290 surfmode_check_for_desat_1: |
| 383 incf message_counter,F ; increase counter | 291 incf message_counter,F ; YES - increase counter |
| 384 call TFT_desaturation_time ; show desaturation time | 292 call TFT_desaturation_time ; - show desaturation time |
| 385 return | 293 return ; - done |
| 386 | 294 |
| 387 surfmode_check_for_nofly: | 295 surfmode_check_for_nofly: |
| 388 banksel int_O_nofly_time | 296 banksel int_O_nofly_time |
| 389 movf int_O_nofly_time+0,W | 297 movf int_O_nofly_time+0,W |
| 390 iorwf int_O_nofly_time+1,W | 298 iorwf int_O_nofly_time+1,W |
| 391 banksel common | 299 banksel common ; back to bank common |
| 392 bnz surfmode_check_for_nofly_1 ; is the nofly-time > 0 ? | 300 bnz surfmode_check_for_nofly_1 ; is the nofly-time > 0 ? |
| 393 return ; NO | 301 return ; NO - done |
| 394 surfmode_check_for_nofly_1: ; YES | 302 surfmode_check_for_nofly_1: |
| 395 incf message_counter,F ; increase counter | 303 incf message_counter,F ; YES - increase counter |
| 396 call TFT_nofly_time ; show nofly-time | 304 call TFT_nofly_time ; - show nofly-time |
| 305 return ; - done | |
| 306 | |
| 307 | |
| 308 ;============================================================================= | |
| 309 | |
| 310 test_switches_surfmode: ; check buttons in surface mode | |
| 311 btfsc switch_right ; right button pressed? | |
| 312 bra test_switches_surfmode2 ; YES | |
| 313 btfsc switch_left ; left button pressed? | |
| 314 bra test_switches_surfmode3 ; YES | |
| 315 return ; NO to both - done | |
| 316 | |
| 317 test_switches_surfmode2: ; right button pressed | |
| 318 bcf switch_right ; clear button event | |
| 319 rcall reset_timeout_surfmode ; reset timeout | |
| 320 IFDEF _compass | |
| 321 movlw .6 ; coding for surface custom compass view | |
| 322 cpfseq active_customview ; in compass view? | |
| 323 bra test_switches_surfmode2a ; NO | |
| 324 btfss compass_menu ; "set course" selection shown? | |
| 325 bra test_switches_surfmode2a ; NO | |
| 326 bsf compass_bearing_set ; YES - set new course | |
| 327 MOVII compass_heading_shown,compass_bearing | |
| 328 bra test_switches_surfmode3b ; - clear "Course" label and return | |
| 329 ENDIF | |
| 330 test_switches_surfmode2a: | |
| 331 bsf request_next_custview ; request next custom view | |
| 332 bcf compass_menu ; "set course" selection not shown anymore | |
| 397 return | 333 return |
| 398 | 334 |
| 399 | 335 test_switches_surfmode3: ; left button pressed |
| 400 ;============================================================================= | 336 bcf switch_left ; clear button event |
| 401 | 337 rcall reset_timeout_surfmode ; reset timeout |
| 402 test_switches_surfmode: ; check switches in surfacemode | 338 IFDEF _compass |
| 403 btfsc switch_right | 339 movlw .6 ; coding for surface custom view compass |
| 404 bra test_switches_surfmode2 | 340 cpfseq active_customview ; in compass view? |
| 405 btfsc switch_left | 341 bra test_switches_surfmode3a ; NO |
| 406 bra test_switches_surfmode3 | 342 btfsc compass_menu ; YES - "set course" selection already shown? |
| 407 ; no button pressed | 343 bra test_switches_surfmode3b ; YES - remove it |
| 344 call TFT_surf_set_bearing ; NO - show it | |
| 408 return | 345 return |
| 409 | 346 ENDIF |
| 410 test_switches_surfmode3: | 347 test_switches_surfmode3a: |
| 411 movlw .6 | 348 bcf compass_bearing_set ; clear course on entering menu |
| 412 cpfseq menupos3 ; in compass view? | 349 bsf surfmode_menu ; flag that the surface menu shall be entered |
| 413 bra test_switches_surfmode3a ; NO | |
| 414 | |
| 415 btfsc premenu ; "Bearing" already shown? | |
| 416 bra test_switches_surfmode3b ; YES - remove it | |
| 417 call TFT_surf_set_bearing ; NO - show it | |
| 418 bcf switch_left | |
| 419 return | 350 return |
| 420 | 351 |
| 421 test_switches_surfmode3a: | 352 IFDEF _compass |
| 422 bcf switch_left | 353 test_switches_surfmode3b: |
| 423 bcf compass_bearing_set ; clear bearing on entering menu | 354 WIN_BOX_BLACK .158,.190, .15, .99 ; clear "Course" label (top, bottom, left, right) |
| 424 bsf menubit ; enter the main menu | 355 bcf compass_menu ; clear flag for "set course" selection |
| 425 return | 356 return |
| 426 | 357 ENDIF |
| 427 test_switches_surfmode3b: | 358 |
| 428 ; clear "Bearing" | 359 |
| 429 WIN_BOX_BLACK .158,.190, .15, .99 ; top, bottom, left, right | 360 ; handle data imprinting, screen dump request, timeout and entering dive mode |
| 430 bcf premenu | 361 global housekeeping |
| 431 bcf switch_left | 362 housekeeping: |
| 432 return | 363 btfss trigger_full_second ; new 1/1 second begun? |
| 433 | 364 bra housekeeping_1 ; NO |
| 434 test_switches_surfmode2: | 365 |
| 435 movlw .6 | 366 ; tasks any new second |
| 436 cpfseq menupos3 ; in compass view? | 367 bcf trigger_full_second ; YES - clear flag |
| 437 bra test_switches_surfmode2a ; NO | 368 call get_battery_voltage ; - get battery voltage |
| 438 btfss premenu ; "Heading?" shown? | 369 |
| 439 bra test_switches_surfmode2a ; NO | 370 btfsc imprint_time_date ; - shall imprint the current time & date? |
| 440 ; set new heading | 371 call TFT_show_time_date_menu ; YES - imprint time and date on display (copies running time to latch registers) |
| 441 bcf premenu | 372 |
| 442 bsf compass_bearing_set | |
| 443 movff compass_heading_shown+0,compass_bearing+0 | |
| 444 movff compass_heading_shown+1,compass_bearing+1 | |
| 445 bcf switch_right | |
| 446 return | |
| 447 | |
| 448 test_switches_surfmode2a: | |
| 449 bcf switch_right | |
| 450 bsf toggle_customview | |
| 451 bcf premenu | |
| 452 clrf timeout_counter2 ; and reset timeout | |
| 453 return | |
| 454 | |
| 455 global timeout_surfmode | |
| 456 timeout_surfmode: | |
| 457 movlw timeout_surfacemode ; load default timeout | |
| 458 btfsc menu_update_sensor_mv ; in the "Calibrate" menu? | |
| 459 movlw timeout_calibrate_menu ; YES - replace with CCR Calibrate Menu timeout | |
| 460 IFDEF _rx_functions | 373 IFDEF _rx_functions |
| 461 btfsc FLAG_pairing_mode ; in the "Setup Tank" menu? | 374 btfsc tr_functions_activated ; - TR functions activated? |
| 462 movlw timeout_tanksetup_menu ; YES - replace with Tank Setup Menu timeout | 375 call I2C_get_tankdata ; YES - get new transmitter data |
| 463 ENDIF | 376 |
| 464 btfsc menubit ; in menu? | 377 btfsc imprint_xmitter_pres ; - shall imprint transmitter ID and pressure? |
| 465 bra timeout_testmode ; NO - done | 378 call TFT_menu_tank_pres ; YES - imprint transmitter ID and pressure |
| 466 ; must be in surface mode | 379 ENDIF |
| 467 btfss FLAG_ccr_mode ; in CCR mode? (fixed ppO2 or sensor) | 380 |
| 468 bra timeout_testmode ; NO - not CCR | 381 btfss imprint_surfmode_data ; - shall imprint all surface mode data? |
| 469 movlw timeout_ccr_surface ; YES - replace with CCR surface mode timeout | 382 bra housekeeping_0 ; NO |
| 470 | 383 call TFT_time_surfmode ; YES - update displayed time |
| 471 global timeout_testmode | 384 call TFT_batt_surfmode ; - update displayed battery voltage |
| 472 timeout_testmode: | 385 btfss timebase_1sec,0 ; - on even second? |
| 473 incf timeout_counter2,F ; increase timeout counter | 386 call surfmode_check_for_warnings ; YES - check for warnings and display/update them |
| 474 cpfsgt timeout_counter2 ; compare with timeout limit | 387 |
| 475 return ; return, no timeout | 388 IFDEF _rx_functions |
| 476 bsf sleepmode ; set flag | 389 btfss tr_functions_activated ; - TR functions activated? |
| 477 return ; return | 390 bra housekeeping_0 ; NO - skip tank pressure part |
| 391 | |
| 392 call get_pressure_readings ; YES - get pressure readings | |
| 393 call TFT_surface_tank_pres ; - update first gas/diluent pressure | |
| 394 | |
| 395 movf active_customview,W ; - get current custom view | |
| 396 xorlw .10 ; - coding of tank data custom view | |
| 397 btfsc STATUS,Z ; - equal? | |
| 398 call TFT_surface_tankdata ; YES - update tank data custom view | |
| 399 ENDIF | |
| 400 | |
| 401 housekeeping_0: | |
| 402 bsf restart_fast ; default to doing a fast restart (no logos) | |
| 403 call set_dive_modes ; check if dive mode needs to be entered, will set dive mode flag if yes | |
| 404 btfsc simulatormode ; in simulator mode? | |
| 405 bra housekeeping_1 ; YES - can't restart or go to sleep without prior cleanup | |
| 406 btfsc divemode ; NO - need to enter dive mode? | |
| 407 goto restart ; YES - restart, will proceed to dive mode | |
| 408 btfss trigger_timeout ; NO - timeout? | |
| 409 bra housekeeping_1 ; NO | |
| 410 btfsc surfmode_menu ; YES - in surface menus? | |
| 411 goto restart ; YES - goto restart, will proceed to surface mode | |
| 412 bcf restart_fast ; NO - set next restart to be done slow, i.e. with logos | |
| 413 goto sleeploop ; - goto sleep mode | |
| 414 | |
| 415 housekeeping_1: | |
| 416 btfss trigger_quarter_second ; new 1/4 second begun? | |
| 417 bra housekeeping_2 ; NO | |
| 418 | |
| 419 ; tasks any new 1/4 second | |
| 420 bcf trigger_quarter_second ; YES - clear flag | |
| 421 IFDEF _external_sensor | |
| 422 btfsc imprint_sensor_mv ; - shall imprint sensor mV data? | |
| 423 call TFT_menu_calibrate ; YES - imprint sensor mV data | |
| 424 ENDIF ; _external_sensor | |
| 425 btfss imprint_surfmode_data ; - shall imprint all surface mode data? | |
| 426 bra housekeeping_2 ; NO | |
| 427 btfsc trigger_pres_cur_changed ; YES - pressure changed? | |
| 428 call TFT_pres_surfmode ; YES - display surface pressure | |
| 429 bcf trigger_pres_cur_changed ; - clear flag (anyhow) | |
| 430 IFDEF _compass | |
| 431 movf active_customview,W ; - get current custom view | |
| 432 xorlw .6 ; - coding of compass custom view | |
| 433 btfsc STATUS,Z ; - equal? | |
| 434 call TFT_surface_compass_heading ; YES - update compass view | |
| 435 ENDIF ; _compass | |
| 436 IFDEF _external_sensor | |
| 437 btfsc FLAG_ccr_mode ; - in CCR mode? | |
| 438 bra housekeeping_1a ; - YES - handle sensors | |
| 439 btfsc FLAG_pscr_mode ; - in pSCR mode? | |
| 440 bra housekeeping_1a ; YES - handle sensors | |
| 441 bra housekeeping_2 ; NO to both | |
| 442 housekeeping_1a: ; handle sensors | |
| 443 movff opt_ccr_mode,WREG ; =0: fixed SP, =1: sensor, =2: autoSP | |
| 444 decfsz WREG ; opt_ccr_mode = 1 (sensor)? | |
| 445 bra housekeeping_2 ; NO - skip sensor readings | |
| 446 call calc_deko_divemode_sensor ; YES - read & calculate sensor data | |
| 447 call TFT_surface_sensor ; - update displayed sensor data | |
| 448 call TFT_sensor_surface_warning ; - show a down-arrow behind sensor readings when sensor is at end-of-life | |
| 449 movf active_customview,W ; - get current custom view | |
| 450 xorlw .9 ; - coding of sensor mV readings custom view | |
| 451 btfsc STATUS,Z ; - equal? | |
| 452 call TFT_sensor_mV ; YES - update mV readings | |
| 453 ENDIF ; _external_sensor | |
| 454 housekeeping_2: | |
| 455 btfss trigger_full_minute ; new 1/1 minute begun? | |
| 456 bra housekeeping_3 ; NO | |
| 457 | |
| 458 ; tasks any new minute | |
| 459 bcf trigger_full_minute ; YES - clear flag | |
| 460 btfsc simulatormode ; - in simulator mode? | |
| 461 bra housekeeping_2a ; YES - real tissues are in the vault, skip desaturation calculations | |
| 462 call deco_calc_dive_interval_1min; NO - calculate 1 minute at surface conditions (C-code) | |
| 463 call deco_calc_desaturation_time ; - calculate desaturation and no-fly/no-altitude time (C-code) | |
| 464 banksel common ; - back to bank common | |
| 465 housekeeping_2a: | |
| 466 btfss imprint_surfmode_data ; - shall imprint all surface mode data? | |
| 467 bra housekeeping_3 ; NO | |
| 468 call TFT_date_surfmode ; YES - update displayed date | |
| 469 | |
| 470 btfsc trigger_temp_changed ; - temperature changed? | |
| 471 call TFT_temp_surfmode ; YES - display temperature | |
| 472 bcf trigger_temp_changed ; - clear flag (anyhow) | |
| 473 | |
| 474 movf active_customview,W ; - get current custom view | |
| 475 xorlw .5 ; - coding of tissue custom view | |
| 476 btfsc STATUS,Z ; - equal? | |
| 477 call TFT_surface_tissues ; YES - update tissue diagram | |
| 478 | |
| 479 movf active_customview,W ; - get current custom view | |
| 480 xorlw .8 ; - coding of last dive info custom view | |
| 481 btfsc STATUS,Z ; - equal? | |
| 482 call TFT_surface_lastdive ; YES - update last dive infos | |
| 483 | |
| 484 housekeeping_3: | |
| 485 ; tasks any round | |
| 486 IFDEF _screendump | |
| 487 btfsc screen_dump_avail ; screen dump function enabled? | |
| 488 call TFT_dump_screen_check ; YES - check if requested and do it | |
| 489 ELSE | |
| 490 btfsc comm_mode_disabled ; COMM mode disabled? | |
| 491 return ; YES - done | |
| 492 ENDIF | |
| 493 btfss surfmode_menu ; in surface menus? | |
| 494 return ; NO - done | |
| 495 | |
| 496 btfsc simulatormode ; currently in simulator (deco calculator) mode? | |
| 497 return ; YES - suppress COMM mode to not jeopardize backup/restore of tissue data | |
| 498 | |
| 499 btfss vusb_in ; USB plugged in? | |
| 500 return ; NO - done | |
| 501 IFDEF _screendump | |
| 502 btfsc screen_dump_avail ; YES - screen dump enabled? | |
| 503 return ; YES - no COMM mode to be able to make screen shots of the menu and simulator mode | |
| 504 ENDIF | |
| 505 goto comm_mode_usb ; YES / NO - proceed to COMM mode, will also set CPU to speed normal | |
| 506 | |
| 507 | |
| 508 global reset_timeout_surfmode | |
| 509 reset_timeout_surfmode: | |
| 510 movlw surfmode_timeout_default ; load default timeout value | |
| 511 btfsc imprint_sensor_mv ; currently imprinting O2 sensor mV data? | |
| 512 movlw surfmode_timeout_calibrate ; YES - replace with CCR Calibrate Menu timeout | |
| 513 btfsc simulatormode ; currently in simulator (deco calculator) mode? | |
| 514 movlw surfmode_timeout_simulator ; YES - replace with simulator timeout | |
| 515 IFDEF _rx_functions | |
| 516 btfsc imprint_xmitter_ID ; currently selecting pressure transmitter? | |
| 517 movlw surfmode_timeout_xmitter ; YES - replace with transmitter selection timeout | |
| 518 ENDIF ; _rx_functions | |
| 519 IFDEF _external_sensor | |
| 520 btfsc surfmode_menu ; in surface menu? | |
| 521 bra reset_timeout_time ; YES - keep timeout value | |
| 522 btfsc FLAG_ccr_mode ; NO - in CCR mode? | |
| 523 bra reset_timeout_surfmode_loop ; YES - continue checking if in sensor mode | |
| 524 btfsc FLAG_ccr_mode ; NO - in pSCR mode? | |
| 525 bra reset_timeout_surfmode_loop ; YES - continue checking if in sensor mode | |
| 526 bra reset_timeout_time ; NO - keep timeout value | |
| 527 reset_timeout_surfmode_loop: | |
| 528 movff opt_ccr_mode,lo ; get loop mode (=0: fixed/calculated SP, =1: sensor, =2: auto SP) | |
| 529 decfsz lo,f ; in sensor mode? | |
| 530 bra reset_timeout_time ; NO - keep timeout value | |
| 531 movlw surfmode_timeout_sensor ; YES - replace with sensor mode timeout | |
| 532 ENDIF ; _external_sensor | |
| 533 ;bra reset_timeout_time ; - set timeout value | |
| 534 | |
| 535 | |
| 536 global reset_timeout_time | |
| 537 reset_timeout_time: ; entry point with timeout value in WREG | |
| 538 movwf isr_timeout_reload ; copy WREG to isr_timeout_reload | |
| 539 bsf reset_timeout ; request ISR to reset the timeout | |
| 540 bcf trigger_timeout ; clear any pending timeout trigger | |
| 541 return ; done | |
| 542 | |
| 543 ;----------------------------------------------------------------------------- | |
| 478 | 544 |
| 479 END | 545 END |
