annotate src/compass_ops.asm @ 656:8af5aefbcdaf default tip

Update to 3.31 beta
author heinrichsweikamp
date Thu, 27 Nov 2025 18:32:58 +0100
parents 75e90cd0c2c3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
1 ;=============================================================================
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
2 ;
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
3 ; File compass_ops.asm combined next generation V3.09.5
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
4 ;
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
5 ; Compass Operations
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
6 ;
654
75e90cd0c2c3 hwOS sport 10.77 release
heinrichsweikamp
parents: 650
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, heinrichs weikamp gmbh, all right reserved.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
8 ;=============================================================================
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
9
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
10 #include "hwos.inc"
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
11 #include "i2c.inc"
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
12 #include "tft_outputs.inc"
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
13 #include "tft.inc"
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
14 #include "strings.inc"
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
15 #include "wait.inc"
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
16 #include "surfmode.inc"
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
17 #include "divemode.inc"
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
18 #include "math.inc"
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
19 #include "convert.inc"
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
20 #include "start.inc"
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
21 #include "colorschemes.inc"
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
22
0
heinrichsweikamp
parents:
diff changeset
23
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
24 IFDEF _compass
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
25
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
26
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
27 ; local flags
656
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
28 ;#DEFINE compass_show_cardinal compass_flags,0 ; =1: show the cardinal (N, NE, E, ...)
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
29 ;#DEFINE compass_bearing_eq compass_flags,1 ; =1: bearing is in direction, do not show << or >>
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
30 ;#DEFINE compass_bearing_lft compass_flags,2 ; =1: bearing is to the left/<<, =0: to the right/>>
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
31 ;#DEFINE compass_bearing_vis compass_flags,3 ; =1: bearing is visible (either ahead or behind/-180°)
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
32 ;#DEFINE compass_bearing_ahd compass_flags,4 ; =1: bearing is ahead, =0: behind
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
33 ;; compass_flags,5 ; --- unused
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
34 ;; compass_flags,6 ; --- unused
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
35 ;; compass_flags,7 ; --- unused
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
36
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
37
0
heinrichsweikamp
parents:
diff changeset
38 ; Make sure symbols from the .inc are available to the C code:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
39
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
40 ; filtered data - Compass
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
41 global compass_DX_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
42 global compass_DY_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
43 global compass_DZ_f
0
heinrichsweikamp
parents:
diff changeset
44
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
45 ; filtered Data - Accelerometer
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
46 global accel_DX_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
47 global accel_DY_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
48 global accel_DZ_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
49
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
50 ; Calibration Data
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
51 global compass_CX_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
52 global compass_CY_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
53 global compass_CZ_f
0
heinrichsweikamp
parents:
diff changeset
54
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
55 ; Temporary Values to pass Q15 Arithmetics around
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
56 global compass_a
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
57 global compass_b
0
heinrichsweikamp
parents:
diff changeset
58
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
59 ; Result
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
60 global compass_heading_new
0
heinrichsweikamp
parents:
diff changeset
61
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
62
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
63 extern compass
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
64 extern compass_reset_calibration
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
65 extern compass_add_calibration
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
66 extern compass_solve_calibration
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
67
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
68 extern option_check_and_store_all
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
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
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
71 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
72 compass_ops1 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
73 ;=============================================================================
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
74
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
75
0
heinrichsweikamp
parents:
diff changeset
76 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
77 ; Filter compass values
heinrichsweikamp
parents:
diff changeset
78 ;
heinrichsweikamp
parents:
diff changeset
79 ; Apply linear filtering to input parameters.
heinrichsweikamp
parents:
diff changeset
80
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
81 ; Apply filtering formula: reg_f += (reg - reg_f) / 4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
82 FILTER16 MACRO reg, reg_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
83 movf reg_f+0,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
84 subwf reg+0,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
85 movwf PRODL
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
86 movf reg_f+1,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
87 subwfb reg+1,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
88 rcall filter_16_common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
89 addwf reg_f+0,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
90 movf PRODH,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
91 addwfc reg_f+1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
92 ENDM
148
022b886eddaf some cleanup
heinrichsweikamp
parents: 147
diff changeset
93
022b886eddaf some cleanup
heinrichsweikamp
parents: 147
diff changeset
94 filter_16_common:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
95 movwf PRODH
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
96 bcf STATUS,C ; copy sign bit into carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
97 btfsc PRODH,7
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
98 bsf STATUS,C
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
99 rrcf PRODH,F ; 16 bit shift right
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
100 rrcf PRODL,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
101 bcf STATUS,C ; copy sign bit into carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
102 btfsc PRODH,7
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
103 bsf STATUS,C
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
104 rrcf PRODH,F ; 16 bit shift right
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
105 rrcf PRODL,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
106 return
0
heinrichsweikamp
parents:
diff changeset
107
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
108
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
109 global compass_filter
0
heinrichsweikamp
parents:
diff changeset
110 compass_filter:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
111 banksel compass_DX ; select bank common2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
112 FILTER16 compass_DX, compass_DX_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
113 FILTER16 compass_DY, compass_DY_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
114 FILTER16 compass_DZ, compass_DZ_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
115 FILTER16 accel_DX, accel_DX_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
116 FILTER16 accel_DY, accel_DY_f
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
117 FILTER16 accel_DZ, accel_DZ_f
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
118 banksel common ; back to bank common
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
119 return
0
heinrichsweikamp
parents:
diff changeset
120
heinrichsweikamp
parents:
diff changeset
121
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
122 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
123 compass_ops2 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
124 ;=============================================================================
0
heinrichsweikamp
parents:
diff changeset
125
heinrichsweikamp
parents:
diff changeset
126 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
127 ; Q15 fractional numbers: a * b / 2**16 (UNSIGNED)
heinrichsweikamp
parents:
diff changeset
128 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
129 ; Uses 16x16->16 multiply, for positive integers, keeping only the most
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
130 ; relevant bits.
0
heinrichsweikamp
parents:
diff changeset
131 ;
heinrichsweikamp
parents:
diff changeset
132 ; Used to multiply two Q15 numbers, in the range 0..1,
heinrichsweikamp
parents:
diff changeset
133 ; represented as 0..32767, that is a / 2**15.
heinrichsweikamp
parents:
diff changeset
134 ;
heinrichsweikamp
parents:
diff changeset
135 ; (a/2**15) * (b/2**15) = a*b / 2**30 = (a*b/2**16) / 2**14.
heinrichsweikamp
parents:
diff changeset
136 ; So to get back a Q15 number, we need a shift-left...
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
137
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
138 global compass_umul ; called from compass.c
0
heinrichsweikamp
parents:
diff changeset
139 compass_umul:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
140 banksel compass_a ; select bank common2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
141 rcall compass_mul_16
0
heinrichsweikamp
parents:
diff changeset
142
heinrichsweikamp
parents:
diff changeset
143 ; The 2x time, by left-shifting inserting the missing bit:
heinrichsweikamp
parents:
diff changeset
144 compass_mul_2:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
145 rlcf compass_r+2,F ; missing bit into carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
146 rlcf compass_r+0,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
147 rlcf compass_r+1,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
148 MOVII compass_r,PROD ; return value into PROD
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
149 return
0
heinrichsweikamp
parents:
diff changeset
150
heinrichsweikamp
parents:
diff changeset
151 ; The 16x16-> multiply:
heinrichsweikamp
parents:
diff changeset
152 compass_mul_16:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
153 movf compass_a+1,W ; block ah*bh
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
154 mulwf compass_b+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
155 movff PRODL,compass_r+0 ; and copy
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
156 movff PRODH,compass_r+1
0
heinrichsweikamp
parents:
diff changeset
157
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
158 movf compass_a+0,W ; block al*bl
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
159 mulwf compass_b+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
160 movff PRODH,compass_r+2 ; into fraction byte
0
heinrichsweikamp
parents:
diff changeset
161
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
162 movf compass_a+1,W ; block ah*bl
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
163 mulwf compass_b+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
164 movf PRODL,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
165 addwf compass_r+2,F ; fraction part to carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
166 movf PRODH,W ; and add16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
167 addwfc compass_r+0,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
168 movlw 0
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
169 addwfc compass_r+1,F
0
heinrichsweikamp
parents:
diff changeset
170
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
171 movf compass_a+0,W ; block al*bh
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
172 mulwf compass_b+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
173 movf PRODL,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
174 addwf compass_r+2,F ; fraction part to carry
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
175 movf PRODH,W ; and add16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
176 addwfc compass_r+0,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
177 movlw 0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
178 addwfc compass_r+1,F
0
heinrichsweikamp
parents:
diff changeset
179
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
180 return
0
heinrichsweikamp
parents:
diff changeset
181
heinrichsweikamp
parents:
diff changeset
182 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
183 ; Q15 fractional numbers: a * b / 2**16 (SIGNED)
heinrichsweikamp
parents:
diff changeset
184
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
185 global compass_imul ; called from compass.c
0
heinrichsweikamp
parents:
diff changeset
186 compass_imul:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
187 banksel compass_a ; select bank common2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
188 rcall compass_mul_16
0
heinrichsweikamp
parents:
diff changeset
189
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
190 btfss compass_b+1,7
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
191 bra compass_mul_3
0
heinrichsweikamp
parents:
diff changeset
192
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
193 movf compass_a+0,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
194 subwf compass_r+0,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
195 movf compass_a+1,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
196 subwfb compass_r+1,F
0
heinrichsweikamp
parents:
diff changeset
197
heinrichsweikamp
parents:
diff changeset
198 compass_mul_3:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
199 btfss compass_a+1,7
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
200 bra compass_mul_4
0
heinrichsweikamp
parents:
diff changeset
201
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
202 movf compass_b+0,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
203 subwf compass_r+0,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
204 movf compass_b+1,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
205 subwfb compass_r+1,F
0
heinrichsweikamp
parents:
diff changeset
206
heinrichsweikamp
parents:
diff changeset
207 compass_mul_4:
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
208 bcf compass_r+1,6 ; copy bit 7 to 6, so keep it after 2x
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
209 btfsc compass_r+1,7
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
210 bsf compass_r+1,6
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
211 bra compass_mul_2
0
heinrichsweikamp
parents:
diff changeset
212
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
213
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
214 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
215 compass_ops3 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
216 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
217
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
218 global compass_calibration
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
219 compass_calibration: ; compass calibration
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
220 bsf block_sensor_interrupt ; disable sensor interrupts
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
221 call I2C_sleep_compass ; stop compass
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
222 call TFT_ClearScreen ; clear the screen
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
223 ; Mask
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
224 WIN_STD .16,.0 ; set position
656
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
225 FONT_COLOR color_green ; set font color
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
226 STRCPY_TEXT_PRINT tCompassCalibration
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
227 btfss switch_right2 ; wait until button (with a moving magnet in some OSTC!) is released
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
228 bra $-2
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
229
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
230 ; WIN_SMALL .0,.215
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
231 ; FONT_COLOR color_standard
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
232 ; STRCPY_TEXT_PRINT tExit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
233 WAITMS d'255'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
234 WAITMS d'255'
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
235
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
236 call request_speed_fastest ; request CPU speed change to fastest speed
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
237
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
238 movlw .5 ; initialize gain
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
239 movff WREG,opt_compass_gain ; ...
428
eccae727702f some cleanup
heinrichsweikamp
parents: 386
diff changeset
240
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
241 movlw .60 ; initialize timeout to 60 seconds
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
242 movwf isr_timeout_reload ; copy WREG to isr_timeout_reload
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
243 bsf restart_timeout ; request ISR to restart the timeout
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
244 bcf trigger_timeout ; clear any pending timeout trigger
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
245 compass_calibration_gainset: ; reduce the gain, set bank here!
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
246 banksel opt_compass_gain ; select bank options table
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
247 decf opt_compass_gain,F ; reduce by one
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
248 btfsc STATUS,N ; < 0 ?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
249 clrf opt_compass_gain ; YES - keep at zero
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
250 btfsc STATUS,N ; < 0 ?
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
251 bra compass_calibration_loop1 ; YES - skip gain stuff (Would hang here in case of compass failure)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
252 banksel common ; bank to bank common
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
253
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
254 call I2C_init_compass ; initialize compass chip
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
255
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
256 btfsc compass_type3 ; compass type 3 ?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
257 bra compass_calibration_loop1 ; YES - skip gain stuff
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
258 btfsc compass_type2 ; compass type 2 ?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
259 bra compass_calibration_loop1 ; YES - skip gain stuff
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
260
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
261 rcall TFT_compass_show_gain ; show the current compass gain
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
262
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
263 WAITMS d'250'
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
264 WAITMS d'250' ; wait for first reading...
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
265
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
266 movlw .60 ; calibration shall run for 60 seconds
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
267 call restart_timeout_time ; restart the timeout
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
268
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
269 call I2C_RX_compass ; read compass
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
270 call I2C_RX_accelerometer ; read accelerometer
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
271
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
272 ; Test all axes for +4096 (Hi byte=16)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
273 banksel compass_DX ; select bank common2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
274 movlw .16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
275 cpfseq compass_DX+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
276 bra $+4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
277 bra compass_calibration_gainset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
278 cpfseq compass_DY+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
279 bra $+4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
280 bra compass_calibration_gainset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
281 cpfseq compass_DZ+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
282 bra $+4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
283 bra compass_calibration_gainset
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
284
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
285 ; Test all axes for -4096 (Hi byte=240)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
286 movlw .240
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
287 cpfseq compass_DX+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
288 bra $+4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
289 bra compass_calibration_gainset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
290 cpfseq compass_DY+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
291 bra $+4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
292 bra compass_calibration_gainset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
293 cpfseq compass_DZ+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
294 bra $+4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
295 bra compass_calibration_gainset
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
296
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
297 compass_calibration_loop1: ; done with gain
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
298 banksel common ; bank to bank common
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
299 rcall compass_filter_init ; set DX_f values
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
300 call compass_reset_calibration ; reset CX_f values (C-code)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
301 banksel common ; back to bank common
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
302
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
303 compass_calibration_loop2:
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
304 call I2C_RX_compass ; read compass
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
305 call I2C_RX_accelerometer ; test accelerometer
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
306 call compass_filter ; filter compass raw data
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
307
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
308 ; Twice
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
309 call I2C_RX_compass ; read compass
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
310 call I2C_RX_accelerometer ; test accelerometer
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
311 call compass_filter ; filter compass raw data
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
312
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
313 ; btfsc compass_type1 ; compass1?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
314 ; bra compass_calibration_loop3 ; YES - skip gain stuff
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
315
645
070528a88715 3.16 release
heinrichsweikamp
parents: 643
diff changeset
316 banksel opt_compass_gain ; select bank options table
070528a88715 3.16 release
heinrichsweikamp
parents: 643
diff changeset
317 tstfsz opt_compass_gain ; =0?
070528a88715 3.16 release
heinrichsweikamp
parents: 643
diff changeset
318 bra $+4 ; No
070528a88715 3.16 release
heinrichsweikamp
parents: 643
diff changeset
319 bra compass_calibration_loop3 ; YES - skip gain stuff
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
320 ; Test all axes for +4096 (Hi byte=16)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
321 banksel compass_DX ; select bank common2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
322 movlw .16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
323 cpfseq compass_DX+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
324 bra $+4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
325 bra compass_calibration_gainset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
326 cpfseq compass_DY+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
327 bra $+4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
328 bra compass_calibration_gainset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
329 cpfseq compass_DZ+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
330 bra $+4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
331 bra compass_calibration_gainset
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
332
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
333 ; Test all axes for -4096 (Hi byte=240)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
334 movlw .240
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
335 cpfseq compass_DX+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
336 bra $+4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
337 bra compass_calibration_gainset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
338 cpfseq compass_DY+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
339 bra $+4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
340 bra compass_calibration_gainset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
341 cpfseq compass_DZ+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
342 bra $+4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
343 bra compass_calibration_gainset
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
344
428
eccae727702f some cleanup
heinrichsweikamp
parents: 386
diff changeset
345 compass_calibration_loop3:
645
070528a88715 3.16 release
heinrichsweikamp
parents: 643
diff changeset
346 banksel common ; back to bank common
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
347 ; and register only one value out of four:
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
348 call compass_add_calibration ; check and store new max/min values (C-code)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
349 banksel common ; back to bank common
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
350
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
351 rcall TFT_compass_fast ; show values
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
352 btfsc trigger_timeout ; timeout (calibration done)?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
353 bra compass_calibration_exit ; YES - done
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
354 btfss trigger_full_second ; NO - new second begun?
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
355 bra compass_calibration_loop2 ; NO - loop
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
356 bcf trigger_full_second ; YES - clear flag
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
357 rcall TFT_show_timeout_testmode ; - show remaining time
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
358 bra compass_calibration_loop2 ; - loop
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
359
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
360 compass_calibration_exit:
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
361 bcf block_sensor_interrupt ; re-enable sensor interrupts
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
362
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
363 call compass_solve_calibration ; calculate calibration factors (C-code)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
364 banksel common ; back to bank common
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
365
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
366 call request_speed_normal ; request CPU speed change to normal speed
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
367
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
368 bsf option_changed ; flag that option values have changed
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
369 bsf restart_fast ; request to skip logos and waits on restart
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
370
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
371 movlw .6 ; coding for surface compass view
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
372 movff WREG,customview_surfmode ; set to compass view to show
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
373
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
374 goto restart ; done
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
375
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
376
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
377 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
378 ; Helper Function
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
379 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
380 compass_filter_init:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
381 MOVII compass_DX,compass_DX_f
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
382 MOVII compass_DY,compass_DY_f
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
383 MOVII compass_DZ,compass_DZ_f
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
384
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
385 MOVII accel_DX,accel_DX_f
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
386 MOVII accel_DY,accel_DY_f
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
387 MOVII accel_DZ,accel_DZ_f
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
388 return
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
389
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
390 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
391 ; Show Calibration Progress
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
392 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
393 TFT_compass_fast:
650
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 649
diff changeset
394 WIN_TINY .5,.50 ; set font and position
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
395 FONT_COLOR_MEMO ; set font color
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
396
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
397 STRCPY "Cx:" ; print label
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
398 MOVII compass_DX,mpr ; get value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
399 rcall TFT_compass_fast_helper ; print value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
400
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
401 STRCAT " Cy:" ; print label
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
402 MOVII compass_DY,mpr ; get value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
403 rcall TFT_compass_fast_helper ; print value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
404
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
405 STRCAT " Cz:" ; print label
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
406 MOVII compass_DZ,mpr ; get value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
407 rcall TFT_compass_fast_helper ; print value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
408
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
409 PRINT ; dump to screen
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
410
650
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 649
diff changeset
411 WIN_TINY .5,.104 ; set font and position
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
412 FONT_COLOR_MEMO ; set font color
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
413
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
414 STRCPY "Ax:" ; print label
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
415 MOVII accel_DX,mpr ; get value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
416 rcall TFT_compass_fast_helper ; print value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
417
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
418 STRCAT " Ay:" ; print label
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
419 MOVII accel_DY,mpr ; get value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
420 rcall TFT_compass_fast_helper ; print value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
421
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
422 STRCAT " Az:" ; print label
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
423 MOVII accel_DZ,mpr ; get value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
424 rcall TFT_compass_fast_helper ; print value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
425
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
426 PRINT ; dump to screen
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
427 return ; done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
428
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
429
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
430 TFT_compass_fast_helper:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
431 call convert_signed_16bit ; convert lo:hi into unsigned-short and add '-' to POSTINC2 if required
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
432 btfsc neg_flag ; is value negative?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
433 bra TFT_compass_fast_helper1; YES - print value
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
434 PUTC '+' ; NO - print a plus sign first
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
435 TFT_compass_fast_helper1:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
436 output_65535 ; print value (0-65535)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
437 return
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
438
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
439
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
440
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
441 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
442 ; Show remaining Calibration Time
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
443 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
444 TFT_show_timeout_testmode:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
445 WIN_TINY .0,.68 ; set font and position
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
446 FONT_COLOR_MEMO ; set font color
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
447 STRCPY "T:" ; print label
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
448 movff isr_timeout_timer,lo ; get remaining time
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
449 output_256 ; print remaining time (xxx)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
450 PUTC_PRINT "s" ; append unit and dump to screen
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
451 return ; done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
452
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
453
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
454 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
455 ; Show current Compass Gain
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
456 ;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
457 TFT_compass_show_gain: ; show the current compass gain
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
458 ; movff opt_compass_gain,lo ; 0-7 (230 LSB/Gauss to 1370 LSB/Gauss)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
459 ; tstfsz lo
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
460 ; return ; do not show unless gain > 0
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
461 WIN_TINY .0,.86 ; set font and position
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
462 FONT_COLOR_MEMO ; set font color
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
463 STRCPY_TEXT tCompassGain ; print label
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
464 movff opt_compass_gain,lo ; get value: 0-7 (230 LSB/Gauss to 1370 LSB/Gauss)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
465 output_99 ; print value (xx)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
466 PRINT ; dump to screen
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
467 return ; done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
468
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
469
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
470 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
471 compass_ops4 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
472 ;=============================================================================
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
473
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
474 ;-----------------------------------------------------------------------------
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
475 ; Mask for Compass in Surface Mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
476 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
477 global TFT_surface_compass_mask
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
478 TFT_surface_compass_mask:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
479 WIN_SMALL surf_compass_mask_column,surf_compass_mask_row
656
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
480 FONT_COLOR color_green ; set font color
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
481 STRCPY_TEXT_PRINT tHeading ; print "Heading:"
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
482 return ; done
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
483
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
484
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
485 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
486 ; Compass Display in Surface Mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
487 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
488 global TFT_surface_compass_heading
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
489 TFT_surface_compass_heading:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
490 call compass_heading_common ; compute heading
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
491 WIN_STD surf_compass_head_column,surf_compass_head_row
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
492
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
493 TFT_surface_compass_heading_com: ; show "000° N"
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
494 FONT_COLOR_MEMO ; set default / dive-mode standard color
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
495 movff compass_heading_new+1,WREG ; get upper byte of actual heading
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
496 btfsc WREG,7 ; compass calibrated?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
497 bra TFT_compass_uncalibrated ; NO
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
498 MOVII compass_heading_shown,mpr ; get heading to be shown
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
499 rcall TFT_compass_helper ; show heading and its cardinal
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
500 btfsc divemode ; in dive mode?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
501 return ; YES - done for dive mode
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
502 ; in surface mode - shall show bearing?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
503 btfss compass_bearing_set ; is a bearing set?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
504 return ; NO - done
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
505 btfsc compass_menu ; is the "set bearing" selection shown?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
506 return ; YES - done
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
507 ; show bearing
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
508 WIN_SMALL surf_compass_bear_column,surf_compass_bear_row
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
509 FONT_COLOR color_yellow ; set font color
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
510 MOVII compass_bearing,mpr ; get bearing
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
511 ;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
512
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
513 TFT_compass_helper:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
514 output_999 ; print bearing
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
515 STRCAT "° " ; append unit and a space
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
516 call tft_compass_cardinal ; append cardinal buffer
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
517 PRINT ; dump to screen
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
518 return ; done
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
519
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
520 TFT_compass_uncalibrated:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
521 STRCAT_PRINT "---°" ; print "---°"
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
522 return ; done
382
6f3530eb48f9 allow compass bearing on surface
heinrichsweikamp
parents: 371
diff changeset
523
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
524
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
525 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
526 compass_ops5 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
527 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
528
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
529
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
530 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
531 ; Mask for Compass in Dive Mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
532 ;
656
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
533 global TFT_dive_compass_mask
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
534 TFT_dive_compass_mask:
656
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
535 FONT_COLOR_MASK ; select color
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
536 WIN_TINY dm_custom_compass_mask_column,dm_custom_compass_mask_row
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
537 STRCPY_TEXT_PRINT tCompassMenu ; print label
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
538 return
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
539
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
540
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
541 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
542 ; Compass Display in Dive Mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
543 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
544 global TFT_dive_compass_heading
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
545 TFT_dive_compass_heading:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
546 call compass_heading_common ; compute heading
656
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
547 ; Text output
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
548 FONT_COLOR_MEMO ; set default / dive-mode standard color
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
549 WIN_MEDIUM dm_custom_compass_head_column, dm_custom_compass_head_row
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
550 MOVII compass_heading_shown,mpr ; get heading to be shown
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
551 bsf leading_zeros
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
552 output_999 ; print bearing
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
553 bcf leading_zeros
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
554 PRINT ; dump to screen
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
555 WIN_STD dm_custom_compass_unit_column, dm_custom_compass_unit_row
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
556 STRCAT "°"
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
557 call tft_compass_cardinal ; append cardinal buffer
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
558 PRINT
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
559 ; shall show bearing?
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
560 btfss compass_bearing_set ; is a bearing set?
656
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
561 return ; NO - done
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
562 ; show bearing
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
563 WIN_SMALL dm_compass_bear_column,dm_compass_bear_row
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
564 FONT_COLOR color_yellow ; set font color
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
565 MOVII compass_bearing,mpr ; get bearing
8af5aefbcdaf Update to 3.31 beta
heinrichsweikamp
parents: 654
diff changeset
566 goto TFT_compass_helper ; show number and cardinal and return
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
567
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
568 tft_compass_cardinal:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
569 btfsc hi,0 ; heading > 255° ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
570 bra tft_compass_cardinal2 ; YES - must be W, NW or N
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
571 ; NO - must be W, SW, S, SE, E, NE or N
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
572 movlw .23
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
573 subwf lo,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
574 btfss STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
575 bra tft_compass_cardinal_N
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
576 movlw .68
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
577 subwf lo,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
578 btfss STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
579 bra tft_compass_cardinal_NE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
580 movlw .113
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
581 subwf lo,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
582 btfss STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
583 bra tft_compass_cardinal_E
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
584 movlw .158
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
585 subwf lo,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
586 btfss STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
587 bra tft_compass_cardinal_SE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
588 movlw .203
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
589 subwf lo,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
590 btfss STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
591 bra tft_compass_cardinal_S
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
592 movlw .248
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
593 subwf lo,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
594 btfss STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
595 bra tft_compass_cardinal_SW
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
596 bra tft_compass_cardinal_W
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
597
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
598 tft_compass_cardinal2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
599 movlw .37
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
600 subwf lo,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
601 btfss STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
602 bra tft_compass_cardinal_W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
603 movlw .82
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
604 subwf lo,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
605 btfss STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
606 bra tft_compass_cardinal_NW
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
607 ; bra tft_compass_cardinal_N
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
608
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
609 tft_compass_cardinal_N:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
610 STRCAT_TEXT tN
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
611 return
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
612 tft_compass_cardinal_NE:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
613 STRCAT_TEXT tNE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
614 return
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
615 tft_compass_cardinal_E:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
616 STRCAT_TEXT tE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
617 return
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
618 tft_compass_cardinal_SE:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
619 STRCAT_TEXT tSE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
620 return
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
621 tft_compass_cardinal_S:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
622 STRCAT_TEXT tS
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
623 return
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
624 tft_compass_cardinal_SW:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
625 STRCAT_TEXT tSW
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
626 return
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
627 tft_compass_cardinal_W:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
628 STRCAT_TEXT tW
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
629 return
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
630 tft_compass_cardinal_NW:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
631 STRCAT_TEXT tNW
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
632 return
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
633
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
634 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
635 compass_ops6 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
636 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
637
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
638 ;-----------------------------------------------------------------------------
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
639 ; get and process heading
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
640 ;
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
641 compass_heading_common:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
642 btfss compass_enabled ; compass enabled?
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
643 bra compass_heading_common_zero ; NO
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
644
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
645 ; Get an averaged new heading
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
646 movlw compass_averaging ; number of averaging cycles
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
647 movwf up ; initialize loop counter
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
648 compass_heading_common_1:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
649 call I2C_RX_compass ; test compass
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
650 call I2C_RX_accelerometer ; test accelerometer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
651 call compass_filter ; filter raw compass + accelerometer readings
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
652 decfsz up,F ; decrement loop counter, done?
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
653 bra compass_heading_common_1 ; NO - loop
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
654
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
655 call compass ; do compass correction (C-code)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
656 banksel common ; back to bank common
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
657
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
658 ; Check for calibration and change
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
659 MOVII compass_heading_shown,sub_a ; transfer shown heading to sub_a
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
660 MOVII compass_heading_new, sub_b ; transfer new heading to sub_b
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
661
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
662 btfsc sub_b+1,7 ; valid compass calibration?
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
663 bra compass_heading_common_zero ; NO
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
664
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
665 movf sub_a+0,W ; get shown heading, low byte
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
666 cpfseq sub_b+0 ; compare with new heading, low byte, equal?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
667 bra compass_heading_common_2 ; NO - not equal
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
668 movf sub_a+1,W ; get shown heading, high byte
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
669 cpfseq sub_b+1 ; compare with new heading, high byte, equal?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
670 bra compass_heading_common_2 ; NO - not equal
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
671 return ; YES - done
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
672
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
673 compass_heading_common_2:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
674 ; turn both headings such that compass_heading_new points to 0°
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
675 call subU16 ; sub_c = compass_heading_shown - compass_heading_new
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
676 btfss neg_flag ; was compass_heading_new in 1st halve?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
677 bra compass_heading_common_3 ; YES - check where compass_heading_shown is now
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
678 MOVLI .360, sub_a ; NO - overturned, need to turn back to match 360°
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
679 MOVII sub_c,sub_b ; - move overturned compass_heading_new to sub_b
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
680 call subU16 ; - sub_c = angle between overturned compass_heading_shown and 360°
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
681 compass_heading_common_3:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
682 ; check if turned compass_heading_shown is in 1st or 2nd halve
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
683 MOVII sub_c,sub_a ; sub_a = turned compass_heading_shown
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
684 MOVLI .180, sub_b ; sub_b = begin of 2nd halve
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
685 call cmpU16 ; check (turned compass_heading_shown) - 180°
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
686 btfss neg_flag ; result negative?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
687 bra compass_heading_common_5 ; NO - in 2nd halve, increment towards compass_heading_new
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
688 ;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
689
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
690 compass_heading_common_4:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
691 ; decrement compass_heading_shown towards compass_heading_new
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
692 rcall compass_heading_stepsize_2 ; calculate step size and put it into sub_b
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
693 MOVII compass_heading_shown,sub_a ; transfer unturned shown heading to sub_a
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
694 call subU16 ; decrement heading: sub_c = compass_heading_shown - step size
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
695 btfss neg_flag ; did an under-run occur?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
696 bra compass_heading_common_6 ; NO - store result
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
697 MOVLI .360, sub_a ; YES - wrap around 360°
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
698 MOVII sub_c,sub_b ; - transfer decrement result to sub_b
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
699 call subU16 ; - wrap decrement result around
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
700 bra compass_heading_common_6 ; - store wrapped result
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
701
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
702 compass_heading_common_5:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
703 ; increment compass_heading_shown towards compass_heading_new
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
704 rcall compass_heading_stepsize_1 ; calculate step size and put it into sub_b
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
705 MOVII compass_heading_shown,sub_a ; transfer unturned shown heading to sub_a
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
706 call addU16 ; increment heading: sub_c = compass_heading_shown + step size
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
707 MOVII sub_c,sub_a ; transfer increment result to sub_a
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
708 MOVLI .360, sub_b ; load wrap-around threshold
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
709 call subU16 ; calculate if over-run occurred
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
710 btfss neg_flag ; did an over-run occur?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
711 bra compass_heading_common_6 ; YES - store already wrapped-around result
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
712 MOVII sub_a,sub_c ; NO - retrieve former straight increment result
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
713 bra compass_heading_common_6 ; - store wrapped result
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
714
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
715 compass_heading_common_zero:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
716 CLRI sub_c ; set heading to 0°
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
717 ;bra compass_heading_common_6 ; store heading
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
718
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
719 compass_heading_common_6:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
720 MOVII sub_c,compass_heading_shown ; store new shown heading
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
721 return ; done
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
722
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
723 compass_heading_stepsize_1:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
724 ; turn heading difference (180...359) into a step size
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
725 MOVLI .360, sub_a ; load 360°
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
726 MOVII sub_c,sub_b ; load difference
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
727 call subU16 ; sub_c = 360 - difference (i.e. 1...180 now)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
728 compass_heading_stepsize_2:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
729 ; turn heading difference (1...180) into a step size
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
730 bcf STATUS,C ; clear carry
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
731 rrcf sub_c+0 ; heading difference /= 2
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
732 bcf STATUS,C ; clear carry
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
733 rrcf sub_c+0 ; heading difference /= 2, total /= 4 now
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
734 incf sub_c+0,f ; final += 1 to have one increment / decrement at least
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
735 MOVII sub_c,sub_b ; transfer result to sub_b
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
736 return
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
737
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 621
diff changeset
738 ENDIF ; _compass
256
5b4ef0b9090d place compass display code into compass_ops.asm
heinrichsweikamp
parents: 214
diff changeset
739
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
740 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
741
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 574
diff changeset
742 END