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