Mercurial > public > hwos_code
annotate src/surfmode.asm @ 620:cd986267a5ca
potential compass bug "fixed"
author | heinrichsweikamp |
---|---|
date | Fri, 22 Feb 2019 16:30:05 +0100 |
parents | ca4556fb60b9 |
children | 1ad0531e9078 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
604 | 3 ; File surfmode.asm REFACTORED VERSION V2.99e |
0 | 4 ; |
5 ; Surfacemode | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
582 | 10 ; 2011-08-07 : [mH] moving from OSTC code |
0 | 11 |
582 | 12 #include "hwos.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" | |
30 #include "calibrate.inc" | |
0 | 31 |
604 | 32 IFDEF _rx_functions |
33 #include "rx_ops.inc" | |
34 ENDIF | |
35 | |
582 | 36 extern do_main_menu |
604 | 37 extern TFT_sensor_mV |
38 extern TFT_surface_compass_heading | |
39 extern check_cns_violation | |
40 extern check_warn_battery | |
41 extern check_and_store_gf_violation | |
42 extern check_mbubbles | |
43 | |
44 IFDEF _osct_logo | |
45 extern ostc_logo_block | |
46 ENDIF | |
582 | 47 |
48 | |
49 ;---- Private local variables ------------------------------------------------- | |
213 | 50 |
604 | 51 CBLOCK local1 ; max size is 16 Byte !!! |
52 ; currently not used | |
53 ENDC ; used: 0 byte, remaining: 16 byte | |
582 | 54 |
0 | 55 |
582 | 56 #DEFINE menu_pos_row .215 |
57 #DEFINE menu_pos_column .1 | |
58 #DEFINE view_row .215 | |
59 #DEFINE view_column .124 | |
0 | 60 |
604 | 61 sfmode CODE |
0 | 62 |
63 ;============================================================================= | |
64 ; Boot tasks for all modes | |
604 | 65 |
0 | 66 global surfloop |
67 surfloop: | |
582 | 68 call speed_normal |
604 | 69 bcf no_sensor_int ; normal pressure mode |
0 | 70 |
582 | 71 bcf LEDr |
245 | 72 |
582 | 73 clrf CCP1CON ; stop PWM |
604 | 74 bcf PORTC,2 ; pull PWM output to GND |
75 call TFT_boot ; initialize TFT (includes clear screen) | |
582 | 76 bcf restore_deco_data |
0 | 77 |
604 | 78 WIN_TOP .40 |
582 | 79 WIN_LEFT .10 |
604 | 80 TFT_WRITE_PROM_IMAGE_BY_ADDR hw_logo_block ; show heinrichsweikamp logo |
0 | 81 |
604 | 82 IFDEF _ostc_logo |
83 WIN_TOP .100 | |
582 | 84 WIN_LEFT .34 |
604 | 85 TFT_WRITE_PROM_IMAGE_BY_LABEL ostc_logo_block ; show OSTC logo |
86 ELSE | |
87 WIN_COLOR color_white | |
88 WIN_STD .30,.90 ; column, row | |
89 STRCPY_PRINT "Open Source" ; show OSTC banner text, line 1 | |
90 WIN_STD .20,.130 ; column, row | |
91 STRCPY_PRINT "Tauch-Computer" ; show OSTC banner text, line 2 | |
92 ENDIF | |
93 | |
94 WIN_COLOR color_white | |
95 WIN_SMALL .35,.180 | |
96 PUTC "v" ; print v | |
97 call TFT_cat_firmware ; print x.y | |
98 PUTC " " ; print _ | |
99 call TFT_cat_beta_release ; print BetaZ or Release | |
100 STRCAT_PRINT "" ; finalize output | |
101 bcf win_invert ; clean up eventual color-coding | |
102 call TFT_standard_color ; ditto | |
103 | |
104 call TFT_Display_FadeIn ; show splash | |
0 | 105 |
582 | 106 ;---- Do any useful initializes that takes time ------------------------- |
604 | 107 |
108 call restart_set_modes_and_flags ; sets deco mode flags | |
0 | 109 bcf pressure_refresh |
604 | 110 call I2C_sleep_compass |
111 call I2C_sleep_accelerometer | |
0 | 112 clrf ext_flash_address+0 |
113 clrf ext_flash_address+1 | |
114 clrf ext_flash_address+2 | |
115 | |
582 | 116 movlw surface_sp ; in cbar |
604 | 117 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics |
221
90923a081ae7
minor: configure buttons during splash screen
heinrichsweikamp
parents:
213
diff
changeset
|
118 |
0 | 119 clrf timeout_counter2 |
582 | 120 ; clrf timeout_counter3 ; not used / required [rl] |
121 bcf menubit ; clear menu flag | |
122 bcf premenu | |
0 | 123 clrf last_pressure+0 |
124 clrf last_pressure+1 | |
604 | 125 bcf FLAG_bailout_mode ; =1: Bailout |
126 bcf FLAG_diluent_setup ; use OC gases for gaslist routine | |
0 | 127 |
604 | 128 bcf simulatormode_active ; quit simulator mode (if active) |
129 | |
130 call wait_1s ; wait <= 1 second | |
131 call wait_1s ; wait 1 second | |
132 call wait_1s ; wait 1 second | |
0 | 133 |
134 ;---- Fade to standard surface view -------------------------------------- | |
135 | |
604 | 136 call TFT_Display_FadeOut ; go to black screen |
137 call TFT_ClearScreen ; then change everything | |
138 WIN_TOP .0 | |
582 | 139 WIN_LEFT .0 |
140 WIN_FONT FT_SMALL | |
604 | 141 bcf win_invert ; reset invert flag |
0 | 142 |
582 | 143 WIN_COLOR color_lightblue |
144 WIN_SMALL menu_pos_column,menu_pos_row | |
145 STRCPY_TEXT_PRINT tMenu ;"<Menu" | |
146 WIN_SMALL view_column,view_row | |
147 STRCPY_TEXT_PRINT tView ;"View>" | |
148 call TFT_standard_color | |
0 | 149 |
48 | 150 ; Logo |
604 | 151 IFDEF _ostc_logo |
152 WIN_TOP .0 | |
582 | 153 WIN_LEFT .70 |
604 | 154 TFT_WRITE_PROM_IMAGE_BY_LABEL ostc_logo_block ; show OSTC logo |
155 ELSE | |
156 WIN_COLOR color_white | |
157 WIN_STD .100,.0 | |
158 STRCPY_PRINT "OSTC" ; show "OSTC" | |
159 WIN_COLOR color_cyan | |
160 WIN_TINY .140,.0 | |
161 STRCPY_PRINT "hwOS" ; show "hwOS" | |
162 WIN_TINY .139,.12 | |
163 STRCPY_PRINT "tech" ; show "tech" | |
164 ENDIF | |
0 | 165 |
158 | 166 call TFT_clock ; display time |
582 | 167 call update_surfloop60 |
158 | 168 call get_battery_voltage ; get battery voltage |
169 call TFT_update_batt_voltage ; display battery voltage | |
170 call TFT_update_surf_press ; display surface pressure | |
604 | 171 call TFT_temp_surfmode ; display temperature |
158 | 172 call TFT_display_decotype_surface |
560 | 173 call calc_deko_divemode_sensor |
234
57155164faad
Show OSTC2-like active gas boxes in surface mode
heinrichsweikamp
parents:
233
diff
changeset
|
174 |
604 | 175 TSTOSS opt_dive_mode ; in OC ? (0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR) |
176 call TFT_show_OC_startgas_surface; YES - show first gas and "OSTC2-like" active gases | |
0 | 177 |
604 | 178 movff customview_surfmode,menupos3; reload last custom view |
179 call surf_customview_mask ; redraw last custom view | |
180 | |
181 call TFT_Display_FadeIn ; display resulting surface screen | |
0 | 182 |
560 | 183 bcf switch_left |
184 bcf switch_right | |
582 | 185 |
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 | |
0 | 189 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine |
582 | 190 movff last_surfpressure_30min+1,int_I_pres_surface+1 ; 30min old values |
604 | 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 | |
0 | 193 |
560 | 194 movff opt_GF_low,char_I_GF_Low_percentage |
195 movff opt_GF_high,char_I_GF_High_percentage | |
582 | 196 |
197 ; Startup tasks for all modes | |
198 ; Desaturation time needs: | |
199 ; int_I_pres_surface | |
200 ; char_I_desaturation_multiplier | |
0 | 201 call deco_calc_desaturation_time ; calculate desaturation time |
560 | 202 banksel common |
0 | 203 |
604 | 204 IFDEF _screendump |
205 btfsc enable_screen_dumps ; =1: ignore vin_usb, wait for "l" command (Screen dump) | |
206 call enable_rs232 ; also sets to speed_normal | |
207 ENDIF | |
0 | 208 |
209 surfloop_loop: | |
210 btfss onesecupdate ; do every second tasks? | |
604 | 211 bra surfloop_loop2 ; NO - loop |
0 | 212 |
604 | 213 ; one second tasks for all modes |
0 | 214 call speed_normal |
487 | 215 ;call TFT_debug_output |
0 | 216 call TFT_clock ; update clock |
604 | 217 call timeout_surfmode ; check timeout |
0 | 218 call get_battery_voltage ; get battery voltage |
219 call TFT_update_batt_voltage ; display battery voltage | |
604 | 220 call set_dive_modes ; tests if depth > threshold |
221 btfss secs,0 ; every two seconds... | |
222 call TFT_temp_surfmode ; ... displays temperature | |
223 btfss secs,0 ; every two seconds... | |
582 | 224 call surfmode_check_for_warnings ; ... check for warnings (and display/update) them |
0 | 225 bcf onesecupdate ; every second tasks done |
582 | 226 |
604 | 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 | |
0 | 240 call test_switches_surfmode ; check switches |
604 | 241 ;call TFT_debug_output |
0 | 242 |
604 | 243 ; one minute tasks for all modes |
0 | 244 btfsc oneminupdate ; do every minute tasks |
245 call update_surfloop60 ; yes, e.g. update time and date | |
246 | |
604 | 247 ; mode tasks |
248 btfsc divemode ; divemode active? | |
249 goto diveloop ; YES - switch into divemode! | |
230
f6548e8f06f5
Bugfix: Check for divemode before checking for menu
mh@mh-THINK
parents:
226
diff
changeset
|
250 |
604 | 251 btfsc menubit ; shall enter menu? |
252 goto do_main_menu ; YES - enter menu | |
0 | 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 | |
604 | 258 ; updates every 1/4 second |
582 | 259 btfss quarter_second_update |
260 bra surfloop_loop2b | |
261 | |
262 bcf quarter_second_update | |
263 | |
604 | 264 ; update sensors |
582 | 265 call calc_deko_divemode_sensor |
266 | |
604 | 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 | |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
272 |
582 | 273 surfloop_loop2a1: |
604 | 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 | |
476
7c10557c248e
no sensors in surface mode if the computer has no sensor inputs
heinrichsweikamp
parents:
382
diff
changeset
|
277 |
582 | 278 call TFT_surface_sensor ; ...update sensor data in surface mode |
604 | 279 call TFT_sensor_surface_warning ; show a warning arrow-down behind sensor readings when sensor is end-of-life |
582 | 280 movlw .9 |
604 | 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) | |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
284 |
476
7c10557c248e
no sensors in surface mode if the computer has no sensor inputs
heinrichsweikamp
parents:
382
diff
changeset
|
285 surfloop_loop2a: |
582 | 286 movlw .6 |
287 cpfseq menupos3 ; in compass view? | |
604 | 288 bra surfloop_loop2b ; NO |
289 call TFT_surface_compass_heading ; YES - update compass heading value | |
0 | 290 |
476
7c10557c248e
no sensors in surface mode if the computer has no sensor inputs
heinrichsweikamp
parents:
382
diff
changeset
|
291 surfloop_loop2b: |
604 | 292 btfsc toggle_customview ; next view? |
293 call surf_customview_toggle ; YES - show next customview (and delete this flag) | |
582 | 294 |
604 | 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 | |
582 | 299 |
604 | 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 | | |
582 | 302 |
604 | 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 | |
0 | 307 |
308 update_surfloop60: | |
604 | 309 ; one minute tasks for all modes |
310 call TFT_date ; update date | |
582 | 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 | |
560 | 314 banksel common |
582 | 315 |
560 | 316 ; update tissue diagram if it is on display |
582 | 317 movlw .5 ; number of tissue custom view |
604 | 318 cpfseq menupos3 ; is this the current custom view? |
582 | 319 bra update_surfloop60_1 ; NO |
320 call TFT_standard_color ; YES - set standard color | |
321 call TFT_surface_tissues ; show tissue diagram | |
322 | |
560 | 323 update_surfloop60_1: |
324 ; update last dive info if it is on display | |
604 | 325 movlw .8 ; number of the last dive info custom view |
326 cpfseq menupos3 ; is this the current custom view? | |
582 | 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 | |
560 | 331 update_surfloop60_2: |
582 | 332 bcf oneminupdate |
0 | 333 return |
334 | |
335 surfmode_check_for_warnings: | |
604 | 336 bcf message_attention ; clear flag for messages of level attention |
337 bcf message_warning ; clear flag for messages of level warning | |
338 clrf message_counter ; clear message counter | |
560 | 339 |
604 | 340 ; warnings for all modes |
341 call check_warn_battery ; check if the battery level should be displayed/warned | |
0 | 342 |
604 | 343 btfsc FLAG_apnoe_mode ; done for Apnoe or Gauge mode |
582 | 344 bra surfmode_check_for_warnings2 |
604 | 345 btfsc FLAG_gauge_mode ; done for Apnoe or Gauge mode |
582 | 346 bra surfmode_check_for_warnings2 |
0 | 347 |
604 | 348 ; warnings only in deco modes |
349 rcall surfmode_check_for_desat ; check if desat time should be shown | |
350 rcall surfmode_check_for_nofly ; check if nofly time should be shown | |
351 call check_cns_violation ; check CNS value and display it, if required | |
352 call check_and_store_gf_violation; check GF value and display it, if required | |
353 call check_mbubbles ; check for micro bubbles | |
560 | 354 |
0 | 355 surfmode_check_for_warnings2: |
604 | 356 ; setup message page number |
357 incf message_page,F | |
582 | 358 bcf STATUS,C |
604 | 359 rlcf message_page,W ; *2 |
360 cpfsgt message_counter ; > message_counter? | |
361 clrf message_page ; NO - clear | |
0 | 362 |
604 | 363 ; clear both rows of warnings if there is nothing to show at all |
364 tstfsz message_counter ; any warnings? | |
582 | 365 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 | |
367 return | |
0 | 368 |
582 | 369 surfmode_check_for_warnings3: |
604 | 370 ; clear 2nd row of warnings if there is nothing to show (on this page) |
582 | 371 btfss second_row_warning ; =1: The second row contains a warning |
604 | 372 call TFT_clear_warning_text_2nd_row ; NO - clear this row |
582 | 373 return ; Done. |
0 | 374 |
375 surfmode_check_for_desat: | |
560 | 376 banksel int_O_desaturation_time |
604 | 377 movf int_O_desaturation_time+0,W |
582 | 378 iorwf int_O_desaturation_time+1,W |
379 banksel common | |
604 | 380 bnz surfmode_check_for_desat_1 ; is the desat-time > 0 ? |
381 return ; NO | |
582 | 382 surfmode_check_for_desat_1: ; YES |
604 | 383 incf message_counter,F ; increase counter |
582 | 384 call TFT_desaturation_time ; show desaturation time |
385 return | |
0 | 386 |
387 surfmode_check_for_nofly: | |
560 | 388 banksel int_O_nofly_time |
604 | 389 movf int_O_nofly_time+0,W |
582 | 390 iorwf int_O_nofly_time+1,W |
560 | 391 banksel common |
604 | 392 bnz surfmode_check_for_nofly_1 ; is the nofly-time > 0 ? |
393 return ; NO | |
582 | 394 surfmode_check_for_nofly_1: ; YES |
604 | 395 incf message_counter,F ; increase counter |
582 | 396 call TFT_nofly_time ; show nofly-time |
397 return | |
0 | 398 |
399 | |
400 ;============================================================================= | |
560 | 401 |
604 | 402 test_switches_surfmode: ; check switches in surfacemode |
0 | 403 btfsc switch_right |
404 bra test_switches_surfmode2 | |
405 btfsc switch_left | |
582 | 406 bra test_switches_surfmode3 |
604 | 407 ; no button pressed |
0 | 408 return |
409 | |
410 test_switches_surfmode3: | |
582 | 411 movlw .6 |
412 cpfseq menupos3 ; in compass view? | |
604 | 413 bra test_switches_surfmode3a ; NO |
382 | 414 |
604 | 415 btfsc premenu ; "Bearing" already shown? |
416 bra test_switches_surfmode3b ; YES - remove it | |
417 call TFT_surf_set_bearing ; NO - show it | |
582 | 418 bcf switch_left |
419 return | |
382 | 420 |
421 test_switches_surfmode3a: | |
0 | 422 bcf switch_left |
587 | 423 bcf compass_bearing_set ; clear bearing on entering menu |
604 | 424 bsf menubit ; enter the main menu |
0 | 425 return |
426 | |
382 | 427 test_switches_surfmode3b: |
604 | 428 ; clear "Bearing" |
582 | 429 WIN_BOX_BLACK .158,.190, .15, .99 ; top, bottom, left, right |
430 bcf premenu | |
431 bcf switch_left | |
432 return | |
382 | 433 |
0 | 434 test_switches_surfmode2: |
582 | 435 movlw .6 |
436 cpfseq menupos3 ; in compass view? | |
604 | 437 bra test_switches_surfmode2a ; NO |
582 | 438 btfss premenu ; "Heading?" shown? |
604 | 439 bra test_switches_surfmode2a ; NO |
440 ; set new heading | |
582 | 441 bcf premenu |
442 bsf compass_bearing_set | |
443 movff compass_heading_shown+0,compass_bearing+0 | |
444 movff compass_heading_shown+1,compass_bearing+1 | |
382 | 445 bcf switch_right |
582 | 446 return |
382 | 447 |
448 test_switches_surfmode2a: | |
0 | 449 bcf switch_right |
450 bsf toggle_customview | |
582 | 451 bcf premenu |
452 clrf timeout_counter2 ; and reset timeout | |
0 | 453 return |
454 | |
455 global timeout_surfmode | |
456 timeout_surfmode: | |
604 | 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 | |
461 btfsc FLAG_pairing_mode ; in the "Setup Tank" menu? | |
462 movlw timeout_tanksetup_menu ; YES - replace with Tank Setup Menu timeout | |
463 ENDIF | |
464 btfsc menubit ; in menu? | |
465 bra timeout_testmode ; NO - done | |
466 ; must be in surface mode | |
467 btfss FLAG_ccr_mode ; in CCR mode? (fixed ppO2 or sensor) | |
468 bra timeout_testmode ; NO - not CCR | |
469 movlw timeout_ccr_surface ; YES - replace with CCR surface mode timeout | |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
470 |
0 | 471 global timeout_testmode |
472 timeout_testmode: | |
582 | 473 incf timeout_counter2,F ; increase timeout counter |
604 | 474 cpfsgt timeout_counter2 ; compare with timeout limit |
582 | 475 return ; return, no timeout |
604 | 476 bsf sleepmode ; set flag |
477 return ; return | |
0 | 478 |
582 | 479 END |