Mercurial > public > hwos_code
annotate src/surfmode.asm @ 603:00b24fb4324d
second method to detect a full charge
author | heinrichsweikamp |
---|---|
date | Thu, 11 Oct 2018 21:06:29 +0200 |
parents | e81cf407261a |
children | ca4556fb60b9 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
587 | 3 ; File surfmode.asm REFACTORED VERSION V2.97 SP1 |
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 |
582 | 32 extern do_main_menu |
33 extern color_image | |
34 | |
35 | |
36 ;---- Private local variables ------------------------------------------------- | |
213 | 37 |
582 | 38 CBLOCK local1 ; max size is 16 Byte !!! |
39 ; currently not used | |
40 ENDC ; used: 0 byte, remaining: 16 byte | |
41 | |
0 | 42 |
582 | 43 #DEFINE menu_pos_row .215 |
44 #DEFINE menu_pos_column .1 | |
45 #DEFINE view_row .215 | |
46 #DEFINE view_column .124 | |
0 | 47 |
582 | 48 gui CODE |
0 | 49 |
50 ;============================================================================= | |
51 ; Boot tasks for all modes | |
52 global surfloop | |
53 surfloop: | |
582 | 54 call speed_normal |
55 bcf no_sensor_int ; Normal pressure mode | |
0 | 56 |
582 | 57 bcf LEDr |
245 | 58 |
582 | 59 clrf CCP1CON ; stop PWM |
60 bcf PORTC,2 ; Pull PWM output to GND | |
61 call TFT_boot ; Initialize TFT (includes clear screen) | |
62 bcf restore_deco_data | |
0 | 63 |
582 | 64 WIN_TOP .50 |
65 WIN_LEFT .10 | |
66 movlw LOW 0x1E000 | |
67 movwf TBLPTRL | |
68 movlw HIGH 0x1E000 | |
69 movwf TBLPTRH | |
70 movlw UPPER 0x1E000 | |
71 movwf TBLPTRU | |
72 call color_image ; Show logo | |
0 | 73 |
582 | 74 WIN_TOP .100 |
75 WIN_LEFT .34 | |
76 extern ostc_logo_block | |
77 movlw LOW ostc_logo_block | |
78 movwf TBLPTRL | |
79 movlw HIGH ostc_logo_block ; &0xFFFF | |
80 movwf TBLPTRH | |
81 movlw UPPER ostc_logo_block | |
82 movwf TBLPTRU | |
83 call color_image | |
84 call TFT_Display_FadeIn ; Show splash | |
85 call TFT_serial ; Show serial and firmware version | |
0 | 86 |
582 | 87 ;---- Do any useful initializes that takes time ------------------------- |
88 call restart_set_modes_and_flags ; Sets deco mode flags | |
0 | 89 bcf pressure_refresh |
582 | 90 call I2C_init_compass |
91 call I2C_init_accelerometer | |
0 | 92 clrf ext_flash_address+0 |
93 clrf ext_flash_address+1 | |
94 clrf ext_flash_address+2 | |
95 | |
582 | 96 movlw surface_sp ; in cbar |
97 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
|
98 |
0 | 99 clrf timeout_counter2 |
582 | 100 ; clrf timeout_counter3 ; not used / required [rl] |
101 bcf menubit ; clear menu flag | |
102 bcf premenu | |
0 | 103 clrf last_pressure+0 |
104 clrf last_pressure+1 | |
582 | 105 bcf is_bailout ; =1: Bailout |
106 bcf ccr_diluent_setup ; Use OC gases for gaslist routine | |
0 | 107 |
582 | 108 bcf simulatormode_active ; Quit simulator mode (if active) |
0 | 109 |
110 ;---- Fade to standard surface view -------------------------------------- | |
111 ; Wait 1 second | |
112 bcf onesecupdate | |
113 btfss onesecupdate | |
114 bra $-2 | |
115 ; Wait 1 second | |
116 bcf onesecupdate | |
117 btfss onesecupdate | |
118 bra $-2 | |
119 | |
582 | 120 call TFT_Display_FadeOut ; Go to black screen |
121 call TFT_ClearScreen ; Then change everything | |
122 WIN_TOP .0 | |
123 WIN_LEFT .0 | |
124 WIN_FONT FT_SMALL | |
125 bcf win_invert ; Reset invert flag | |
0 | 126 |
582 | 127 WIN_COLOR color_lightblue |
128 WIN_SMALL menu_pos_column,menu_pos_row | |
129 STRCPY_TEXT_PRINT tMenu ;"<Menu" | |
130 WIN_SMALL view_column,view_row | |
131 STRCPY_TEXT_PRINT tView ;"View>" | |
132 call TFT_standard_color | |
0 | 133 |
48 | 134 ; Logo |
582 | 135 WIN_TOP .0 |
136 WIN_LEFT .70 | |
137 movlw LOW ostc_logo_block | |
138 movwf TBLPTRL | |
139 movlw HIGH ostc_logo_block ; &0xFFFF | |
140 movwf TBLPTRH | |
141 movlw UPPER ostc_logo_block | |
142 movwf TBLPTRU | |
143 call color_image | |
0 | 144 |
158 | 145 call TFT_clock ; display time |
582 | 146 call update_surfloop60 |
158 | 147 call get_battery_voltage ; get battery voltage |
148 call TFT_update_batt_voltage ; display battery voltage | |
149 call TFT_update_surf_press ; display surface pressure | |
150 call TFT_temp_surfmode ; Displays temperature | |
151 call TFT_display_decotype_surface | |
560 | 152 call calc_deko_divemode_sensor |
234
57155164faad
Show OSTC2-like active gas boxes in surface mode
heinrichsweikamp
parents:
233
diff
changeset
|
153 |
582 | 154 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR |
155 tstfsz lo | |
156 bra surfloop_no_oc ; Not OC | |
157 call TFT_show_OC_startgas_surface; Show first gas and "OSTC2-like" active gases | |
232 | 158 surfloop_no_oc: |
582 | 159 movff customview_surfmode,menupos3; Reload last customview |
160 call surf_customview_mask ; Update #menupos3 view | |
0 | 161 |
582 | 162 call TFT_Display_FadeIn ; Display resulting surface screen. |
0 | 163 |
560 | 164 bcf switch_left |
165 bcf switch_right | |
582 | 166 |
167 ;---- Late initializations ----------------------------------------------- | |
168 movff last_surfpressure_30min+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine | |
169 movff last_surfpressure_30min+1,int_I_pres_respiration+1 ; 30min old values | |
0 | 170 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine |
582 | 171 movff last_surfpressure_30min+1,int_I_pres_surface+1 ; 30min old values |
172 movff last_surfpressure_30min+0,last_surfpressure+0 ; Use 30min old airpressure | |
0 | 173 movff last_surfpressure_30min+1,last_surfpressure+1 ; Use 30min old airpressure |
174 | |
560 | 175 movff opt_GF_low,char_I_GF_Low_percentage |
176 movff opt_GF_high,char_I_GF_High_percentage | |
582 | 177 |
178 ; Startup tasks for all modes | |
179 ; Desaturation time needs: | |
180 ; int_I_pres_surface | |
181 ; char_I_desaturation_multiplier | |
0 | 182 call deco_calc_desaturation_time ; calculate desaturation time |
560 | 183 banksel common |
0 | 184 |
582 | 185 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) |
186 call enable_rs232 ; Also sets to speed_normal ... | |
0 | 187 |
188 surfloop_loop: | |
189 btfss onesecupdate ; do every second tasks? | |
190 bra surfloop_loop2 ; no, loop | |
191 | |
192 ; One Second tasks for all modes | |
193 call speed_normal | |
487 | 194 ;call TFT_debug_output |
0 | 195 call TFT_clock ; update clock |
196 call timeout_surfmode ; check timeout | |
197 call get_battery_voltage ; get battery voltage | |
198 call TFT_update_batt_voltage ; display battery voltage | |
199 call set_dive_modes ; tests if depth>threshold | |
582 | 200 btfss secs,0 ; Every two seconds... |
0 | 201 call TFT_temp_surfmode ; Displays temperature |
582 | 202 btfss secs,0 ; Every two seconds... |
203 call surfmode_check_for_warnings ; ... check for warnings (and display/update) them | |
0 | 204 bcf onesecupdate ; every second tasks done |
582 | 205 |
0 | 206 surfloop_loop2: |
207 ; Tasks approx. every 50ms for all modes | |
208 call test_switches_surfmode ; check switches | |
487 | 209 call TFT_debug_output |
0 | 210 |
211 ; One minute tasks for all modes | |
212 btfsc oneminupdate ; do every minute tasks | |
213 call update_surfloop60 ; yes, e.g. update time and date | |
214 | |
215 ; Mode tasks | |
230
f6548e8f06f5
Bugfix: Check for divemode before checking for menu
mh@mh-THINK
parents:
226
diff
changeset
|
216 btfsc divemode ; Divemode active? |
f6548e8f06f5
Bugfix: Check for divemode before checking for menu
mh@mh-THINK
parents:
226
diff
changeset
|
217 goto diveloop ; Yes, switch into Divemode! |
f6548e8f06f5
Bugfix: Check for divemode before checking for menu
mh@mh-THINK
parents:
226
diff
changeset
|
218 |
0 | 219 btfsc menubit ; Menu? |
220 goto do_main_menu ; Menu! | |
221 | |
222 btfsc pressure_refresh ; new pressure available? | |
223 call TFT_update_surf_press ; display surface pressure | |
224 bcf pressure_refresh ; until new pressure is available | |
225 | |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
226 ; Updates every 1/4 second |
582 | 227 btfss quarter_second_update |
228 bra surfloop_loop2b | |
229 | |
230 bcf quarter_second_update | |
231 | |
232 ; Update Sensors | |
233 call calc_deko_divemode_sensor | |
234 | |
235 btfsc FLAG_ccr_mode ; In CCR mode? | |
236 bra surfloop_loop2a1 ; Yes. | |
237 btfss FLAG_pscr_mode ; In PSCR mode? | |
238 bra surfloop_loop2a ; No, skip | |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
239 |
582 | 240 surfloop_loop2a1: |
241 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP | |
242 sublw .1 ; opt_ccr_mode = 1 (Sensor)? | |
243 bnz surfloop_loop2a ; No, skip | |
476
7c10557c248e
no sensors in surface mode if the computer has no sensor inputs
heinrichsweikamp
parents:
382
diff
changeset
|
244 |
582 | 245 call TFT_surface_sensor ; ...update sensor data in surface mode |
246 call TFT_sensor_surface_warning ; Show a warning arrow-down behind sensor readings when sensor is end-of-life | |
247 movlw .9 | |
248 cpfseq menupos3 ; in Sensor mV surface custom view? | |
249 bra surfloop_loop2a ; No | |
250 extern TFT_sensor_mV | |
251 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
|
252 |
476
7c10557c248e
no sensors in surface mode if the computer has no sensor inputs
heinrichsweikamp
parents:
382
diff
changeset
|
253 surfloop_loop2a: |
582 | 254 movlw .6 |
255 cpfseq menupos3 ; in compass view? | |
256 bra surfloop_loop2b ; No | |
257 extern TFT_surface_compass_heading | |
258 call TFT_surface_compass_heading ; Yes, update compass heading value | |
0 | 259 |
476
7c10557c248e
no sensors in surface mode if the computer has no sensor inputs
heinrichsweikamp
parents:
382
diff
changeset
|
260 surfloop_loop2b: |
0 | 261 btfsc toggle_customview ; Next view? |
582 | 262 call surf_customview_toggle ; Yes, show next customview (and delete this flag) |
263 | |
264 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
265 bra surfloop_loop3 | |
0 | 266 |
582 | 267 ;btfsc vusb_in ; USB plugged in? |
268 ;call comm_mode ; Start COMM mode | |
269 | |
270 bra surfloop_loop4 | |
271 | |
0 | 272 surfloop_loop3: |
582 | 273 btfss vusb_in ; USB (still) plugged in? |
274 bcf enable_screen_dumps ; No, clear flag | |
275 call rs232_get_byte | |
276 btfsc rs232_receive_overflow | |
277 bra surfloop_loop4 | |
278 movlw "l" | |
279 cpfseq RCREG1 | |
280 bra surfloop_loop4 | |
281 call TFT_dump_screen ; Dump the screen contents | |
282 | |
0 | 283 surfloop_loop4: |
582 | 284 btfss sleepmode ; shall we go into sleepmode? |
285 bra surfloop_loop ; NO - loop in surfacemode | |
286 movff menupos3,customview_surfmode; YES - save last customview | |
287 goto sleeploop ; switch into sleepmode | |
0 | 288 |
289 | |
290 update_surfloop60: | |
291 ; One minute tasks for all modes | |
582 | 292 call TFT_date ; Update date |
293 | |
294 call deco_calc_dive_interval_1min; calculate deco in surface mode. int_I_pres_surface gets updated by | |
295 call deco_calc_desaturation_time ; TFT_update_surf_press when amb_pressure has changed by >= 10 mbar | |
560 | 296 banksel common |
582 | 297 |
560 | 298 ; update tissue diagram if it is on display |
582 | 299 movlw .5 ; number of tissue custom view |
300 cpfseq menupos3 ; is this the current customview? | |
301 bra update_surfloop60_1 ; NO | |
302 call TFT_standard_color ; YES - set standard color | |
303 call TFT_surface_tissues ; show tissue diagram | |
304 | |
560 | 305 update_surfloop60_1: |
306 ; update last dive info if it is on display | |
582 | 307 movlw .8 ; number of the last dive info customview |
308 cpfseq menupos3 ; is this the current customview? | |
309 bra update_surfloop60_2 ; NO | |
310 call TFT_standard_color ; YES - set standard color | |
311 call TFT_surface_lastdive ; show last dive infos | |
312 | |
560 | 313 update_surfloop60_2: |
582 | 314 bcf oneminupdate |
0 | 315 return |
316 | |
582 | 317 extern check_cns_violation,check_warn_battery,check_and_store_gf_violation |
0 | 318 surfmode_check_for_warnings: |
582 | 319 bcf warning_active ; Clear flag |
320 clrf warning_counter ; Clear counter | |
560 | 321 |
582 | 322 ; Warnings for all modes |
323 call check_warn_battery ; Check if the battery level should be displayed/warned | |
0 | 324 |
582 | 325 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode |
326 bra surfmode_check_for_warnings2 | |
327 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
328 bra surfmode_check_for_warnings2 | |
0 | 329 |
582 | 330 ; Warnings only in deco modes |
331 rcall surfmode_check_for_desat ; Check if desat time should be shown | |
332 rcall surfmode_check_for_nofly ; Check if nofly time should be shown | |
333 call check_cns_violation ; Check CNS value and display it, if required | |
334 call check_and_store_gf_violation; Check GF value and display it, if required | |
0 | 335 |
582 | 336 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings |
337 btfsc WREG,mbubble_warning_lock ; do we have a microbubbles warning? | |
560 | 338 extern warn_mbubbles |
582 | 339 call warn_mbubbles ; YES |
560 | 340 |
0 | 341 surfmode_check_for_warnings2: |
582 | 342 ; Setup warning_page number |
343 incf warning_page,F | |
344 bcf STATUS,C | |
345 rlcf warning_page,W ; *2 | |
346 cpfsgt warning_counter ; > warning_counter | |
347 clrf warning_page ; No, clear | |
0 | 348 |
582 | 349 ; Clear both rows of warnings if there is nothing to show at all |
350 tstfsz warning_counter ; any warnings? | |
351 bra surfmode_check_for_warnings3; YES - look if second row needs to be cleared | |
352 call TFT_clear_warning_text ; NO - clear complete warnings area | |
353 return | |
0 | 354 |
582 | 355 surfmode_check_for_warnings3: |
356 ; Clear 2nd row of warnings if there is nothing to show (on this page) | |
357 btfss second_row_warning ; =1: The second row contains a warning | |
358 call TFT_clear_warning_text_2nd_row ; No, clear this row | |
359 return ; Done. | |
0 | 360 |
361 surfmode_check_for_desat: | |
560 | 362 banksel int_O_desaturation_time |
582 | 363 movf int_O_desaturation_time+0,W ; is nofly-time null ? |
364 iorwf int_O_desaturation_time+1,W | |
365 banksel common | |
366 bnz surfmode_check_for_desat_1 ; NO | |
367 return | |
368 surfmode_check_for_desat_1: ; YES | |
369 incf warning_counter,F ; increase counter | |
370 call TFT_desaturation_time ; show desaturation time | |
371 return | |
0 | 372 |
373 surfmode_check_for_nofly: | |
560 | 374 banksel int_O_nofly_time |
582 | 375 movf int_O_nofly_time+0,W ; is nofly-time null ? |
376 iorwf int_O_nofly_time+1,W | |
560 | 377 banksel common |
582 | 378 bnz surfmode_check_for_nofly_1 ; No... |
379 return | |
380 surfmode_check_for_nofly_1: ; YES | |
381 incf warning_counter,F ; increase counter | |
382 call TFT_nofly_time ; show nofly-time | |
383 return | |
0 | 384 |
385 | |
386 ;============================================================================= | |
560 | 387 |
582 | 388 test_switches_surfmode: ; checks switches in surfacemode |
0 | 389 btfsc switch_right |
390 bra test_switches_surfmode2 | |
391 btfsc switch_left | |
582 | 392 bra test_switches_surfmode3 |
393 ; No button pressed | |
0 | 394 return |
395 | |
396 test_switches_surfmode3: | |
582 | 397 movlw .6 |
398 cpfseq menupos3 ; in compass view? | |
399 bra test_switches_surfmode3a ; No | |
382 | 400 |
582 | 401 btfsc premenu ; already shown "Bearing" |
402 bra test_switches_surfmode3b ; Yes, remove it | |
382 | 403 |
582 | 404 extern TFT_surf_set_bearing |
405 call TFT_surf_set_bearing ; Yes. | |
406 bcf switch_left | |
407 return | |
382 | 408 |
409 test_switches_surfmode3a: | |
0 | 410 bcf switch_left |
587 | 411 bcf compass_bearing_set ; clear bearing on entering menu |
560 | 412 bsf menubit ; Enter Menu! |
0 | 413 return |
414 | |
382 | 415 test_switches_surfmode3b: |
582 | 416 ; Clear "Heading?" |
417 WIN_BOX_BLACK .158,.190, .15, .99 ; top, bottom, left, right | |
418 bcf premenu | |
419 bcf switch_left | |
420 return | |
382 | 421 |
0 | 422 test_switches_surfmode2: |
582 | 423 movlw .6 |
424 cpfseq menupos3 ; in compass view? | |
425 bra test_switches_surfmode2a ; No | |
426 btfss premenu ; "Heading?" shown? | |
427 bra test_switches_surfmode2a ; No | |
428 ; Set new heading | |
429 bcf premenu | |
430 bsf compass_bearing_set | |
431 movff compass_heading_shown+0,compass_bearing+0 | |
432 movff compass_heading_shown+1,compass_bearing+1 | |
382 | 433 bcf switch_right |
582 | 434 return |
382 | 435 |
436 test_switches_surfmode2a: | |
0 | 437 bcf switch_right |
438 bsf toggle_customview | |
582 | 439 bcf premenu |
440 clrf timeout_counter2 ; and reset timeout | |
0 | 441 return |
442 | |
443 global timeout_surfmode | |
444 timeout_surfmode: | |
582 | 445 movlw timeout_surfacemode ; [s] Default timeout |
446 btfsc menu_show_sensors2 ; In the "Calibrate" menu? | |
447 movlw timeout_calibrate_menu ; [s] CCR Calibrate Menu timeout | |
448 btfsc menubit ; in Menu? | |
449 bra timeout_testmode ; No, done. | |
450 ; Must be in surface mode | |
451 btfss FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active | |
452 bra timeout_testmode ; No, not CCR | |
453 movlw timeout_ccr_surface ; [s] CCR Surface mode timeout | |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
454 |
0 | 455 global timeout_testmode |
456 timeout_testmode: | |
582 | 457 incf timeout_counter2,F ; increase timeout counter |
458 cpfsgt timeout_counter2 ; Compare with timeout limit | |
459 return ; return, no timeout | |
460 bsf sleepmode ; Set Flag | |
461 return ; Return | |
0 | 462 |
582 | 463 END |