Mercurial > public > hwos_code
annotate src/surfmode.asm @ 97:53a99a2dc6a1
CHANGE: Always compute bailout plan based on all active gases
CHANGE: Re-select last diluent when returning from bailout to OC
author | heinrichsweikamp |
---|---|
date | Mon, 28 Apr 2014 16:26:31 +0200 |
parents | a5ea132770db |
children | f3062a611eef |
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" | |
30 | |
31 #DEFINE menu_pos_row .215 | |
32 #DEFINE menu_pos_column .0 | |
33 #DEFINE view_row .215 | |
34 #DEFINE view_column .124 | |
35 | |
36 extern do_main_menu | |
37 | |
38 gui CODE | |
39 | |
40 | |
41 ;============================================================================= | |
42 ; Boot tasks for all modes | |
43 global surfloop | |
44 surfloop: | |
45 call speed_normal | |
46 bcf no_sensor_int ; Normal pressure mode | |
47 | |
48 clrf CCP1CON ; stop PWM | |
49 bcf PORTC,2 ; Pull PWM output to GND | |
50 call TFT_boot ; Initialize TFT (includes clear screen) | |
51 bcf restore_deco_data | |
52 | |
53 WIN_TOP .50 | |
54 WIN_LEFT .10 | |
55 movlw LOW 0x1E000 | |
56 movwf TBLPTRL | |
57 movlw HIGH 0x1E000 | |
58 movwf TBLPTRH | |
59 movlw UPPER 0x1E000 | |
60 movwf TBLPTRU | |
61 extern color_image | |
62 call color_image ; Show logo | |
63 | |
64 WIN_TOP .100 | |
65 WIN_LEFT .34 | |
66 extern ostc3_logo_block | |
67 movlw LOW(ostc3_logo_block) | |
68 movwf TBLPTRL | |
69 movlw HIGH ostc3_logo_block;&0xFFFF | |
70 movwf TBLPTRH | |
71 movlw UPPER(ostc3_logo_block) | |
72 movwf TBLPTRU | |
73 call color_image | |
74 call TFT_Display_FadeIn ; Show splash | |
75 call TFT_serial ; Show serial and firmware version | |
76 | |
77 ;---- Do any usefull initializes that takes time ------------------------- | |
78 call restart_set_modes_and_flags ; Sets decomode flags | |
79 ; call speed_fastest | |
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 | |
87 clrf timeout_counter2 | |
88 clrf timeout_counter3 | |
89 bcf menubit ; clear menu flag | |
90 clrf last_pressure+0 | |
91 clrf last_pressure+1 | |
92 bcf is_bailout ; =1: Bailout | |
93 bcf ccr_diluent_setup ; Use OC gases for gaslist routine | |
94 | |
95 bcf simulatormode_active ; Quit simulator mode (if active) | |
96 bcf switch_left | |
97 bcf switch_right | |
98 bcf LEDg | |
99 bcf LEDr | |
100 | |
101 ;---- Fade to standard surface view -------------------------------------- | |
102 ; Wait 1 second | |
103 bcf onesecupdate | |
104 btfss onesecupdate | |
105 bra $-2 | |
106 ; Wait 1 second | |
107 bcf onesecupdate | |
108 btfss onesecupdate | |
109 bra $-2 | |
110 | |
111 call TFT_Display_FadeOut ; Go to black screen | |
112 call TFT_ClearScreen ; Then change everything | |
113 WIN_TOP .0 | |
114 WIN_LEFT .0 | |
115 WIN_FONT FT_SMALL | |
116 WIN_INVERT .0 ; Init new Wordprocessor | |
117 | |
118 ; call TFT_user_image ; Show the user image/text | |
119 | |
120 WIN_COLOR color_lightblue | |
121 WIN_SMALL menu_pos_column,menu_pos_row | |
122 STRCPY_TEXT_PRINT tMenu ;"<Menu" | |
123 WIN_SMALL view_column,view_row | |
124 STRCPY_TEXT_PRINT tView ;"View>" | |
125 call TFT_standard_color | |
126 | |
127 call TFT_clock ; display time | |
128 call update_surfloop60 | |
129 call get_battery_voltage ; get battery voltage | |
130 call TFT_update_batt_voltage ; display battery voltage | |
131 call TFT_update_surf_press ; display surface pressure | |
132 call TFT_temp_surfmode ; Displays temperature | |
133 call TFT_display_decotype_surface | |
39
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
134 movff customview_surfmode,menupos3 ; Reload last customview |
0 | 135 call surf_customview_mask ; Update #menupos3 view |
136 | |
48 | 137 ; Logo |
0 | 138 WIN_TOP .0 |
139 WIN_LEFT .70 | |
140 movlw LOW(ostc3_logo_block) | |
141 movwf TBLPTRL | |
142 movlw HIGH ostc3_logo_block;&0xFFFF | |
143 movwf TBLPTRH | |
144 movlw UPPER(ostc3_logo_block) | |
145 movwf TBLPTRU | |
146 call color_image | |
147 | |
148 btfsc FLAG_apnoe_mode ; Ignore in Apnoe mode | |
149 bra surfloop1 | |
150 btfsc FLAG_gauge_mode ; Ignore in Gauge mode | |
151 bra surfloop1 | |
152 | |
153 surfloop1: | |
154 call TFT_Display_FadeIn ; Display resulting surface screen. | |
155 | |
156 ;---- Late initialisations ----------------------------------------------- | |
157 movff last_surfpressure_30min+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine | |
158 movff last_surfpressure_30min+1,int_I_pres_respiration+1 ; 30min old values | |
159 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine | |
160 movff last_surfpressure_30min+1,int_I_pres_surface+1 ; 30min old values | |
161 movff last_surfpressure_30min+0,last_surfpressure+0 ; Use 30min old airpressure | |
162 movff last_surfpressure_30min+1,last_surfpressure+1 ; Use 30min old airpressure | |
163 | |
164 extern do_demo_divemode | |
165 ; goto do_demo_divemode | |
166 | |
167 ; Startup tasks for all modes | |
168 ; Desaturation time needs: | |
169 ; int_I_pres_surface | |
170 ; char_I_desaturation_multiplier | |
171 call deco_calc_desaturation_time ; calculate desaturation time | |
172 movlb b'00000001' ; select ram bank 1 | |
173 | |
174 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
175 call enable_rs232 ; Also sets to speed_normal ... | |
176 | |
177 surfloop_loop: | |
178 btfss onesecupdate ; do every second tasks? | |
179 bra surfloop_loop2 ; no, loop | |
180 | |
181 ; One Second tasks for all modes | |
182 call speed_normal | |
183 call TFT_debug_output | |
184 call TFT_clock ; update clock | |
185 call timeout_surfmode ; check timeout | |
186 call get_battery_voltage ; get battery voltage | |
187 call TFT_update_batt_voltage ; display battery voltage | |
188 call set_dive_modes ; tests if depth>threshold | |
189 btfss secs,0 ; Every two seconds... | |
190 call TFT_temp_surfmode ; Displays temperature | |
191 btfss secs,0 ; Every two seconds... | |
192 call surfmode_check_for_warnings ; ... check for warnings (and display/update) them | |
193 | |
194 btfsc FLAG_ccr_mode ; In CCR mode... | |
195 call TFT_surface_hud ; ...update HUD data in surface mode | |
196 | |
197 bcf onesecupdate ; every second tasks done | |
198 | |
199 surfloop_loop2: | |
200 ; Tasks approx. every 50ms for all modes | |
201 call test_switches_surfmode ; check switches | |
202 call speed_normal | |
203 | |
204 ; One minute tasks for all modes | |
205 btfsc oneminupdate ; do every minute tasks | |
206 call update_surfloop60 ; yes, e.g. update time and date | |
207 | |
208 ; Mode tasks | |
209 btfsc menubit ; Menu? | |
210 goto do_main_menu ; Menu! | |
211 | |
212 btfsc pressure_refresh ; new pressure available? | |
213 call TFT_update_surf_press ; display surface pressure | |
214 bcf pressure_refresh ; until new pressure is available | |
215 | |
216 btfss quarter_second_update | |
217 bra surfloop_loop2a | |
218 bcf quarter_second_update | |
219 movlw .6 | |
220 cpfseq menupos3 ; in compass view? | |
221 bra surfloop_loop2a ; No | |
222 call TFT_surface_compass_heading ; Yes, update compass heading value | |
223 | |
224 surfloop_loop2a: | |
225 btfsc toggle_customview ; Next view? | |
226 call surf_customview_toggle ; Yes, show next customview (and delete this flag) | |
227 | |
228 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
229 bra surfloop_loop3 | |
230 btfsc vusb_in ; USB plugged in? | |
231 goto comm_mode ; Start COMM mode | |
232 bra surfloop_loop4 | |
233 surfloop_loop3: | |
234 btfss vusb_in ; USB (still) plugged in? | |
235 bcf enable_screen_dumps ; No, clear flag | |
236 call rs232_get_byte | |
237 btfsc rs232_recieve_overflow | |
238 bra surfloop_loop4 | |
239 movlw "l" | |
240 cpfseq RCREG1 | |
241 bra surfloop_loop4 | |
242 call TFT_dump_screen ; Dump the screen contents | |
243 surfloop_loop4: | |
244 btfsc divemode ; Divemode active? | |
245 goto diveloop ; Yes, switch into Divemode! | |
246 btfsc sleepmode ; Sleepmode active? | |
247 goto sleeploop ; Yes, switch into sleepmode! | |
248 | |
249 bra surfloop_loop ; loop surfacemode | |
250 | |
251 update_surfloop60: | |
252 ; One minute tasks for all modes | |
253 call TFT_date ; Update date | |
254 call calc_deko_surfmode ; calculate desaturation every minute | |
255 bcf oneminupdate | |
256 return | |
257 | |
258 extern check_cns_violation,check_warn_battery,check_and_store_gf_violation | |
259 surfmode_check_for_warnings: | |
260 movf warning_counter_backup,W | |
261 cpfseq warning_counter ; warning_counter_backup = warning_counter? | |
262 call TFT_clear_warning_text ; No, clear all warnings | |
263 movff warning_counter,warning_counter_backup ; copy warning_counter | |
264 | |
265 bcf warning_active ; Clear flag | |
266 clrf warning_counter ; Clear counter | |
267 | |
268 ; Warnings for all modes | |
269 call check_warn_battery ; Check if the battery level should be displayed/warned | |
270 call surfmode_check_for_nofly ; Check if nofly time should be shown | |
271 call surfmode_check_for_desat ; Check if desat time should be shown | |
272 call surfmode_check_for_interval ; Check if surface interval should be shown | |
273 | |
274 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
275 bra surfmode_check_for_warnings2 | |
276 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
277 bra surfmode_check_for_warnings2 | |
278 | |
279 ; Warnings only in deco modes | |
280 call check_cns_violation ; Check CNS value and display it, if required | |
281 call check_and_store_gf_violation ; Check GF value and display it, if required | |
282 | |
283 surfmode_check_for_warnings2: | |
284 ; Setup warning_page number | |
285 incf warning_page,F | |
286 bcf STATUS,C | |
287 rlcf warning_page,W ; *2 | |
288 cpfsgt warning_counter ; > warning_counter | |
289 clrf warning_page ; No, clear | |
290 | |
291 ; Clear 2nd row of warnings if there is nothing to show (on this page) | |
292 btfss second_row_warning ; =1: The second row contains a warning | |
293 call TFT_clear_warning_text_2nd_row ; No, clear this row | |
294 return ; Done. | |
295 | |
296 surfmode_check_for_interval: | |
297 movf surface_interval+0,W ; Is interval null ? | |
298 iorwf surface_interval+0,W | |
299 bnz surfmode_check_for_interval2 ; No | |
300 return | |
301 surfmode_check_for_interval2: | |
302 incf warning_counter,F ; increase counter | |
303 call TFT_interval | |
304 return | |
305 | |
306 | |
307 surfmode_check_for_desat: | |
308 movf desaturation_time+0,W ; Is nofly null ? | |
309 iorwf desaturation_time+1,W | |
310 bnz surfmode_check_for_desat2 ; No | |
311 return | |
312 surfmode_check_for_desat2: | |
313 incf warning_counter,F ; increase counter | |
314 call TFT_desaturation_time | |
315 return | |
316 | |
317 surfmode_check_for_nofly: | |
318 movf nofly_time+0,W ; Is nofly null ? | |
319 iorwf nofly_time+1,W | |
320 bnz surfmode_check_for_nofly2 ; No... | |
321 return | |
322 surfmode_check_for_nofly2: | |
323 incf warning_counter,F ; increase counter | |
324 call TFT_nofly_time | |
325 return | |
326 | |
327 | |
328 ;============================================================================= | |
329 global calc_deko_surfmode | |
330 calc_deko_surfmode: | |
331 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy surface air pressure to deco routine | |
332 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode | |
333 banksel common | |
334 return | |
335 | |
336 test_switches_surfmode: ; checks switches in surfacemode | |
337 btfsc switch_right | |
338 bra test_switches_surfmode2 | |
339 btfsc switch_left | |
340 bra test_switches_surfmode3 | |
341 | |
342 ; No button press | |
343 return | |
344 | |
345 test_switches_surfmode3: | |
346 bcf switch_left | |
347 bsf menubit ; Enter Menu! | |
348 return | |
349 | |
350 test_switches_surfmode2: | |
351 bcf switch_right | |
352 bsf toggle_customview | |
353 clrf timeout_counter2 ; and reset timeout | |
354 return | |
355 | |
356 global timeout_surfmode | |
357 timeout_surfmode: | |
358 movlw timeout_surfacemode ; [s] | |
359 global timeout_testmode | |
360 timeout_testmode: | |
361 incf timeout_counter2,F ; increase timeout counter | |
362 cpfsgt timeout_counter2 ; Compare with timeout_counter2 | |
363 return ; return, no timeout | |
364 bsf sleepmode ; Set Flag | |
365 return ; Return | |
366 | |
367 END |