Mercurial > public > hwos_code
comparison src/compass_ops.asm @ 634:4050675965ea
3.10 stable release
author | heinrichsweikamp |
---|---|
date | Tue, 28 Apr 2020 17:34:31 +0200 |
parents | 185ba2f91f59 |
children | 7d8a4c60ec1a 5b7fe7777425 |
comparison
equal
deleted
inserted
replaced
633:690c48db7b5b | 634:4050675965ea |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File compass_ops.asm combined next generation V3.08.8 | 3 ; File compass_ops.asm combined next generation V3.09.5 |
4 ; | 4 ; |
5 ; Compass Operations | 5 ; Compass Operations |
6 ; | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. |
8 ;============================================================================= | 8 ;============================================================================= |
9 | 9 |
10 #include "hwos.inc" | 10 #include "hwos.inc" |
11 #include "i2c.inc" | 11 #include "i2c.inc" |
12 #include "tft_outputs.inc" | 12 #include "tft_outputs.inc" |
13 #include "tft.inc" | 13 #include "tft.inc" |
14 #include "strings.inc" | 14 #include "strings.inc" |
15 #include "wait.inc" | 15 #include "wait.inc" |
16 #include "surfmode.inc" | 16 #include "surfmode.inc" |
17 #include "divemode.inc" | 17 #include "divemode.inc" |
18 #include "math.inc" | 18 #include "math.inc" |
19 #include "convert.inc" | 19 #include "convert.inc" |
20 #include "start.inc" | 20 #include "start.inc" |
21 #include "colorschemes.inc" | |
21 | 22 |
22 | 23 |
23 IFDEF _compass | 24 IFDEF _compass |
24 | 25 |
25 | 26 |
65 extern compass_solve_calibration | 66 extern compass_solve_calibration |
66 | 67 |
67 extern option_check_and_store_all | 68 extern option_check_and_store_all |
68 | 69 |
69 | 70 |
70 compass_ops code | |
71 | |
72 ;============================================================================= | 71 ;============================================================================= |
72 compass_ops1 CODE | |
73 ;============================================================================= | |
74 | |
73 | 75 |
74 ;----------------------------------------------------------------------------- | 76 ;----------------------------------------------------------------------------- |
75 ; Filter compass values | 77 ; Filter compass values |
76 ; | 78 ; |
77 ; Apply linear filtering to input parameters. | 79 ; Apply linear filtering to input parameters. |
114 FILTER16 accel_DY, accel_DY_f | 116 FILTER16 accel_DY, accel_DY_f |
115 FILTER16 accel_DZ, accel_DZ_f | 117 FILTER16 accel_DZ, accel_DZ_f |
116 banksel common ; back to bank common | 118 banksel common ; back to bank common |
117 return | 119 return |
118 | 120 |
119 ;----------------------------------------------------------------------------- | 121 |
120 | 122 ;============================================================================= |
121 compass_filter_init: | 123 compass_ops2 CODE |
122 MOVII compass_DX,compass_DX_f | 124 ;============================================================================= |
123 MOVII compass_DY,compass_DY_f | |
124 MOVII compass_DZ,compass_DZ_f | |
125 | |
126 MOVII accel_DX,accel_DX_f | |
127 MOVII accel_DY,accel_DY_f | |
128 MOVII accel_DZ,accel_DZ_f | |
129 return | |
130 | 125 |
131 ;----------------------------------------------------------------------------- | 126 ;----------------------------------------------------------------------------- |
132 ; Q15 fractional numbers: a * b / 2**16 (UNSIGNED) | 127 ; Q15 fractional numbers: a * b / 2**16 (UNSIGNED) |
133 ; | 128 ; |
134 ; Uses 16x16->16 multiply, for positive integers, keeping only the most | 129 ; Uses 16x16->16 multiply, for positive integers, keeping only the most |
213 bcf compass_r+1,6 ; copy bit 7 to 6, so keep it after 2x | 208 bcf compass_r+1,6 ; copy bit 7 to 6, so keep it after 2x |
214 btfsc compass_r+1,7 | 209 btfsc compass_r+1,7 |
215 bsf compass_r+1,6 | 210 bsf compass_r+1,6 |
216 bra compass_mul_2 | 211 bra compass_mul_2 |
217 | 212 |
218 ;----------------------------------------------------------------------------- | 213 |
219 | 214 ;============================================================================= |
220 global compass_calibration_loop | 215 compass_ops3 CODE |
221 compass_calibration_loop: ; compass calibration | 216 ;============================================================================= |
217 | |
218 global compass_calibration | |
219 compass_calibration: ; compass calibration | |
222 bsf block_sensor_interrupt ; disable sensor interrupts | 220 bsf block_sensor_interrupt ; disable sensor interrupts |
223 call I2C_sleep_compass ; stop compass | 221 call I2C_sleep_compass ; stop compass |
224 call TFT_ClearScreen | 222 call TFT_ClearScreen ; clear the screen |
225 ; Mask | 223 ; Mask |
226 WIN_COLOR color_greenish | 224 WIN_STD .16,.0 ; set position |
227 WIN_SMALL .16,.0 | 225 FONT_COLOR color_greenish ; set font color |
228 STRCPY_TEXT_PRINT tCompassMenu | 226 STRCPY_TEXT_PRINT tCompassCalibration |
229 btfss switch_right2 ; wait until button is released | 227 btfss switch_right2 ; wait until button (with a moving magnet in some OSTC!) is released |
230 bra $-2 | 228 bra $-2 |
231 | 229 |
232 call TFT_standard_color | |
233 ; WIN_SMALL .0,.215 | 230 ; WIN_SMALL .0,.215 |
231 ; FONT_COLOR color_standard | |
234 ; STRCPY_TEXT_PRINT tExit | 232 ; STRCPY_TEXT_PRINT tExit |
235 WAITMS d'255' | 233 WAITMS d'255' |
236 WAITMS d'255' | 234 WAITMS d'255' |
237 | 235 |
238 call request_speed_fastest ; request CPU speed change to fastest speed | 236 call request_speed_fastest ; request CPU speed change to fastest speed |
239 | 237 |
240 movlw .7 ; initialize gain | 238 movlw .7 ; initialize gain |
241 movff WREG,opt_compass_gain | 239 movff WREG,opt_compass_gain ; ... |
242 | 240 |
243 movlw .60 ; initialize timeout to 60 seconds | 241 movlw .60 ; initialize timeout to 60 seconds |
244 movwf isr_timeout_reload ; copy WREG to isr_timeout_reload | 242 movwf isr_timeout_reload ; copy WREG to isr_timeout_reload |
245 bsf reset_timeout ; request ISR to reset the timeout | 243 bsf restart_timeout ; request ISR to restart the timeout |
246 bcf trigger_timeout ; clear any pending timeout trigger | 244 bcf trigger_timeout ; clear any pending timeout trigger |
247 compass_calibration_gainset: ; reduce the gain, set bank here! | 245 compass_calibration_gainset: ; reduce the gain, set bank here! |
248 banksel opt_compass_gain ; select bank options table | 246 banksel opt_compass_gain ; select bank options table |
249 decf opt_compass_gain,F ; reduce by one | 247 decf opt_compass_gain,F ; reduce by one |
250 btfsc STATUS,N ; < 0 ? | 248 btfsc STATUS,N ; < 0 ? |
251 clrf opt_compass_gain ; YES - keep at zero | 249 clrf opt_compass_gain ; YES - keep at zero |
252 btfsc STATUS,N ; < 0 ? | 250 btfsc STATUS,N ; < 0 ? |
253 bra compass_calibration_loop1 ; YES - skip gain stuff (Would hang here in case of compass failure) | 251 bra compass_calibration_loop1 ; YES - skip gain stuff (Would hang here in case of compass failure) |
254 banksel common ; bank to bank common | 252 banksel common ; bank to bank common |
255 | 253 |
256 call I2C_init_compass | 254 call I2C_init_compass ; initialize compass chip |
257 | 255 |
258 btfsc compass_type3 ; compass type 3 ? | 256 btfsc compass_type3 ; compass type 3 ? |
259 bra compass_calibration_loop1 ; YES - skip gain stuff | 257 bra compass_calibration_loop1 ; YES - skip gain stuff |
260 btfsc compass_type2 ; compass type 2 ? | 258 btfsc compass_type2 ; compass type 2 ? |
261 bra compass_calibration_loop1 ; YES - skip gain stuff | 259 bra compass_calibration_loop1 ; YES - skip gain stuff |
264 | 262 |
265 WAITMS d'250' | 263 WAITMS d'250' |
266 WAITMS d'250' ; wait for first reading... | 264 WAITMS d'250' ; wait for first reading... |
267 | 265 |
268 movlw .60 ; calibration shall run for 60 seconds | 266 movlw .60 ; calibration shall run for 60 seconds |
269 call reset_timeout_time ; set timeout | 267 call restart_timeout_time ; restart the timeout |
270 | 268 |
271 call I2C_RX_compass ; read compass | 269 call I2C_RX_compass ; read compass |
272 call I2C_RX_accelerometer ; read accelerometer | 270 call I2C_RX_accelerometer ; read accelerometer |
273 | 271 |
274 ; Test all axes for +4096 (Hi byte=16) | 272 ; Test all axes for +4096 (Hi byte=16) |
303 banksel common ; back to bank common | 301 banksel common ; back to bank common |
304 | 302 |
305 compass_calibration_loop2: | 303 compass_calibration_loop2: |
306 call I2C_RX_compass ; read compass | 304 call I2C_RX_compass ; read compass |
307 call I2C_RX_accelerometer ; test accelerometer | 305 call I2C_RX_accelerometer ; test accelerometer |
308 rcall compass_filter ; filter compass raw data | 306 call compass_filter ; filter compass raw data |
309 | 307 |
310 ; Twice | 308 ; Twice |
311 call I2C_RX_compass ; read compass | 309 call I2C_RX_compass ; read compass |
312 call I2C_RX_accelerometer ; test accelerometer | 310 call I2C_RX_accelerometer ; test accelerometer |
313 rcall compass_filter ; filter compass raw data | 311 call compass_filter ; filter compass raw data |
314 | 312 |
315 ; btfsc compass_type1 ; compass1? | 313 ; btfsc compass_type1 ; compass1? |
316 ; bra compass_calibration_loop3 ; YES - skip gain stuff | 314 ; bra compass_calibration_loop3 ; YES - skip gain stuff |
317 | 315 |
318 ; Test all axes for +4096 (Hi byte=16) | 316 ; Test all axes for +4096 (Hi byte=16) |
338 bra compass_calibration_gainset | 336 bra compass_calibration_gainset |
339 cpfseq compass_DZ+1 | 337 cpfseq compass_DZ+1 |
340 bra $+4 | 338 bra $+4 |
341 bra compass_calibration_gainset | 339 bra compass_calibration_gainset |
342 banksel common ; back to bank common | 340 banksel common ; back to bank common |
343 ; | 341 |
344 ; ; Three | 342 ; ; Three |
345 ; call I2C_RX_compass ; read compass | 343 ; call I2C_RX_compass ; read compass |
346 ; call I2C_RX_accelerometer ; test accelerometer | 344 ; call I2C_RX_accelerometer ; test accelerometer |
347 ; call compass_filter ; filter compass raw data | 345 ; call compass_filter ; filter compass raw data |
348 ; | 346 ; |
371 call compass_solve_calibration ; calculate calibration factors (C-code) | 369 call compass_solve_calibration ; calculate calibration factors (C-code) |
372 banksel common ; back to bank common | 370 banksel common ; back to bank common |
373 | 371 |
374 call request_speed_normal ; request CPU speed change to normal speed | 372 call request_speed_normal ; request CPU speed change to normal speed |
375 | 373 |
376 bsf options_changed ; flag that option values have changed | 374 bsf option_changed ; flag that option values have changed |
377 bsf restart_fast ; request to skip logos and waits on restart | 375 bsf restart_fast ; request to skip logos and waits on restart |
378 | 376 |
379 movlw .6 ; coding for surface compass view | 377 movlw .6 ; coding for surface compass view |
380 movff WREG,customview_surfmode ; set to compass view to show | 378 movff WREG,customview_surfmode ; set to compass view to show |
381 | 379 |
382 goto restart ; done | 380 goto restart ; done |
383 | 381 |
382 | |
384 ;----------------------------------------------------------------------------- | 383 ;----------------------------------------------------------------------------- |
385 | 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 | |
390 | |
391 MOVII accel_DX,accel_DX_f | |
392 MOVII accel_DY,accel_DY_f | |
393 MOVII accel_DZ,accel_DZ_f | |
394 return | |
395 | |
396 ;----------------------------------------------------------------------------- | |
397 ; Show Calibration Progress | |
398 ; | |
386 TFT_compass_fast: | 399 TFT_compass_fast: |
387 WIN_TINY .0,.50 | 400 WIN_TINY .0,.50 ; set font and position |
388 STRCPY "Cx:" | 401 FONT_COLOR_MEMO ; set font color |
389 MOVII compass_DX,mpr | 402 |
390 call TFT_convert_signed_16bit ; convert lo:hi into signed-short and add '-' to POSTINC2 if required | 403 STRCPY "Cx:" ; print label |
391 output_16 | 404 MOVII compass_DX,mpr ; get value |
392 STRCAT " Cy:" | 405 rcall TFT_compass_fast_helper ; print value |
393 MOVII compass_DY,mpr | 406 |
394 call TFT_convert_signed_16bit ; convert lo:hi into signed-short and add '-' to POSTINC2 if required | 407 STRCAT " Cy:" ; print label |
395 output_16 | 408 MOVII compass_DY,mpr ; get value |
396 STRCAT " Cz:" | 409 rcall TFT_compass_fast_helper ; print value |
397 MOVII compass_DZ,mpr | 410 |
398 call TFT_convert_signed_16bit ; convert lo:hi into signed-short and add '-' to POSTINC2 if required | 411 STRCAT " Cz:" ; print label |
399 output_16 | 412 MOVII compass_DZ,mpr ; get value |
400 STRCAT_PRINT " " | 413 rcall TFT_compass_fast_helper ; print value |
401 | 414 |
402 WIN_TINY .0,.104 | 415 PRINT ; dump to screen |
403 STRCPY "Ax:" | 416 |
404 MOVII accel_DX,mpr | 417 WIN_TINY .0,.104 ; set font and position |
405 call TFT_convert_signed_16bit ; convert lo:hi into signed-short and add '-' to POSTINC2 if required | 418 FONT_COLOR_MEMO ; set font color |
406 output_16 | 419 |
407 STRCAT " Ay:" | 420 STRCPY "Ax:" ; print label |
408 MOVII accel_DY,mpr | 421 MOVII accel_DX,mpr ; get value |
409 call TFT_convert_signed_16bit ; convert lo:hi into signed-short and add '-' to POSTINC2 if required | 422 rcall TFT_compass_fast_helper ; print value |
410 output_16 | 423 |
411 STRCAT " Az:" | 424 STRCAT " Ay:" ; print label |
412 MOVII accel_DZ,mpr | 425 MOVII accel_DY,mpr ; get value |
413 call TFT_convert_signed_16bit ; convert lo:hi into signed-short and add '-' to POSTINC2 if required | 426 rcall TFT_compass_fast_helper ; print value |
414 output_16 | 427 |
415 STRCAT_PRINT " " | 428 STRCAT " Az:" ; print label |
416 return | 429 MOVII accel_DZ,mpr ; get value |
417 | 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) | |
443 return | |
444 | |
445 | |
446 | |
447 ;----------------------------------------------------------------------------- | |
448 ; Show remaining Calibration Time | |
449 ; | |
418 TFT_show_timeout_testmode: | 450 TFT_show_timeout_testmode: |
419 WIN_TINY .0,.68 | 451 WIN_TINY .0,.68 ; set font and position |
420 STRCPY "T:" | 452 FONT_COLOR_MEMO ; set font color |
421 movff isr_timeout_timer,lo | 453 STRCPY "T:" ; print label |
422 bsf leftbind | 454 movff isr_timeout_timer,lo ; get remaining time |
423 output_8 ; display remaining time | 455 output_256 ; print remaining time (xxx) |
424 bcf leftbind | 456 PUTC_PRINT "s" ; append unit and dump to screen |
425 STRCAT_PRINT "s " | 457 return ; done |
426 return | 458 |
427 | 459 |
460 ;----------------------------------------------------------------------------- | |
461 ; Show current Compass Gain | |
462 ; | |
428 TFT_compass_show_gain: ; show the current compass gain | 463 TFT_compass_show_gain: ; show the current compass gain |
429 ; movff opt_compass_gain,lo ; 0-7 (230 LSB/Gauss to 1370 LSB/Gauss) | 464 ; movff opt_compass_gain,lo ; 0-7 (230 LSB/Gauss to 1370 LSB/Gauss) |
430 ; tstfsz lo | 465 ; tstfsz lo |
431 ; return ; do not show unless gain=0 | 466 ; return ; do not show unless gain > 0 |
432 WIN_TINY .0,.86 | 467 WIN_TINY .0,.86 ; set font and position |
433 STRCPY_TEXT tCompassGain | 468 FONT_COLOR_MEMO ; set font color |
434 movff opt_compass_gain,lo ; 0-7 (230 LSB/Gauss to 1370 LSB/Gauss) | 469 STRCPY_TEXT tCompassGain ; print label |
435 bsf leftbind | 470 movff opt_compass_gain,lo ; get value: 0-7 (230 LSB/Gauss to 1370 LSB/Gauss) |
436 output_8 | 471 output_99 ; print value (xx) |
437 bcf leftbind | 472 PRINT ; dump to screen |
438 STRCAT_PRINT "" | 473 return ; done |
439 return | 474 |
475 | |
476 ;============================================================================= | |
477 compass_ops4 CODE | |
478 ;============================================================================= | |
440 | 479 |
441 ;----------------------------------------------------------------------------- | 480 ;----------------------------------------------------------------------------- |
442 | 481 ; Mask for Compass in Surface Mode |
482 ; | |
443 global TFT_surface_compass_mask | 483 global TFT_surface_compass_mask |
444 TFT_surface_compass_mask: | 484 TFT_surface_compass_mask: |
445 WIN_SMALL surf_compass_mask_column,surf_compass_mask_row | 485 WIN_SMALL surf_compass_mask_column,surf_compass_mask_row |
446 call TFT_standard_color | 486 FONT_COLOR_MEMO ; set font color |
447 STRCPY_TEXT_PRINT tHeading ; print "Heading:" | 487 STRCPY_TEXT_PRINT tHeading ; print "Heading:" |
448 return | 488 return ; done |
449 | 489 |
450 | 490 |
451 global TFT_dive_compass_mask ; draws the white box around the heading tape | 491 ;----------------------------------------------------------------------------- |
452 TFT_dive_compass_mask: | 492 ; Compass Display in Surface Mode |
453 WIN_FRAME_STD dm_custom_compass_graph_row, dm_custom_compass_graph_row+dm_custom_compass_graph_height, .0, .159 | 493 ; |
454 return | |
455 | |
456 | |
457 global TFT_surface_compass_heading | 494 global TFT_surface_compass_heading |
458 TFT_surface_compass_heading: | 495 TFT_surface_compass_heading: |
459 rcall compass_heading_common | 496 call compass_heading_common ; compute heading |
460 WIN_STD surf_compass_head_column,surf_compass_head_row | 497 WIN_STD surf_compass_head_column,surf_compass_head_row |
461 call TFT_standard_color | 498 |
462 TFT_surface_compass_heading_com: ; show "000° N" | 499 TFT_surface_compass_heading_com: ; show "000° N" |
500 FONT_COLOR_MEMO ; set default / dive-mode standard color | |
463 movff compass_heading_new+1,WREG ; get upper byte of actual heading | 501 movff compass_heading_new+1,WREG ; get upper byte of actual heading |
464 btfsc WREG,7 ; compass calibrated? | 502 btfsc WREG,7 ; compass calibrated? |
465 bra TFT_compass_uncalibrated ; NO | 503 bra TFT_compass_uncalibrated ; NO |
466 MOVII compass_heading_shown,mpr ; get heading to be shown | 504 MOVII compass_heading_shown,mpr ; get heading to be shown |
467 rcall TFT_compass_helper ; show heading and its cardinal | 505 rcall TFT_compass_helper ; show heading and its cardinal |
472 return ; NO - done | 510 return ; NO - done |
473 btfsc compass_menu ; is the "set bearing" selection shown? | 511 btfsc compass_menu ; is the "set bearing" selection shown? |
474 return ; YES - done | 512 return ; YES - done |
475 ; show bearing | 513 ; show bearing |
476 WIN_SMALL surf_compass_bear_column,surf_compass_bear_row | 514 WIN_SMALL surf_compass_bear_column,surf_compass_bear_row |
477 call TFT_attention_color | 515 FONT_COLOR color_yellow ; set font color |
478 MOVII compass_bearing,mpr ; get bearing | 516 MOVII compass_bearing,mpr ; get bearing |
479 ;bra TFT_compass_helper ; show number and cardinal and return | 517 ;bra TFT_compass_helper ; show number and cardinal and return |
480 | 518 |
481 TFT_compass_helper: | 519 TFT_compass_helper: |
482 bsf leftbind | 520 output_999 ; print bearing |
483 output_16dp .2 ; result is "0.000" in buffer | 521 STRCAT "° " ; append unit and a space |
484 bcf leftbind | 522 call tft_compass_cardinal ; append cardinal buffer |
485 ; rearrange figures to "000" | 523 PRINT ; dump to screen |
486 movff buffer+2,buffer+0 | |
487 movff buffer+3,buffer+1 | |
488 movff buffer+4,buffer+2 | |
489 lfsr FSR2,buffer+3 | |
490 STRCAT "° " | |
491 rcall tft_compass_cardinal ; add cardinal to POSTINC2 | |
492 STRCAT_PRINT "" ; finalize output | |
493 return ; done | 524 return ; done |
494 | 525 |
495 TFT_compass_uncalibrated: | 526 TFT_compass_uncalibrated: |
496 STRCAT_PRINT "---°" ; print "---°" | 527 STRCAT_PRINT "---°" ; print "---°" |
497 return ; done | 528 return ; done |
498 | 529 |
499 | 530 |
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 ; | |
500 global TFT_dive_compass_heading | 548 global TFT_dive_compass_heading |
501 TFT_dive_compass_heading: | 549 TFT_dive_compass_heading: |
502 rcall compass_heading_common | 550 call compass_heading_common ; compute heading |
503 WIN_FONT FT_SMALL ; set font size | |
504 | 551 |
505 ; ; ### for development only, hard-coding the bearing ### | 552 ; ; ### for development only, hard-coding the bearing ### |
506 ; ; 244° : SW - W | 553 ; ; 244° : SW - W |
507 ; MOVLI .244,xA ; xA used as temp | 554 ; MOVLI .244,xA ; xA used as temp |
508 ; MOVII xA,compass_bearing ; compass_bearing is stored in bank isr_backup | 555 ; MOVII xA,compass_bearing ; compass_bearing is stored in bank isr_backup |
509 | 556 |
510 MOVII compass_heading_shown,xA | 557 FONT_SIZE FT_SMALL ; set font size |
558 MOVII compass_heading_shown,xA ; get heading | |
511 ; 160° viewing angle: add +360 offset if xA <= 292 for non-negative scale | 559 ; 160° viewing angle: add +360 offset if xA <= 292 for non-negative scale |
512 MOVLI .292,sub_a | 560 MOVLI .292,sub_a |
513 MOVII xA, sub_b | 561 MOVII xA, sub_b |
514 call subU16 ; sub_c = sub_a - sub_b | 562 call subU16 ; sub_c = sub_a - sub_b |
515 btfsc neg_flag ; xA > 292 ? | 563 btfsc neg_flag ; xA > 292 ? |
732 movff lo,win_leftx2 ; 0..159 | 780 movff lo,win_leftx2 ; 0..159 |
733 movlw dm_custom_compass_tick_top_top | 781 movlw dm_custom_compass_tick_top_top |
734 movwf win_top ; set position for upper ticks | 782 movwf win_top ; set position for upper ticks |
735 movlw dm_custom_compass_tick_height | 783 movlw dm_custom_compass_tick_height |
736 movwf win_height ; set hight of ticks | 784 movwf win_height ; set hight of ticks |
737 call TFT_standard_color ; set color | 785 movf pallet_color_memo,W ; select color |
738 call TFT_box ; draw tick | 786 BOX_COLOR ; draw tick |
739 movlw dm_custom_compass_tick_bot_top | 787 movlw dm_custom_compass_tick_bot_top |
740 movwf win_top ; set position for lower ticks | 788 movwf win_top ; set position for lower ticks |
741 movlw dm_custom_compass_tick_height | 789 movlw dm_custom_compass_tick_height |
742 movwf win_height ; set hight of ticks | 790 movwf win_height ; set hight of ticks |
743 call TFT_standard_color ; color in WREG is trashed, must be set again! | 791 movf pallet_color_memo,W ; select color |
744 call TFT_box ; draw tick | 792 BOX_COLOR ; draw tick |
745 ; 4. If D < 82 and RM > 79: means we put something over the center line, | 793 ; 4. If D < 82 and RM > 79: means we put something over the center line, |
746 ; so redraw the center line | 794 ; so redraw the center line |
747 movlw d'82' | 795 movlw d'82' |
748 cpfslt hi,1 | 796 cpfslt hi,1 |
749 bra TFT_dive_compass_ruler_loop_zz2 | 797 bra TFT_dive_compass_ruler_loop_zz2 |
774 ; 10. clear it | 822 ; 10. clear it |
775 rcall TFT_dive_compass_clr_ruler | 823 rcall TFT_dive_compass_clr_ruler |
776 | 824 |
777 TFT_dive_compass_labels: | 825 TFT_dive_compass_labels: |
778 ; done with the compass ruler, put the labels on the screen | 826 ; done with the compass ruler, put the labels on the screen |
827 FONT_COLOR_MEMO ; set dive-mode standard color | |
779 clrf hi ; hi stores the display position | 828 clrf hi ; hi stores the display position |
780 movff hi,xHI ; bank-safe clear of xHI | 829 movff hi,xHI ; bank-safe clear of xHI |
781 clrf lo ; lo stores the last item's display position | 830 clrf lo ; lo stores the last item's display position |
782 movff lo,xLO ; bank-safe clear of xLO | 831 movff lo,xLO ; bank-safe clear of xLO |
783 MOVLI .219,sub_a ; position of the cardinal | 832 MOVLI .219,sub_a ; position of the cardinal |
896 rcall TFT_dive_compass_dir_lclr ; bearing == heading - no need for direction markers | 945 rcall TFT_dive_compass_dir_lclr ; bearing == heading - no need for direction markers |
897 rcall TFT_dive_compass_dir_rclr | 946 rcall TFT_dive_compass_dir_rclr |
898 bra TFT_dive_compass_text | 947 bra TFT_dive_compass_text |
899 | 948 |
900 TFT_dive_compass_dir_text_2: | 949 TFT_dive_compass_dir_text_2: |
901 movlw color_green | 950 FONT_COLOR color_green |
902 call TFT_set_color | |
903 btfsc compass_bearing_lft | 951 btfsc compass_bearing_lft |
904 bra TFT_dive_compass_dir_ldir ; bearing_lft=1, print the left marker | 952 bra TFT_dive_compass_dir_ldir ; bearing_lft=1, print the left marker |
905 ;TFT_dive_compass_text_rdir: | 953 ;TFT_dive_compass_text_rdir: |
906 WIN_SMALL dm_custom_compass_rdir_column, dm_custom_compass_head_row-.2 | 954 WIN_SMALL dm_custom_compass_rdir_column, dm_custom_compass_head_row-.2 |
907 STRCPY_PRINT ">>" | 955 STRCPY_PRINT ">>" |
917 TFT_dive_compass_text: | 965 TFT_dive_compass_text: |
918 ; Clear some unused space on the right mH | 966 ; Clear some unused space on the right mH |
919 WIN_BOX_BLACK dm_custom_compass_tick_top_bot+.1,dm_custom_compass_tick_bot_top-.1,.158,.159 ; top, bottom, left, right | 967 WIN_BOX_BLACK dm_custom_compass_tick_top_bot+.1,dm_custom_compass_tick_bot_top-.1,.158,.159 ; top, bottom, left, right |
920 | 968 |
921 ; Text output | 969 ; Text output |
922 call TFT_standard_color | |
923 WIN_SMALL dm_custom_compass_head_column, dm_custom_compass_head_row | 970 WIN_SMALL dm_custom_compass_head_column, dm_custom_compass_head_row |
924 rcall TFT_surface_compass_heading_com ; show "xxx° N" | 971 call TFT_surface_compass_heading_com ; show "xxx° N" |
925 return | 972 return |
926 | 973 |
927 TFT_dive_compass_dir_lclr: | 974 TFT_dive_compass_dir_lclr: |
928 WIN_SMALL dm_custom_compass_ldir_column, dm_custom_compass_head_row-.2 | 975 WIN_SMALL dm_custom_compass_ldir_column, dm_custom_compass_head_row-.2 |
929 STRCPY_PRINT " " | 976 STRCPY_PRINT " " |
969 cpfsgt lo | 1016 cpfsgt lo |
970 bra TFT_dive_compass_label_proc_p | 1017 bra TFT_dive_compass_label_proc_p |
971 rcall TFT_dive_compass_clr_label | 1018 rcall TFT_dive_compass_clr_label |
972 TFT_dive_compass_label_proc_p: | 1019 TFT_dive_compass_label_proc_p: |
973 ; 4. print the SQ on the screen | 1020 ; 4. print the SQ on the screen |
974 call TFT_standard_color | 1021 FONT_COLOR_MEMO |
975 bsf compass_show_cardinal | 1022 bsf compass_show_cardinal |
976 ;TFT_dive_compass_label_print: | 1023 ;TFT_dive_compass_label_print: |
977 movlw dm_custom_compass_label_row | 1024 movlw dm_custom_compass_label_row ; set output position |
978 movff WREG,win_top | 1025 movff WREG,win_top ; ... |
979 movff lo,win_leftx2 | 1026 movff lo,win_leftx2 ; ... |
980 WIN_FONT FT_SMALL | 1027 FONT_SIZE FT_SMALL ; set font size |
981 ; 6. retain the new display positions | 1028 ; 6. retain the new display positions |
982 movff lo,hi | 1029 movff lo,hi |
983 movff up,WREG | 1030 movff up,WREG |
984 addwf hi,F | 1031 addwf hi,F |
985 movff lo,xLO | 1032 movff lo,xLO |
1077 movwf win_bargraph | 1124 movwf win_bargraph |
1078 movwf win_width+0 | 1125 movwf win_width+0 |
1079 clrf win_width+1 | 1126 clrf win_width+1 |
1080 movlw color_green | 1127 movlw color_green |
1081 btfss compass_show_cardinal | 1128 btfss compass_show_cardinal |
1082 movlw color_red | 1129 movlw color_red ; select color |
1083 call TFT_set_color | 1130 BOX_COLOR ; draw box |
1084 call TFT_box | |
1085 TFT_dive_compass_mk_print_5: | 1131 TFT_dive_compass_mk_print_5: |
1086 return | 1132 return |
1087 | 1133 |
1088 TFT_dive_compass_clr_label: | 1134 TFT_dive_compass_clr_label: |
1089 movlw dm_custom_compass_label_row-.2 ; set top & height | 1135 movlw dm_custom_compass_label_row-.2 ; set top & height |
1118 clrf win_width+1 | 1164 clrf win_width+1 |
1119 movlw .1 | 1165 movlw .1 |
1120 cpfsgt win_width+0 | 1166 cpfsgt win_width+0 |
1121 bra TFT_dive_compass_clear3 ; do not clear a single pixel (or less) | 1167 bra TFT_dive_compass_clear3 ; do not clear a single pixel (or less) |
1122 movff hi,win_leftx2 | 1168 movff hi,win_leftx2 |
1123 movlw color_black | 1169 movlw color_black ; select color |
1124 call TFT_set_color | 1170 BOX_COLOR ; draw box |
1125 call TFT_box | |
1126 TFT_dive_compass_clear3: | 1171 TFT_dive_compass_clear3: |
1127 return | 1172 return |
1128 | 1173 |
1129 tft_compass_cardinal: | 1174 tft_compass_cardinal: |
1130 btfsc hi,0 ; heading > 255° ? | 1175 btfsc hi,0 ; heading > 255° ? |
1190 return | 1235 return |
1191 tft_compass_cardinal_NW: | 1236 tft_compass_cardinal_NW: |
1192 STRCAT_TEXT tNW | 1237 STRCAT_TEXT tNW |
1193 return | 1238 return |
1194 | 1239 |
1240 ;============================================================================= | |
1241 compass_ops6 CODE | |
1242 ;============================================================================= | |
1243 | |
1195 ;----------------------------------------------------------------------------- | 1244 ;----------------------------------------------------------------------------- |
1196 | 1245 ; get and process heading |
1246 ; | |
1197 compass_heading_common: | 1247 compass_heading_common: |
1198 btfss compass_enabled ; compass enabled? | 1248 btfss compass_enabled ; compass enabled? |
1199 bra compass_heading_common_zero ; NO | 1249 bra compass_heading_common_zero ; NO |
1200 | 1250 |
1201 ; Get an averaged new heading | 1251 ; Get an averaged new heading |
1253 MOVLI .360, sub_a ; YES - wrap around 360° | 1303 MOVLI .360, sub_a ; YES - wrap around 360° |
1254 MOVII sub_c,sub_b ; - transfer decrement result to sub_b | 1304 MOVII sub_c,sub_b ; - transfer decrement result to sub_b |
1255 call subU16 ; - wrap decrement result around | 1305 call subU16 ; - wrap decrement result around |
1256 bra compass_heading_common_6 ; - store wrapped result | 1306 bra compass_heading_common_6 ; - store wrapped result |
1257 | 1307 |
1258 | |
1259 compass_heading_common_5: | 1308 compass_heading_common_5: |
1260 ; increment compass_heading_shown towards compass_heading_new | 1309 ; increment compass_heading_shown towards compass_heading_new |
1261 rcall compass_heading_stepsize_1 ; calculate step size and put it into sub_b | 1310 rcall compass_heading_stepsize_1 ; calculate step size and put it into sub_b |
1262 MOVII compass_heading_shown,sub_a ; transfer unturned shown heading to sub_a | 1311 MOVII compass_heading_shown,sub_a ; transfer unturned shown heading to sub_a |
1263 call addU16 ; increment heading: sub_c = compass_heading_shown + step size | 1312 call addU16 ; increment heading: sub_c = compass_heading_shown + step size |
1290 rrcf sub_c+0 ; heading difference /= 2, total /= 4 now | 1339 rrcf sub_c+0 ; heading difference /= 2, total /= 4 now |
1291 incf sub_c+0,f ; final += 1 to have one increment / decrement at least | 1340 incf sub_c+0,f ; final += 1 to have one increment / decrement at least |
1292 MOVII sub_c,sub_b ; transfer result to sub_b | 1341 MOVII sub_c,sub_b ; transfer result to sub_b |
1293 return | 1342 return |
1294 | 1343 |
1295 | |
1296 ENDIF ; _compass | 1344 ENDIF ; _compass |
1297 | 1345 |
1346 ;----------------------------------------------------------------------------- | |
1347 | |
1298 END | 1348 END |