Mercurial > public > hwos_code
annotate src/surfmode.asm @ 223:940155e9aefb
PC config, 1.72 release
| author | heinrichsweikamp |
|---|---|
| date | Wed, 14 Jan 2015 11:37:19 +0100 |
| parents | 90923a081ae7 |
| children | 8c11f60193be |
| rev | line source |
|---|---|
| 0 | 1 ;============================================================================= |
| 2 ; | |
| 3 ; File surfmode.asm | |
| 4 ; | |
| 5 ; Surfacemode | |
| 6 ; | |
| 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
| 8 ;============================================================================= | |
| 9 ; HISTORY | |
| 10 ; 2011-08-07 : [mH] moving from OSTC code | |
| 11 | |
| 12 #include "ostc3.inc" ; Mandatory header | |
| 13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c | |
| 14 #include "start.inc" | |
| 15 #include "tft.inc" | |
| 16 #include "tft_outputs.inc" | |
| 17 #include "isr.inc" | |
| 18 #include "adc_lightsensor.inc" | |
| 19 #include "menu_processor.inc" | |
| 20 #include "strings.inc" | |
| 21 #include "sleepmode.inc" | |
| 22 #include "wait.inc" ; speed_* | |
| 23 #include "external_flash.inc" | |
| 24 #include "customview.inc" | |
| 25 #include "divemode.inc" | |
| 26 #include "mcp.inc" ; RX | |
| 27 #include "i2c.inc" | |
| 28 #include "comm.inc" | |
| 29 #include "eeprom_rs232.inc" | |
| 113 | 30 #include "calibrate.inc" |
| 0 | 31 |
| 213 | 32 extern do_main_menu |
| 33 | |
| 0 | 34 #DEFINE menu_pos_row .215 |
| 213 | 35 #DEFINE menu_pos_column .1 |
| 0 | 36 #DEFINE view_row .215 |
| 37 #DEFINE view_column .124 | |
| 38 | |
| 39 gui CODE | |
| 40 | |
| 41 | |
| 42 ;============================================================================= | |
| 43 ; Boot tasks for all modes | |
| 44 global surfloop | |
| 45 surfloop: | |
| 46 call speed_normal | |
| 47 bcf no_sensor_int ; Normal pressure mode | |
| 48 | |
| 49 clrf CCP1CON ; stop PWM | |
| 50 bcf PORTC,2 ; Pull PWM output to GND | |
| 51 call TFT_boot ; Initialize TFT (includes clear screen) | |
| 52 bcf restore_deco_data | |
| 53 | |
| 54 WIN_TOP .50 | |
| 55 WIN_LEFT .10 | |
| 56 movlw LOW 0x1E000 | |
| 57 movwf TBLPTRL | |
| 58 movlw HIGH 0x1E000 | |
| 59 movwf TBLPTRH | |
| 60 movlw UPPER 0x1E000 | |
| 61 movwf TBLPTRU | |
| 62 extern color_image | |
| 63 call color_image ; Show logo | |
| 64 | |
| 65 WIN_TOP .100 | |
| 66 WIN_LEFT .34 | |
| 67 extern ostc3_logo_block | |
| 68 movlw LOW(ostc3_logo_block) | |
| 69 movwf TBLPTRL | |
| 70 movlw HIGH ostc3_logo_block;&0xFFFF | |
| 71 movwf TBLPTRH | |
| 72 movlw UPPER(ostc3_logo_block) | |
| 73 movwf TBLPTRU | |
| 74 call color_image | |
| 75 call TFT_Display_FadeIn ; Show splash | |
| 76 call TFT_serial ; Show serial and firmware version | |
| 77 | |
| 78 ;---- Do any usefull initializes that takes time ------------------------- | |
| 79 call restart_set_modes_and_flags ; Sets decomode flags | |
| 80 bcf pressure_refresh | |
| 81 call I2C_init_compass | |
| 82 call I2C_init_accelerometer | |
| 83 clrf ext_flash_address+0 | |
| 84 clrf ext_flash_address+1 | |
| 85 clrf ext_flash_address+2 | |
| 86 | |
|
221
90923a081ae7
minor: configure buttons during splash screen
heinrichsweikamp
parents:
213
diff
changeset
|
87 btfss cr_hardware |
|
90923a081ae7
minor: configure buttons during splash screen
heinrichsweikamp
parents:
213
diff
changeset
|
88 call piezo_config ; Configure buttons |
|
90923a081ae7
minor: configure buttons during splash screen
heinrichsweikamp
parents:
213
diff
changeset
|
89 |
| 0 | 90 clrf timeout_counter2 |
| 91 clrf timeout_counter3 | |
| 92 bcf menubit ; clear menu flag | |
| 93 clrf last_pressure+0 | |
| 94 clrf last_pressure+1 | |
| 95 bcf is_bailout ; =1: Bailout | |
| 96 bcf ccr_diluent_setup ; Use OC gases for gaslist routine | |
| 97 | |
| 98 bcf simulatormode_active ; Quit simulator mode (if active) | |
| 99 bcf switch_left | |
| 100 bcf switch_right | |
| 101 bcf LEDg | |
| 102 bcf LEDr | |
| 103 | |
| 104 ;---- Fade to standard surface view -------------------------------------- | |
| 105 ; Wait 1 second | |
| 106 bcf onesecupdate | |
| 107 btfss onesecupdate | |
| 108 bra $-2 | |
| 109 ; Wait 1 second | |
| 110 bcf onesecupdate | |
| 111 btfss onesecupdate | |
| 112 bra $-2 | |
| 113 | |
| 114 call TFT_Display_FadeOut ; Go to black screen | |
| 115 call TFT_ClearScreen ; Then change everything | |
| 116 WIN_TOP .0 | |
| 117 WIN_LEFT .0 | |
| 118 WIN_FONT FT_SMALL | |
|
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
188
diff
changeset
|
119 bcf win_invert ; Reset invert flag |
| 0 | 120 |
| 121 WIN_COLOR color_lightblue | |
| 122 WIN_SMALL menu_pos_column,menu_pos_row | |
| 123 STRCPY_TEXT_PRINT tMenu ;"<Menu" | |
| 124 WIN_SMALL view_column,view_row | |
| 125 STRCPY_TEXT_PRINT tView ;"View>" | |
| 126 call TFT_standard_color | |
| 127 | |
| 48 | 128 ; Logo |
| 0 | 129 WIN_TOP .0 |
| 130 WIN_LEFT .70 | |
| 131 movlw LOW(ostc3_logo_block) | |
| 132 movwf TBLPTRL | |
| 133 movlw HIGH ostc3_logo_block;&0xFFFF | |
| 134 movwf TBLPTRH | |
| 135 movlw UPPER(ostc3_logo_block) | |
| 136 movwf TBLPTRU | |
| 137 call color_image | |
| 138 | |
| 158 | 139 call TFT_clock ; display time |
| 140 call update_surfloop60 | |
| 141 call get_battery_voltage ; get battery voltage | |
| 142 call TFT_update_batt_voltage ; display battery voltage | |
| 143 call TFT_update_surf_press ; display surface pressure | |
| 144 call TFT_temp_surfmode ; Displays temperature | |
| 145 call TFT_display_decotype_surface | |
| 146 movff customview_surfmode,menupos3 ; Reload last customview | |
| 147 call surf_customview_mask ; Update #menupos3 view | |
| 0 | 148 |
| 149 call TFT_Display_FadeIn ; Display resulting surface screen. | |
| 150 | |
| 151 ;---- Late initialisations ----------------------------------------------- | |
| 152 movff last_surfpressure_30min+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine | |
| 153 movff last_surfpressure_30min+1,int_I_pres_respiration+1 ; 30min old values | |
| 154 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine | |
| 155 movff last_surfpressure_30min+1,int_I_pres_surface+1 ; 30min old values | |
| 156 movff last_surfpressure_30min+0,last_surfpressure+0 ; Use 30min old airpressure | |
| 157 movff last_surfpressure_30min+1,last_surfpressure+1 ; Use 30min old airpressure | |
| 158 | |
| 158 | 159 ; Startup tasks for all modes |
| 0 | 160 ; Desaturation time needs: |
| 161 ; int_I_pres_surface | |
| 162 ; char_I_desaturation_multiplier | |
| 163 call deco_calc_desaturation_time ; calculate desaturation time | |
| 164 movlb b'00000001' ; select ram bank 1 | |
| 165 | |
| 166 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
| 167 call enable_rs232 ; Also sets to speed_normal ... | |
| 168 | |
| 169 surfloop_loop: | |
| 170 btfss onesecupdate ; do every second tasks? | |
| 171 bra surfloop_loop2 ; no, loop | |
| 172 | |
| 173 ; One Second tasks for all modes | |
| 174 call speed_normal | |
| 175 call TFT_debug_output | |
| 176 call TFT_clock ; update clock | |
| 177 call timeout_surfmode ; check timeout | |
| 178 call get_battery_voltage ; get battery voltage | |
| 179 call TFT_update_batt_voltage ; display battery voltage | |
| 180 call set_dive_modes ; tests if depth>threshold | |
| 181 btfss secs,0 ; Every two seconds... | |
| 182 call TFT_temp_surfmode ; Displays temperature | |
| 183 btfss secs,0 ; Every two seconds... | |
| 184 call surfmode_check_for_warnings ; ... check for warnings (and display/update) them | |
| 185 | |
| 186 bcf onesecupdate ; every second tasks done | |
| 187 | |
| 188 surfloop_loop2: | |
| 189 ; Tasks approx. every 50ms for all modes | |
| 190 call test_switches_surfmode ; check switches | |
| 191 | |
| 192 ; One minute tasks for all modes | |
| 193 btfsc oneminupdate ; do every minute tasks | |
| 194 call update_surfloop60 ; yes, e.g. update time and date | |
| 195 | |
| 196 ; Mode tasks | |
| 197 btfsc menubit ; Menu? | |
| 198 goto do_main_menu ; Menu! | |
| 199 | |
| 200 btfsc pressure_refresh ; new pressure available? | |
| 201 call TFT_update_surf_press ; display surface pressure | |
| 202 bcf pressure_refresh ; until new pressure is available | |
| 203 | |
|
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
204 ; Updates every 1/4 second |
| 0 | 205 btfss quarter_second_update |
| 206 bra surfloop_loop2a | |
|
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
207 |
| 0 | 208 bcf quarter_second_update |
|
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
209 ; Update Sensors |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
210 |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
211 call compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
212 call check_sensors ; Set enable/disable flags |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
213 btfsc FLAG_ccr_mode ; In CCR mode... |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
214 call TFT_surface_sensor ; ...update sensor data in surface mode |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
215 |
| 0 | 216 movlw .6 |
| 217 cpfseq menupos3 ; in compass view? | |
| 218 bra surfloop_loop2a ; No | |
| 219 call TFT_surface_compass_heading ; Yes, update compass heading value | |
| 220 | |
| 221 surfloop_loop2a: | |
| 222 btfsc toggle_customview ; Next view? | |
| 223 call surf_customview_toggle ; Yes, show next customview (and delete this flag) | |
| 224 | |
| 225 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
| 226 bra surfloop_loop3 | |
| 227 btfsc vusb_in ; USB plugged in? | |
| 113 | 228 call comm_mode ; Start COMM mode |
| 0 | 229 bra surfloop_loop4 |
| 230 surfloop_loop3: | |
| 231 btfss vusb_in ; USB (still) plugged in? | |
| 232 bcf enable_screen_dumps ; No, clear flag | |
| 233 call rs232_get_byte | |
| 234 btfsc rs232_recieve_overflow | |
| 235 bra surfloop_loop4 | |
| 236 movlw "l" | |
| 237 cpfseq RCREG1 | |
| 238 bra surfloop_loop4 | |
| 239 call TFT_dump_screen ; Dump the screen contents | |
| 240 surfloop_loop4: | |
| 241 btfsc divemode ; Divemode active? | |
| 242 goto diveloop ; Yes, switch into Divemode! | |
| 243 btfsc sleepmode ; Sleepmode active? | |
| 244 goto sleeploop ; Yes, switch into sleepmode! | |
| 245 | |
| 246 bra surfloop_loop ; loop surfacemode | |
| 247 | |
| 248 update_surfloop60: | |
| 249 ; One minute tasks for all modes | |
| 250 call TFT_date ; Update date | |
| 251 call calc_deko_surfmode ; calculate desaturation every minute | |
| 252 bcf oneminupdate | |
| 253 return | |
| 254 | |
| 255 extern check_cns_violation,check_warn_battery,check_and_store_gf_violation | |
| 256 surfmode_check_for_warnings: | |
| 257 movf warning_counter_backup,W | |
| 258 cpfseq warning_counter ; warning_counter_backup = warning_counter? | |
| 259 call TFT_clear_warning_text ; No, clear all warnings | |
| 260 movff warning_counter,warning_counter_backup ; copy warning_counter | |
| 261 | |
| 262 bcf warning_active ; Clear flag | |
| 263 clrf warning_counter ; Clear counter | |
| 264 | |
| 265 ; Warnings for all modes | |
| 266 call check_warn_battery ; Check if the battery level should be displayed/warned | |
| 205 | 267 rcall surfmode_check_for_nofly ; Check if nofly time should be shown |
| 268 rcall surfmode_check_for_desat ; Check if desat time should be shown | |
| 269 rcall surfmode_check_for_interval ; Check if surface interval should be shown | |
| 0 | 270 |
| 271 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
| 272 bra surfmode_check_for_warnings2 | |
| 273 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
| 274 bra surfmode_check_for_warnings2 | |
| 275 | |
| 276 ; Warnings only in deco modes | |
| 277 call check_cns_violation ; Check CNS value and display it, if required | |
| 278 call check_and_store_gf_violation ; Check GF value and display it, if required | |
| 279 | |
| 280 surfmode_check_for_warnings2: | |
| 281 ; Setup warning_page number | |
| 282 incf warning_page,F | |
| 283 bcf STATUS,C | |
| 284 rlcf warning_page,W ; *2 | |
| 285 cpfsgt warning_counter ; > warning_counter | |
| 286 clrf warning_page ; No, clear | |
| 287 | |
| 288 ; Clear 2nd row of warnings if there is nothing to show (on this page) | |
| 289 btfss second_row_warning ; =1: The second row contains a warning | |
| 290 call TFT_clear_warning_text_2nd_row ; No, clear this row | |
| 291 return ; Done. | |
| 292 | |
| 293 surfmode_check_for_interval: | |
| 294 movf surface_interval+0,W ; Is interval null ? | |
|
133
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
295 iorwf surface_interval+1,W |
| 0 | 296 bnz surfmode_check_for_interval2 ; No |
| 297 return | |
| 298 surfmode_check_for_interval2: | |
| 299 incf warning_counter,F ; increase counter | |
| 300 call TFT_interval | |
| 301 return | |
| 302 | |
| 303 | |
| 304 surfmode_check_for_desat: | |
| 305 movf desaturation_time+0,W ; Is nofly null ? | |
| 306 iorwf desaturation_time+1,W | |
| 307 bnz surfmode_check_for_desat2 ; No | |
| 308 return | |
| 309 surfmode_check_for_desat2: | |
| 310 incf warning_counter,F ; increase counter | |
| 311 call TFT_desaturation_time | |
| 312 return | |
| 313 | |
| 314 surfmode_check_for_nofly: | |
| 315 movf nofly_time+0,W ; Is nofly null ? | |
| 316 iorwf nofly_time+1,W | |
| 317 bnz surfmode_check_for_nofly2 ; No... | |
| 318 return | |
| 319 surfmode_check_for_nofly2: | |
| 320 incf warning_counter,F ; increase counter | |
| 321 call TFT_nofly_time | |
| 322 return | |
| 323 | |
| 324 | |
| 325 ;============================================================================= | |
| 326 global calc_deko_surfmode | |
| 327 calc_deko_surfmode: | |
| 328 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy surface air pressure to deco routine | |
| 329 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode | |
| 330 banksel common | |
| 331 return | |
| 332 | |
| 333 test_switches_surfmode: ; checks switches in surfacemode | |
| 334 btfsc switch_right | |
| 335 bra test_switches_surfmode2 | |
| 336 btfsc switch_left | |
| 337 bra test_switches_surfmode3 | |
| 338 | |
| 339 ; No button press | |
| 340 return | |
| 341 | |
| 342 test_switches_surfmode3: | |
| 343 bcf switch_left | |
| 344 bsf menubit ; Enter Menu! | |
| 345 return | |
| 346 | |
| 347 test_switches_surfmode2: | |
| 348 bcf switch_right | |
| 349 bsf toggle_customview | |
| 350 clrf timeout_counter2 ; and reset timeout | |
| 351 return | |
| 352 | |
| 353 global timeout_surfmode | |
| 354 timeout_surfmode: | |
|
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
355 movlw timeout_surfacemode ; [s] Default timeout |
|
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
356 btfsc menu_show_sensors2 ; In the "Calibrate" menu? |
|
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
357 movlw timeout_calibrate_menu ; [s] CCR Calibrate Menu timeout |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
358 btfsc menubit ; in Menu? |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
359 bra timeout_testmode ; No, done. |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
360 ; Must be in surface mode |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
361 btfss FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
362 bra timeout_testmode ; No, not CCR |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
363 movlw timeout_ccr_surface ; [s] CCR Surface mode timeout |
|
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
364 |
| 0 | 365 global timeout_testmode |
| 366 timeout_testmode: | |
| 367 incf timeout_counter2,F ; increase timeout counter | |
| 368 cpfsgt timeout_counter2 ; Compare with timeout_counter2 | |
| 369 return ; return, no timeout | |
| 370 bsf sleepmode ; Set Flag | |
| 371 return ; Return | |
| 372 | |
| 373 END |
