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