Rev 27 | Rev 29 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 27 | Rev 28 | ||
---|---|---|---|
Line 101... | Line 101... | ||
101 | 101 | ||
102 | { |
102 | { |
103 | bool stat = updateLocation (&loc, &uc1); |
103 | bool stat = updateLocation (&loc, &uc1); |
104 | 104 | ||
105 | // process button press : done by polling loop |
105 | // process button press : done by polling loop |
106 | uint8_t const buttonLimit = 3; |
106 | uint8_t const buttonLimit = 3; |
107 | uint8_t newPush = HAL_GPIO_ReadPin ( encoder_push_GPIO_Port, |
107 | uint8_t newPush = HAL_GPIO_ReadPin ( encoder_push_GPIO_Port, |
108 | encoder_push_Pin); |
108 | encoder_push_Pin); |
109 | if (newPush == buttonState) |
109 | if (newPush == buttonState) |
110 | buttonCount = 0; |
110 | buttonCount = 0; |
111 | else if (buttonCount < buttonLimit) |
111 | else if (buttonCount < buttonLimit) |
112 | buttonCount++; |
112 | buttonCount++; |
113 | 113 | ||
114 | if (buttonCount == buttonLimit) |
114 | if (buttonCount == buttonLimit) |
115 | { |
115 | { |
116 | buttonState = newPush; |
116 | buttonState = newPush; |
117 | buttonCount = 0; |
117 | buttonCount = 0; |
118 | 118 | ||
119 | // if the button is held down , we set the average speed |
119 | // if the button is held down , we set the average speed |
120 | if (buttonState == GPIO_PIN_RESET) |
120 | if (buttonState == GPIO_PIN_RESET) |
121 | { |
121 | { |
122 | speedAvgSum = 0.0; |
122 | speedAvgSum = 0.0; |
123 | speedAvgTime = 0.0; |
123 | speedAvgTime = 0.0; |
124 | } |
124 | } |
125 | } |
125 | } |
126 | - | ||
127 | - | ||
128 | 126 | ||
129 | if(rmc_flag) |
127 | if (rmc_flag) |
130 | { |
128 | { |
- | 129 | // get the time from the RTC |
|
- | 130 | RTC_TimeTypeDef sTime; |
|
131 | rmc_flag = 0; |
131 | rmc_flag = 0; |
132 | display1.clearDisplay (); |
132 | display1.clearDisplay (); |
133 | dial.draw_scale (0, 360, 8, 1, 45); |
133 | dial.draw_scale (0, 360, 8, 1, 45); |
134 | 134 | ||
135 | if ( loc.good) |
135 | if (loc.good) |
136 | { |
136 | { |
137 | 137 | ||
138 | heading = loc.heading; |
138 | heading = loc.heading; |
139 | // add in time * speed to give "distance" |
139 | // add in time * speed to give "distance" |
140 | if (loc.valid == 'A') |
140 | if (loc.valid == 'A') |
141 | { |
141 | { |
- | 142 | sTime.Seconds = loc.tv.tm_sec; |
|
- | 143 | sTime.Minutes = loc.tv.tm_min; |
|
- | 144 | sTime.Hours = loc.tv.tm_hour; |
|
- | 145 | HAL_RTC_SetTime (&hrtc, &sTime, RTC_FORMAT_BIN); |
|
- | 146 | ||
142 | if (lastLocTime != 0) |
147 | if (lastLocTime != 0) |
143 | { |
148 | { |
144 | double delta = difftime (loc.utc, lastLocTime); |
149 | double delta = difftime (loc.utc, lastLocTime); |
145 | // believe the speed . |
150 | // believe the speed . |
146 | if (delta > 0 && delta < 2) |
151 | if (delta > 0 && delta < 2) |
147 | { |
152 | { |
148 | speedAvgSum += loc.speed * delta; |
153 | speedAvgSum += loc.speed * delta; |
149 | speedAvgTime += delta; |
154 | speedAvgTime += delta; |
- | 155 | lastLocTime = loc.utc; |
|
- | 156 | } |
|
- | 157 | else |
|
150 | lastLocTime = loc.utc; |
158 | lastLocTime = loc.utc; |
151 | } |
159 | } |
152 | else |
- | |
153 | lastLocTime = loc.utc; |
- | |
154 | } |
- | |
155 | else |
160 | else |
156 | { |
161 | { |
157 | lastLocTime = loc.utc; |
162 | lastLocTime = loc.utc; |
158 | } |
163 | } |
159 | } |
164 | } |
160 | } |
165 | } |
161 | else |
166 | else |
162 | { |
167 | { |
163 | memset (loc.time, '-', 6); |
168 | HAL_RTC_GetTime (&hrtc, &sTime, RTC_FORMAT_BIN); |
164 | } |
- | |
165 | 169 | } |
|
166 | 170 | ||
167 | // update the display once per second |
- | |
168 | - | ||
169 | // slow down the output of ata |
171 | // slow down the output of ata |
170 | if (speedAvgTime > 0) |
172 | if (speedAvgTime > 0) |
171 | speedAvg = (speedAvgSum / speedAvgTime) * KNOTS_TO_MPH; |
173 | speedAvg = (speedAvgSum / speedAvgTime) * KNOTS_TO_MPH; |
172 | else |
174 | else |
173 | speedAvg = 0.0; |
175 | speedAvg = 0.0; |
174 | 176 | ||
- | 177 | // update the display once per second |
|
- | 178 | loc.time[0] = (sTime.Hours / 10) + '0'; |
|
- | 179 | loc.time[1] = (sTime.Hours % 10) + '0'; |
|
- | 180 | loc.time[2] = (sTime.Minutes / 10) + '0'; |
|
- | 181 | loc.time[3] = (sTime.Minutes % 10) + '0'; |
|
- | 182 | loc.time[4] = (sTime.Seconds / 10) + '0'; |
|
- | 183 | loc.time[5] = (sTime.Seconds % 10) + '0'; |
|
175 | // print out the GMT time at the top of the screen |
184 | // print out the GMT time at the top of the screen |
176 | display1.gotoxy (0, 0); |
185 | display1.gotoxy (0, 0); |
177 | display1.printString (small_font, &loc.time[0], 2, WHITE); |
186 | display1.printString (small_font, &loc.time[0], 2, WHITE); |
178 | display1.printString (small_font, ":", 1, WHITE); |
187 | display1.printString (small_font, ":", 1, WHITE); |
179 | display1.printString (small_font, &loc.time[2], 2, WHITE); |
188 | display1.printString (small_font, &loc.time[2], 2, WHITE); |
180 | 189 | ||
181 | display1.printString (small_font, ":", 1, WHITE); |
190 | display1.printString (small_font, ":", 1, WHITE); |
182 | display1.printString (small_font, &loc.time[4], 2, WHITE); |
191 | display1.printString (small_font, &loc.time[4], 2, WHITE); |
183 | 192 | ||
184 | int dial_ang = heading + 180; |
193 | int dial_ang = heading + 180; |
185 | dial.draw_needle (dial_ang); |
194 | dial.draw_needle (dial_ang); |
186 | 195 | ||
187 | display1.gotoxy (70, 25); |
196 | display1.gotoxy (70, 25); |
188 | if (loc.valid == 'A') |
197 | if (loc.valid == 'A') |
189 | { |
198 | { |
190 | display1.fontDigits (large_font, 3, -1, heading); |
199 | display1.fontDigits (large_font, 3, -1, heading); |
191 | } |
200 | } |
192 | else |
201 | else |
193 | display1.printString (large_font, "GPS?", 4, WHITE); |
202 | display1.printString (large_font, "GPS?", 4, WHITE); |
194 | 203 | ||
195 | if (loc.valid == 'A') |
204 | if (loc.valid == 'A') |
196 | speedMPH = loc.speed * KNOTS_TO_MPH; |
205 | speedMPH = loc.speed * KNOTS_TO_MPH; |
197 | else |
206 | else |
198 | speedMPH = 0.0; |
207 | speedMPH = 0.0; |
199 | 208 | ||
200 | display1.gotoxy (0, 8); |
209 | display1.gotoxy (0, 8); |
201 | display1.fontDigits (large_font, 4,1, speedMPH * 10 ); |
210 | display1.fontDigits (large_font, 4, 1, speedMPH * 10); |
202 | display1.printString (small_font, "c", 2, WHITE); |
211 | display1.printString (small_font, "c", 2, WHITE); |
203 | display1.gotoxy (0,24); |
212 | display1.gotoxy (0, 24); |
204 | display1.fontDigits (large_font, 4, 1, speedAvg * 10); |
213 | display1.fontDigits (large_font, 4, 1, speedAvg * 10); |
205 | display1.printString (small_font, "av", 2, WHITE); |
214 | display1.printString (small_font, "av", 2, WHITE); |
206 | 215 | ||
207 | float x, y, z; |
216 | float x, y, z; |
208 | if (IMU.magneticFieldAvailable ()) |
217 | if (IMU.magneticFieldAvailable ()) |
209 | { |
218 | { |
210 | 219 | ||
211 | IMU.readMagneticField (x, y, z); |
220 | IMU.readMagneticField (x, y, z); |
212 | } |
221 | } |
213 | 222 | ||
214 | if (IMU.accelerationAvailable ()) |
223 | if (IMU.accelerationAvailable ()) |
215 | { |
224 | { |
216 | IMU.readAcceleration (x, y, z); |
225 | IMU.readAcceleration (x, y, z); |
217 | } |
226 | } |
218 | 227 | ||
219 | struct bmp280_uncomp_data ucomp_data, ucomp_data2; |
228 | struct bmp280_uncomp_data ucomp_data, ucomp_data2; |
220 | 229 | ||
221 | if (HAL_GetTick () - lastTick > 100) |
230 | if (HAL_GetTick () - lastTick > 100) |
222 | { |
231 | { |
223 | lastTick = HAL_GetTick (); |
232 | lastTick = HAL_GetTick (); |
224 | /* Reading the raw data from sensor */ |
233 | /* Reading the raw data from sensor */ |
225 | rslt = bmp280_get_uncomp_data (&ucomp_data, bmp); |
234 | rslt = bmp280_get_uncomp_data (&ucomp_data, bmp); |
226 | 235 | ||
227 | /* reading the raw data from the second sensor */ |
236 | /* reading the raw data from the second sensor */ |
228 | rslt2 = bmp280_get_uncomp_data (&ucomp_data2, bmp2); |
237 | rslt2 = bmp280_get_uncomp_data (&ucomp_data2, bmp2); |
229 | 238 | ||
230 | if (rslt2 == BMP280_OK) |
239 | if (rslt2 == BMP280_OK) |
231 | { |
240 | { |
232 | rslt2 = bmp280_get_comp_temp_32bit (&temp32_out, |
241 | rslt2 = bmp280_get_comp_temp_32bit (&temp32_out, |
233 | ucomp_data2.uncomp_temp, bmp2); |
242 | ucomp_data2.uncomp_temp, |
- | 243 | bmp2); |
|
234 | } |
244 | } |
235 | 245 | ||
236 | if (rslt == BMP280_OK) |
246 | if (rslt == BMP280_OK) |
237 | { |
247 | { |
238 | /* Getting the 32 bit compensated temperature */ |
248 | /* Getting the 32 bit compensated temperature */ |
239 | rslt = bmp280_get_comp_temp_32bit (&temp32, |
249 | rslt = bmp280_get_comp_temp_32bit (&temp32, |
240 | ucomp_data.uncomp_temp, |
250 | ucomp_data.uncomp_temp, bmp); |
241 | bmp); |
- | |
242 | 251 | ||
243 | rslt = bmp280_get_comp_pres_32bit (&pres32, |
252 | rslt = bmp280_get_comp_pres_32bit (&pres32, |
244 | ucomp_data.uncomp_press, |
253 | ucomp_data.uncomp_press, bmp); |
245 | bmp); |
- | |
246 | 254 | ||
247 | #if defined USB_DEVICE |
255 | #if defined USB_DEVICE |
248 | /* |
256 | /* |
249 | * $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF> \\ |
257 | * $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF> \\ |
250 | 258 | ||
Line 279... | Line 287... | ||
279 | cnt+= small_sprintf(buffer+cnt,"*%02X\n",sum); |
287 | cnt+= small_sprintf(buffer+cnt,"*%02X\n",sum); |
280 | 288 | ||
281 | CDC_Transmit_FS(reinterpret_cast<uint8_t*>(&buffer[0]),cnt); |
289 | CDC_Transmit_FS(reinterpret_cast<uint8_t*>(&buffer[0]),cnt); |
282 | #endif |
290 | #endif |
283 | 291 | ||
284 | } |
292 | } |
285 | } |
293 | } |
286 | display1.gotoxy (0,40); |
294 | display1.gotoxy (0, 40); |
287 | display1.fontDigits (large_font, 4, 1, temp32_out / 10, WHITE); |
295 | display1.fontDigits (large_font, 4, 1, temp32_out / 10, WHITE); |
288 | display1.printString (small_font, "C", 1, WHITE); |
296 | display1.printString (small_font, "°", 1, WHITE); |
289 | 297 | ||
290 | display1.gotoxy (0, 56); |
298 | display1.gotoxy (0, 56); |
291 | display1.fontDigits (small_font, 3, 1, temp32 / 10, WHITE); |
299 | display1.fontDigits (small_font, 3, 1, temp32 / 10, WHITE); |
292 | display1.printString (small_font, "C", 2, WHITE); |
300 | display1.printString (small_font, "° ", 2, WHITE); |
293 | - | ||
294 | display1.fontDigits (small_font, 4, -1, pres32 / 100, WHITE); |
301 | display1.fontDigits (small_font, 4, -1, pres32 / 100, WHITE); |
295 | display1.printString (small_font, "mb ", 2, WHITE); |
302 | display1.printString (small_font, "mb", 2, WHITE); |
296 | 303 | ||
297 | display1.display (); |
304 | display1.display (); |
298 | 305 | ||
299 | } |
306 | } |
300 | 307 | ||
301 | HAL_Delay(10); |
308 | HAL_Delay (10); |
302 | } |
309 | } |