Mercurial > public > hwos_code
annotate src/compass_ops.asm @ 642:a9a0188091e4
fix rare upgrade issue with OSTC sport 2019 hardware
author | heinrichsweikamp |
---|---|
date | Thu, 14 Jan 2021 16:24:07 +0100 |
parents | 4050675965ea |
children | 7d8a4c60ec1a 5b7fe7777425 |
rev | line source |
---|---|
582 | 1 ;============================================================================= |
2 ; | |
634 | 3 ; File compass_ops.asm combined next generation V3.09.5 |
582 | 4 ; |
5 ; Compass Operations | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 | |
634 | 10 #include "hwos.inc" |
11 #include "i2c.inc" | |
12 #include "tft_outputs.inc" | |
13 #include "tft.inc" | |
14 #include "strings.inc" | |
15 #include "wait.inc" | |
16 #include "surfmode.inc" | |
17 #include "divemode.inc" | |
18 #include "math.inc" | |
19 #include "convert.inc" | |
20 #include "start.inc" | |
21 #include "colorschemes.inc" | |
147 | 22 |
0 | 23 |
623 | 24 IFDEF _compass |
25 | |
26 | |
27 ; local flags | |
28 #DEFINE compass_show_cardinal compass_flags,0 ; =1: show the cardinal (N, NE, E, ...) | |
29 #DEFINE compass_bearing_eq compass_flags,1 ; =1: bearing is in direction, do not show << or >> | |
30 #DEFINE compass_bearing_lft compass_flags,2 ; =1: bearing is to the left/<<, =0: to the right/>> | |
31 #DEFINE compass_bearing_vis compass_flags,3 ; =1: bearing is visible (either ahead or behind/-180°) | |
32 #DEFINE compass_bearing_ahd compass_flags,4 ; =1: bearing is ahead, =0: behind | |
33 ; compass_flags,5 ; --- unused | |
34 ; compass_flags,6 ; --- unused | |
35 ; compass_flags,7 ; --- unused | |
36 | |
37 | |
0 | 38 ; Make sure symbols from the .inc are available to the C code: |
623 | 39 |
40 ; filtered data - Compass | |
582 | 41 global compass_DX_f |
42 global compass_DY_f | |
43 global compass_DZ_f | |
0 | 44 |
623 | 45 ; filtered Data - Accelerometer |
582 | 46 global accel_DX_f |
47 global accel_DY_f | |
48 global accel_DZ_f | |
49 | |
623 | 50 ; Calibration Data |
582 | 51 global compass_CX_f |
52 global compass_CY_f | |
53 global compass_CZ_f | |
0 | 54 |
623 | 55 ; Temporary Values to pass Q15 Arithmetics around |
582 | 56 global compass_a |
57 global compass_b | |
0 | 58 |
582 | 59 ; Result |
623 | 60 global compass_heading_new |
0 | 61 |
147 | 62 |
582 | 63 extern compass |
64 extern compass_reset_calibration | |
65 extern compass_add_calibration | |
66 extern compass_solve_calibration | |
623 | 67 |
631 | 68 extern option_check_and_store_all |
582 | 69 |
337
508d7fb98b34
cleanup menu, add "Auto SP" option (Not working yet), minor layout change in compass menu
heinrichsweikamp
parents:
300
diff
changeset
|
70 |
634 | 71 ;============================================================================= |
72 compass_ops1 CODE | |
73 ;============================================================================= | |
582 | 74 |
75 | |
0 | 76 ;----------------------------------------------------------------------------- |
77 ; Filter compass values | |
78 ; | |
79 ; Apply linear filtering to input parameters. | |
80 | |
582 | 81 ; Apply filtering formula: reg_f += (reg - reg_f) / 4 |
82 FILTER16 MACRO reg, reg_f | |
83 movf reg_f+0,W | |
84 subwf reg+0,W | |
85 movwf PRODL | |
86 movf reg_f+1,W | |
87 subwfb reg+1,W | |
88 rcall filter_16_common | |
89 addwf reg_f+0,F | |
90 movf PRODH,W | |
91 addwfc reg_f+1,F | |
92 ENDM | |
148 | 93 |
94 filter_16_common: | |
582 | 95 movwf PRODH |
623 | 96 bcf STATUS,C ; copy sign bit into carry |
582 | 97 btfsc PRODH,7 |
98 bsf STATUS,C | |
623 | 99 rrcf PRODH,F ; 16 bit shift right |
582 | 100 rrcf PRODL,F |
623 | 101 bcf STATUS,C ; copy sign bit into carry |
582 | 102 btfsc PRODH,7 |
103 bsf STATUS,C | |
623 | 104 rrcf PRODH,F ; 16 bit shift right |
582 | 105 rrcf PRODL,W |
106 return | |
0 | 107 |
623 | 108 |
582 | 109 global compass_filter |
0 | 110 compass_filter: |
623 | 111 banksel compass_DX ; select bank common2 |
582 | 112 FILTER16 compass_DX, compass_DX_f |
113 FILTER16 compass_DY, compass_DY_f | |
114 FILTER16 compass_DZ, compass_DZ_f | |
115 FILTER16 accel_DX, accel_DX_f | |
116 FILTER16 accel_DY, accel_DY_f | |
117 FILTER16 accel_DZ, accel_DZ_f | |
623 | 118 banksel common ; back to bank common |
582 | 119 return |
0 | 120 |
121 | |
634 | 122 ;============================================================================= |
123 compass_ops2 CODE | |
124 ;============================================================================= | |
0 | 125 |
126 ;----------------------------------------------------------------------------- | |
127 ; Q15 fractional numbers: a * b / 2**16 (UNSIGNED) | |
128 ; | |
623 | 129 ; Uses 16x16->16 multiply, for positive integers, keeping only the most |
130 ; relevant bits. | |
0 | 131 ; |
132 ; Used to multiply two Q15 numbers, in the range 0..1, | |
133 ; represented as 0..32767, that is a / 2**15. | |
134 ; | |
135 ; (a/2**15) * (b/2**15) = a*b / 2**30 = (a*b/2**16) / 2**14. | |
136 ; So to get back a Q15 number, we need a shift-left... | |
623 | 137 |
138 global compass_umul ; called from compass.c | |
0 | 139 compass_umul: |
623 | 140 banksel compass_a ; select bank common2 |
582 | 141 rcall compass_mul_16 |
0 | 142 |
143 ; The 2x time, by left-shifting inserting the missing bit: | |
144 compass_mul_2: | |
623 | 145 rlcf compass_r+2,F ; missing bit into carry |
582 | 146 rlcf compass_r+0,F |
147 rlcf compass_r+1,F | |
623 | 148 MOVII compass_r,PROD ; return value into PROD |
582 | 149 return |
0 | 150 |
151 ; The 16x16-> multiply: | |
152 compass_mul_16: | |
623 | 153 movf compass_a+1,W ; block ah*bh |
582 | 154 mulwf compass_b+1 |
155 movff PRODL,compass_r+0 ; and copy | |
156 movff PRODH,compass_r+1 | |
0 | 157 |
623 | 158 movf compass_a+0,W ; block al*bl |
159 mulwf compass_b+0 | |
160 movff PRODH,compass_r+2 ; into fraction byte | |
0 | 161 |
623 | 162 movf compass_a+1,W ; block ah*bl |
582 | 163 mulwf compass_b+0 |
164 movf PRODL,W | |
623 | 165 addwf compass_r+2,F ; fraction part to carry |
582 | 166 movf PRODH,W ; and add16 |
167 addwfc compass_r+0,F | |
168 movlw 0 | |
628 | 169 addwfc compass_r+1,F |
0 | 170 |
623 | 171 movf compass_a+0,W ; block al*bh |
582 | 172 mulwf compass_b+1 |
173 movf PRODL,W | |
623 | 174 addwf compass_r+2,F ; fraction part to carry |
582 | 175 movf PRODH,W ; and add16 |
176 addwfc compass_r+0,F | |
177 movlw 0 | |
178 addwfc compass_r+1,F | |
0 | 179 |
582 | 180 return |
0 | 181 |
182 ;----------------------------------------------------------------------------- | |
183 ; Q15 fractional numbers: a * b / 2**16 (SIGNED) | |
184 | |
623 | 185 global compass_imul ; called from compass.c |
0 | 186 compass_imul: |
623 | 187 banksel compass_a ; select bank common2 |
582 | 188 rcall compass_mul_16 |
0 | 189 |
582 | 190 btfss compass_b+1,7 |
191 bra compass_mul_3 | |
0 | 192 |
582 | 193 movf compass_a+0,W |
194 subwf compass_r+0,F | |
195 movf compass_a+1,W | |
196 subwfb compass_r+1,F | |
0 | 197 |
198 compass_mul_3: | |
582 | 199 btfss compass_a+1,7 |
200 bra compass_mul_4 | |
0 | 201 |
582 | 202 movf compass_b+0,W |
203 subwf compass_r+0,F | |
204 movf compass_b+1,W | |
623 | 205 subwfb compass_r+1,F |
0 | 206 |
207 compass_mul_4: | |
628 | 208 bcf compass_r+1,6 ; copy bit 7 to 6, so keep it after 2x |
582 | 209 btfsc compass_r+1,7 |
210 bsf compass_r+1,6 | |
211 bra compass_mul_2 | |
0 | 212 |
623 | 213 |
634 | 214 ;============================================================================= |
215 compass_ops3 CODE | |
216 ;============================================================================= | |
217 | |
218 global compass_calibration | |
219 compass_calibration: ; compass calibration | |
628 | 220 bsf block_sensor_interrupt ; disable sensor interrupts |
221 call I2C_sleep_compass ; stop compass | |
634 | 222 call TFT_ClearScreen ; clear the screen |
582 | 223 ; Mask |
634 | 224 WIN_STD .16,.0 ; set position |
225 FONT_COLOR color_greenish ; set font color | |
226 STRCPY_TEXT_PRINT tCompassCalibration | |
227 btfss switch_right2 ; wait until button (with a moving magnet in some OSTC!) is released | |
623 | 228 bra $-2 |
147 | 229 |
582 | 230 ; WIN_SMALL .0,.215 |
634 | 231 ; FONT_COLOR color_standard |
582 | 232 ; STRCPY_TEXT_PRINT tExit |
233 WAITMS d'255' | |
234 WAITMS d'255' | |
147 | 235 |
628 | 236 call request_speed_fastest ; request CPU speed change to fastest speed |
623 | 237 |
628 | 238 movlw .7 ; initialize gain |
634 | 239 movff WREG,opt_compass_gain ; ... |
428 | 240 |
628 | 241 movlw .60 ; initialize timeout to 60 seconds |
242 movwf isr_timeout_reload ; copy WREG to isr_timeout_reload | |
634 | 243 bsf restart_timeout ; request ISR to restart the timeout |
628 | 244 bcf trigger_timeout ; clear any pending timeout trigger |
245 compass_calibration_gainset: ; reduce the gain, set bank here! | |
246 banksel opt_compass_gain ; select bank options table | |
247 decf opt_compass_gain,F ; reduce by one | |
248 btfsc STATUS,N ; < 0 ? | |
249 clrf opt_compass_gain ; YES - keep at zero | |
250 btfsc STATUS,N ; < 0 ? | |
634 | 251 bra compass_calibration_loop1 ; YES - skip gain stuff (Would hang here in case of compass failure) |
628 | 252 banksel common ; bank to bank common |
623 | 253 |
634 | 254 call I2C_init_compass ; initialize compass chip |
582 | 255 |
628 | 256 btfsc compass_type3 ; compass type 3 ? |
257 bra compass_calibration_loop1 ; YES - skip gain stuff | |
258 btfsc compass_type2 ; compass type 2 ? | |
259 bra compass_calibration_loop1 ; YES - skip gain stuff | |
582 | 260 |
628 | 261 rcall TFT_compass_show_gain ; show the current compass gain |
147 | 262 |
582 | 263 WAITMS d'250' |
628 | 264 WAITMS d'250' ; wait for first reading... |
147 | 265 |
628 | 266 movlw .60 ; calibration shall run for 60 seconds |
634 | 267 call restart_timeout_time ; restart the timeout |
147 | 268 |
628 | 269 call I2C_RX_compass ; read compass |
270 call I2C_RX_accelerometer ; read accelerometer | |
147 | 271 |
582 | 272 ; Test all axes for +4096 (Hi byte=16) |
628 | 273 banksel compass_DX ; select bank common2 |
582 | 274 movlw .16 |
275 cpfseq compass_DX+1 | |
276 bra $+4 | |
277 bra compass_calibration_gainset | |
278 cpfseq compass_DY+1 | |
279 bra $+4 | |
280 bra compass_calibration_gainset | |
281 cpfseq compass_DZ+1 | |
282 bra $+4 | |
283 bra compass_calibration_gainset | |
147 | 284 |
582 | 285 ; Test all axes for -4096 (Hi byte=240) |
286 movlw .240 | |
287 cpfseq compass_DX+1 | |
288 bra $+4 | |
289 bra compass_calibration_gainset | |
290 cpfseq compass_DY+1 | |
291 bra $+4 | |
292 bra compass_calibration_gainset | |
293 cpfseq compass_DZ+1 | |
294 bra $+4 | |
295 bra compass_calibration_gainset | |
147 | 296 |
628 | 297 compass_calibration_loop1: ; done with gain |
298 banksel common ; bank to bank common | |
299 rcall compass_filter_init ; set DX_f values | |
300 call compass_reset_calibration ; reset CX_f values (C-code) | |
301 banksel common ; back to bank common | |
147 | 302 |
303 compass_calibration_loop2: | |
628 | 304 call I2C_RX_compass ; read compass |
305 call I2C_RX_accelerometer ; test accelerometer | |
634 | 306 call compass_filter ; filter compass raw data |
147 | 307 |
582 | 308 ; Twice |
628 | 309 call I2C_RX_compass ; read compass |
310 call I2C_RX_accelerometer ; test accelerometer | |
634 | 311 call compass_filter ; filter compass raw data |
582 | 312 |
628 | 313 ; btfsc compass_type1 ; compass1? |
314 ; bra compass_calibration_loop3 ; YES - skip gain stuff | |
147 | 315 |
582 | 316 ; Test all axes for +4096 (Hi byte=16) |
628 | 317 banksel compass_DX ; select bank common2 |
582 | 318 movlw .16 |
319 cpfseq compass_DX+1 | |
320 bra $+4 | |
321 bra compass_calibration_gainset | |
322 cpfseq compass_DY+1 | |
323 bra $+4 | |
324 bra compass_calibration_gainset | |
325 cpfseq compass_DZ+1 | |
326 bra $+4 | |
327 bra compass_calibration_gainset | |
147 | 328 |
582 | 329 ; Test all axes for -4096 (Hi byte=240) |
330 movlw .240 | |
331 cpfseq compass_DX+1 | |
332 bra $+4 | |
333 bra compass_calibration_gainset | |
334 cpfseq compass_DY+1 | |
335 bra $+4 | |
336 bra compass_calibration_gainset | |
337 cpfseq compass_DZ+1 | |
338 bra $+4 | |
339 bra compass_calibration_gainset | |
628 | 340 banksel common ; back to bank common |
634 | 341 |
582 | 342 ; ; Three |
628 | 343 ; call I2C_RX_compass ; read compass |
344 ; call I2C_RX_accelerometer ; test accelerometer | |
345 ; call compass_filter ; filter compass raw data | |
147 | 346 ; |
582 | 347 ; ; Four times to get cleaner values |
628 | 348 ; call I2C_RX_compass ; read compass |
349 ; call I2C_RX_accelerometer ; test accelerometer | |
350 ; call compass_filter ; filter compass raw data | |
147 | 351 |
428 | 352 compass_calibration_loop3: |
623 | 353 ; and register only one value out of four: |
628 | 354 call compass_add_calibration ; check and store new max/min values (C-code) |
355 banksel common ; back to bank common | |
147 | 356 |
628 | 357 rcall TFT_compass_fast ; show values |
358 btfsc trigger_timeout ; timeout (calibration done)? | |
359 bra compass_calibration_exit ; YES - done | |
360 btfss trigger_full_second ; NO - new second begun? | |
631 | 361 bra compass_calibration_loop2 ; NO - loop |
628 | 362 bcf trigger_full_second ; YES - clear flag |
363 rcall TFT_show_timeout_testmode ; - show remaining time | |
364 bra compass_calibration_loop2 ; - loop | |
147 | 365 |
366 compass_calibration_exit: | |
628 | 367 bcf block_sensor_interrupt ; re-enable sensor interrupts |
623 | 368 |
628 | 369 call compass_solve_calibration ; calculate calibration factors (C-code) |
370 banksel common ; back to bank common | |
371 | |
372 call request_speed_normal ; request CPU speed change to normal speed | |
623 | 373 |
634 | 374 bsf option_changed ; flag that option values have changed |
631 | 375 bsf restart_fast ; request to skip logos and waits on restart |
376 | |
377 movlw .6 ; coding for surface compass view | |
378 movff WREG,customview_surfmode ; set to compass view to show | |
379 | |
380 goto restart ; done | |
623 | 381 |
147 | 382 |
634 | 383 ;----------------------------------------------------------------------------- |
384 ; Helper Function | |
385 ; | |
386 compass_filter_init: | |
387 MOVII compass_DX,compass_DX_f | |
388 MOVII compass_DY,compass_DY_f | |
389 MOVII compass_DZ,compass_DZ_f | |
628 | 390 |
634 | 391 MOVII accel_DX,accel_DX_f |
392 MOVII accel_DY,accel_DY_f | |
393 MOVII accel_DZ,accel_DZ_f | |
582 | 394 return |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
395 |
634 | 396 ;----------------------------------------------------------------------------- |
397 ; Show Calibration Progress | |
398 ; | |
399 TFT_compass_fast: | |
400 WIN_TINY .0,.50 ; set font and position | |
401 FONT_COLOR_MEMO ; set font color | |
402 | |
403 STRCPY "Cx:" ; print label | |
404 MOVII compass_DX,mpr ; get value | |
405 rcall TFT_compass_fast_helper ; print value | |
406 | |
407 STRCAT " Cy:" ; print label | |
408 MOVII compass_DY,mpr ; get value | |
409 rcall TFT_compass_fast_helper ; print value | |
410 | |
411 STRCAT " Cz:" ; print label | |
412 MOVII compass_DZ,mpr ; get value | |
413 rcall TFT_compass_fast_helper ; print value | |
414 | |
415 PRINT ; dump to screen | |
416 | |
417 WIN_TINY .0,.104 ; set font and position | |
418 FONT_COLOR_MEMO ; set font color | |
419 | |
420 STRCPY "Ax:" ; print label | |
421 MOVII accel_DX,mpr ; get value | |
422 rcall TFT_compass_fast_helper ; print value | |
423 | |
424 STRCAT " Ay:" ; print label | |
425 MOVII accel_DY,mpr ; get value | |
426 rcall TFT_compass_fast_helper ; print value | |
427 | |
428 STRCAT " Az:" ; print label | |
429 MOVII accel_DZ,mpr ; get value | |
430 rcall TFT_compass_fast_helper ; print value | |
431 | |
432 PRINT ; dump to screen | |
433 return ; done | |
434 | |
435 | |
436 TFT_compass_fast_helper: | |
437 call convert_signed_16bit ; convert lo:hi into unsigned-short and add '-' to POSTINC2 if required | |
438 btfsc neg_flag ; is value negative? | |
439 bra TFT_compass_fast_helper1; YES - print value | |
440 PUTC '+' ; NO - print a plus sign first | |
441 TFT_compass_fast_helper1: | |
442 output_65535 ; print value (0-65535) | |
582 | 443 return |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
444 |
634 | 445 |
446 | |
447 ;----------------------------------------------------------------------------- | |
448 ; Show remaining Calibration Time | |
449 ; | |
450 TFT_show_timeout_testmode: | |
451 WIN_TINY .0,.68 ; set font and position | |
452 FONT_COLOR_MEMO ; set font color | |
453 STRCPY "T:" ; print label | |
454 movff isr_timeout_timer,lo ; get remaining time | |
455 output_256 ; print remaining time (xxx) | |
456 PUTC_PRINT "s" ; append unit and dump to screen | |
457 return ; done | |
458 | |
459 | |
460 ;----------------------------------------------------------------------------- | |
461 ; Show current Compass Gain | |
462 ; | |
628 | 463 TFT_compass_show_gain: ; show the current compass gain |
464 ; movff opt_compass_gain,lo ; 0-7 (230 LSB/Gauss to 1370 LSB/Gauss) | |
582 | 465 ; tstfsz lo |
634 | 466 ; return ; do not show unless gain > 0 |
467 WIN_TINY .0,.86 ; set font and position | |
468 FONT_COLOR_MEMO ; set font color | |
469 STRCPY_TEXT tCompassGain ; print label | |
470 movff opt_compass_gain,lo ; get value: 0-7 (230 LSB/Gauss to 1370 LSB/Gauss) | |
471 output_99 ; print value (xx) | |
472 PRINT ; dump to screen | |
473 return ; done | |
474 | |
475 | |
476 ;============================================================================= | |
477 compass_ops4 CODE | |
478 ;============================================================================= | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
479 |
628 | 480 ;----------------------------------------------------------------------------- |
634 | 481 ; Mask for Compass in Surface Mode |
482 ; | |
582 | 483 global TFT_surface_compass_mask |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
484 TFT_surface_compass_mask: |
582 | 485 WIN_SMALL surf_compass_mask_column,surf_compass_mask_row |
634 | 486 FONT_COLOR_MEMO ; set font color |
628 | 487 STRCPY_TEXT_PRINT tHeading ; print "Heading:" |
634 | 488 return ; done |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
489 |
623 | 490 |
634 | 491 ;----------------------------------------------------------------------------- |
492 ; Compass Display in Surface Mode | |
493 ; | |
582 | 494 global TFT_surface_compass_heading |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
495 TFT_surface_compass_heading: |
634 | 496 call compass_heading_common ; compute heading |
582 | 497 WIN_STD surf_compass_head_column,surf_compass_head_row |
634 | 498 |
628 | 499 TFT_surface_compass_heading_com: ; show "000° N" |
634 | 500 FONT_COLOR_MEMO ; set default / dive-mode standard color |
628 | 501 movff compass_heading_new+1,WREG ; get upper byte of actual heading |
502 btfsc WREG,7 ; compass calibrated? | |
503 bra TFT_compass_uncalibrated ; NO | |
504 MOVII compass_heading_shown,mpr ; get heading to be shown | |
505 rcall TFT_compass_helper ; show heading and its cardinal | |
506 btfsc divemode ; in dive mode? | |
507 return ; YES - done for dive mode | |
508 ; in surface mode - shall show bearing? | |
509 btfss compass_bearing_set ; is a bearing set? | |
510 return ; NO - done | |
511 btfsc compass_menu ; is the "set bearing" selection shown? | |
512 return ; YES - done | |
513 ; show bearing | |
514 WIN_SMALL surf_compass_bear_column,surf_compass_bear_row | |
634 | 515 FONT_COLOR color_yellow ; set font color |
628 | 516 MOVII compass_bearing,mpr ; get bearing |
517 ;bra TFT_compass_helper ; show number and cardinal and return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
518 |
628 | 519 TFT_compass_helper: |
634 | 520 output_999 ; print bearing |
521 STRCAT "° " ; append unit and a space | |
522 call tft_compass_cardinal ; append cardinal buffer | |
523 PRINT ; dump to screen | |
628 | 524 return ; done |
525 | |
526 TFT_compass_uncalibrated: | |
527 STRCAT_PRINT "---°" ; print "---°" | |
528 return ; done | |
382 | 529 |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
530 |
634 | 531 ;============================================================================= |
532 compass_ops5 CODE | |
533 ;============================================================================= | |
534 | |
535 | |
536 ;----------------------------------------------------------------------------- | |
537 ; Mask for Compass in Dive Mode | |
538 ; | |
539 global TFT_dive_compass_mask ; draws the white box around the heading tape | |
540 TFT_dive_compass_mask: | |
541 WIN_FRAME_STD dm_custom_compass_graph_row, dm_custom_compass_graph_row+dm_custom_compass_graph_height, .0, .159 | |
542 return | |
543 | |
544 | |
545 ;----------------------------------------------------------------------------- | |
546 ; Compass Display in Dive Mode | |
547 ; | |
582 | 548 global TFT_dive_compass_heading |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
549 TFT_dive_compass_heading: |
634 | 550 call compass_heading_common ; compute heading |
628 | 551 |
623 | 552 ; ; ### for development only, hard-coding the bearing ### |
582 | 553 ; ; 244° : SW - W |
628 | 554 ; MOVLI .244,xA ; xA used as temp |
555 ; MOVII xA,compass_bearing ; compass_bearing is stored in bank isr_backup | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
556 |
634 | 557 FONT_SIZE FT_SMALL ; set font size |
558 MOVII compass_heading_shown,xA ; get heading | |
623 | 559 ; 160° viewing angle: add +360 offset if xA <= 292 for non-negative scale |
560 MOVLI .292,sub_a | |
561 MOVII xA, sub_b | |
628 | 562 call subU16 ; sub_c = sub_a - sub_b |
563 btfsc neg_flag ; xA > 292 ? | |
564 bra TFT_dive_compass_heading_1 ; YES | |
565 ADDLI .360,xA ; NO - add offset | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
566 TFT_dive_compass_heading_1: |
628 | 567 SUBLI .80,xA ; subtract 80 (left pixel offset from the center) |
568 MOVII xA,xRD ; save result to xRD | |
569 ADDLI .160,xA ; add 160 (display with in pixels) | |
570 MOVII xA,xRDr ; save result to xRDr | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
571 |
628 | 572 btfss compass_bearing_set ; is a bearing set? |
573 bra TFT_dive_compass_ruler ; NO - skip next calculations | |
574 MOVII xRDr,sub_a ; YES - calculate xRD180 = xRDr - 180 | |
623 | 575 MOVLI .180,sub_b |
628 | 576 call subU16 ; sub_c = sub_a - sub_b |
623 | 577 MOVII sub_c,xRD180 |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
578 |
258 | 579 TFT_dive_compass_bearing_1: |
582 | 580 ; calculate bearing position and visibility (ahead or behind) |
628 | 581 bcf compass_bearing_vis ; default is not-visible |
582 bcf compass_bearing_ahd ; default is behind | |
623 | 583 MOVII compass_bearing,xA |
628 | 584 ADDLI .360,xA ; calculate the bearing virtual display offset |
585 MOVII xA,divA ; save it for reuse for upper/lower turns and ahead/behind checks | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
586 |
623 | 587 ; check if bearing is ahead |
628 | 588 MOVII divA,sub_a ; load the bearing offset into sub_a |
589 MOVII xRD, sub_b ; load the display offset back to sub_b | |
582 | 590 rcall TFT_dive_compass_bearing_ap |
628 | 591 btfsc compass_bearing_vis ; bearing visible? |
592 bra TFT_dive_compass_bearing_dir; YES | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
593 |
628 | 594 ; check if it is ahead with an upper turn |
595 MOVII divA,sub_a ; load the bearing offset into sub_a | |
596 MOVII xRD, sub_b ; load the display offset back to sub_b | |
623 | 597 ADDLI .360,sub_b |
582 | 598 rcall TFT_dive_compass_bearing_ap |
628 | 599 btfsc compass_bearing_vis ; bearing visible? |
600 bra TFT_dive_compass_bearing_dir; YES | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
601 |
628 | 602 ; check if it is ahead with a lower turn |
603 MOVII divA,sub_a ; load the bearing offset into sub_a | |
623 | 604 ADDLI .360,sub_a |
628 | 605 MOVII xRD, sub_b ; load the display offset back to sub_b |
582 | 606 rcall TFT_dive_compass_bearing_ap |
628 | 607 btfsc compass_bearing_vis ; bearing visible? |
608 bra TFT_dive_compass_bearing_dir; YES | |
258 | 609 |
623 | 610 ; marker is not ahead of us, check if it is behind of us |
582 | 611 ; use the (160 - (xRD180 - xCM)) formula to see if it's on the display |
628 | 612 MOVII xRD180,sub_a ; load the display offset back to sub_a |
613 MOVII divA, sub_b ; load the marker's offset into sub_b | |
582 | 614 rcall TFT_dive_compass_bearing_bp |
628 | 615 btfsc compass_bearing_vis ; bearing behind of us? |
616 bra TFT_dive_compass_bearing_dir; YES | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
617 |
628 | 618 ; check if it is behind with the upper turn |
623 | 619 MOVII xRD180,sub_a |
620 MOVII divA, sub_b | |
621 ADDLI .360, sub_b | |
622 rcall TFT_dive_compass_bearing_bp | |
628 | 623 btfsc compass_bearing_vis ; bearing behind of us? |
624 bra TFT_dive_compass_bearing_dir; YES | |
623 | 625 |
628 | 626 ; check if it is behind with the lower turn |
623 | 627 MOVII xRD180,sub_a |
628 ADDLI .360, sub_a | |
628 | 629 MOVII divA, sub_b ; load the marker's offset into sub_b |
582 | 630 rcall TFT_dive_compass_bearing_bp |
631 bra TFT_dive_compass_bearing_dir | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
632 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
633 TFT_dive_compass_bearing_ap: |
582 | 634 ; xCM received in sub_a |
635 ; xRD received in sub_b | |
636 ; 1/a. check if it's viewable from the left side | |
628 | 637 call subU16 ; sub_c = sub_a - sub_b |
638 btfsc neg_flag ; xRD > divA ? | |
639 return ; NO - done | |
640 MOVII sub_c,xC ; YES - store the RO=RP-RD for drawing | |
623 | 641 ; 1/b. check if it's viewable from the right side |
628 | 642 ADDLI .2,sub_a ; avoid thin mess on the side of the display |
643 ADDLI .158,sub_b ; load the display offset right side into sub_b | |
644 call subU16 ; sub_c = sub_a - sub_b | |
645 btfss neg_flag ; xRDr > xA(+2) ? | |
646 return ; NO - done | |
647 ; YES - print the bearing lines on the screen | |
582 | 648 movff xC+0,xCM |
628 | 649 bsf compass_bearing_vis ; set visible |
650 bsf compass_bearing_ahd ; set ahead | |
651 return ; done | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
652 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
653 TFT_dive_compass_bearing_bp: |
582 | 654 ; use the (160 - (xRD180 - xCM)) formula to see if it's on the display |
655 ; the marker's offset received in sub_b | |
656 ; the xRD180 display offset received in sub_a | |
657 ; xRD180 - xCM | |
628 | 658 call subU16 ; sub_c = sub_a - sub_b |
659 btfsc neg_flag ; CM > xRD180 ? | |
660 return ; NO - not on screen, done | |
661 ; YES - check 160 - (X) | |
662 MOVLI .158, sub_a ; 158 to avoid thin mess on the side of the display | |
623 | 663 MOVII sub_c,sub_b |
628 | 664 call subU16 ; sub_c = sub_a - sub_b |
665 btfsc neg_flag ; X > 160 ? | |
666 return ; NO - not on screen, done | |
623 | 667 ; check if not overflow - this sounds like a double check... |
628 | 668 tstfsz sub_c+1 ; high byte = 0 ? |
669 return ; NO - sub_c must be > 160 then, done | |
670 movlw d'158' ; YES - load a 158 | |
671 cpfslt sub_c+0 ; - low byte < 158 ? | |
672 return ; NO - done | |
673 movff sub_c+0,xCM ; YES - print the bearing lines on the screen | |
674 bsf compass_bearing_vis ; - flag to show bearing lines | |
675 return ; - done | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
676 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
677 TFT_dive_compass_bearing_dir: |
582 | 678 ; check if bearing to heading, and calculate the direction |
679 bcf compass_bearing_eq | |
680 btfss compass_bearing_vis | |
681 bra TFT_dive_compass_bearing_lr | |
682 btfss compass_bearing_ahd | |
683 bra TFT_dive_compass_bearing_lr | |
684 movff xCM,xA+0 | |
685 movlw d'80' | |
686 cpfseq xA+0 | |
687 bra TFT_dive_compass_bearing_lr | |
688 bsf compass_bearing_eq | |
628 | 689 bra TFT_dive_compass_ruler ; bearing points to heading, no signs are required, go to the ruler |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
690 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
691 TFT_dive_compass_bearing_lr: |
582 | 692 ; get the bearing virtual display offset |
623 | 693 MOVII compass_bearing,xA |
694 ; xA = xA > 292 ? xA : xA+360 | |
695 MOVLI .292,sub_a | |
696 MOVII xA, sub_b | |
628 | 697 call subU16 ; sub_c = sub_a - sub_b |
698 btfsc neg_flag ; xA > 292 ? | |
699 bra TFT_dive_compass_bearing_lr_1; YES | |
700 ADDLI .360,xA ; NO - add 360 | |
623 | 701 |
258 | 702 TFT_dive_compass_bearing_lr_1: |
582 | 703 ; 1. calculate whether bearing is to left or to right |
628 | 704 bsf compass_bearing_lft ; to the left by default |
582 | 705 ; xC: save center value to compare the direction to front value |
623 | 706 MOVII xA,xC |
582 | 707 ; xB: we need the left side for comparison... left = -180 |
623 | 708 MOVII xA, sub_a |
709 MOVLI .180,sub_b | |
628 | 710 call subU16 ; sub_c = sub_a - sub_b |
711 MOVII sub_c,xB ; xB has the left side of the 180° distance center | |
623 | 712 ; xA = xRD > (xC+100) ? RD-280 : xRD+80 |
713 MOVII xC, sub_a | |
714 ADDLI .100,sub_a | |
715 MOVII xRD, sub_b | |
628 | 716 call subU16 ; sub_c = sub_a - sub_b |
717 btfsc neg_flag ; xRD > xC + 100 ? | |
718 bra TFT_dive_compass_bearing_lr_2; YES - xA = xRD - 280 | |
719 ; NO - xA = xRD + 80 | |
623 | 720 MOVII xRD,xA |
721 ADDLI .80,xA | |
582 | 722 bra TFT_dive_compass_bearing_lr_c |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
723 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
724 TFT_dive_compass_bearing_lr_2: |
623 | 725 MOVII xRD,sub_a |
726 MOVLI .280,sub_b | |
628 | 727 call subU16 ; sub_c = sub_a - sub_b |
623 | 728 MOVII sub_c,xA |
582 | 729 ;bra TFT_dive_compass_bearing_lr_c |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
730 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
731 TFT_dive_compass_bearing_lr_c: |
582 | 732 ; xB < xA < xC => right, otherwise left (default) |
623 | 733 MOVII xA,sub_b |
734 MOVII xB,sub_a | |
628 | 735 call subU16 ; sub_c = sub_a - sub_b |
736 btfss neg_flag ; xA > xB ? | |
737 bra TFT_dive_compass_ruler ; NO - xB >= xA, keep default left | |
623 | 738 MOVII xA,sub_a |
739 MOVII xC,sub_b | |
628 | 740 call subU16 ; sub_c = sub_a - sub_b |
741 btfss neg_flag ; xC > xA ? | |
742 bra TFT_dive_compass_ruler ; NO - xA >= xC, keep default left | |
582 | 743 bcf compass_bearing_lft |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
744 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
745 TFT_dive_compass_ruler: |
582 | 746 ; calculate mod15 for the ticks |
623 | 747 MOVII xRD,xA |
748 MOVLI .15,xB | |
628 | 749 call div16x16 ; xA/xB=xC with xA+0 as remainder |
623 | 750 ; check the remainder |
582 | 751 movlw d'0' |
628 | 752 cpfsgt xA+0 ; mod15 > 0 ? |
753 bra TFT_dive_compass_ruler_1 ; NO - RM = 0 | |
754 ; YES - RM = 15 - RDmod15 | |
582 | 755 movlw d'15' |
623 | 756 subfwb xA+0,F |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
757 TFT_dive_compass_ruler_1: |
628 | 758 movff xA+0,lo ; xA+0 holds the RM, store it to 'lo' |
759 clrf hi ; initialize DD to zero, store it to 'hi' | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
760 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
761 TFT_dive_compass_ruler_loop: |
623 | 762 ; 1. check if we run out of the display |
628 | 763 movlw d'159' ; looks like 159 works because TFT_box limits the display |
582 | 764 cpfslt lo,1 |
628 | 765 bra TFT_dive_compass_ruler_lend ; xRM >= W |
582 | 766 ; 2. Clear the tick area from DD to RM - in segments to avoid blinking |
767 ; don't do a clear if we are at 0 (zero) otherwise it will blink | |
768 ; because of the width underflow | |
769 movlw d'0' | |
770 cpfsgt lo,1 | |
771 bra TFT_dive_compass_ruler_loop_zz | |
772 rcall TFT_dive_compass_clr_ruler | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
773 TFT_dive_compass_ruler_loop_zz: |
582 | 774 ; 3. Draw the markers @ RM |
775 ; we receive RM in lo and DD in hi | |
776 movlw d'2' | |
628 | 777 movwf win_bargraph ; set with of ticks |
582 | 778 movwf win_width+0 |
779 clrf win_width+1 | |
628 | 780 movff lo,win_leftx2 ; 0..159 |
781 movlw dm_custom_compass_tick_top_top | |
782 movwf win_top ; set position for upper ticks | |
582 | 783 movlw dm_custom_compass_tick_height |
628 | 784 movwf win_height ; set hight of ticks |
634 | 785 movf pallet_color_memo,W ; select color |
786 BOX_COLOR ; draw tick | |
628 | 787 movlw dm_custom_compass_tick_bot_top |
788 movwf win_top ; set position for lower ticks | |
789 movlw dm_custom_compass_tick_height | |
790 movwf win_height ; set hight of ticks | |
634 | 791 movf pallet_color_memo,W ; select color |
792 BOX_COLOR ; draw tick | |
628 | 793 ; 4. If D < 82 and RM > 79: means we put something over the center line, |
794 ; so redraw the center line | |
582 | 795 movlw d'82' |
796 cpfslt hi,1 | |
797 bra TFT_dive_compass_ruler_loop_zz2 | |
798 movlw d'79' | |
799 cpfsgt lo,1 | |
800 bra TFT_dive_compass_ruler_loop_zz2 | |
623 | 801 ; enough to print center line as bearing marker is not in the ticker area |
628 | 802 rcall TFT_dive_compass_c ; draw center line in yellow |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
803 TFT_dive_compass_ruler_loop_zz2: |
582 | 804 ; 5. set D = RM + 2 : position after the 2px tick |
805 movff lo,hi | |
806 movlw d'2' | |
807 addwf hi,F | |
808 ; 6. set RM = RM + 15 : position to the next tick | |
809 movlw d'15' | |
810 addwf lo,F | |
811 ; 7. loop | |
812 bra TFT_dive_compass_ruler_loop | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
813 |
628 | 814 TFT_dive_compass_ruler_lend: ; loop end |
815 ; 8. clear the rest of the tick area if D < 160 | |
582 | 816 movlw d'160' |
817 cpfslt hi | |
628 | 818 bra TFT_dive_compass_labels ; D >= W |
582 | 819 ; 9. position left to end of display to clear the remaining area |
820 movlw d'159' | |
821 movwf lo | |
822 ; 10. clear it | |
823 rcall TFT_dive_compass_clr_ruler | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
824 |
628 | 825 TFT_dive_compass_labels: |
582 | 826 ; done with the compass ruler, put the labels on the screen |
634 | 827 FONT_COLOR_MEMO ; set dive-mode standard color |
628 | 828 clrf hi ; hi stores the display position |
829 movff hi,xHI ; bank-safe clear of xHI | |
830 clrf lo ; lo stores the last item's display position | |
831 movff lo,xLO ; bank-safe clear of xLO | |
832 MOVLI .219,sub_a ; position of the cardinal | |
833 MOVII xRD, sub_b ; get the RD back to sub_b | |
834 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
835 btfss compass_show_cardinal ; shall show cardinal? | |
836 bra dcr_1 ; NO | |
837 STRCPY_TEXT_PRINT tSW ; YES - print it | |
582 | 838 dcr_1: |
628 | 839 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
840 MOVLI .267,sub_a ; position of the cardinal | |
841 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
842 btfss compass_show_cardinal ; shall show cardinal? | |
843 bra dcr_2 ; NO | |
844 STRCPY_TEXT_PRINT tW ; YES - print it | |
582 | 845 dcr_2: |
628 | 846 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
847 MOVLI .309,sub_a ; position of the cardinal | |
848 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
849 btfss compass_show_cardinal ; shall show cardinal? | |
850 bra dcr_3 ; NO | |
851 STRCPY_TEXT_PRINT tNW ; YES - print it | |
582 | 852 dcr_3: |
628 | 853 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
854 MOVLI .358,sub_a ; position of the cardinal | |
855 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
856 btfss compass_show_cardinal ; shall show cardinal? | |
857 bra dcr_4 ; NO | |
858 STRCPY_TEXT_PRINT tN ; YES - print it | |
582 | 859 dcr_4: |
628 | 860 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
861 MOVLI .399,sub_a ; position of the cardinal | |
862 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
863 btfss compass_show_cardinal ; shall show cardinal? | |
864 bra dcr_5 ; NO | |
865 STRCPY_TEXT_PRINT tNE ; YES - print it | |
582 | 866 dcr_5: |
628 | 867 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
868 MOVLI .448,sub_a ; position of the cardinal | |
869 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
870 btfss compass_show_cardinal ; shall show cardinal? | |
871 bra dcr_6 ; NO | |
872 STRCPY_TEXT_PRINT tE ; YES - print it | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
873 dcr_6: |
628 | 874 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
875 MOVLI .489,sub_a ; position of the cardinal | |
876 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
877 btfss compass_show_cardinal ; shall show cardinal? | |
878 bra dcr_7 ; NO | |
879 STRCPY_TEXT_PRINT tSE ; YES - print it | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
880 dcr_7: |
628 | 881 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
882 MOVLI .538,sub_a ; position of the cardinal | |
883 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
884 btfss compass_show_cardinal ; shall show cardinal? | |
885 bra dcr_8 ; NO | |
886 STRCPY_TEXT_PRINT tS ; YES - print it | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
887 dcr_8: |
628 | 888 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
889 MOVLI .579,sub_a ; position of the cardinal | |
890 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
891 btfss compass_show_cardinal ; shall show cardinal? | |
892 bra dcr_9 ; NO | |
893 STRCPY_TEXT_PRINT tSW ; YES - print it | |
582 | 894 dcr_9: |
628 | 895 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
896 MOVLI .627,sub_a ; position of the cardinal | |
897 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
898 btfss compass_show_cardinal ; shall show cardinal? | |
899 bra dcr_10 ; NO | |
900 STRCPY_TEXT_PRINT tW ; YES - print it | |
582 | 901 dcr_10: |
628 | 902 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
903 MOVLI .669,sub_a ; position of the cardinal | |
904 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
905 btfss compass_show_cardinal ; shall show cardinal? | |
906 bra dcr_11 ; NO | |
907 STRCPY_TEXT_PRINT tNW ; YES - print it | |
582 | 908 dcr_11: |
628 | 909 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
910 MOVLI .718,sub_a ; position of the cardinal | |
911 rcall TFT_dive_compass_label_proc ; check if the cardinal shall be on screen | |
912 btfss compass_show_cardinal ; shall show? | |
913 bra dcr_12 ; NO | |
914 STRCPY_TEXT_PRINT tN ; YES - print it | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
915 dcr_12: |
628 | 916 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
917 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
918 TFT_dive_compass_label_end: |
628 | 919 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
582 | 920 ; restore lo and hi for the final cleanup |
628 | 921 movff xLO,lo ; xLO and xHI are stored in bank isr_backup |
582 | 922 movff xHI,hi |
628 | 923 ; clear the rest of the SQ area if there is more space |
582 | 924 movlw d'159' |
925 cpfslt hi | |
628 | 926 bra TFT_dive_compass_label_end2 ; D >= 160, no more space |
582 | 927 ; position left to end of display to clear the remaining area |
928 movlw d'158' | |
929 movwf lo | |
930 ; clear it | |
931 rcall TFT_dive_compass_clr_label | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
932 TFT_dive_compass_label_end2: |
628 | 933 rcall TFT_dive_compass_c_mk ; check if cardinal is on the center line or the marker |
582 | 934 ; do we have bearing set? |
628 | 935 btfsc compass_bearing_set ; bearing set? |
936 bra TFT_dive_compass_dir_text ; YES - print the direction (<< or >>) | |
937 rcall TFT_dive_compass_dir_lclr ; NO - clear the area (e.g. we had but removed) | |
582 | 938 rcall TFT_dive_compass_dir_rclr |
939 bra TFT_dive_compass_text | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
940 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
941 TFT_dive_compass_dir_text: |
582 | 942 ; bearing set, but does it point to heading? |
943 btfss compass_bearing_eq | |
628 | 944 bra TFT_dive_compass_dir_text_2 ; bearing != heading - go and print the direction |
945 rcall TFT_dive_compass_dir_lclr ; bearing == heading - no need for direction markers | |
582 | 946 rcall TFT_dive_compass_dir_rclr |
947 bra TFT_dive_compass_text | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
948 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
949 TFT_dive_compass_dir_text_2: |
634 | 950 FONT_COLOR color_green |
582 | 951 btfsc compass_bearing_lft |
628 | 952 bra TFT_dive_compass_dir_ldir ; bearing_lft=1, print the left marker |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
953 ;TFT_dive_compass_text_rdir: |
582 | 954 WIN_SMALL dm_custom_compass_rdir_column, dm_custom_compass_head_row-.2 |
955 STRCPY_PRINT ">>" | |
628 | 956 rcall TFT_dive_compass_dir_lclr ; do not forget to clear the left |
582 | 957 bra TFT_dive_compass_text |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
958 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
959 TFT_dive_compass_dir_ldir: |
582 | 960 WIN_SMALL dm_custom_compass_ldir_column, dm_custom_compass_head_row-.2 |
961 STRCPY_PRINT "<<" | |
628 | 962 rcall TFT_dive_compass_dir_rclr ; do not forget to clear the right |
582 | 963 ;bra TFT_dive_compass_text |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
964 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
965 TFT_dive_compass_text: |
582 | 966 ; Clear some unused space on the right mH |
967 WIN_BOX_BLACK dm_custom_compass_tick_top_bot+.1,dm_custom_compass_tick_bot_top-.1,.158,.159 ; top, bottom, left, right | |
371 | 968 |
582 | 969 ; Text output |
970 WIN_SMALL dm_custom_compass_head_column, dm_custom_compass_head_row | |
634 | 971 call TFT_surface_compass_heading_com ; show "xxx° N" |
582 | 972 return |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
973 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
974 TFT_dive_compass_dir_lclr: |
582 | 975 WIN_SMALL dm_custom_compass_ldir_column, dm_custom_compass_head_row-.2 |
976 STRCPY_PRINT " " | |
977 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
978 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
979 TFT_dive_compass_dir_rclr: |
582 | 980 WIN_SMALL dm_custom_compass_rdir_column, dm_custom_compass_head_row-.2 |
981 STRCPY_PRINT " " | |
982 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
983 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
984 TFT_dive_compass_label_proc: |
582 | 985 movlw d'14' |
628 | 986 movwf up ; cardinal width in px |
623 | 987 bcf compass_show_cardinal |
582 | 988 ; 1/a. check if it's viewable ? sub_a(RP) >= sub_b(RD) ? |
989 ; set the carry flag if sub_b(xRD) is equal to or greater than sub_a(xRP): | |
623 | 990 MOVII xRD,sub_b |
628 | 991 call subU16 ; sub_c = sub_a - sub_b |
992 btfsc neg_flag ; >= 0 ? | |
993 return ; NO | |
582 | 994 ; store the RO=RP-RD for drawing |
623 | 995 MOVII sub_c,xC |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
996 |
582 | 997 ; 1/b. check if it's viewable ? sub_a(RP)+up(width) < sub_b(RD)+160 |
998 ; if already above, no need to process the rest of the labels | |
628 | 999 movff up,WREG ; take care about the width |
582 | 1000 addwf sub_a+0,1 |
1001 btfsc STATUS, C | |
1002 incf sub_a+1 | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1003 |
623 | 1004 MOVII xRDr,sub_b |
628 | 1005 call subU16 ; sub_c = sub_a - sub_b |
1006 btfss neg_flag ; < 0 ? | |
1007 bra TFT_dive_compass_label_end ; NO | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1008 |
582 | 1009 ; 2. restore RO=RP-RD from 1/a. |
1010 movff xC+0,lo | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1011 |
582 | 1012 ; 3. Clear the segment from DD(hi) to lo |
1013 ; don't do a clear if we are at 0 (zero) otherwise it will blink | |
1014 ; ?because of the width underflow? | |
1015 movlw d'1' | |
1016 cpfsgt lo | |
1017 bra TFT_dive_compass_label_proc_p | |
1018 rcall TFT_dive_compass_clr_label | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1019 TFT_dive_compass_label_proc_p: |
582 | 1020 ; 4. print the SQ on the screen |
634 | 1021 FONT_COLOR_MEMO |
623 | 1022 bsf compass_show_cardinal |
257
5dd0f39d05d4
minor speed and size improvements for the compass routine
heinrichsweikamp
parents:
256
diff
changeset
|
1023 ;TFT_dive_compass_label_print: |
634 | 1024 movlw dm_custom_compass_label_row ; set output position |
1025 movff WREG,win_top ; ... | |
1026 movff lo,win_leftx2 ; ... | |
1027 FONT_SIZE FT_SMALL ; set font size | |
582 | 1028 ; 6. retain the new display positions |
1029 movff lo,hi | |
1030 movff up,WREG | |
1031 addwf hi,F | |
1032 movff lo,xLO | |
1033 movff hi,xHI | |
1034 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1035 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1036 TFT_dive_compass_c_mk: |
582 | 1037 ; Common task to draw center line and marker |
1038 ; until a proper implementation make it simple: | |
1039 rcall TFT_dive_compass_mk | |
628 | 1040 TFT_dive_compass_c: |
582 | 1041 movlw color_yellow |
1042 WIN_BOX_COLOR dm_custom_compass_tick_top_top, dm_custom_compass_tick_bot_bot,.80,.81 ; center line in yellow | |
1043 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1044 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1045 TFT_dive_compass_mk: |
582 | 1046 ; draw the bearing on the screen if visible and if we just put something over it |
628 | 1047 btfss compass_bearing_set ; bearing set? |
1048 return ; NO - done | |
1049 btfss compass_bearing_vis ; YES - bearing visible? | |
1050 return ; NO - bearing set but not visible, done | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1051 |
582 | 1052 ; save lo/hi from trashing |
623 | 1053 MOVII mpr,xA |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1054 |
582 | 1055 ; did we just update the marker's position? |
1056 ; DD.......DD | |
1057 ; CM+2>=DD(old) or CM-2<=DD | |
1058 ; ToDo | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1059 |
582 | 1060 btfss compass_bearing_ahd |
1061 bra TFT_dive_compass_mk_rear | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1062 ;TFT_dive_compass_mk_front: |
582 | 1063 clrf lo |
1064 movff xCM,lo | |
628 | 1065 bsf compass_show_cardinal ; set=green marker |
582 | 1066 rcall TFT_dive_compass_mk_print |
623 | 1067 bcf compass_show_cardinal |
582 | 1068 bra TFT_dive_compass_mk_end |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1069 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1070 TFT_dive_compass_mk_rear: |
582 | 1071 clrf lo |
1072 movff xCM,lo | |
628 | 1073 bcf compass_show_cardinal ; set=red marker |
582 | 1074 rcall TFT_dive_compass_mk_print |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1075 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1076 TFT_dive_compass_mk_end: |
623 | 1077 MOVII xA,mpr |
582 | 1078 return |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1079 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1080 TFT_dive_compass_mk_print: |
582 | 1081 movlw d'1' |
1082 cpfsgt lo | |
628 | 1083 bra TFT_dive_compass_mk_print_2 ; lo <= 1, skip the first line |
582 | 1084 movlw d'2' |
1085 subwf lo,0 | |
1086 ; movff WREG,win_leftx2 | |
1087 rcall TFT_dive_compass_mk_print_3 | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1088 TFT_dive_compass_mk_print_2: |
582 | 1089 ; save hi/lo |
623 | 1090 MOVII mpr,divA |
582 | 1091 ; clear the middle of the bearing marker |
1092 movff lo,hi | |
1093 movlw d'2' | |
1094 addwf lo,1 | |
1095 rcall TFT_dive_compass_clr_label | |
1096 ; restore hi/lo | |
623 | 1097 MOVII divA,mpr |
582 | 1098 ; print a dot on the middle |
623 | 1099 movf lo,W |
582 | 1100 rcall TFT_dive_compass_mk_print_dot |
1101 ; finally print the right marker line | |
1102 movlw d'2' | |
1103 addwf lo,0 | |
1104 ; rcall TFT_dive_compass_mk_print_3 | |
1105 ; return | |
257
5dd0f39d05d4
minor speed and size improvements for the compass routine
heinrichsweikamp
parents:
256
diff
changeset
|
1106 TFT_dive_compass_mk_print_3: |
582 | 1107 movwf win_leftx2 |
1108 movlw dm_custom_compass_label_row | |
1109 movwf win_top | |
1110 movlw dm_custom_compass_label_height-.2 | |
1111 movwf win_height | |
1112 bra TFT_dive_compass_mk_print_4 | |
264
9dbdb060d44c
Fix compass ruler's missing bottom ticks; Clear between the bearing marker lines and draw a dot.
janos_kovacs <kovjanos@gmail.com>
parents:
259
diff
changeset
|
1113 TFT_dive_compass_mk_print_dot: |
582 | 1114 movwf win_leftx2 |
1115 movlw dm_custom_compass_label_row + .9 | |
1116 movwf win_top | |
1117 movlw d'4' | |
1118 movwf win_height | |
264
9dbdb060d44c
Fix compass ruler's missing bottom ticks; Clear between the bearing marker lines and draw a dot.
janos_kovacs <kovjanos@gmail.com>
parents:
259
diff
changeset
|
1119 TFT_dive_compass_mk_print_4: |
582 | 1120 movlw .158 |
1121 cpfslt win_leftx2 | |
1122 bra TFT_dive_compass_mk_print_5 | |
1123 movlw d'2' | |
623 | 1124 movwf win_bargraph |
582 | 1125 movwf win_width+0 |
1126 clrf win_width+1 | |
1127 movlw color_green | |
623 | 1128 btfss compass_show_cardinal |
634 | 1129 movlw color_red ; select color |
1130 BOX_COLOR ; draw box | |
371 | 1131 TFT_dive_compass_mk_print_5: |
582 | 1132 return |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1133 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1134 TFT_dive_compass_clr_label: |
582 | 1135 movlw dm_custom_compass_label_row-.2 ; set top & height |
623 | 1136 movwf win_top |
582 | 1137 movlw dm_custom_compass_label_height+.2 |
623 | 1138 movwf win_height |
582 | 1139 rcall TFT_dive_compass_clear |
1140 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1141 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1142 TFT_dive_compass_clr_ruler: |
582 | 1143 ; top tick |
1144 movlw dm_custom_compass_tick_top_top ; set top & height | |
623 | 1145 movwf win_top |
582 | 1146 movlw dm_custom_compass_tick_height |
623 | 1147 movwf win_height |
582 | 1148 rcall TFT_dive_compass_clear |
1149 ;bottom tick | |
1150 movlw dm_custom_compass_tick_bot_top ; set top & height | |
623 | 1151 movwf win_top |
582 | 1152 movlw dm_custom_compass_tick_height |
623 | 1153 movwf win_height |
582 | 1154 ; rcall TFT_dive_compass_clear |
1155 ; return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1156 TFT_dive_compass_clear: |
582 | 1157 ; we receive RM in lo and DD in hi |
1158 ; calculate width = RM-D | |
623 | 1159 movf hi,W |
582 | 1160 subwf lo,W |
623 | 1161 bz TFT_dive_compass_clear3 ; do nothing if there is nothing to do |
582 | 1162 movwf win_width+0 ; RM-DD |
1163 movwf win_bargraph | |
1164 clrf win_width+1 | |
1165 movlw .1 | |
1166 cpfsgt win_width+0 | |
623 | 1167 bra TFT_dive_compass_clear3 ; do not clear a single pixel (or less) |
582 | 1168 movff hi,win_leftx2 |
634 | 1169 movlw color_black ; select color |
1170 BOX_COLOR ; draw box | |
370 | 1171 TFT_dive_compass_clear3: |
582 | 1172 return |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1173 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1174 tft_compass_cardinal: |
623 | 1175 btfsc hi,0 ; heading > 255° ? |
1176 bra tft_compass_cardinal2 ; YES - must be W, NW or N | |
1177 ; NO - must be W, SW, S, SE, E, NE or N | |
582 | 1178 movlw .23 |
1179 subwf lo,W | |
1180 btfss STATUS,C | |
1181 bra tft_compass_cardinal_N | |
1182 movlw .68 | |
1183 subwf lo,W | |
1184 btfss STATUS,C | |
1185 bra tft_compass_cardinal_NE | |
1186 movlw .113 | |
1187 subwf lo,W | |
1188 btfss STATUS,C | |
1189 bra tft_compass_cardinal_E | |
1190 movlw .158 | |
1191 subwf lo,W | |
1192 btfss STATUS,C | |
1193 bra tft_compass_cardinal_SE | |
1194 movlw .203 | |
1195 subwf lo,W | |
1196 btfss STATUS,C | |
1197 bra tft_compass_cardinal_S | |
1198 movlw .248 | |
1199 subwf lo,W | |
1200 btfss STATUS,C | |
1201 bra tft_compass_cardinal_SW | |
1202 bra tft_compass_cardinal_W | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1203 |
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1204 tft_compass_cardinal2: |
582 | 1205 movlw .37 |
1206 subwf lo,W | |
1207 btfss STATUS,C | |
1208 bra tft_compass_cardinal_W | |
1209 movlw .82 | |
1210 subwf lo,W | |
1211 btfss STATUS,C | |
1212 bra tft_compass_cardinal_NW | |
1213 ; bra tft_compass_cardinal_N | |
1214 | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1215 tft_compass_cardinal_N: |
582 | 1216 STRCAT_TEXT tN |
1217 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1218 tft_compass_cardinal_NE: |
582 | 1219 STRCAT_TEXT tNE |
1220 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1221 tft_compass_cardinal_E: |
582 | 1222 STRCAT_TEXT tE |
1223 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1224 tft_compass_cardinal_SE: |
582 | 1225 STRCAT_TEXT tSE |
1226 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1227 tft_compass_cardinal_S: |
582 | 1228 STRCAT_TEXT tS |
1229 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1230 tft_compass_cardinal_SW: |
582 | 1231 STRCAT_TEXT tSW |
1232 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1233 tft_compass_cardinal_W: |
582 | 1234 STRCAT_TEXT tW |
1235 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1236 tft_compass_cardinal_NW: |
582 | 1237 STRCAT_TEXT tNW |
1238 return | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1239 |
634 | 1240 ;============================================================================= |
1241 compass_ops6 CODE | |
1242 ;============================================================================= | |
1243 | |
628 | 1244 ;----------------------------------------------------------------------------- |
634 | 1245 ; get and process heading |
1246 ; | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1247 compass_heading_common: |
623 | 1248 btfss compass_enabled ; compass enabled? |
628 | 1249 bra compass_heading_common_zero ; NO |
623 | 1250 |
628 | 1251 ; Get an averaged new heading |
623 | 1252 movlw compass_averaging ; number of averaging cycles |
1253 movwf up ; initialize loop counter | |
628 | 1254 compass_heading_common_1: |
623 | 1255 call I2C_RX_compass ; test compass |
1256 call I2C_RX_accelerometer ; test accelerometer | |
1257 call compass_filter ; filter raw compass + accelerometer readings | |
1258 decfsz up,F ; decrement loop counter, done? | |
628 | 1259 bra compass_heading_common_1 ; NO - loop |
623 | 1260 |
628 | 1261 call compass ; do compass correction (C-code) |
623 | 1262 banksel common ; back to bank common |
1263 | |
628 | 1264 ; Check for calibration and change |
1265 MOVII compass_heading_shown,sub_a ; transfer shown heading to sub_a | |
1266 MOVII compass_heading_new, sub_b ; transfer new heading to sub_b | |
623 | 1267 |
1268 btfsc sub_b+1,7 ; valid compass calibration? | |
628 | 1269 bra compass_heading_common_zero ; NO |
1270 | |
1271 movf sub_a+0,W ; get shown heading, low byte | |
1272 cpfseq sub_b+0 ; compare with new heading, low byte, equal? | |
1273 bra compass_heading_common_2 ; NO - not equal | |
1274 movf sub_a+1,W ; get shown heading, high byte | |
1275 cpfseq sub_b+1 ; compare with new heading, high byte, equal? | |
1276 bra compass_heading_common_2 ; NO - not equal | |
1277 return ; YES - done | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1278 |
628 | 1279 compass_heading_common_2: |
1280 ; turn both headings such that compass_heading_new points to 0° | |
1281 call subU16 ; sub_c = compass_heading_shown - compass_heading_new | |
1282 btfss neg_flag ; was compass_heading_new in 1st halve? | |
1283 bra compass_heading_common_3 ; YES - check where compass_heading_shown is now | |
1284 MOVLI .360, sub_a ; NO - overturned, need to turn back to match 360° | |
1285 MOVII sub_c,sub_b ; - move overturned compass_heading_new to sub_b | |
1286 call subU16 ; - sub_c = angle between overturned compass_heading_shown and 360° | |
1287 compass_heading_common_3: | |
1288 ; check if turned compass_heading_shown is in 1st or 2nd halve | |
1289 MOVII sub_c,sub_a ; sub_a = turned compass_heading_shown | |
1290 MOVLI .180, sub_b ; sub_b = begin of 2nd halve | |
1291 call cmpU16 ; check (turned compass_heading_shown) - 180° | |
1292 btfss neg_flag ; result negative? | |
1293 bra compass_heading_common_5 ; NO - in 2nd halve, increment towards compass_heading_new | |
1294 ;bra compass_heading_common_4 ; YES - in 1st halve, decrement towards compass_heading_new | |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1295 |
628 | 1296 compass_heading_common_4: |
1297 ; decrement compass_heading_shown towards compass_heading_new | |
1298 rcall compass_heading_stepsize_2 ; calculate step size and put it into sub_b | |
1299 MOVII compass_heading_shown,sub_a ; transfer unturned shown heading to sub_a | |
1300 call subU16 ; decrement heading: sub_c = compass_heading_shown - step size | |
1301 btfss neg_flag ; did an under-run occur? | |
1302 bra compass_heading_common_6 ; NO - store result | |
1303 MOVLI .360, sub_a ; YES - wrap around 360° | |
1304 MOVII sub_c,sub_b ; - transfer decrement result to sub_b | |
1305 call subU16 ; - wrap decrement result around | |
1306 bra compass_heading_common_6 ; - store wrapped result | |
1307 | |
1308 compass_heading_common_5: | |
1309 ; increment compass_heading_shown towards compass_heading_new | |
1310 rcall compass_heading_stepsize_1 ; calculate step size and put it into sub_b | |
1311 MOVII compass_heading_shown,sub_a ; transfer unturned shown heading to sub_a | |
1312 call addU16 ; increment heading: sub_c = compass_heading_shown + step size | |
1313 MOVII sub_c,sub_a ; transfer increment result to sub_a | |
1314 MOVLI .360, sub_b ; load wrap-around threshold | |
1315 call subU16 ; calculate if over-run occurred | |
1316 btfss neg_flag ; did an over-run occur? | |
1317 bra compass_heading_common_6 ; YES - store already wrapped-around result | |
1318 MOVII sub_a,sub_c ; NO - retrieve former straight increment result | |
1319 bra compass_heading_common_6 ; - store wrapped result | |
1320 | |
1321 compass_heading_common_zero: | |
1322 CLRI sub_c ; set heading to 0° | |
1323 ;bra compass_heading_common_6 ; store heading | |
1324 | |
1325 compass_heading_common_6: | |
1326 MOVII sub_c,compass_heading_shown ; store new shown heading | |
1327 return ; done | |
1328 | |
1329 compass_heading_stepsize_1: | |
1330 ; turn heading difference (180...359) into a step size | |
1331 MOVLI .360, sub_a ; load 360° | |
1332 MOVII sub_c,sub_b ; load difference | |
1333 call subU16 ; sub_c = 360 - difference (i.e. 1...180 now) | |
1334 compass_heading_stepsize_2: | |
1335 ; turn heading difference (1...180) into a step size | |
1336 bcf STATUS,C ; clear carry | |
1337 rrcf sub_c+0 ; heading difference /= 2 | |
1338 bcf STATUS,C ; clear carry | |
1339 rrcf sub_c+0 ; heading difference /= 2, total /= 4 now | |
1340 incf sub_c+0,f ; final += 1 to have one increment / decrement at least | |
1341 MOVII sub_c,sub_b ; transfer result to sub_b | |
1342 return | |
1343 | |
623 | 1344 ENDIF ; _compass |
256
5b4ef0b9090d
place compass display code into compass_ops.asm
heinrichsweikamp
parents:
214
diff
changeset
|
1345 |
634 | 1346 ;----------------------------------------------------------------------------- |
1347 | |
582 | 1348 END |