Mercurial > public > mk2
comparison code_part1/OSTC_code_asm_part1/menu_logbook.asm @ 0:96a35aeda5f2
Initial setup
author | heinrichsweikamp |
---|---|
date | Tue, 12 Jan 2010 15:05:59 +0100 |
parents | |
children | 3cf8af30b36e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:96a35aeda5f2 |
---|---|
1 | |
2 ; OSTC - diving computer code | |
3 ; Copyright (C) 2008 HeinrichsWeikamp GbR | |
4 | |
5 ; This program is free software: you can redistribute it and/or modify | |
6 ; it under the terms of the GNU General Public License as published by | |
7 ; the Free Software Foundation, either version 3 of the License, or | |
8 ; (at your option) any later version. | |
9 | |
10 ; This program is distributed in the hope that it will be useful, | |
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 ; GNU General Public License for more details. | |
14 | |
15 ; You should have received a copy of the GNU General Public License | |
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | |
18 | |
19 ; Menu "Logbook" | |
20 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
21 ; written: 060107 | |
22 ; last updated: 081026 | |
23 ; known bugs: | |
24 ; ToDo: | |
25 | |
26 ; searches external EEPROM for dive headers and displays them in a list | |
27 ; a detailed view with all informations and profile can be selected | |
28 ; does not require a FAT, will work with other profile intervals as ten seconds, too | |
29 | |
30 menu_logbook: | |
31 bcf return_from_profileview ; clear some flags | |
32 ;call enable_rs232 | |
33 menu_logbook1: | |
34 bcf logbook_header_drawn | |
35 call PLED_ClearScreen ; Clear screen | |
36 bcf all_dives_shown ; clear some flags | |
37 bcf logbook_profile_view | |
38 bcf logbook_page_not_empty | |
39 clrf menupos3 ; Here: used rows on current logbook-page | |
40 clrf menupos2 ; Here: # of current displayed page | |
41 clrf divenumber ; # of dive in list during search | |
42 | |
43 | |
44 menu_logbook1a: | |
45 WIN_INVERT .1 | |
46 DISPLAYTEXT .12 ;" Wait.." | |
47 WIN_INVERT .0 | |
48 clrf divemins+0 ; Here: used as temp variables | |
49 clrf divemins+1 | |
50 call I2CReset ; Reset I2C Bus | |
51 call get_free_EEPROM_location ; search from "here" backwards through the external memory | |
52 clrf temp1 ; max. 32KB | |
53 clrf temp2 | |
54 | |
55 movlw d'5' | |
56 movwf menupos ; Here: stores current position on display (5-x) | |
57 | |
58 menu_logbook1b: | |
59 ; search external EEPROM backwards from eeprom_address | |
60 ; for 0xFA, 0xFA (store 1st. 0xFA position for next search) | |
61 ; read header data and display it | |
62 ; wait for user to confirm/exit | |
63 ; recopy data to search from here | |
64 WIN_INVERT .1 | |
65 DISPLAYTEXT .12 ;" Wait.." | |
66 WIN_INVERT .0 | |
67 bcf first_FA ; clear flags | |
68 bcf second_FA | |
69 | |
70 menu_logbook2: | |
71 movlw d'1' ; increase 16Bit value | |
72 addwf divemins+0,F | |
73 movlw d'0' | |
74 addwfc divemins+1,F | |
75 | |
76 btfsc divemins+1,7 ; At 0x8000? | |
77 bra menu_logbook_reset ; yes, restart (if not empty) | |
78 | |
79 decf_eeprom_address d'1' ; Macro, that subtracts 8Bit from eeprom_address:2 with banking at 0x8000 | |
80 | |
81 call I2CREAD ; reads one byte (Slow! Better use Blockread!) | |
82 | |
83 btfsc first_FA ; | |
84 bra test_2nd_FA | |
85 | |
86 bsf first_FA ; Found 1st. 0xFA? | |
87 movlw 0xFA | |
88 cpfseq SSPBUF | |
89 bcf first_FA ; No, clear flag | |
90 bra menu_logbook3 ; and continue search | |
91 | |
92 test_2nd_FA: | |
93 btfsc second_FA | |
94 bra test_FA_DONE | |
95 | |
96 bsf second_FA ; found 2nd 0xFA? | |
97 movlw 0xFA | |
98 cpfseq SSPBUF | |
99 rcall no_second_FA ; No, clear both flags! | |
100 bra menu_logbook3 ; and continue search | |
101 | |
102 test_FA_DONE: ; Found 0xFA 0xFA! | |
103 movff eeprom_address+0,eeprom_header_address+0 ; store current address into temp register | |
104 movff eeprom_address+1,eeprom_header_address+1 ; we must continue search here later | |
105 incf divenumber,F ; new header found, increase divenumber | |
106 bra menu_logbook4 ; Done with searching, display the header! | |
107 | |
108 no_second_FA: ; discard both flags! | |
109 bcf second_FA | |
110 bcf first_FA | |
111 return | |
112 | |
113 | |
114 menu_logbook3: | |
115 movlw d'1' ; increase global counter | |
116 addwf temp1,F | |
117 movlw d'0' | |
118 addwfc temp2,F | |
119 | |
120 btfsc temp2,7 ; 32KB searched? | |
121 bra menu_logbook3b ; Yes | |
122 bra menu_logbook2 ; No, not now | |
123 | |
124 | |
125 menu_logbook3b: | |
126 btfss logbook_page_not_empty ; Was there at least one dive? | |
127 goto menu ; Not a single header was found, leave logbook. | |
128 bra menu_logbook_display_loop2 ; rcall of get_free_eeprom_location not required here (faster) | |
129 | |
130 menu_logbook_reset: | |
131 movf divenumber,W | |
132 btfsc STATUS,Z ; Was there at least one dive? | |
133 bra menu_logbook3b ; No, Nothing to do | |
134 | |
135 bsf all_dives_shown ; Yes | |
136 bra menu_logbook_display_loop2 ; rcall of get_free_eeprom_location not required here (faster) | |
137 | |
138 | |
139 menu_logbook4: | |
140 ; Adjust eeprom_address to set pointer on first headerbyte | |
141 incf_eeprom_address d'3' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000 | |
142 | |
143 btfss logbook_profile_view ; Display profile (search routine is used in profileview, too) | |
144 bra menu_logbook_display_loop ; No, display overwiev list | |
145 | |
146 movf divesecs,W ; divenumber that is searched | |
147 cpfseq divenumber ; current divenumber | |
148 bra next_logbook ; No match, continue search | |
149 bra display_profile2 | |
150 | |
151 | |
152 menu_logbook_display_loop: | |
153 btfsc all_dives_shown ; All dives displayed? | |
154 bra menu_logbook_display_loop2 ; Yes, but display first page again. | |
155 | |
156 rcall display_listdive ; display short header for list on current list position | |
157 | |
158 movlw d'5' | |
159 cpfseq menupos ; first dive on list (top place)? | |
160 bra menu_logbook_display_loop1 ; no, so skip saving of address | |
161 | |
162 | |
163 movff divenumber,mintemp+0 ; store all registered required to rebuilt the current logbookpage after the detail/profile view | |
164 movff eeprom_header_address+0,decodata+0 ; several registers are used as temp registers here | |
165 movff eeprom_header_address+1,decodata+1 | |
166 movff divemins+0,max_pressure+0 | |
167 movff divemins+1,max_pressure+1 | |
168 movff temp1,logbook_temp6 | |
169 movff temp2,samplesecs | |
170 | |
171 movlw d'3' | |
172 addwf decodata+0,F | |
173 movlw d'0' | |
174 addwfc decodata+1,F ; Re-Adjust pointer again | |
175 movlw d'3' ; So first row will be the same again after detail/profile view | |
176 subwf max_pressure+0,F | |
177 movlw d'0' | |
178 subwfb max_pressure+1,F | |
179 | |
180 menu_logbook_display_loop1: | |
181 decfsz menupos,F ; List full? | |
182 bra next_logbook ; no, search another dive for our current logbook page | |
183 | |
184 menu_logbook_display_loop2: | |
185 btfss logbook_page_not_empty ; Was there one dive at all? | |
186 bra menu_logbook ; Yes, so reload the first page | |
187 | |
188 call PLED_topline_box ; Draw box | |
189 WIN_INVERT .1 | |
190 DISPLAYTEXT .26 ; "Logbook" | |
191 WIN_INVERT .0 | |
192 | |
193 DISPLAYTEXT .11 ; Displays "Exit" in the last row on the current page | |
194 | |
195 bcf sleepmode ; clear some flags for user input | |
196 bcf menubit2 | |
197 bcf menubit3 | |
198 bcf cursor | |
199 bcf switch_right | |
200 bcf switch_left | |
201 clrf timeout_counter2 | |
202 | |
203 movlw d'1' ; Set cursor to position 1... | |
204 btfsc return_from_profileview ; .. unless we are returning from a detail/profile view | |
205 movf mintemp+1,W ; load last cursor position again | |
206 movwf menupos ; and set menupos byte | |
207 bcf return_from_profileview ; Do this only once while the page is loaded again! | |
208 | |
209 bcf logbook_page_not_empty ; Obviously the current page is NOT empty | |
210 call PLED_logbook_cursor | |
211 | |
212 menu_logbook_loop: | |
213 call check_switches_logbook | |
214 | |
215 btfsc menubit3 ; SET/MENU? | |
216 bra next_logbook3 ; adjust cursor or create new page | |
217 | |
218 btfsc menubit2 ; ENTER? | |
219 bra display_profile_or_exit ; view details/profile or exit logbook | |
220 | |
221 btfsc onesecupdate | |
222 call timeout_surfmode ; Timeout | |
223 | |
224 btfsc onesecupdate | |
225 call set_dive_modes ; Check, if divemode must be entered | |
226 | |
227 bcf onesecupdate ; one second update | |
228 | |
229 btfsc sleepmode ; Timeout? | |
230 goto menu ; Yes | |
231 | |
232 btfsc divemode | |
233 goto restart ; Enter Divemode if required | |
234 | |
235 bra menu_logbook_loop ; Wait for something to do | |
236 | |
237 display_profile_or_exit: | |
238 bcf menubit2 ; debounce | |
239 movlw d'6' ; exit? | |
240 cpfseq menupos | |
241 bra display_profile ; No, show details/profile | |
242 goto menu | |
243 | |
244 display_profile: | |
245 movff menupos,mintemp+1 ; store current cursor position | |
246 bsf return_from_profileview ; tweak search routine to exit after found | |
247 | |
248 movf menupos2,W ; Number of page | |
249 mullw d'5' | |
250 movf PRODL,W | |
251 addwf menupos,W ; page*5+menupos= | |
252 movwf divesecs ; # of dive to search | |
253 | |
254 call PLED_ClearScreen ; search for dive | |
255 bsf logbook_profile_view ; set flag for search routine | |
256 | |
257 clrf divenumber ; search from scratch | |
258 bra menu_logbook1a ; start search | |
259 display_profile2: | |
260 bcf logbook_profile_view ; clear flag for search routine | |
261 | |
262 call PLED_display_wait_clear | |
263 WIN_TOP .0 | |
264 WIN_LEFT .0 | |
265 lfsr FSR2,letter | |
266 movlw '#' | |
267 movwf POSTINC2 | |
268 | |
269 GETCUSTOM15 .28 ; Logbook Offset -> lo, hi | |
270 tstfsz lo ; lo=0? | |
271 bra display_profile_offset1 ; No, adjust offset | |
272 tstfsz hi ; hi=0? | |
273 bra display_profile_offset1 ; No, adjust offset | |
274 bra display_profile_offset2 ; lo=0 and hi=0 -> skip Offset routine | |
275 | |
276 display_profile_offset1: | |
277 movlw d'1' | |
278 addwf lo,F | |
279 movlw d'0' | |
280 addwfc hi,F ; hi:lo = hi:lo + 1 | |
281 movff lo,sub_a+0 | |
282 movff hi,sub_a+1 | |
283 movff divesecs,sub_b+0 | |
284 clrf sub_b+1 | |
285 call sub16 ; sub_c = sub_a - sub_b | |
286 movff sub_c+0,lo | |
287 movff sub_c+1,hi | |
288 bsf leftbind | |
289 output_16dp d'10' ; # of dive with offset | |
290 bra display_profile_offset3 ; Skip normal routine | |
291 | |
292 display_profile_offset2: | |
293 movff divesecs,lo | |
294 output_99x ; # of dive | |
295 | |
296 display_profile_offset3: | |
297 movlw ' ' | |
298 movwf POSTINC2 | |
299 call I2CREAD2 | |
300 movff SSPBUF,lo ; | |
301 | |
302 call I2CREAD2 ; Skip Profile version | |
303 movff SSPBUF,lo ; read month | |
304 | |
305 movff eeprom_address+0, EventByte ; Store current EEPROM position | |
306 movff eeprom_address+1, ProfileFlagByte | |
307 ; Offset to SamplingRate | |
308 incf_eeprom_address d'32' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000 | |
309 call I2CREAD ; Read Sampling rate | |
310 movff SSPBUF,samplesecs_value ; Copy sampling rate | |
311 | |
312 movff EventByte, eeprom_address+0 ; Re-Store current EEPROM position | |
313 movff ProfileFlagByte, eeprom_address+1 ; Re-Store current EEPROM position | |
314 | |
315 ;display_profile2a: | |
316 | |
317 movff lo,convert_value_temp+0 ; Month (in lo, see above) | |
318 call I2CREAD2 ; Day | |
319 movff SSPBUF,convert_value_temp+1 | |
320 call I2CREAD2 ; Year | |
321 movff SSPBUF,convert_value_temp+2 | |
322 call PLED_convert_date ; converts into "DD/MM/YY" or "MM/DD/YY" or "YY/MM/DD" in postinc2 | |
323 | |
324 movlw ' ' | |
325 movwf POSTINC2 | |
326 call I2CREAD2 ; hour | |
327 movff SSPBUF,lo | |
328 output_99x | |
329 movlw ':' | |
330 movwf POSTINC2 | |
331 call I2CREAD2 ; Minute | |
332 movff SSPBUF,lo | |
333 output_99x | |
334 call word_processor ; Display 1st row of details | |
335 | |
336 WIN_TOP .25 | |
337 WIN_LEFT .05 | |
338 lfsr FSR2,letter | |
339 call I2CREAD2 | |
340 movff SSPBUF,lo | |
341 call I2CREAD2 | |
342 movff SSPBUF,hi | |
343 movff lo,xA+0 ; calculate y-scale for profile display | |
344 movff hi,xA+1 | |
345 movlw d'164' ; 164pixel height available | |
346 movwf xB+0 | |
347 clrf xB+1 | |
348 call div16x16 ; does xA/xB=xC | |
349 movff xC+0,sim_pressure+0 ; holds LOW byte of y-scale (mbar/pixel!) | |
350 movff xC+1,sim_pressure+1 ; holds HIGH byte of y-scale (mbar/pixel!) | |
351 incf sim_pressure+0,F ; increase one, because there may be a remainder | |
352 movlw d'0' | |
353 addwfc sim_pressure+1,F | |
354 | |
355 bsf leftbind | |
356 output_16dp d'3' ; max. depth | |
357 movlw 'm' | |
358 movwf POSTINC2 | |
359 movlw ' ' | |
360 movwf POSTINC2 | |
361 call I2CREAD2 | |
362 movff SSPBUF,lo | |
363 call I2CREAD2 | |
364 movff SSPBUF,hi | |
365 | |
366 movff lo,xA+0 ; calculate x-scale for profile display | |
367 movff hi,xA+1 ; calculate total diveseconds first | |
368 movlw d'60' ; 60seconds are one minute | |
369 movwf xB+0 | |
370 clrf xB+1 | |
371 call mult16x16 ; result is in xC:2 ! | |
372 | |
373 bsf leftbind | |
374 output_16 ; divetime minutes | |
375 movlw d'39' | |
376 movwf POSTINC2 | |
377 call I2CREAD2 | |
378 movff SSPBUF,lo | |
379 movf lo,W ; add seconds to total seconds | |
380 addwf xC+0 | |
381 movlw d'0' | |
382 addwfc xC+1 ; xC:2 now holds total dive seconds! | |
383 movff xC+0,xA+0 ; now calculate x-scale value | |
384 movff xC+1,xA+1 | |
385 movlw d'159' ; 159pix width available | |
386 movwf xB+0 | |
387 clrf xB+1 | |
388 call div16x16 ; xA/xB=xC | |
389 movff xC+0,xA+0 | |
390 movff xC+1,xA+1 | |
391 movf samplesecs_value,W ; devide through sample interval! | |
392 movwf xB+0 | |
393 clrf xB+1 | |
394 call div16x16 ; xA/xB=xC | |
395 movff xC+0,profile_temp+0 ; store value (use any #xC sample, skip xC-1) into temp registers | |
396 movff xC+1,profile_temp+1 ; store value (use any #xC sample, skip xC-1) into temp registers | |
397 incf profile_temp+0,F ; increase one, because there may be a remainder | |
398 movlw d'0' | |
399 addwfc profile_temp+1,F | |
400 | |
401 bsf leftbind | |
402 output_99x ; divetime seconds | |
403 movlw '"' | |
404 movwf POSTINC2 | |
405 movlw ' ' | |
406 movwf POSTINC2 | |
407 call I2CREAD2 | |
408 movff SSPBUF,lo | |
409 call I2CREAD2 | |
410 movff SSPBUF,hi | |
411 movlw d'3' | |
412 movwf ignore_digits | |
413 bsf leftbind | |
414 output_16dp d'2' ; temperature | |
415 movlw '°' | |
416 movwf POSTINC2 | |
417 movlw 'C' | |
418 movwf POSTINC2 | |
419 call word_processor ; Display 2nd row of details | |
420 | |
421 WIN_TOP .50 | |
422 WIN_LEFT .05 | |
423 lfsr FSR2,letter | |
424 | |
425 call I2CREAD2 | |
426 movff SSPBUF,lo | |
427 call I2CREAD2 | |
428 movff SSPBUF,hi | |
429 bsf leftbind | |
430 output_16 ; Air pressure before dive | |
431 movlw 'm' | |
432 movwf POSTINC2 | |
433 movlw 'b' | |
434 movwf POSTINC2 | |
435 movlw 'a' | |
436 movwf POSTINC2 | |
437 movlw 'r' | |
438 movwf POSTINC2 | |
439 movlw ' ' | |
440 movwf POSTINC2 | |
441 | |
442 movlw 'D' | |
443 movwf POSTINC2 | |
444 movlw 'e' | |
445 movwf POSTINC2 | |
446 movlw 's' | |
447 movwf POSTINC2 | |
448 movlw 'a' | |
449 movwf POSTINC2 | |
450 movlw 't' | |
451 movwf POSTINC2 | |
452 movlw ' ' | |
453 movwf POSTINC2 | |
454 | |
455 call I2CREAD2 | |
456 movff SSPBUF,lo | |
457 call I2CREAD2 | |
458 movff SSPBUF,hi | |
459 call convert_time ; converts hi:lo in minutes to hours (hi) and minutes (lo) | |
460 bsf leftbind | |
461 movf lo,W | |
462 movff hi,lo | |
463 movwf hi ; exchange lo and hi... | |
464 output_8 ; Hours | |
465 movlw ':' | |
466 movwf POSTINC2 | |
467 movff hi,lo ; Minutes | |
468 output_99x | |
469 bcf leftbind | |
470 call word_processor ; display 3rd page of details | |
471 | |
472 call I2CREAD2 ; Skip Gas1 current O2 | |
473 call I2CREAD2 ; Skip Gas1 current HE | |
474 call I2CREAD2 ; Skip Gas2 current O2 | |
475 call I2CREAD2 ; Skip Gas2 current HE | |
476 call I2CREAD2 ; Skip Gas3 current O2 | |
477 call I2CREAD2 ; Skip Gas3 current HE | |
478 call I2CREAD2 ; Skip Gas4 current O2 | |
479 call I2CREAD2 ; Skip Gas4 current HE | |
480 call I2CREAD2 ; Skip Gas5 current O2 | |
481 call I2CREAD2 ; Skip Gas5 current HE | |
482 call I2CREAD2 ; Skip Gas6 current O2 | |
483 call I2CREAD2 ; Skip Gas6 current HE | |
484 call I2CREAD2 ; Skip Start Gas | |
485 call I2CREAD2 ; Skip Firmware x | |
486 call I2CREAD2 ; Skip Firmware y | |
487 call I2CREAD2 ; Skip battery | |
488 call I2CREAD2 ; Skip battery | |
489 call I2CREAD2 ; Skip Sampling rate | |
490 call I2CREAD2 ; Read divisor | |
491 movff SSPBUF,divisor_temperature ; Store divisor | |
492 bcf divisor_temperature,4 ; Clear information length | |
493 bcf divisor_temperature,5 | |
494 bcf divisor_temperature,6 | |
495 bcf divisor_temperature,7 | |
496 incf divisor_temperature,F ; increase divisor | |
497 movff divisor_temperature,logbook_temp1 ; Store as temp, too | |
498 call I2CREAD2 ; Read divisor | |
499 movff SSPBUF,divisor_deco ; Store divisor | |
500 bcf divisor_deco,4 ; Clear information length | |
501 bcf divisor_deco,5 | |
502 bcf divisor_deco,6 | |
503 bcf divisor_deco,7 | |
504 movff divisor_deco,logbook_temp2 ; Store as temp, too | |
505 call I2CREAD2 ; Read divisor | |
506 movff SSPBUF,divisor_tank ; Store divisor | |
507 call I2CREAD2 ; Read divisor | |
508 movff SSPBUF,divisor_ppo2 ; Store divisor | |
509 call I2CREAD2 ; Read divisor | |
510 movff SSPBUF,divisor_deco_debug ; Store divisor | |
511 call I2CREAD2 ; Read divisor | |
512 movff SSPBUF,divisor_nuy2 ; Store divisor | |
513 call I2CREAD2 ; Read Salinity | |
514 call I2CREAD2 ; Skip Dummy byte | |
515 | |
516 display_profile2d: | |
517 ; Start Profile display | |
518 | |
519 movlw color_deepblue | |
520 movff WREG,box_temp+0 ; Data | |
521 movlw .75 | |
522 movff WREG,box_temp+1 ; row top (0-239) | |
523 movlw .239 | |
524 movff WREG,box_temp+2 ; row bottom (0-239) | |
525 movlw .0 | |
526 movff WREG,box_temp+3 ; column left (0-159) | |
527 movlw .159 | |
528 movff WREG,box_temp+4 ; column right (0-159) | |
529 call PLED_box | |
530 | |
531 | |
532 call I2CREAD2 ; skip 0xFB (Header-end) | |
533 clrf timeout_counter2 ; here: used as counter for depth readings | |
534 call I2CREAD2 ; skip 0xFB (Header-end) | |
535 movlw d'158' | |
536 movwf ignore_digits ; here: used as counter for x-pixels | |
537 bcf second_FD ; clear flag | |
538 movlw d'5' | |
539 movwf timeout_counter3 ; here: used as colum x2 (Start at Colum 5) | |
540 movlw d'75' ; Zero-m row | |
541 movwf apnoe_mins ; here: used for fill between rows | |
542 incf timeout_counter3,W ; Init Column | |
543 call PLED_SetColumnPixel ; pixel x2 | |
544 | |
545 profile_display_loop: | |
546 movff profile_temp+0,profile_temp2+0 | |
547 movff profile_temp+1,profile_temp2+1 ; 16Bit x-scaler | |
548 incf profile_temp2+1,F | |
549 | |
550 profile_display_loop2: | |
551 rcall profile_view_get_depth ; reads depth, ignores temp and profile data -> hi, lo | |
552 | |
553 btfsc second_FD ; end-of profile reached? | |
554 bra profile_display_loop_done ; Yes, skip all remaining pixels | |
555 | |
556 movff sim_pressure+0,xB+0 ; devide pressure in mbar/quant for row offsett | |
557 movff sim_pressure+1,xB+1 | |
558 movff lo,xA+0 | |
559 movff hi,xA+1 | |
560 call div16x16 ; xA/xB=xC | |
561 movlw d'75' | |
562 addwf xC+0,F ; add 75 pixel offset to result | |
563 call profile_display_fill ; In this column between this row (xC+0) and the last row (apnoe_mins) | |
564 movff xC+0,apnoe_mins ; Store last row for fill routine | |
565 movf xC+0,W | |
566 call PLED_SetRow ; 0...259 | |
567 | |
568 incf timeout_counter3,F | |
569 movf timeout_counter3,W | |
570 call PLED_SetColumnPixel ; pixel x2 | |
571 WIN_COLOR color_white | |
572 call PLED_PxlWrite ; Write two pixels | |
573 | |
574 profile_display_skip_loop1: ; skips readings! | |
575 dcfsnz profile_temp2+0,F | |
576 bra profile_display_loop3 ; check 16bit.... | |
577 | |
578 rcall profile_view_get_depth ; reads depth, ignores temp and profile data | |
579 bra profile_display_skip_loop1 | |
580 | |
581 profile_display_loop3: | |
582 decfsz profile_temp2+1,F ; 16 bit x-scaler test | |
583 bra profile_display_skip_loop1 ; skips readings! | |
584 | |
585 decfsz ignore_digits,F ; counts x-pixels to zero | |
586 bra profile_display_loop ; Not ready yet | |
587 ; Done. | |
588 profile_display_loop_done: | |
589 bcf sleepmode ; clear some flags | |
590 bcf menubit2 | |
591 bcf menubit3 | |
592 bcf switch_right | |
593 bcf switch_left | |
594 clrf timeout_counter2 | |
595 | |
596 display_profile_loop: | |
597 call check_switches_logbook | |
598 | |
599 btfsc menubit2 ; SET/MENU? | |
600 bra exit_profileview ; back to list | |
601 | |
602 btfsc menubit3 ; ENTER? | |
603 bra profileview_menu ; Switch to the Profileview menu | |
604 | |
605 btfsc onesecupdate | |
606 call timeout_surfmode ; timeout | |
607 | |
608 btfsc onesecupdate | |
609 call set_dive_modes ; check, if divemode must be entered | |
610 | |
611 bcf onesecupdate ; one second update | |
612 | |
613 btfsc sleepmode ; Timeout? | |
614 bra exit_profileview ; back to list | |
615 | |
616 btfsc divemode | |
617 goto restart ; Enter Divemode if required | |
618 | |
619 bra display_profile_loop ; wait for something to do | |
620 | |
621 profile_display_fill: ; In this column between this row (xC+0) and the last row (apnoe_mins), keep xC+0!! | |
622 ; First, check if xC+0>apnoe_mins or xC+0<aponoe_mins | |
623 movf xC+0,W | |
624 cpfseq apnoe_mins ; xC+0 = apone_mins? | |
625 bra profile_display_fill2 ; No! | |
626 return | |
627 profile_display_fill2: | |
628 movf xC+0,W | |
629 cpfsgt apnoe_mins ; apnoe_mins>xC+0? | |
630 bra profile_display_fill_up ; Yes! | |
631 | |
632 profile_display_fill_down: ; Fill downwards from apone_mins to xC+0! | |
633 movff apnoe_mins,xC+1 ; Copy | |
634 profile_display_fill_down2: ; Loop | |
635 decf xC+1,F | |
636 movf xC+1,W ; Row | |
637 call PLED_SetRow ; 0...259 | |
638 WIN_COLOR color_white | |
639 call PLED_PxlWrite_Single; Write one Pixel | |
640 movf xC+0,W | |
641 cpfseq xC+1 ; Loop until xC+1=xC+0 | |
642 bra profile_display_fill_down2 | |
643 return ; apnoe_mins and xC+0 are untouched | |
644 | |
645 profile_display_fill_up: ; Fill upwards from xC+0 to apone_mins! | |
646 movff xC+0,xC+1 ; Copy | |
647 profile_display_fill_up2: ; Loop | |
648 decf xC+1,F | |
649 movf xC+1,W ; Row | |
650 call PLED_SetRow ; 0...259 | |
651 WIN_COLOR color_white | |
652 call PLED_PxlWrite_Single; Write one Pixel | |
653 movf apnoe_mins,W | |
654 cpfseq xC+1 ; Loop until xC+1=apnoe_mins | |
655 bra profile_display_fill_up2 | |
656 return ; apnoe_mins and xC+0 are untouched | |
657 | |
658 profile_view_get_depth: | |
659 call I2CREAD2 ; read first depth | |
660 movff SSPBUF,lo ; low value | |
661 call I2CREAD2 ; read first depth | |
662 movff SSPBUF,hi ; high value | |
663 call I2CREAD2 ; read Profile Flag Byte | |
664 movff SSPBUF,timeout_counter2 ; Read Profile Flag Byte | |
665 bcf event_occured ; clear flag | |
666 btfsc timeout_counter2,7 | |
667 bsf event_occured ; We also have an Event byte! | |
668 bcf timeout_counter2,7 ; Clear Event Byte Flag (If any) | |
669 ; timeout_counter2 now holds the number of additional bytes to ignore (0-127) | |
670 movlw 0xFD ; end of profile bytes? | |
671 cpfseq lo | |
672 bra profile_view_get_depth_new1 ; no 0xFD | |
673 movlw 0xFD ; end of profile bytes? | |
674 cpfseq hi | |
675 bra profile_view_get_depth_new1 ; no 0xFD | |
676 bsf second_FD ; End found! Set Flag! Skip remaining pixels! | |
677 return | |
678 | |
679 profile_view_get_depth_new1: | |
680 decfsz divisor_deco,F ; Check divisor | |
681 bra profile_view_get_depth_new1_1 ; Divisor not zero... | |
682 | |
683 ; tstfsz timeout_counter2 ; Any bytes to ignore | |
684 ; bra profile_view_get_depth_new2 ; Yes (1-127) | |
685 ; return ; No (0) | |
686 | |
687 movff logbook_temp2,divisor_deco ; Restore divisor value! | |
688 ; check for event byte and the extra informations | |
689 btfss event_occured | |
690 bra profile_view_get_depth_new2 ; No event! | |
691 | |
692 call I2CREAD2 ; read event byte | |
693 decf timeout_counter2,F ; Reduce number of bytes to ignore | |
694 | |
695 movlw d'0' ; Extra bytes to ignore because of event | |
696 btfsc SSPBUF,4 | |
697 addlw d'2' ; two bytes for manual gas set | |
698 btfsc SSPBUF,5 | |
699 addlw d'1' ; one byte for gas change | |
700 movwf logbook_temp5 ; store extra bytes to ignore | |
701 | |
702 tstfsz logbook_temp5 ; Anything to ignore? | |
703 bra profile_view_get_depth_new1_2 ; Yes | |
704 bra profile_view_get_depth_new2 ; No, continue with normal routine | |
705 | |
706 profile_view_get_depth_new1_2: | |
707 call I2CREAD2 ; ignore byte | |
708 decf timeout_counter2,F ; Reduce number of bytes to ignore | |
709 decfsz logbook_temp5,F ; reduce extra bytes ignore counter | |
710 bra profile_view_get_depth_new1_2 ; loop | |
711 | |
712 profile_view_get_depth_new2: | |
713 movlw d'4' ; Temp (2) and Deko (2) in the sample? | |
714 cpfseq timeout_counter2 | |
715 bra profile_view_get_depth_new2_2 ; No | |
716 ; Yes, skip Temp! | |
717 call I2CREAD2 ; ignore byte | |
718 decf timeout_counter2,F ; Reduce number of bytes to ignore | |
719 call I2CREAD2 ; ignore byte | |
720 decf timeout_counter2,F ; Reduce number of bytes to ignore | |
721 | |
722 profile_view_get_depth_new2_2: | |
723 call I2CREAD2 ; ignore byte | |
724 | |
725 decfsz timeout_counter2,F ; reduce counter | |
726 bra profile_view_get_depth_new2_2; Loop | |
727 return | |
728 | |
729 profile_view_get_depth_new1_1: | |
730 tstfsz timeout_counter2 ; Any bytes to ignore | |
731 bra profile_view_get_depth_new3 ; Yes (1-127) | |
732 return ; No (0) | |
733 | |
734 ; timeout_counter2 now holds the number of additional bytes to ignore (0-127) | |
735 profile_view_get_depth_new3: | |
736 call I2CREAD2 ; ignore byte | |
737 decfsz timeout_counter2,F ; reduce counter | |
738 bra profile_view_get_depth_new3 ; Loop | |
739 return | |
740 | |
741 exit_profileview: | |
742 bcf sleepmode | |
743 clrf timeout_counter2 ; restore all registers to build same page again | |
744 movff decodata+0,eeprom_address+0 | |
745 movff decodata+1,eeprom_address+1 | |
746 movff max_pressure+0,divemins+0 | |
747 movff max_pressure+1,divemins+1 | |
748 movff mintemp+0, divenumber | |
749 movff logbook_temp6,temp1 | |
750 movff samplesecs,temp2 | |
751 decf divenumber,F | |
752 bcf all_dives_shown | |
753 | |
754 decf menupos2,F | |
755 | |
756 clrf menupos3 ; here: used row on current page | |
757 movlw d'5' | |
758 movwf menupos ; here: active row on current page | |
759 incf menupos2,F ; start new page | |
760 call PLED_ClearScreen ; clear details/profile | |
761 bra menu_logbook1b ; start search | |
762 | |
763 next_logbook2: | |
764 btfsc all_dives_shown ; all shown | |
765 goto menu_logbook1 ; all reset | |
766 | |
767 clrf menupos3 | |
768 movlw d'5' | |
769 movwf menupos ; | |
770 incf menupos2,F ; start new screen | |
771 call PLED_ClearScreen | |
772 | |
773 next_logbook: | |
774 movff eeprom_header_address+0,eeprom_address+0 | |
775 movff eeprom_header_address+1,eeprom_address+1 ; continue search here | |
776 goto menu_logbook1b | |
777 | |
778 check_switches_logbook: | |
779 btfsc switch_right | |
780 bsf menubit3 | |
781 btfsc switch_left | |
782 bsf menubit2 ; Enter | |
783 return | |
784 | |
785 next_logbook3: | |
786 incf menupos,F | |
787 movlw d'7' | |
788 cpfseq menupos ; =7? | |
789 bra next_logbook3a ; No | |
790 bra next_logbook2 ; yes, new page please | |
791 | |
792 next_logbook3a: | |
793 incf menupos3,W ; | |
794 cpfseq menupos | |
795 bra next_logbook3b | |
796 movlw d'6' | |
797 movwf menupos ; Jump directly to exit if page is not full | |
798 | |
799 next_logbook3b: | |
800 clrf timeout_counter2 | |
801 call PLED_logbook_cursor | |
802 | |
803 bcf switch_right | |
804 bcf menubit3 ; clear flag | |
805 bra menu_logbook_loop | |
806 | |
807 display_listdive: | |
808 bsf logbook_page_not_empty ; Page not empty | |
809 incf menupos3,F | |
810 | |
811 btfsc logbook_header_drawn ; "Logbook already displayed? | |
812 bra display_listdive1a | |
813 call PLED_topline_box ; Draw box | |
814 WIN_INVERT .1 | |
815 DISPLAYTEXT .26 ; "Logbook" | |
816 WIN_INVERT .0 | |
817 bsf logbook_header_drawn | |
818 | |
819 display_listdive1a: | |
820 WIN_LEFT .20 | |
821 | |
822 movf menupos2,W | |
823 mullw d'5' | |
824 movf PRODL,W | |
825 subwf divenumber,W ; current row on page | |
826 | |
827 mullw d'30' ; x30 | |
828 movf PRODL,W ; is pixel-row for entry | |
829 addlw d'5' ; +5 Pixel, so list entries are at rows 35,65,95,125,155,185 | |
830 movff WREG,win_top | |
831 | |
832 lfsr FSR2,letter | |
833 movff divenumber,lo | |
834 output_99x ; # of dive | |
835 movlw ' ' | |
836 movwf POSTINC2 | |
837 call I2CREAD2 | |
838 movff SSPBUF,lo | |
839 movlw d'13' | |
840 cpfsgt lo ; Skip if lo>13 | |
841 bra display_listdive2 ; use old format | |
842 | |
843 call I2CREAD2 ; Skip Profile version | |
844 movff SSPBUF,lo ; in new format, read month | |
845 | |
846 display_listdive2: | |
847 movff lo,convert_value_temp+0 ; Month (in lo, see above) | |
848 call I2CREAD2 ; Day | |
849 movff SSPBUF,convert_value_temp+1 | |
850 call I2CREAD2 ; Year | |
851 movff SSPBUF,convert_value_temp+2 | |
852 call PLED_convert_date_short ; converts into "DD/MM" or "MM/DD" or "MM/DD" in postinc2 | |
853 | |
854 | |
855 call I2CREAD2 ; hours (Skip) | |
856 call I2CREAD2 ; minutes (skip) | |
857 movlw ' ' | |
858 movwf POSTINC2 | |
859 call I2CREAD2 ; Depth | |
860 movff SSPBUF,lo | |
861 call I2CREAD2 | |
862 movff SSPBUF,hi | |
863 bsf leftbind | |
864 bsf ignore_digit5 ; Do not display 1cm figure | |
865 output_16dp d'3' ; max. depth | |
866 movlw 'm' | |
867 movwf POSTINC2 | |
868 movlw ' ' | |
869 movwf POSTINC2 | |
870 call I2CREAD2 | |
871 movff SSPBUF,lo | |
872 call I2CREAD2 | |
873 movff SSPBUF,hi | |
874 bsf leftbind | |
875 output_16 ; Divetime minutes | |
876 movlw d'39' ; "'" | |
877 movwf POSTINC2 | |
878 | |
879 call word_processor ; Display header-row in list | |
880 return | |
881 | |
882 | |
883 profileview_menu: | |
884 movlw d'1' | |
885 movwf menupos | |
886 profileview_menu1: | |
887 call PLED_clear_divemode_menu | |
888 call PLED_profileview_menu ; Displays Menu | |
889 profileview_menu2: | |
890 call PLED_divemenu_cursor | |
891 bcf sleepmode ; clear some flags | |
892 bcf menubit2 | |
893 bcf menubit3 | |
894 bcf switch_right | |
895 bcf switch_left | |
896 clrf timeout_counter2 | |
897 | |
898 profileview_menu_loop: | |
899 call check_switches_logbook | |
900 | |
901 btfsc menubit3 ; SET/MENU? | |
902 bra profileview_menu_move_cursor; Move Cursor | |
903 btfsc menubit2 ; ENTER? | |
904 bra profileview_menu_do ; Do task | |
905 | |
906 btfsc onesecupdate | |
907 call timeout_surfmode ; timeout | |
908 btfsc onesecupdate | |
909 call set_dive_modes ; check, if divemode must be entered | |
910 bcf onesecupdate ; one second update | |
911 btfsc sleepmode ; Timeout? | |
912 bra exit_profileview ; back to list | |
913 btfsc divemode | |
914 goto restart ; Enter Divemode if required | |
915 | |
916 bra profileview_menu_loop ; wait for something to do | |
917 | |
918 profileview_menu_do: | |
919 dcfsnz menupos,F | |
920 bra exit_profileview ; back to list, quit profileview menu | |
921 dcfsnz menupos,F | |
922 bra profileview_menu_delete ; Delete Dive from external EEPROM | |
923 dcfsnz menupos,F | |
924 bra profileview_menu_format ; Delete all Dives from external EEPROM | |
925 | |
926 profileview_menu_move_cursor: | |
927 incf menupos,F | |
928 movlw d'4' ; number of menu options+1 | |
929 cpfseq menupos ; =limit? | |
930 bra profileview_menu_move_cursor2 ; No! | |
931 movlw d'1' ; Yes, reset to position 1! | |
932 movwf menupos | |
933 profileview_menu_move_cursor2: | |
934 bra profileview_menu2 ; Return to Profile Menu, also updates cursor | |
935 | |
936 profileview_menu_format: | |
937 call PLED_confirmbox ; Returns WREG=0 for Cancel (Or Timeout) and WREG=1 for OK! | |
938 | |
939 movwf menupos ; Used as temp | |
940 tstfsz menupos | |
941 bra profileview_menu_format_loop2 ; Format now! | |
942 | |
943 bra exit_profileview ; back to list, quit profileview menu | |
944 | |
945 profileview_menu_format_loop2: ; Do now format! | |
946 call PLED_ClearScreen | |
947 DISPLAYTEXT .12 ; "Wait.." | |
948 call reset_external_eeprom ; delete profile memory | |
949 goto menu ; Return to Menu | |
950 | |
951 profileview_menu_delete: | |
952 call PLED_confirmbox ; Returns WREG=0 for Cancel (Or Timeout) and WREG=1 for OK! | |
953 movwf menupos ; Used as temp | |
954 tstfsz menupos | |
955 bra profileview_menu_delete_loop2 ; Delete now! | |
956 | |
957 bra exit_profileview ; back to list, quit profileview menu | |
958 | |
959 profileview_menu_delete_loop2: ; Do now delete | |
960 call PLED_ClearScreen | |
961 DISPLAYTEXT .12 ; "Wait.." | |
962 | |
963 ; eeprom_address:2 is set to the second byte after the ending 0xFD 0xFD | |
964 ; eeprom_address:2 - 1 -> set to the last byte after the 0xFD 0xFD of the current dive | |
965 | |
966 ; Set pointer to Byte after the final "0xFD 0xFD" | |
967 decf_eeprom_address d'1' ; Macro, that subtracts 8Bit from eeprom_address:2 with banking at 0x8000 | |
968 movff eeprom_address+0,divemins+0 | |
969 movff eeprom_address+1,divemins+1 | |
970 | |
971 ; eeprom_header_address:2 + 1 -> set to the first 0xFA of the 0xFA 0xFA start bytes of the header | |
972 movlw d'1' ; | |
973 addwf eeprom_header_address+0,F | |
974 movlw d'0' | |
975 addwfc eeprom_header_address+1,F ; eeprom_header_address:2 + 1 | |
976 btfsc eeprom_header_address+1,7 ; at 7FFF? | |
977 clrf eeprom_header_address+0 ; Yes, clear address (+0 first!) | |
978 btfsc eeprom_header_address+1,7 ; at 7FFF? | |
979 clrf eeprom_header_address+1 ; Yes, clear address | |
980 | |
981 movff divemins+0,eeprom_address+0 | |
982 movff divemins+1,eeprom_address+1 ; Read source | |
983 call I2CREAD ; reads one byte (Slow! Better use Blockread!) | |
984 movwf profile_temp+0 | |
985 movlw 0xFE | |
986 cpfseq profile_temp+0 | |
987 bra profileview_menu_delete_notlast ; we're not deleting the last dive.... | |
988 | |
989 ; Just move the 0xFE after the dive and delete the rest with 0xFF | |
990 movff eeprom_header_address+0, eeprom_address+0 | |
991 movff eeprom_header_address+1, eeprom_address+1 ; Write target | |
992 movlw 0xFE | |
993 call I2CWRITE ; Write the byte | |
994 | |
995 ; Now, delete everything _between_ eeprom_header_address and divemins:2+2 with 0xFF | |
996 movlw d'1' ; | |
997 addwf eeprom_header_address+0,F | |
998 movlw d'0' | |
999 addwfc eeprom_header_address+1,F ; eeprom_header_address:2 + 1 | |
1000 btfsc eeprom_header_address+1,7 ; at 7FFF? | |
1001 clrf eeprom_header_address+0 ; Yes, clear address (+0 first!) | |
1002 btfsc eeprom_header_address+1,7 ; at 7FFF? | |
1003 clrf eeprom_header_address+1 ; Yes, clear address | |
1004 | |
1005 movff eeprom_header_address+0,eeprom_address+0 | |
1006 movff eeprom_header_address+1,eeprom_address+1 | |
1007 | |
1008 movlw d'1' ; | |
1009 addwf divemins+0,F | |
1010 movlw d'0' | |
1011 addwfc divemins+1,F ; divemins:2 + 1 | |
1012 btfss divemins+1,7 ; at 7FFF? | |
1013 bra profileview_menu_delete_loop2a ; Skip | |
1014 clrf divemins+0 ; Yes, clear address | |
1015 clrf divemins+1 | |
1016 | |
1017 ; movff eeprom_header_address+0,eeprom_address+0 | |
1018 ; movff eeprom_header_address+1,eeprom_address+1 | |
1019 | |
1020 | |
1021 profileview_menu_delete_loop2a: | |
1022 movlw 0xFF | |
1023 call I2CWRITE ; Write the byte | |
1024 | |
1025 incf_eeprom_address d'1' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000 | |
1026 | |
1027 movff divemins+0,sub_a+0 | |
1028 movff divemins+1,sub_a+1 | |
1029 movff eeprom_address+0,sub_b+0 | |
1030 movff eeprom_address+1,sub_b+1 | |
1031 call sub16 ; sub_c = sub_a - sub_b | |
1032 tstfsz sub_c+0 ; Done (Result=Zero?) ? | |
1033 bra profileview_menu_delete_loop2a ; No, continue | |
1034 tstfsz sub_c+1 ; Done (Result=Zero?) ? | |
1035 bra profileview_menu_delete_loop2a ; No, continue | |
1036 goto menu_logbook ; Return to list when done deleting | |
1037 | |
1038 profileview_menu_delete_notlast: | |
1039 ; Move everything byte-wise from divemins:2 to eeprom_header_address:2 until 0xFD 0xFD 0xFE is found and were moved | |
1040 call get_free_EEPROM_location ; Searches 0xFD, 0xFD, 0xFE and sets Pointer to 0xFE | |
1041 | |
1042 incf_eeprom_address d'2' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000 | |
1043 movff eeprom_address+0,profile_temp+0 | |
1044 movff eeprom_address+1,profile_temp+1 | |
1045 ; holds now address of 0xFE + 2 (Abort condition....) | |
1046 decf_eeprom_address d'2' ; Macro, that subtracts 8Bit from eeprom_address:2 with banking at 0x8000 | |
1047 ; holds now address of 0xFE again | |
1048 movff eeprom_address+0,divemins+0 | |
1049 movff eeprom_address+1,divemins+1 ; Copy to working read registers | |
1050 | |
1051 profileview_menu_delete_loop3: | |
1052 movff divemins+0,eeprom_address+0 | |
1053 movff divemins+1,eeprom_address+1 ; Read source | |
1054 call I2CREAD ; reads one byte (Slow! Better use Blockread!) | |
1055 movff eeprom_header_address+0, eeprom_address+0 | |
1056 movff eeprom_header_address+1, eeprom_address+1 ; Write target | |
1057 call I2CWRITE ; Write the byte | |
1058 | |
1059 movff divemins+0,eeprom_address+0 | |
1060 movff divemins+1,eeprom_address+1 ; Set to source again | |
1061 movlw 0xFF | |
1062 call I2CWRITE ; Delete the source.... | |
1063 | |
1064 movlw d'1' | |
1065 addwf divemins+0,F ; Increase source (Divemins:2) | |
1066 movlw d'0' | |
1067 addwfc divemins+1,F | |
1068 btfsc divemins+1,7 ; at 0x8000? | |
1069 clrf divemins+0 ; Yes, clear address (+0 first!) | |
1070 btfsc divemins+1,7 ; at 0x8000? | |
1071 clrf divemins+1 ; Yes, clear address | |
1072 | |
1073 movlw d'1' ; Increase target (eeprom_header_address:2) | |
1074 addwf eeprom_header_address+0,F | |
1075 movlw d'0' | |
1076 addwfc eeprom_header_address+1,F ; eeprom_header_address:2 + 1 | |
1077 btfsc eeprom_header_address+1,7 ; at 7FFF? | |
1078 clrf eeprom_header_address+0 ; Yes, clear address (+0 first!) | |
1079 btfsc eeprom_header_address+1,7 ; at 7FFF? | |
1080 clrf eeprom_header_address+1 ; Yes, clear address | |
1081 | |
1082 movff divemins+0,sub_a+0 | |
1083 movff divemins+1,sub_a+1 | |
1084 movff profile_temp+0,sub_b+0 | |
1085 movff profile_temp+1,sub_b+1 | |
1086 call sub16 ; sub_c = sub_a - sub_b | |
1087 tstfsz sub_c+0 ; Done (Result=Zero?) ? | |
1088 bra profileview_menu_delete_loop3 ; No, continue | |
1089 tstfsz sub_c+1 ; Done (Result=Zero?) ? | |
1090 bra profileview_menu_delete_loop3 ; No, continue | |
1091 | |
1092 goto menu_logbook ; Return to list when done deleting | |
1093 | |
1094 | |
1095 |