Rev 18 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6 | mjames | 1 | #include "main.h" |
15 | mjames | 2 | #include "libNMEA/nmea.h" |
9 | mjames | 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 | |
19 | mjames | 8 | #include "libBME280/bme280.h" |
11 | mjames | 9 | |
13 | mjames | 10 | #include "libSmallPrintf/small_printf.h" |
15 | mjames | 11 | |
12 | #if defined USB_DEVICE |
||
13 | mjames | 13 | #include "usbd_cdc_if.h" |
15 | mjames | 14 | #endif |
13 | mjames | 15 | |
6 | mjames | 16 | namespace |
17 | { |
||
18 | int const WIDTH = 128; |
||
19 | int const HEIGHT = 64; |
||
20 | int const DISPLAY_RAMWIDTH = 132; |
||
21 | |||
22 | } |
||
23 | |||
10 | mjames | 24 | float speedMPH = 0.0; |
25 | float speedAVG = 0.0; |
||
19 | mjames | 26 | int speedTimer = 0; |
15 | mjames | 27 | float speedDist = 0.0; |
28 | |||
9 | mjames | 29 | int heading = 0; |
30 | Location loc; |
||
31 | |||
11 | mjames | 32 | uint32_t lastTick = 0; |
33 | int32_t rslt; |
||
34 | |||
6 | mjames | 35 | uint8_t displayBuffer[dataSize (WIDTH, HEIGHT)]; |
36 | |||
37 | stm32_halDisplay_t display1 (WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer, |
||
38 | &hspi1, |
||
39 | |||
40 | SPI_CD_GPIO_Port, |
||
41 | SPI_CD_Pin, |
||
42 | SPI_RESET_GPIO_Port, |
||
43 | SPI_RESET_Pin, |
||
44 | SPI_NSS1_GPIO_Port, |
||
45 | SPI_NSS1_Pin); |
||
46 | |||
9 | mjames | 47 | displayDial_t dial (display1, 96, 32, 32, 180); |
8 | mjames | 48 | |
6 | mjames | 49 | extern "C" void |
50 | cc_init () |
||
51 | { |
||
11 | mjames | 52 | display1.reset (); |
53 | |||
9 | mjames | 54 | display1.init (); |
6 | mjames | 55 | display1.clearDisplay (); |
56 | |||
9 | mjames | 57 | dial.draw_scale (0, 360, 8, 1, 45); |
6 | mjames | 58 | |
59 | display1.display (); |
||
9 | mjames | 60 | |
10 | mjames | 61 | memset (loc.time, '-', 6); |
6 | mjames | 62 | } |
63 | |||
9 | mjames | 64 | char fontBuf[] = "01234567"; |
6 | mjames | 65 | extern "C" void |
19 | mjames | 66 | cc_run (struct bme280_dev *dev) |
11 | mjames | 67 | |
6 | mjames | 68 | { |
7 | mjames | 69 | |
9 | mjames | 70 | display1.clearDisplay (); |
71 | dial.draw_scale (0, 360, 8, 1, 45); |
||
8 | mjames | 72 | |
15 | mjames | 73 | bool stat = updateLocation (&loc, &uc1); |
9 | mjames | 74 | if (loc.good) |
75 | { |
||
76 | heading = loc.heading; |
||
8 | mjames | 77 | |
9 | mjames | 78 | loc.good = false; |
11 | mjames | 79 | } |
80 | if (loc.valid == 'V') |
||
81 | memset (loc.time, '-', 6); |
||
9 | mjames | 82 | |
11 | mjames | 83 | // print out the GMT time at the top of the screen |
84 | display1.gotoxy (0, 0); |
||
85 | display1.printString (small_font, &loc.time[0], 2, WHITE); |
||
86 | display1.printString (small_font, ":", 1, WHITE); |
||
87 | display1.printString (small_font, &loc.time[2], 2, WHITE); |
||
9 | mjames | 88 | |
11 | mjames | 89 | display1.printString (small_font, ":", 1, WHITE); |
90 | display1.printString (small_font, &loc.time[4], 2, WHITE); |
||
91 | int dial_ang = heading + 180; |
||
92 | dial.draw_needle (dial_ang); |
||
9 | mjames | 93 | |
11 | mjames | 94 | display1.gotoxy (70, 25); |
95 | if (loc.valid == 'A') |
||
96 | { |
||
97 | display1.fontDigits (large_font, 3, -1, heading); |
||
98 | } |
||
99 | else |
||
100 | display1.printString (large_font, "GPS?", 4, WHITE); |
||
9 | mjames | 101 | |
11 | mjames | 102 | if (loc.valid == 'A') |
103 | speedMPH = loc.speed / 1.815; |
||
9 | mjames | 104 | |
11 | mjames | 105 | display1.gotoxy (0, 8); |
106 | display1.printString (small_font, "Speed", 5, WHITE); |
||
107 | display1.gotoxy (0, 16); |
||
108 | display1.fontDigits (large_font, 4, 1, speedMPH * 10); |
||
9 | mjames | 109 | |
11 | mjames | 110 | display1.gotoxy (0, 32); |
111 | display1.printString (small_font, "Average", 7, WHITE); |
||
112 | display1.gotoxy (0, 40); |
||
113 | display1.fontDigits (large_font, 4, 1, speedAVG * 10); |
||
9 | mjames | 114 | |
19 | mjames | 115 | if (HAL_GetTick () - lastTick > 100) |
116 | { |
||
117 | lastTick = HAL_GetTick (); |
||
9 | mjames | 118 | |
19 | mjames | 119 | // storage for readings |
120 | struct bme280_data comp_data; |
||
10 | mjames | 121 | |
19 | mjames | 122 | rslt = bme280_get_sensor_data (BME280_ALL, &comp_data, dev); |
123 | if (rslt == BME280_OK) |
||
124 | { |
||
10 | mjames | 125 | |
19 | mjames | 126 | float temp, press, hum; |
10 | mjames | 127 | |
19 | mjames | 128 | #ifdef BME280_FLOAT_ENABLE |
129 | temp = comp_data.temperature; |
||
130 | press = 0.01 * comp_data.pressure; |
||
131 | hum = comp_data.humidity; |
||
132 | #else |
||
133 | #ifdef BME280_64BIT_ENABLE |
||
134 | temp = 0.01f * comp_data.temperature; |
||
135 | press = 0.0001f * comp_data.pressure; |
||
136 | hum = 1.0f / 1024.0f * comp_data.humidity; |
||
137 | #else |
||
138 | temp = 0.01f * comp_data.temperature; |
||
139 | press = 0.01f * comp_data.pressure; |
||
140 | hum = 1.0f / 1024.0f * comp_data.humidity; |
||
141 | #endif |
||
142 | #endif |
||
143 | |||
144 | uint32_t temp32 = 0; |
||
145 | uint32_t press32 = 0; |
||
146 | uint32_t hum32 = 0; |
||
147 | |||
15 | mjames | 148 | #if defined USB_DEVICE |
19 | mjames | 149 | /* |
150 | * $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF> \\ |
||
15 | mjames | 151 | |
16 | mjames | 152 | Field Number: |
19 | mjames | 153 | 1) Transducer Type |
154 | 2) Measurement Data |
||
155 | 3) Units of measurement |
||
156 | 4) Name of transducer |
||
157 | x) More of the same |
||
158 | n) Checksum |
||
16 | mjames | 159 | |
19 | mjames | 160 | Example: |
161 | $IIXDR,C,19.52,C,TempAir*19 |
||
162 | $IIXDR,P,1.02481,B,Barometer*29 |
||
16 | mjames | 163 | |
19 | mjames | 164 | Currently, OpenCPN recognizes the following transducers: |
16 | mjames | 165 | |
19 | mjames | 166 | Measured Value | Transducer Type | Measured Data | Unit of measure | Transducer Name |
167 | ------------------------------------------------------------------------------------------------------ |
||
168 | barometric | "P" pressure | 0.8..1.1 or 800..1100 | "B" bar | "Barometer" |
||
169 | air temperature| "C" temperature | 2 decimals | "C" celsius | "TempAir" or "ENV_OUTAIR_T" |
||
170 | pitch | "A" angle |-180..0 nose down 0..180 nose up | "D" degrees | "PTCH" or "PITCH" |
||
171 | rolling | "A" angle |-180..0 L 0..180 R | "D" degrees | "ROLL" |
||
172 | water temp | "C" temperature | 2 decimals | "C" celsius | "ENV_WATER_T" |
||
173 | */ |
||
174 | // compile a logger message over USB |
||
175 | char buffer[200]; |
||
176 | int cnt = small_sprintf(buffer,"$MJXDR,C,%ld.%02ld,C,AirTemp,P,%01ld.%05ld,B,AirPres",temp32/100,temp32%100,press32/100000,press32%100000); |
||
177 | uint8_t sum=0; |
||
178 | for(int i=1; i<cnt; i++) |
||
179 | sum += buffer[i]; |
||
180 | cnt+= small_sprintf(buffer+cnt,"*%02X\n",sum); |
||
13 | mjames | 181 | |
19 | mjames | 182 | CDC_Transmit_FS(reinterpret_cast<uint8_t*>(&buffer[0]),cnt); |
15 | mjames | 183 | #endif |
13 | mjames | 184 | |
19 | mjames | 185 | display1.gotoxy (0, 56); |
186 | display1.printString (small_font, "T", 2, WHITE); |
||
187 | display1.fontDigits (small_font, 4, 1, temp32 / 10, WHITE); |
||
188 | display1.printString (small_font, " P", 2, WHITE); |
||
189 | display1.fontDigits (small_font, 5, 0, press32 / 100, WHITE); |
||
190 | display1.printString (small_font, " ", 1, WHITE); |
||
10 | mjames | 191 | |
19 | mjames | 192 | display1.display (); |
193 | } |
||
194 | } |
||
6 | mjames | 195 | } |