Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6 | mjames | 1 | #include "main.h" |
9 | mjames | 2 | #include "nmea.h" |
3 | #include <cstring> |
||
6 | mjames | 4 | #include "libOLED/stm32_halDisplay.H" |
7 | mjames | 5 | #include "libOLED/fontclass.H" |
8 | mjames | 6 | #include "libOLED/displayDial.H" |
7 | mjames | 7 | |
11 | mjames | 8 | #include "libBMP280/bmp280.h" |
9 | |||
13 | mjames | 10 | #include "libSmallPrintf/small_printf.h" |
11 | #include "usbd_cdc_if.h" |
||
12 | |||
6 | mjames | 13 | namespace |
14 | { |
||
15 | int const WIDTH = 128; |
||
16 | int const HEIGHT = 64; |
||
17 | int const DISPLAY_RAMWIDTH = 132; |
||
18 | |||
19 | } |
||
20 | |||
10 | mjames | 21 | float speedMPH = 0.0; |
22 | float speedAVG = 0.0; |
||
9 | mjames | 23 | int heading = 0; |
24 | Location loc; |
||
25 | |||
11 | mjames | 26 | uint32_t lastTick = 0; |
27 | int32_t temp32 = 0; |
||
28 | uint32_t pres32 = 0; |
||
29 | int32_t rslt; |
||
30 | |||
6 | mjames | 31 | uint8_t displayBuffer[dataSize (WIDTH, HEIGHT)]; |
32 | |||
33 | stm32_halDisplay_t display1 (WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer, |
||
34 | &hspi1, |
||
35 | |||
36 | SPI_CD_GPIO_Port, |
||
37 | SPI_CD_Pin, |
||
38 | SPI_RESET_GPIO_Port, |
||
39 | SPI_RESET_Pin, |
||
40 | SPI_NSS1_GPIO_Port, |
||
41 | SPI_NSS1_Pin); |
||
42 | |||
9 | mjames | 43 | displayDial_t dial (display1, 96, 32, 32, 180); |
8 | mjames | 44 | |
6 | mjames | 45 | extern "C" void |
46 | cc_init () |
||
47 | { |
||
11 | mjames | 48 | display1.reset (); |
49 | |||
9 | mjames | 50 | display1.init (); |
6 | mjames | 51 | display1.clearDisplay (); |
52 | |||
9 | mjames | 53 | dial.draw_scale (0, 360, 8, 1, 45); |
6 | mjames | 54 | |
55 | display1.display (); |
||
9 | mjames | 56 | |
10 | mjames | 57 | memset (loc.time, '-', 6); |
6 | mjames | 58 | } |
59 | |||
9 | mjames | 60 | char fontBuf[] = "01234567"; |
6 | mjames | 61 | extern "C" void |
11 | mjames | 62 | cc_run (struct bmp280_dev *bmp) |
63 | |||
6 | mjames | 64 | { |
7 | mjames | 65 | |
9 | mjames | 66 | display1.clearDisplay (); |
67 | dial.draw_scale (0, 360, 8, 1, 45); |
||
8 | mjames | 68 | |
9 | mjames | 69 | bool stat = updateLocation (&loc); |
70 | if (loc.good) |
||
71 | { |
||
72 | heading = loc.heading; |
||
8 | mjames | 73 | |
9 | mjames | 74 | loc.good = false; |
11 | mjames | 75 | } |
76 | if (loc.valid == 'V') |
||
77 | memset (loc.time, '-', 6); |
||
9 | mjames | 78 | |
11 | mjames | 79 | // print out the GMT time at the top of the screen |
80 | display1.gotoxy (0, 0); |
||
81 | display1.printString (small_font, &loc.time[0], 2, WHITE); |
||
82 | display1.printString (small_font, ":", 1, WHITE); |
||
83 | display1.printString (small_font, &loc.time[2], 2, WHITE); |
||
9 | mjames | 84 | |
11 | mjames | 85 | display1.printString (small_font, ":", 1, WHITE); |
86 | display1.printString (small_font, &loc.time[4], 2, WHITE); |
||
87 | int dial_ang = heading + 180; |
||
88 | dial.draw_needle (dial_ang); |
||
9 | mjames | 89 | |
11 | mjames | 90 | display1.gotoxy (70, 25); |
91 | if (loc.valid == 'A') |
||
92 | { |
||
93 | display1.fontDigits (large_font, 3, -1, heading); |
||
94 | } |
||
95 | else |
||
96 | display1.printString (large_font, "GPS?", 4, WHITE); |
||
9 | mjames | 97 | |
11 | mjames | 98 | if (loc.valid == 'A') |
99 | speedMPH = loc.speed / 1.815; |
||
9 | mjames | 100 | |
11 | mjames | 101 | display1.gotoxy (0, 8); |
102 | display1.printString (small_font, "Speed", 5, WHITE); |
||
103 | display1.gotoxy (0, 16); |
||
104 | display1.fontDigits (large_font, 4, 1, speedMPH * 10); |
||
9 | mjames | 105 | |
11 | mjames | 106 | display1.gotoxy (0, 32); |
107 | display1.printString (small_font, "Average", 7, WHITE); |
||
108 | display1.gotoxy (0, 40); |
||
109 | display1.fontDigits (large_font, 4, 1, speedAVG * 10); |
||
9 | mjames | 110 | |
11 | mjames | 111 | struct bmp280_uncomp_data ucomp_data; |
9 | mjames | 112 | |
11 | mjames | 113 | if (HAL_GetTick () - lastTick > 1000) |
114 | { |
||
115 | lastTick = HAL_GetTick (); |
||
116 | /* Reading the raw data from sensor */ |
||
117 | rslt = bmp280_get_uncomp_data (&ucomp_data, bmp); |
||
10 | mjames | 118 | |
11 | mjames | 119 | if (rslt == BMP280_OK) |
120 | { |
||
121 | /* Getting the 32 bit compensated temperature */ |
||
122 | rslt = bmp280_get_comp_temp_32bit (&temp32, ucomp_data.uncomp_temp, |
||
123 | bmp); |
||
10 | mjames | 124 | |
11 | mjames | 125 | rslt = bmp280_get_comp_pres_32bit (&pres32, ucomp_data.uncomp_press, |
126 | bmp); |
||
10 | mjames | 127 | |
13 | mjames | 128 | // compile a logger message over USB |
129 | char buffer[100]; |
||
130 | int cnt = small_sprintf(buffer,"$TP,%ld,%ld",temp32,pres32); |
||
131 | uint8_t sum=0; |
||
132 | for(int i=1; i<cnt; i++) |
||
133 | sum += buffer[i]; |
||
134 | cnt+= small_sprintf(buffer+cnt,"*%02X\n",sum); |
||
135 | |||
136 | CDC_Transmit_FS(reinterpret_cast<uint8_t*>(&buffer[0]),cnt); |
||
137 | |||
138 | |||
11 | mjames | 139 | } |
140 | } |
||
141 | display1.gotoxy (0, 56); |
||
142 | display1.printString (small_font, "T", 2, WHITE); |
||
143 | display1.fontDigits (small_font, 4, 1, temp32/10, WHITE); |
||
144 | display1.printString (small_font, " P", 2, WHITE); |
||
145 | display1.fontDigits (small_font, 5, 0, pres32/100, WHITE); |
||
146 | display1.printString (small_font, " ", 1, WHITE); |
||
10 | mjames | 147 | |
13 | mjames | 148 | |
11 | mjames | 149 | display1.display (); |
150 | |||
6 | mjames | 151 | } |