Mercurial > public > hwos_code
annotate src/surfmode.asm @ 330:0532cac03ccd new_screen_layout
Merged default into new_screen_layout
author | Janos Kovacs <kovjanos@gmail.com> |
---|---|
date | Wed, 24 Jun 2015 22:19:32 +0200 |
parents | 653a3ab08062 |
children | 5c6da9fa5cb0 |
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 | |
275 | 12 #include "hwos.inc" ; Mandatory header |
0 | 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 | |
47 bcf no_sensor_int ; Normal pressure mode | |
48 | |
245 | 49 bcf LEDg |
50 bcf LEDr | |
51 | |
0 | 52 clrf CCP1CON ; stop PWM |
53 bcf PORTC,2 ; Pull PWM output to GND | |
54 call TFT_boot ; Initialize TFT (includes clear screen) | |
55 bcf restore_deco_data | |
56 | |
57 WIN_TOP .50 | |
58 WIN_LEFT .10 | |
59 movlw LOW 0x1E000 | |
60 movwf TBLPTRL | |
61 movlw HIGH 0x1E000 | |
62 movwf TBLPTRH | |
63 movlw UPPER 0x1E000 | |
64 movwf TBLPTRU | |
65 extern color_image | |
66 call color_image ; Show logo | |
67 | |
68 WIN_TOP .100 | |
69 WIN_LEFT .34 | |
275 | 70 extern ostc_logo_block |
71 movlw LOW(ostc_logo_block) | |
0 | 72 movwf TBLPTRL |
275 | 73 movlw HIGH ostc_logo_block;&0xFFFF |
0 | 74 movwf TBLPTRH |
275 | 75 movlw UPPER(ostc_logo_block) |
0 | 76 movwf TBLPTRU |
77 call color_image | |
78 call TFT_Display_FadeIn ; Show splash | |
79 call TFT_serial ; Show serial and firmware version | |
80 | |
81 ;---- Do any usefull initializes that takes time ------------------------- | |
82 call restart_set_modes_and_flags ; Sets decomode flags | |
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 | |
235
23311219dacc
under construction: new hardware_flag to configure different hardware versions
heinrichsweikamp
parents:
234
diff
changeset
|
90 btfsc rechargeable |
221
90923a081ae7
minor: configure buttons during splash screen
heinrichsweikamp
parents:
213
diff
changeset
|
91 call piezo_config ; Configure buttons |
90923a081ae7
minor: configure buttons during splash screen
heinrichsweikamp
parents:
213
diff
changeset
|
92 |
0 | 93 clrf timeout_counter2 |
94 clrf timeout_counter3 | |
95 bcf menubit ; clear menu flag | |
96 clrf last_pressure+0 | |
97 clrf last_pressure+1 | |
98 bcf is_bailout ; =1: Bailout | |
99 bcf ccr_diluent_setup ; Use OC gases for gaslist routine | |
100 | |
101 bcf simulatormode_active ; Quit simulator mode (if active) | |
102 bcf switch_left | |
103 bcf switch_right | |
104 | |
105 ;---- Fade to standard surface view -------------------------------------- | |
106 ; Wait 1 second | |
107 bcf onesecupdate | |
108 btfss onesecupdate | |
109 bra $-2 | |
110 ; Wait 1 second | |
111 bcf onesecupdate | |
112 btfss onesecupdate | |
113 bra $-2 | |
114 | |
115 call TFT_Display_FadeOut ; Go to black screen | |
116 call TFT_ClearScreen ; Then change everything | |
117 WIN_TOP .0 | |
118 WIN_LEFT .0 | |
119 WIN_FONT FT_SMALL | |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
188
diff
changeset
|
120 bcf win_invert ; Reset invert flag |
0 | 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 | |
275 | 132 movlw LOW(ostc_logo_block) |
0 | 133 movwf TBLPTRL |
275 | 134 movlw HIGH ostc_logo_block;&0xFFFF |
0 | 135 movwf TBLPTRH |
275 | 136 movlw UPPER(ostc_logo_block) |
0 | 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 | |
234
57155164faad
Show OSTC2-like active gas boxes in surface mode
heinrichsweikamp
parents:
233
diff
changeset
|
147 |
232 | 148 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea |
149 tstfsz lo | |
150 bra surfloop_no_oc ; Not OC | |
234
57155164faad
Show OSTC2-like active gas boxes in surface mode
heinrichsweikamp
parents:
233
diff
changeset
|
151 call TFT_show_OC_startgas_surface; Show first gas and "OSTC2-like" active gases |
232 | 152 surfloop_no_oc: |
158 | 153 movff customview_surfmode,menupos3 ; Reload last customview |
154 call surf_customview_mask ; Update #menupos3 view | |
0 | 155 |
156 call TFT_Display_FadeIn ; Display resulting surface screen. | |
157 | |
158 ;---- Late initialisations ----------------------------------------------- | |
159 movff last_surfpressure_30min+0,int_I_pres_respiration+0 ; copy surface air pressure to deco routine | |
160 movff last_surfpressure_30min+1,int_I_pres_respiration+1 ; 30min old values | |
161 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; copy surface air pressure to deco routine | |
162 movff last_surfpressure_30min+1,int_I_pres_surface+1 ; 30min old values | |
163 movff last_surfpressure_30min+0,last_surfpressure+0 ; Use 30min old airpressure | |
164 movff last_surfpressure_30min+1,last_surfpressure+1 ; Use 30min old airpressure | |
165 | |
158 | 166 ; Startup tasks for all modes |
0 | 167 ; Desaturation time needs: |
168 ; int_I_pres_surface | |
169 ; char_I_desaturation_multiplier | |
170 call deco_calc_desaturation_time ; calculate desaturation time | |
171 movlb b'00000001' ; select ram bank 1 | |
172 | |
173 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
174 call enable_rs232 ; Also sets to speed_normal ... | |
175 | |
176 surfloop_loop: | |
177 btfss onesecupdate ; do every second tasks? | |
178 bra surfloop_loop2 ; no, loop | |
179 | |
180 ; One Second tasks for all modes | |
181 call speed_normal | |
182 call TFT_debug_output | |
183 call TFT_clock ; update clock | |
184 call timeout_surfmode ; check timeout | |
185 call get_battery_voltage ; get battery voltage | |
186 call TFT_update_batt_voltage ; display battery voltage | |
187 call set_dive_modes ; tests if depth>threshold | |
188 btfss secs,0 ; Every two seconds... | |
189 call TFT_temp_surfmode ; Displays temperature | |
190 btfss secs,0 ; Every two seconds... | |
191 call surfmode_check_for_warnings ; ... check for warnings (and display/update) them | |
192 | |
193 bcf onesecupdate ; every second tasks done | |
194 | |
195 surfloop_loop2: | |
196 ; Tasks approx. every 50ms for all modes | |
197 call test_switches_surfmode ; check switches | |
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 | |
230
f6548e8f06f5
Bugfix: Check for divemode before checking for menu
mh@mh-THINK
parents:
226
diff
changeset
|
204 btfsc divemode ; Divemode active? |
f6548e8f06f5
Bugfix: Check for divemode before checking for menu
mh@mh-THINK
parents:
226
diff
changeset
|
205 goto diveloop ; Yes, switch into Divemode! |
f6548e8f06f5
Bugfix: Check for divemode before checking for menu
mh@mh-THINK
parents:
226
diff
changeset
|
206 |
0 | 207 btfsc menubit ; Menu? |
208 goto do_main_menu ; Menu! | |
209 | |
210 btfsc pressure_refresh ; new pressure available? | |
211 call TFT_update_surf_press ; display surface pressure | |
212 bcf pressure_refresh ; until new pressure is available | |
213 | |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
214 ; Updates every 1/4 second |
0 | 215 btfss quarter_second_update |
216 bra surfloop_loop2a | |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
217 |
0 | 218 bcf quarter_second_update |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
219 ; Update Sensors |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
220 |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
221 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
|
222 call check_sensors ; Set enable/disable flags |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
223 btfsc FLAG_ccr_mode ; In CCR mode... |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
224 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
|
225 |
0 | 226 movlw .6 |
227 cpfseq menupos3 ; in compass view? | |
228 bra surfloop_loop2a ; No | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
245
diff
changeset
|
229 extern TFT_surface_compass_heading |
0 | 230 call TFT_surface_compass_heading ; Yes, update compass heading value |
231 | |
232 surfloop_loop2a: | |
233 btfsc toggle_customview ; Next view? | |
234 call surf_customview_toggle ; Yes, show next customview (and delete this flag) | |
235 | |
236 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
237 bra surfloop_loop3 | |
238 btfsc vusb_in ; USB plugged in? | |
113 | 239 call comm_mode ; Start COMM mode |
0 | 240 bra surfloop_loop4 |
241 surfloop_loop3: | |
242 btfss vusb_in ; USB (still) plugged in? | |
243 bcf enable_screen_dumps ; No, clear flag | |
244 call rs232_get_byte | |
245 btfsc rs232_recieve_overflow | |
246 bra surfloop_loop4 | |
247 movlw "l" | |
248 cpfseq RCREG1 | |
249 bra surfloop_loop4 | |
250 call TFT_dump_screen ; Dump the screen contents | |
251 surfloop_loop4: | |
252 btfsc sleepmode ; Sleepmode active? | |
253 goto sleeploop ; Yes, switch into sleepmode! | |
254 | |
255 bra surfloop_loop ; loop surfacemode | |
256 | |
257 update_surfloop60: | |
258 ; One minute tasks for all modes | |
259 call TFT_date ; Update date | |
260 call calc_deko_surfmode ; calculate desaturation every minute | |
261 bcf oneminupdate | |
262 return | |
263 | |
264 extern check_cns_violation,check_warn_battery,check_and_store_gf_violation | |
265 surfmode_check_for_warnings: | |
266 movf warning_counter_backup,W | |
267 cpfseq warning_counter ; warning_counter_backup = warning_counter? | |
268 call TFT_clear_warning_text ; No, clear all warnings | |
269 movff warning_counter,warning_counter_backup ; copy warning_counter | |
270 | |
271 bcf warning_active ; Clear flag | |
272 clrf warning_counter ; Clear counter | |
273 | |
274 ; Warnings for all modes | |
275 call check_warn_battery ; Check if the battery level should be displayed/warned | |
205 | 276 rcall surfmode_check_for_nofly ; Check if nofly time should be shown |
277 rcall surfmode_check_for_desat ; Check if desat time should be shown | |
278 rcall surfmode_check_for_interval ; Check if surface interval should be shown | |
0 | 279 |
280 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
281 bra surfmode_check_for_warnings2 | |
282 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
283 bra surfmode_check_for_warnings2 | |
284 | |
285 ; Warnings only in deco modes | |
286 call check_cns_violation ; Check CNS value and display it, if required | |
287 call check_and_store_gf_violation ; Check GF value and display it, if required | |
288 | |
289 surfmode_check_for_warnings2: | |
290 ; Setup warning_page number | |
291 incf warning_page,F | |
292 bcf STATUS,C | |
293 rlcf warning_page,W ; *2 | |
294 cpfsgt warning_counter ; > warning_counter | |
295 clrf warning_page ; No, clear | |
296 | |
297 ; Clear 2nd row of warnings if there is nothing to show (on this page) | |
298 btfss second_row_warning ; =1: The second row contains a warning | |
299 call TFT_clear_warning_text_2nd_row ; No, clear this row | |
300 return ; Done. | |
301 | |
302 surfmode_check_for_interval: | |
303 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
|
304 iorwf surface_interval+1,W |
0 | 305 bnz surfmode_check_for_interval2 ; No |
306 return | |
307 surfmode_check_for_interval2: | |
308 incf warning_counter,F ; increase counter | |
309 call TFT_interval | |
310 return | |
311 | |
312 | |
313 surfmode_check_for_desat: | |
314 movf desaturation_time+0,W ; Is nofly null ? | |
315 iorwf desaturation_time+1,W | |
316 bnz surfmode_check_for_desat2 ; No | |
317 return | |
318 surfmode_check_for_desat2: | |
319 incf warning_counter,F ; increase counter | |
320 call TFT_desaturation_time | |
321 return | |
322 | |
323 surfmode_check_for_nofly: | |
324 movf nofly_time+0,W ; Is nofly null ? | |
325 iorwf nofly_time+1,W | |
326 bnz surfmode_check_for_nofly2 ; No... | |
327 return | |
328 surfmode_check_for_nofly2: | |
329 incf warning_counter,F ; increase counter | |
330 call TFT_nofly_time | |
331 return | |
332 | |
333 | |
334 ;============================================================================= | |
335 global calc_deko_surfmode | |
336 calc_deko_surfmode: | |
337 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy surface air pressure to deco routine | |
338 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode | |
339 banksel common | |
340 return | |
341 | |
342 test_switches_surfmode: ; checks switches in surfacemode | |
343 btfsc switch_right | |
344 bra test_switches_surfmode2 | |
345 btfsc switch_left | |
346 bra test_switches_surfmode3 | |
347 | |
348 ; No button press | |
349 return | |
350 | |
351 test_switches_surfmode3: | |
352 bcf switch_left | |
353 bsf menubit ; Enter Menu! | |
354 return | |
355 | |
356 test_switches_surfmode2: | |
357 bcf switch_right | |
358 bsf toggle_customview | |
359 clrf timeout_counter2 ; and reset timeout | |
360 return | |
361 | |
362 global timeout_surfmode | |
363 timeout_surfmode: | |
188
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
364 movlw timeout_surfacemode ; [s] Default timeout |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
158
diff
changeset
|
365 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
|
366 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
|
367 btfsc menubit ; in Menu? |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
368 bra timeout_testmode ; No, done. |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
369 ; Must be in surface mode |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
370 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
|
371 bra timeout_testmode ; No, not CCR |
ebc28381f17d
NEW: Show Bailout Gas List in Surface mode (CCR Modes)
heinrichsweikamp
parents:
187
diff
changeset
|
372 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
|
373 |
0 | 374 global timeout_testmode |
375 timeout_testmode: | |
376 incf timeout_counter2,F ; increase timeout counter | |
377 cpfsgt timeout_counter2 ; Compare with timeout_counter2 | |
378 return ; return, no timeout | |
379 bsf sleepmode ; Set Flag | |
380 return ; Return | |
381 | |
382 END |