Mercurial > public > hwos_code
annotate src/surfmode.asm @ 57:130719108ccf
minor
author | heinrichsweikamp |
---|---|
date | Wed, 02 Oct 2013 08:32:35 +0200 |
parents | ec4d8503ec45 |
children | a5ea132770db |
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 premenu ; clear premenu flag | |
90 bcf menubit ; clear menu flag | |
91 clrf last_pressure+0 | |
92 clrf last_pressure+1 | |
93 bcf is_bailout ; =1: Bailout | |
94 bcf ccr_diluent_setup ; Use OC gases for gaslist routine | |
95 | |
96 bcf simulatormode_active ; Quit simulator mode (if active) | |
97 bcf switch_left | |
98 bcf switch_right | |
99 bcf LEDg | |
100 bcf LEDr | |
101 | |
102 ;---- Fade to standard surface view -------------------------------------- | |
103 ; Wait 1 second | |
104 bcf onesecupdate | |
105 btfss onesecupdate | |
106 bra $-2 | |
107 ; Wait 1 second | |
108 bcf onesecupdate | |
109 btfss onesecupdate | |
110 bra $-2 | |
111 | |
112 call TFT_Display_FadeOut ; Go to black screen | |
113 call TFT_ClearScreen ; Then change everything | |
114 WIN_TOP .0 | |
115 WIN_LEFT .0 | |
116 WIN_FONT FT_SMALL | |
117 WIN_INVERT .0 ; Init new Wordprocessor | |
118 | |
119 ; call TFT_user_image ; Show the user image/text | |
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 | |
128 call TFT_clock ; display time | |
129 call update_surfloop60 | |
130 call get_battery_voltage ; get battery voltage | |
131 call TFT_update_batt_voltage ; display battery voltage | |
132 call TFT_update_surf_press ; display surface pressure | |
133 call TFT_temp_surfmode ; Displays temperature | |
134 call TFT_display_decotype_surface | |
39
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
0
diff
changeset
|
135 movff customview_surfmode,menupos3 ; Reload last customview |
0 | 136 call surf_customview_mask ; Update #menupos3 view |
137 | |
48 | 138 ; Logo |
0 | 139 WIN_TOP .0 |
140 WIN_LEFT .70 | |
141 movlw LOW(ostc3_logo_block) | |
142 movwf TBLPTRL | |
143 movlw HIGH ostc3_logo_block;&0xFFFF | |
144 movwf TBLPTRH | |
145 movlw UPPER(ostc3_logo_block) | |
146 movwf TBLPTRU | |
147 call color_image | |
148 | |
149 btfsc FLAG_apnoe_mode ; Ignore in Apnoe mode | |
150 bra surfloop1 | |
151 btfsc FLAG_gauge_mode ; Ignore in Gauge mode | |
152 bra surfloop1 | |
153 | |
154 surfloop1: | |
155 call TFT_Display_FadeIn ; Display resulting surface screen. | |
156 | |
157 ;---- Late initialisations ----------------------------------------------- | |
158 movff last_surfpressure_30min+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine | |
159 movff last_surfpressure_30min+1,int_I_pres_respiration+1 ; 30min old values | |
160 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine | |
161 movff last_surfpressure_30min+1,int_I_pres_surface+1 ; 30min old values | |
162 movff last_surfpressure_30min+0,last_surfpressure+0 ; Use 30min old airpressure | |
163 movff last_surfpressure_30min+1,last_surfpressure+1 ; Use 30min old airpressure | |
164 | |
165 extern do_demo_divemode | |
166 ; goto do_demo_divemode | |
167 | |
168 ; Startup tasks for all modes | |
169 ; Desaturation time needs: | |
170 ; int_I_pres_surface | |
171 ; char_I_desaturation_multiplier | |
172 call deco_calc_desaturation_time ; calculate desaturation time | |
173 movlb b'00000001' ; select ram bank 1 | |
174 | |
175 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
176 call enable_rs232 ; Also sets to speed_normal ... | |
177 | |
178 surfloop_loop: | |
179 btfss onesecupdate ; do every second tasks? | |
180 bra surfloop_loop2 ; no, loop | |
181 | |
182 ; One Second tasks for all modes | |
183 call speed_normal | |
184 call TFT_debug_output | |
185 call TFT_clock ; update clock | |
186 call timeout_surfmode ; check timeout | |
187 call get_battery_voltage ; get battery voltage | |
188 call TFT_update_batt_voltage ; display battery voltage | |
189 call timeout_premenu ; timeout premenu | |
190 call set_dive_modes ; tests if depth>threshold | |
191 btfss secs,0 ; Every two seconds... | |
192 call TFT_temp_surfmode ; Displays temperature | |
193 btfss secs,0 ; Every two seconds... | |
194 call surfmode_check_for_warnings ; ... check for warnings (and display/update) them | |
195 | |
196 btfsc FLAG_ccr_mode ; In CCR mode... | |
197 call TFT_surface_hud ; ...update HUD data in surface mode | |
198 | |
199 bcf onesecupdate ; every second tasks done | |
200 | |
201 surfloop_loop2: | |
202 ; Tasks approx. every 50ms for all modes | |
203 call test_switches_surfmode ; check switches | |
204 call speed_normal | |
205 | |
206 ; One minute tasks for all modes | |
207 btfsc oneminupdate ; do every minute tasks | |
208 call update_surfloop60 ; yes, e.g. update time and date | |
209 | |
210 ; Mode tasks | |
211 btfsc menubit ; Menu? | |
212 goto do_main_menu ; Menu! | |
213 | |
214 btfsc pressure_refresh ; new pressure available? | |
215 call TFT_update_surf_press ; display surface pressure | |
216 bcf pressure_refresh ; until new pressure is available | |
217 | |
218 btfss quarter_second_update | |
219 bra surfloop_loop2a | |
220 bcf quarter_second_update | |
221 movlw .6 | |
222 cpfseq menupos3 ; in compass view? | |
223 bra surfloop_loop2a ; No | |
224 call TFT_surface_compass_heading ; Yes, update compass heading value | |
225 | |
226 surfloop_loop2a: | |
227 btfsc toggle_customview ; Next view? | |
228 call surf_customview_toggle ; Yes, show next customview (and delete this flag) | |
229 | |
230 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
231 bra surfloop_loop3 | |
232 btfsc vusb_in ; USB plugged in? | |
233 goto comm_mode ; Start COMM mode | |
234 bra surfloop_loop4 | |
235 surfloop_loop3: | |
236 btfss vusb_in ; USB (still) plugged in? | |
237 bcf enable_screen_dumps ; No, clear flag | |
238 call rs232_get_byte | |
239 btfsc rs232_recieve_overflow | |
240 bra surfloop_loop4 | |
241 movlw "l" | |
242 cpfseq RCREG1 | |
243 bra surfloop_loop4 | |
244 call TFT_dump_screen ; Dump the screen contents | |
245 surfloop_loop4: | |
246 btfsc divemode ; Divemode active? | |
247 goto diveloop ; Yes, switch into Divemode! | |
248 btfsc sleepmode ; Sleepmode active? | |
249 goto sleeploop ; Yes, switch into sleepmode! | |
250 | |
251 bra surfloop_loop ; loop surfacemode | |
252 | |
253 update_surfloop60: | |
254 ; One minute tasks for all modes | |
255 call TFT_date ; Update date | |
256 call calc_deko_surfmode ; calculate desaturation every minute | |
257 bcf oneminupdate | |
258 return | |
259 | |
260 extern check_cns_violation,check_warn_battery,check_and_store_gf_violation | |
261 surfmode_check_for_warnings: | |
262 movf warning_counter_backup,W | |
263 cpfseq warning_counter ; warning_counter_backup = warning_counter? | |
264 call TFT_clear_warning_text ; No, clear all warnings | |
265 movff warning_counter,warning_counter_backup ; copy warning_counter | |
266 | |
267 bcf warning_active ; Clear flag | |
268 clrf warning_counter ; Clear counter | |
269 | |
270 ; Warnings for all modes | |
271 call check_warn_battery ; Check if the battery level should be displayed/warned | |
272 call surfmode_check_for_nofly ; Check if nofly time should be shown | |
273 call surfmode_check_for_desat ; Check if desat time should be shown | |
274 call surfmode_check_for_interval ; Check if surface interval should be shown | |
275 | |
276 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
277 bra surfmode_check_for_warnings2 | |
278 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
279 bra surfmode_check_for_warnings2 | |
280 | |
281 ; Warnings only in deco modes | |
282 call check_cns_violation ; Check CNS value and display it, if required | |
283 call check_and_store_gf_violation ; Check GF value and display it, if required | |
284 | |
285 surfmode_check_for_warnings2: | |
286 ; Setup warning_page number | |
287 incf warning_page,F | |
288 bcf STATUS,C | |
289 rlcf warning_page,W ; *2 | |
290 cpfsgt warning_counter ; > warning_counter | |
291 clrf warning_page ; No, clear | |
292 | |
293 ; Clear 2nd row of warnings if there is nothing to show (on this page) | |
294 btfss second_row_warning ; =1: The second row contains a warning | |
295 call TFT_clear_warning_text_2nd_row ; No, clear this row | |
296 return ; Done. | |
297 | |
298 surfmode_check_for_interval: | |
299 movf surface_interval+0,W ; Is interval null ? | |
300 iorwf surface_interval+0,W | |
301 bnz surfmode_check_for_interval2 ; No | |
302 return | |
303 surfmode_check_for_interval2: | |
304 incf warning_counter,F ; increase counter | |
305 call TFT_interval | |
306 return | |
307 | |
308 | |
309 surfmode_check_for_desat: | |
310 movf desaturation_time+0,W ; Is nofly null ? | |
311 iorwf desaturation_time+1,W | |
312 bnz surfmode_check_for_desat2 ; No | |
313 return | |
314 surfmode_check_for_desat2: | |
315 incf warning_counter,F ; increase counter | |
316 call TFT_desaturation_time | |
317 return | |
318 | |
319 surfmode_check_for_nofly: | |
320 movf nofly_time+0,W ; Is nofly null ? | |
321 iorwf nofly_time+1,W | |
322 bnz surfmode_check_for_nofly2 ; No... | |
323 return | |
324 surfmode_check_for_nofly2: | |
325 incf warning_counter,F ; increase counter | |
326 call TFT_nofly_time | |
327 return | |
328 | |
329 | |
330 ;============================================================================= | |
331 global calc_deko_surfmode | |
332 calc_deko_surfmode: | |
333 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy surface air pressure to deco routine | |
334 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode | |
335 banksel common | |
336 return | |
337 | |
338 timeout_premenu: | |
339 btfsc premenu ; is "<Menu" displayed? | |
340 bra timeout_premenu1 ; Yes | |
341 return | |
342 | |
343 timeout_premenu1: | |
344 incf timeout_counter3,F ; Yes... | |
345 movlw d'2' | |
346 cpfsgt timeout_counter3 ; ... longer then premenu_timeout | |
347 return ; No! | |
348 | |
349 bcf premenu ; Yes, so clear "Menu?" and clear pre_menu bit | |
350 | |
351 WIN_SMALL menu_pos_column,menu_pos_row | |
352 WIN_COLOR color_lightblue | |
353 STRCPY_TEXT_PRINT tMenu ; "<Menu" | |
354 call TFT_standard_color | |
355 clrf timeout_counter3 ; Also clear timeout | |
356 bcf switch_left ; and debounce switches | |
357 bcf switch_right | |
358 return | |
359 | |
360 test_switches_surfmode: ; checks switches in surfacemode | |
361 btfsc switch_right | |
362 bra test_switches_surfmode2 | |
363 btfsc switch_left | |
364 bra test_switches_surfmode3 | |
365 | |
366 ; No button press | |
367 return | |
368 | |
369 test_switches_surfmode3: | |
370 bcf switch_left | |
371 btfss premenu | |
372 bra test_switches_surfmode4 | |
373 bsf menubit ; Enter Menu! | |
374 return | |
375 | |
376 test_switches_surfmode4: | |
377 WIN_COLOR color_lightblue | |
378 WIN_SMALL view_column,view_row | |
379 STRCPY_TEXT_PRINT tView ;"View" | |
380 WIN_SMALL menu_pos_column,menu_pos_row | |
381 call TFT_standard_color | |
382 WIN_INVERT .1 ; Init new Wordprocessor | |
383 STRCPY_TEXT_PRINT tMenu ;"<Menu" | |
384 WIN_INVERT .0 ; Init new Wordprocessor | |
385 bsf premenu | |
386 clrf timeout_counter2 | |
387 return | |
388 | |
389 test_switches_surfmode2: | |
390 bcf switch_right | |
391 bsf toggle_customview | |
392 clrf timeout_counter2 ; and reset timeout | |
393 return | |
394 | |
395 test_switches_surfmode5: | |
396 WIN_SMALL menu_pos_column,menu_pos_row | |
397 WIN_COLOR color_lightblue | |
398 STRCPY_TEXT_PRINT tMenu ;"<Menu" | |
399 call TFT_standard_color | |
400 bcf premenu | |
401 clrf timeout_counter2 | |
402 return | |
403 | |
404 global timeout_surfmode | |
405 timeout_surfmode: | |
406 movlw timeout_surfacemode ; [s] | |
407 global timeout_testmode | |
408 timeout_testmode: | |
409 incf timeout_counter2,F ; increase timeout counter | |
410 cpfsgt timeout_counter2 ; Compare with timeout_counter2 | |
411 return ; return, no timeout | |
412 bsf sleepmode ; Set Flag | |
413 return ; Return | |
414 | |
415 END |