Subversion Repositories dashGPS

Rev

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

  1. #include "main.h"
  2. #include "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. namespace
  11. {
  12.   int const WIDTH = 128;
  13.   int const HEIGHT = 64;
  14.   int const DISPLAY_RAMWIDTH = 132;
  15.  
  16. }
  17.  
  18. float speedMPH = 0.0;
  19. float speedAVG = 0.0;
  20. int heading = 0;
  21. Location loc;
  22.  
  23. uint32_t lastTick = 0;
  24. int32_t temp32 = 0;
  25. uint32_t pres32 = 0;
  26. int32_t rslt;
  27.  
  28. uint8_t displayBuffer[dataSize (WIDTH, HEIGHT)];
  29.  
  30. stm32_halDisplay_t display1 (WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer,
  31.                              &hspi1,
  32.  
  33.                              SPI_CD_GPIO_Port,
  34.                              SPI_CD_Pin,
  35.                              SPI_RESET_GPIO_Port,
  36.                              SPI_RESET_Pin,
  37.                              SPI_NSS1_GPIO_Port,
  38.                              SPI_NSS1_Pin);
  39.  
  40. displayDial_t dial (display1, 96, 32, 32, 180);
  41.  
  42. extern "C" void
  43. cc_init ()
  44. {
  45.   display1.reset ();
  46.  
  47.   display1.init ();
  48.   display1.clearDisplay ();
  49.  
  50.   dial.draw_scale (0, 360, 8, 1, 45);
  51.  
  52.   display1.display ();
  53.  
  54.   memset (loc.time, '-', 6);
  55. }
  56.  
  57. char fontBuf[] = "01234567";
  58. extern "C" void
  59. cc_run (struct bmp280_dev *bmp)
  60.  
  61. {
  62.  
  63.   display1.clearDisplay ();
  64.   dial.draw_scale (0, 360, 8, 1, 45);
  65.  
  66.   bool stat = updateLocation (&loc);
  67.   if (loc.good)
  68.     {
  69.       heading = loc.heading;
  70.  
  71.       loc.good = false;
  72.     }
  73.   if (loc.valid == 'V')
  74.     memset (loc.time, '-', 6);
  75.  
  76.   // print out the GMT time at the top of the screen
  77.   display1.gotoxy (0, 0);
  78.   display1.printString (small_font, &loc.time[0], 2, WHITE);
  79.   display1.printString (small_font, ":", 1, WHITE);
  80.   display1.printString (small_font, &loc.time[2], 2, WHITE);
  81.  
  82.   display1.printString (small_font, ":", 1, WHITE);
  83.   display1.printString (small_font, &loc.time[4], 2, WHITE);
  84.   int dial_ang = heading + 180;
  85.   dial.draw_needle (dial_ang);
  86.  
  87.   display1.gotoxy (70, 25);
  88.   if (loc.valid == 'A')
  89.     {
  90.       display1.fontDigits (large_font, 3, -1, heading);
  91.     }
  92.   else
  93.     display1.printString (large_font, "GPS?", 4, WHITE);
  94.  
  95.   if (loc.valid == 'A')
  96.     speedMPH = loc.speed / 1.815;
  97.  
  98.   display1.gotoxy (0, 8);
  99.   display1.printString (small_font, "Speed", 5, WHITE);
  100.   display1.gotoxy (0, 16);
  101.   display1.fontDigits (large_font, 4, 1, speedMPH * 10);
  102.  
  103.   display1.gotoxy (0, 32);
  104.   display1.printString (small_font, "Average", 7, WHITE);
  105.   display1.gotoxy (0, 40);
  106.   display1.fontDigits (large_font, 4, 1, speedAVG * 10);
  107.  
  108.   struct bmp280_uncomp_data ucomp_data;
  109.  
  110.   if (HAL_GetTick () - lastTick > 1000)
  111.     {
  112.       lastTick = HAL_GetTick ();
  113.       /* Reading the raw data from sensor */
  114.       rslt = bmp280_get_uncomp_data (&ucomp_data, bmp);
  115.  
  116.       if (rslt == BMP280_OK)
  117.         {
  118.           /* Getting the 32 bit compensated temperature */
  119.           rslt = bmp280_get_comp_temp_32bit (&temp32, ucomp_data.uncomp_temp,
  120.                                              bmp);
  121.  
  122.           rslt = bmp280_get_comp_pres_32bit (&pres32, ucomp_data.uncomp_press,
  123.                                              bmp);
  124.  
  125.         }
  126.     }
  127.   display1.gotoxy (0, 56);
  128.   display1.printString (small_font, "T", 2, WHITE);
  129.   display1.fontDigits (small_font, 4, 1, temp32/10, WHITE);
  130.   display1.printString (small_font, " P", 2, WHITE);
  131.   display1.fontDigits (small_font, 5, 0, pres32/100, WHITE);
  132.   display1.printString (small_font, " ", 1, WHITE);
  133.  
  134.   display1.display ();
  135.  
  136. }
  137.