Mercurial > public > hwos_code
annotate src/surfmode.asm @ 216:973a0969e0ac
NEW: On-board simulator can increase divetime in 5min steps
author | heinrichsweikamp |
---|---|
date | Mon, 15 Dec 2014 19:50:51 +0100 |
parents | 3b5df65d53fc |
children | 90923a081ae7 |
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 |
213 | 32 extern do_main_menu |
33 | |
0 | 34 #DEFINE menu_pos_row .215 |
213 | 35 #DEFINE menu_pos_column .1 |
0 | 36 #DEFINE view_row .215 |
37 #DEFINE view_column .124 | |
38 | |
39 gui CODE | |
40 | |
41 | |
42 ;============================================================================= | |
43 ; Boot tasks for all modes | |
44 global surfloop | |
45 surfloop: | |
46 call speed_normal | |
200 | 47 btfss cr_hardware |
113 | 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 | |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
188
diff
changeset
|
118 bcf win_invert ; Reset invert flag |
0 | 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 | |
48 | 127 ; Logo |
0 | 128 WIN_TOP .0 |
129 WIN_LEFT .70 | |
130 movlw LOW(ostc3_logo_block) | |
131 movwf TBLPTRL | |
132 movlw HIGH ostc3_logo_block;&0xFFFF | |
133 movwf TBLPTRH | |
134 movlw UPPER(ostc3_logo_block) | |
135 movwf TBLPTRU | |
136 call color_image | |
137 | |
158 | 138 call TFT_clock ; display time |
139 call update_surfloop60 | |
140 call get_battery_voltage ; get battery voltage | |
141 call TFT_update_batt_voltage ; display battery voltage | |
142 call TFT_update_surf_press ; display surface pressure | |
143 call TFT_temp_surfmode ; Displays temperature | |
144 call TFT_display_decotype_surface | |
145 movff customview_surfmode,menupos3 ; Reload last customview | |
146 call surf_customview_mask ; Update #menupos3 view | |
0 | 147 |
148 call TFT_Display_FadeIn ; Display resulting surface screen. | |
149 | |
150 ;---- Late initialisations ----------------------------------------------- | |
151 movff last_surfpressure_30min+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine | |
152 movff last_surfpressure_30min+1,int_I_pres_respiration+1 ; 30min old values | |
153 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine | |
154 movff last_surfpressure_30min+1,int_I_pres_surface+1 ; 30min old values | |
155 movff last_surfpressure_30min+0,last_surfpressure+0 ; Use 30min old airpressure | |
156 movff last_surfpressure_30min+1,last_surfpressure+1 ; Use 30min old airpressure | |
157 | |
158 | 158 ; Startup tasks for all modes |
0 | 159 ; Desaturation time needs: |
160 ; int_I_pres_surface | |
161 ; char_I_desaturation_multiplier | |
162 call deco_calc_desaturation_time ; calculate desaturation time | |
163 movlb b'00000001' ; select ram bank 1 | |
164 | |
165 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
166 call enable_rs232 ; Also sets to speed_normal ... | |
167 | |
168 surfloop_loop: | |
169 btfss onesecupdate ; do every second tasks? | |
170 bra surfloop_loop2 ; no, loop | |
171 | |
172 ; One Second tasks for all modes | |
173 call speed_normal | |
174 call TFT_debug_output | |
175 call TFT_clock ; update clock | |
176 call timeout_surfmode ; check timeout | |
177 call get_battery_voltage ; get battery voltage | |
178 call TFT_update_batt_voltage ; display battery voltage | |
179 call set_dive_modes ; tests if depth>threshold | |
180 btfss secs,0 ; Every two seconds... | |
181 call TFT_temp_surfmode ; Displays temperature | |
182 btfss secs,0 ; Every two seconds... | |
183 call surfmode_check_for_warnings ; ... check for warnings (and display/update) them | |
184 | |
185 bcf onesecupdate ; every second tasks done | |
186 | |
187 surfloop_loop2: | |
188 ; Tasks approx. every 50ms for all modes | |
189 call test_switches_surfmode ; check switches | |
190 | |
191 ; One minute tasks for all modes | |
192 btfsc oneminupdate ; do every minute tasks | |
193 call update_surfloop60 ; yes, e.g. update time and date | |
194 | |
195 ; Mode tasks | |
196 btfsc menubit ; Menu? | |
197 goto do_main_menu ; Menu! | |
198 | |
199 btfsc pressure_refresh ; new pressure available? | |
200 call TFT_update_surf_press ; display surface pressure | |
201 bcf pressure_refresh ; until new pressure is available | |
202 | |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
203 ; Updates every 1/4 second |
0 | 204 btfss quarter_second_update |
205 bra surfloop_loop2a | |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
206 |
0 | 207 bcf quarter_second_update |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
208 ; Update Sensors |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
209 |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
210 call compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
211 call check_sensors ; Set enable/disable flags |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
212 btfsc FLAG_ccr_mode ; In CCR mode... |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
213 call TFT_surface_sensor ; ...update sensor data in surface mode |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
214 |
0 | 215 movlw .6 |
216 cpfseq menupos3 ; in compass view? | |
217 bra surfloop_loop2a ; No | |
218 call TFT_surface_compass_heading ; Yes, update compass heading value | |
219 | |
220 surfloop_loop2a: | |
221 btfsc toggle_customview ; Next view? | |
222 call surf_customview_toggle ; Yes, show next customview (and delete this flag) | |
223 | |
224 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
225 bra surfloop_loop3 | |
226 btfsc vusb_in ; USB plugged in? | |
113 | 227 call comm_mode ; Start COMM mode |
0 | 228 bra surfloop_loop4 |
229 surfloop_loop3: | |
230 btfss vusb_in ; USB (still) plugged in? | |
231 bcf enable_screen_dumps ; No, clear flag | |
232 call rs232_get_byte | |
233 btfsc rs232_recieve_overflow | |
234 bra surfloop_loop4 | |
235 movlw "l" | |
236 cpfseq RCREG1 | |
237 bra surfloop_loop4 | |
238 call TFT_dump_screen ; Dump the screen contents | |
239 surfloop_loop4: | |
240 btfsc divemode ; Divemode active? | |
241 goto diveloop ; Yes, switch into Divemode! | |
242 btfsc sleepmode ; Sleepmode active? | |
243 goto sleeploop ; Yes, switch into sleepmode! | |
244 | |
245 bra surfloop_loop ; loop surfacemode | |
246 | |
247 update_surfloop60: | |
248 ; One minute tasks for all modes | |
249 call TFT_date ; Update date | |
250 call calc_deko_surfmode ; calculate desaturation every minute | |
251 bcf oneminupdate | |
252 return | |
253 | |
254 extern check_cns_violation,check_warn_battery,check_and_store_gf_violation | |
255 surfmode_check_for_warnings: | |
256 movf warning_counter_backup,W | |
257 cpfseq warning_counter ; warning_counter_backup = warning_counter? | |
258 call TFT_clear_warning_text ; No, clear all warnings | |
259 movff warning_counter,warning_counter_backup ; copy warning_counter | |
260 | |
261 bcf warning_active ; Clear flag | |
262 clrf warning_counter ; Clear counter | |
263 | |
264 ; Warnings for all modes | |
265 call check_warn_battery ; Check if the battery level should be displayed/warned | |
205 | 266 rcall surfmode_check_for_nofly ; Check if nofly time should be shown |
267 rcall surfmode_check_for_desat ; Check if desat time should be shown | |
268 rcall surfmode_check_for_interval ; Check if surface interval should be shown | |
0 | 269 |
270 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
271 bra surfmode_check_for_warnings2 | |
272 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
273 bra surfmode_check_for_warnings2 | |
274 | |
275 ; Warnings only in deco modes | |
276 call check_cns_violation ; Check CNS value and display it, if required | |
277 call check_and_store_gf_violation ; Check GF value and display it, if required | |
278 | |
279 surfmode_check_for_warnings2: | |
280 ; Setup warning_page number | |
281 incf warning_page,F | |
282 bcf STATUS,C | |
283 rlcf warning_page,W ; *2 | |
284 cpfsgt warning_counter ; > warning_counter | |
285 clrf warning_page ; No, clear | |
286 | |
287 ; Clear 2nd row of warnings if there is nothing to show (on this page) | |
288 btfss second_row_warning ; =1: The second row contains a warning | |
289 call TFT_clear_warning_text_2nd_row ; No, clear this row | |
290 return ; Done. | |
291 | |
292 surfmode_check_for_interval: | |
293 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
|
294 iorwf surface_interval+1,W |
0 | 295 bnz surfmode_check_for_interval2 ; No |
296 return | |
297 surfmode_check_for_interval2: | |
298 incf warning_counter,F ; increase counter | |
299 call TFT_interval | |
300 return | |
301 | |
302 | |
303 surfmode_check_for_desat: | |
304 movf desaturation_time+0,W ; Is nofly null ? | |
305 iorwf desaturation_time+1,W | |
306 bnz surfmode_check_for_desat2 ; No | |
307 return | |
308 surfmode_check_for_desat2: | |
309 incf warning_counter,F ; increase counter | |
310 call TFT_desaturation_time | |
311 return | |
312 | |
313 surfmode_check_for_nofly: | |
314 movf nofly_time+0,W ; Is nofly null ? | |
315 iorwf nofly_time+1,W | |
316 bnz surfmode_check_for_nofly2 ; No... | |
317 return | |
318 surfmode_check_for_nofly2: | |
319 incf warning_counter,F ; increase counter | |
320 call TFT_nofly_time | |
321 return | |
322 | |
323 | |
324 ;============================================================================= | |
325 global calc_deko_surfmode | |
326 calc_deko_surfmode: | |
327 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy surface air pressure to deco routine | |
328 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode | |
329 banksel common | |
330 return | |
331 | |
332 test_switches_surfmode: ; checks switches in surfacemode | |
333 btfsc switch_right | |
334 bra test_switches_surfmode2 | |
335 btfsc switch_left | |
336 bra test_switches_surfmode3 | |
337 | |
338 ; No button press | |
339 return | |
340 | |
341 test_switches_surfmode3: | |
342 bcf switch_left | |
343 bsf menubit ; Enter Menu! | |
344 return | |
345 | |
346 test_switches_surfmode2: | |
347 bcf switch_right | |
348 bsf toggle_customview | |
349 clrf timeout_counter2 ; and reset timeout | |
350 return | |
351 | |
352 global timeout_surfmode | |
353 timeout_surfmode: | |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
354 movlw timeout_surfacemode ; [s] Default timeout |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
355 btfsc menu_show_sensors2 ; In the "Calibrate" menu? |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
356 movlw timeout_calibrate_menu ; [s] CCR Calibrate Menu timeout |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
357 btfsc menubit ; in Menu? |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
358 bra timeout_testmode ; No, done. |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
359 ; Must be in surface mode |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
360 btfss FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
361 bra timeout_testmode ; No, not CCR |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
362 movlw timeout_ccr_surface ; [s] CCR Surface mode timeout |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
363 |
0 | 364 global timeout_testmode |
365 timeout_testmode: | |
366 incf timeout_counter2,F ; increase timeout counter | |
367 cpfsgt timeout_counter2 ; Compare with timeout_counter2 | |
368 return ; return, no timeout | |
369 bsf sleepmode ; Set Flag | |
370 return ; Return | |
371 | |
372 END |