Rev 18 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 18 | Rev 19 | ||
---|---|---|---|
Line 3... | Line 3... | ||
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 | 7 | ||
8 | #include "libBMP280/bmp280.h" |
8 | #include "libBME280/bme280.h" |
9 | 9 | ||
10 | #include "libSmallPrintf/small_printf.h" |
10 | #include "libSmallPrintf/small_printf.h" |
11 | 11 | ||
12 | #if defined USB_DEVICE |
12 | #if defined USB_DEVICE |
13 | #include "usbd_cdc_if.h" |
13 | #include "usbd_cdc_if.h" |
Line 21... | Line 21... | ||
21 | 21 | ||
22 | } |
22 | } |
23 | 23 | ||
24 | float speedMPH = 0.0; |
24 | float speedMPH = 0.0; |
25 | float speedAVG = 0.0; |
25 | float speedAVG = 0.0; |
26 | int speedTimer = 0; |
26 | int speedTimer = 0; |
27 | float speedDist = 0.0; |
27 | float speedDist = 0.0; |
28 | 28 | ||
29 | - | ||
30 | int heading = 0; |
29 | int heading = 0; |
31 | Location loc; |
30 | Location loc; |
32 | 31 | ||
33 | uint32_t lastTick = 0; |
32 | uint32_t lastTick = 0; |
34 | int32_t temp32 = 0; |
- | |
35 | uint32_t pres32 = 0; |
- | |
36 | int32_t rslt; |
33 | int32_t rslt; |
37 | 34 | ||
38 | uint8_t displayBuffer[dataSize (WIDTH, HEIGHT)]; |
35 | uint8_t displayBuffer[dataSize (WIDTH, HEIGHT)]; |
39 | 36 | ||
40 | stm32_halDisplay_t display1 (WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer, |
37 | stm32_halDisplay_t display1 (WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer, |
Line 64... | Line 61... | ||
64 | memset (loc.time, '-', 6); |
61 | memset (loc.time, '-', 6); |
65 | } |
62 | } |
66 | 63 | ||
67 | char fontBuf[] = "01234567"; |
64 | char fontBuf[] = "01234567"; |
68 | extern "C" void |
65 | extern "C" void |
69 | cc_run (struct bmp280_dev *bmp) |
66 | cc_run (struct bme280_dev *dev) |
70 | 67 | ||
71 | { |
68 | { |
72 | 69 | ||
73 | display1.clearDisplay (); |
70 | display1.clearDisplay (); |
74 | dial.draw_scale (0, 360, 8, 1, 45); |
71 | dial.draw_scale (0, 360, 8, 1, 45); |
Line 81... | Line 78... | ||
81 | loc.good = false; |
78 | loc.good = false; |
82 | } |
79 | } |
83 | if (loc.valid == 'V') |
80 | if (loc.valid == 'V') |
84 | memset (loc.time, '-', 6); |
81 | memset (loc.time, '-', 6); |
85 | 82 | ||
86 | - | ||
87 | - | ||
88 | // print out the GMT time at the top of the screen |
83 | // print out the GMT time at the top of the screen |
89 | display1.gotoxy (0, 0); |
84 | display1.gotoxy (0, 0); |
90 | display1.printString (small_font, &loc.time[0], 2, WHITE); |
85 | display1.printString (small_font, &loc.time[0], 2, WHITE); |
91 | display1.printString (small_font, ":", 1, WHITE); |
86 | display1.printString (small_font, ":", 1, WHITE); |
92 | display1.printString (small_font, &loc.time[2], 2, WHITE); |
87 | display1.printString (small_font, &loc.time[2], 2, WHITE); |
Line 115... | Line 110... | ||
115 | display1.gotoxy (0, 32); |
110 | display1.gotoxy (0, 32); |
116 | display1.printString (small_font, "Average", 7, WHITE); |
111 | display1.printString (small_font, "Average", 7, WHITE); |
117 | display1.gotoxy (0, 40); |
112 | display1.gotoxy (0, 40); |
118 | display1.fontDigits (large_font, 4, 1, speedAVG * 10); |
113 | display1.fontDigits (large_font, 4, 1, speedAVG * 10); |
119 | 114 | ||
120 | struct bmp280_uncomp_data ucomp_data; |
- | |
121 | - | ||
122 | if (HAL_GetTick () - lastTick > 100) |
115 | if (HAL_GetTick () - lastTick > 100) |
123 | { |
116 | { |
124 | lastTick = HAL_GetTick (); |
117 | lastTick = HAL_GetTick (); |
- | 118 | ||
125 | /* Reading the raw data from sensor */ |
119 | // storage for readings |
126 | rslt = bmp280_get_uncomp_data (&ucomp_data, bmp); |
120 | struct bme280_data comp_data; |
127 | 121 | ||
- | 122 | rslt = bme280_get_sensor_data (BME280_ALL, &comp_data, dev); |
|
128 | if (rslt == BMP280_OK) |
123 | if (rslt == BME280_OK) |
- | 124 | { |
|
- | 125 | ||
- | 126 | float temp, press, hum; |
|
129 | { |
127 | |
- | 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 |
|
130 | /* Getting the 32 bit compensated temperature */ |
134 | temp = 0.01f * comp_data.temperature; |
- | 135 | press = 0.0001f * comp_data.pressure; |
|
131 | rslt = bmp280_get_comp_temp_32bit (&temp32, ucomp_data.uncomp_temp, |
136 | hum = 1.0f / 1024.0f * comp_data.humidity; |
- | 137 | #else |
|
- | 138 | temp = 0.01f * comp_data.temperature; |
|
132 | bmp); |
139 | press = 0.01f * comp_data.pressure; |
- | 140 | hum = 1.0f / 1024.0f * comp_data.humidity; |
|
- | 141 | #endif |
|
- | 142 | #endif |
|
133 | 143 | ||
- | 144 | uint32_t temp32 = 0; |
|
134 | rslt = bmp280_get_comp_pres_32bit (&pres32, ucomp_data.uncomp_press, |
145 | uint32_t press32 = 0; |
135 | bmp); |
146 | uint32_t hum32 = 0; |
136 | 147 | ||
137 | #if defined USB_DEVICE |
148 | #if defined USB_DEVICE |
138 | /* |
149 | /* |
139 | * $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF> \\ |
150 | * $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF> \\ |
140 | 151 | ||
141 | Field Number: |
152 | Field Number: |
142 | 1) Transducer Type |
153 | 1) Transducer Type |
143 | 2) Measurement Data |
154 | 2) Measurement Data |
144 | 3) Units of measurement |
155 | 3) Units of measurement |
145 | 4) Name of transducer |
156 | 4) Name of transducer |
146 | x) More of the same |
157 | x) More of the same |
147 | n) Checksum |
158 | n) Checksum |
148 | 159 | ||
149 | Example: |
160 | Example: |
150 | $IIXDR,C,19.52,C,TempAir*19 |
161 | $IIXDR,C,19.52,C,TempAir*19 |
151 | $IIXDR,P,1.02481,B,Barometer*29 |
162 | $IIXDR,P,1.02481,B,Barometer*29 |
152 | 163 | ||
153 | Currently, OpenCPN recognizes the following transducers: |
164 | Currently, OpenCPN recognizes the following transducers: |
154 | 165 | ||
155 | Measured Value | Transducer Type | Measured Data | Unit of measure | Transducer Name |
166 | Measured Value | Transducer Type | Measured Data | Unit of measure | Transducer Name |
156 | ------------------------------------------------------------------------------------------------------ |
167 | ------------------------------------------------------------------------------------------------------ |
157 | barometric | "P" pressure | 0.8..1.1 or 800..1100 | "B" bar | "Barometer" |
168 | barometric | "P" pressure | 0.8..1.1 or 800..1100 | "B" bar | "Barometer" |
158 | air temperature| "C" temperature | 2 decimals | "C" celsius | "TempAir" or "ENV_OUTAIR_T" |
169 | air temperature| "C" temperature | 2 decimals | "C" celsius | "TempAir" or "ENV_OUTAIR_T" |
159 | pitch | "A" angle |-180..0 nose down 0..180 nose up | "D" degrees | "PTCH" or "PITCH" |
170 | pitch | "A" angle |-180..0 nose down 0..180 nose up | "D" degrees | "PTCH" or "PITCH" |
160 | rolling | "A" angle |-180..0 L 0..180 R | "D" degrees | "ROLL" |
171 | rolling | "A" angle |-180..0 L 0..180 R | "D" degrees | "ROLL" |
161 | water temp | "C" temperature | 2 decimals | "C" celsius | "ENV_WATER_T" |
172 | water temp | "C" temperature | 2 decimals | "C" celsius | "ENV_WATER_T" |
162 | */ |
173 | */ |
163 | // compile a logger message over USB |
174 | // compile a logger message over USB |
164 | char buffer[200]; |
175 | char buffer[200]; |
165 | int cnt = small_sprintf(buffer,"$MJXDR,C,%ld.%02ld,C,AirTemp,P,%01ld.%05ld,B,AirPres",temp32/100,temp32%100,pres32/100000,pres32%100000); |
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); |
166 | uint8_t sum=0; |
177 | uint8_t sum=0; |
167 | for(int i=1; i<cnt; i++) |
178 | for(int i=1; i<cnt; i++) |
168 | sum += buffer[i]; |
179 | sum += buffer[i]; |
169 | cnt+= small_sprintf(buffer+cnt,"*%02X\n",sum); |
180 | cnt+= small_sprintf(buffer+cnt,"*%02X\n",sum); |
170 | 181 | ||
171 | CDC_Transmit_FS(reinterpret_cast<uint8_t*>(&buffer[0]),cnt); |
182 | CDC_Transmit_FS(reinterpret_cast<uint8_t*>(&buffer[0]),cnt); |
172 | #endif |
183 | #endif |
173 | 184 | ||
174 | } |
- | |
175 | } |
- | |
176 | display1.gotoxy (0, 56); |
185 | display1.gotoxy (0, 56); |
177 | display1.printString (small_font, "T", 2, WHITE); |
186 | display1.printString (small_font, "T", 2, WHITE); |
178 | display1.fontDigits (small_font, 4, 1, temp32/10, WHITE); |
187 | display1.fontDigits (small_font, 4, 1, temp32 / 10, WHITE); |
179 | display1.printString (small_font, " P", 2, WHITE); |
188 | display1.printString (small_font, " P", 2, WHITE); |
180 | display1.fontDigits (small_font, 5, 0, pres32/100, WHITE); |
189 | display1.fontDigits (small_font, 5, 0, press32 / 100, WHITE); |
181 | display1.printString (small_font, " ", 1, WHITE); |
190 | display1.printString (small_font, " ", 1, WHITE); |
182 | - | ||
183 | 191 | ||
184 | display1.display (); |
192 | display1.display (); |
- | 193 | } |
|
185 | 194 | } |
|
186 | } |
195 | } |