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