Rev 26 | Rev 28 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 26 | Rev 27 | ||
---|---|---|---|
Line 61... | Line 61... | ||
61 | displayDial_t dial (display1, 96, 32, 32, 180); |
61 | displayDial_t dial (display1, 96, 32, 32, 180); |
62 | 62 | ||
63 | // debouncer for the button |
63 | // debouncer for the button |
64 | char buttonState; |
64 | char buttonState; |
65 | char buttonCount; |
65 | char buttonCount; |
- | 66 | char rmc_flag = 0; |
|
- | 67 | ||
- | 68 | extern "C" uint8_t |
|
- | 69 | rmc_callback (uint8_t *data, uint16_t length) |
|
- | 70 | { |
|
- | 71 | rmc_flag = 1; |
|
- | 72 | HAL_GPIO_TogglePin (Green_LED_GPIO_Port, Green_LED_Pin); |
|
- | 73 | ||
- | 74 | return CDC_Transmit_FS (data, length); |
|
- | 75 | } |
|
66 | 76 | ||
67 | extern "C" void |
77 | extern "C" void |
68 | cc_init () |
78 | cc_init () |
69 | { |
79 | { |
70 | display1.reset (); |
80 | display1.reset (); |
Line 76... | Line 86... | ||
76 | 86 | ||
77 | display1.display (); |
87 | display1.display (); |
78 | 88 | ||
79 | memset (loc.time, '-', 6); |
89 | memset (loc.time, '-', 6); |
80 | // every time we receive GPRMC, forward the text line to the USB driver |
90 | // every time we receive GPRMC, forward the text line to the USB driver |
81 | setRmcCallback (&CDC_Transmit_FS); |
91 | setRmcCallback (&rmc_callback); |
82 | 92 | ||
83 | // initialise IMU operations |
93 | // initialise IMU operations |
84 | IMU.begin (); |
94 | IMU.begin (); |
85 | 95 | ||
86 | } |
96 | } |
Line 88... | Line 98... | ||
88 | char fontBuf[] = "01234567"; |
98 | char fontBuf[] = "01234567"; |
89 | extern "C" void |
99 | extern "C" void |
90 | cc_run (struct bmp280_dev *bmp, struct bmp280_dev *bmp2) |
100 | cc_run (struct bmp280_dev *bmp, struct bmp280_dev *bmp2) |
91 | 101 | ||
92 | { |
102 | { |
93 | display1.clearDisplay (); |
- | |
94 | dial.draw_scale (0, 360, 8, 1, 45); |
- | |
95 | while (1) |
- | |
96 | { |
- | |
97 | bool stat = updateLocation (&loc, &uc1); |
103 | bool stat = updateLocation (&loc, &uc1); |
98 | if (!stat) |
- | |
99 | break; |
- | |
100 | if (stat && loc.good) |
- | |
101 | { |
- | |
102 | 104 | ||
103 | heading = loc.heading; |
- | |
104 | // add in time * speed to give "distance" |
- | |
105 | if (loc.valid == 'A') |
- | |
106 | { |
- | |
107 | if (lastLocTime != 0) |
- | |
108 | { |
- | |
109 | double delta = difftime (loc.utc, lastLocTime); |
- | |
110 | // believe the speed . |
- | |
111 | if (delta > 0 && delta < 2) |
- | |
112 | { |
- | |
113 | speedAvgSum += loc.speed * delta; |
- | |
114 | speedAvgTime += delta; |
- | |
115 | lastLocTime = loc.utc; |
- | |
116 | } |
- | |
117 | else |
- | |
118 | lastLocTime = loc.utc; |
- | |
119 | } |
- | |
120 | else |
- | |
121 | { |
- | |
122 | lastLocTime = loc.utc; |
- | |
123 | } |
- | |
124 | } |
- | |
125 | } |
- | |
126 | else |
- | |
127 | { |
- | |
128 | memset (loc.time, '-', 6); |
- | |
129 | } |
- | |
130 | } |
- | |
131 | // process button press |
105 | // process button press : done by polling loop |
132 | uint8_t const buttonLimit = 3; |
106 | uint8_t const buttonLimit = 3; |
133 | uint8_t newPush = HAL_GPIO_ReadPin ( encoder_push_GPIO_Port, |
107 | uint8_t newPush = HAL_GPIO_ReadPin ( encoder_push_GPIO_Port, |
134 | encoder_push_Pin); |
108 | encoder_push_Pin); |
135 | if (newPush == buttonState) |
109 | if (newPush == buttonState) |
136 | buttonCount = 0; |
110 | buttonCount = 0; |
137 | else if (buttonCount < buttonLimit) |
111 | else if (buttonCount < buttonLimit) |
138 | buttonCount++; |
112 | buttonCount++; |
139 | 113 | ||
140 | if (buttonCount == buttonLimit) |
114 | if (buttonCount == buttonLimit) |
141 | { |
115 | { |
142 | buttonState = newPush; |
116 | buttonState = newPush; |
143 | buttonCount = 0; |
117 | buttonCount = 0; |
144 | 118 | ||
145 | // if the button is held down , we set the average speed |
119 | // if the button is held down , we set the average speed |
146 | if (buttonState == GPIO_PIN_RESET) |
120 | if (buttonState == GPIO_PIN_RESET) |
147 | { |
121 | { |
148 | speedAvgSum = 0.0; |
122 | speedAvgSum = 0.0; |
149 | speedAvgTime = 0.0; |
123 | speedAvgTime = 0.0; |
150 | } |
124 | } |
151 | } |
125 | } |
152 | 126 | ||
153 | // update the display once per second |
- | |
154 | if (HAL_GetTick () > nextPosTime) |
- | |
155 | { |
- | |
156 | nextPosTime += 1000; |
- | |
157 | 127 | ||
- | 128 | ||
- | 129 | if(rmc_flag) |
|
- | 130 | { |
|
- | 131 | rmc_flag = 0; |
|
- | 132 | display1.clearDisplay (); |
|
- | 133 | dial.draw_scale (0, 360, 8, 1, 45); |
|
- | 134 | ||
- | 135 | if ( loc.good) |
|
- | 136 | { |
|
- | 137 | ||
- | 138 | heading = loc.heading; |
|
- | 139 | // add in time * speed to give "distance" |
|
- | 140 | if (loc.valid == 'A') |
|
- | 141 | { |
|
- | 142 | if (lastLocTime != 0) |
|
- | 143 | { |
|
- | 144 | double delta = difftime (loc.utc, lastLocTime); |
|
- | 145 | // believe the speed . |
|
- | 146 | if (delta > 0 && delta < 2) |
|
- | 147 | { |
|
- | 148 | speedAvgSum += loc.speed * delta; |
|
- | 149 | speedAvgTime += delta; |
|
- | 150 | lastLocTime = loc.utc; |
|
- | 151 | } |
|
- | 152 | else |
|
- | 153 | lastLocTime = loc.utc; |
|
- | 154 | } |
|
- | 155 | else |
|
- | 156 | { |
|
- | 157 | lastLocTime = loc.utc; |
|
- | 158 | } |
|
- | 159 | } |
|
- | 160 | } |
|
- | 161 | else |
|
- | 162 | { |
|
- | 163 | memset (loc.time, '-', 6); |
|
- | 164 | } |
|
- | 165 | ||
- | 166 | ||
- | 167 | // update the display once per second |
|
- | 168 | ||
158 | // slow down the output of ata |
169 | // slow down the output of ata |
159 | if (speedAvgTime > 0) |
170 | if (speedAvgTime > 0) |
160 | speedAvg = (speedAvgSum / speedAvgTime) * KNOTS_TO_MPH; |
171 | speedAvg = (speedAvgSum / speedAvgTime) * KNOTS_TO_MPH; |
161 | else |
172 | else |
162 | speedAvg = 0.0; |
173 | speedAvg = 0.0; |
163 | 174 | ||
164 | // print out the GMT time at the top of the screen |
175 | // print out the GMT time at the top of the screen |
165 | display1.gotoxy (0, 0); |
176 | display1.gotoxy (0, 0); |
166 | display1.printString (small_font, &loc.time[0], 2, WHITE); |
177 | display1.printString (small_font, &loc.time[0], 2, WHITE); |
167 | display1.printString (small_font, ":", 1, WHITE); |
178 | display1.printString (small_font, ":", 1, WHITE); |
168 | display1.printString (small_font, &loc.time[2], 2, WHITE); |
179 | display1.printString (small_font, &loc.time[2], 2, WHITE); |
169 | 180 | ||
170 | display1.printString (small_font, ":", 1, WHITE); |
181 | display1.printString (small_font, ":", 1, WHITE); |
171 | display1.printString (small_font, &loc.time[4], 2, WHITE); |
182 | display1.printString (small_font, &loc.time[4], 2, WHITE); |
172 | 183 | ||
173 | int dial_ang = heading + 180; |
184 | int dial_ang = heading + 180; |
174 | dial.draw_needle (dial_ang); |
185 | dial.draw_needle (dial_ang); |
175 | 186 | ||
176 | display1.gotoxy (70, 25); |
187 | display1.gotoxy (70, 25); |
177 | if (loc.valid == 'A') |
188 | if (loc.valid == 'A') |
178 | { |
189 | { |
179 | display1.fontDigits (large_font, 3, -1, heading); |
190 | display1.fontDigits (large_font, 3, -1, heading); |
180 | } |
191 | } |
181 | else |
192 | else |
182 | display1.printString (large_font, "GPS?", 4, WHITE); |
193 | display1.printString (large_font, "GPS?", 4, WHITE); |
183 | 194 | ||
184 | if (loc.valid == 'A') |
195 | if (loc.valid == 'A') |
185 | speedMPH = loc.speed * KNOTS_TO_MPH; |
196 | speedMPH = loc.speed * KNOTS_TO_MPH; |
186 | else |
197 | else |
187 | speedMPH = 0.0; |
198 | speedMPH = 0.0; |
188 | 199 | ||
189 | display1.gotoxy (0, 8); |
200 | display1.gotoxy (0, 8); |
190 | display1.fontDigits (large_font, 4,1, speedMPH * 10 ); |
201 | display1.fontDigits (large_font, 4,1, speedMPH * 10 ); |
191 | display1.printString (small_font, "c", 2, WHITE); |
202 | display1.printString (small_font, "c", 2, WHITE); |
192 | display1.gotoxy (0,24); |
203 | display1.gotoxy (0,24); |
193 | display1.fontDigits (large_font, 4, 1, speedAvg * 10); |
204 | display1.fontDigits (large_font, 4, 1, speedAvg * 10); |
194 | display1.printString (small_font, "av", 2, WHITE); |
205 | display1.printString (small_font, "av", 2, WHITE); |
195 | 206 | ||
196 | float x, y, z; |
207 | float x, y, z; |
197 | if (IMU.magneticFieldAvailable ()) |
208 | if (IMU.magneticFieldAvailable ()) |
198 | { |
209 | { |
199 | 210 | ||
200 | IMU.readMagneticField (x, y, z); |
211 | IMU.readMagneticField (x, y, z); |
201 | } |
212 | } |
202 | 213 | ||
203 | if (IMU.accelerationAvailable ()) |
214 | if (IMU.accelerationAvailable ()) |
204 | { |
215 | { |
205 | IMU.readAcceleration (x, y, z); |
216 | IMU.readAcceleration (x, y, z); |
206 | } |
217 | } |
207 | 218 | ||
208 | struct bmp280_uncomp_data ucomp_data, ucomp_data2; |
219 | struct bmp280_uncomp_data ucomp_data, ucomp_data2; |
209 | 220 | ||
210 | if (HAL_GetTick () - lastTick > 100) |
221 | if (HAL_GetTick () - lastTick > 100) |
211 | { |
222 | { |
212 | lastTick = HAL_GetTick (); |
223 | lastTick = HAL_GetTick (); |
213 | /* Reading the raw data from sensor */ |
224 | /* Reading the raw data from sensor */ |
214 | rslt = bmp280_get_uncomp_data (&ucomp_data, bmp); |
225 | rslt = bmp280_get_uncomp_data (&ucomp_data, bmp); |
215 | 226 | ||
216 | /* reading the raw data from the second sensor */ |
227 | /* reading the raw data from the second sensor */ |
217 | rslt2 = bmp280_get_uncomp_data (&ucomp_data2, bmp2); |
228 | rslt2 = bmp280_get_uncomp_data (&ucomp_data2, bmp2); |
218 | 229 | ||
219 | if (rslt2 == BMP280_OK) |
230 | if (rslt2 == BMP280_OK) |
220 | { |
231 | { |
221 | rslt2 = bmp280_get_comp_temp_32bit (&temp32_out, |
232 | rslt2 = bmp280_get_comp_temp_32bit (&temp32_out, |
222 | ucomp_data2.uncomp_temp, bmp2); |
233 | ucomp_data2.uncomp_temp, bmp2); |
223 | } |
234 | } |
224 | - | ||
225 | 235 | ||
226 | if (rslt == BMP280_OK) |
236 | if (rslt == BMP280_OK) |
227 | { |
237 | { |
228 | /* Getting the 32 bit compensated temperature */ |
238 | /* Getting the 32 bit compensated temperature */ |
229 | rslt = bmp280_get_comp_temp_32bit (&temp32, |
239 | rslt = bmp280_get_comp_temp_32bit (&temp32, |
230 | ucomp_data.uncomp_temp, |
240 | ucomp_data.uncomp_temp, |
231 | bmp); |
241 | bmp); |
232 | 242 | ||
233 | rslt = bmp280_get_comp_pres_32bit (&pres32, |
243 | rslt = bmp280_get_comp_pres_32bit (&pres32, |
234 | ucomp_data.uncomp_press, |
244 | ucomp_data.uncomp_press, |
235 | bmp); |
245 | bmp); |
236 | 246 | ||
237 | #if defined USB_DEVICE |
247 | #if defined USB_DEVICE |
238 | /* |
248 | /* |
239 | * $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF> \\ |
249 | * $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF> \\ |
240 | 250 | ||
241 | Field Number: |
251 | Field Number: |
242 | 1) Transducer Type |
252 | 1) Transducer Type |
243 | 2) Measurement Data |
253 | 2) Measurement Data |
244 | 3) Units of measurement |
254 | 3) Units of measurement |
245 | 4) Name of transducer |
255 | 4) Name of transducer |
246 | x) More of the same |
256 | x) More of the same |
247 | n) Checksum |
257 | n) Checksum |
248 | 258 | ||
249 | Example: |
259 | Example: |
250 | $IIXDR,C,19.52,C,TempAir*19 |
260 | $IIXDR,C,19.52,C,TempAir*19 |
251 | $IIXDR,P,1.02481,B,Barometer*29 |
261 | $IIXDR,P,1.02481,B,Barometer*29 |
252 | 262 | ||
253 | Currently, OpenCPN recognizes the following transducers: |
263 | Currently, OpenCPN recognizes the following transducers: |
254 | 264 | ||
255 | Measured Value | Transducer Type | Measured Data | Unit of measure | Transducer Name |
265 | Measured Value | Transducer Type | Measured Data | Unit of measure | Transducer Name |
256 | ------------------------------------------------------------------------------------------------------ |
266 | ------------------------------------------------------------------------------------------------------ |
257 | barometric | "P" pressure | 0.8..1.1 or 800..1100 | "B" bar | "Barometer" |
267 | barometric | "P" pressure | 0.8..1.1 or 800..1100 | "B" bar | "Barometer" |
258 | air temperature| "C" temperature | 2 decimals | "C" celsius | "TempAir" or "ENV_OUTAIR_T" |
268 | air temperature| "C" temperature | 2 decimals | "C" celsius | "TempAir" or "ENV_OUTAIR_T" |
259 | pitch | "A" angle |-180..0 nose down 0..180 nose up | "D" degrees | "PTCH" or "PITCH" |
269 | pitch | "A" angle |-180..0 nose down 0..180 nose up | "D" degrees | "PTCH" or "PITCH" |
260 | rolling | "A" angle |-180..0 L 0..180 R | "D" degrees | "ROLL" |
270 | rolling | "A" angle |-180..0 L 0..180 R | "D" degrees | "ROLL" |
261 | water temp | "C" temperature | 2 decimals | "C" celsius | "ENV_WATER_T" |
271 | water temp | "C" temperature | 2 decimals | "C" celsius | "ENV_WATER_T" |
262 | */ |
272 | */ |
263 | // compile a logger message over USB |
273 | // compile a logger message over USB |
264 | char buffer[200]; |
274 | char buffer[200]; |
265 | int cnt = small_sprintf(buffer,"$MJXDR,C,%ld.%02ld,C,AirTemp,P,%01ld.%05ld,B,AirPres",temp32/100,temp32%100,pres32/100000,pres32%100000); |
275 | int cnt = small_sprintf(buffer,"$MJXDR,C,%ld.%02ld,C,AirTemp,P,%01ld.%05ld,B,AirPres",temp32/100,temp32%100,pres32/100000,pres32%100000); |
266 | uint8_t sum=0; |
276 | uint8_t sum=0; |
267 | for(int i=1; i<cnt; i++) |
277 | for(int i=1; i<cnt; i++) |
268 | sum += buffer[i]; |
278 | sum += buffer[i]; |
269 | cnt+= small_sprintf(buffer+cnt,"*%02X\n",sum); |
279 | cnt+= small_sprintf(buffer+cnt,"*%02X\n",sum); |
270 | 280 | ||
271 | CDC_Transmit_FS(reinterpret_cast<uint8_t*>(&buffer[0]),cnt); |
281 | CDC_Transmit_FS(reinterpret_cast<uint8_t*>(&buffer[0]),cnt); |
272 | #endif |
282 | #endif |
273 | 283 | ||
274 | } |
284 | } |
275 | } |
285 | } |
276 | display1.gotoxy (0,40); |
286 | display1.gotoxy (0,40); |
277 | display1.fontDigits (large_font, 4, 1, temp32_out / 10, WHITE); |
287 | display1.fontDigits (large_font, 4, 1, temp32_out / 10, WHITE); |
278 | display1.printString (small_font, "C", 1, WHITE); |
288 | display1.printString (small_font, "C", 1, WHITE); |
279 | - | ||
280 | display1.gotoxy (0, 56); |
- | |
281 | display1.fontDigits (small_font, 3, 1, temp32 / 10, WHITE); |
- | |
282 | display1.printString (small_font, "C", 2, WHITE); |
- | |
283 | 289 | ||
- | 290 | display1.gotoxy (0, 56); |
|
284 | display1.fontDigits (small_font, 4, -1, pres32 / 100, WHITE); |
291 | display1.fontDigits (small_font, 3, 1, temp32 / 10, WHITE); |
285 | display1.printString (small_font, "mb ", 2, WHITE); |
292 | display1.printString (small_font, "C", 2, WHITE); |
286 | 293 | ||
- | 294 | display1.fontDigits (small_font, 4, -1, pres32 / 100, WHITE); |
|
287 | display1.display (); |
295 | display1.printString (small_font, "mb ", 2, WHITE); |
288 | 296 | ||
- | 297 | display1.display (); |
|
- | 298 | ||
289 | } |
299 | } |
290 | } |
300 | |
- | 301 | HAL_Delay(10); |
|
- | 302 | } |