Subversion Repositories dashGPS

Rev

Rev 16 | Rev 23 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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