Rev 25 | Rev 27 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 25 | Rev 26 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | #include "libNMEA/nmea.h" |
2 | #include "libNMEA/nmea.h" |
| 3 | #include <cstring> |
3 | #include <cstring> |
| 4 | #include "libOLED/stm32_halDisplay.H" |
4 | #include "libOLED/stm32_halDisplay.H" |
| 5 | #include "libOLED/fontclass.H" |
5 | #include "libOLED/fontclass.H" |
| 6 | #include "libOLED/displayDial.H" |
6 | #include "libOLED/displayDial.H" |
| - | 7 | #include "libLSM9DS1/LSM9DS1.h" |
|
| 7 | 8 | ||
| 8 | #include "libBMP280/bmp280.h" |
9 | #include "libBMP280/bmp280.h" |
| 9 | 10 | ||
| 10 | #include "libSmallPrintf/small_printf.h" |
11 | #include "libSmallPrintf/small_printf.h" |
| 11 | 12 | ||
| 12 | #if defined USB_DEVICE |
13 | #if defined USB_DEVICE |
| 13 | #include "usbd_cdc_if.h" |
14 | #include "usbd_cdc_if.h" |
| 14 | #endif |
15 | #endif |
| 15 | 16 | ||
| - | 17 | LSM9DS1Class IMU (&hi2c2); |
|
| - | 18 | ||
| 16 | namespace |
19 | namespace |
| 17 | { |
20 | { |
| 18 | int const WIDTH = 128; |
21 | int const WIDTH = 128; |
| 19 | int const HEIGHT = 64; |
22 | int const HEIGHT = 64; |
| 20 | int const DISPLAY_RAMWIDTH = 132; |
23 | int const DISPLAY_RAMWIDTH = 132; |
| Line 37... | Line 40... | ||
| 37 | 40 | ||
| 38 | uint32_t lastTick = 0; |
41 | uint32_t lastTick = 0; |
| 39 | int32_t temp32 = 0; |
42 | int32_t temp32 = 0; |
| 40 | uint32_t pres32 = 0; |
43 | uint32_t pres32 = 0; |
| 41 | int32_t rslt; |
44 | int32_t rslt; |
| - | 45 | int32_t rslt2; // result from read of second sensor |
|
| - | 46 | // second sensor |
|
| - | 47 | int32_t temp32_out = 0; |
|
| 42 | 48 | ||
| 43 | uint8_t displayBuffer[dataSize (WIDTH, HEIGHT)]; |
49 | uint8_t displayBuffer[dataSize (WIDTH, HEIGHT)]; |
| 44 | 50 | ||
| 45 | stm32_halDisplay_t display1 (WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer, |
51 | stm32_halDisplay_t display1 (WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer, |
| 46 | &hspi1, |
52 | &hspi1, |
| Line 69... | Line 75... | ||
| 69 | dial.draw_scale (0, 360, 8, 1, 45); |
75 | dial.draw_scale (0, 360, 8, 1, 45); |
| 70 | 76 | ||
| 71 | display1.display (); |
77 | display1.display (); |
| 72 | 78 | ||
| 73 | memset (loc.time, '-', 6); |
79 | memset (loc.time, '-', 6); |
| - | 80 | // every time we receive GPRMC, forward the text line to the USB driver |
|
| - | 81 | setRmcCallback (&CDC_Transmit_FS); |
|
| - | 82 | ||
| - | 83 | // initialise IMU operations |
|
| - | 84 | IMU.begin (); |
|
| - | 85 | ||
| 74 | } |
86 | } |
| 75 | 87 | ||
| 76 | char fontBuf[] = "01234567"; |
88 | char fontBuf[] = "01234567"; |
| 77 | extern "C" void |
89 | extern "C" void |
| 78 | cc_run (struct bmp280_dev *bmp) |
90 | cc_run (struct bmp280_dev *bmp, struct bmp280_dev *bmp2) |
| 79 | 91 | ||
| 80 | { |
92 | { |
| 81 | display1.clearDisplay (); |
93 | display1.clearDisplay (); |
| 82 | dial.draw_scale (0, 360, 8, 1, 45); |
94 | dial.draw_scale (0, 360, 8, 1, 45); |
| 83 | while (1) |
95 | while (1) |
| Line 101... | Line 113... | ||
| 101 | speedAvgSum += loc.speed * delta; |
113 | speedAvgSum += loc.speed * delta; |
| 102 | speedAvgTime += delta; |
114 | speedAvgTime += delta; |
| 103 | lastLocTime = loc.utc; |
115 | lastLocTime = loc.utc; |
| 104 | } |
116 | } |
| 105 | else |
117 | else |
| 106 | lastLocTime = loc.utc; |
118 | lastLocTime = loc.utc; |
| 107 | } |
119 | } |
| 108 | else |
120 | else |
| 109 | { |
121 | { |
| 110 | lastLocTime = loc.utc; |
122 | lastLocTime = loc.utc; |
| 111 | } |
123 | } |
| 112 | } |
124 | } |
| 113 | } |
125 | } |
| 114 | else |
126 | else |
| 115 | { |
127 | { |
| 116 | memset (loc.time, '-', 6); |
128 | memset (loc.time, '-', 6); |
| 117 | } |
129 | } |
| 118 | } |
130 | } |
| 119 | // process button press |
131 | // process button press |
| 120 | uint8_t const buttonLimit = 3; |
132 | uint8_t const buttonLimit = 3; |
| 121 | uint8_t newPush = HAL_GPIO_ReadPin ( encoder_push_GPIO_Port, |
133 | uint8_t newPush = HAL_GPIO_ReadPin ( encoder_push_GPIO_Port, |
| Line 137... | Line 149... | ||
| 137 | speedAvgTime = 0.0; |
149 | speedAvgTime = 0.0; |
| 138 | } |
150 | } |
| 139 | } |
151 | } |
| 140 | 152 | ||
| 141 | // update the display once per second |
153 | // update the display once per second |
| 142 | if (HAL_GetTick() > nextPosTime ) |
154 | if (HAL_GetTick () > nextPosTime) |
| 143 | { |
155 | { |
| 144 | nextPosTime += 1000; |
156 | nextPosTime += 1000; |
| 145 | 157 | ||
| 146 | // slow down the output of ata |
158 | // slow down the output of ata |
| 147 | if (speedAvgTime > 0) |
159 | if (speedAvgTime > 0) |
| Line 173... | Line 185... | ||
| 173 | speedMPH = loc.speed * KNOTS_TO_MPH; |
185 | speedMPH = loc.speed * KNOTS_TO_MPH; |
| 174 | else |
186 | else |
| 175 | speedMPH = 0.0; |
187 | speedMPH = 0.0; |
| 176 | 188 | ||
| 177 | display1.gotoxy (0, 8); |
189 | display1.gotoxy (0, 8); |
| 178 | display1.printString (small_font, "Speed", 5, WHITE); |
- | |
| 179 | display1.gotoxy (0, 16); |
- | |
| 180 | display1.fontDigits (large_font, 4, 1, speedMPH * 10); |
190 | display1.fontDigits (large_font, 4,1, speedMPH * 10 ); |
| 181 | - | ||
| 182 | display1.gotoxy (0, 32); |
- | |
| 183 | display1.printString (small_font, "Average", 7, WHITE); |
191 | display1.printString (small_font, "c", 2, WHITE); |
| 184 | display1.gotoxy (0, 40); |
192 | display1.gotoxy (0,24); |
| 185 | display1.fontDigits (large_font, 4, 1, speedAvg * 10); |
193 | display1.fontDigits (large_font, 4, 1, speedAvg * 10); |
| - | 194 | display1.printString (small_font, "av", 2, WHITE); |
|
| - | 195 | ||
| - | 196 | float x, y, z; |
|
| - | 197 | if (IMU.magneticFieldAvailable ()) |
|
| - | 198 | { |
|
| 186 | 199 | ||
| - | 200 | IMU.readMagneticField (x, y, z); |
|
| - | 201 | } |
|
| - | 202 | ||
| - | 203 | if (IMU.accelerationAvailable ()) |
|
| - | 204 | { |
|
| - | 205 | IMU.readAcceleration (x, y, z); |
|
| - | 206 | } |
|
| - | 207 | ||
| 187 | struct bmp280_uncomp_data ucomp_data; |
208 | struct bmp280_uncomp_data ucomp_data, ucomp_data2; |
| 188 | 209 | ||
| 189 | if (HAL_GetTick () - lastTick > 100) |
210 | if (HAL_GetTick () - lastTick > 100) |
| 190 | { |
211 | { |
| 191 | lastTick = HAL_GetTick (); |
212 | lastTick = HAL_GetTick (); |
| 192 | /* Reading the raw data from sensor */ |
213 | /* Reading the raw data from sensor */ |
| 193 | rslt = bmp280_get_uncomp_data (&ucomp_data, bmp); |
214 | rslt = bmp280_get_uncomp_data (&ucomp_data, bmp); |
| 194 | 215 | ||
| - | 216 | /* reading the raw data from the second sensor */ |
|
| - | 217 | rslt2 = bmp280_get_uncomp_data (&ucomp_data2, bmp2); |
|
| - | 218 | ||
| 195 | if (rslt == BMP280_OK) |
219 | if (rslt2 == BMP280_OK) |
| 196 | { |
220 | { |
| 197 | /* Getting the 32 bit compensated temperature */ |
- | |
| 198 | rslt = bmp280_get_comp_temp_32bit (&temp32, |
221 | rslt2 = bmp280_get_comp_temp_32bit (&temp32_out, |
| 199 | ucomp_data.uncomp_temp, bmp); |
222 | ucomp_data2.uncomp_temp, bmp2); |
| - | 223 | } |
|
| - | 224 | ||
| 200 | 225 | ||
| - | 226 | if (rslt == BMP280_OK) |
|
| - | 227 | { |
|
| - | 228 | /* Getting the 32 bit compensated temperature */ |
|
| - | 229 | rslt = bmp280_get_comp_temp_32bit (&temp32, |
|
| - | 230 | ucomp_data.uncomp_temp, |
|
| - | 231 | bmp); |
|
| - | 232 | ||
| 201 | rslt = bmp280_get_comp_pres_32bit (&pres32, |
233 | rslt = bmp280_get_comp_pres_32bit (&pres32, |
| 202 | ucomp_data.uncomp_press, bmp); |
234 | ucomp_data.uncomp_press, |
| - | 235 | bmp); |
|
| 203 | 236 | ||
| 204 | #if defined USB_DEVICE |
237 | #if defined USB_DEVICE |
| 205 | /* |
238 | /* |
| 206 | * $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF> \\ |
239 | * $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF> \\ |
| 207 | 240 | ||
| Line 238... | Line 271... | ||
| 238 | CDC_Transmit_FS(reinterpret_cast<uint8_t*>(&buffer[0]),cnt); |
271 | CDC_Transmit_FS(reinterpret_cast<uint8_t*>(&buffer[0]),cnt); |
| 239 | #endif |
272 | #endif |
| 240 | 273 | ||
| 241 | } |
274 | } |
| 242 | } |
275 | } |
| - | 276 | display1.gotoxy (0,40); |
|
| - | 277 | display1.fontDigits (large_font, 4, 1, temp32_out / 10, WHITE); |
|
| - | 278 | display1.printString (small_font, "C", 1, WHITE); |
|
| - | 279 | ||
| 243 | display1.gotoxy (0, 56); |
280 | display1.gotoxy (0, 56); |
| 244 | display1.fontDigits (small_font, 3, 1, temp32 / 10, WHITE); |
281 | display1.fontDigits (small_font, 3, 1, temp32 / 10, WHITE); |
| 245 | display1.printString (small_font, "C", 2, WHITE); |
282 | display1.printString (small_font, "C", 2, WHITE); |
| - | 283 | ||
| 246 | display1.fontDigits (small_font, 4, -1, pres32 / 100, WHITE); |
284 | display1.fontDigits (small_font, 4, -1, pres32 / 100, WHITE); |
| 247 | display1.printString (small_font, "mb", 2, WHITE); |
285 | display1.printString (small_font, "mb ", 2, WHITE); |
| 248 | 286 | ||
| 249 | display1.display (); |
287 | display1.display (); |
| - | 288 | ||
| 250 | } |
289 | } |
| 251 | } |
290 | } |